Normals for water simulation

Started by
16 comments, last by tasseloff 19 years, 4 months ago
k....
so i guess ill try to look into the lighting stuff, but im not 100% sure its that tho because if there was no lighting then my plane should be black as thats the original color i gave it...
Advertisement
ah, my brain has just worken up [grin]

You draw the reflection with a white background, yes?
Thus, when you project the texture you are projecting a white texture onto the plane which will vanish into the background.

Just to give you a hint on the shaders, the ones i'm using are
// vertex programvarying vec4 projCoord;void main(){  vec3 lightVect, trueNormal;  vec4 realPos = gl_ModelViewMatrix * gl_Vertex;    lightVect = normalize(gl_LightSource[0].position.xyz - realPos.xyz);  trueNormal = gl_NormalMatrix * gl_Normal;    projCoord = gl_TextureMatrix[0] * gl_Vertex;  gl_FrontColor = vec4(dot(lightVect, trueNormal) - 0.1);    gl_Position = ftransform();}// fragment programuniform sampler2D reflectTex;varying vec4 projCoord;const vec4 ambient = vec4(0.13), boost = vec4(1.06);void main(){  vec4 reflectionValue = texture2DProj(reflectTex, projCoord);  gl_FragColor = boost * gl_Color * reflectionValue + ambient;}

(projCoord is the same as using the multi-texture coord thing you use)

It could be adjusted to use glLighting later, but as a proof of concept it works well [smile]
ahh yeah....so i guess i have to set some sort of blending on my projection....
well, i've got some work ahead :)
tks a LOT for your help...
also to calculate the normals i've used the technique on the site given by gamelife
N = Vector3D(z[x-1][y] - z[x+1][y], z[x][y-1] - z[x][y+1], 2);
N.Normalize();

so far it seems to work ok, so now i guess i just have to work a bit more on my shaders and implement a few things concerning lighting and colors.
ill keep ya posted :)
tks again
ok....i calculated the normals and everything but....shouldn't the surface be all smooth now when i disburb it??

http://pallots.kicks-ass.net/planarreflect/disturb.jpg
and you can see better here without any reflections:
http://pallots.kicks-ass.net/planarreflect/disturb2.jpg
there you can see a bit what it looks like... whatever disturbance i do i still see all the square facets and afaik with a normal for every vertex i shouldn't....

also im wondering if anyone had or could tell me where i could get just a small surrounding (like a terrain) on which i could put my water to really see if the reflections are right...
OK i fixed it, it was indeed the normals, here's what it looks like now:
http://pallots.kicks-ass.net/planarreflect/disturb5.jpg
compared to
http://pallots.kicks-ass.net/planarreflect/disturb4.jpg

:D

[Edited by - tasseloff on December 5, 2004 10:37:44 PM]
hi, i know this is my old thread but, didn't want to start a new one for nothing.....
right now, im using the calculation given on the link above to calculate normals.....basically its

normalize(height[x-1,y] - height[x+1,y], height[x,y-1] - height[x,y+1], 2)

however...id like to know where that comes from.....it seems to be a common way to calculate normals on a heightfield but im just wondering what's the math behind all that...
the math term for that equation is finite difference. It's a way to compute the derivative of a discrete data field. Geometrically speaking, it approximates the 2D tangential plane over each texel. The surface normal of that plane is the normal of the height field texel.
ahh, tks a lot Yann :)
hope your trip went well

finally i was able to get my simulation based on the Obrien paper to work, even tho the code you gave in your lecture seemed more efficient there's a few things i wasn't sure about so i just didn't use it

tks for the reply

This topic is closed to new replies.

Advertisement