ShadowGenerator

Default implementation IShadowGenerator. This is the main object responsible of generating shadows in the framework. Documentation: https://doc.babylonjs.com/babylon101/shadows

Hierarchy

  • ShadowGenerator

Implements

Index

Constructors

constructor

Find examples in Playground
  • Creates a ShadowGenerator object. A ShadowGenerator is the required tool to use the shadows. Each light casting shadows needs to use its own ShadowGenerator. Documentation : http://doc.babylonjs.com/tutorials/shadows

    Parameters

    • mapSize: number

      The size of the texture what stores the shadows. Example : 1024.

    • light: IShadowLight

      The light object generating the shadows.

    • Optional useFullFloatFirst: boolean

      By default the generator will try to use half float textures but if you need precision (for self shadowing for instance), you can use this option to enforce full float texture.

    Returns ShadowGenerator

Properties

bias

Find examples in Playground
bias: number

Sets the bias: offset applied on the depth preventing acnea (in light direction).

blurBoxOffset

Find examples in Playground
blurBoxOffset: number

Sets the blur box offset: offset applied during the blur pass. Only usefull if useKernelBlur = false

blurKernel

Find examples in Playground
blurKernel: number

Sets the blur kernel: kernel size of the blur pass. Only usefull if useKernelBlur = true

blurScale

Find examples in Playground
blurScale: number

Sets the blur scale: scale of the blurred texture compared to the main shadow map. 2 means half of the size.

contactHardeningLightSizeUVRatio

Find examples in Playground
contactHardeningLightSizeUVRatio: number

Sets the Light Size (in shadow map uv unit) used in PCSS to determine the blocker search area and the penumbra size. Using a ratio helps keeping shape stability independently of the map size.

It does not account for the light projection as it was having too much instability during the light setup or during light position changes.

Only valid if useContactHardeningShadow is true.

depthScale

Find examples in Playground
depthScale: number

Sets the depth scale used in ESM mode. This can override the scale stored on the light.

filter

Find examples in Playground
filter: number

Sets the current mode of the shadow generator (normal, PCF, ESM...). The returned value is a number equal to one of the available mode defined in ShadowMap.FILTER_x like FILTERNONE

filteringQuality

Find examples in Playground
filteringQuality: number

Sets the PCF or PCSS Quality. Only valid if usePercentageCloserFiltering or usePercentageCloserFiltering is true.

forceBackFacesOnly

Find examples in Playground
forceBackFacesOnly: boolean

If true the shadow map is generated by rendering the back face of the mesh instead of the front face. This can help with self-shadowing as the geometry making up the back of objects is slightly offset. It might on the other hand introduce peter panning.

frustumEdgeFalloff

Find examples in Playground
frustumEdgeFalloff: number

Controls the extent to which the shadows fade out at the edge of the frustum Used only by directionals and spots

normalBias

Find examples in Playground
normalBias: number

Sets the normalBias: offset applied on the depth preventing acnea (along side the normal direction and proportinal to the light/normal angle).

useBlurCloseExponentialShadowMap

Find examples in Playground
useBlurCloseExponentialShadowMap: boolean

Sets the current filter to filtered "close ESM" (using the inverse of the exponential to prevent steep falloff artifacts).

useBlurExponentialShadowMap

Find examples in Playground
useBlurExponentialShadowMap: boolean

Gets if the current filter is set to filtered ESM.

useBlurVarianceShadowMap

Find examples in Playground
useBlurVarianceShadowMap: boolean

Sets the current filter is to blurred VSM. DEPRECATED. Should use useBlurExponentialShadowMap instead.

useCloseExponentialShadowMap

Find examples in Playground
useCloseExponentialShadowMap: boolean

Sets the current filter to "close ESM" (using the inverse of the exponential to prevent steep falloff artifacts).

useContactHardeningShadow

Find examples in Playground
useContactHardeningShadow: boolean

Sets the current filter to "PCSS" (contact hardening).

useExponentialShadowMap

Find examples in Playground
useExponentialShadowMap: boolean

Sets the current filter is to ESM.

useKernelBlur

Find examples in Playground
useKernelBlur: boolean

