Skip to content

Effect ​

A post-processing effect of the experience, as a script changes it while it runs. Get one with scene.getEffect(id). Changes apply to the running effect only, never to the stored one, and they last while the experience runs, also when a scene change or an action shows the effect again.

Properties ​

id read-only ​

  • Type: string
  • The effect's id in the experience.

Methods ​

setParameter() ​

javascript
setParameter(name: string, value: any, typeHint?: any): Effect

Sets a parameter of the effect's shader. Converts the value as Material.setParameter does, and replaces a parameter bound to a variable. A name the shader does not have is reported in the console.

Example:

javascript
scene.getEffect('vignetteEffectId')
    .setParameter('strength', 0.8)
    .setParameter('tint', '#FF3366', { type: 'color' });

Parameters:

  • name (string) - The parameter's name, as the shader's Parameters panel shows it.
  • value (any) - Number, boolean, string, array (vector2/3/4), Vector3, or a color ('#RRGGBB', Color).
  • typeHint (any) (optional) - Overrides the inferred type: { type: "float" | "int" | "vector2" | "vector3" | "vector4" | "matrix4x4" | "color" | "boolean" | "string" }.

Returns: Effect

shaderTexture() ​

javascript
shaderTexture(name: string, texture: any): Effect

Binds a texture to one of the effect shader's named texture slots. Takes what Material.shaderTexture takes: a URL, an asset id or a texture handle, and a texture handle keeps updating in the slot. A slot the shader does not have, a texture of another kind than the slot reads, or one that fails to load is reported in the console.

Example:

javascript
const trail = await Texture.compute({ pixelFormat: 'rgba16Float', width: 512, height: 512 });
scene.getEffect('smearEffectId').shaderTexture('trail', trail).shaderTexture('grain', 'grainAssetId');

Parameters:

  • name (string) - The slot's name.
  • texture (any) - A URL, an asset id or a texture handle.

Returns: Effect