Skip to content

GPUComputationRenderer: Make use of FullScreenQuad. #28637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions examples/jsm/misc/GPUComputationRenderer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {
Camera,
ClampToEdgeWrapping,
DataTexture,
FloatType,
Mesh,
NearestFilter,
PlaneGeometry,
RGBAFormat,
Scene,
ShaderMaterial,
WebGLRenderTarget
} from 'three';

import { FullScreenQuad } from '../postprocessing/Pass.js';

/**
* GPUComputationRenderer, based on SimulationRenderer by zz85
*
Expand Down Expand Up @@ -119,20 +117,13 @@ class GPUComputationRenderer {

let dataType = FloatType;

const scene = new Scene();

const camera = new Camera();
camera.position.z = 1;

const passThruUniforms = {
passThruTexture: { value: null }
};

const passThruShader = createShaderMaterial( getPassThroughFragmentShader(), passThruUniforms );

const mesh = new Mesh( new PlaneGeometry( 2, 2 ), passThruShader );
scene.add( mesh );

const quad = new FullScreenQuad( passThruShader );

this.setDataType = function ( type ) {

Expand Down Expand Up @@ -284,8 +275,7 @@ class GPUComputationRenderer {

this.dispose = function () {

mesh.geometry.dispose();
mesh.material.dispose();
quad.dispose();

const variables = this.variables;

Expand Down Expand Up @@ -395,10 +385,10 @@ class GPUComputationRenderer {

renderer.xr.enabled = false; // Avoid camera modification
renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
mesh.material = material;
quad.material = material;
renderer.setRenderTarget( output );
renderer.render( scene, camera );
mesh.material = passThruShader;
quad.render( renderer );
quad.material = passThruShader;

renderer.xr.enabled = currentXrEnabled;
renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
Expand Down