Hey,
To preface this I’m pretty new into the shaders and general GPU side of development so not very versed in technicalities of this stuff.
I’ve been looking to create a system that pixelates only certain objects within a scene. I’ve tried various ways of doing this but landed on having two cameras, one that renders pixelated objects via a layer/Culling Mask, and another camera that renders everything else. The pixelated camera runs a pixelating Compute Shader in its OnRenderImage function then sets this RenderTexture to the secondary texture of another shader which, Blit’d with the normal cameras Render Texture, renders the two cameras together.
On a simple scene with no changing variables this gives the exact visual effect I’m looking for, however what might be evident already is that since the pixelated objects and everything else are under different lables, there is absolutely no clipping or culling happening between the two. I’ve tried various things including trying to use _CameraDepthTexture aswell as going down a rabbit hole of manually rendering seperate depth textures for each of my cameras so that I can perform some kind of manual clipping from within the shader but none of these have come to a satisfying conclusion.
There’s got to be something simple I’m missing here as there seems to be very little resources of people attempting similar techniques but as I see it at the moment I can either pixelate the whole screen with correct clipping or pixelate the objects I want with incorrect clipping.
Image 1: These are my two Camera scripts
Image 2: The shader that handles combining the two views aswell as the simple compute shader for pixelizing the entire screen.
Image 3: The lack of clipping shown in unity
Image 4: Another example
Again I’m sure theres something simple I’m missing here but all the resources I’ve looked at to try and fix this either don’t achieve the same effect that I’m looking for or are so convoluted to the point it seems I’ve searched the wrong term (URP stack cameras and seperate shaders for each camera was a mess). If theres any way for example I can write depth to the alpha channel of my RenderTexture or something similar that I can work with from within the shader that would be perfect but I’m unsure.
Image hosts incase embed doesnt work:
Image 1: Screenshot by Lightshot
Image 2: Screenshot by Lightshot
Image 3: Screenshot by Lightshot
Image 4: Screenshot by Lightshot
Thanks,
-Jake





