I have a Spotlight source in OpenGL, pointing towards a texture mapped sphere.
我在OpenGL中有一个Spotlight源,指向纹理映射的球体。
I rotate the lightsource with the sphere, such that if I rotate the sphere to the 'non-light' side, that side should be dark.
我用球体旋转光源,这样如果我将球体旋转到“非光”侧,那边应该是暗的。
The odd part is, the spotlight seems to be shining through my sphere (it's a solid, no gaps between triangles. The light seems to be 'leaking' through to the other side.
奇怪的是,聚光灯似乎在我的球体上闪耀(它是一个坚固的,三角形之间没有间隙。光似乎是'泄漏'到另一边。
Any thoughts on why this is happening?
有关为什么会发生这种情况的任何想法?
Screenshots:
Front view, low light to emphasize the problem
前视图,低光强调问题
Back view, notice the round area that is 'shining through'
后视图,请注意“透过”的圆形区域
2 个解决方案
#1
Its really hard to tell from the images, but:
它很难从图像中分辨出来,但是:
Check if GL_LIGHT_MODEL_TWO_SIDE is being set (two sided lighting), but more importantly have a look at the normals of the sphere you are rendering.
检查是否正在设置GL_LIGHT_MODEL_TWO_SIDE(双面照明),但更重要的是要查看要渲染的球体的法线。
Edit: Also - change the background colour to something lighter. Oh and make sure you aren't rendering with alpha blending turned on (maybe its a polygon sorting issue).
编辑:另外 - 将背景颜色更改为更轻的颜色。哦,并确保你没有打开alpha混合渲染(也许它是一个多边形排序问题)。
#2
OK, I'm a nob - I was specifying my normals, but not calling glEnableClientState(GL_NORMAL_ARRAY). Hence all normals were facing one direction (I think that's the default, no?)
好的,我是一个nob - 我正在指定我的法线,但没有调用glEnableClientState(GL_NORMAL_ARRAY)。因此所有法线都面向一个方向(我认为这是默认的,不是吗?)
Anyway - a lesson learned - always go back over the basics.
无论如何 - 吸取的教训 - 总是回顾基础知识。
#1
Its really hard to tell from the images, but:
它很难从图像中分辨出来,但是:
Check if GL_LIGHT_MODEL_TWO_SIDE is being set (two sided lighting), but more importantly have a look at the normals of the sphere you are rendering.
检查是否正在设置GL_LIGHT_MODEL_TWO_SIDE(双面照明),但更重要的是要查看要渲染的球体的法线。
Edit: Also - change the background colour to something lighter. Oh and make sure you aren't rendering with alpha blending turned on (maybe its a polygon sorting issue).
编辑:另外 - 将背景颜色更改为更轻的颜色。哦,并确保你没有打开alpha混合渲染(也许它是一个多边形排序问题)。
#2
OK, I'm a nob - I was specifying my normals, but not calling glEnableClientState(GL_NORMAL_ARRAY). Hence all normals were facing one direction (I think that's the default, no?)
好的,我是一个nob - 我正在指定我的法线,但没有调用glEnableClientState(GL_NORMAL_ARRAY)。因此所有法线都面向一个方向(我认为这是默认的,不是吗?)
Anyway - a lesson learned - always go back over the basics.
无论如何 - 吸取的教训 - 总是回顾基础知识。