Custom Shadow Contrast

Started by
3 comments, last by Geometrian 15 years, 10 months ago
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

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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)

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement