Engine API Reference - v2.8.0
    Preparing search index...

    Class ParticleMaterial

    A material for rendering particle geometry by the particle emitter.

    Hierarchy (View Summary)

    Index

    Properties

    alphaTest: number = 0

    The alpha test reference value to control which fragments are written to the currently active render target based on alpha value. All fragments with an alpha value of less than the alphaTest reference value will be discarded. alphaTest defaults to 0 (all fragments pass).

    alphaToCoverage: boolean = false

    Enables or disables alpha to coverage (WebGL2 only). When enabled, and if hardware anti-aliasing is on, limited order-independent transparency can be achieved. Quality depends on the number of MSAA samples of the current render target. It can nicely soften edges of otherwise sharp alpha cutouts, but isn't recommended for large area semi-transparent surfaces. Note, that you don't need to enable blending to make alpha to coverage work. It will work without it, just like alphaTest.

    cull: number = CULLFACE_BACK

    Controls how triangles are culled based on their face direction with respect to the viewpoint. Can be:

    • CULLFACE_NONE: Do not cull triangles based on face direction.
    • CULLFACE_BACK: Cull the back faces of triangles (do not render triangles facing away from the view point).
    • CULLFACE_FRONT: Cull the front faces of triangles (do not render triangles facing towards the view point).

    Defaults to CULLFACE_BACK.

    emitter: ParticleEmitter = null

    The color of the particles.

    name: string = 'Untitled'

    The name of the material.

    stencilBack: null | StencilParameters = null

    Stencil parameters for back faces (default is null).

    stencilFront: null | StencilParameters = null

    Stencil parameters for front faces (default is null).

    userId: string = ''

    A unique id the user can assign to the material. The engine internally does not use this for anything, and the user can assign a value to this id for any purpose they like. Defaults to an empty string.

    Accessors

    • get alphaWrite(): boolean

      Gets whether the alpha channel is written to the color buffer.

      Returns boolean

    • set alphaWrite(value: boolean): void

      Sets whether the alpha channel is written to the color buffer. If true, the red component of fragments generated by the shader of this material is written to the color buffer of the currently active render target. If false, the alpha component will not be written. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get blueWrite(): boolean

      Gets whether the blue channel is written to the color buffer.

      Returns boolean

    • set blueWrite(value: boolean): void

      Sets whether the blue channel is written to the color buffer. If true, the red component of fragments generated by the shader of this material is written to the color buffer of the currently active render target. If false, the blue component will not be written. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get depthBias(): number

      Gets the offset for the output depth buffer value.

      Returns number

    • set depthBias(value: number): void

      Sets the offset for the output depth buffer value. Useful for decals to prevent z-fighting. Typically a small negative value (-0.1) is used to render the mesh slightly closer to the camera.

      Parameters

      • value: number

      Returns void

    • get depthTest(): boolean

      Gets whether depth testing is enabled.

      Returns boolean

    • set depthTest(value: boolean): void

      Sets whether depth testing is enabled. If true, fragments generated by the shader of this material are only written to the current render target if they pass the depth test. If false, fragments generated by the shader of this material are written to the current render target regardless of what is in the depth buffer. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get depthWrite(): boolean

      Gets whether depth writing is enabled.

      Returns boolean

    • set depthWrite(value: boolean): void

      Sets whether depth writing is enabled. If true, fragments generated by the shader of this material write a depth value to the depth buffer of the currently active render target. If false, no depth value is written. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get greenWrite(): boolean

      Gets whether the green channel is written to the color buffer.

      Returns boolean

    • set greenWrite(value: boolean): void

      Sets whether the green channel is written to the color buffer. If true, the red component of fragments generated by the shader of this material is written to the color buffer of the currently active render target. If false, the green component will not be written. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get redWrite(): boolean

      Gets whether the red channel is written to the color buffer.

      Returns boolean

    • set redWrite(value: boolean): void

      Sets whether the red channel is written to the color buffer. If true, the red component of fragments generated by the shader of this material is written to the color buffer of the currently active render target. If false, the red component will not be written. Defaults to true.

      Parameters

      • value: boolean

      Returns void

    • get shaderChunksVersion(): string

      Returns the version of the shader chunks.

      Returns string

    • set shaderChunksVersion(value: string): void

      Sets the version of the shader chunks.

      This should be a string containing the current engine major and minor version (e.g., '2.8' for engine v2.8.1) and ensures compatibility with the current engine version. When providing custom shader chunks, set this to the latest supported version. If a future engine release no longer supports the specified version, a warning will be issued. In that case, update your shader chunks to match the new format and set this to the latest version accordingly.

      Parameters

      • value: string

      Returns void

    • get slopeDepthBias(): number

      Gets the offset for the output depth buffer value based on the slope of the triangle relative to the camera.

      Returns number

    • set slopeDepthBias(value: number): void

      Sets the offset for the output depth buffer value based on the slope of the triangle relative to the camera.

      Parameters

      • value: number

      Returns void

    Methods

    • Returns true if a define is enabled on the material, otherwise false.

      Parameters

      • name: string

        The name of the define to check.

      Returns boolean

      The value of the define.

    • Returns an object containing shader chunks for a specific shader language for the material. These chunks define custom GLSL or WGSL code used to construct the final shader for the material. The chunks can be also be included in shaders using the #include "ChunkName" directive.

      On the WebGL platform:

      • If GLSL chunks are provided, they are used directly.

      On the WebGPU platform:

      • If WGSL chunks are provided, they are used directly.
      • If only GLSL chunks are provided, a GLSL shader is generated and then transpiled to WGSL, which is less efficient.

      To ensure faster shader compilation, it is recommended to provide shader chunks for all supported platforms.

      A simple example on how to override a shader chunk providing emissive color for both GLSL and WGSL to simply return a red color:

      material.getShaderChunks(pc.SHADERLANGUAGE_GLSL).set('emissivePS', `
      void getEmission() {
      dEmission = vec3(1.0, 0.0, 1.0);
      }
      `);

      material.getShaderChunks(pc.SHADERLANGUAGE_WGSL).set('emissivePS', `
      fn getEmission() {
      dEmission = vec3f(1.0, 0.0, 1.0);
      }
      `);

      // call update to apply the changes
      material.update();

      Parameters

      • OptionalshaderLanguage: string = SHADERLANGUAGE_GLSL

        Specifies the shader language of shaders. Defaults to SHADERLANGUAGE_GLSL.

      Returns ShaderChunkMap

      • The shader chunks for the specified shader language.
    • Adds or removes a define on the material. Defines can be used to enable or disable various parts of the shader code.

      Parameters

      • name: string

        The name of the define to set.

      • value: undefined | string | boolean

        The value of the define. If undefined or false, the define is removed.

        A simple example on how to set a custom shader define value used by the shader processor.

        material.setDefine('MY_DEFINE', true);

        // call update to apply the changes, which will recompile the shader using the new define
        material.update();

      Returns void