Hello, I’m struggling to find a way to do multipass shader - so that I can have multiple persistent samplers which I can play around with on a final pass (and do generative feedback loops). At the moment I have no idea how to configure this with RenderTargetTexture
objects, and have tried a lot of things.
My shader is setup like this, which demonstrates the end result I’m aiming for:
#version 300 es
precision highp float;
in vec2 vUV;
in vec2 vNormal;
out vec4 outColor;
uniform mat4 worldViewProjection;
uniform int PASSINDEX;
uniform sampler2D pass0;
uniform sampler2D pass1;
uniform sampler2D pass2;
uniform sampler2D pass3;
void main() {
vec2 xy = vec2(vUV);
vec4 c0 = texture( pass0, vUV );
vec4 c1 = texture( pass1, vUV );
vec4 c2 = texture( pass2, vUV );
vec4 c3 = texture( pass3, vUV );
vec4 red = vec4(1.0,0.0,0.0,1.0);
vec4 blue = vec4(0.0,0.0,1.0,1.0);
vec4 green = vec4(0.0,1.0,0.0,1.0);
vec4 white = vec4(1.0,1.0,1.0,1.0);
if (PASSINDEX == 0) {
outColor = white;
} else if (PASSINDEX == 1) {
outColor = mix( blue, c0, 0.0);
} else if (PASSINDEX == 2) {
outColor = mix( green, c1, 0.0);
} else if (PASSINDEX == 3) {
// outColor = mix( red, c2, 0.0 );
// outColor = c0; // white?
outColor = c1; // blue?
// outColor = c2; // green?
// outColor = c3; // red?
}
}
In Babylon I’m attempting various things like this:
let PASSINDEX = 0
const passes = [
new BABYLON.RenderTargetTexture('pass0', $_DIMENSIONS, scene),
new BABYLON.RenderTargetTexture('pass1', $_DIMENSIONS, scene),
new BABYLON.RenderTargetTexture('pass2', $_DIMENSIONS, scene),
new BABYLON.RenderTargetTexture('pass3', $_DIMENSIONS, scene)
]
for ( let idx = 0; idx < passes.length; idx++ ) {
object.material.setTexture( 'pass'+idx, passes[idx] )
}
engine.runRenderLoop( () => {
checkIfCompiled( shaderMaterial )
/* ------------- SHADER ------------- */
object.material.setVector2('RENDERSIZE', new BABYLON.Vector2($_DIMENSIONS.width, $_DIMENSIONS.height))
for (let i = 0; i < passes.length; i++) {
PASSINDEX = i;
object.material.setInt('PASSINDEX', i)
passes[i].renderList = [ object ]
scene.customRenderTargets = [ passes[i] ]
scene.render()
}
})
Though I have no idea how to do this properly. I’ve been able to get some strange visual feedback loops goingbut it’s not the result I was hoping for, and very laggy.