|
@@ -3,12 +3,13 @@
|
|
|
*/
|
|
|
|
|
|
import { Node } from '../../core/Node.js';
|
|
|
+import { ColorNode } from '../../inputs/ColorNode.js';
|
|
|
|
|
|
function SimpleNode() {
|
|
|
|
|
|
- Node.call( this );
|
|
|
+ Node.call( this );
|
|
|
|
|
|
- this.color = new ColorNode( 0xFFFFFF );
|
|
|
+ this.color = new ColorNode( 0xFFFFFF );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -18,93 +19,106 @@ SimpleNode.prototype.nodeType = "Simple";
|
|
|
|
|
|
SimpleNode.prototype.generate = function ( builder ) {
|
|
|
|
|
|
- var code;
|
|
|
+ var code;
|
|
|
|
|
|
- if (builder.isShader('vertex')) {
|
|
|
+ if ( builder.isShader( 'vertex' ) ) {
|
|
|
|
|
|
- var position = this.position ? this.position.analyzeAndFlow( builder, 'v3', { cache: 'position' } ) : undefined;
|
|
|
+ var position = this.position ? this.position.analyzeAndFlow( builder, 'v3', { cache: 'position' } ) : undefined;
|
|
|
|
|
|
- var output = [
|
|
|
- "vec3 transformed = position;"
|
|
|
- ];
|
|
|
+ var output = [
|
|
|
+ "vec3 transformed = position;"
|
|
|
+ ];
|
|
|
|
|
|
- if ( position ) {
|
|
|
- output.push(
|
|
|
- position.code,
|
|
|
- position.result ? "gl_Position = " + position.result + ";" : ''
|
|
|
- );
|
|
|
- } else {
|
|
|
- output.push( "gl_Position = projectionMatrix * modelViewMatrix * vec4(transformed, 1.0)" );
|
|
|
- }
|
|
|
+ if ( position ) {
|
|
|
|
|
|
- code = output.join("\n");
|
|
|
- } else {
|
|
|
- // Analyze all nodes to reuse generate codes
|
|
|
- this.color.analyze( builder, { slot: 'color' } );
|
|
|
+ output.push(
|
|
|
+ position.code,
|
|
|
+ position.result ? "gl_Position = " + position.result + ";" : ''
|
|
|
+ );
|
|
|
|
|
|
- if ( this.alpha ) this.alpha.analyze( builder );
|
|
|
+ } else {
|
|
|
|
|
|
- // Build code
|
|
|
- var color = this.color.flow(builder, 'c', { slot: 'color' });
|
|
|
- var alpha = this.alpha ? this.alpha.flow( builder, 'f' ) : undefined;
|
|
|
+ output.push( "gl_Position = projectionMatrix * modelViewMatrix * vec4(transformed, 1.0)" );
|
|
|
|
|
|
- builder.requires.transparent = alpha !== undefined;
|
|
|
+ }
|
|
|
|
|
|
- var output = [
|
|
|
- color.code,
|
|
|
- ];
|
|
|
+ code = output.join( "\n" );
|
|
|
|
|
|
- if ( alpha ) {
|
|
|
- output.push(
|
|
|
- alpha.code,
|
|
|
- '#ifdef ALPHATEST',
|
|
|
+ } else {
|
|
|
|
|
|
- ' if ( ' + alpha.result + ' <= ALPHATEST ) discard;',
|
|
|
+ // Analyze all nodes to reuse generate codes
|
|
|
+ this.color.analyze( builder, { slot: 'color' } );
|
|
|
|
|
|
- '#endif'
|
|
|
- );
|
|
|
- }
|
|
|
+ if ( this.alpha ) this.alpha.analyze( builder );
|
|
|
|
|
|
- if ( alpha ) {
|
|
|
- output.push( "gl_FragColor = vec4(" + color.result + ", " + alpha.result + " );" );
|
|
|
- } else {
|
|
|
- output.push( "gl_FragColor = vec4(" + color.result + ", 1.0 );" );
|
|
|
- }
|
|
|
+ // Build code
|
|
|
+ var color = this.color.flow( builder, 'c', { slot: 'color' } );
|
|
|
+ var alpha = this.alpha ? this.alpha.flow( builder, 'f' ) : undefined;
|
|
|
|
|
|
- code = output.join( "\n" );
|
|
|
- }
|
|
|
+ builder.requires.transparent = alpha !== undefined;
|
|
|
|
|
|
- return code;
|
|
|
+ var output = [
|
|
|
+ color.code,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if ( alpha ) {
|
|
|
+
|
|
|
+ output.push(
|
|
|
+ alpha.code,
|
|
|
+ '#ifdef ALPHATEST',
|
|
|
+
|
|
|
+ ' if ( ' + alpha.result + ' <= ALPHATEST ) discard;',
|
|
|
+
|
|
|
+ '#endif'
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( alpha ) {
|
|
|
+
|
|
|
+ output.push( "gl_FragColor = vec4(" + color.result + ", " + alpha.result + " );" );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ output.push( "gl_FragColor = vec4(" + color.result + ", 1.0 );" );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ code = output.join( "\n" );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return code;
|
|
|
|
|
|
};
|
|
|
|
|
|
SimpleNode.prototype.copy = function ( source ) {
|
|
|
|
|
|
- Node.prototype.copy.call( this, source );
|
|
|
+ Node.prototype.copy.call( this, source );
|
|
|
|
|
|
- this.position = source.position;
|
|
|
- this.color = source.color;
|
|
|
- this.alpha = source.alpha;
|
|
|
+ this.position = source.position;
|
|
|
+ this.color = source.color;
|
|
|
+ this.alpha = source.alpha;
|
|
|
|
|
|
- return this;
|
|
|
+ return this;
|
|
|
|
|
|
};
|
|
|
|
|
|
SimpleNode.prototype.toJSON = function ( meta ) {
|
|
|
|
|
|
- var data = this.getJSONNode( meta );
|
|
|
+ var data = this.getJSONNode( meta );
|
|
|
|
|
|
- if ( ! data ) {
|
|
|
+ if ( ! data ) {
|
|
|
|
|
|
- data = this.createJSONNode( meta );
|
|
|
+ data = this.createJSONNode( meta );
|
|
|
|
|
|
- data.position = this.position.toJSON( meta ).uuid;
|
|
|
- data.color = this.color.toJSON( meta ).uuid;
|
|
|
- data.alpha = this.alpha.toJSON( meta ).uuid;
|
|
|
+ data.position = this.position.toJSON( meta ).uuid;
|
|
|
+ data.color = this.color.toJSON( meta ).uuid;
|
|
|
+ data.alpha = this.alpha.toJSON( meta ).uuid;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- return data;
|
|
|
+ return data;
|
|
|
|
|
|
};
|
|
|
|