Sets whether the blur pass is a kernel blur (if true) or box blur. Only usefull in filtered mode (useBlurExponentialShadowMap...)

usePercentageCloserFiltering

Find examples in Playground
usePercentageCloserFiltering: boolean

Sets the current filter to "PCF" (percentage closer filtering).

usePoissonSampling

Find examples in Playground
usePoissonSampling: boolean

Sets the current filter to Poisson Sampling.

useVarianceShadowMap

Find examples in Playground
useVarianceShadowMap: boolean

Sets the current filter is to VSM. DEPRECATED. Should use useExponentialShadowMap instead.

Static FILTER_BLURCLOSEEXPONENTIALSHADOWMAP

Find examples in Playground
FILTER_BLURCLOSEEXPONENTIALSHADOWMAP: number

Shadow generator mode ESM: Blurred Exponential Shadow Mapping using the inverse of the exponential preventing edge artifacts on steep falloff. (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)

Static FILTER_BLUREXPONENTIALSHADOWMAP

Find examples in Playground
FILTER_BLUREXPONENTIALSHADOWMAP: number

Shadow generator mode ESM: Blurred Exponential Shadow Mapping. (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)

Static FILTER_CLOSEEXPONENTIALSHADOWMAP

Find examples in Playground
FILTER_CLOSEEXPONENTIALSHADOWMAP: number

Shadow generator mode ESM: Exponential Shadow Mapping using the inverse of the exponential preventing edge artifacts on steep falloff. (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)

Static FILTER_EXPONENTIALSHADOWMAP

Find examples in Playground
FILTER_EXPONENTIALSHADOWMAP: number

