Skip to content

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

readonly static BILLBOARD_SPHERICAL: 1 = 1

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


BILLBOARD_SYLINDRAL

readonly static BILLBOARD_SYLINDRAL: 2 = 2

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


MATERIAL_INSTANCE_DATA_OFFSET

readonly static MATERIAL_INSTANCE_DATA_OFFSET: 9 = 9

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

Methods

getObjectColorUniformName()

static getObjectColorUniformName(): string

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

Returns

string


getWorldMatrixUniformName()

static getWorldMatrixUniformName(): string

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

Returns

string


getPrevWorldMatrixUniformName()

static getPrevWorldMatrixUniformName(): string

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

Returns

string


getPrevWorldMatrixFrameUniformName()

static getPrevWorldMatrixFrameUniformName(): string

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

Returns

string


getInstanceDataUniformName()

static getInstanceDataUniformName(): string

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

Returns

string


getInstanceDataOffsetUniformName()

static getInstanceDataOffsetUniformName(): string

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

Returns

string


getInstanceDataStrideUniformName()

static getInstanceDataStrideUniformName(): string

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

Returns

string


getBoneMatricesUniformName()

static getBoneMatricesUniformName(): string

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

Returns

string


getBoneTextureSizeUniformName()

static getBoneTextureSizeUniformName(): string

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

Returns

string


getBoneInvBindMatrixUniformName()

static getBoneInvBindMatrixUniformName(): string

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

Returns

string


getMorphDataUniformName()

static getMorphDataUniformName(): string

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

Returns

string


getMorphInfoUniformName()

static getMorphInfoUniformName(): string

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

Returns

string


getLightBufferUniformName()

static getLightBufferUniformName(): string

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

Returns

string


getDrawableBindGroupLayout()

static getDrawableBindGroupLayout(skinning, morphing, instancing): BindGroupLayout

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

Parameters

skinning

boolean

morphing

boolean

instancing

boolean

Returns

BindGroupLayout


prepareFragmentShader()

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

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:189

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: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()

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

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

static calculateMorphDelta(scope, attrib): PBShaderExp

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

Parameters

scope

PBInsideFunctionScope

attrib

number

Returns

PBShaderExp


resolveVertexPosition()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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:1576

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: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()

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

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

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

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

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

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

Released under the MIT License.