123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import NodeBuilder from '../../nodes/core/NodeBuilder.js';
- import NodeSlot from '../../nodes/core/NodeSlot.js';
- class WebGLNodeBuilder extends NodeBuilder {
- constructor( material, renderer, properties ) {
- super( material, renderer );
- this.properties = properties;
- this._parseMaterial();
- }
- _parseMaterial() {
- const material = this.material;
- // parse inputs
- if ( material.colorNode !== undefined ) {
- this.addSlot( 'fragment', new NodeSlot( material.colorNode, 'COLOR', 'vec4' ) );
- }
- }
- getVaryFromNode( node, type ) {
- const vary = super.getVaryFromNode( node, type );
- if ( node.isUVNode ) {
- vary.name = 'vUv';
- }
- return vary;
- }
- getTexture( textureProperty, uvSnippet ) {
- return `sRGBToLinear( texture2D( ${textureProperty}, ${uvSnippet} ) )`;
- }
- getUniformsHeaderSnippet( shaderStage ) {
- const uniforms = this.uniforms[ shaderStage ];
- let snippet = '';
- for ( const uniform of uniforms ) {
- if ( uniform.type === 'texture' ) {
- snippet += `uniform sampler2D ${uniform.name};`;
- } else {
- const vectorType = this.getVectorType( uniform.type );
- snippet += `uniform ${vectorType} ${uniform.name};`;
- }
- }
- return snippet;
- }
- getAttributesHeaderSnippet( /*shaderStage*/ ) {
- }
- getVarsHeaderSnippet( /*shaderStage*/ ) {
- }
- getVarsBodySnippet( /*shaderStage*/ ) {
- }
- getVarysHeaderSnippet( /*shaderStage*/ ) {
- }
- getVarysBodySnippet( /*shaderStage*/ ) {
- }
- composeUniforms() {
- const uniforms = this.uniforms[ 'fragment' ];
- for ( const uniform of uniforms ) {
- this.properties.uniforms[ uniform.name ] = uniform;
- }
- }
- build() {
- super.build();
- this.properties.defines[ 'NODE_HEADER_UNIFORMS' ] = this.defines[ 'fragment' ][ 'NODE_HEADER_UNIFORMS' ];
- this.properties.defines[ 'NODE_COLOR' ] = this.defines[ 'fragment' ][ 'NODE_COLOR' ];
- this.composeUniforms();
- return this;
- }
- }
- export { WebGLNodeBuilder };
|