Per pixel fresnel term

Started by
16 comments, last by pasman 19 years ago
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.
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?
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...
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.
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.
You should never let your fears become the boundaries of your dreams.
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?
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?
You should never let your fears become the boundaries of your dreams.
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.
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.
You should never let your fears become the boundaries of your dreams.
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?

This topic is closed to new replies.

Advertisement