Advertisement
Guest User

Untitled

a guest
May 25th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. Shader "Unlit/ColorVignette"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. }
  7. SubShader
  8. {
  9. Tags { "RenderType"="Opaque" }
  10. Cull Front
  11. ZTest Always
  12. ZWrite Off
  13. GrabPass{ "_GrabAss" }
  14.  
  15. Pass
  16. {
  17. CGPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. // make fog work
  21. #pragma multi_compile_fog
  22.  
  23. #include "UnityCG.cginc"
  24.  
  25. struct appdata
  26. {
  27. float4 vertex : POSITION;
  28. float4 uv : TEXCOORD0;
  29. float4 vertexColor : COLOR;
  30. };
  31.  
  32. struct v2f
  33. {
  34. float4 uv : TEXCOORD0;
  35. float4 vertex : SV_POSITION;
  36. float4 screenCoord : TEXCOORD1;
  37. float4 vertexColor : COLOR;
  38. };
  39.  
  40. v2f vert (appdata v)
  41. {
  42. v2f o;
  43. o.vertex = UnityObjectToClipPos(v.vertex);
  44. o.screenCoord = ComputeGrabScreenPos(o.vertex);
  45. o.vertexColor = v.vertexColor;
  46. o.uv = v.uv;
  47.  
  48. return o;
  49. }
  50.  
  51. sampler2D _GrabAss;
  52.  
  53. fixed4 frag (v2f i) : SV_Target
  54. {
  55.  
  56. {
  57.  
  58. float OuterVig = 1.0; // Position for the Outer vignette
  59.  
  60. float InnerVig = 0.05; // Position for the inner Vignette Ring
  61.  
  62. float2 uv = i.screenCoord.xy / i.screenCoord.w;
  63.  
  64.  
  65.  
  66. float4 color = tex2D(_GrabAss, uv);
  67.  
  68. float2 center = float2(0.5,.5); // Center of Screen
  69.  
  70. float dist = distance(center,uv )*1.414213; // Distance between center and the current Uv. Multiplyed by 1.414213 to fit in the range of 0.0 to 1.0
  71.  
  72. float vig = clamp((OuterVig-dist) / (OuterVig-InnerVig),0.0,1.0); // Generate the Vignette with Clamp which go from outer Viggnet ring to inner vignette ring with smooth steps
  73.  
  74. color *= vig; // Multiply the Vignette with the texture color
  75.  
  76. return color;
  77. }
  78.  
  79.  
  80. }
  81. ENDCG
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement