Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MaterialHelper

"Static Class" containing the most commonly used helper while dealing with material for rendering purpose.

It contains the basic tools to help defining defines, binding uniform for the common part of the materials.

This works by convention in BabylonJS but is meant to be use only with shader following the in place naming rules and conventions.

Hierarchy

  • MaterialHelper

Index

Methods

Static BindBonesParametersSearch playground for BindBonesParameters

  • Binds the bones information from the mesh to the effect.

    Parameters

    • Optional mesh: AbstractMesh

      The mesh we are binding the information to render

    • Optional effect: Effect

      The effect we are binding the data to

    • Optional prePassConfiguration: PrePassConfiguration

      Configuration for the prepass, in case prepass is activated

    Returns void

Static BindClipPlaneSearch playground for BindClipPlane

  • Binds the clip plane information from the scene to the effect.

    Parameters

    • effect: Effect

      The effect we are binding the data to

    • scene: Scene

      The scene the clip plane information are extracted from

    Returns void

Static BindFogParametersSearch playground for BindFogParameters

  • Binds the fog information from the scene to the effect for the given mesh.

    Parameters

    • scene: Scene

      The scene the lights belongs to

    • mesh: AbstractMesh

      The mesh we are binding the information to render

    • effect: Effect

      The effect we are binding the data to

    • Optional linearSpace: boolean

      Defines if the fog effect is applied in linear space

    Returns void

Static BindLightSearch playground for BindLight

  • BindLight(light: Light, lightIndex: number, scene: Scene, effect: Effect, useSpecular: boolean, receiveShadows?: boolean): void
  • Binds the lights information from the scene to the effect for the given mesh.

    Parameters

    • light: Light

      Light to bind

    • lightIndex: number

      Light index

    • scene: Scene

      The scene where the light belongs to

    • effect: Effect

      The effect we are binding the data to

    • useSpecular: boolean

      Defines if specular is supported

    • Optional receiveShadows: boolean

      Defines if the effect (mesh) we bind the light for receives shadows

    Returns void

Static BindLightPropertiesSearch playground for BindLightProperties

  • BindLightProperties(light: Light, effect: Effect, lightIndex: number): void
  • Binds the light information to the effect.

    Parameters

    • light: Light

      The light containing the generator

    • effect: Effect

      The effect we are binding the data to

    • lightIndex: number

      The light index in the effect used to render

    Returns void

Static BindLightsSearch playground for BindLights

  • Binds the lights information from the scene to the effect for the given mesh.

    Parameters

    • scene: Scene

      The scene the lights belongs to

    • mesh: AbstractMesh

      The mesh we are binding the information to render

    • effect: Effect

      The effect we are binding the data to

    • defines: any

      The generated defines for the effect

    • Optional maxSimultaneousLights: number

      The maximum number of light that can be bound to the effect

    Returns void

Static BindLogDepthSearch playground for BindLogDepth

  • BindLogDepth(defines: any, effect: Effect, scene: Scene): void
  • Binds the logarithmic depth information from the scene to the effect for the given defines.

    Parameters

    • defines: any

      The generated defines used in the effect

    • effect: Effect

      The effect we are binding the data to

    • scene: Scene

      The scene we are willing to render with logarithmic scale for

    Returns void

Static BindMorphTargetParametersSearch playground for BindMorphTargetParameters

  • Binds the morph targets information from the mesh to the effect.

    Parameters

    • abstractMesh: AbstractMesh

      The mesh we are binding the information to render

    • effect: Effect

      The effect we are binding the data to

    Returns void

Static BindSceneUniformBufferSearch playground for BindSceneUniformBuffer

  • Binds the scene's uniform buffer to the effect.

    Parameters

    • effect: Effect

      defines the effect to bind to the scene uniform buffer

    • sceneUbo: UniformBuffer

      defines the uniform buffer storing scene data

    Returns void

