Sign in to follow this  

Custom Shadow Contrast

This topic is 3491 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 program in Python. Recently, I've been trying to get shadow mapping to work. There are few tutorials for this--even in C--and none in Python. After searching for a good long time, and finding partial solutions, I've decided to just make my own--I already know the theory. That's exactly what I did this evening. It works, but there is a small problem. The shadowmap texture has too low contrast. The following modified image explains this: My Shadowmapping Screenshot--Modified As you can see, I've gotten quite far. The original image, however, looked white where the picture is grey. In actuality, it was (254,254,254). I've used a flood fill in a paint program to get what you see here. So, my question: How can the texture be changed to have a higher contrast? Here's where I create the texture from the depth buffer:
ShadowMapTexture = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, ShadowMapTexture)
    glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT,0,0,ShadowMapSize,ShadowMapSize,0)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
Thanks, G

Share this post


Link to post
Share on other sites
I recommend that you create the texture like this


ShadowMapTexture = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, ShadowMapTexture)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_DEPTH_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE)
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, ShadowMapSize, ShadowMapSize, GL_DEPTH_COMPONENT, NULL)



The last parameter for glTexImage2D tells it to not initialize any texels.
You will update the texels in your render loop later.

This line is important
glTexParameterf(GL_TEXTURE_2D, GL_DEPTH_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE)
because the default is GL_NONE.
It's also important to setup your render stage properly : the ambient, diffuse, specular and the light properties. You might want to show your fragment shader as well.

Share this post


Link to post
Share on other sites
I'm afraid that didn't work:
ShadowMapTexture = glGenTextures(1)

glBindTexture(GL_TEXTURE_2D, ShadowMapTexture)

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)

#This line doesn't work. The docs don't seem to have GL_DEPTH_COMPARE_MODE:
#glTexParameterf(GL_TEXTURE_2D,GL_DEPTH_COMPARE_MODE,GL_COMPARE_R_TO_TEXTURE)

#This didn't work either:
#glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT24,ShadowMapSize,ShadowMapSize,GL_DEPTH_COMPONENT,NULL)
#I changed it as follows to work:
glTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT24,ShadowMapSize,ShadowMapSize,0,GL_DEPTH_COMPONENT,GL_UNSIGNED_BYTE,None)

Share this post


Link to post
Share on other sites
Maybe there is some thing you need to include. I don't really know Python. I just used it for scripting for a brief moment of time.

Even this is not standard
ShadowMapTexture = glGenTextures(1)

The function should actually be something like
== C and C++
glGenTextures(1, &ShadowMapTexture);

== Pascal
glGenTextures(1, @ShadowMapTexture);

== Java
GL.glGenTextures(1, &ShadowMapTexture);

== VB
glGenTextures(1, ShadowMapTexture);

Can't they do something like that in Python? Because they are off the standard.

Share this post


Link to post
Share on other sites

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