Many objects like grass meshes, rocks and so on start flickering/jittering on a distance during a camera movement. The only thing that solves this problem is hardware antialiasing like msaa or ssaa. But due to perfomance reasons i want to use this kind of aa for the grass layer only. I’m using separate camera that renders the grass layer to a separate Render target.
const renderTargetGrass = new THREE.WebGLRenderTarget(...biggestSize, {
depthBuffer: true,
format: THREE.RGBAFormat,
type: THREE.UnsignedByteType,
samples: 0, // doesnt matter in this case because i use ssaa for this test. msaa result is the same
});
So i wanted to get this render target texture and just mix it with other scene layers. But as i understood antialiasing makes the edges of the meshes smooth blending it with current background respecting the colors at render moment only. So putting antialiased texture to any other background removes antialiasing from the image. For example in my custom shader pass i do this:
vec4 grassTex = texture2D(tDiffuse, vUv);
gl_FragColor = mix(vec4(1.0), grassTex, grassTex.a);
Mixing the grass texture with a white background shows the same flickering while changing mix color to black vec4(0.0) shows antialised (almost) image.
Maybe anyone has any wise ideas how to combine smooth edged grass with any custom background for the best perfomance?