Hi, I hope someone can spot what stupid mistake I’m making here…
Part of a bigger feature, I need to render the main scene at a specific point and apply some effects to it, but I’m getting weird results. I stripped it down to basically a copy shader, but I can’t seem to be able to get the same output as when I just normally render the scene using App.renderer.render(App.scene, App.camera);
.
Here is the stripped down setup:
const uniforms = {
uBgTexture: { value: null }
};
/**
* App.renderer.render(...) is not called in this case, RenderPass renders the scene,
* then it gets passed to the CustomPass, which is forced to render to screen.
*/
const composer = new EffectComposer(App.renderer);
composer.renderToScreen = false;
composer.addPass(new RenderPass(App.scene, App.camera)); // renders to buffer
composer.addPass(new CustomPass(uniforms)); // renders to screen
and in CustomPass
:
export class CustomPass extends Pass {
protected material: ShaderMaterial;
protected fsQuad: FullScreenQuad;
constructor(uniforms: { [uniform: string]: IUniform }) {
super();
this.material = new ShaderMaterial({
uniforms,
vertexShader,
fragmentShader
});
this.fsQuad = new FullScreenQuad(this.material);
}
render(renderer: WebGLRenderer, writeBuffer: WebGLRenderTarget, readBuffer: WebGLRenderTarget) {
this.material.uniforms.uBgTexture.value = readBuffer.texture;
renderer.setRenderTarget(null);
renderer.clear(); // makes no difference
this.fsQuad.render(renderer);
}
dispose() {
this.material.dispose();
this.fsQuad.dispose();
}
}
in the fragment shader I simply copy the whole scene:
void main()
{
vec4 bg = texture(uBgTexture, vUv);
gl_FragColor = bg;
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
This is what it should look like (using App.renderer.render(...)
):
This is what I get with the EffectComposer setup (more opaque, and maybe saturated):
And finally, if I comment out either the colorspace_fragment
or both includes in the shader, I get this:
Adding an OutputPass
to the end doesn’t change anything.
I’m pretty sure I’m missing something trivial