由于博主常年逃课,所以期末考试期间只能突击,但偶尔还能拿个奖学金啥的,哈哈,所以近一个月没有做游戏,也没有发博客= =。。。

这个景深的方法很简单

我们需要求的是CoC(circle of confusion)模糊圈

CoC与R相关 主要原理如下图所示

alpha是透镜的半径 zf为焦点,z为物距

要求R知道一些高中的三角公式就可以了

Unity3d shader之SWAP Force Depth-of-Field Shader-LMLPHP

再根据CoC决定模糊程度 需要的变量为zf焦点-决定模糊的深度位置,alpha透镜的半径-决定模糊的域的范围,direction-模糊方向

需要注意的是因为循环的次数是变量所以需要用到texel fetch方法,在unity中是tex2Dlod

Unity3d shader之SWAP Force Depth-of-Field Shader-LMLPHP

博主又弄了一下sparkle版的,改动下模糊方式即可,这个可以自由发挥

60fps完美运行

Unity3d shader之SWAP Force Depth-of-Field Shader-LMLPHP

普通模糊:

Unity3d shader之SWAP Force Depth-of-Field Shader-LMLPHP

Unity3d shader之SWAP Force Depth-of-Field Shader-LMLPHPUnity3d shader之SWAP Force Depth-of-Field Shader-LMLPHP

sparkle:

Unity3d shader之SWAP Force Depth-of-Field Shader-LMLPHPUnity3d shader之SWAP Force Depth-of-Field Shader-LMLPHPUnity3d shader之SWAP Force Depth-of-Field Shader-LMLPHPUnity3d shader之SWAP Force Depth-of-Field Shader-LMLPHPUnity3d shader之SWAP Force Depth-of-Field Shader-LMLPHP

博主近期渲染:最近用unity5弄的一些渲染

---- by wolf96(主博客)  http://blog.csdn.net/wolf96

04-20 16:38