Explorar el Código

Replaced basic shader with custom shader in deferred shading.

This is in anticipation of combining more geometry passes, need modifiable shader.
alteredq hace 12 años
padre
commit
61c9e5f119

+ 82 - 0
examples/js/ShaderDeferred.js

@@ -7,6 +7,88 @@
 
 THREE.ShaderDeferred = {
 
+	"color" : {
+
+		uniforms: THREE.UniformsUtils.merge( [
+
+			THREE.UniformsLib[ "common" ],
+			THREE.UniformsLib[ "fog" ],
+			THREE.UniformsLib[ "shadowmap" ]
+
+		] ),
+
+		fragmentShader : [
+
+			"uniform vec3 diffuse;",
+			"uniform float opacity;",
+
+			THREE.ShaderChunk[ "color_pars_fragment" ],
+			THREE.ShaderChunk[ "map_pars_fragment" ],
+			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
+			THREE.ShaderChunk[ "envmap_pars_fragment" ],
+			THREE.ShaderChunk[ "fog_pars_fragment" ],
+			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
+			THREE.ShaderChunk[ "specularmap_pars_fragment" ],
+
+			"void main() {",
+
+				"gl_FragColor = vec4( diffuse, opacity );",
+
+				THREE.ShaderChunk[ "map_fragment" ],
+				THREE.ShaderChunk[ "alphatest_fragment" ],
+				THREE.ShaderChunk[ "specularmap_fragment" ],
+				THREE.ShaderChunk[ "lightmap_fragment" ],
+				THREE.ShaderChunk[ "color_fragment" ],
+				THREE.ShaderChunk[ "envmap_fragment" ],
+				THREE.ShaderChunk[ "shadowmap_fragment" ],
+
+				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
+
+				THREE.ShaderChunk[ "fog_fragment" ],
+
+			"}"
+
+		].join("\n"),
+
+		vertexShader : [
+
+			THREE.ShaderChunk[ "map_pars_vertex" ],
+			THREE.ShaderChunk[ "lightmap_pars_vertex" ],
+			THREE.ShaderChunk[ "envmap_pars_vertex" ],
+			THREE.ShaderChunk[ "color_pars_vertex" ],
+			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
+			THREE.ShaderChunk[ "skinning_pars_vertex" ],
+			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
+
+			"void main() {",
+
+				THREE.ShaderChunk[ "map_vertex" ],
+				THREE.ShaderChunk[ "lightmap_vertex" ],
+				THREE.ShaderChunk[ "color_vertex" ],
+
+				"#ifdef USE_ENVMAP",
+
+				THREE.ShaderChunk[ "morphnormal_vertex" ],
+				THREE.ShaderChunk[ "skinbase_vertex" ],
+				THREE.ShaderChunk[ "skinnormal_vertex" ],
+				THREE.ShaderChunk[ "defaultnormal_vertex" ],
+
+				"#endif",
+
+				THREE.ShaderChunk[ "morphtarget_vertex" ],
+				THREE.ShaderChunk[ "skinning_vertex" ],
+				THREE.ShaderChunk[ "default_vertex" ],
+
+				THREE.ShaderChunk[ "worldpos_vertex" ],
+				THREE.ShaderChunk[ "envmap_vertex" ],
+				THREE.ShaderChunk[ "shadowmap_vertex" ],
+
+			"}"
+
+		].join("\n")
+
+	},
+
 	"clipDepth" : {
 
 		uniforms: { },

+ 5 - 6
examples/webgl_lights_deferred_morphs.html

@@ -109,7 +109,7 @@
 
 			// materials
 
-			var normalShader, bumpShader, clipDepthShader, lightShader, unlitShader, compositeShader;
+			var colorShader, normalShader, bumpShader, clipDepthShader, lightShader, unlitShader, compositeShader;
 			var matNormal, matClipDepth, matBasic, matUnlit;
 
 			// lights
@@ -327,21 +327,19 @@
 
 			function initScene( object, y, scale ) {
 
-				var shader = THREE.ShaderLib[ "basic" ];
-
 				object.traverse( function( node ) {
 
 					if ( node.material ) {
 
 						// color material
 
-						var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
+						var uniforms = THREE.UniformsUtils.clone( colorShader.uniforms );
 						var defines = { "USE_MAP": !!node.material.map, "GAMMA_INPUT": true };
 
 						var material = new THREE.ShaderMaterial( {
 
-							fragmentShader: shader.fragmentShader,
-							vertexShader: 	shader.vertexShader,
+							fragmentShader: colorShader.fragmentShader,
+							vertexShader: 	colorShader.vertexShader,
 							uniforms: 		uniforms,
 							defines: 		defines,
 							shading:		node.material.shading
@@ -464,6 +462,7 @@
 				// shader definitions
 				// -----------------------
 
+				colorShader = THREE.ShaderDeferred[ "color" ];
 				normalShader = THREE.ShaderDeferred[ "normals" ];
 				bumpShader = THREE.ShaderDeferred[ "bump" ];
 				clipDepthShader = THREE.ShaderDeferred[ "clipDepth" ];

+ 12 - 5
examples/webgl_lights_deferred_pointlights.html

@@ -112,7 +112,7 @@
 
 			// materials
 
-			var compColor, compNormals, compDepth, compLightBuffer, compFinal, compEmitter, compositePass;
+			var colorShader, normalShader, bumpShader, clipDepthShader, lightShader, unlitShader, compositeShader;
 			var matNormal, matClipDepth, matBasic, matUnlit;
 
 			var numLights = 50;
@@ -331,18 +331,24 @@
 
 			function initScene( object, y, scale ) {
 
-				var shader = THREE.ShaderLib[ "basic" ];
-
 				object.traverse( function( node ) {
 
 					if ( node.material ) {
 
 						// color material
 
-						var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
+						var uniforms = THREE.UniformsUtils.clone( colorShader.uniforms );
 						var defines = { "USE_MAP": !!node.material.map, "GAMMA_INPUT": true };
 
-						var material = new THREE.ShaderMaterial( { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, defines: defines } );
+						var material = new THREE.ShaderMaterial( {
+
+							fragmentShader: colorShader.fragmentShader,
+							vertexShader: 	colorShader.vertexShader,
+							uniforms: 		uniforms,
+							defines: 		defines
+
+						} );
+
 						uniforms.diffuse.value.copy( node.material.color );
 						uniforms.map.value = node.material.map;
 
@@ -420,6 +426,7 @@
 				// shader definitions
 				// -----------------------
 
+				colorShader = THREE.ShaderDeferred[ "color" ];
 				normalShader = THREE.ShaderDeferred[ "normals" ];
 				bumpShader = THREE.ShaderDeferred[ "bump" ];
 				clipDepthShader = THREE.ShaderDeferred[ "clipDepth" ];