HSVShader.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. //From http://forum.unity3d.com/threads/89041-Problem-with-getting-hue-shift-shader-right
  3. //Shouldn't be used for big things as with 8 planes on screen it dropped the frame rate to 12fps even on iPod5g
  4. Shader "Custom/HSVShader" {
  5. Properties {
  6. _MainTex ("Texture", 2D) = "white" {}
  7. _HueShift("HueShift", Float ) = 0
  8. _Sat("Saturation", Float) = 1
  9. _Val("Value", Float) = 1
  10. }
  11. SubShader {
  12. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType" = "Transparent" }
  13. ZWrite Off
  14. Blend SrcAlpha OneMinusSrcAlpha
  15. Cull Off
  16. Pass
  17. {
  18. CGPROGRAM
  19. #pragma vertex vert
  20. #pragma fragment frag
  21. #pragma target 2.0
  22. #include "UnityCG.cginc"
  23. float3 shift_col(float3 RGB, float3 shift)
  24. {
  25. float3 RESULT = float3(RGB);
  26. float VSU = shift.z*shift.y*cos(shift.x*3.14159265/180);
  27. float VSW = shift.z*shift.y*sin(shift.x*3.14159265/180);
  28. RESULT.x = (.299*shift.z+.701*VSU+.168*VSW)*RGB.x
  29. + (.587*shift.z-.587*VSU+.330*VSW)*RGB.y
  30. + (.114*shift.z-.114*VSU-.497*VSW)*RGB.z;
  31. RESULT.y = (.299*shift.z-.299*VSU-.328*VSW)*RGB.x
  32. + (.587*shift.z+.413*VSU+.035*VSW)*RGB.y
  33. + (.114*shift.z-.114*VSU+.292*VSW)*RGB.z;
  34. RESULT.z = (.299*shift.z-.3*VSU+1.25*VSW)*RGB.x
  35. + (.587*shift.z-.588*VSU-1.05*VSW)*RGB.y
  36. + (.114*shift.z+.886*VSU-.203*VSW)*RGB.z;
  37. return (RESULT);
  38. }
  39. struct v2f {
  40. float4 pos : SV_POSITION;
  41. float2 uv : TEXCOORD0;
  42. };
  43. float4 _MainTex_ST;
  44. v2f vert (appdata_base v)
  45. {
  46. v2f o;
  47. o.pos = UnityObjectToClipPos (v.vertex);
  48. o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
  49. return o;
  50. }
  51. sampler2D _MainTex;
  52. float _HueShift;
  53. float _Sat;
  54. float _Val;
  55. half4 frag(v2f i) : COLOR
  56. {
  57. half4 col = tex2D(_MainTex, i.uv);
  58. float3 shift = float3(_HueShift, _Sat, _Val);
  59. return half4( half3(shift_col(col, shift)), col.a);
  60. }
  61. ENDCG
  62. }
  63. }
  64. Fallback "Particles/Alpha Blended"
  65. }