Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GLSLNodeParser, NodeBuilder, TextureNode, vectorComponents } from '../../../nodes/Nodes.js';
import { GLSLNodeParser, NodeBuilder, TextureNode, vectorComponents, CodeNode } from '../../../nodes/Nodes.js';

import NodeUniformBuffer from '../../common/nodes/NodeUniformBuffer.js';
import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js';
Expand All @@ -9,13 +9,20 @@ import { NoColorSpace, ByteType, ShortType, RGBAIntegerFormat, RGBIntegerFormat,
import { DataTexture } from '../../../textures/DataTexture.js';
import { error } from '../../../utils.js';

const glslPolyfills = {
bitcast_int_uint: new CodeNode( /* glsl */'uint tsl_bitcast_uint_to_int ( int x ) { return floatBitsToInt( uintBitsToFloat( x ) ); }' ),
bitcast_uint_int: new CodeNode( /* glsl */'uint tsl_bitcast_int_to_uint ( int x ) { return floatBitsToUint( intBitsToFloat ( x ) ); }' )
};

const glslMethods = {
textureDimensions: 'textureSize',
equals: 'equal',
bitcast_float_int: 'floatBitsToInt',
bitcast_int_float: 'intBitsToFloat',
bitcast_uint_float: 'uintBitsToFloat',
bitcast_float_uint: 'floatBitsToUint',
bitcast_uint_int: 'tsl_bitcast_uint_to_int',
bitcast_int_uint: 'tsl_bitcast_int_to_uint'
};

const precisionLib = {
Expand Down Expand Up @@ -127,6 +134,25 @@ class GLSLNodeBuilder extends NodeBuilder {

}

/**
* Includes the given method name into the current
* function node.
*
* @private
* @param {string} name - The method name to include.
* @return {CodeNode} The respective code node.
*/
_include( name ) {

const codeNode = glslPolyfills[ name ];
codeNode.build( this );

this.addInclude( codeNode );

return codeNode;

}

/**
* Returns the native shader method name for a given generic name.
*
Expand All @@ -135,6 +161,12 @@ class GLSLNodeBuilder extends NodeBuilder {
*/
getMethod( method ) {

if ( glslPolyfills[ method ] !== undefined ) {

this._include( method );

}

return glslMethods[ method ] || method;

}
Expand All @@ -148,7 +180,7 @@ class GLSLNodeBuilder extends NodeBuilder {
*/
getBitcastMethod( type, inputType ) {

return glslMethods[ `bitcast_${ inputType }_${ type }` ];
return this.getMethod( `bitcast_${ inputType }_${ type }` );

}

Expand Down
6 changes: 1 addition & 5 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2068,11 +2068,7 @@ ${ flowData.code }
const codeNode = wgslPolyfill[ name ];
codeNode.build( this );

if ( this.currentFunctionNode !== null ) {

this.currentFunctionNode.includes.push( codeNode );

}
this.addInclude( codeNode );

return codeNode;

Expand Down