refract
Keywords: refract, NVIDIA, NVIDIA Cg Toolkit, Cg Toolkit, Shader, Shader Programming, GPU Shader Programming, GPU Program

> ## Name

> refract - computes a refraction vector.

> ## Synopsis

>     fixed3 refract(fixed3 i, fixed3 n, fixed eta);
>     half3  refract(half3  i, half3  n, half  eta);
>     float3 refract(float3 i, float3 n, float eta);

> ## Parameters

> i
>   Incidence vector.
> n
>   Normal vector.
> eta
>   Ratio of indices of refraction at the surface interface.

> ## Description

> Returns a refraction vector given an incidence vector, a normal vector for a surface, and a ratio of indices of refraction at the surface's interface.

> The incidence vector i and normal vector n should be normalized.

> ## Reference Implementation

> reflect for float3 vectors could be implemented this way:

>     float3 refract( float3 i, float3 n, float eta )
>     {
>       float cosi = dot(-i, n);
>       float cost2 = 1.0f - eta * eta * (1.0f - cosi*cosi);
>       float3 t = eta*i + ((eta*cosi - sqrt(abs(cost2))) * n);
>       return t * (float3)(cost2 > 0);
>     }

> ## Profile Support

> refract is supported in all profiles.

> Support in the fp20 is limited.

> ## See Also

> abs, cos, dot, reflect, sqrt