Bokeh34.shader 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Shader "Hidden/Dof/Bokeh34" {
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. _Source ("Base (RGB)", 2D) = "black" {}
  5. }
  6. SubShader {
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. sampler2D _MainTex;
  10. sampler2D _Source;
  11. uniform half4 _ArScale;
  12. uniform half _Intensity;
  13. uniform half4 _Source_TexelSize;
  14. struct v2f {
  15. half4 pos : SV_POSITION;
  16. half2 uv2 : TEXCOORD0;
  17. half4 source : TEXCOORD1;
  18. };
  19. #define COC bokeh.a
  20. v2f vert (appdata_full v)
  21. {
  22. v2f o;
  23. o.pos = v.vertex;
  24. o.uv2.xy = v.texcoord.xy;// * 2.0; <- needed when using Triangles.js and not Quads.js
  25. #if UNITY_UV_STARTS_AT_TOP
  26. float4 bokeh = tex2Dlod (_Source, half4 (v.texcoord1.xy * half2(1,-1) + half2(0,1), 0, 0));
  27. #else
  28. float4 bokeh = tex2Dlod (_Source, half4 (v.texcoord1.xy, 0, 0));
  29. #endif
  30. o.source = bokeh;
  31. o.pos.xy += (v.texcoord.xy * 2.0 - 1.0) * _ArScale.xy * COC;// + _ArScale.zw * coc;
  32. o.source.rgb *= _Intensity;
  33. return o;
  34. }
  35. half4 frag (v2f i) : SV_Target
  36. {
  37. half4 color = tex2D (_MainTex, i.uv2.xy);
  38. color.rgb *= i.source.rgb;
  39. color.a *= Luminance(i.source.rgb*0.25);
  40. return color;
  41. }
  42. ENDCG
  43. Pass {
  44. Blend OneMinusDstColor One
  45. ZTest Always Cull Off ZWrite Off
  46. CGPROGRAM
  47. #pragma target 3.0
  48. #pragma vertex vert
  49. #pragma fragment frag
  50. ENDCG
  51. }
  52. }
  53. Fallback off
  54. }