GLSL projective shadows Solved :) stupid mistake :(

Started by
2 comments, last by SaTANO 14 years, 3 months ago
Hi everybody. I am new to OpenGL and I am also new here and this is my first post. I am from Slovakia and my English is not that great, but I hope you will understand what I am writing (sorry for mistakes) I have got a problem with shadow mapping implementation using GLSL. Everything works fine using glTexGeni with GL_EYE_LINEAR. I generate my shadow map, transform it and bind to texture. Problem is multitexturing because I have nvidia card which supports only 4 active texture units (also another pass for rendering shadowed area - on ATI I used GL_TEXTURE_COMPARE_FAIL_VALUE_ARB ) and I want to use diffuse map and normal map on model so only 2 remain for shadows and of course I want to use more shadows for some scenes. So my way leads to GLSL. I read a lot of tutorials and forums but I did not find good explanation for this. So far I was able to texture objects using GLSL and combine it with another textures. My real problem is projective shadow texture. In my current code I am using: glTexGenfv(GL_S, GL_EYE_PLANE, &(textureMatrix[0])); glTexGenfv(GL_T, GL_EYE_PLANE, &(textureMatrix[4])); glTexGenfv(GL_R, GL_EYE_PLANE, &(textureMatrix[8])); glTexGenfv(GL_Q, GL_EYE_PLANE, &(textureMatrix[12])); and as you can see my textureMatrix is matrix generated by translating->multiplying->transposing etc model view and projection matrix of my active light. Before I render my scene I activate texture unit, use glTexGenfv for shadow texture and disable mapping(I will enable it later in rendering) for active lights and everything works great. If I try to send this texture unit to my shader, my texture projection is not working well. What I need to know is how to perform this texgen operation for my projective texture for GLSL, if there is any equivalent for this function or some matrix operations. I already found some tuts for EYE_LINEAR mapping but I was unable to successfully implement it. I will really appreciate any hint. Thanks for replies Stanley [Edited by - SaTANO on January 8, 2010 6:06:25 PM]
Advertisement
GL_EYE_PLANE means that each plane equation, in other words, each plane needs to be transformed to eye space.
Then you need to transform the vertex to eye space.
Then it is basically a dot product between the vertex and plane.
http://www.opengl.org/wiki/Mathematics_of_glTexGen

Any questions?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Thanks V-man
I was out for a while (NEW YEAR and some semestral exams) and after I read the post I find out that there must be problem somewhere else and tried different approach. For many people works simple formula bias*lightProjection*lightModelView. I think the problem is somewhere in my matrixe. I am changing modelview matrix every time i am rendering object (cameraModelView translated rotated scaled to rendered object position). In Fabien Sanglard tutorial of shadow mapping I saw that when he is translating modelview matrix to object he is also translating texture matrix with same values. So first problem was here

As you said I need to transform each vertex from camera space to eye space. So its matrix only operations and I think this should works but its not

load bias=> multiply light projection => multiply light modelview => Scale Translate Rotate

In shader I should be able to use

gl_TextureMatrix[2] * gl_Vertex; // I stored light matrix to texture2

What I think is correct. I tried to project shadow map from camera to see if my shader works correctly so I used gl_ModelViewProjectionMatrix * gl_Vertex and switch my camera to position of light and it works.
There must be problem in my matrix.

I would like to know if there is some additional operation for shadowtexture matrix.

[Edited by - SaTANO on January 8, 2010 6:11:31 PM]
Punch me
Problem solved
I was making 3 different algorithms to calculate matrix and every one was right
After 2 weeks of researching, reading books/forums/tutorials, spamming my friend I found problem
Guess what
I was sending matrix to my function and store it (I used only pointer) and do matrix magic on them (for texgen operation). But what I forget is after I make this, I changed my matrix so I was multiplying already multiplied matrix. It was really strange when I send same matrix to shader but I have got different results so I decide to print this matrix and saw that "What Am I stupid?"
And this stupid thing cost me 2 weeks

So it works like charm

[Edited by - SaTANO on January 8, 2010 6:59:13 PM]

This topic is closed to new replies.

Advertisement