Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
704 views
in Technique[技术] by (71.8m points)

opengl - No spot of light on cube

I have made three sources of light and one cube

I don't see a spot of light on faces. It's look like entire polygon is lit. And i don't know is this posible and cube need more polygons or mayby light settings are bad. Settings i use.

glShadeModel(GL_SMOOTH);
glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 150.0f);
glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 15.0f);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Remember that the fixed-function lighting equation is only evaluated at the vertices of a triangle and interpolated across the fragment. No per-pixel lighting unless you get creative with GL_DOT3_RGB textures.

Therefore if you want to see a nice spotlight highlight on your cube you'll need to subdivide your cube faces so that they're closer to pixel-sized:

Subdivision Example

EDIT: Also remember to pass in reasonable per-vertex normals. Lighting doesn't work too well without them :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...