VignettingShader.shader 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/Vignetting" {
  3. Properties {
  4. _MainTex ("Base", 2D) = "white" {}
  5. _VignetteTex ("Vignette", 2D) = "white" {}
  6. }
  7. CGINCLUDE
  8. #include "UnityCG.cginc"
  9. struct v2f {
  10. float4 pos : SV_POSITION;
  11. float2 uv : TEXCOORD0;
  12. float2 uv2 : TEXCOORD1;
  13. };
  14. sampler2D _MainTex;
  15. sampler2D _VignetteTex;
  16. half _Intensity;
  17. half _Blur;
  18. float4 _MainTex_TexelSize;
  19. v2f vert( appdata_img v ) {
  20. v2f o;
  21. o.pos = UnityObjectToClipPos(v.vertex);
  22. o.uv = v.texcoord.xy;
  23. o.uv2 = v.texcoord.xy;
  24. #if UNITY_UV_STARTS_AT_TOP
  25. if (_MainTex_TexelSize.y < 0)
  26. o.uv2.y = 1.0 - o.uv2.y;
  27. #endif
  28. return o;
  29. }
  30. half4 frag(v2f i) : SV_Target {
  31. half2 coords = i.uv;
  32. half2 uv = i.uv;
  33. coords = (coords - 0.5) * 2.0;
  34. half coordDot = dot (coords,coords);
  35. half4 color = tex2D (_MainTex, uv);
  36. float mask = 1.0 - coordDot * _Intensity * 0.1;
  37. half4 colorBlur = tex2D (_VignetteTex, i.uv2);
  38. color = lerp (color, colorBlur, saturate (_Blur * coordDot));
  39. return color * mask;
  40. }
  41. ENDCG
  42. Subshader {
  43. Pass {
  44. ZTest Always Cull Off ZWrite Off
  45. CGPROGRAM
  46. #pragma vertex vert
  47. #pragma fragment frag
  48. ENDCG
  49. }
  50. }
  51. Fallback off
  52. }