Hello!
When I discard pixels in the fragment shader it sees through correctly but SAO effect sees no transparency and adds no darkness. Any solution to this?
Kind regards
Tomas
Hello!
When I discard pixels in the fragment shader it sees through correctly but SAO effect sees no transparency and adds no darkness. Any solution to this?
Kind regards
Tomas
I think the SSAO pass uses its own material to do the depth prepass, which doesn’t have your discard logic in it. Not sure how to work around this without modifying the Effects shader.
I have a very vague recollection of a MaskPass
in the EffectComposer
. It uses stencil buffers under the hood. I have never tried this mask pass, so I’m absolutely unsure whether it is useful for your case. Just mentioning it as a potential option.
Thanks for the clue, I have hardly studied postprocessing source code at all or understand behind the scenes, not sure if you can answer, but why isnt sao using afterwards same depthbuffer as the normal rendering?
Possibly because “normal” rendering doesn’t have any guarantees about the state of the depth buffer after rendering… for instance, the transparent object pass may write to the depth buffer, which may not matter visually since transparent objects are depth sorted, but might leave the depth buffer in a state unusable for ssao. This is just one example I can think of off the top of my head.
Might be one of those cases where the answer is “because literally everything about 3d rendering that isn’t raytracing, is a complete hack”.
Full disclosure, I’m just speculating about all this, but… it is plausible to me. Another possible reason is that post processing passes need to be self contained, since they may be arranged in any order, so additionally there is not guarantee that any of the other effects in the stack are going to leave the depth buffer intact.
Ok I see, I really wanted to use the nice sao effect for the discarded pixels and have to investigate further, I guess there is some extra cost if you need to execute the fragment shader multiple times also. I have wondering sometimes how all buffers are treated in passes and if it shared stuff.
Ok thanks, not sure, I think I have to dig into the SAOPass to understand it better and maybe modify it instead
One other thing to check out if you haven’t already:
https://threejs.org/docs/#api/en/core/Object3D.customDepthMaterial