Jump to content
  • Advertisement
Sign in to follow this  
Little Coding Fox

Need a little help with a Fresnel Shader.

This topic is 3479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!