OpenGL - How does texturing affect shadows/lightning?
So the question is: when I switch from ColorPointers to Textures, it seems that the lightning/shadows effects are greatly reduced. Some solution that I have found but doesnt do that much is setting glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR ). Is there anything more I could do to get closer effects to what I would get without textures?
This is how I init my lights/scene:
glClearColor (0.0, 0.0, 0.0, 0.5); # Black Background
glClearDepth (1.0); # Depth Buffer Setup
glDepthFunc(GL_LEQUAL) # The Type Of Depth Testing
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH); # Select Smooth Shading
glColor4f(0.90, 6.0, 6.0, 1.0)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
#glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0)
glEnable(GL_COLOR_MATERIAL);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [0.7, 0.7, 0.7, 0])
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.8, 0.8, 0.7, 0])
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [0.8, 0.8, 0.8, 0])
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 30)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR );
glLightfv(GL_LIGHT0, GL_POSITION, [0.85, 0.8, 0.75, 0])
glLightfv(GL_LIGHT0, GL_AMBIENT, [0.8, 0.8, 0.7, 0])
glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.7, 0.7, 0.7, 0])
glLightfv(GL_LIGHT0, GL_SPECULAR, [0.8, 0.8, 0.8, 0])
And for the actual drawing.
glEnableClientState(GL_VERTEX_ARRAY)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferVertices)
glVertexPointer(3, GL_FLOAT, 0, None)
glEnableClientState(GL_NORMAL_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferNormals)
glNormalPointer(GL_FLOAT, 0, None)
#glEnableClientState(GL_COLOR_ARRAY)
#glColorPointer(3, GL_FLOAT, 0, None)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glBindBufferARB(GL_ARRAY_BUFFER_ARB, self.bufferTextureIndex)
glTexCoordPointer(1, GL_FLOAT, 0, None);
glBindTexture(GL_TEXTURE_1D, self.texture)
glEnable(GL_TEXTURE_1D)
glDrawElements(GL_TRIANGLES, len(self.triangles) , GL_UNSIGNED_SHORT, ADT.voidDataPointer(self.triangles))
For the colors of each vertex I was using the normals as dummy colors, since that was just a step in the way of integrating textures. The texture is a self generated one , basically the values are from:
def getColor(self, value):
if value < 0:
return [1, 0, 0]
if value >=0开发者_如何学Go and value < 0.8:
return [1, 0.5, 0]
if value >= 0.8 and value < 1:
return [1, 1, 0]
if value >=1 and value < 1.2:
return [0.5, 1, 0]
if value >=1.2 and value < 1.4:
return [0, 1, 0]
if value >= 1.4 and value < 1.6:
return [0, 1, 0.5]
if value >= 1.6 and value < 1.8:
return [0, 1, 1]
if value >= 1.8 and value < 2:
return [0, 0.5, 1]
if value >= 2:
return [0, 0, 1]
The actual creation:
glBindTexture(GL_TEXTURE_1D, self.texture)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP)
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 190, 0, GL_RGB , GL_FLOAT, textureArray)
Regards, Bogdan
EDIT
Ok I got close to the effect I wanted but it was purely by trying different combinations of glColor4f with materials and ligths in the following part.
glColor4f(2.2, 2.2, 2.2, 1.0)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0)
glEnable(GL_COLOR_MATERIAL)
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [0.6, 0.6, 0.6, 1.0])
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, [0.6, 0.6, 0.6, 1.0])
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, [0.8, 0.8, 0.8, 1.0])
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, 30)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR )
glLightfv(GL_LIGHT0, GL_POSITION, [0, -10, -400, 0])
glLightfv(GL_LIGHT0, GL_AMBIENT, [0, 0, 0, 0])
glLightfv(GL_LIGHT0, GL_DIFFUSE, [0.7, 0.7, 0.7, 0])
glLightfv(GL_LIGHT0, GL_SPECULAR, [0.8, 0.8, 0.8, 0])
Is there some kind of formula of how all of these (glColor4f + Materials + Lights + Texture) influence the final color/shadow/shininess effects ?
If you are using your shader in your other question here OpenGL shaders questions
then the answer is that you are not handling lighting in your shader which disables the fixed function lighting routines when you enable your shader.
If I am jumping the gun on this conclusion and you are seeing thing without the shader, I apologize.
Edit
Yes, there is a formula. It is covered extensively in the orange book and briefly in the red book http://glprogramming.com/red/chapter05.html. Older version are freely available of the red, book.
Basically it depends on the texture of the object, if there is a color and how it is applied, modulated, added, multiplied. The material and how it reflects lights of different colors, plus any emisions the material makes ( think glow in the dark sticker material for emission ), and the color of the light and the angle the light is striking the face. "Shiny" comes from specular reflection of light.
精彩评论