Sign in to follow this  

Textures in Shadow Mapping - pass

This topic is 3588 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

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!

Share this post


Link to post
Share on other sites
Bind the shadow map texture to a different texture unit.

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

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.

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
hi again!
i still had no success with getting texturing to work in the last pass.

i think i am using glActiveTexture not correctly. is there anything else that must be set up for multitexturing? like glEnable(GL_MULTITEXTURE)?

i did yet not check for glerrors, but i will do so asap, and then check back here.

thanks!

Share this post


Link to post
Share on other sites
I haven't set this up properly but you may want to check out the
Parallel Split Shadow Mapping Demo by Jeroen Put at:
http://hax.fi/asko/PSSM.html#OpenGL

This uses two texture units in the Octree.cpp class file. You might be able to reverse engineer what you need to do from that. Plus, the demo is pretty amazing.

Neutrinohunter

Share this post


Link to post
Share on other sites

This topic is 3588 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this