- Home /
Depth of Field with Shader Replacement?
I am using Unity 4 free version. I saw this "shader replacement" in the Unity Asset store. I was wondering if I could use this shader replacement to make Depth of Field.
http://u3d.as/content/unity-technologies/shader-replacement/3zx
Here is what the description says:
Depth of Field A simple Depth-of-Field implementation. Shader replacement used to render blurriness factor of the scene.
Is there any way I can use these shaders for Depth of Field?
Thanks in advance! :D
AFAI$$anonymous$$ you need Pro to use "RenderWithShader"
Answer by CaptainScience · Oct 27, 2013 at 10:46 AM
This question is a bit old, but I will answer it anyway in case anyone else is wondering.
The answer is actually, yes, you can use this with Unity Free to create a "depth of field" effect. I've done it, but you can not do it as efficiently as you can with Unity Pro. In Unity Free, you do not have off-screen rendering (i.e. Render Textures), but you can replace them by simply rendering to the screen, ReadPixels() the framebuffer into a texture, and then clear the screen before rendering your final scene. The problem is that it requires a trip to the GPU to render the low res scene, back to the CPU when you read the pixels, and then BACK to the GPU when you Texture.Apply() the changes. This is for each pass BEFORE you even start rendering your final scene.
This makes it infeasible to do many full screen passes. Depending on your hardware you might get one or two with a reasonable frame rate, but that will be eating up a lot of your rendering budget. If you stick to, for example, 1/4 of the width and height of the screen, you can get four passes while only reading back a quarter of the screen. This may give you enough performance and render passes to create blur effects such as DOF (render one pass as depth with a replacement shader). There will be artifacts or ghosting created by using a lower resolution texture when applying a full-screen effect, but how severe they are will depend on your specific scene and the hardware you are targeting.
This technique would be most useful for things like refractions or reflections--create a very small texture and blur it. Even a very low quality refraction effect is better than none at all especially if it is highly distorted by a normal map. High quality full-screen effects (like tone-mapping or anti-aliasing) could be possible with sufficient hardware, but it may not be worth the opportunity cost of all the other geometry, effects, etc. you could be rendering instead.
I hope that makes sense, but the summary is: it is possible but very expensive.