Home Reference Source
public class | source

Effect

An abstract effect.

Effects can be combined using the EffectPass.

Constructor Summary

Public Constructor
public

constructor(name: String, fragmentShader: String, options: Object)

Constructs a new effect.

Member Summary

Public Members
public

[key]: *

public

The effect attributes.

public

The blend mode of this effect.

public

Preprocessor macro definitions.

public

WebGL extensions that are required by this effect.

public

The fragment shader.

public

The name of this effect.

public

uniforms: Map<String, Uniform>

Shader uniforms.

public

The vertex shader.

Method Summary

Public Methods
public

Performs a shallow search for properties that define a dispose method and deletes them.

public

initialize(renderer: WebGLRenderer, alpha: Boolean)

Performs initialization tasks.

public

setDepthTexture(depthTexture: Texture, depthPacking: Number)

Sets the depth texture.

public

setSize(width: Number, height: Number)

Updates the size of this effect.

public

update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, delta: Number)

Updates the effect by performing supporting operations.

Public Constructors

public constructor(name: String, fragmentShader: String, options: Object) source

Constructs a new effect.

Params:

NameTypeAttributeDescription
name String

The name of this effect. Doesn't have to be unique.

fragmentShader String

The fragment shader. This shader is required.

options Object
  • optional

Additional options.

options.attributes EffectAttribute
  • optional
  • default: EffectAttribute.NONE

The effect attributes that determine the execution priority and resource requirements.

options.blendFunction BlendFunction
  • optional
  • default: BlendFunction.SCREEN

The blend function of this effect.

options.defines Map<String, String>
  • optional

Custom preprocessor macro definitions. Keys are names and values are code.

options.uniforms Map<String, Uniform>
  • optional

Custom shader uniforms. Keys are names and values are uniforms.

options.extensions Set<WebGLExtension>
  • optional

WebGL extensions.

options.vertexShader String
  • optional
  • default: null

The vertex shader. Most effects don't need one.

Public Members

public [key]: * source

public attributes: EffectAttribute source

The effect attributes.

Effects that have the same attributes will be executed in the order in which they were registered. Some attributes imply a higher priority.

public blendMode: BlendMode source

The blend mode of this effect.

The result of this effect will be blended with the result of the previous effect using this blend mode.

Feel free to adjust the opacity of the blend mode at runtime. However, you'll need to call EffectPass#recompile if you change the blend function.

public defines: Map<String, String> source

Preprocessor macro definitions.

You'll need to call EffectPass#recompile after changing a macro.

public extensions: Set<WebGLExtension> source

WebGL extensions that are required by this effect.

You'll need to call EffectPass#recompile after adding or removing an extension.

public fragmentShader: String source

The fragment shader.

public name: String source

The name of this effect.

public uniforms: Map<String, Uniform> source

Shader uniforms.

You may freely modify the values of these uniforms at runtime. However, uniforms must not be removed or added after the effect was created.

public vertexShader: String source

The vertex shader.

Public Methods

public dispose() source

Performs a shallow search for properties that define a dispose method and deletes them. The effect will be inoperative after this method was called!

Disposable objects:

  • render targets
  • materials
  • textures

The EffectPass calls this method when it is being destroyed. Do not call this method directly.

public initialize(renderer: WebGLRenderer, alpha: Boolean) source

Performs initialization tasks.

By overriding this method you gain access to the renderer. You'll also be able to configure your custom render targets to use the appropriate format (RGB or RGBA).

The provided renderer can be used to warm up special off-screen render targets by performing a preliminary render operation.

The EffectPass calls this method during its own initialization which happens after the size has been set.

Params:

NameTypeAttributeDescription
renderer WebGLRenderer

The renderer.

alpha Boolean

Whether the renderer uses the alpha channel or not.

Example:

if(!alpha) { this.myRenderTarget.texture.format = RGBFormat; }

public setDepthTexture(depthTexture: Texture, depthPacking: Number) source

Sets the depth texture.

You may override this method if your effect requires direct access to the depth texture that is bound to the associated EffectPass.

Params:

NameTypeAttributeDescription
depthTexture Texture

A depth texture.

depthPacking Number
  • optional
  • default: 0

The depth packing.

public setSize(width: Number, height: Number) source

Updates the size of this effect.

You may override this method in case you want to be informed about the main render size.

The EffectPass calls this method before this effect is initialized and every time its own size is updated.

Params:

NameTypeAttributeDescription
width Number

The width.

height Number

The height.

Example:

this.myRenderTarget.setSize(width, height);

public update(renderer: WebGLRenderer, inputBuffer: WebGLRenderTarget, delta: Number) source

Updates the effect by performing supporting operations.

This method is called by the EffectPass right before the main fullscreen render operation, even if the blend function is set to SKIP.

You may override this method if you need to render additional off-screen textures or update custom uniforms.

Params:

NameTypeAttributeDescription
renderer WebGLRenderer

The renderer.

inputBuffer WebGLRenderTarget

A frame buffer that contains the result of the previous pass.

delta Number
  • optional

The time between the last frame and the current one in seconds.