Jump to content
  • Advertisement
Sign in to follow this  

GLSL and Materials

This topic is 4681 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

I'm working through some basic tutorials on shaders, and right now I'm modifying my cel shader to use the object's material to determine the color. I'm rendering a .OBJ model, and when I go to change the material, the material doesn't change. That is, my entire object is one color. It's always the color of the first material set. When I turn off the shader before changing materials and turn it back on afterward, the model displays as expected. However, on my card, this gives a huge performance hit (ATI Radeon Mobility X300). Does GLSL intercept calls to glMaterialfv or something? I couldn't imagine it would, but perhaps my understanding of shaders is a bit shoddy. Here's my fragment shader:
varying vec3 normal;

void main()
	vec3 n = normalize(normal);
	float intensity = dot(vec3(gl_LightSource[0].position),n);
	if (intensity > 0.95) intensity = 1.0;
	else if (intensity > 0.75) intensity = 0.75;
	else if (intensity > 0.5) intensity = 0.5;
	else if (intensity > 0.25) intensity = 0.25;
	else intensity = 0.10;

	gl_FragColor = gl_FrontMaterial.diffuse * intensity;

And the relevant section of code:
for (int faceGroup = 0; faceGroup < mFaceGroups.size(); faceGroup++)

			glMaterialfv(GL_FRONT, GL_AMBIENT, mMaterials[mFaceGroups[faceGroup].materialID].ambient);
			glMaterialfv(GL_FRONT, GL_DIFFUSE, mMaterials[mFaceGroups[faceGroup].materialID].diffuse);
			glMaterialfv(GL_FRONT, GL_SPECULAR, mMaterials[mFaceGroups[faceGroup].materialID].specular);


			for (int face = 0; face < mFaceGroups[faceGroup].faces.size(); face++)
				Face f = mFaceGroups[faceGroup].faces[face];


Cheers, --Brian

Share this post

Link to post
Share on other sites
changinf materials with glMaterialfv(GL_FRONT, GL_AMBIENT,
is very slow , the faster method is to use GL_COLOR_MATERIAL (ch3ck the spec)
though since youre glsl i wouldnt use the fixed pipeline material stuff at all
but instead either supply the material color data as either uniforms or attributes

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!