Phaser API Documentation

  Version: 
setSampler2DBuffer(uniformKey, texture, width, height, [textureIndex], [textureData])

Description:

Sets a sampler2D uniform on this shader where the source texture is a WebGLTexture.

This allows you to feed the output from one Shader into another:

let shader1 = this.add.shader(baseShader1, 0, 0, 512, 512).setRenderToTexture();
let shader2 = this.add.shader(baseShader2, 0, 0, 512, 512).setRenderToTexture('output');

shader1.setSampler2DBuffer('iChannel0', shader2.glTexture, 512, 512);
shader2.setSampler2DBuffer('iChannel0', shader1.glTexture, 512, 512);

In the above code, the result of baseShader1 is fed into Shader2 as the iChannel0 sampler2D uniform. The result of baseShader2 is then fed back into shader1 again, creating a feedback loop.

If you wish to use an image from the Texture Manager as a sampler2D input for this shader, see the Shader.setSampler2D method.

Parameters:

name type arguments description
uniformKey string

The key of the sampler2D uniform to be updated, i.e. iChannel0.

texture WebGLTexture

A WebGLTexture reference.

width number

The width of the texture.

height number

The height of the texture.

textureIndex number <optional>

The texture index.

textureData any <optional>

Additional texture data.

Returns:
Description:

This Shader instance.

Since: 3.19.0