Static BindTextureMatrixSearch playground for BindTextureMatrix

  • Binds a texture matrix value to its corresponding uniform

    Parameters

    • texture: BaseTexture

      The texture to bind the matrix for

    • uniformBuffer: UniformBuffer

      The uniform buffer receiving the data

    • key: string

      The channel key "diffuse", "specular"... used in the shader

    Returns void

Static GetFogStateSearch playground for GetFogState

  • Gets the current status of the fog (should it be enabled?)

    Parameters

    • mesh: AbstractMesh

      defines the mesh to evaluate for fog support

    • scene: Scene

      defines the hosting scene

    Returns boolean

    true if fog must be enabled

Static HandleFallbacksForShadowsSearch playground for HandleFallbacksForShadows

  • HandleFallbacksForShadows(defines: any, fallbacks: EffectFallbacks, maxSimultaneousLights?: number, rank?: number): number
  • This helps decreasing rank by rank the shadow quality (0 being the highest rank and quality)

    Parameters

    • defines: any

      The defines to update while falling back

    • fallbacks: EffectFallbacks

      The authorized effect fallbacks

    • Optional maxSimultaneousLights: number

      The maximum number of lights allowed

    • Optional rank: number

      the current rank of the Effect

    Returns number

    The newly affected rank

Static PrepareAttributesForBonesSearch playground for PrepareAttributesForBones

  • Prepares the list of attributes required for bones according to the effect defines.

    Parameters

    • attribs: string[]

      The current list of supported attribs

    • mesh: AbstractMesh

      The mesh to prepare the bones attributes for

    • defines: any

      The current Defines of the effect

    • fallbacks: EffectFallbacks

      The current effect fallback strategy

    Returns void

Static PrepareAttributesForInstancesSearch playground for PrepareAttributesForInstances

  • PrepareAttributesForInstances(attribs: string[], defines: MaterialDefines): void
  • Check and prepare the list of attributes required for instances according to the effect defines.

    Parameters

    • attribs: string[]

      The current list of supported attribs

    • defines: MaterialDefines

      The current MaterialDefines of the effect

    Returns void

Static PrepareAttributesForMorphTargetsSearch playground for PrepareAttributesForMorphTargets

  • PrepareAttributesForMorphTargets(attribs: string[], mesh: AbstractMesh, defines: any): void
  • Prepares the list of attributes required for morph targets according to the effect defines.

    Parameters

    • attribs: string[]

      The current list of supported attribs

    • mesh: AbstractMesh

      The mesh to prepare the morph targets attributes for

    • defines: any

      The current Defines of the effect

    Returns void

Static PrepareAttributesForMorphTargetsInfluencersSearch playground for PrepareAttributesForMorphTargetsInfluencers

  • PrepareAttributesForMorphTargetsInfluencers(attribs: string[], mesh: AbstractMesh, influencers: number): void
  • Prepares the list of attributes required for morph targets according to the effect defines.

    Parameters

    • attribs: string[]

      The current list of supported attribs

    • mesh: AbstractMesh

      The mesh to prepare the morph targets attributes for

    • influencers: number

      The number of influencers

    Returns void

Static PrepareDefinesForAttributesSearch playground for PrepareDefinesForAttributes

  • PrepareDefinesForAttributes(mesh: AbstractMesh, defines: any, useVertexColor: boolean, useBones: boolean, useMorphTargets?: boolean, useVertexAlpha?: boolean): boolean
  • Prepares the defines used in the shader depending on the attributes data available in the mesh

    Parameters

    • mesh: AbstractMesh

      The mesh containing the geometry data we will draw

    • defines: any

      The defines to update

    • useVertexColor: boolean

      Precise whether vertex colors should be used or not (override mesh info)

    • useBones: boolean

      Precise whether bones should be used or not (override mesh info)

    • Optional useMorphTargets: boolean

      Precise whether morph targets should be used or not (override mesh info)

    • Optional useVertexAlpha: boolean

      Precise whether vertex alpha should be used or not (override mesh info)

    Returns boolean

    false if defines are considered not dirty and have not been checked

