Mr.doob пре 10 година
родитељ
комит
1aabcb379c

+ 1 - 0
examples/index.html

@@ -358,6 +358,7 @@
 				"webgl_shadowmap",
 				"webgl_shadowmap",
 				"webgl_shadowmap_performance",
 				"webgl_shadowmap_performance",
 				"webgl_shadowmap_viewer",
 				"webgl_shadowmap_viewer",
+				"webgl_shadowmesh",
 				"webgl_sprites",
 				"webgl_sprites",
 				"webgl_terrain_dynamic",
 				"webgl_terrain_dynamic",
 				"webgl_test_memory",
 				"webgl_test_memory",

+ 16 - 23
examples/js/SkyShader.js

@@ -1,16 +1,16 @@
 /**
 /**
  * @author zz85 / https://github.com/zz85
  * @author zz85 / https://github.com/zz85
- * 
- * Based on "A Practical Analytic Model for Daylight" 
+ *
+ * Based on "A Practical Analytic Model for Daylight"
  * aka The Preetham Model, the de facto standard analytic skydome model
  * aka The Preetham Model, the de facto standard analytic skydome model
  * http://www.cs.utah.edu/~shirley/papers/sunsky/sunsky.pdf
  * http://www.cs.utah.edu/~shirley/papers/sunsky/sunsky.pdf
- * 
+ *
  * First implemented by Simon Wallner
  * First implemented by Simon Wallner
  * http://www.simonwallner.at/projects/atmospheric-scattering
  * http://www.simonwallner.at/projects/atmospheric-scattering
- * 
+ *
  * Improved by Martin Upitis
  * Improved by Martin Upitis
  * http://blenderartists.org/forum/showthread.php?245954-preethams-sky-impementation-HDR
  * http://blenderartists.org/forum/showthread.php?245954-preethams-sky-impementation-HDR
- * 
+ *
  * Three.js integration by zz85 http://twitter.com/blurspline
  * Three.js integration by zz85 http://twitter.com/blurspline
 */
 */
 
 
