1

My scene is quite simple that I have two spheres placed close to each other. I have one point light in the scene and set the position of it to be inside of one of the two spheres. However the other sphere can still get the light from that point light. What I want is the light is occluded by the sphere.

My context is the followings:

glShadeModel(GL_SMOOTH);

glEnable(GL_DEPTH_TEST);
glDepthFunc( GL_LEQUAL );
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

glEnable(GL_MULTISAMPLE);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_LIGHTING);
// Light's color
GLfloat ambientColor[] = { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat diffuseColor[] = { 1.0f, 0.0f, 1.0, 1.0f };
GLfloat lightPosition[] = {0, 0, 0, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientColor);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseColor);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glEnable(GL_LIGHT0);

Do I miss something?

4

1 回答 1

5

当光线被表面和光线之间的插入物体阻挡时,这称为阴影。固定功能的 OpenGL 光照系统不做阴影。OpenGL 只是一个三角形渲染器;它不知道物体、场景或任何东西。任何灯光的基本假设是灯光和三角形之间没有遮挡表面。

如果你想要阴影,那么你将不得不手动实现各种阴影技术之一。

于 2013-06-04T11:06:16.657 回答