GLSL matrix question
Hi,
Im rendering shadow map with FBOs on my engine, in the first pass i save level and models to a texture in FBOs.
I works correctly.
In the second pass i compare the texture depth information with the camera depth information and it works, but only for the level not for the models, because every time i render the model i use:
glPushMatrix
glTranslatef
glRotatef
rendermodel
glPopMatrix
So the matrix that i cought on glsl isnt the correct, i tought on transforming (translating and rotating) every vertex model before render it without using opengl functions, but it would be very expensive.
I should convert my new vertex (after applying opengl functions) inside glsl vertex, would be enough if i multiply the new vertex by the previous modelview matrix??
Im quite lost.
Thanks in advance.
varying vec4 lightproj;varying vec4 lightpos;//uniform mat4 LPM;uniform vec3 lpos;void main(void){ gl_TexCoord[0] = gl_MultiTexCoord0; gl_TexCoord[1] = gl_MultiTexCoord1; //lightproj = LPM * gl_Vertex; lightproj = gl_TextureMatrix[2] * gl_Vertex; lightpos = gl_ModelViewMatrix * gl_Vertex; //light is in 0,0,0 gl_Position = ftransform();}
I supose that the problem is calculating lightpos.
I must compare all the vertex's depth from the camera point of view to the depth from LPOV stored in the FBOs texture.
This work only for the level because i render the level from the CPOV, but after rendering the level i do glTranslatef and glRotatef and when it calls the vertex shader this vertex depth is not corresponding to CPOV so the depth comparision isnt working.
And dont know if i store modelview matrix before rendering the level and i pass it to the vertex shader will work?
lightpos = CPOV * gl_Vertex; //light is in 0,0,0
Thanks in advance
I try to save CPOV before render the level
matriz CPOV;
glGetFloatv(GL_MODELVIEW_MATRIX, CPOV.m);
And passing it to the vertex shader
glUniformMatrix4fvARB(glGetUniformLocationARB(glsl_get_program(GLSL_VARIANCE_SHADOW_MAP), "CPOV"), 1, GL_FALSE, CPOV.m);
with this the level isnt working neither ?¿?¿
If i dont make any translation and rotations, this isnt the same?
lightpos = gl_ModelViewMatrix * gl_Vertex;
lightpos = CPOV * gl_Vertex;
matriz CPOV;
glGetFloatv(GL_MODELVIEW_MATRIX, CPOV.m);
And passing it to the vertex shader
glUniformMatrix4fvARB(glGetUniformLocationARB(glsl_get_program(GLSL_VARIANCE_SHADOW_MAP), "CPOV"), 1, GL_FALSE, CPOV.m);
with this the level isnt working neither ?¿?¿
If i dont make any translation and rotations, this isnt the same?
lightpos = gl_ModelViewMatrix * gl_Vertex;
lightpos = CPOV * gl_Vertex;
I decide to do it manually instead GLSL.
But now im getting new problems
When i wanted to render a model i did this.
//...before i set the camglPushMatrix();glTranslatef(modelpos.x, modelpos.y, modelpos.z);glRotatef(angle, 0, 1, 0);RenderModel();glPopMatrix();
Now i do this:
//...before i set the cam//for each model vertex...//coverting angle to radiansangle *= PI_RAD_ANGLE;float xsave, ysave, zsave;xsave = tempvertex[index].x;zsave = tempvertex[index].z;//rotaing around 0,0,0??tempvertex[index].x = xsave * cos(angle) - zsave * sin(angle);tempvertex[index].z = xsave * sin(angle) + zsave * cos(angle);tempvertex[index].x += modelpos.x;tempvertex[index].y += modelpos.y;tempvertex[index].z += modelpos.z;
Inst the same? the model is on the place that should be, but the angle is not the correct.
Help please!!
Thanks in advance.
WRT your first reply
lightproj = gl_TextureMatrix[2] * gl_Vertex;
i assume lightproj is the shadowmaps projection matrix?
now in that line youre not taking into consideration the glTranslatef, glRotatef stuff
ie u will need to multiply that by the mv or the projmv matrix as well
lightproj = gl_TextureMatrix[2] * gl_Vertex;
i assume lightproj is the shadowmaps projection matrix?
now in that line youre not taking into consideration the glTranslatef, glRotatef stuff
ie u will need to multiply that by the mv or the projmv matrix as well
You say this:
lightproj = gl_TextureMatrix[2] * gl_ModelViewMatrix * gl_Vertex; ????
Im no multipliyng the lightMatrix by the inverseofthe currente modelview matrix, should i?
I tought that gl_Vertex (alone) inside GLSL was a vertex free of matrix manipulations. So i want this vertex to be converted to light point of view to do after
vec3 pos = lightproj.xyz / lightproj.w;
vec4 shadmap = texture2D(shadowMap,pos.xy);
because the shadowmap is stored in LPOV.
Could you explain me your answer in more detail?
Thanks for your help.
lightproj = gl_TextureMatrix[2] * gl_ModelViewMatrix * gl_Vertex; ????
Im no multipliyng the lightMatrix by the inverseofthe currente modelview matrix, should i?
I tought that gl_Vertex (alone) inside GLSL was a vertex free of matrix manipulations. So i want this vertex to be converted to light point of view to do after
vec3 pos = lightproj.xyz / lightproj.w;
vec4 shadmap = texture2D(shadowMap,pos.xy);
because the shadowmap is stored in LPOV.
Could you explain me your answer in more detail?
Thanks for your help.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement