123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /**
- * @author sunag / http://www.sunag.com.br/
- */
- import { Node } from '../../core/Node.js';
- import { ColorNode } from '../../inputs/ColorNode.js';
- function BasicNode() {
- Node.call( this );
- this.color = new ColorNode( 0xFFFFFF );
- }
- BasicNode.prototype = Object.create( Node.prototype );
- BasicNode.prototype.constructor = BasicNode;
- BasicNode.prototype.nodeType = "Basic";
- BasicNode.prototype.generate = function ( builder ) {
- var code;
- if ( builder.isShader( 'vertex' ) ) {
- var position = this.position ? this.position.analyzeAndFlow( builder, 'v3', { cache: 'position' } ) : undefined;
- 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)" );
- }
- code = output.join( "\n" );
- } else {
- // Analyze all nodes to reuse generate codes
- this.color.analyze( builder, { slot: 'color' } );
- if ( this.alpha ) this.alpha.analyze( builder );
- // Build code
- var color = this.color.flow( builder, 'c', { slot: 'color' } );
- var alpha = this.alpha ? this.alpha.flow( builder, 'f' ) : undefined;
- builder.requires.transparent = alpha !== undefined;
- 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;
- };
- BasicNode.prototype.copy = function ( source ) {
- Node.prototype.copy.call( this, source );
- this.position = source.position;
- this.color = source.color;
- this.alpha = source.alpha;
- return this;
- };
- BasicNode.prototype.toJSON = function ( meta ) {
- var data = this.getJSONNode( meta );
- if ( ! data ) {
- 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;
- }
- return data;
- };
- export { BasicNode };
|