Search Unity

Adding a color picker...

Discussion in 'Shaders' started by Vectorbox, Jan 21, 2021.

  1. Vectorbox

    Vectorbox

    Joined:
    Jan 27, 2014
    Posts:
    232
    Shaders are not my strong point but I've usually managed to adapt existing examples to suit my needs, until now.

    I found the following 'UVRotation' shader on this forum and it's almost perfect for my needs apart from the lack of a colour picker which as yet, I've failed to address.

    Could a shader guru could point me in the right direction ?

    Code (CSharp):
    1. Shader "Custom/UVRotation"
    2. {
    3. Properties
    4. {
    5. _MainTex ("Texture", 2D) = "white" {}
    6. _Angle ("Angle", Range(-5.0, 5.0)) = 0.0
    7. }
    8. SubShader
    9. {
    10. Tags { "RenderType"="Opaque" }
    11.  
    12. Pass
    13. {
    14. CGPROGRAM
    15. #pragma vertex vert
    16. #pragma fragment frag
    17. #include "UnityCG.cginc"
    18.  
    19. struct v2f {
    20. float4 pos : SV_POSITION;
    21. float2 uv : TEXCOORD0;
    22. };
    23.  
    24. float _Angle;
    25.  
    26. v2f vert(appdata_base v)
    27. {
    28. v2f o;
    29. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    30.  
    31. // Pivot
    32. float2 pivot = float2(0.5, 0.5);
    33. // Rotation Matrix
    34. float cosAngle = cos(_Angle);
    35. float sinAngle = sin(_Angle);
    36. float2x2 rot = float2x2(cosAngle, -sinAngle, sinAngle, cosAngle);
    37.  
    38. // Rotation consedering pivot
    39. float2 uv = v.texcoord.xy - pivot;
    40. o.uv = mul(rot, uv);
    41. o.uv += pivot;
    42.  
    43. return o;
    44. }
    45.  
    46. sampler2D _MainTex;
    47.  
    48. fixed4 frag(v2f i) : SV_Target
    49. {
    50. // Texel sampling
    51. return tex2D(_MainTex, i.uv);
    52. }
    53.  
    54. ENDCG
    55. }
    56. }
    57. }
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
  3. Vectorbox

    Vectorbox

    Joined:
    Jan 27, 2014
    Posts:
    232
    Thanks for the 'gentle-introduction' link but I've adapted the shader as required.