Import
GPUComputationRenderer is an addon, and must be imported explicitly, see Installation#Addons.
import { GPUComputationRenderer } from 'three/addons/misc/GPUComputationRenderer.js';
Constructor
new GPUComputationRenderer( sizeX : number, sizeY : number, renderer : WebGLRenderer )
Constructs a new GPU computation renderer.
| sizeX |
Computation problem size is always 2d: sizeX * sizeY elements. |
| sizeY |
Computation problem size is always 2d: sizeX * sizeY elements. |
| renderer |
The renderer. |
Properties
.addResolutionDefine
Adds a resolution defined for the given material shader.
Methods
.addVariable( variableName : string, computeFragmentShader : string, initialValueTexture : Texture ) : Object
Adds a compute variable to the renderer.
| variableName |
The variable name. |
| computeFragmentShader |
The compute (fragment) shader source. |
| initialValueTexture |
The initial value texture. |
- Returns: The compute variable.
.compute()
Executes the compute. This method is usually called in the animation loop.
.createRenderTarget( sizeXTexture : number, sizeYTexture : number, wrapS : number, wrapT : number, minFilter : number, magFilter : number ) : WebGLRenderTarget
Creates a new render target from the given parameters.
| sizeXTexture |
The width of the render target. |
| sizeYTexture |
The height of the render target. |
| wrapS |
The wrapS value. |
| wrapT |
The wrapS value. |
| minFilter |
The minFilter value. |
| magFilter |
The magFilter value. |
- Returns: The new render target.
.createTexture() : DataTexture
Creates a new data texture.
- Returns: The new data texture.
.dispose()
Frees all internal resources. Call this method if you don't need the renderer anymore.
.doRenderTarget( material : Material, output : WebGLRenderTarget )
Renders the given material into the given render target with a full-screen pass.
| material |
The material. |
| output |
The output. |
.getAlternateRenderTarget( variable : Object ) : WebGLRenderTarget
Returns the alternate render target for the given compute variable.
| variable |
The compute variable. |
- Returns: The alternate render target.
.getCurrentRenderTarget( variable : Object ) : WebGLRenderTarget
Returns the current render target for the given compute variable.
| variable |
The compute variable. |
- Returns: The current render target.
.init() : string
Initializes the renderer.
- Returns: Returns
nullif no errors are detected. Otherwise returns the error message.
.renderTexture( input : Texture, output : WebGLRenderTarget )
Renders the given texture into the given render target.
| input |
The input. |
| output |
The output. |
.setDataType( type : FloatType | HalfFloatType ) : GPUComputationRenderer
Sets the data type of the internal textures.
| type |
The type to set. |
- Returns: A reference to this renderer.
.setVariableDependencies( variable : Object, dependencies : Array.<Object> )
Sets variable dependencies.
| variable |
The compute variable. |
| dependencies |
Other compute variables that represents the dependencies. |