Textures in Shadow Mapping - pass

Started by
10 comments, last by Neutrinohunter 16 years, 2 months ago
hello, i was using this tutorial to implement shadow mapping. http://www.paulsprojects.net/tutorials/smt/smt.html but in the 3rd pass where the shadow-comparison takes place, you need to have the shadow-map-texture bound at all times, so you cant use any other textures in the regular scene anymore. how can i still have textures in the 3rd and final pass? thanks! also, what is this biasMatrix for, that Paul uses? thanks!
Advertisement
Bind the shadow map texture to a different texture unit.

glActiveTexture(GL_TEXTURE0);    // Use this for regular textureglBindTexture(...);glActiveTexture(GL_TEXTURE1);glBindTexture(...);


Using this means that all things related to the shadow map will have to be to the second texture unit. So when you manipulate the GL_TEXTURE matrix, make sure the current unit is GL_TEXTURE1.
Since I followed this tutorial and have today succeeded in extending it, I will give my two cents on what I know here.

I am still having the problem you face despite binding to a different texture unit (I'm actually using an FBO).

The biasmatrix is used to get the values of the texture coordinates in the range 0, 1.

And what he is doing is the equivalent of
glMatrixMode(GL_TEXTURE);
glTranslatef(0.5,0.5,0.5);
glScalef(0.5, 0.5f, 0.5);
glMultMatrixf(lightProjectionMatrix);
glMultMatrixf(lightModelViewMatrix);

As for the texture unit, biggoron is correct. Its 3 in the morning here, but this is the next thing I'm going to try so when I get it working I'll post the howto :)

Neutrinohunter
thank you guys very very much!

Neutrinohunter, yes please keep me updated on any news you got with your shadow mapping.
there is still something not working correctly in my shadow mapping test:

here is a screenshot:


as you can see there are strange moire artifacts on the non-shadowed areas.

what could be wrong? thanks!

also, what i do not really understand so far, what do these openGL commands actually do?

glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.getRow(3));

thanks a lot!
They setup the projective texture coordinates for the shadow mapping. The problem is due to biasing. Try to add a

glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.1f, 4.0f);

Before you render the shadow map, then
glDisable(GL_POLYGON_OFFSET_FILL) immediately afterwards and it should solve the problem.

Or you could change the values of the matrix at 12,13 and 14 to a bit larger numbers, I think that should also work.I prefer the first, its easier and works better IMO.

Just out of interest did you solve the two texture units problem? I was working on it last night and couldn't get it to work with my FBO.

Neutrinohunter
thanks! yes the polygon_offset_trick worked! but why didnt paul need this trick?

i did yet not try multitexturing, but i will now and post here if i manage it or if i run into any problems!

thanks again!
To be fair, the Shadow Mapping tutorial could well be ten years old (not sure exactly) but it doesn't use many of the newest features (FBO, Support for larger textures than 512 etc) and I'm not sure how old the polygon offset function is,might be 1.4 or 2.0 specification.

Only Paul can tell you why :) In his demo it doesn't seem like he needs it but I'm sure he put some bias in, in another way I'll have a look when I'm at my home computer.

I couldn't get it to work, but that might be the FBO being a problem.
I was doing something like

glActiveTexture(GL_TEXTURE1);

and then swapping to glActiveTexture(GL_TEXTURE0) when needing to use a texture for a model. Maybe its something I'm doing wrong.

Neutrinohunter
thanks!

actually i already had a shadowmapping algorithm using FBOs running before, but since my casual game targets low end hardware, i want to go back to ARB_shadow, since it is more widely available.


ok i am now trying to get it to work with multitexturing, so i am calling glActiveTexture(GL_TEXTURE0) always before i am binding a normal texture and glActiveTexture(GL_TEXTURE1) always before i bind the shadowmap-texture. is there something more i need to do?


this is what it looks like now:
Yes, I'm doing something similar and finding difficulties. At the moment my app looks like so.



I'll have to have a think while I'm at work tomorrow what could be causing the problem. I am getting a GL invalid enumerant error which I guess could b causing the problem.

Neutrinohunter

This topic is closed to new replies.

Advertisement