# The Industry's Foundation for High Performance Graphics

1. ## 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. ## 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. ## 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

4. ## Re: Refraction in GLSL

I hope so. It's useful functionality.

5. ## 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. ## 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
•