Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

Custom Shadow Contrast

This topic is 3795 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
Advertisement
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
Nope. That's how one does it in Python.
I think I figured my problem out--I'm not capitalizing on the depth buffer effectively. The near plane was something like 0.1 and the far, 1000, but the objects were only like 10 apart.
G

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!