Jump to content
  • Advertisement
Sign in to follow this  

OpenGL GLSL projective shadows Solved :) stupid mistake :(

This topic is 3182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post

Link to post
Share on other sites
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]

Share this post

Link to post
Share on other sites
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]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!