Selaa lähdekoodia

WebGLBackground: Simplified skybox code.

Mr.doob 8 vuotta sitten
vanhempi
commit
1e4ae4fcc1

+ 0 - 2
src/renderers/shaders/ShaderLib/cube_frag.glsl

@@ -4,8 +4,6 @@ uniform float opacity;
 
 
 varying vec3 vWorldPosition;
 varying vec3 vWorldPosition;
 
 
-#include <common>
-
 void main() {
 void main() {
 
 
 	gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );
 	gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );

+ 1 - 3
src/renderers/shaders/ShaderLib/cube_vert.glsl

@@ -5,8 +5,6 @@ varying vec3 vWorldPosition;
 void main() {
 void main() {
 
 
 	vWorldPosition = transformDirection( position, modelMatrix );
 	vWorldPosition = transformDirection( position, modelMatrix );
-
-	#include <begin_vertex>
-	#include <project_vertex>
+	gl_Position = projectionMatrix * vec4( normalMatrix * position, 1.0 );
 
 
 }
 }

+ 5 - 11
src/renderers/webgl/WebGLBackground.js

@@ -19,7 +19,7 @@ function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
 	var clearAlpha = 0;
 	var clearAlpha = 0;
 
 
 	var planeCamera, planeMesh;
 	var planeCamera, planeMesh;
-	var boxCamera, boxMesh;
+	var boxMesh;
 
 
 	function render( scene, camera, forceClear ) {
 	function render( scene, camera, forceClear ) {
 
 
@@ -44,9 +44,7 @@ function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
 
 
 		if ( background && background.isCubeTexture ) {
 		if ( background && background.isCubeTexture ) {
 
 
-			if ( boxCamera === undefined ) {
-
-				boxCamera = new PerspectiveCamera();
+			if ( boxMesh === undefined ) {
 
 
 				boxMesh = new Mesh(
 				boxMesh = new Mesh(
 					new BoxBufferGeometry( 5, 5, 5 ),
 					new BoxBufferGeometry( 5, 5, 5 ),
@@ -63,17 +61,13 @@ function WebGLBackground( renderer, state, geometries, premultipliedAlpha ) {
 
 
 			}
 			}
 
 
-			boxCamera.projectionMatrix.copy( camera.projectionMatrix );
-
-			boxCamera.matrixWorld.extractRotation( camera.matrixWorld );
-			boxCamera.matrixWorldInverse.getInverse( boxCamera.matrixWorld );
-
 			boxMesh.material.uniforms[ "tCube" ].value = background;
 			boxMesh.material.uniforms[ "tCube" ].value = background;
-			boxMesh.modelViewMatrix.multiplyMatrices( boxCamera.matrixWorldInverse, boxMesh.matrixWorld );
+			boxMesh.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, boxMesh.matrixWorld );
+			boxMesh.normalMatrix.getNormalMatrix( boxMesh.modelViewMatrix );
 
 
 			geometries.update( boxMesh.geometry );
 			geometries.update( boxMesh.geometry );
 
 
-			renderer.renderBufferDirect( boxCamera, null, boxMesh.geometry, boxMesh.material, boxMesh, null );
+			renderer.renderBufferDirect( camera, null, boxMesh.geometry, boxMesh.material, boxMesh, null );
 
 
 		} else if ( background && background.isTexture ) {
 		} else if ( background && background.isTexture ) {