Need a little help with a Fresnel Shader.

Recommended Posts

Hello everyone, I'm trying to write a fresnel shader for water reflections, but i'm being unable to be sure whether what i've written is a proper fresnel shader. Would you guys mind to take a look at my shader source, and tell me if i'm "doing it right"?
//vertex shader
varying float FresnelFactor;
varying vec4 TexCoord;
uniform vec4 vViewPosition;

void main(void)
{
vec3 Normal = normalize(gl_Normal * gl_NormalMatrix);

TexCoord = gl_MultiTexCoord0;

vec3 EyeVector = normalize(vViewPosition - gl_ModelViewMatrix * gl_Vertex).xyz;

FresnelFactor = dot(Normal, EyeVector);

gl_Position = ftransform();
}

varying float FresnelFactor;
varying vec4 TexCoord;
uniform sampler2D Texture0;

void main(void)
{
vec3 NonReflective = texture2D(Texture0, TexCoord.st).rgb;
vec3 Reflective = vec3(1, 1, 1);

gl_FragColor = vec4(NonReflective * (1.0 - FresnelFactor) + Reflective * FresnelFactor, 1);
}


Thank you for your time regarding this message, and have a nice day!

Share on other sites
Viik    252
Good Fresnel term would be more complex than simple dot product and it's better to calculate per pixel as yur water might have a normal map for small bumps. Check this article: