我正在使用Three.js r58(使用WebGLRenderer)創建一個系統,該系統顯示建築物的3D模型,其中包含燈光的實際位置和暗淡程度。向場景中添加超過37個聚光燈時發生Three.js錯誤
從數據庫中的每個光由CubeGeometry對象(物理光)和焦點(顯示什麼的光被輸出的假象)作爲創建表示如下:
// 'this' is an existing custom object as populated from the database - all code there is fine
var geometry = new THREE.CubeGeometry(4.8, 0.6, 1.36);
var material = new THREE.MeshBasicMaterial({color:0x444444, vertexColors:THREE.FaceColors});
this.objectMesh = new THREE.Mesh(geometry, material);
this.objectMesh.position.set(0, 20, 0);
scene.add(this.objectMesh);
this.lightEmitter = new THREE.SpotLight(0xffffff, 0, 22, true);
this.lightEmitter.position.set(this.objectMesh.position.x, this.objectMesh.position.y - (this.objectMesh.geometry.height/10), this.objectMesh.position.z);
this.lightEmitter.rotation.set(this.objectMesh.rotation.x, this.objectMesh.rotation.y, this.objectMesh.rotation.z)
this.lightEmitter.target.position.set(this.objectMesh.position.x, 0, this.objectMesh.position.z);
this.lightEmitter.angle = 0.9;
scene.add(this.lightEmitter);
現在,一切都被可以在場景中使用多達37個燈光完美工作,但只要我添加第38號燈光,我會收到以下錯誤:Could not initialise shader VALIDATE_STATUS: false, gl error [1285]
此錯誤出現在帶有GeForce GTX 650的Windows 7 PC上的Firefox和Chrome中,以及Ubuntu筆記本電腦上的Firefox(不確定顯卡,但可以找出是否需要)。在Android Nexus 7上的Chrome上,我收到了一個額外的錯誤:(0) : error C6007: Constant register limit exceeded; more than 256 constant registers needed to compiled program 50 lines, 1 errors
- 不確定這是否相關。
如果我從場景中刪除建築模型並在平面上加載,我還會得到:ERROR: too many uniforms
38個燈,其中37個燈正常工作。我也嘗試防止燈光和物體投射和接收陰影,但沒有幫助。
我是否通過在場景中渲染如此多的燈光來達到硬件和/或OpenGL和/或WebGL限制?如果沒有人有任何可能導致問題的想法?
我忘了提及,並不是所有的燈都在同一時間。在編寫問題時,6個燈亮起,並且下一個燈是否打開仍然會出現相同的錯誤,儘管我目前在該建築模型中有16個燈沒有錯誤,而另一個建築模型使用了確切的相同的代碼與20 +在同一時間點亮。 –
@gaitat:固定流水線着色器中可以使用的燈的數量是有限制的,但是Threejs不使用它(我不認爲WebGL中固定的流水線可用)。 Winterblood:你只是達到了硬件限制=>每次使用光源時,threejs需要分配一些寄存器來處理它(對於光位置,顏色......),並且可用寄存器的數量受限於圖形卡。你可以做的事情不多,除了只打開燈並打開其他燈,以便在任何時候只有幾個燈可以處理(比如說少於10個燈)。 – Popov