我正在編寫GLSL程序,作爲運行在閉源3D應用程序Maya內的插件的一部分。 Maya使用固定功能管道來定義它的燈光,所以我的程序必須使用兼容性配置文件從gl_LightSource
陣列中獲取它的光信息。我的燈光評估工作正常(thanks Nicol Bolas)除了一件事,我不知道如何確定陣列中的特定燈是啓用還是禁用。以下是我迄今爲止:檢測glsl兼容性配置文件中是否啓用了gl_LightSource
#version 410 compatibility
vec3 incidentLight (in gl_LightSourceParameters light, in vec3 position)
{
if (light.position.w == 0) {
return normalize (-light.position.xyz);
} else {
vec3 offset = position - light.position.xyz;
float distance = length (offset);
vec3 direction = normalize (offset);
float intensity;
if (light.spotCutoff <= 90.) {
float spotCos = dot (direction, normalize (light.spotDirection));
intensity = pow (spotCos, light.spotExponent) *
step (light.spotCosCutoff, spotCos);
} else {
intensity = 1.;
}
intensity /= light.constantAttenuation +
light.linearAttenuation * distance +
light.quadraticAttenuation * distance * distance;
return intensity * direction;
}
}
void main()
{
for (int i = 0; i < gl_MaxLights; ++i) {
if (/* ??? gl_LightSource[i] is enabled ??? */ 1) {
vec3 incident = incidentLight (gl_LightSource[i], position);
<snip>
}
}
<snip>
}
當瑪雅使新的燈我的程序工作正常,但是當瑪雅禁用先前啓用的光,想必使用glDisable (GL_LIGHTi)
,它的參數是不是gl_LightSource
陣列和gl_MaxLights
在重置明顯不會改變,所以我的程序繼續在它的着色計算中使用那些陳舊的燈光信息。儘管我沒有在上面顯示它,但光線顏色(例如gl_LightSource[i].diffuse
)在禁用後也會繼續顯示非零值。
Maya使用固定功能管線(無GLSL)繪製所有其他幾何圖形,並且這些對象正確地忽略禁用的燈光,我怎樣才能模仿GLSL中的這種行爲?
是的,在C++中,我可以測試所有燈的啓用狀態,並將其作爲單獨的統一信息傳遞或以某種方式重置它們的值。在規範中多麼奇怪的監督... – atb 2012-07-06 18:26:51