Documentation / scene / ShaderHelper
Class: ShaderHelper
Defined in: libs/scene/src/material/shader/helper.ts:108
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:109
BILLBOARD_SYLINDRAL
readonlystaticBILLBOARD_SYLINDRAL:2=2
Defined in: libs/scene/src/material/shader/helper.ts:110
MATERIAL_INSTANCE_DATA_OFFSET
readonlystaticMATERIAL_INSTANCE_DATA_OFFSET:9=9
Defined in: libs/scene/src/material/shader/helper.ts:111
Methods
getObjectColorUniformName()
staticgetObjectColorUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:149
Returns
string
getWorldMatrixUniformName()
staticgetWorldMatrixUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:152
Returns
string
getPrevWorldMatrixUniformName()
staticgetPrevWorldMatrixUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:155
Returns
string
getPrevWorldMatrixFrameUniformName()
staticgetPrevWorldMatrixFrameUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:158
Returns
string
getInstanceDataUniformName()
staticgetInstanceDataUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:161
Returns
string
getInstanceDataOffsetUniformName()
staticgetInstanceDataOffsetUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:164
Returns
string
getInstanceDataStrideUniformName()
staticgetInstanceDataStrideUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:167
Returns
string
getBoneMatricesUniformName()
staticgetBoneMatricesUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:170
Returns
string
getBoneTextureSizeUniformName()
staticgetBoneTextureSizeUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:173
Returns
string
getBoneInvBindMatrixUniformName()
staticgetBoneInvBindMatrixUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:176
Returns
string
getSkinInfluenceDataUniformName()
staticgetSkinInfluenceDataUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:179
Returns
string
getSkinInfluenceInfoUniformName()
staticgetSkinInfluenceInfoUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:182
Returns
string
getMorphDataUniformName()
staticgetMorphDataUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:185
Returns
string
getMorphInfoUniformName()
staticgetMorphInfoUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:188
Returns
string
getLightBufferUniformName()
staticgetLightBufferUniformName():string
Defined in: libs/scene/src/material/shader/helper.ts:191
Returns
string
getDrawableBindGroupLayout()
staticgetDrawableBindGroupLayout(skinning,morphing,instancing):BindGroupLayout
Defined in: libs/scene/src/material/shader/helper.ts:194
Parameters
skinning
boolean
morphing
boolean
instancing
boolean
Returns
BindGroupLayout
prepareFragmentShader()
staticprepareFragmentShader(pb,ctx):void
Defined in: libs/scene/src/material/shader/helper.ts:222
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:234
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:451
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:461
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:471
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:564
Parameters
scope
PBInsideFunctionScope
attrib
number
Returns
PBShaderExp
resolveVertexPosition()
staticresolveVertexPosition(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:942
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:999
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
getSkinMatrix()
staticgetSkinMatrix(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1020
Gets the skinning matrix in the vertex shader, if the mesh being drawn is skinned.
Parameters
scope
PBInsideFunctionScope
Current shader scope, must be vertex stage
Returns
PBShaderExp
The skinning matrix of type mat4, or null when the mesh is not skinned
Remarks
Lets a material apply the same skinning transform to its own uniform-supplied object-space vectors that ShaderHelper.resolveVertexNormal applies to the normal attribute, so such vectors stay attached to the deforming mesh.
resolveVertexNormal()
staticresolveVertexNormal(scope,normal?):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1031
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:1071
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:1109
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:1124
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:1166
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:1182
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:1192
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
calculateWaterCaustic()
staticcalculateWaterCaustic(scope,worldPos,lightType,lightDirection,ctx):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1580
Attenuation the water caustics apply to one light at a world position.
Returns the product of two effects: the caustic pattern focused by the waves, and the Beer-Lambert transmittance of the water column the light travelled through to reach the point. The result is 1 for any light that is not the caustic light, above the surface, and outside the water region, so the caller can multiply unconditionally.
The caustic light is identified at runtime by comparing directions rather than by which pass is running. Shadow-casting lights reach the opaque queue through the clustered path when the screen-space shadow mask is on (the default) and through a per-light additive pass when it is off; only a runtime test covers both. Two directional lights pointing the same way would both pick up the caustics, but they are physically the same light.
Parameters
scope
PBInsideFunctionScope
Current shader scope.
worldPos
PBShaderExp
World position of the shaded fragment.
lightType
PBShaderExp
The light's type constant.
lightDirection
PBShaderExp
Direction the light travels, i.e. directionAndCutoff.xyz.
ctx
Current draw context.
Returns
PBShaderExp
A vec3 multiplier, or null when this pass has no caustics.
getEnvLightStrength()
staticgetEnvLightStrength(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1846
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:1858
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:1866
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:1874
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:1882
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:1890
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:1898
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:1906
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:1914
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:1922
Gets current baked skybox texture
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
current baked skybox texture
sampleBakedSkyPreExposed()
staticsampleBakedSkyPreExposed(scope,direction):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1939
Samples the baked sky cubemap in the same pre-exposed space as the scene color buffer.
Parameters
scope
PBInsideFunctionScope
Current shader scope
direction
PBShaderExp
Sampling direction
Returns
PBShaderExp
Pre-exposed sky radiance
Remarks
The bake is cached and therefore exposure-independent, stored at the fixed PHYSICAL_BAKE_EXPOSURE. Anything that blends it against already-pre-exposed lit color (water reflection, blueprint sky lookups) must first convert it to the live exposure. envLightStrength carries exactly that ratio in physical mode, and the legacy environment strength (its established meaning) otherwise.
getPreExposureUniform()
staticgetPreExposureUniform(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1957
Gets the camera pre-exposure factor.
Parameters
scope
PBInsideFunctionScope
Current shader scope
Returns
PBShaderExp
The pre-exposure factor
Remarks
The multiplier every photometric quantity is scaled by before it reaches the HDR target. 1 in legacy. Use it for material-authored emitters (emissive), which are not covered by the CPU-side light pre-exposure.
getElapsedTime()
staticgetElapsedTime(scope):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:1965
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:2016
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:2024
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:2032
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:2040
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:2048
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:2056
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:2064
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:2072
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:2183
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:2191
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:2199
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:2207
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:2215
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:2223
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:2231
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:2239
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:2247
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:2255
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:2263
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:2271
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:2377
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:2392
Get shadow map uniform value
Parameters
scope
PBInsideFunctionScope
Shader scope
Returns
PBShaderExp
The shadow map texture uniform
calculateShadow()
staticcalculateShadow(scope,worldPos,worldNormal,NoL,ctx):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:2468
Calculates shadow of current fragment
Parameters
scope
PBInsideFunctionScope
Shader scope
worldPos
PBShaderExp
worldNormal
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:2581
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:2624
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:2650
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:2670
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
linearNormalizedToNonLinearDepth()
staticlinearNormalizedToNonLinearDepth(scope,depth,nearFar?):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:2696
Converts normalized linear depth back to device non-linear depth.
Parameters
scope
PBInsideFunctionScope
Current shader scope
depth
PBShaderExp
The normalized 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 device non-linear depth
Remarks
The normalized linear depth convention (range [near/far, 1] with 1 at the far plane, as produced by ShaderHelper.nonLinearDepthToLinearNormalized) is independent of the engine depth convention; only the mapping to device depth flips under reverse-Z.
deviceDepthToClipZ()
staticdeviceDepthToClipZ(scope,depth):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:2717
Maps a device depth value to the canonical clip-space z coordinate (GL [-1,1] under standard-Z, zero-to-one under reverse-Z), suitable for unprojection with the engine's inverse projection matrices.
Parameters
scope
PBInsideFunctionScope
Current shader scope
depth
PBShaderExp
The device depth value
Returns
PBShaderExp
The canonical clip-space z
farthestClipZ()
staticfarthestClipZ(scope,w):number|PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:2729
Clip-space z that places a vertex exactly on the far plane (sky domes, background geometry).
Parameters
scope
PBInsideFunctionScope
Current shader scope
w
PBShaderExp
The clip-space w coordinate of the vertex
Returns
number | PBShaderExp
The clip-space z value for the far plane
isFarthestDepth()
staticisFarthestDepth(scope,depth):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:2740
Tests whether a device depth value equals the cleared (farthest) depth, i.e. no geometry was rendered at this position.
Parameters
scope
PBInsideFunctionScope
Current shader scope
depth
PBShaderExp
The device depth value
Returns
PBShaderExp
Boolean expression, true for background pixels
closerDepth()
staticcloserDepth(scope,a,b):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:2751
Selects the closer of two device depth values.
Parameters
scope
PBInsideFunctionScope
Current shader scope
a
PBShaderExp
First device depth value
b
PBShaderExp
Second device depth value
Returns
PBShaderExp
The value closer to the camera
fartherDepth()
staticfartherDepth(scope,a,b):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:2762
Selects the farther of two device depth values.
Parameters
scope
PBInsideFunctionScope
Current shader scope
a
PBShaderExp
First device depth value
b
PBShaderExp
Second device depth value
Returns
PBShaderExp
The value farther from the camera
sampleLinearDepth()
staticsampleLinearDepth(scope,tex,uv,level):PBShaderExp
Defined in: libs/scene/src/material/shader/helper.ts:2773
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:2783
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:2821
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:2837
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