- Home /
Rendering different shader when camera get near object
Hello,
My goal is to create the same effect that I have in this video
When the camera get near the material change and become colored and transparent.
So, I already have this effect in a shader someone helped me to make in ShaderForge.
Problem is, I don't know how I should process to apply this effect to my whole scene, and not to every material one by one, this would be way too complicated because I would have to get all the information of the old shader, then mix those information with the new shader.
In my mind I should probably try to do some kind of post process to apply this effect to the whole scene, but I don't know how to do it.
Is there any other way to do this than writing a post process? Am I on the right track or should I think of another way to do it?
Thanks for taking the time to read me,
Cheers
Answer by hrgchris · Feb 24, 2017 at 11:56 AM
Hi There
There are various approaches to this issue, though there won't be a trivial post-processing effect you can apply just to one camera. This is because a post-process can only modify pixels that have been rendered, so you couldn't take solid pixels then realise you actually wanted them transparent!
If your goal is to find a solution that doesn't require modifying lots of materials (a perfectly valid desire!) then I would:
render all objects that you don't want the clipping effect on as normal
render objects that you do want the clipping effect on into a render texture (that includes depth)
now in a post process you can combine these 2 separate renders into 1, using the depth values to calculate how transparent the clipped versions should be
This would require you to work out which objects you wanted rendered into which textures, though you might be able to do this with a trick as simple as having 2 cameras with different front/back view planes. i.e:
normal camera has view planes 1m->1000m
clipped object camera has view planes 0.1m->1m
If that works it'll be nice, as unity will do the job of separating out clipped from none-clipped objects for you.
Hope that gets you in the right direction. I would start by just seeing if you can use the above technique with cameras to separate normal from clipped, then see if you can make a post processing effect that makes any clipped object semi transparent. Once you have that working, you can start looking at nicer effects that go more transparent/change colour when they get close to the camera.
-Chris