@@ -30,13 +30,11 @@ THREE.ShaderLib['sky'] = {
 	vertexShader: [
 	vertexShader: [
 
 
 		"varying vec3 vWorldPosition;",
 		"varying vec3 vWorldPosition;",
-		"varying vec2 vUv;",
 
 
 		"void main() {",
 		"void main() {",
 
 
 			"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
 			"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
 			"vWorldPosition = worldPosition.xyz;",
 			"vWorldPosition = worldPosition.xyz;",
-			"vUv = uv;",
 
 
 			"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 			"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 
 
@@ -46,12 +44,9 @@ THREE.ShaderLib['sky'] = {
 
 
 	fragmentShader: [
 	fragmentShader: [
 
 
-
 		"uniform sampler2D skySampler;",
 		"uniform sampler2D skySampler;",
 		"uniform vec3 sunPosition;",
 		"uniform vec3 sunPosition;",
 		"varying vec3 vWorldPosition;",
 		"varying vec3 vWorldPosition;",
-		"varying vec2 vUv;",
-
 
 
 		"vec3 cameraPos = vec3(0., 0., 0.);",
 		"vec3 cameraPos = vec3(0., 0., 0.);",
 		"// uniform sampler2D sDiffuse;",
 		"// uniform sampler2D sDiffuse;",
@@ -67,7 +62,6 @@ THREE.ShaderLib['sky'] = {
 		"uniform float mieCoefficient;",
 		"uniform float mieCoefficient;",
 		"uniform float mieDirectionalG;",
 		"uniform float mieDirectionalG;",
 
 
-
 		"vec3 sunDirection = normalize(sunPosition);",
 		"vec3 sunDirection = normalize(sunPosition);",
 		"float reileighCoefficient = reileigh;",
 		"float reileighCoefficient = reileigh;",
 
 
@@ -165,9 +159,9 @@ THREE.ShaderLib['sky'] = {
 			"// luminance =  1.0 ;// vWorldPosition.y / 450000. + 0.5; //sunPosition.y / 450000. * 1. + 0.5;",
 			"// luminance =  1.0 ;// vWorldPosition.y / 450000. + 0.5; //sunPosition.y / 450000. * 1. + 0.5;",
 
 
 			 "// gl_FragColor = vec4(sunfade, sunfade, sunfade, 1.0);",
 			 "// gl_FragColor = vec4(sunfade, sunfade, sunfade, 1.0);",
-			
+
 			"reileighCoefficient = reileighCoefficient - (1.0* (1.0-sunfade));",
 			"reileighCoefficient = reileighCoefficient - (1.0* (1.0-sunfade));",
-			
+
 			"float sunE = sunIntensity(dot(sunDirection, up));",
 			"float sunE = sunIntensity(dot(sunDirection, up));",
 
 
 			"// extinction (absorbtion + out scattering) ",
 			"// extinction (absorbtion + out scattering) ",
@@ -210,7 +204,7 @@ THREE.ShaderLib['sky'] = {
 			"vec2 uv = vec2(phi, theta) / vec2(2.0*pi, pi) + vec2(0.5, 0.0);",
 			"vec2 uv = vec2(phi, theta) / vec2(2.0*pi, pi) + vec2(0.5, 0.0);",
 			"// vec3 L0 = texture2D(skySampler, uv).rgb+0.1 * Fex;",
 			"// vec3 L0 = texture2D(skySampler, uv).rgb+0.1 * Fex;",
 			"vec3 L0 = vec3(0.1) * Fex;",
 			"vec3 L0 = vec3(0.1) * Fex;",
-			
+
 			"// composition + solar disc",
 			"// composition + solar disc",
 			"//if (cosTheta > sunAngularDiameterCos)",
 			"//if (cosTheta > sunAngularDiameterCos)",
 			"float sundisk = smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);",
 			"float sundisk = smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);",
@@ -219,25 +213,25 @@ THREE.ShaderLib['sky'] = {
 
 
 
 
 			"vec3 whiteScale = 1.0/Uncharted2Tonemap(vec3(W));",
 			"vec3 whiteScale = 1.0/Uncharted2Tonemap(vec3(W));",
-			
+
 			"vec3 texColor = (Lin+L0);   ",
 			"vec3 texColor = (Lin+L0);   ",
 			"texColor *= 0.04 ;",
 			"texColor *= 0.04 ;",
 			"texColor += vec3(0.0,0.001,0.0025)*0.3;",
 			"texColor += vec3(0.0,0.001,0.0025)*0.3;",
-			
+
 			"float g_fMaxLuminance = 1.0;",
 			"float g_fMaxLuminance = 1.0;",
 			"float fLumScaled = 0.1 / luminance;     ",
 			"float fLumScaled = 0.1 / luminance;     ",
 			"float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (g_fMaxLuminance * g_fMaxLuminance)))) / (1.0 + fLumScaled); ",
 			"float fLumCompressed = (fLumScaled * (1.0 + (fLumScaled / (g_fMaxLuminance * g_fMaxLuminance)))) / (1.0 + fLumScaled); ",
 
 
 			"float ExposureBias = fLumCompressed;",
 			"float ExposureBias = fLumCompressed;",
-		   
+
 			"vec3 curr = Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);",
 			"vec3 curr = Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);",
 			"vec3 color = curr*whiteScale;",
 			"vec3 color = curr*whiteScale;",
 
 
 			"vec3 retColor = pow(color,vec3(1.0/(1.2+(1.2*sunfade))));",
 			"vec3 retColor = pow(color,vec3(1.0/(1.2+(1.2*sunfade))));",
 
 
-			
+
 			"gl_FragColor.rgb = retColor;",
 			"gl_FragColor.rgb = retColor;",
-				
+
 			"gl_FragColor.a = 1.0;",
 			"gl_FragColor.a = 1.0;",
 		"}",
 		"}",
 
 
@@ -250,9 +244,9 @@ THREE.Sky = function () {
 	var skyShader = THREE.ShaderLib[ "sky" ];
 	var skyShader = THREE.ShaderLib[ "sky" ];
 	var skyUniforms = THREE.UniformsUtils.clone( skyShader.uniforms );
 	var skyUniforms = THREE.UniformsUtils.clone( skyShader.uniforms );
 
 
-	var skyMat = new THREE.ShaderMaterial( { 
-		fragmentShader: skyShader.fragmentShader, 
-		vertexShader: skyShader.vertexShader, 
+	var skyMat = new THREE.ShaderMaterial( {
+		fragmentShader: skyShader.fragmentShader,
+		vertexShader: skyShader.vertexShader,
 		uniforms: skyUniforms,
 		uniforms: skyUniforms,
 		side: THREE.BackSide
 		side: THREE.BackSide
 	} );
 	} );
@@ -265,5 +259,4 @@ THREE.Sky = function () {
 	this.mesh = skyMesh;
 	this.mesh = skyMesh;
 	this.uniforms = skyUniforms;
 	this.uniforms = skyUniforms;
 
 
-
 };
 };

+ 2 - 2
examples/js/math/Lut.js

@@ -300,7 +300,7 @@ THREE.Lut.prototype = {
 		contextTitle.fillText( this.legend.labels.title.toString() + this.legend.labels.um.toString(), borderThickness, this.legend.labels.fontsize + borderThickness );
 		contextTitle.fillText( this.legend.labels.title.toString() + this.legend.labels.um.toString(), borderThickness, this.legend.labels.fontsize + borderThickness );
 
 
 		var txtTitle = new THREE.Texture( canvasTitle );
 		var txtTitle = new THREE.Texture( canvasTitle );
-
+		txtTitle.minFilter = THREE.LinearFilter;
 		txtTitle.needsUpdate = true;
 		txtTitle.needsUpdate = true;
 
 
 		var spriteMaterialTitle = new THREE.SpriteMaterial( { map: txtTitle, useScreenCoordinates: false } );
 		var spriteMaterialTitle = new THREE.SpriteMaterial( { map: txtTitle, useScreenCoordinates: false } );
@@ -385,7 +385,7 @@ THREE.Lut.prototype = {
 				contextTick.fillText( value.toString(), borderThickness, this.legend.labels.fontsize + borderThickness );
 				contextTick.fillText( value.toString(), borderThickness, this.legend.labels.fontsize + borderThickness );
 
 
 				var txtTick = new THREE.Texture( canvasTick );
 				var txtTick = new THREE.Texture( canvasTick );
-
+				txtTick.minFilter = THREE.LinearFilter;
 				txtTick.needsUpdate = true;
 				txtTick.needsUpdate = true;
 
 
 				var spriteMaterialTick = new THREE.SpriteMaterial( { map: txtTick, useScreenCoordinates: false } );
 				var spriteMaterialTick = new THREE.SpriteMaterial( { map: txtTick, useScreenCoordinates: false } );

+ 8 - 8
examples/js/postprocessing/AdaptiveToneMappingPass.js

@@ -16,7 +16,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
 	this.luminanceRT = null;
 	this.luminanceRT = null;
 	this.previousLuminanceRT = null;
 	this.previousLuminanceRT = null;
 	this.currentLuminanceRT = null;
 	this.currentLuminanceRT = null;
-	
+
 	if ( THREE.CopyShader === undefined )
 	if ( THREE.CopyShader === undefined )
 		console.error( "THREE.AdaptiveToneMappingPass relies on THREE.CopyShader" );
 		console.error( "THREE.AdaptiveToneMappingPass relies on THREE.CopyShader" );
 
 
@@ -72,15 +72,15 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
 			"uniform sampler2D currentLum;",
 			"uniform sampler2D currentLum;",
 			"uniform float delta;",
 			"uniform float delta;",
 			"uniform float tau;",
 			"uniform float tau;",
-			
+
 			"void main() {",
 			"void main() {",
 
 
 				"vec4 lastLum = texture2D( lastLum, vUv, MIP_LEVEL_1X1 );",
 				"vec4 lastLum = texture2D( lastLum, vUv, MIP_LEVEL_1X1 );",
 				"vec4 currentLum = texture2D( currentLum, vUv, MIP_LEVEL_1X1 );",
 				"vec4 currentLum = texture2D( currentLum, vUv, MIP_LEVEL_1X1 );",
-				
+
 				"float fLastLum = lastLum.r;",
 				"float fLastLum = lastLum.r;",
 				"float fCurrentLum = currentLum.r;",
 				"float fCurrentLum = currentLum.r;",
-				
+
 				//The adaption seems to work better in extreme lighting differences
 				//The adaption seems to work better in extreme lighting differences
 				//if the input luminance is squared.
 				//if the input luminance is squared.
 				"fCurrentLum *= fCurrentLum;",
 				"fCurrentLum *= fCurrentLum;",
@@ -120,7 +120,7 @@ THREE.AdaptiveToneMappingPass = function ( adaptive, resolution ) {
 	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
 	this.camera = new THREE.OrthographicCamera( -1, 1, 1, -1, 0, 1 );
 	this.scene  = new THREE.Scene();
 	this.scene  = new THREE.Scene();
 
 
-	this.quad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ), null );
+	this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), null );
 	this.scene.add( this.quad );
 	this.scene.add( this.quad );
 
 
 };
 };
@@ -160,7 +160,7 @@ THREE.AdaptiveToneMappingPass.prototype = {
 		this.quad.material = this.materialToneMap;
 		this.quad.material = this.materialToneMap;
 		this.materialToneMap.uniforms.tDiffuse.value = readBuffer;
 		this.materialToneMap.uniforms.tDiffuse.value = readBuffer;
 		renderer.render( this.scene, this.camera, writeBuffer, this.clear );
 		renderer.render( this.scene, this.camera, writeBuffer, this.clear );
-		
+
 	},
 	},
 
 
 	reset: function( renderer ) {
 	reset: function( renderer ) {
@@ -184,7 +184,7 @@ THREE.AdaptiveToneMappingPass.prototype = {
 		//We only need mipmapping for the current luminosity because we want a down-sampled version to sample in our adaptive shader
 		//We only need mipmapping for the current luminosity because we want a down-sampled version to sample in our adaptive shader
 		pars.minFilter = THREE.LinearMipMapLinearFilter;
 		pars.minFilter = THREE.LinearMipMapLinearFilter;
 		this.currentLuminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
 		this.currentLuminanceRT = new THREE.WebGLRenderTarget( this.resolution, this.resolution, pars );
-		
+
 		if ( this.adaptive ) {
 		if ( this.adaptive ) {
 			this.materialToneMap.defines["ADAPTED_LUMINANCE"] = "";
 			this.materialToneMap.defines["ADAPTED_LUMINANCE"] = "";
 			this.materialToneMap.uniforms.luminanceMap.value = this.luminanceRT;
 			this.materialToneMap.uniforms.luminanceMap.value = this.luminanceRT;
@@ -261,4 +261,4 @@ THREE.AdaptiveToneMappingPass.prototype = {
 		}
 		}
 	}
 	}
 
 
-};
+};

+ 6 - 5
examples/misc_fps.html

@@ -163,7 +163,7 @@
 								var actualHeight = hits[0].distance - birdsEye;
 								var actualHeight = hits[0].distance - birdsEye;
 
 
 								// collision: stick to the surface if landing on it
 								// collision: stick to the surface if landing on it
-								
+
 								if( ( motion.velocity.y <= 0 ) && ( Math.abs( actualHeight ) < kneeDeep ) ) {
 								if( ( motion.velocity.y <= 0 ) && ( Math.abs( actualHeight ) < kneeDeep ) ) {
 									motion.position.y -= actualHeight;
 									motion.position.y -= actualHeight;
 									motion.velocity.y = 0;
 									motion.velocity.y = 0;
@@ -185,9 +185,9 @@
 							// limit the tilt at ±0.4 radians
 							// limit the tilt at ±0.4 radians
 
 
 							motion.rotation.x = Math.max( -0.4, Math.min ( +0.4, motion.rotation.x ) );
 							motion.rotation.x = Math.max( -0.4, Math.min ( +0.4, motion.rotation.x ) );
-							
+
 							// wrap horizontal rotation to 0...2π
 							// wrap horizontal rotation to 0...2π
-							
+
 							motion.rotation.y += tau; motion.rotation.y %= tau;
 							motion.rotation.y += tau; motion.rotation.y %= tau;
 
 
 							timeLeft -= dt;
 							timeLeft -= dt;
@@ -233,6 +233,7 @@
 				var placeholder = new THREE.Object3D();
 				var placeholder = new THREE.Object3D();
 
 
 				var texture = THREE.ImageUtils.loadTexture( textureUrl );
 				var texture = THREE.ImageUtils.loadTexture( textureUrl );
+				texture.minFilter = THREE.LinearFilter;
 				texture.anisotropy = textureQuality;
 				texture.anisotropy = textureQuality;
 
 
 				var loader = new THREE.JSONLoader();
 				var loader = new THREE.JSONLoader();
@@ -256,7 +257,7 @@
 			var camera = new THREE.PerspectiveCamera( 60, 1, 0.1, 9000 );
 			var camera = new THREE.PerspectiveCamera( 60, 1, 0.1, 9000 );
 
 
 			var scene = new THREE.Scene();
 			var scene = new THREE.Scene();
-			
+
 			scene.add( camera );
 			scene.add( camera );
 
 
 			scene.add( makeSkybox( [
 			scene.add( makeSkybox( [
@@ -294,7 +295,7 @@
 
 
 					// call our game loop with the time elapsed since last rendering, in ms
 					// call our game loop with the time elapsed since last rendering, in ms
 					gameLoop( timeElapsed );
 					gameLoop( timeElapsed );
-					
+
 					renderer.render( scene, camera );
 					renderer.render( scene, camera );
 					requestAnimationFrame( render );
 					requestAnimationFrame( render );
 				};
 				};

+ 1 - 0
examples/webgl_interactive_cubes_gpu.html

@@ -75,6 +75,7 @@
 
 
 				pickingScene = new THREE.Scene();
 				pickingScene = new THREE.Scene();
 				pickingTexture = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight );
 				pickingTexture = new THREE.WebGLRenderTarget( window.innerWidth, window.innerHeight );
+				pickingTexture.minFilter = THREE.LinearFilter;
 				pickingTexture.generateMipmaps = false;
 				pickingTexture.generateMipmaps = false;
 
 
 				scene.add( new THREE.AmbientLight( 0x555555 ) );
 				scene.add( new THREE.AmbientLight( 0x555555 ) );

+ 13 - 24
examples/webgl_shaders_sky.html

@@ -20,8 +20,8 @@
 			}
 			}
 
 
 			#info {
 			#info {
-				color:#333;
-				text-shadow: 1px 1px #fff;
+				color:#ccc;
+				text-shadow: 1px 1px rgba(0,0,0,0.25);
 				position: absolute;
 				position: absolute;
 				top: 0px; width: 100%;
 				top: 0px; width: 100%;
 				padding: 5px;
 				padding: 5px;
@@ -29,7 +29,7 @@
 			}
 			}
 
 
 			a {
 			a {
-				color: #333;
+				color: #fff;
 			}
 			}
 
 
 		</style>
 		</style>
@@ -90,7 +90,7 @@
 					mieDirectionalG: 0.8,
 					mieDirectionalG: 0.8,
 					luminance: 1,
 					luminance: 1,
 					inclination: 0.49, // elevation / inclination
 					inclination: 0.49, // elevation / inclination
-					azimuth: 0.25, // Facing front,					
+					azimuth: 0.25, // Facing front,
 					sun: !true
 					sun: !true
 				}
 				}
 
 
@@ -108,8 +108,8 @@
 					var phi = 2 * Math.PI * (effectController.azimuth - 0.5);
 					var phi = 2 * Math.PI * (effectController.azimuth - 0.5);
 
 
 					sunSphere.position.x = distance * Math.cos(phi);
 					sunSphere.position.x = distance * Math.cos(phi);
-					sunSphere.position.y = distance * Math.sin(phi) * Math.sin(theta); 
-					sunSphere.position.z = distance * Math.sin(phi) * Math.cos(theta); 
+					sunSphere.position.y = distance * Math.sin(phi) * Math.sin(theta);
+					sunSphere.position.z = distance * Math.sin(phi) * Math.cos(theta);
 
 
 					sunSphere.visible = effectController.sun;
 					sunSphere.visible = effectController.sun;
 
 
@@ -129,14 +129,14 @@
 				gui.add( effectController, "inclination", 0, 1, 0.0001).onChange( guiChanged );
 				gui.add( effectController, "inclination", 0, 1, 0.0001).onChange( guiChanged );
 				gui.add( effectController, "azimuth", 0, 1, 0.0001).onChange( guiChanged );
 				gui.add( effectController, "azimuth", 0, 1, 0.0001).onChange( guiChanged );
 				gui.add( effectController, "sun").onChange( guiChanged );
 				gui.add( effectController, "sun").onChange( guiChanged );
-				
+
 
 
 				guiChanged();
 				guiChanged();
 
 
 
 
 				camera.lookAt(sunSphere.position)
 				camera.lookAt(sunSphere.position)
 
 
-	
+
 			}
 			}
 
 
 
 
@@ -150,21 +150,10 @@
 
 
 				scene = new THREE.Scene();
 				scene = new THREE.Scene();
 
 
-				var size = 500;
-
-				var geometryLines = new THREE.BoxGeometry( size, size, size );
-	
-				var geometryPlane = new THREE.PlaneGeometry( size * 10, size * 10, 1, 1);
-				geometryPlane.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
-	
-
-				var materialLines = new THREE.MeshBasicMaterial( { wireframe: true } );
-
-				meshLines = new THREE.Mesh( geometryLines, materialLines );
-
-				// scene.add( meshLines );
-
-				scene.add( new THREE.Mesh( geometryPlane, materialLines ) );
+				var helper = new THREE.GridHelper( 5000, 5000 );
+				helper.color1.setHex( 0xffffff );
+				helper.color2.setHex( 0xffffff );
+				scene.add( helper );
 
 
 				initSky();
 				initSky();
 
 
@@ -206,7 +195,7 @@
 				time = Date.now();
 				time = Date.now();
 
 
 				requestAnimationFrame( animate );
 				requestAnimationFrame( animate );
-				
+
 				controls.update();
 				controls.update();
 
 
 				render();
 				render();

+ 1 - 1
examples/webgl_terrain_dynamic.html

@@ -606,7 +606,7 @@
 
 
 				var sceneTmp = new THREE.Scene();
 				var sceneTmp = new THREE.Scene();
 
 
-				var meshTmp = new THREE.Mesh( new THREE.PlaneGeometry( SCREEN_WIDTH, SCREEN_HEIGHT ), shaderMaterial );
+				var meshTmp = new THREE.Mesh( new THREE.PlaneBufferGeometry( SCREEN_WIDTH, SCREEN_HEIGHT ), shaderMaterial );
 				meshTmp.position.z = -500;
 				meshTmp.position.z = -500;
 
 
 				sceneTmp.add( meshTmp );
 				sceneTmp.add( meshTmp );