Im trying to understand how to implement multiple buffers in three.js by porting a shader from shadertoy with help of this thread.
https://discourse.threejs.org/t/help-porting-shadertoy-to-threejs/
I tried to rewrite it for js but it doesnt compile.
Here is the code:
It is based on this one:
My understanding of using buffers is:
-
create a bufferscene
bufferAscene = new THREE.Scene();
-
create a texture
textureA = new THREE.WebGLRenderTarget(window.innerWidth, window.innerHeight, {
minFilter: THREE.LinearFilter,
magFilter: THREE.NearestFilter
}); -
create a shadermaterial where you define the uniforms for passing to the shader
bufferA = new THREE.ShaderMaterial({
uniforms: {
iFrame: { value: 0 },
iResolution: { value: resolution },
iMouse: { value: mousePosition },
iChannel0: { value: textureA.texture },
iChannel1: { value: textureB.texture }
},
vertexShader: VERTEX_SHADER,
fragmentShader: BUFFER_A_FRAG,
}); -
create a PlaneBufferGeometry and create a mesh from the geometry and buffermaterial
new THREE.Mesh(planeA, bufferA)
-
add it to the Scene
bufferAscene.add(new THREE.Mesh(planeA, bufferA));
In the render:
- update the uniforms
bufferA.uniforms.iChannel0.value = textureA
I dont really understand the swap though.
If anyone can help me to get the application to compile it would be very much apreciated!