Capítulo 657 de 859

Chapter 657: GLSLNodeBuilder

Core Idea

A node builder targeting GLSL.

This module generates GLSL shader code from node materials and also generates the respective bindings and vertex buffer definitions. These data are later used by the renderer to create render and compute pipelines for render objects.

Key Concepts

  • builtins : Object.<string, Array.<string>>: A dictionary that holds for each shader stage an Array of used builtins.
  • extensions : Object.<string, Map.<string, Object>>: A dictionary that holds for each shader stage a Map of used extensions.
  • transforms : Array.<Object.<string, (AttributeNode|string)>>: An array that holds objects defining the varying and attribute data in context of Transform Feedback.
  • uniformGroups : Object.<string, Object.<string, NodeUniformsGroup>>: A dictionary holds for each shader stage ('vertex', 'fragment', 'compute') another dictionary which manages UBOs per group ('render','frame…

Reference Tables

Constructor

Signature
new GLSLNodeBuilder( object : Object3D, renderer : Renderer )

Properties

PropertyDescription
.builtins : Object.<string, Array.<string>>A dictionary that holds for each shader stage an Array of used builtins.
.extensions : Object.<string, Map.<string, Object>>A dictionary that holds for each shader stage a Map of used extensions.
`.transforms : Array.<Object.<string, (AttributeNodestring)>>`
.uniformGroups : Object.<string, Object.<string, NodeUniformsGroup>>A dictionary holds for each shader stage ('vertex', 'fragment', 'compute') another dictionary which manages UBOs per group ('render','frame','object').

Methods

MethodDescription
.buildCode()Controls the code build of the shader stages.
.buildFunctionCode( shaderNode : ShaderNodeInternal ) : stringBuilds the given shader node.
.enableExtension( name : string, behavior : string, shaderStage : string )Enables the given extension.
.enableHardwareClipping( planeCount : string )Enables hardware clipping.
.enableMultiview()Enables multiview.
.generatePBO( storageArrayElementNode : StorageArrayElementNode ) : stringSetups the Pixel Buffer Object (PBO) for the given storage buffer node.
.generateTexture( texture : Texture, textureProperty : string, uvSnippet : string, depthSnippet : string, offsetSnippet : string ) : stringGenerates the GLSL snippet for sampling/loading the given texture.
.generateTextureBias( texture : Texture, textureProperty : string, uvSnippet : string, biasSnippet : string, depthSnippet : string, offsetSnippet : string ) : stringGenerates the GLSL snippet when sampling textures with a bias to the mip level.
.generateTextureCompare( texture : Texture, textureProperty : string, uvSnippet : string, compareSnippet : string, depthSnippet : string, offsetSnippet : string, shaderStage : string ) : stringGenerates the GLSL snippet for sampling a depth texture and comparing the sampled depth values against a reference value.
.generateTextureGather( texture : Texture, textureProperty : string, uvSnippet : string, gatherSnippet : string, depthSnippet : string, offsetSnippet : string, flipYSnippet : string ) : stringGenerates the GLSL snippet for gathering four texels from the given texture.
.generateTextureGatherCompare( texture : Texture, textureProperty : string, uvSnippet : string, compareSnippet : string, depthSnippet : string, offsetSnippet : string, flipYSnippet : string ) : stringGenerates the GLSL snippet for performing a depth comparison on four texels in the given depth texture.
.generateTextureGrad( texture : Texture, textureProperty : string, uvSnippet : string, gradSnippet : Array.<string>, depthSnippet : string, offsetSnippet : string ) : stringGenerates the GLSL snippet for sampling/loading the given texture using explicit gradients.
.generateTextureLevel( texture : Texture, textureProperty : string, uvSnippet : string, levelSnippet : string, depthSnippet : string, offsetSnippet : string ) : stringGenerates the GLSL snippet when sampling textures with explicit mip level.
.generateTextureLoad( texture : Texture, textureProperty : string, uvIndexSnippet : string, levelSnippet : string, depthSnippet : string, offsetSnippet : string ) : stringGenerates the GLSL snippet that reads a single texel from a texture without sampling or filtering.
.getAttributes( shaderStage : string ) : stringReturns the shader attributes of the given shader stage as a GLSL string.
.getBitcastMethod( type : string, inputType : string ) : stringReturns the bitcast method name for a given input and outputType.
.getClipDistance() : stringReturns the clip distances builtin.
.getDrawIndex() : stringReturns the draw index builtin.
.getExtensions( shaderStage : string ) : stringReturns the enabled extensions of the given shader stage as a GLSL string.
.getFloatPackingMethod( encoding : string ) : stringReturns the float packing method name for a given numeric encoding.
.getFloatUnpackingMethod( encoding : string ) : stringReturns the float unpacking method name for a given numeric encoding.
.getFragCoord() : stringReturns the frag coord builtin.
.getFragDepth() : stringReturns the frag depth builtin.
.getFrontFacing() : stringReturns the front facing builtin.
.getInstanceIndex() : stringContextually returns either the vertex stage instance index builtin or the linearized index of an compute invocation within a grid of workgroups.
.getInvocationLocalIndex() : stringReturns a builtin representing the index of an invocation within its workgroup.
.getInvocationSubgroupIndex()Returns a builtin representing the index of an invocation within its subgroup.
.getMethod( method : string ) : stringReturns the native shader method name for a given generic name.
.getOutputStructName() : stringReturns the output struct name. Not relevant for GLSL.
.getPropertyName( node : Node, shaderStage : string ) : stringReturns a GLSL snippet that represents the property name of the given node.
.getStructMembers( struct : StructTypeNode ) : stringReturns the members of the given struct type node as a GLSL string.
.getStructs( shaderStage : string ) : stringReturns the structs of the given shader stage as a GLSL string.
.getSubgroupIndex()Returns a builtin representing the index of the current invocation's subgroup within its workgroup.
.getSubgroupSize()Returns a builtin representing the size of a subgroup within the current shader.
.getTernary( condSnippet : string, ifSnippet : string, elseSnippet : string ) : stringReturns the native snippet for a ternary operation.
.getTransforms( shaderStage : string ) : stringReturns the transforms of the given shader stage as a GLSL string.
.getTypeFromAttribute( attribute : BufferAttribute ) : stringReturns the type for a given buffer attribute.
.getUniformFromNode( node : UniformNode, type : string, shaderStage : string, name : string ) : NodeUniformThis method is one of the more important ones since it's responsible for generating a matching binding instance for the given uniform node.
.getUniforms( shaderStage : string ) : stringReturns the uniforms of the given shader stage as a GLSL string.
.getVaryings( shaderStage : string ) : stringReturns the varyings of the given shader stage as a GLSL string.
.getVertexIndex() : stringReturns the vertex index builtin.
.isAvailable( name : string ) : booleanWhether the requested feature is available or not.
.isFlipY() : booleanWhether to flip texture data along its vertical axis or not.
.needsToWorkingColorSpace( texture : Texture ) : booleanChecks if the given texture requires a manual conversion to the working color space.
.registerTransform( varyingName : string, attributeNode : AttributeNode )Registers a transform in context of Transform Feedback.
.setupPBO( storageBufferNode : StorageBufferNode )Setups the Pixel Buffer Object (PBO) for the given storage buffer node.

Key Takeaways

  1. GLSLNodeBuilder extends: NodeBuilder
  2. Most relevant properties: builtins, extensions, transforms, uniformGroups.
  3. Key methods: buildCode, buildFunctionCode, enableExtension, enableHardwareClipping.

Connects To