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)
Custom Shadow Contrast
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:
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:
Thanks,
G
I recommend that you create the texture like this
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.
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.
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)
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement