Sign in to follow this  
Little Coding Fox

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();
}

//fragment shader
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 this post


Link to post
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:
http://ati.amd.com/developer/shaderx/ShaderX_PerPixelFresnel.pdf

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this