1

我有一个从搅拌机导出的简单室内场景。它有一个房间,天花板上有 3 个球体,里面有各自的光源。每一个灯都可以单独工作,但是当我将它们全部插入场景中时,只有一个灯可以工作!有时与 2 一起工作,但从不与他们三个一起工作。这是我的灯代码:

luz_sala1 = new THREE.PointLight(0xFFFFFF,0.5, 50.0);
luz_sala1.position = new THREE.Vector3(16.14323,2.52331,13.93375);
scene.add(luz_sala1);

luz_sala2 = new THREE.PointLight(0xFFFFFF, 0.5, 50.0);
luz_sala2.position = new THREE.Vector3(27.70114,2.52331,-6.20571);
scene.add(luz_sala2);

luz_sala3 = new THREE.PointLight(0xFFFFFF, 0.5, 50.0);
luz_sala3.position = new THREE.Vector3(21.50580,3.10719,-27.82775);
scene.add(luz_sala3);

如果我将距离设置为 0,效果很好,但我需要这些灯只影响它们所在的区域。我也尝试过 THREE.Spotlight(0xFFFFFF,0.5,50.0,Math.PI, 0) 但使用同样的结果。当它们以某种方式共享相同的距离时,它们看起来会相互抵消吗?

请帮忙,这很混乱。

编辑:另外,我在房间的另一部分有一些聚光灯模型(我有大约 4 个),但是当我将这 4 个聚光灯添加到场景中时,我遇到了着色器编译错误。搜索完问题,发现需要在渲染器中设置maxLights属性。我将它设置为 10,但问题仍然存在,场景中的灯光不能超过 4 个。还有什么我可以做的吗?

编辑2:这里有一些图片。作为参考,“luz_sala1”是靠近电视的那个,“luz_sala2”是中间的,“luz_sala3”是更远的。

这个是上面的代码(所有 3 个灯),除了 0.8 强度。 http://www.mediafire.com/view/?s85qr4rplhort29

这是在打开 2 和 3 的情况下(评论了“scene.add(luz_sala1);”): http ://www.mediafire.com/view/?83qbbua9f8ee3b4

所以,如您所见,2 个点光源可以很好地协同工作,但 3 个点光源似乎“加起来”到第一个?

4

1 回答 1

0

The maxLight property not having any effect is most likely due to your hardware, drivers or ANGLE (library that translates WebGL to Direct3D) not supporting enough varying vectors in shaders - each light requires one and other things too. This might also be in the background of your general problem.

In order to have more lights there are three options:

  1. Try if it helps if you make your browser prefer native OpenGL over ANGLE (google for instructions). Make sure you have up-to-date OpenGL drivers installed though.
  2. Implement a deferred renderer. This is nowadays very common in the desktop world, but it's tricky if not impossible to implement with good performance in WebGL due to framebuffer limitations.
  3. Implement a light manager that only ever uses some lights, disabling the rest. Simplest, though far from perfect method would be to select the lights closest to the camera.

Also worth mentioning is that currently SpotLights are just PointLights that cast shadow to one direction.

于 2012-09-14T09:28:19.633 回答