Documentation / scene / ShaderHelper
Class: ShaderHelper
Defined in: libs/scene/src/material/shader/helper.ts:70
Helper shader functions for the builtin material system
Constructors
Constructor
new ShaderHelper():
ShaderHelper
Returns
ShaderHelper
Properties
BILLBOARD_SPHERICAL
readonlystaticBILLBOARD_SPHERICAL:1=1
Defined in: libs/scene/src/material/shader/helper.ts:71
BILLBOARD_SYLINDRAL
readonlystaticBILLBOARD_SYLINDRAL:2=2
Defined in: libs/scene/src/material/shader/helper.ts:72
MATERIAL_INSTANCE_DATA_OFFSET
readonlystaticMATERIAL_INSTANCE_DATA_OFFSET:9=9
Defined in: libs/scene/src/material/shader/helper.ts:73
Methods
getObjectColorUniformName()
staticgetObjectColorUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:110
Returns
string
getWorldMatrixUniformName()
staticgetWorldMatrixUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:113
Returns
string
getPrevWorldMatrixUniformName()
staticgetPrevWorldMatrixUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:116
Returns
string
getPrevWorldMatrixFrameUniformName()
staticgetPrevWorldMatrixFrameUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:119
Returns
string
getInstanceDataUniformName()
staticgetInstanceDataUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:122
Returns
string
getInstanceDataOffsetUniformName()
staticgetInstanceDataOffsetUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:125
Returns
string
getInstanceDataStrideUniformName()
staticgetInstanceDataStrideUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:128
Returns
string
getBoneMatricesUniformName()
staticgetBoneMatricesUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:131
Returns
string
getBoneTextureSizeUniformName()
staticgetBoneTextureSizeUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:134
Returns
string
getBoneInvBindMatrixUniformName()
staticgetBoneInvBindMatrixUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:137
Returns
string
getMorphDataUniformName()
staticgetMorphDataUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:140
Returns
string
getMorphInfoUniformName()
staticgetMorphInfoUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:143
Returns
string
getLightBufferUniformName()
staticgetLightBufferUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:146
Returns
string
getDrawableBindGroupLayout()
staticgetDrawableBindGroupLayout(skinning,morphing,instancing):BindGroupLayout
Defined in: libs/scene/src/material/shader/helper.ts:149
Parameters
skinning
boolean
morphing
boolean
instancing
boolean
Returns
BindGroupLayout
prepareFragmentShader()
staticprepareFragmentShader(pb,ctx):void
Defined in: libs/scene/src/material/shader/helper.ts:177
Prepares the fragment shader which is going to be used in our material system
Parameters
pb
ProgramBuilder
The program builder
ctx
The drawing context
Returns
void
Remarks
This function will setup all nessesary uniforms acoording to the drawing context
prepareVertexShader()
staticprepareVertexShader(pb,ctx):void
Defined in: libs/scene/src/material/shader/helper.ts:189
Prepares the vertex shader which is going to be used in our material system
Parameters
pb
ProgramBuilder
The program builder
ctx
The drawing context
Returns
void
Remarks
This function will setup all nessesary uniforms according to the drawing context
hasSkinning()
statichasSkinning(scope):boolean
Defined in: libs/scene/src/material/shader/helper.ts:378
This function checks if the shader needs to process skeletal animation.
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
boolean
true if the shader needs to process skeletal animation, otherwise false.
hasMorphing()
statichasMorphing(scope):boolean
Defined in: libs/scene/src/material/shader/helper.ts:388
This function checks if the shader needs to process morph target animation.
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
boolean
true if the shader needs to process morph target animation, otherwise false.
calculateSkinMatrix()
staticcalculateSkinMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:398
Calculate skinning matrix for current vertex
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
Skinning matrix for current vertex, or null if there is not skeletal animation
calculateMorphDelta()
staticcalculateMorphDelta(scope,attrib):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:446
Parameters
scope
PBInsideFunctionScope
attrib
number
Returns
PBShaderExp
resolveVertexPosition()
staticresolveVertexPosition(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:583
Calculates the vertex position of type vec3 in object space
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The calculated vertex position in object space, or null if pos is null
resolveMotionVector()
staticresolveMotionVector(scope,worldPos,prevWorldPos):void
Defined in: libs/scene/src/material/shader/helper.ts:640
Resolve motion vector
Parameters
scope
PBInsideFunctionScope
Current shader scope
worldPos
PBShaderExp
Current object position in world space
prevWorldPos
PBShaderExp
Previous object position in world space
Returns
void
resolveVertexNormal()
staticresolveVertexNormal(scope,normal?):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:658
Calculates the normal vector of type vec3 in object space
Parameters
scope
PBInsideFunctionScope
Current shader scope
normal?
PBShaderExp
Vertex normal input, must be type of vec3, null if no vertex normal input
Returns
PBShaderExp
The calculated normal vector in object space, or null if normal is null
resolveVertexTangent()
staticresolveVertexTangent(scope,tangent?):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:690
Calculates the tangent vector of type vec3 in object space
Parameters
scope
PBInsideFunctionScope
Current shader scope
tangent?
PBShaderExp
Vertex tangent input, must be type of vec4, null if no vertex tangent input
Returns
PBShaderExp
The calculated tangent vector of type vec4 in object space, or null if tangent is null
getWorldMatrix()
staticgetWorldMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:724
Gets the uniform variable of type mat4 which holds the world matrix of current object to be drawn
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The world matrix of current object to be drawn
getPrevWorldMatrix()
staticgetPrevWorldMatrix(scope):any
Defined in: libs/scene/src/material/shader/helper.ts:739
Gets the uniform variable of type mat4 which holds the world matrix at previous frame of current object to be drawn
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
any
The world matrix at previous frame of current object to be drawn
getInstancedUniform()
staticgetInstancedUniform(scope,uniformIndex):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:781
Gets the instance uniform value of type vec4 by uniform index
Parameters
scope
PBInsideFunctionScope
Current shader scope
uniformIndex
number | PBShaderExp
Returns
PBShaderExp
instance uniform value
getNormalMatrix()
staticgetNormalMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:797
Gets the uniform variable of type mat4 which holds the normal matrix of current object to be drawn
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The normal matrix of current object to be drawn
vertexShaderDrawableStuff()
staticvertexShaderDrawableStuff(scope,skinning,morphing,instanced):void
Defined in: libs/scene/src/material/shader/helper.ts:807
Vertex shader drawable stuff
Parameters
scope
PBGlobalScope
Current shader scope
skinning
boolean
true if skinning is used, otherwise false.
morphing
boolean
instanced
boolean
true if instancing is used, otherwise false.
Returns
void
getEnvLightStrength()
staticgetEnvLightStrength(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1007
Gets the uniform variable of type float which holds the strength of the environment light
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The uniform variable of which presents the strength of the environment light
Remarks
This function can only be used in the fragment shader
getEnvLightSpecularStrength()
staticgetEnvLightSpecularStrength(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1019
Gets the uniform variable of type float which holds the specular strength of the environment light
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The uniform variable which presents the specular strength of the environment light
Remarks
This function can only be used in the fragment shader
getSceneColorTexture()
staticgetSceneColorTexture(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1027
Gets current scene color texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
current scene color texture
getSceneColorTextureSize()
staticgetSceneColorTextureSize(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1035
Gets the size of current scene color texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The size of current scene color texture
getLinearDepthTexture()
staticgetLinearDepthTexture(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1043
Gets current linear depth texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
current linear depth texture
getLinearDepthTextureSize()
staticgetLinearDepthTextureSize(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1051
Gets the size of current linear depth texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The size of current linear depth texture
getHiZDepthTexture()
staticgetHiZDepthTexture(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1059
Gets current HiZ depth texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
current HiZ depth texture
getHiZDepthTextureSize()
staticgetHiZDepthTextureSize(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1067
Gets the size of current HiZ depth texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The size of current HiZ depth texture
getHiZDepthTextureMipLevelCount()
staticgetHiZDepthTextureMipLevelCount(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1075
Gets the mipmap levels count of current HiZ depth texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The mipmap levels count of current HiZ depth texture
getBakedSkyTexture()
staticgetBakedSkyTexture(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1083
Gets current baked skybox texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
current baked skybox texture
getElapsedTime()
staticgetElapsedTime(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1091
Gets the elapsed time in seconds
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The elapsed time in seconds
getElapsedTimeFrame()
staticgetElapsedTimeFrame(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1099
Gets the elapsed time since last frame in seconds
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The elapsed time since last frame in seconds
getCameraPosition()
staticgetCameraPosition(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1107
Gets the uniform variable of type vec3 which holds the camera position
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The camera position
getCameraRoughnessFactor()
staticgetCameraRoughnessFactor(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1115
Gets the uniform variable of type float which holds the roughness factor
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The roughness factor
getRenderSize()
staticgetRenderSize(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1123
Gets framebuffer size for rendering
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The roughness factor
getFramestamp()
staticgetFramestamp(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1131
Gets the uniform variable of type uint which holds the framestamp
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The framestamp
getCameraClipPlaneFlag()
staticgetCameraClipPlaneFlag(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1139
Gets the clip plane flag
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
A float value of 1 indices the clip plane presents, otherwise 0
getCameraClipPlane()
staticgetCameraClipPlane(scope):any
Defined in: libs/scene/src/material/shader/helper.ts:1147
Gets the clip plane
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
any
A vec4 presents the clip plane
getCameraParams()
staticgetCameraParams(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1155
Gets the uniform variable of type vec4 which holds the camera parameters
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The camera parameters
getAtmosphereParams()
staticgetAtmosphereParams(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1266
Gets the uniform variable that contains atmosphere parameters
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The atmosphere parameters
getAerialPerspectiveLUT()
staticgetAerialPerspectiveLUT(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1274
Gets the aerial perspective LUT
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The aerial perspective LUT texture
getViewProjectionMatrix()
staticgetViewProjectionMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1282
Gets the uniform variable of type mat4 which holds the view projection matrix of current camera
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The view projection matrix of current camera
getInvViewProjectionMatrix()
staticgetInvViewProjectionMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1290
Gets the uniform variable of type mat4 which holds the inversed view projection matrix of current camera
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The inversed view projection matrix of current camera
getProjectionMatrix()
staticgetProjectionMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1298
Gets the uniform variable of type mat4 which holds the projection matrix of current camera
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The projection matrix of current camera
getInvProjectionMatrix()
staticgetInvProjectionMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1306
Gets the uniform variable of type mat4 which holds the inversed projection matrix of current camera
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The inversed projection matrix of current camera
getUnjitteredViewProjectionMatrix()
staticgetUnjitteredViewProjectionMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1314
Gets the uniform variable of type mat4 which holds the unjittered view projection matrix of current camera
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The unjittered view projection matrix of current camera
getProjectionMatrixJitterValue()
staticgetProjectionMatrixJitterValue(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1322
Gets the uniform variable of type vec2 which holds the jitter value of the projection matrix of current camera
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The jitter value of projection matrix of current camera
getJitteredInvVPMatrix()
staticgetJitteredInvVPMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1330
Gets the uniform variable of type mat4 which holds the jittered inversed view-projection matrix
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The jittered inversed view-projection matrix
getPrevUnjitteredViewProjectionMatrix()
staticgetPrevUnjitteredViewProjectionMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1338
Gets the uniform variable of type mat4 which holds the unjittered view projection at previous frame matrix of current camera
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The unjittered view projection matrix at previous frame of current camera
getViewMatrix()
staticgetViewMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1346
Gets the uniform variable of type mat4 which holds the view matrix of current camera (world space to camera space)
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The view matrix of current camera
getInvViewMatrix()
staticgetInvViewMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1354
Gets the uniform variable of type mat4 which holds the inv-view matrix of current camera (camera space to world space)
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The inv-view matrix of current camera
setClipSpacePosition()
staticsetClipSpacePosition(scope,pos):void
Defined in: libs/scene/src/material/shader/helper.ts:1460
Sets the clip space position in vertex shader
Parameters
scope
PBInsideFunctionScope
Current shader scope
pos
PBShaderExp
The clip space position to be set
Returns
void
Remarks
Use this function instead of using
// Do not use this this.$builtins.position = some_value; // Use this ShaderFramework.setClipSpacePosition(some_value);,
getShadowMap()
staticgetShadowMap(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1475
Get shadow map uniform value
Parameters
scope
PBInsideFunctionScope
Shader scope
Returns
PBShaderExp
The shadow map texture uniform
calculateShadow()
staticcalculateShadow(scope,worldPos,NoL,ctx):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1485
Calculates shadow of current fragment
Parameters
scope
PBInsideFunctionScope
Shader scope
worldPos
PBShaderExp
NoL
PBShaderExp
NdotL vector
ctx
Returns
PBShaderExp
Shadow of current fragment, 1 means no shadow and 0 means full shadowed.
applyFog()
staticapplyFog(scope,worldPos,color,ctx):void
Defined in: libs/scene/src/material/shader/helper.ts:1576
Parameters
scope
PBInsideFunctionScope
worldPos
PBShaderExp
color
PBShaderExp
ctx
Returns
void
linearDepthToNonLinear()
staticlinearDepthToNonLinear(scope,depth,nearFar?):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1619
Calculates the non-linear depth from linear depth
Parameters
scope
PBInsideFunctionScope
Current shader scope
depth
PBShaderExp
The linear depth
nearFar?
PBShaderExp
A vector that contains the near clip plane in x component and the far clip plane in y component
Returns
PBShaderExp
The calculated non-linear depth
nonLinearDepthToLinear()
staticnonLinearDepthToLinear(scope,depth,nearFar?):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1639
Calculates the linear depth from non-linear depth
Parameters
scope
PBInsideFunctionScope
Current shader scope
depth
PBShaderExp
The non-linear depth
nearFar?
PBShaderExp
A vector that contains the near clip plane in x component and the far clip plane in y component
Returns
PBShaderExp
The calculated linear depth
nonLinearDepthToLinearNormalized()
staticnonLinearDepthToLinearNormalized(scope,depth,nearFar?):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1656
Calculates the normalized linear depth from non-linear depth
Parameters
scope
PBInsideFunctionScope
Current shader scope
depth
PBShaderExp
The non-linear depth
nearFar?
PBShaderExp
A vector that contains the near clip plane in x component and the far clip plane in y component
Returns
PBShaderExp
The calculated normalized linear depth
sampleLinearDepth()
staticsampleLinearDepth(scope,tex,uv,level):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1673
Sample linear depth from linear depth texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
tex
PBShaderExp
The linear depth texture
uv
PBShaderExp
The uv coordinates
level
number | PBShaderExp
The mipmap level to sample
Returns
PBShaderExp
Linear depth value
samplePositionFromDepth()
staticsamplePositionFromDepth(scope,depthTex,uv,mat,cameraNearFar):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1683
Parameters
scope
PBInsideFunctionScope
depthTex
PBShaderExp
uv
PBShaderExp
mat
PBShaderExp
cameraNearFar
PBShaderExp
Returns
PBShaderExp
sampleLinearDepthWithBackface()
staticsampleLinearDepthWithBackface(scope,tex,uv,level):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1720
Sample linear depth from linear depth texture with backface
Parameters
scope
PBInsideFunctionScope
Current shader scope
tex
PBShaderExp
The linear depth texture
uv
PBShaderExp
The uv coordinates
level
number | PBShaderExp
The mipmap level to sample
Returns
PBShaderExp
Linear depth value
encodeColorOutput()
staticencodeColorOutput(scope,outputColor):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1736
Transform color to sRGB color space if nessesary
Parameters
scope
PBInsideFunctionScope
Current shader scope
outputColor
PBShaderExp
The color to be transformed
Returns
PBShaderExp
The transformed color