Skip to content

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

readonly static BILLBOARD_SPHERICAL: 1 = 1

Defined in: libs/scene/src/material/shader/helper.ts:109


BILLBOARD_SYLINDRAL

readonly static BILLBOARD_SYLINDRAL: 2 = 2

Defined in: libs/scene/src/material/shader/helper.ts:110


MATERIAL_INSTANCE_DATA_OFFSET

readonly static MATERIAL_INSTANCE_DATA_OFFSET: 9 = 9

Defined in: libs/scene/src/material/shader/helper.ts:111

Methods

getObjectColorUniformName()

static getObjectColorUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:149

Returns

string


getWorldMatrixUniformName()

static getWorldMatrixUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:152

Returns

string


getPrevWorldMatrixUniformName()

static getPrevWorldMatrixUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:155

Returns

string


getPrevWorldMatrixFrameUniformName()

static getPrevWorldMatrixFrameUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:158

Returns

string


getInstanceDataUniformName()

static getInstanceDataUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:161

Returns

string


getInstanceDataOffsetUniformName()

static getInstanceDataOffsetUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:164

Returns

string


getInstanceDataStrideUniformName()

static getInstanceDataStrideUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:167

Returns

string


getBoneMatricesUniformName()

static getBoneMatricesUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:170

Returns

string


getBoneTextureSizeUniformName()

static getBoneTextureSizeUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:173

Returns

string


getBoneInvBindMatrixUniformName()

static getBoneInvBindMatrixUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:176

Returns

string


getSkinInfluenceDataUniformName()

static getSkinInfluenceDataUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:179

Returns

string


getSkinInfluenceInfoUniformName()

static getSkinInfluenceInfoUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:182

Returns

string


getMorphDataUniformName()

static getMorphDataUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:185

Returns

string


getMorphInfoUniformName()

static getMorphInfoUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:188

Returns

string


getLightBufferUniformName()

static getLightBufferUniformName(): string

Defined in: libs/scene/src/material/shader/helper.ts:191

Returns

string


getDrawableBindGroupLayout()

static getDrawableBindGroupLayout(skinning, morphing, instancing): BindGroupLayout

Defined in: libs/scene/src/material/shader/helper.ts:194

Parameters

skinning

boolean

morphing

boolean

instancing

boolean

Returns

BindGroupLayout


prepareFragmentShader()

static prepareFragmentShader(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

DrawContext

The drawing context

Returns

void

Remarks

This function will setup all nessesary uniforms acoording to the drawing context


prepareVertexShader()

static prepareVertexShader(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

DrawContext

The drawing context

Returns

void

Remarks

This function will setup all nessesary uniforms according to the drawing context


hasSkinning()

static hasSkinning(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()

static hasMorphing(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()

static calculateSkinMatrix(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()

static calculateMorphDelta(scope, attrib): PBShaderExp

Defined in: libs/scene/src/material/shader/helper.ts:564

Parameters

scope

PBInsideFunctionScope

attrib

number

Returns

PBShaderExp


resolveVertexPosition()

static resolveVertexPosition(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()

static resolveMotionVector(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()

static getSkinMatrix(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()

static resolveVertexNormal(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()

static resolveVertexTangent(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()

static getWorldMatrix(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()

static getPrevWorldMatrix(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()

static getInstancedUniform(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()

static getNormalMatrix(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()

static vertexShaderDrawableStuff(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()

static calculateWaterCaustic(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

DrawContext

Current draw context.

Returns

PBShaderExp

A vec3 multiplier, or null when this pass has no caustics.


getEnvLightStrength()

static getEnvLightStrength(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()

static getEnvLightSpecularStrength(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()

static getSceneColorTexture(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()

static getSceneColorTextureSize(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()

static getLinearDepthTexture(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()

static getLinearDepthTextureSize(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()

static getHiZDepthTexture(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()

static getHiZDepthTextureSize(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()

static getHiZDepthTextureMipLevelCount(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()

static getBakedSkyTexture(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()

static sampleBakedSkyPreExposed(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()

static getPreExposureUniform(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()

static getElapsedTime(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()

static getElapsedTimeFrame(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()

static getCameraPosition(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()

static getCameraRoughnessFactor(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()

static getRenderSize(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()

static getFramestamp(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()

static getCameraClipPlaneFlag(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()

static getCameraClipPlane(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()

static getCameraParams(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()

static getAtmosphereParams(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()

static getAerialPerspectiveLUT(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()

static getViewProjectionMatrix(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()

static getInvViewProjectionMatrix(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()

static getProjectionMatrix(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()

static getInvProjectionMatrix(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()

static getUnjitteredViewProjectionMatrix(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()

static getProjectionMatrixJitterValue(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()

static getJitteredInvVPMatrix(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()

static getPrevUnjitteredViewProjectionMatrix(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()

static getViewMatrix(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()

static getInvViewMatrix(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()

static setClipSpacePosition(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()

static getShadowMap(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()

static calculateShadow(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

DrawContext

Returns

PBShaderExp

Shadow of current fragment, 1 means no shadow and 0 means full shadowed.


applyFog()

static applyFog(scope, worldPos, color, ctx): void

Defined in: libs/scene/src/material/shader/helper.ts:2581

Parameters

scope

PBInsideFunctionScope

worldPos

PBShaderExp

color

PBShaderExp

ctx

DrawContext

Returns

void


linearDepthToNonLinear()

static linearDepthToNonLinear(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()

static nonLinearDepthToLinear(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()

static nonLinearDepthToLinearNormalized(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()

static linearNormalizedToNonLinearDepth(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()

static deviceDepthToClipZ(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()

static farthestClipZ(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()

static isFarthestDepth(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()

static closerDepth(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()

static fartherDepth(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()

static sampleLinearDepth(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()

static samplePositionFromDepth(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()

static sampleLinearDepthWithBackface(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()

static encodeColorOutput(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

Released under the MIT License.