Sign in to follow this  
Geometrian

OpenGL Materials in Shaders

Recommended Posts

Hello, I'm making a program, and I'm getting a strange bug when rendering a material with this shader (http://www.lighthouse3d.com/opengl/glsl/index.php?pointlight). It runs, but strangely, the ambient and diffuse aspects of the colors aren't being accessed correctly. I set the material every frame, like so:
#This should make a gold color with a weak specular highlight.
glMaterialfv(GL_FRONT,GL_AMBIENT,(0.2,0.2,0.2,1.0))
glMaterialfv(GL_FRONT,GL_DIFFUSE,(0.8,0.8,0.4,1.0))
glMaterialfv(GL_FRONT,GL_SPECULAR,(1,1,1,1))
glMaterialfv(GL_FRONT,GL_EMISSION,(0,0,0,1))
glMaterialfv(GL_FRONT,GL_SHININESS,128)
If I set the material and then use the shader with only specular, I see the specular highlights using the material parameters rendered correctly, and nothing else. This is the expected behavior. However, if I set the material and then use the shader with only ambient and/or only diffuse, the ambient and diffuse material properties aren't used--instead, both are (1,1,1,1). In shader jargon, I can change gl_FrontMaterial.specular and gl_FrontMaterial.shininess, but I can't change gl_FrontMaterial.ambient or gl_FrontMaterial.diffuse. This is a very strange error, and I want to know how to fix it. Thank you, -Geometrian

Share this post


Link to post
Share on other sites
In a very simple example, when using this shader:
//vertex shader
void main() {
gl_Position = ftransform();
}
//fragment shader
void main() {
gl_FragColor = gl_FrontMaterial.specular;
}
I get a red object. But when using this shader:
//vertex shader
void main() {
gl_Position = ftransform();
}
//fragment shader
void main() {
gl_FragColor = gl_FrontMaterial.ambient;
}
I get a white object. I set the materials for this like this
glMaterialfv(GL_FRONT,GL_SPECULAR,(1,0,0,1))
glMaterialfv(GL_FRONT,GL_AMBIENT,(1,0,0,1))


[EDIT: more specific problem continues here: http://www.gamedev.net/community/forums/topic.asp?topic_id=512598]

[Edited by - Geometrian on October 25, 2008 1:31:46 AM]

Share this post


Link to post
Share on other sites

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