NoiseEffectShaderRGB.shader 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Hidden/Noise Shader RGB" {
  3. Properties {
  4. _MainTex ("Base (RGB)", 2D) = "white" {}
  5. _GrainTex ("Base (RGB)", 2D) = "gray" {}
  6. _ScratchTex ("Base (RGB)", 2D) = "gray" {}
  7. }
  8. SubShader {
  9. Pass {
  10. ZTest Always Cull Off ZWrite Off Fog { Mode off }
  11. CGPROGRAM
  12. #pragma vertex vert
  13. #pragma fragment frag
  14. #pragma fragmentoption ARB_precision_hint_fastest
  15. #include "UnityCG.cginc"
  16. struct v2f {
  17. float4 pos : POSITION;
  18. float2 uv : TEXCOORD0;
  19. float2 uvg : TEXCOORD1; // grain
  20. float2 uvs : TEXCOORD2; // scratch
  21. };
  22. uniform sampler2D _MainTex;
  23. uniform sampler2D _GrainTex;
  24. uniform sampler2D _ScratchTex;
  25. uniform float4 _GrainOffsetScale;
  26. uniform float4 _ScratchOffsetScale;
  27. uniform fixed4 _Intensity; // x=grain, y=scratch
  28. v2f vert (appdata_img v)
  29. {
  30. v2f o;
  31. o.pos = UnityObjectToClipPos (v.vertex);
  32. o.uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord);
  33. o.uvg = v.texcoord.xy * _GrainOffsetScale.zw + _GrainOffsetScale.xy;
  34. o.uvs = v.texcoord.xy * _ScratchOffsetScale.zw + _ScratchOffsetScale.xy;
  35. return o;
  36. }
  37. fixed4 frag (v2f i) : COLOR
  38. {
  39. fixed4 col = tex2D(_MainTex, i.uv);
  40. // sample noise texture and do a signed add
  41. fixed3 grain = tex2D(_GrainTex, i.uvg).rgb * 2 - 1;
  42. col.rgb += grain * _Intensity.x;
  43. // sample scratch texture and do a signed add
  44. fixed3 scratch = tex2D(_ScratchTex, i.uvs).rgb * 2 - 1;
  45. col.rgb += scratch * _Intensity.y;
  46. return col;
  47. }
  48. ENDCG
  49. }
  50. }
  51. Fallback off
  52. }