I’m trying to do some GPGPU in Three.js and the title pretty much says it all
Here’s a short version of my code:
var geometry = new THREE.PlaneBufferGeometry();
var camera = new THREE.OrthographicCamera( 0, 1, 1, 0, -1000, 1000 );
export function shade2(inTex, fragmentShader) {
var uniforms = { tex: { value: inTex } };
var material = new THREE.ShaderMaterial( {
uniforms: uniforms,
vertexShader: vertexShader,
fragmentShader: fragmentShader,
side: THREE.DoubleSide
} );
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set(.5, .5, 0);
var scene = new THREE.Scene();
var renderTarget = new THREE.WebGLRenderTarget(inTex.width, inTex.height);
scene.add( mesh );
renderer.setRenderTarget(renderTarget);
renderer.render(scene, camera);
material.dispose();
renderTarget.dispose();
return renderTarget.texture;
}
Of course, the texture returned by shade2 is invalid because renderTarget.dispose();
has already disposed that texture.
TIA!