mrdoob/three.js — Issue #1292: Shaders with multiple lights issue in 
Author: MiiBond
Created: 2012-02-09 21:20:19+00:00
State: open

This morning, I let Firefox update itself to version 10.0 and, since then, I've been having trouble with my fragment shaders that support multiple lights of the same type (through the MAX_DIR_LIGHTS define). This problem is happening with the ShaderUtils.lib["normal"] shader as well.

If I have, for example, 2 directional lights, the diffuse and specular components end up black (somehow, the "normal" vector ends up as (0,0,0) inside the "for" loop for the directional lights even though it's never assigned to). With only one light of any type, the scene renders fine.

After debugging this, it seems that the issue has something to do with the way the lighting "for" loop is unrolled when the GLSL is compiled. If I unroll the "for" loop manually (by just referring to directionalLightDirection[0] and directionalLightDirection[1]) , everything renders properly. If I don't, I don't get any diffuse or specular contribution.

I'm new to WebGL (and web development in general), but can the browser effect the settings used to compile the shaders? My shaders (and the ShaderUtils.lib["normal"] shader) worked fine yesterday but not today.