DoF with transparent shaders in Unity 5
Heya,
so I know this question has been asked heaps, and I tried every single shader tweaks to make it work, but the fact is UNITY 5 CANNOT HANDLE DOF WITH TRANSPARENT CUSTOM SHADERS. This is as simple as that.
So now, workarounds... Anyone has a good idea on how the following could be achieved? I have a 3D model of a planet that is the center of "the world". The main (and only) camera is revolving around this object. I want the planet to be blurred if an object is between the camera and the planet, but only while the object is within a certain range. So I just described DOF, I know, but since it is not working (my planet has a transparent object around it to simulate the atmosphere) I need to find a workaround. My idea so far is to render the planet and the skybox using one camera (A), other objects with another camera (B), and blur camera A if oject is within the defined range. Old PS2 style DOF.
Thing is I have no clue how to implement this. I don't know how to overlay camera - but I do know how to assign objects to layers. Can please someone point me towards something that would be helpful to solve this problem?
Thanks so much.
Aurelien
Answer by aur8l · Feb 27, 2017 at 01:06 AM
Solved it. If anyone is interested in the solution, shout out.
Answer by KensonTsang · Feb 27, 2017 at 10:43 AM
YES!!!! I'm facing this problem too!!
Hey @$$anonymous$$ensonTsang,
Pretty easy actually. You need 2 cameras. One will render everything except the objects in the foreground and the other nothing but the objects in the foreground. Of course, this has to be adapted to your situation but: camera that renders the foreground will need to have a child (I used a cube mesh with no mesh renderer - just to get the collider which is a trigger) that will serve as the DoF detection zone. On this is a script attached that call a function in the root object (see below) to blur the background camera, using OnTrigger events.
All my camera are themselves children of a master object, that will control the blur of the camera rendering the background.
Voila. Let me know if you want even more details. It is not ideal of course as I need to have this dummy cube being a Rigidbody for nothing (except throwing the OnTrigger events).
edit: forgot to mention that if an object enters the detection zone it should change layers to be rendered by the foreground camera, and vice-versa.
Your answer
Follow this Question
Related Questions
URP Camera.RenderWithShader(..) doesn't seem to work? 0 Answers
Rendering viewmodel over everything WITHOUT dual camera 1 Answer
Stop Post-Processing Effects on UI? 3 Answers
Why does everything render in the scene editor, but not after I build it? 0 Answers
How to hide and show level based on player/camera position? 0 Answers