Static PrepareDefinesForBonesSearch playground for PrepareDefinesForBones

  • PrepareDefinesForBones(mesh: AbstractMesh, defines: any): void
  • Prepares the defines for bones

    Parameters

    • mesh: AbstractMesh

      The mesh containing the geometry data we will draw

    • defines: any

      The defines to update

    Returns void

Static PrepareDefinesForFrameBoundValuesSearch playground for PrepareDefinesForFrameBoundValues

  • PrepareDefinesForFrameBoundValues(scene: Scene, engine: Engine, defines: any, useInstances: boolean, useClipPlane?: Nullable<boolean>, useThinInstances?: boolean): void
  • Helper used to prepare the list of defines associated with frame values for shader compilation

    Parameters

    • scene: Scene

      defines the current scene

    • engine: Engine

      defines the current engine

    • defines: any

      specifies the list of active defines

    • useInstances: boolean

      defines if instances have to be turned on

    • Optional useClipPlane: Nullable<boolean>

      defines if clip plane have to be turned on

    • Optional useThinInstances: boolean

      defines if thin instances have to be turned on

    Returns void

Static PrepareDefinesForLightSearch playground for PrepareDefinesForLight

  • PrepareDefinesForLight(scene: Scene, mesh: AbstractMesh, light: Light, lightIndex: number, defines: any, specularSupported: boolean, state: { lightmapMode: boolean; needNormals: boolean; needRebuild: boolean; shadowEnabled: boolean; specularEnabled: boolean }): void
  • Prepares the defines related to the light information passed in parameter

    Parameters

    • scene: Scene

      The scene we are intending to draw

    • mesh: AbstractMesh

      The mesh the effect is compiling for

    • light: Light

      The light the effect is compiling for

    • lightIndex: number

      The index of the light

    • defines: any

      The defines to update

    • specularSupported: boolean

      Specifies whether specular is supported or not (override lights data)

    • state: { lightmapMode: boolean; needNormals: boolean; needRebuild: boolean; shadowEnabled: boolean; specularEnabled: boolean }

      Defines the current state regarding what is needed (normals, etc...)

      • lightmapMode: boolean
      • needNormals: boolean
      • needRebuild: boolean
      • shadowEnabled: boolean
      • specularEnabled: boolean

    Returns void

Static PrepareDefinesForLightsSearch playground for PrepareDefinesForLights

  • PrepareDefinesForLights(scene: Scene, mesh: AbstractMesh, defines: any, specularSupported: boolean, maxSimultaneousLights?: number, disableLighting?: boolean): boolean
  • Prepares the defines related to the light information passed in parameter

    Parameters

    • scene: Scene

      The scene we are intending to draw

    • mesh: AbstractMesh

      The mesh the effect is compiling for

    • defines: any

      The defines to update

    • specularSupported: boolean

      Specifies whether specular is supported or not (override lights data)

    • Optional maxSimultaneousLights: number

      Specifies how manuy lights can be added to the effect at max

    • Optional disableLighting: boolean

      Specifies whether the lighting is disabled (override scene and light)

    Returns boolean

    true if normals will be required for the rest of the effect

Static PrepareDefinesForMergedUVSearch playground for PrepareDefinesForMergedUV

  • PrepareDefinesForMergedUV(texture: BaseTexture, defines: any, key: string): void
  • Helps preparing the defines values about the UVs in used in the effect. UVs are shared as much as we can across channels in the shaders.

    Parameters

    • texture: BaseTexture

      The texture we are preparing the UVs for

    • defines: any

      The defines to update

    • key: string

      The channel key "diffuse", "specular"... used in the shader

    Returns void

