How to hide/dissolve the level depending on if player is hidden or not

Hey there,

Got a question that could’ve been in shaders, but i’m not totally sure what the best solution here would be.

I have a levels i create in a custom editor, in a sort of fixed perspective, and i need to hide dissolve/slightly hide, maybe just make temporarily transparent, depending on if my asset is hidden.

I was considering making a Shader that dissolves the world geometry based on some specific distance the entity is from the camera, but, the issue i keep coming to here is that, i want this to be a shader that can “clip” the information, or alter the pixels, of a material that shades before this does.

The idea was to make a material that renders after the main material, and then it handles this…

I haven’t made a global shader like this, ever, so i wonder, what would be the best approach here? Would making a screen shader make more sense? If it would, how would i specifically target the entities i’m talking about with this particular shader? What are the methods in achieving this sort of effect, is there something easier i can do with some new Unity feature i’m not aware of?

I heard of replacement shaders, but to my knowledge, it seems to have to replace the shader of all of my assets that are being rendered, which doesn’t make sense, cause all my assets have custom materials that do their own things.

I feel at a lost, i’ve been googling for weeks now and i can’t find a solution to this that feels elegant.

My ideal situation is to be able to just have a replacement shader i can put on the camera, that targets specific assets, without me having to change the materials of the objects i’m talking about, and works over-top the materials they have.

That or if i can define a “global” shader that gets applied to everything after they’ve already rendered, that let’s me edit the resulting information of their frag / vert shaders.

Any ideas?

  • PROGRESS *

I’m currently looking through this tutorial:

https://connect.unity.com/p/articles-dissolving-the-world-part-2

I’ve implemented a shader noise library, and currently am trying to do that solution where

I have 2 cameras, one renders my objects, and based on the depth of these, it clips the object using the perlin noise variables.

However, when i call “Clip” in an image effect shader, it becomes black… I don’t understand, it is set to depth only, and it should be rendering after the first, i actually confirmed that’s exactly what happens, but when my 2nd camera renders out no pixels , it blocks the previous camera.

What am i doing wrong? Why doesn’t the CLIP function work properly and just not render pixels, therefore, not blocking the image underneath?

I’m still trying to understand exactly what you’re trying to do, but…

If I understand this comment correctly you’re looking to have an object render normally, then have another material that renders afterward that hides the previously rendered object to show what was there before that object was rendered.

Fundamentally, this is not possible. Once an object has been rendered, what was there before has been lost. Objects that render afterward can only draw over what was rendered before. I like to use an analogy of putting cheap paper stickers with really good glue onto a piece of paper.

Imagine each object you render is a sticker. Once it’s been placed it cannot be moved or modified, it’s just there. Before it’s placed you can cut it however you want, and you can put new stickers on top, but you can’t remove a sticker to reveal the paper, or a previous sticker without destroying the entire page.

Really, for this to work correctly and efficiently, the base material must be using a custom shader that does the clipping. You cannot separate the clipping shader and the base object’s shader into separate passes.

OK makes sense.

Then i’ll just zoom back to what i was trying to do as an alternative:

Correct me if my logic is wrong here but:

  1. If i have 2 cameras, one made for rendering all non-clippable objects, and one for the ones i want to apply clipping to
  2. I run an image effect shader on the clip camera, that does the algorithm that clips the pixel data based on information i get from the depth buffer of the camera, so i can cut out these models effectively, from the cameras perspective.
  3. I make it so that the clip camera, renders on top of the non-clip camera.

The issue is, the result you see above. Why is it that clipping, or simply setting the rendered image to be transparent from the clip-camera image effect, give me black where it should be showing the non-clip cameras render?

This makes no sense to me, but maybe i am missing something here.