PDA

View Full Version : Cubemap reflections



M/\dm/\n
01-28-2004, 11:37 PM
I have one small problem (math I guess)...
If I'm rendering 1st person shooter, I have a weapon or smthn like that in front of me...



gluLookAt(x,y,z,lx,ly,lz,ux,uy,uz);
renderworld();
glPushMatrix();
glDepthRange(0,0.01);
glLoadIdentity();
DrawModel1stpass();//Cubemap on Texgen (normal map) on, color 1,1,1,1
glDepthFunc(GL_EQUAL);
Drawmodel2ndpass();//Cubemp off, blend on, color 1,1,1,0.8, tex2d on
glDepthFunc(GL_LEQUAL);
glDepthRange(0,1);
glPopMatrix();


The problem is that even when I look around, (gluLookAt) reflections stays static, what can I do about that??

Relic
01-29-2004, 12:23 AM
Change the texture matrix on the cubemap texture unit to follow the rotation of your player.

marcus256
01-29-2004, 04:39 AM
...in other words, the texture matrix should be the inverse of the rotational part of the modelview matrix. I did this yesterday, and the delphi code looks like this:



{ Calculate and load environment map texture transformation matrix }
EnvMapMatrix[0,0]:=AModelView[0,0];
EnvMapMatrix[0,1]:=AModelView[1,0];
EnvMapMatrix[0,2]:=AModelView[2,0];
EnvMapMatrix[0,3]:=0.0;
EnvMapMatrix[1,0]:=AModelView[0,1];
EnvMapMatrix[1,1]:=AModelView[1,1];
EnvMapMatrix[1,2]:=AModelView[2,1];
EnvMapMatrix[1,3]:=0.0;
EnvMapMatrix[2,0]:=AModelView[0,2];
EnvMapMatrix[2,1]:=AModelView[1,2];
EnvMapMatrix[2,2]:=AModelView[2,2];
EnvMapMatrix[2,3]:=0.0;
EnvMapMatrix[3,0]:=0.0;
EnvMapMatrix[3,1]:=0.0;
EnvMapMatrix[3,2]:=0.0;
EnvMapMatrix[3,3]:=1.0;
glMatrixMode(GL_TEXTURE);
glLoadMatrixd(@EnvMapMatrix);
glMatrixMode(GL_MODELVIEW);

...in this case I assume that the modelview matrix is orthonormalized, which should be the case for you too.

M/\dm/\n
01-29-2004, 09:17 AM
Yes, thanks, I solved this problem.
But ther's another one. I must calculate custom lightning on the same weapon model, so it comes that I must mul all light, eye, normal vectors, with inverse transpose gluLookAt matrix?

Relic
01-30-2004, 06:20 AM
If it should be high quality, maybe.
Else do modelspace lighting (no weather http://www.opengl.org/discussion_boards/ubb/wink.gif) by transforming the light into the model coordinate system. Works best with directional light and infinite viewer.