I’m trying to combine multiple composers, and haven’t been successful.
In particular, I’m trying to create two separate composers with their own shaders, and to create another composer which combines the results of those shaders.
The user’s webcam is the only object in the scene.
For a dummy example, I’ve created a ‘greenComposer’ and ‘blueComposer’, each of which creates a ShaderPass with the ColorifyShader, colorifying the canvas green or blue - these two composers are initialized with WebGLRenderTargets as target parameters.
The final composer is a blend composer, whose uniform diffuse arrays are set as the textures of the targets sent to the other composers.
Running example is here:
Unfortunately, this seems to output simply the renderpass of the final composer.
I’ve set the autoClear parameter of the renderer to false, but I’m not sure what I’ve been missing. Any help would greatly be appreciated.
Have you tried passing the readbuffer of the composers you want to combine to the textures of the blendShader?
That what worked for me (Although I haven’t used the BlendShader, but a custom one).
It’s part of a bigger engine, but you can see how I do for Polygonjs here:
Thanks for the tip, and the example.
Unfortunately, no luck…
Looks like the EffectComposer constructor sets the readbuffer to be the passed-in rendertarget, so they should be the same thing, no?
They should be the same thing, but I had different results when I was passing it. It could be because you may have more controls on how you set it up that way.
Could you make a jsfiddle? It would be easier to try things.
I think I have it working:
I changed the following:
- you had a typo
rendertoScreen instead of
renderToScreen (I always recommend using typescript to avoid those, took me a while to notice it)
- I give the readBuffers to the shader textures, even though I admit not being sure why this is necessary.
- I replaced the fragment shader of the blendShader with a custom one. Not very different, but made debugging easier.
Hope that helps!
Yep - got it working!
After fixing the typo, I still needed to change to the shader textures. I agree, it’s unclear why, but hey, if it works, it works
Thanks so much for your help.