Can I customize a material to look different when it is behind another object?

Hello folks,

I have an object and started to apply a physical material in the editor. What I want is that the material should look different (maybe only outlines visible or some kind of transparency) whenever it is occluded by another object. Is there a way to achieve this in a single material, maybe with shader chunks? Or will I always need to copy my mesh and add another material to it? Thanks in advance.

Hello,

I think this example showing the object outlines is what you are after? Not sure about your question on copying a mesh.

2 Likes

@Wibke and here is that engine example adapted for use in editor:

https://playcanvas.com/project/682988/overview/model-outline

2 Likes

Thank you both. Exactly what I needed. I thought for outlines you should need to use the same mesh and make it bigger/smaller and render it twice but this is way better. I still need some time to get the full potential of the layer system and the post effects.

2 Likes

Well, that’s how outlines shader works behind the scenes. It just renders the mesh a second time, bigger than the first one, then removes pixels that are drawn over the original one, leaving only the ones that are outside. This gives an effect of an outline.

1 Like

@yaustar thinking this may be quite useful to have in the Tutorials/Examples section.

Ah, now I see. I was more thinking of that you need to have the actual mesh twice in big and small to receive only the outlines.

Yes, do you mind if I duplicate the project and tweak it a bit?

Not at all, feel free!

1 Like

Based this example, I wrote smoothed outline for mobiles. Not so accurate, but very fast.


1 Like

Nice! Thanks for sharing. Do you have a build url to take a glimpse?

https://playcanvas.com/editor/project/690556
Outline, caustic, hologram

1 Like

That’s look great, nice job @KpoKec!

heightmap_anim on BG used for pseudo water effect, based on caustic algorithm.
I used it for water animation simulation on texture over animated model.
Caustic over sphere may looks like ocean or like water (or whatever) globe.

2 Likes