Shadow generator mode ESM: Exponential Shadow Mapping. (http://developer.download.nvidia.com/presentations/2008/GDC/GDC08_SoftShadowMapping.pdf)

Static FILTER_NONE

Find examples in Playground
FILTER_NONE: number

Shadow generator mode None: no filtering applied.

Static FILTER_PCF

Find examples in Playground
FILTER_PCF: number

Shadow generator mode PCF: Percentage Closer Filtering benefits from Webgl 2 shadow samplers. Fallback to Poisson Sampling in Webgl 1 (https://developer.nvidia.com/gpugems/GPUGems/gpugems_ch11.html)

Static FILTER_PCSS

Find examples in Playground
FILTER_PCSS: number

Shadow generator mode PCSS: Percentage Closering Soft Shadow. benefits from Webgl 2 shadow samplers. Fallback to Poisson Sampling in Webgl 1 Contact Hardening

Static FILTER_POISSONSAMPLING

Find examples in Playground
FILTER_POISSONSAMPLING: number

Shadow generator mode Poisson Sampling: Percentage Closer Filtering. (Multiple Tap around evenly distributed around the pixel are used to evaluate the shadow strength)

Static QUALITY_HIGH

Find examples in Playground
QUALITY_HIGH: number

Reserved for PCF and PCSS Highest Quality.

Execute PCF on a 5*5 kernel improving a lot the shadow aliasing artifacts.

Execute PCSS with 32 taps blocker search and 64 taps PCF.

Static QUALITY_LOW

Find examples in Playground
QUALITY_LOW: number

Reserved for PCF and PCSS The lowest quality but the fastest.

Execute PCF on a 1*1 kernel.

Execute PCSS with 16 taps blocker search and 16 taps PCF.

Static QUALITY_MEDIUM

Find examples in Playground
QUALITY_MEDIUM: number

Reserved for PCF and PCSS Good tradeoff for quality/perf cross devices

Execute PCF on a 3*3 kernel.

Execute PCSS with 16 taps blocker search and 32 taps PCF.

Methods

addShadowCaster

Find examples in Playground
  • Helper function to add a mesh and its descendants to the list of shadow casters.

    Parameters

    • mesh: AbstractMesh

      Mesh to add

    • Optional includeDescendants: boolean

      boolean indicating if the descendants should be added. Default to true

    Returns ShadowGenerator

    the Shadow Generator itself

bindShadowLight

Find examples in Playground
  • bindShadowLight(lightIndex: string, effect: Effect): void
  • Binds the shadow related information inside of an effect (information like near, far, darkness... defined in the generator but impacting the effect).

    Parameters

    • lightIndex: string

      Index of the light in the enabled light list of the material owning the effect

    • effect: Effect

      The effect we are binfing the information for

    Returns void

dispose

Find examples in Playground
  • dispose(): void

forceCompilation

Find examples in Playground
  • forceCompilation(onCompiled?: function, options?: Partial<object>): void
  • Forces all the attached effect to compile to enable rendering only once ready vs. lazyly compiling effects.

    Parameters

    • Optional onCompiled: function

      Callback triggered at the and of the effects compilation

    • Optional options: Partial<object>

      Sets of optional options forcing the compilation with different modes

    Returns void

forceCompilationAsync

Find examples in Playground
  • forceCompilationAsync(options?: Partial<object>): Promise<void>
  • Forces all the attached effect to compile to enable rendering only once ready vs. lazyly compiling effects.

    Parameters

    • Optional options: Partial<object>

      Sets of optional options forcing the compilation with different modes

    Returns Promise<void>

    A promise that resolves when the compilation completes

getDarkness

Find examples in Playground
  • getDarkness(): number
  • Returns the darkness value (float). This can only decrease the actual darkness of a shadow. 0 means strongest and 1 would means no shadow.

    Returns number

    the darkness.

getLight

Find examples in Playground
  • Returns the associated light object.

    Returns IShadowLight

    the light generating the shadow

getShadowMap

Find examples in Playground

getShadowMapForRendering

Find examples in Playground

getTransformMatrix

Find examples in Playground
  • getTransformMatrix(): Matrix
  • Gets the transformation matrix used to project the meshes into the map from the light point of view. (eq to shadow prjection matrix * light transform matrix)

    Returns Matrix

    The transform matrix used to create the shadow map

isReady

Find examples in Playground
  • isReady(subMesh: SubMesh, useInstances: boolean): boolean
  • Determine wheter the shadow generator is ready or not (mainly all effects and related post processes needs to be ready).

    Parameters

    • subMesh: SubMesh

      The submesh we want to render in the shadow map

    • useInstances: boolean

      Defines wether will draw in the map using instances

    Returns boolean

    true if ready otherwise, false

prepareDefines

Find examples in Playground
  • prepareDefines(defines: any, lightIndex: number): void
  • Prepare all the defines in a material relying on a shadow map at the specified light index.

    Parameters

    • defines: any

      Defines of the material we want to update

    • lightIndex: number

      Index of the light in the enabled light list of the material

    Returns void

recreateShadowMap

Find examples in Playground
  • recreateShadowMap(): void
  • Recreates the shadow map dependencies like RTT and post processes. This can be used during the switch between Cube and 2D textures for instance.

    Returns void

removeShadowCaster

Find examples in Playground
  • Helper function to remove a mesh and its descendants from the list of shadow casters

    Parameters

    • mesh: AbstractMesh

      Mesh to remove

    • Optional includeDescendants: boolean

      boolean indicating if the descendants should be removed. Default to true

    Returns ShadowGenerator

    the Shadow Generator itself

serialize

Find examples in Playground
  • serialize(): any
  • Serializes the shadow generator setup to a json object.

    Returns any

    The serialized JSON object

setDarkness

Find examples in Playground
  • Sets the darkness value (float). This can only decrease the actual darkness of a shadow.

    Parameters

    • darkness: number

      The darkness value 0 means strongest and 1 would means no shadow.

    Returns ShadowGenerator

    the shadow generator allowing fluent coding.

setTransparencyShadow

Find examples in Playground
  • Sets the ability to have transparent shadow (boolean).

    Parameters

    • transparent: boolean

      True if transparent else False

    Returns ShadowGenerator

    the shadow generator allowing fluent coding

Static Parse

Find examples in Playground
  • Parses a serialized ShadowGenerator and returns a new ShadowGenerator.

    Parameters

    • parsedShadowGenerator: any

      The JSON object to parse

    • scene: Scene

      The scene to create the shadow map for

    Returns ShadowGenerator

    The parsed shadow generator

Generated using TypeDoc