Static PrepareDefinesForMiscSearch playground for PrepareDefinesForMisc

  • PrepareDefinesForMisc(mesh: AbstractMesh, scene: Scene, useLogarithmicDepth: boolean, pointsCloud: boolean, fogEnabled: boolean, alphaTest: boolean, defines: any): void
  • Helper used to prepare the list of defines associated with misc. values for shader compilation

    Parameters

    • mesh: AbstractMesh

      defines the current mesh

    • scene: Scene

      defines the current scene

    • useLogarithmicDepth: boolean

      defines if logarithmic depth has to be turned on

    • pointsCloud: boolean

      defines if point cloud rendering has to be turned on

    • fogEnabled: boolean

      defines if fog has to be turned on

    • alphaTest: boolean

      defines if alpha testing has to be turned on

    • defines: any

      defines the current list of defines

    Returns void

Static PrepareDefinesForMorphTargetsSearch playground for PrepareDefinesForMorphTargets

  • PrepareDefinesForMorphTargets(mesh: AbstractMesh, defines: any): void
  • Prepares the defines for morph targets

    Parameters

    • mesh: AbstractMesh

      The mesh containing the geometry data we will draw

    • defines: any

      The defines to update

    Returns void

Static PrepareDefinesForMultiviewSearch playground for PrepareDefinesForMultiview

  • PrepareDefinesForMultiview(scene: Scene, defines: any): void
  • Prepares the defines related to multiview

    Parameters

    • scene: Scene

      The scene we are intending to draw

    • defines: any

      The defines to update

    Returns void

Static PrepareDefinesForPrePassSearch playground for PrepareDefinesForPrePass

  • PrepareDefinesForPrePass(scene: Scene, defines: any, canRenderToMRT: boolean): void
  • Prepares the defines related to the prepass

    Parameters

    • scene: Scene

      The scene we are intending to draw

    • defines: any

      The defines to update

    • canRenderToMRT: boolean

      Indicates if this material renders to several textures in the prepass

    Returns void

Static PrepareUniformsAndSamplersForLightSearch playground for PrepareUniformsAndSamplersForLight

  • PrepareUniformsAndSamplersForLight(lightIndex: number, uniformsList: string[], samplersList: string[], projectedLightTexture?: any, uniformBuffersList?: Nullable<string[]>, updateOnlyBuffersList?: boolean): void
  • Prepares the uniforms and samplers list to be used in the effect (for a specific light)

    Parameters

    • lightIndex: number

      defines the light index

    • uniformsList: string[]

      The uniform list

    • samplersList: string[]

      The sampler list

    • Optional projectedLightTexture: any

      defines if projected texture must be used

    • Optional uniformBuffersList: Nullable<string[]>

      defines an optional list of uniform buffers

    • Optional updateOnlyBuffersList: boolean

      True to only update the uniformBuffersList array

    Returns void

Static PrepareUniformsAndSamplersListSearch playground for PrepareUniformsAndSamplersList

  • PrepareUniformsAndSamplersList(uniformsListOrOptions: string[] | IEffectCreationOptions, samplersList?: string[], defines?: any, maxSimultaneousLights?: number): void
  • Prepares the uniforms and samplers list to be used in the effect

    Parameters

    • uniformsListOrOptions: string[] | IEffectCreationOptions

      The uniform names to prepare or an EffectCreationOptions containing the list and extra information

    • Optional samplersList: string[]

      The sampler list

    • Optional defines: any

      The defines helping in the list generation

    • Optional maxSimultaneousLights: number

      The maximum number of simultaneous light allowed in the effect

    Returns void

Static PushAttributesForInstancesSearch playground for PushAttributesForInstances

  • PushAttributesForInstances(attribs: string[], needsPreviousMatrices?: boolean): void
  • Add the list of attributes required for instances to the attribs array.

    Parameters

    • attribs: string[]

      The current list of supported attribs

    • Optional needsPreviousMatrices: boolean

      If the shader needs previous matrices

    Returns void

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method