Jump to content
  • Advertisement
Sign in to follow this  
Dexus

How to render shiny black balls?

This topic is 4814 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've found a problem when trying to render pool balls with a black texture such as the 8 ball. You can see below how my 8 ball appears. The white circle part is reflecting the white specular highlight from my specular lighting but the black part is entirely black. Also when I don't use a texture but simply set the ball's colour to black then the specular highlights do appear. Does anyone know what settings I can use the have the highlights appear on a black texture?

Share this post


Link to post
Share on other sites
Advertisement
Try using glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR). This is an OpenGL 1.2 feature, so if you're using Windows you'll need to use one of the extension headers, or just define GL_SEPARATE_SPECULAR_COLOR to be 0x81FA.

Btw, what's happening is OpenGL is calculating the ambient, diffuse, and specular lighting components, adding them, and the modulating them with the texture color. In the areas where the texture is black, the modulation will always produce a value of zero.

By enabling separate specular color, OpenGL defers the addition of the specular contribution until after texture environment application.

Share this post


Link to post
Share on other sites
Thanks Mr Rhino, that code worked well it looks good now. I understand why the black appears black and I understand how material properties affect how light is reflected and absorbed. Am I right in guessing that this GL_SEPARATE_SPECULAR_COLOR property ignores the colour of the texture and instead applies a white specular highlight to the material whatever its colour?

Share this post


Link to post
Share on other sites
Quote:
Original post by Dexus
Am I right in guessing that this GL_SEPARATE_SPECULAR_COLOR property ignores the colour of the texture and instead applies a white specular highlight to the material whatever its colour?
When GL_LIGHT_MODEL_COLOR_CONTROL is set to GL_SINGLE_COLOR (the default), what happens is that all the lighting calculations are combined, and then multiplied with the texture color (with a combine mode of GL_MODULATE).

When GL_LIGHT_MODEL_COLOR_CONTROL is set to GL_SEPARATE_SPECULAR_COLOR, just the ambient and diffuse contributions from lighting are multiplied with texturing, and then the specular contribution is added to that result.

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!