Jump to content
  • Advertisement
Sign in to follow this  
pasman

OpenGL Per pixel fresnel term

This topic is 4876 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

Hi, I've done some basic water for my game, reflection, surface perturbation (using fragment programs) but I'd like to add fresnel term. The thing is that the water plane has only 4 vertices so it must be done in FP. I tried to implement the formula from nVidia's paper on fresnel term. I'm using CG/OpenGL. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
What's the exact problem that you're having? The idea is to use "N dot V" (normal dotted with view vector) and raise it to some power, usually around 5. Could you elaborate please on the trouble?

Share this post


Link to post
Share on other sites
I'm sorry I don't have the shader source code but here is what I do:
- send eye position to vertex shader
- compute the eye vector
- send it as color to the fragment shader
- in FP I have a float fresnel(float3 light,float3 normal,float R0) function (from nVidia)
- normal (0,1,0)
- then I interpolate between the reflection/refraction using the result

The thing is the transparency is the same over the entire water plane, even though it changes when I move the camera...

Share this post


Link to post
Share on other sites
Make sure that all of your vectors are in the same space. If you're using a constant normal of (0,1,0), that implies that you're working in "tangent space". Thus to take a valid dot product of with the view vector, it must as well be in tangent space! That means that you'll have to form probably a World -> Tangent matrix and multiple the computed view vector by it, all in the vertex shader. Then in the fragment shader you can compute N dot V and it'll be valid for the fresnel calculation.

Share this post


Link to post
Share on other sites
Also make sure the eye vector gets normalized in fragment shader and not in vertex shader. And that it doesn't get clamped to 0,1 range since you are using color to pass it.

Share this post


Link to post
Share on other sites
Quote:
Original post by _DarkWIng_
Also make sure the eye vector gets normalized in fragment shader and not in vertex shader. And that it doesn't get clamped to 0,1 range since you are using color to pass it.


In order not to be clamped shouldn't the eye vector be normalize in vertex shader?
How else could I send the eye vector, because I don't have any texture units available?

EDIT: hmm..maybe send it as the w component from each texture unit?

Share this post


Link to post
Share on other sites
Quote:
Original post by pasman
How else could I send the eye vector, because I don't have any texture units available?

You are using ALL texture coordinates? What else are you sending trough? Do you mind posting shaders here?

Share this post


Link to post
Share on other sites
There is no problem posting the shader but i'm in a short vacation now, outside my town and I don't have it here, but i'm sending projective texture coordinates, diffuse map, a distorsion map and a refraction map(not yet - but reserved space:) ), each having different tex coords to give some variation, although i might drop the refraction map and simply use blending and the fresnel term would be used for alpha channel.
Oh and I'm working on a GeForce FX5200.

Share this post


Link to post
Share on other sites
Well, that only 4 sets. I'm 99% sure GF-FX can do 8 or more. In opengl you can probably do a query to get exact number of avabile interpolators.

Share this post


Link to post
Share on other sites
Quote:
Original post by _DarkWIng_
Well, that only 4 sets. I'm 99% sure GF-FX can do 8 or more. In opengl you can probably do a query to get exact number of avabile interpolators.


I might be missing something but I understand that it has only 4 texture units (so does the query...). But I can use 8 tex coord sets?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!