EasyImageEffectShader.shader 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Shader "MyShader/EasyImageEffectShader"
  2. {
  3. Properties
  4. {
  5. _MainTex("Texture", 2D) = "white" {}
  6. _Brightness("Brightness", Range(0,10)) = 1
  7. _Saturation("Saturation", Range(0,10)) = 1
  8. _Contrast("Contrast", Range(0,10)) = 1
  9. }
  10. SubShader
  11. {
  12. Tags { "RenderType" = "Opaque" }
  13. LOD 100
  14. Pass
  15. {
  16. CGPROGRAM
  17. #pragma vertex vert
  18. #pragma fragment frag
  19. #include "UnityCG.cginc"
  20. struct appdata
  21. {
  22. float4 vertex : POSITION;
  23. float2 uv : TEXCOORD0;
  24. };
  25. struct v2f
  26. {
  27. float2 uv : TEXCOORD0;
  28. float4 vertex : SV_POSITION;
  29. };
  30. sampler2D _MainTex;
  31. float4 _MainTex_ST;
  32. fixed _Brightness;
  33. fixed _Saturation;
  34. fixed _Contrast;
  35. v2f vert(appdata v)
  36. {
  37. v2f o;
  38. o.vertex = UnityObjectToClipPos(v.vertex);
  39. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  40. return o;
  41. }
  42. fixed4 frag(v2f i) : SV_Target
  43. {
  44. fixed4 col = tex2D(_MainTex, i.uv);
  45. //brigtness亮度
  46. fixed3 finalColor = col * _Brightness;
  47. //saturation调整饱和度
  48. fixed gray = 0.2125 * col.r + 0.7154 * col.g + 0.0721 * col.b;
  49. fixed3 grayColor = fixed3(gray, gray, gray);
  50. finalColor = lerp(grayColor, finalColor, _Saturation);
  51. //contrast调整对比度
  52. fixed3 avgColor = fixed3(0.5, 0.5, 0.5);
  53. finalColor = lerp(avgColor, finalColor, _Contrast);
  54. return fixed4(finalColor, col.a);
  55. }
  56. ENDCG
  57. }
  58. }
  59. }