render-to-texture reflections on a non-trivial surface

Started by
14 comments, last by GameDev.net 18 years, 11 months ago
Yann L has wrote an article about Water Reflections some time ago. I assure you it will explain everything(it did for me):
http://www.gamedev.net/reference/articles/article2138.asp

Quote:
Because reflections are not generally constructed with projective texture mapping. Consider using sphere or cube mapping for simulating good-looking (like Far Cry, you know what I mean...) reflections, instead.


Actually, local reflections are implemented using projective texture mapping. You just offset the proj. texture coords using the normal vector. Not exactly physically correct, but it gives a pretty good effect. I'm pretty sure Far Cry and every other game does something similar. Cube mapping is used to reflect objects that are(in theory) infinitely far away, like the skybox.
Advertisement
If the normal-based reflection map offsetting is supposed to just work, then I have no idea what I'm doing wrong - specifying vertex normals has absolutely no effect whatsoever on the reflection.

Thanks for the link, though.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Quote:Original post by Crispy
If the normal-based reflection map offsetting is supposed to just work, then I have no idea what I'm doing wrong - specifying vertex normals has absolutely no effect whatsoever on the reflection.

Thanks for the link, though.


It seems like what I have said before about texture projections was just plain wrong. This is the result of trying to talk about something I'm totally inexperienced...

Anyway, Crispy, If you didn't changed the code, it is normal that changing the normal vectors has no effect on the texture coordinates. I think that, in your case, the best way to distort the texture coordinates is to use a vertex program.

--------------------------------If you can't understand what I said, it's not you, it's because my english sucks!
Crispy, I'd strongly recommend using a vertex shader. Even on hardware that doesn't support it, it can be done in software by the driver quite efficiently, and it will allow you do to per vertex distortion of the water surface.

BTW, how are you distorting the texture matrix? I wanted to do the same, but have yet to think of a good method for doing so...
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Aight - a vertex program it'll be then. I have a GF2, though, so I have no idea what the performance hit might be, even if done in software. Without having Googled for it, does anyone have link to a simple tutorial on the subject?

Quote:
BTW, how are you distorting the texture matrix? I wanted to do the same, but have yet to think of a good method for doing so...


Simple:

for(int j = 0, i0 = 0, i1 = 1, i2 = ex + 1, i3 = ex; j < ez - 1; j++)  {		  for(int i = 0; i < ex - 1; i++, i0++, i1++, i2++, i3++)    {    if(!texcoords)      {      glMatrixMode(GL_TEXTURE);      glPushMatrix();					        glTranslatef(0, oscmap[i0].y, 0);      }    glBegin(GL_QUADS);      if(texcoords) glTexCoord2f(texcoord[i0].u, texcoord[i0].v);      glVertex3fv(oscmap[i0]);      if(texcoords) glTexCoord2f(texcoord[i1].u, texcoord[i1].v);      glVertex3fv(oscmap[i1]);      if(texcoords) glTexCoord2f(texcoord[i2].u, texcoord[i2].v);      glVertex3fv(oscmap[i2]);      if(texcoords) glTexCoord2f(texcoord[i3].u, texcoord[i3].v);      glVertex3fv(oscmap[i3]);    glEnd();	    if(!texcoords)      glPopMatrix();    }    i0++; i1++; i2++; i3++;			  }


Ignore the indexes - they're optimized to not include any array offset calculation inside the loop. This loop could be optimized a little further still by taking the call to glMatrixMode() out.

Otherwise it's meant to be called for either the diffuse map pass or with texcoords set to true or the reflection pass otherwise.

Note that by making oscmap[n].y (wave height) too large, the individual quads will start to form a shifting mosaic pattern since each four adjacent vertices entail an identical texture matrix shift. This is why a vertex program would indeed be a lot better solution - the only problem being that I've never even seen a bit of shader code before.
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
Sorry, I don't know any good tutorials on vertex programs usage...
I learned them the hard way, reading the OpenGL specification!

Search on google, there should be plenty of code examples and tutorials.

This topic is closed to new replies.

Advertisement