Jelajahi Sumber

Merge remote-tracking branch 'alteredq/dev' into dev

Mr.doob 12 tahun lalu
induk
melakukan
d90e934c59

File diff ditekan karena terlalu besar
+ 2 - 2
build/three.min.js


+ 97 - 174
examples/js/ShaderDeferred.js

@@ -17,9 +17,11 @@ THREE.ShaderDeferred = {
 			THREE.UniformsLib[ "shadowmap" ],
 
 			{
-				"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
-				"specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
-				"shininess": { type: "f", value: 30 }
+				"emissive" :  { type: "c", value: new THREE.Color( 0x000000 ) },
+				"specular" :  { type: "c", value: new THREE.Color( 0x111111 ) },
+				"shininess":  { type: "f", value: 30 },
+				"wrapAround": 		{ type: "f", value: 1 },
+				"additiveSpecular": { type: "f", value: 1 }
 			}
 
 		] ),
@@ -30,6 +32,8 @@ THREE.ShaderDeferred = {
 			"uniform vec3 specular;",
 			"uniform vec3 emissive;",
 			"uniform float shininess;",
+			"uniform float wrapAround;",
+			"uniform float additiveSpecular;",
 
 			THREE.ShaderChunk[ "color_pars_fragment" ],
 			THREE.ShaderChunk[ "map_pars_fragment" ],
@@ -66,21 +70,33 @@ THREE.ShaderDeferred = {
 
 				THREE.ShaderChunk[ "fog_fragment" ],
 
+				//
+
+				"const float compressionScale = 0.999;",
+
 				// diffuse color
 
-				"gl_FragColor.x = vec3_to_float( 0.999 * gl_FragColor.xyz );",
+				"gl_FragColor.x = vec3_to_float( compressionScale * gl_FragColor.xyz );",
 
 				// specular color
 
-				"gl_FragColor.y = vec3_to_float( 0.999 * specular );",
+				"gl_FragColor.y = additiveSpecular * vec3_to_float( compressionScale * specular );",
 
 				// shininess
 
-				"gl_FragColor.z = shininess;",
+				"gl_FragColor.z = wrapAround * shininess;",
 
 				// emissive color
 
-				"gl_FragColor.w = vec3_to_float( 0.999 * emissive );",
+				"#ifdef USE_MAP",
+
+					"gl_FragColor.w = vec3_to_float( compressionScale * emissive * texelColor.xyz );",
+
+				"#else",
+
+					"gl_FragColor.w = vec3_to_float( compressionScale * emissive );",
+
+				"#endif",
 
 			"}"
 
@@ -125,60 +141,62 @@ THREE.ShaderDeferred = {
 
 	},
 
-	"clipDepth" : {
+	"normalDepth" : {
 
-		uniforms: { },
+		uniforms: {
 
-		fragmentShader : [
+			bumpMap: 	  { type: "t", value: null },
+			bumpScale:	  { type: "f", value: 1 },
+			offsetRepeat: { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
 
-			"varying vec4 clipPos;",
+		},
 
-			"void main() {",
+		fragmentShader : [
 
-				"gl_FragColor = vec4( clipPos.z / clipPos.w, 1.0, 1.0, 1.0 );",
+			"#ifdef USE_BUMPMAP",
 
-			"}"
+				"#extension GL_OES_standard_derivatives : enable\n",
 
-		].join("\n"),
+				"varying vec2 vUv;",
+				"varying vec3 vViewPosition;",
 
-		vertexShader : [
+				THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
 
-			"varying vec4 clipPos;",
+			"#endif",
 
-			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
+			"varying vec3 normalView;",
+			"varying vec4 clipPos;",
 
 			"void main() {",
 
-				THREE.ShaderChunk[ "morphtarget_vertex" ],
-				THREE.ShaderChunk[ "default_vertex" ],
+				"vec3 normal = normalize( normalView );",
 
-				"clipPos = gl_Position;",
+				"#ifdef USE_BUMPMAP",
 
-			"}"
+					"normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );",
 
-		].join("\n")
+				"#endif",
 
-	},
+				"gl_FragColor.xyz = normal * 0.5 + 0.5;",
+				"gl_FragColor.w = clipPos.z / clipPos.w;",
 
-	"normals" : {
+			"}"
 
-		uniforms: { },
+		].join("\n"),
 
-		fragmentShader : [
+		vertexShader : [
 
 			"varying vec3 normalView;",
+			"varying vec4 clipPos;",
 
-			"void main() {",
-
-				"gl_FragColor = vec4( vec3( normalView * 0.5 + 0.5 ), 1.0 );",
+			"#ifdef USE_BUMPMAP",
 
-			"}"
+				"varying vec2 vUv;",
+				"varying vec3 vViewPosition;",
 
-		].join("\n"),
+				"uniform vec4 offsetRepeat;",
 
-		vertexShader : [
-
-			"varying vec3 normalView;",
+			"#endif",
 
 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
 
@@ -204,105 +222,13 @@ THREE.ShaderDeferred = {
 
 				"normalView = normalize( normalMatrix * objectNormal );",
 
-			"}"
-
-		].join("\n")
-
-	},
-
-	"bump" : {
-
-		uniforms: {
-
-			bumpMap: 	  { type: "t", value: null },
-			bumpScale:	  { type: "f", value: 1 },
-			offsetRepeat: { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
-
-		},
-
-		fragmentShader : [
-
-			"#extension GL_OES_standard_derivatives : enable\n",
-
-			"varying vec3 normalView;",
-			"varying vec2 vUv;",
-			"varying vec3 vViewPosition;",
-
-			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
+				"#ifdef USE_BUMPMAP",
 
-			"void main() {",
-
-				"vec3 normal = normalize( normalView );",
-				"normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );",
-				"gl_FragColor = vec4( vec3( normal * 0.5 + 0.5 ), 1.0 );",
-
-			"}"
-
-		].join("\n"),
-
-		vertexShader : [
+					"vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
+					"vViewPosition = -mvPosition.xyz;",
 
-			"varying vec3 normalView;",
-			"varying vec2 vUv;",
-			"varying vec3 vViewPosition;",
-
-			"uniform vec4 offsetRepeat;",
-
-			"void main() {",
-
-				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
-				"gl_Position = projectionMatrix * mvPosition;",
-				"normalView = normalize( normalMatrix * normal );",
-				"vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
-				"vViewPosition = -mvPosition.xyz;",
-
-			"}"
-
-		].join("\n")
-
-	},
-
-	"unlit" : {
-
-		uniforms: {
-
-			samplerDepth: { type: "t", value: null },
-			viewWidth:    { type: "f", value: 800 },
-			viewHeight:   { type: "f", value: 600 },
-			lightColor:   { type: "c", value: new THREE.Color( 0x000000 ) }
-
-		},
-
-		fragmentShader : [
-
-			"varying vec4 clipPos;",
-			"uniform sampler2D samplerDepth;",
-
-			"uniform float viewHeight;",
-			"uniform float viewWidth;",
-
-			"uniform vec3 lightColor;",
-
-			"void main() {",
-
-				"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
-				"float z = texture2D( samplerDepth, texCoord ).x;",
-				"vec4 color = vec4( lightColor, 1.0 );",
-				"float depth = clipPos.z / clipPos.w;",
-				"if( depth > z && z > 0.0 ) color.w = 0.0;",
-				"gl_FragColor = color;",
-
-			"}"
-
-		].join("\n"),
-
-		vertexShader : [
-
-			"varying vec4 clipPos;",
-
-			"void main() {",
+				"#endif",
 
-				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
 				"clipPos = gl_Position;",
 
 			"}"
@@ -316,7 +242,7 @@ THREE.ShaderDeferred = {
 		uniforms: {
 
 			samplerLight: 	{ type: "t", value: null },
-			multiply:		{ type: "f", value: 1 }
+			brightness:		{ type: "f", value: 1 }
 
 		},
 
@@ -324,12 +250,12 @@ THREE.ShaderDeferred = {
 
 			"varying vec2 texCoord;",
 			"uniform sampler2D samplerLight;",
-			"uniform float multiply;",
+			"uniform float brightness;",
 
 			"void main() {",
 
 				"vec3 color = texture2D( samplerLight, texCoord ).xyz;",
-				"gl_FragColor = vec4( multiply * sqrt( color ), 1.0 );",
+				"gl_FragColor = vec4( brightness * sqrt( color ), 1.0 );",
 
 			"}"
 
@@ -355,9 +281,8 @@ THREE.ShaderDeferred = {
 
 		uniforms: {
 
-			samplerNormals: { type: "t", value: null },
-			samplerDepth: 	{ type: "t", value: null },
-			samplerColor: 	{ type: "t", value: null },
+			samplerNormalDepth: { type: "t", value: null },
+			samplerColor: 		{ type: "t", value: null },
 			matView: 		{ type: "m4", value: new THREE.Matrix4() },
 			matProjInverse: { type: "m4", value: new THREE.Matrix4() },
 			viewWidth: 		{ type: "f", value: 800 },
@@ -375,8 +300,7 @@ THREE.ShaderDeferred = {
 			"varying vec4 clipPos;",
 
 			"uniform sampler2D samplerColor;",
-			"uniform sampler2D samplerDepth;",
-			"uniform sampler2D samplerNormals;",
+			"uniform sampler2D samplerNormalDepth;",
 
 			"uniform float lightRadius;",
 			"uniform float lightIntensity;",
@@ -402,17 +326,10 @@ THREE.ShaderDeferred = {
 
 				"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
 
-				"float z = texture2D( samplerDepth, texCoord ).x;",
-				"float lightZ = clipPos.z / clipPos.w;",
-
-				/*
-				"if ( z == 0.0 ) {",
-
-					"gl_FragColor = vec4( vec3( 0.0 ), 1.0 );",
-					"return;",
+				"vec4 normalDepth = texture2D( samplerNormalDepth, texCoord );",
 
-				"}",
-				*/
+				"float z = normalDepth.w;",
+				"float lightZ = clipPos.z / clipPos.w;",
 
 				"if ( z == 0.0 || lightZ > z ) discard;",
 
@@ -441,7 +358,7 @@ THREE.ShaderDeferred = {
 
 				// normal
 
-				"vec3 normal = texture2D( samplerNormals, texCoord ).xyz * 2.0 - 1.0;",
+				"vec3 normal = normalDepth.xyz * 2.0 - 1.0;",
 
 				// color
 
@@ -449,20 +366,31 @@ THREE.ShaderDeferred = {
 
 				"vec3 albedo = float_to_vec3( abs( colorMap.x ) );",
 				"vec3 specularColor = float_to_vec3( abs( colorMap.y ) );",
-				"float shininess = colorMap.z;",
+				"float shininess = abs( colorMap.z );",
+				"float wrapAround = sign( colorMap.z );",
 
-				// wrap around lighting
+				// light
+
+				"vec3 diffuse;",
 
 				"float diffuseFull = max( dot( normal, lightDir ), 0.0 );",
-				"float diffuseHalf = max( 0.5 + 0.5 * dot( normal, lightDir ), 0.0 );",
 
-				"const vec3 wrapRGB = vec3( 0.6, 0.2, 0.2 );",
-				"vec3 diffuse = mix( vec3 ( diffuseFull ), vec3( diffuseHalf ), wrapRGB );",
+				"if ( wrapAround < 0.0 ) {",
 
-				// simple lighting
+					// wrap around lighting
 
-				//"float diffuseFull = max( dot( normal, lightDir ), 0.0 );",
-				//"vec3 diffuse = vec3 ( diffuseFull );",
+					"float diffuseHalf = max( 0.5 + 0.5 * dot( normal, lightDir ), 0.0 );",
+
+					"const vec3 wrapRGB = vec3( 0.6, 0.2, 0.2 );",
+					"diffuse = mix( vec3( diffuseFull ), vec3( diffuseHalf ), wrapRGB );",
+
+				"} else {",
+
+					// simple lighting
+
+					"diffuse = vec3( diffuseFull );",
+
+				"}",
 
 				// specular
 
@@ -484,15 +412,17 @@ THREE.ShaderDeferred = {
 
 				"vec3 light = lightIntensity * lightColor;",
 
-				"#ifdef ADDITIVE_SPECULAR",
+				"float additiveSpecular = sign( colorMap.y );",
+
+				"if ( additiveSpecular < 0.0 ) {",
 
 					"gl_FragColor = vec4( albedo * light * diffuse, attenuation ) + vec4( light * specular, attenuation );",
 
-				"#else",
+				"} else {",
 
 					"gl_FragColor = vec4( albedo * light * ( diffuse + specular ), attenuation );",
 
-				"#endif",
+				"}",
 
 			"}"
 
@@ -522,9 +452,8 @@ THREE.ShaderDeferred = {
 
 		uniforms: {
 
-			samplerNormals: { type: "t", value: null },
-			samplerDepth: 	{ type: "t", value: null },
-			samplerColor: 	{ type: "t", value: null },
+			samplerNormalDepth: { type: "t", value: null },
+			samplerColor: 		{ type: "t", value: null },
 			matView: 		{ type: "m4", value: new THREE.Matrix4() },
 			matProjInverse: { type: "m4", value: new THREE.Matrix4() },
 			viewWidth: 		{ type: "f", value: 800 },
@@ -541,8 +470,7 @@ THREE.ShaderDeferred = {
 			"varying vec4 clipPos;",
 
 			"uniform sampler2D samplerColor;",
-			"uniform sampler2D samplerDepth;",
-			"uniform sampler2D samplerNormals;",
+			"uniform sampler2D samplerNormalDepth;",
 
 			"uniform float lightRadius;",
 			"uniform float lightIntensity;",
@@ -568,7 +496,8 @@ THREE.ShaderDeferred = {
 
 				"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
 
-				"float z = texture2D( samplerDepth, texCoord ).x;",
+				"vec4 normalDepth = texture2D( samplerNormalDepth, texCoord );",
+				"float z = normalDepth.w;",
 
 				"if ( z == 0.0 ) discard;",
 
@@ -585,7 +514,7 @@ THREE.ShaderDeferred = {
 
 				// normal
 
-				"vec3 normal = texture2D( samplerNormals, texCoord ).xyz * 2.0 - 1.0;",
+				"vec3 normal = normalDepth.xyz * 2.0 - 1.0;",
 
 				// color
 
@@ -665,7 +594,6 @@ THREE.ShaderDeferred = {
 
 		uniforms: {
 
-			samplerDepth: 	{ type: "t", value: null },
 			samplerColor: 	{ type: "t", value: null },
 			viewWidth: 		{ type: "f", value: 800 },
 			viewHeight: 	{ type: "f", value: 600 },
@@ -674,7 +602,6 @@ THREE.ShaderDeferred = {
 
 		fragmentShader : [
 
-			"uniform sampler2D samplerDepth;",
 			"uniform sampler2D samplerColor;",
 
 			"uniform float viewHeight;",
@@ -695,10 +622,6 @@ THREE.ShaderDeferred = {
 
 				"vec2 texCoord = gl_FragCoord.xy / vec2( viewWidth, viewHeight );",
 
-				"float z = texture2D( samplerDepth, texCoord ).x;",
-
-				"if ( z == 0.0 ) discard;",
-
 				"vec4 colorMap = texture2D( samplerColor, texCoord );",
 				"vec3 emissiveColor = float_to_vec3( abs( colorMap.w ) );",
 

+ 79 - 119
examples/js/renderers/WebGLDeferredRenderer.js

@@ -14,8 +14,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 	var scaledWidth = Math.floor( scale * width );
 	var scaledHeight = Math.floor( scale * height );
 
-	var additiveSpecular = parameters.additiveSpecular;
-	var multiply = parameters.multiply;
+	var brightness = parameters.brightness;
 
 	this.renderer = parameters.renderer;
 
@@ -23,7 +22,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 
 		this.renderer = new THREE.WebGLRenderer( { alpha: false } );
 		this.renderer.setSize( width, height );
-		this.renderer.setClearColorHex( 0x000000, 1 );
+		this.renderer.setClearColorHex( 0x000000, 0 );
 
 		this.renderer.autoClear = false;
 
@@ -39,9 +38,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 	var black = new THREE.Color( 0x000000 );
 
 	var colorShader = THREE.ShaderDeferred[ "color" ];
-	var normalShader = THREE.ShaderDeferred[ "normals" ];
-	var bumpShader = THREE.ShaderDeferred[ "bump" ];
-	var clipDepthShader = THREE.ShaderDeferred[ "clipDepth" ];
+	var normalDepthShader = THREE.ShaderDeferred[ "normalDepth" ];
 
 	//
 
@@ -65,19 +62,11 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 
 	//
 
-	var defaultNormalMaterial = new THREE.ShaderMaterial( {
+	var defaultNormalDepthMaterial = new THREE.ShaderMaterial( {
 
-		uniforms:       THREE.UniformsUtils.clone( normalShader.uniforms ),
-		vertexShader:   normalShader.vertexShader,
-		fragmentShader: normalShader.fragmentShader
-
-	} );
-
-	var defaultDepthMaterial = new THREE.ShaderMaterial( {
-
-		uniforms:       THREE.UniformsUtils.clone( clipDepthShader.uniforms ),
-		vertexShader:   clipDepthShader.vertexShader,
-		fragmentShader: clipDepthShader.fragmentShader
+		uniforms:       THREE.UniformsUtils.clone( normalDepthShader.uniforms ),
+		vertexShader:   normalDepthShader.vertexShader,
+		fragmentShader: normalDepthShader.fragmentShader
 
 	} );
 
@@ -88,8 +77,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 		if ( object.material instanceof THREE.MeshFaceMaterial ) {
 
 			var colorMaterials = [];
-			var depthMaterials = [];
-			var normalMaterials = [];
+			var normalDepthMaterials = [];
 
 			var materials = object.material.materials;
 
@@ -98,22 +86,19 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 				var deferredMaterials = createDeferredMaterials( materials[ i ] );
 
 				colorMaterials.push( deferredMaterials.colorMaterial );
-				depthMaterials.push( deferredMaterials.depthMaterial );
-				normalMaterials.push( deferredMaterials.normalMaterial );
+				normalDepthMaterials.push( deferredMaterials.normalDepthMaterial );
 
 			}
 
 			object.properties.colorMaterial = new THREE.MeshFaceMaterial( colorMaterials );
-			object.properties.depthMaterial = new THREE.MeshFaceMaterial( depthMaterials );
-			object.properties.normalMaterial = new THREE.MeshFaceMaterial( normalMaterials );
+			object.properties.normalDepthMaterial = new THREE.MeshFaceMaterial( normalDepthMaterials );
 
 		} else {
 
 			var deferredMaterials = createDeferredMaterials( object.material );
 
 			object.properties.colorMaterial = deferredMaterials.colorMaterial;
-			object.properties.depthMaterial = deferredMaterials.depthMaterial;
-			object.properties.normalMaterial = deferredMaterials.normalMaterial;
+			object.properties.normalDepthMaterial = deferredMaterials.normalDepthMaterial;
 
 		}
 
@@ -161,11 +146,15 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 
 		var specular = originalMaterial.specular !== undefined ? originalMaterial.specular : black;
 		var shininess = originalMaterial.shininess !== undefined ? originalMaterial.shininess : 1;
+		var wrapAround = originalMaterial.wrapAround !== undefined ? ( originalMaterial.wrapAround ? -1 : 1 ) : 1;
+		var additiveSpecular = originalMaterial.metal !== undefined ? ( originalMaterial.metal ? 1 : -1 ) : -1;
 
 		uniforms.emissive.value.copy( emissive );
 		uniforms.diffuse.value.copy( diffuse );
 		uniforms.specular.value.copy( specular );
 		uniforms.shininess.value = shininess;
+		uniforms.wrapAround.value = wrapAround;
+		uniforms.additiveSpecular.value = additiveSpecular;
 
 		uniforms.map.value = originalMaterial.map;
 
@@ -186,77 +175,54 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 
 		deferredMaterials.colorMaterial = material;
 
-		// normal material
+		// normal + depth material
 		// -----------------
 		//	vertex normals
 		//	morph normals
 		//	bump map
 		//	bump scale
+		//  clip depth
 
-		if ( originalMaterial.bumpMap ) {
+		if ( originalMaterial.morphTargets || originalMaterial.bumpMap ) {
 
-			var uniforms = THREE.UniformsUtils.clone( bumpShader.uniforms );
+			var uniforms = THREE.UniformsUtils.clone( normalDepthShader.uniforms );
+			var defines = { "USE_BUMPMAP": !!originalMaterial.bumpMap };
 
-			var normalMaterial = new THREE.ShaderMaterial( {
+			var normalDepthMaterial = new THREE.ShaderMaterial( {
 
-				uniforms: 		uniforms,
-				vertexShader: 	bumpShader.vertexShader,
-				fragmentShader: bumpShader.fragmentShader,
-				defines:		{ "USE_BUMPMAP": true }
+				uniforms:       uniforms,
+				vertexShader:   normalDepthShader.vertexShader,
+				fragmentShader: normalDepthShader.fragmentShader,
+				shading:		originalMaterial.shading,
+				defines:		defines,
+				blending:		THREE.NoBlending
 
 			} );
 
-			uniforms.bumpMap.value = originalMaterial.bumpMap;
-			uniforms.bumpScale.value = originalMaterial.bumpScale;
-
-			var offset = originalMaterial.bumpMap.offset;
-			var repeat = originalMaterial.bumpMap.repeat;
-
-			uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
+			if ( originalMaterial.morphTargets ) {
 
-			deferredMaterials.normalMaterial = normalMaterial;
-
-		} else if ( originalMaterial.morphTargets ) {
-
-			var normalMaterial = new THREE.ShaderMaterial( {
-
-				uniforms:       THREE.UniformsUtils.clone( normalShader.uniforms ),
-				vertexShader:   normalShader.vertexShader,
-				fragmentShader: normalShader.fragmentShader,
-				shading:		originalMaterial.shading
-
-			} );
-
-			normalMaterial.morphTargets = originalMaterial.morphTargets;
-			normalMaterial.morphNormals = originalMaterial.morphNormals;
-
-			deferredMaterials.normalMaterial = normalMaterial;
-
-		} else {
+				normalDepthMaterial.morphTargets = originalMaterial.morphTargets;
+				normalDepthMaterial.morphNormals = originalMaterial.morphNormals;
 
-			deferredMaterials.normalMaterial = defaultNormalMaterial;
-
-		}
-
-		// depth material
+			}
 
-		if ( originalMaterial.morphTargets ) {
+			if ( originalMaterial.bumpMap ) {
 
-			var depthMaterial = new THREE.ShaderMaterial( {
+				uniforms.bumpMap.value = originalMaterial.bumpMap;
+				uniforms.bumpScale.value = originalMaterial.bumpScale;
 
-				uniforms:       THREE.UniformsUtils.clone( clipDepthShader.uniforms ),
-				vertexShader:   clipDepthShader.vertexShader,
-				fragmentShader: clipDepthShader.fragmentShader
+				var offset = originalMaterial.bumpMap.offset;
+				var repeat = originalMaterial.bumpMap.repeat;
 
-			} );
+				uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
 
-			depthMaterial.morphTargets = originalMaterial.morphTargets;
+			}
 
-			deferredMaterials.depthMaterial = depthMaterial;
+			deferredMaterials.normalDepthMaterial = normalDepthMaterial;
 
 		} else {
 
-			deferredMaterials.depthMaterial = defaultDepthMaterial;
+			deferredMaterials.normalDepthMaterial = defaultNormalDepthMaterial;
 
 		}
 
@@ -273,7 +239,6 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 			uniforms:       THREE.UniformsUtils.clone( pointLightShader.uniforms ),
 			vertexShader:   pointLightShader.vertexShader,
 			fragmentShader: pointLightShader.fragmentShader,
-			defines:		{ "ADDITIVE_SPECULAR": additiveSpecular },
 
 			blending:		THREE.AdditiveBlending,
 			depthWrite:		false,
@@ -290,8 +255,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
 
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
-		materialLight.uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
-		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
+		materialLight.uniforms[ 'samplerNormalDepth' ].value = compNormalDepth.renderTarget2;
 
 		// create light proxy mesh
 
@@ -316,7 +280,6 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 			uniforms:       THREE.UniformsUtils.clone( directionalLightShader.uniforms ),
 			vertexShader:   directionalLightShader.vertexShader,
 			fragmentShader: directionalLightShader.fragmentShader,
-			defines:		{ "ADDITIVE_SPECULAR": additiveSpecular },
 
 			blending:		THREE.AdditiveBlending,
 			depthWrite:		false,
@@ -332,8 +295,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
 
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
-		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
-		materialLight.uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
+		materialLight.uniforms[ 'samplerNormalDepth' ].value = compNormalDepth.renderTarget2;
 
 		// create light proxy mesh
 
@@ -358,7 +320,8 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 			vertexShader:   emissiveLightShader.vertexShader,
 			fragmentShader: emissiveLightShader.fragmentShader,
 			depthTest:		false,
-			depthWrite:		false
+			depthWrite:		false,
+			blending:		THREE.NoBlending
 
 		} );
 
@@ -367,7 +330,6 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 		materialLight.uniforms[ "viewHeight" ].value = scaledHeight;
 
 		materialLight.uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
-		materialLight.uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
 
 		// create light proxy mesh
 
@@ -412,15 +374,9 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 
 	};
 
-	var setMaterialDepth = function ( object ) {
-
-		if ( object.material ) object.material = object.properties.depthMaterial;
-
-	};
-
-	var setMaterialNormal = function ( object ) {
+	var setMaterialNormalDepth = function ( object ) {
 
-		if ( object.material ) object.material = object.properties.normalMaterial;
+		if ( object.material ) object.material = object.properties.normalDepthMaterial;
 
 	};
 
@@ -434,8 +390,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 		scaledHeight = Math.floor( scale * height );
 
 		compColor.setSize( scaledWidth, scaledHeight );
-		compNormal.setSize( scaledWidth, scaledHeight );
-		compDepth.setSize( scaledWidth, scaledHeight );
+		compNormalDepth.setSize( scaledWidth, scaledHeight );
 		compLight.setSize( scaledWidth, scaledHeight );
 		compFinal.setSize( scaledWidth, scaledHeight );
 
@@ -447,11 +402,10 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 			uniforms[ "viewHeight" ].value = scaledHeight;
 
 			uniforms[ 'samplerColor' ].value = compColor.renderTarget2;
-			uniforms[ 'samplerDepth' ].value = compDepth.renderTarget2;
 
-			if ( uniforms[ 'samplerNormals' ] ) {
+			if ( uniforms[ 'samplerNormalDepth' ] ) {
 
-				uniforms[ 'samplerNormals' ].value = compNormal.renderTarget2;
+				uniforms[ 'samplerNormalDepth' ].value = compNormalDepth.renderTarget2;
 
 			}
 
@@ -483,33 +437,33 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 		lightSceneFullscreen = scene.properties.lightSceneFullscreen;
 
 		passColor.camera = camera;
-		passNormal.camera = camera;
-		passDepth.camera = camera;
+		passNormalDepth.camera = camera;
 		passLightProxy.camera = camera;
 		passLightFullscreen.camera = THREE.EffectComposer.camera;
 
 		passColor.scene = scene;
-		passNormal.scene = scene;
-		passDepth.scene = scene;
+		passNormalDepth.scene = scene;
 		passLightFullscreen.scene = lightSceneFullscreen;
 		passLightProxy.scene = lightSceneProxy;
 
 		scene.traverse( initDeferredProperties );
 
+		// update scene graph only once per frame
+
+		this.renderer.autoUpdateScene = false;
+		scene.updateMatrixWorld();
+
 		// g-buffer color
 
 		scene.traverse( setMaterialColor );
 		compColor.render();
 
-		// g-buffer depth
-
-		scene.traverse( setMaterialDepth );
-		compDepth.render();
+		// g-buffer normals + depth
 
-		// g-buffer normals
+		scene.traverse( setMaterialNormalDepth );
+		compNormalDepth.render();
 
-		scene.traverse( setMaterialNormal );
-		compNormal.render();
+		this.renderer.autoUpdateScene = true;
 
 		// light pass
 
@@ -554,32 +508,36 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 		// g-buffers
 
 		var rtColor   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatNearest );
-		var rtNormal  = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
-		var rtDepth   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
+		var rtNormalDepth = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
 		var rtLight   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsFloatLinear );
 		var rtFinal   = new THREE.WebGLRenderTarget( scaledWidth, scaledHeight, rtParamsUByte );
 
 		rtColor.generateMipmaps = false;
-		rtNormal.generateMipmaps = false;
-		rtDepth.generateMipmaps = false;
+		rtNormalDepth.generateMipmaps = false;
 		rtLight.generateMipmaps = false;
 		rtFinal.generateMipmaps = false;
 
-		// composers
+		// color composer
 
 		passColor = new THREE.RenderPass();
+		passColor.clear = true;
+
 		compColor = new THREE.EffectComposer( _this.renderer, rtColor );
 		compColor.addPass( passColor );
 
-		passNormal = new THREE.RenderPass();
-		compNormal = new THREE.EffectComposer( _this.renderer, rtNormal );
-		compNormal.addPass( passNormal );
+		// normal + depth composer
+
+		passNormalDepth = new THREE.RenderPass();
+		passNormalDepth.clear = true;
 
-		passDepth = new THREE.RenderPass();
-		compDepth = new THREE.EffectComposer( _this.renderer, rtDepth );
-		compDepth.addPass( passDepth );
+		compNormalDepth = new THREE.EffectComposer( _this.renderer, rtNormalDepth );
+		compNormalDepth.addPass( passNormalDepth );
+
+		// light composer
 
 		passLightFullscreen = new THREE.RenderPass();
+		passLightFullscreen.clear = true;
+
 		passLightProxy = new THREE.RenderPass();
 		passLightProxy.clear = false;
 
@@ -587,11 +545,13 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
 		compLight.addPass( passLightFullscreen );
 		compLight.addPass( passLightProxy );
 
-		// composite
+		// final composer
 
 		compositePass = new THREE.ShaderPass( compositeShader );
 		compositePass.uniforms[ 'samplerLight' ].value = compLight.renderTarget2;
-		compositePass.uniforms[ 'multiply' ].value = multiply;
+		compositePass.uniforms[ 'brightness' ].value = brightness;
+		compositePass.material.blending = THREE.NoBlending;
+		compositePass.clear = true;
 
 		// FXAA
 

+ 2 - 2
examples/webgl_lights_deferred_morphs.html

@@ -111,7 +111,7 @@
 
 				// renderer
 
-				renderer = new THREE.WebGLDeferredRenderer( { width: WIDTH, height: HEIGHT, scale: SCALE, multiply: 2, additiveSpecular: true } );
+				renderer = new THREE.WebGLDeferredRenderer( { width: WIDTH, height: HEIGHT, scale: SCALE, brightness: 2 } );
 
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.top = MARGIN + "px";
@@ -215,7 +215,7 @@
 
 					geometry.computeMorphNormals();
 
-					var material = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x333333, shininess: 20, morphTargets: true, morphNormals: true, vertexColors: THREE.NoColors, shading: THREE.FlatShading } );
+					var material = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x333333, shininess: 20, wrapAround: true, morphTargets: true, morphNormals: true, vertexColors: THREE.NoColors, shading: THREE.FlatShading } );
 					var meshAnim = new THREE.MorphAnimMesh( geometry, material );
 
 					meshAnim.duration = 3000;

+ 5 - 5
examples/webgl_lights_deferred_pointlights.html

@@ -111,7 +111,7 @@
 
 				// renderer
 
-				renderer = new THREE.WebGLDeferredRenderer( { width: WIDTH, height: HEIGHT, scale: SCALE, additiveSpecular: false, multiply: 2 } );
+				renderer = new THREE.WebGLDeferredRenderer( { width: WIDTH, height: HEIGHT, scale: SCALE, brightness: 2 } );
 
 				renderer.domElement.style.position = "absolute";
 				renderer.domElement.style.top = MARGIN + "px";
@@ -242,7 +242,7 @@
 					mapHeight.anisotropy = 4;
 					mapHeight.format = THREE.RGBFormat;
 
-					var material = new THREE.MeshPhongMaterial( { map: mapColor, bumpMap: mapHeight, bumpScale: 2.5, shininess: 75, specular: 0x090909 } );
+					var material = new THREE.MeshPhongMaterial( { map: mapColor, bumpMap: mapHeight, bumpScale: 2.5, shininess: 75, specular: 0x090909, wrapAround: true, metal: true } );
 
 					var object = new THREE.Mesh( geometry, material );
 					object.scale.multiplyScalar( 8 );
@@ -254,7 +254,7 @@
 				var loader = new THREE.BinaryLoader();
 				loader.load( "obj/female02/Female02_bin.js", function( geometry, materials ) {
 
-					var material = new THREE.MeshPhongMaterial( { shininess: 175, specular: 0x999999 } );
+					for ( var i = 0; i < materials.length; i ++ ) materials[ i ].wrapAround = true;
 
 					var object = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
 					object.position.x = -50;
@@ -266,7 +266,7 @@
 
 				loader.load( "obj/male02/Male02_bin.js", function( geometry, materials ) {
 
-					var material = new THREE.MeshPhongMaterial( { shininess: 175, specular: 0x999999 } );
+					for ( var i = 0; i < materials.length; i ++ ) materials[ i ].wrapAround = true;
 
 					var object = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial( materials ) );
 					object.position.x = 50;
@@ -306,7 +306,7 @@
 
 				var matPlane  = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess:  50, bumpMap: mapHeight2, bumpScale: 0.5 } );
 				var matPlane2 = new THREE.MeshPhongMaterial( { color: 0x331919, specular: 0x111111, shininess:  50, bumpMap: mapHeight2, bumpScale: 1 } );
-				var matPlane3 = new THREE.MeshPhongMaterial( { color: 0x00aaff, specular: 0xffffff, shininess: 200, bumpMap: mapHeight3, bumpScale: 1.2 } );
+				var matPlane3 = new THREE.MeshPhongMaterial( { color: 0x00aaff, specular: 0xffffff, shininess: 200, bumpMap: mapHeight3, bumpScale: 1.2, wrapAround: true } );
 				var matPlane4 = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess:  50, bumpMap: mapHeight3, bumpScale: 1 } );
 
 				// bottom

+ 4 - 7
src/renderers/WebGLShaders.js

@@ -268,19 +268,16 @@ THREE.ShaderChunk = {
 
 		"#ifdef USE_MAP",
 
+			"vec4 texelColor = texture2D( map, vUv );",
+
 			"#ifdef GAMMA_INPUT",
 
-				"vec4 texelColor = texture2D( map, vUv );",
 				"texelColor.xyz *= texelColor.xyz;",
 
-				"gl_FragColor = gl_FragColor * texelColor;",
-
-			"#else",
-
-				"gl_FragColor = gl_FragColor * texture2D( map, vUv );",
-
 			"#endif",
 
+			"gl_FragColor = gl_FragColor * texelColor;",
+
 		"#endif"
 
 	].join("\n"),

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini