Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Shaders / GrayscaleImageEffectShader.shader
  1. Shader "MyShaders/Image Effects/My Grayscale Image Effect"{
  2. Properties{
  3. _MainTex("Texture", 2D) = "white"{}
  4. _NoiseTex("Noise Texture", 2D) = "white"{}
  5. _Intensity("Intensity",Range(0,1)) = 0
  6. }
  7. SubShader{
  8. Cull Off
  9. ZWrite Off
  10. ZTest Always
  11. Pass{
  12. HLSLPROGRAM
  13. #pragma vertex MyVertexProgram
  14. #pragma fragment MyFragmentProgram
  15. #include "UnityCG.cginc"
  16. struct VertexData {
  17. float4 position : POSITION;
  18. float2 uv : TEXCOORD0;
  19. };
  20. struct VertexToFragment {
  21. float4 position : SV_POSITION;
  22. float2 uv : TEXCOORD0;
  23. };
  24. sampler2D _MainTex;
  25. float4 _MainTex_ST;
  26. float _Intensity;
  27. VertexToFragment MyVertexProgram(VertexData vertex)
  28. {
  29. VertexToFragment v2f;
  30. v2f.position = UnityObjectToClipPos(vertex.position);
  31. v2f.uv = vertex.uv * _MainTex_ST.xy + _MainTex_ST.zw;
  32. return v2f;
  33. }
  34. float4 MyFragmentProgram(VertexToFragment v2f) : SV_TARGET
  35. {
  36. float4 color = tex2D(_MainTex, v2f.uv);
  37. float avgColor = (color.r + color.g + color.b) / 3;
  38. float4 c = lerp(color, avgColor, _Intensity);
  39. return c;
  40. }
  41. ENDHLSL
  42. }
  43. }
  44. }