Skip to main content
gamedev.net
🔒 Locked

Water Reflection

Started by D3DXVECTOR3 Aug 30, 2008 at 12:22 PM 1 replies 1.2k views
Original Post
D3DXVECTOR3
D3DXVECTOR3
I'm having the same problems as the guys in this topic: http://www.gamedev.net/community/forums/topic.asp?topic_id=489899 http://i2.photobucket.com/albums/y48/klepto2/water1.jpg http://i2.photobucket.com/albums/y48/klepto2/water2.jpg I fixed it by scaling the world with -1 and not the vTexCoord.y, but this introduced a new problem. My skydome isn't "infinite" anymore in the reflection. to sum it up: - reflection rotates incorrect or - "infinite" skydome not working when using scale -1 A solution for one of the problems is needed. below is the source code


// Begin reflection
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glTranslatef(0.0f, 0.0f, 0.0f);
glScalef(1.0f, -1.0f, 1.0f);

double reflectPlane[4] = {0.0f, 1.0f, 0.0f, 0.0f};
glClipPlane(GL_CLIP_PLANE0, reflectPlane);
glEnable(GL_CLIP_PLANE0);
	
glCullFace(GL_FRONT);



// Draw skydome
glDepthMask(GL_FALSE);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranslatef(camera.x, camera.y, camera.z);

RenderDome():

glPopMatrix();
glDepthMask(GL_TRUE);




// End reflection
glCullFace(GL_BACK);
glDisable(GL_CLIP_PLANE0);
glPopMatrix();




[Edited by - D3DXVECTOR3 on August 31, 2008 3:41:55 AM]
Vilem Otte
Vilem Otte
Okay, it sounds like coordinate or transformation issues.

How are you calculating coordinates for reflection? I presume you're doing it in shader ... so they've to be calculated as:
// Vertex ShaderprojectionCoordinates = gl_ModelViewProjectionMatrix * gl_Vertex;// Fragment Shadervec3 reflectionCoordinates = texCoord.xyz / texCoord.q;reflectionCoordinates = (reflectionCoordinates + 1.0) * 0.5;reflectionCoordinates = clamp(reflectionCoordinates , 0.001, 0.999);


If it is transformation issues - they can be made by only one thing, after you flip your scene upside down you're not transformating it by camera.
D3DXVECTOR3
D3DXVECTOR3
Vertex Shader:
OUT.Projection = mul( glstate.matrix.mvp, IN.Position);

Fragment Shader:
float2 vTexCoord = (IN.Projection.xy / IN.Projection.z);
vTexCoord = ( vTexCoord + 1 ) * 0.5f;

What I dont understand is how a scale -1 would have an impact on the skydome not beeing infinite anymore. It is as if it enabled depth test agasin.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.