可以做镜头景深效果的shard-1

  1. Shader "Hidden/Render DOF Factor" {  
  2. Properties {  
  3.  _MainTex ("Base", 2D) = "white" {}  
  4.  _Cutoff ("Cutoff"float) = 0.5  
  5. }  
  6. // Helper code used in all of the below subshaders    
  7. CGINCLUDE  
  8. struct v2f {  
  9.  float4 pos : POSITION;  
  10.  float depth : TEXCOORD0;  
  11. };  
  12. struct v2f_uv {  
  13.  float4 pos : POSITION;  
  14.  float2 uv : TEXCOORD0;  
  15.  float depth : TEXCOORD1;  
  16. };  
  17. uniform float4 _FocalParams;  
  18. half DOFFactor( float z ) {  
  19.  float focalDist = _FocalParams.x;  
  20.  float invRange = _FocalParams.w;  
  21.  float fromFocal = z - focalDist;  
  22.  if( fromFocal < 0.0 )  
  23.   fromFocal *= 4.0;  
  24.  return saturate( abs( fromFocal ) * invRange );  
  25. }  
  26. uniform sampler2D _MainTex;  
  27. uniform float _Cutoff;  
  28. half4 frag(v2f i) : COLOR {  
  29.  return DOFFactor(i.depth);  
  30. }  
  31. half4 frag_uv(v2f_uv i) : COLOR {  
  32.  half4 texcol = tex2D( _MainTex, i.uv );  
  33.  clip( texcol.a - _Cutoff );   
  34.  return DOFFactor(i.depth);  
  35. }  
  36. ENDCG  
  37. Category {  
  38.  Fog { Mode Off }  
  39.    
  40.  // regular opaque objects   
  41.  SubShader {  
  42.   Tags { "RenderType"="Opaque" }  
  43.   Pass {  
  44.     
  45. CGPROGRAM  
  46. #pragma vertex vert  
  47. #pragma fragment frag  
  48. #include "UnityCG.cginc"   
  49. v2f vert( appdata_base v ) {  
  50.  v2f o;  
  51.  o.pos = mul(glstate.matrix.mvp, v.vertex);  
  52.  COMPUTE_EYEDEPTH(o.depth);  
  53.  return o;  
  54. }  
  55. ENDCG  
  56.   }  
  57.  }   
  58.    
  59.  // transparent cutout objects   
  60.  SubShader {  
  61.   Tags { "RenderType"="TransparentCutout" }  
  62.   Pass {  
  63.    Cull Off  
  64.     
  65. CGPROGRAM  
  66. #pragma vertex vert  
  67. #pragma fragment frag_uv  
  68. #include "UnityCG.cginc"   
  69. v2f_uv vert( appdata_base v ) {  
  70.  v2f_uv o;  
  71.  o.pos = mul(glstate.matrix.mvp, v.vertex);  
  72.  o.uv = v.texcoord;  
  73.  COMPUTE_EYEDEPTH(o.depth);  
  74.  return o;  
  75. }  
  76. ENDCG  
  77.   }  
  78.  }   
  79.    
  80.  // terrain tree bark   
  81.  SubShader {  
  82.   Tags { "RenderType"="TreeOpaque" }  
  83.   Pass {  
  84.     
  85. CGPROGRAM  
  86. #pragma vertex vert  
  87. #pragma fragment frag  
  88. #include "UnityCG.cginc"  
  89. #include "TerrainEngine.cginc"   
  90. struct appdata {  
  91.     float4 vertex : POSITION;  
  92.     float4 color : COLOR;  
  93. };  
  94. v2f vert( appdata v ) {  
  95.  v2f o;  
  96.  TerrainAnimateTree(v.vertex, v.color.w);  
  97.  o.pos = mul( glstate.matrix.mvp, v.vertex );  
  98.  COMPUTE_EYEDEPTH(o.depth);  
  99.  return o;  
  100. }  
  101. ENDCG  
  102.   }  
  103.  }  
  104.    
  105.  // terrain tree leaves   
  106.  SubShader {  
  107.   Tags { "RenderType"="TreeTransparentCutout" }  
  108.   Pass {  
  109.    Cull Off  
  110.     
  111. CGPROGRAM  
  112. #pragma vertex vert  
  113. #pragma fragment frag_uv  
  114. #include "UnityCG.cginc"  
  115. #include "TerrainEngine.cginc"   
  116. struct appdata {  
  117.     float4 vertex : POSITION;  
  118.     float4 color : COLOR;  
  119.     float4 texcoord : TEXCOORD0;  
  120. };  
  121. v2f_uv vert( appdata v ) {  
  122.  v2f_uv o;  
  123.  TerrainAnimateTree(v.vertex, v.color.w);  
  124.  o.pos = mul( glstate.matrix.mvp, v.vertex );  
  125.  o.uv = v.texcoord;  
  126.  COMPUTE_EYEDEPTH(o.depth);  
  127.  return o;  
  128. }  
  129. ENDCG  
  130.   }  
  131.  }  
  132.    
  133.  // terrain tree billboards   
  134.  SubShader {  
  135.   Tags { "RenderType"="TreeBillboard" }  
  136.   Pass {  
  137.    Cull Off  
  138.     
  139. CGPROGRAM  
  140. #pragma vertex vert  
  141. #pragma fragment frag_tree  
  142. #include "UnityCG.cginc"  
  143. #include "TerrainEngine.cginc"   
  144. struct appdata {  
  145.     float4 vertex : POSITION;  
  146.     float4 color : COLOR;  
  147.     float4 texcoord : TEXCOORD0;  
  148. };  
  149. v2f_uv vert( appdata_tree_billboard v ) {  
  150.  v2f_uv o;  
  151.  TerrainBillboardTree(v.vertex, v.texcoord1.xy);  
  152.  o.pos = mul( glstate.matrix.mvp, v.vertex );  
  153.  o.uv = v.texcoord;  
  154.  COMPUTE_EYEDEPTH(o.depth);  
  155.  return o;  
  156. }  
  157. half4 frag_tree(v2f_uv i) : COLOR {  
  158.  half4 texcol = tex2D( _MainTex, i.uv );  
  159.  clip( texcol.a - 0.5 );  
  160.  return DOFFactor(i.depth);  
  161. }  
  162. ENDCG  
  163.   }  
  164.  }  
  165.    
  166.  // terrain grass billboards   
  167.  SubShader {  
  168.   Tags { "RenderType"="GrassBillboard" }  
  169.   Pass {  
  170.    Cull Off  
  171.     
  172. CGPROGRAM  
  173. #pragma vertex vert  
  174. #pragma fragment frag_uv  
  175. #pragma multi_compile NO_INTEL_GMA_X3100_WORKAROUND INTEL_GMA_X3100_WORKAROUND  
  176. #include "UnityCG.cginc"  
  177. #include "TerrainEngine.cginc"   
  178. v2f_uv vert (appdata_grass v) {  
  179.  v2f_uv o;  
  180.  TerrainBillboardGrass(v.vertex, v.texcoord1.xy);  
  181.  float waveAmount = v.texcoord1.y;  
  182.  float4 dummyColor = 0;  
  183.  TerrainWaveGrass (v.vertex, waveAmount, dummyColor, dummyColor);  
  184.  o.pos = mul (glstate.matrix.mvp, v.vertex);  
  185.  o.uv = v.texcoord;  
  186.  COMPUTE_EYEDEPTH(o.depth);  
  187.  return o;  
  188. }  
  189. ENDCG  
  190.   }  
  191.  }  
  192.    
  193.  // terrain grass non-billboards   
  194.  SubShader {  
  195.   Tags { "RenderType"="Grass" }  
  196.   Pass {  
  197.    Cull Off  
  198.     
  199. CGPROGRAM  
  200. #pragma vertex vert  
  201. #pragma fragment frag_uv  
  202. #pragma multi_compile NO_INTEL_GMA_X3100_WORKAROUND INTEL_GMA_X3100_WORKAROUND  
  203. #include "UnityCG.cginc"  
  204. #include "TerrainEngine.cginc"   
  205. v2f_uv vert (appdata_grass v) {  
  206.  v2f_uv o;  
  207.  float waveAmount = v.color.a * _WaveAndDistance.z;  
  208.  float4 dummyColor = 0;  
  209.  TerrainWaveGrass (v.vertex, waveAmount, dummyColor, dummyColor);  
  210.  o.pos = mul (glstate.matrix.mvp, v.vertex);  
  211.  o.uv = v.texcoord;  
  212.  COMPUTE_EYEDEPTH(o.depth);  
  213.  return o;  
  214. }  
  215. ENDCG  
  216.   }  
  217.  }  
  218.    
  219. }  
  220. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值