Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Refraction in GLSL

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Nov 2002
    Location
    Latvia
    Posts
    626

    Refraction in GLSL

    I ran GLSL validate on my shaders that were tested on NV & found a lot of incompatibilities. After chanfing all the 1 to 1.0 and removing stuff like asigning to variables that are initializet as varying vec's in the program there is still one thing that I miss...
    That is refraction, in NV GLSL implementation it works just fine, but validator keeps swearing
    What is the formula to calculate refraction?

  2. #2
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,345

    Re: Refraction in GLSL

    A quick look in the spec reviels that there's no refract function. I guess you'll have to write your own.

    http://www.3dlabs.com/support/develo...SpecV1.051.pdf

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    U.S.
    Posts
    149

    Re: Refraction in GLSL

    Here's a sample implementation of the refract routine in Cg ...

    float3 refract(float3 I, float3 N, float etaRatio)
    {
    float cosI = dot(-I, N);
    float cosT2 = 1.0f - etaRatio * etaRatio * (1.0f - cosI * cosI);
    float3 T = etaRatio * I + ((etaRatio * cosI - sqrt(abs)(cosT2))) * N);
    return T * (float3)(cosT2 > 0);
    }

    I = incident ray direction
    N = surface normal
    etaRatio = relative index of refraction
    return = refraction vector

    Will GLSL eventually add this?

  4. #4
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,345

    Re: Refraction in GLSL

    I hope so. It's useful functionality.

  5. #5
    Intern Newbie
    Join Date
    Mar 2004
    Posts
    31

    Re: Refraction in GLSL

    using the compositionality of fragment programs, you can have one main() and several sub-shaders you can call from your main, can't you just write it once and use it wherever you want? Let the time do its job and I bet we'll soon see some cool GLSLANG routines packages.

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2005
    Posts
    2

    Re: Refraction in GLSL

    Actually, refract has been included in the newer version of GLSL:

    http://oss.sgi.com/projects/ogl-samp...ll.1.10.59.pdf

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •