When I mix the two off screen renderers with this shader, result has unusual mix and opacity. I am using the two render passes to create different pixelations for the board and the pieces.
setup:
//Shader pass board
this.pixelationPassBoard = new ShaderPass(PixelationShader(1));
this.pixelationPassBoard.uniforms.pixelSize.value = 1;
this.composerPixelateBoard = new EffectComposer(this.renderer);
this.composerPixelateBoard.addPass(this.renderScene);
this.composerPixelateBoard.addPass(this.pixelationPassBoard);
this.composerPixelateBoard.renderToScreen = false;
//Shader pass pieces
this.pixelationPassPieces = new ShaderPass(PixelationShader(3));
this.pixelationPassPieces.uniforms.pixelSize.value = 3;
this.composerPixelatePieces = new EffectComposer(this.renderer);
this.composerPixelatePieces.addPass(this.renderScene);
this.composerPixelatePieces.addPass(this.pixelationPassPieces);
this.composerPixelatePieces.renderToScreen = false;
//mix the two pixelation shaders
//...there must be a better way to do this :<
mixPass = new ShaderPass(
new ShaderMaterial( {
uniforms: {
pieceTexture: { value: this.composerPixelatePieces.renderTarget2.texture },
boardTexture: { value: this.composerPixelateBoard.renderTarget2.texture }
},
vertexShader: MixShader.vertexShader,
fragmentShader: MixShader.fragmentShader,
defines: {}
} )
);
this.composerFinal.addPass( mixPass ); //mix the two pixelation shaders
const outputPass = new OutputPass(); //threejs coloring from OutputPass
this.composerFinal.addPass( outputPass );
mix shader:
export const MixShader = {
vertexShader:`
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
`,
fragmentShader:`
uniform sampler2D boardTexture;
uniform sampler2D pieceTexture;
varying vec2 vUv;
void main() {
vec4 boardColor = texture2D( boardTexture, vUv );
vec4 pieceColor = texture2D( pieceTexture, vUv );
gl_FragColor = (boardColor + pieceColor) * 0.5;
}
`
};
render:
this.setMaterialVisibilityInLayer(false,0); //turn all off
this.setMaterialVisibilityInLayer(true,2); //turn on board
this.composerPixelateBoard.render(); //render1
this.setMaterialVisibilityInLayer(false,2); //turn off board
this.setMaterialVisibilityInLayer(true,1); //turn on pieces
this.composerPixelatePieces.render(); //render2
this.composerFinal.render(); //render