Browse Source

fix ALPHATEST and cleanup

sunag 7 years ago
parent
commit
5da506d3c9

+ 17 - 16
examples/js/nodes/core/NodeBuilder.js

@@ -64,7 +64,7 @@ function NodeBuilder() {
 	this.attributes = {};
 	
 	this.prefixCode = [
-		"#ifdef GL_EXT_shader_texture_lod",
+		"#ifdef TEXTURE_LOD_EXT",
 
 		"	#define texCube(a, b) textureCube(a, b)",
 		"	#define texCubeBias(a, b, c) textureCubeLodEXT(a, b, c)",
@@ -82,7 +82,8 @@ function NodeBuilder() {
 
 		"#endif",
 
-		"#include <packing>"
+		"#include <packing>",
+		"#include <common>"
 
 	].join( "\n" );
 	
@@ -817,30 +818,30 @@ NodeBuilder.prototype = {
 
 		switch ( typeToType ) {
 
-			case 'f <- v2': return code + '.x';
-			case 'f <- v3': return code + '.x';
-			case 'f <- v4': return code + '.x';
-			case 'f <- i': return 'float( ' + code + ' )';
+			case 'f <- v2' : return code + '.x';
+			case 'f <- v3' : return code + '.x';
+			case 'f <- v4' : return code + '.x';
+			case 'f <- i'  : return 'float( ' + code + ' )';
 
-			case 'v2 <- f': return 'vec2( ' + code + ' )';
+			case 'v2 <- f' : return 'vec2( ' + code + ' )';
 			case 'v2 <- v3': return code + '.xy';
 			case 'v2 <- v4': return code + '.xy';
-			case 'v2 <- i': return 'vec2( float( ' + code + ' ) )';
+			case 'v2 <- i' : return 'vec2( float( ' + code + ' ) )';
 
-			case 'v3 <- f': return 'vec3( ' + code + ' )';
+			case 'v3 <- f' : return 'vec3( ' + code + ' )';
 			case 'v3 <- v2': return 'vec3( ' + code + ', 0.0 )';
 			case 'v3 <- v4': return code + '.xyz';
-			case 'v3 <- i': return 'vec2( float( ' + code + ' ) )';
+			case 'v3 <- i' : return 'vec2( float( ' + code + ' ) )';
 
-			case 'v4 <- f': return 'vec4( ' + code + ' )';
+			case 'v4 <- f' : return 'vec4( ' + code + ' )';
 			case 'v4 <- v2': return 'vec4( ' + code + ', 0.0, 1.0 )';
 			case 'v4 <- v3': return 'vec4( ' + code + ', 1.0 )';
-			case 'v4 <- i': return 'vec4( float( ' + code + ' ) )';
+			case 'v4 <- i' : return 'vec4( float( ' + code + ' ) )';
 
-			case 'i <- f': return 'int( ' + code + ' )';
-			case 'i <- v2': return 'int( ' + code + '.x )';
-			case 'i <- v3': return 'int( ' + code + '.x )';
-			case 'i <- v4': return 'int( ' + code + '.x )';
+			case 'i <- f'  : return 'int( ' + code + ' )';
+			case 'i <- v2' : return 'int( ' + code + '.x )';
+			case 'i <- v3' : return 'int( ' + code + '.x )';
+			case 'i <- v4' : return 'int( ' + code + '.x )';
 
 		}
 

+ 4 - 0
examples/js/nodes/materials/nodes/MeshStandardNode.js

@@ -75,6 +75,10 @@ MeshStandardNode.prototype.build = function ( builder ) {
 			this.normal = new NormalMapNode( builder.resolve( props.normalMap ) );
 			this.normal.scale = builder.findNode( props.normalScale, inputs.normalScale );
 
+		} else {
+			
+			this.normal = undefined;
+			
 		}
 
 		// slots

+ 5 - 4
examples/js/nodes/materials/nodes/PhongNode.js

@@ -25,7 +25,6 @@ PhongNode.prototype.build = function ( builder ) {
 	var code;
 
 	builder.define( 'PHONG' );
-	builder.define( 'ALPHATEST', '0.0' );
 
 	builder.requires.lights = true;
 
@@ -49,7 +48,6 @@ PhongNode.prototype.build = function ( builder ) {
 
 			"#endif",
 
-			"#include <common>",
 			//"#include <encodings_pars_fragment>", // encoding functions
 			"#include <fog_pars_vertex>",
 			"#include <morphtarget_pars_vertex>",
@@ -148,7 +146,6 @@ PhongNode.prototype.build = function ( builder ) {
 		builder.requires.transparent = alpha != undefined;
 
 		builder.addParsCode( [
-			"#include <common>",
 			"#include <fog_pars_fragment>",
 			"#include <bsdfs>",
 			"#include <lights_pars_begin>",
@@ -183,7 +180,11 @@ PhongNode.prototype.build = function ( builder ) {
 
 			output.push(
 				alpha.code,
-				'if ( ' + alpha.result + ' <= ALPHATEST ) discard;'
+				'#ifdef ALPHATEST',
+				
+					'if ( ' + alpha.result + ' <= ALPHATEST ) discard;',
+					
+				'#endif'
 			);
 
 		}

+ 5 - 4
examples/js/nodes/materials/nodes/SpriteNode.js

@@ -23,7 +23,6 @@ SpriteNode.prototype.build = function ( builder ) {
 	var output, code;
 
 	builder.define( 'SPRITE' );
-	builder.define( 'ALPHATEST', '0.0' );
 
 	builder.requires.lights = false;
 	builder.requires.transparent = this.alpha !== undefined;
@@ -37,7 +36,6 @@ SpriteNode.prototype.build = function ( builder ) {
 		] ) );
 
 		builder.addParsCode( [
-			"#include <common>",
 			"#include <fog_pars_vertex>",
 			"#include <logdepthbuf_pars_vertex>",
 			"#include <clipping_planes_pars_vertex>"
@@ -113,7 +111,6 @@ SpriteNode.prototype.build = function ( builder ) {
 	} else {
 
 		builder.addParsCode( [
-			"#include <common>",
 			"#include <fog_pars_fragment>",
 			"#include <logdepthbuf_pars_fragment>",
 			"#include <clipping_planes_pars_fragment>"
@@ -139,7 +136,11 @@ SpriteNode.prototype.build = function ( builder ) {
 
 			output = [
 				alpha.code,
-				'if ( ' + alpha.result + ' <= ALPHATEST ) discard;',
+				'#ifdef ALPHATEST',
+				
+					'if ( ' + alpha.result + ' <= ALPHATEST ) discard;',
+					
+				'#endif',
 				color.code,
 				"gl_FragColor = vec4( " + color.result + ", " + alpha.result + " );"
 			];

+ 5 - 4
examples/js/nodes/materials/nodes/StandardNode.js

@@ -26,7 +26,6 @@ StandardNode.prototype.build = function ( builder ) {
 	var code;
 
 	builder.define( this.clearCoat || this.clearCoatRoughness ? 'PHYSICAL' : 'STANDARD' );
-	builder.define( 'ALPHATEST', '0.0' );
 
 	builder.requires.lights = true;
 
@@ -52,7 +51,6 @@ StandardNode.prototype.build = function ( builder ) {
 
 			"#endif",
 
-			"#include <common>",
 			//"#include <encodings_pars_fragment>", // encoding functions
 			"#include <fog_pars_vertex>",
 			"#include <morphtarget_pars_vertex>",
@@ -181,7 +179,6 @@ StandardNode.prototype.build = function ( builder ) {
 
 			"#endif",
 
-			"#include <common>",
 			"#include <dithering_pars_fragment>",
 			"#include <fog_pars_fragment>",
 			"#include <bsdfs>",
@@ -219,7 +216,11 @@ StandardNode.prototype.build = function ( builder ) {
 
 			output.push(
 				alpha.code,
-				'if ( ' + alpha.result + ' <= ALPHATEST ) discard;'
+				'#ifdef ALPHATEST',
+				
+					'if ( ' + alpha.result + ' <= ALPHATEST ) discard;',
+					
+				'#endif'
 			);
 
 		}

+ 1 - 1
examples/js/nodes/math/CondNode.js

@@ -14,7 +14,7 @@ function CondNode( a, b, ifNode, elseNode, op ) {
 	this.ifNode = ifNode;
 	this.elseNode = elseNode;
 
-	this.op = op || CondNode.EQUAL;
+	this.op = op;
 
 };
 

+ 1 - 1
examples/js/nodes/math/Math1Node.js

@@ -10,7 +10,7 @@ function Math1Node( a, method ) {
 
 	this.a = a;
 
-	this.method = method || Math1Node.SIN;
+	this.method = method;
 
 };
 

+ 1 - 1
examples/js/nodes/math/Math2Node.js

@@ -11,7 +11,7 @@ function Math2Node( a, b, method ) {
 	this.a = a;
 	this.b = b;
 
-	this.method = method || Math2Node.DISTANCE;
+	this.method = method;
 
 };
 

+ 1 - 1
examples/js/nodes/math/Math3Node.js

@@ -12,7 +12,7 @@ function Math3Node( a, b, c, method ) {
 	this.b = b;
 	this.c = c;
 
-	this.method = method || Math3Node.MIX;
+	this.method = method;
 
 };
 

+ 1 - 1
examples/js/nodes/math/OperatorNode.js

@@ -10,7 +10,7 @@ function OperatorNode( a, b, op ) {
 
 	this.a = a;
 	this.b = b;
-	this.op = op || OperatorNode.ADD;
+	this.op = op;
 
 };