Search Unity

how to clamp only one axis of a texture?

Discussion in 'Shaders' started by kosukito, May 1, 2017.

  1. kosukito

    kosukito

    Joined:
    Sep 6, 2014
    Posts:
    8
    1. looking for my problem on the forum i got that you can edit the sampler
    2. but unfortunely i can't get it working i am doing something wrong?

    3. Code (CSharp):
      1. texture _MainTex;
      2. Shader "Unlit/LinearGradient"
      3. {
      4.     Properties{
      5.         _TopColor("Color1", Color) = (1,1,1,1)
      6.         _BottomColor("Color2", Color) = (1,1,1,1)
      7.         _MainTex("Main Texture", 2D) = "white" {}
      8.     }
      9.         SubShader
      10.     {
      11.         Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
      12.         Pass
      13.     {
      14.         ZWrite Off
      15.         Blend SrcAlpha OneMinusSrcAlpha
      16.  
      17.         CGPROGRAM
      18. #pragma vertex vert
      19. #pragma fragment frag
      20.  
      21. #include "UnityCG.cginc"
      22.  
      23.     //sampler2D _MainTex;
      24.     float4 _MainTexSampler_ST;
      25.  
      26.  
      27. texture _MainTex;
      28. sampler2D _MainTexSampler = sampler_state
      29. {
      30.     Texture = <_MainTex>;
      31.     AddressU = REPEAT;
      32.     AddressV = WRAP;
      33.     MinFilter = LINEAR;
      34.     MagFilter = LINEAR;
      35.     MipFilter = LINEAR;
      36. };
      37.     fixed4 _TopColor;
      38.     fixed4 _BottomColor;
      39.     half _Value;
      40.  
      41.     struct v2f {
      42.         float4 position : SV_POSITION;
      43.         fixed4 color : COLOR;
      44.         float2 uv : TEXCOORD0;
      45.     };
      46.  
      47.     v2f vert(appdata_full v)
      48.     {
      49.         v2f o;
      50.         o.position = mul(UNITY_MATRIX_MVP, v.vertex);
      51.         o.uv = TRANSFORM_TEX(v.texcoord, _MainTexSampler);
      52.         o.color = lerp(_TopColor,_BottomColor, v.texcoord.y);
      53.         return o;
      54.     }
      55.  
      56.     fixed4 frag(v2f i) : SV_Target
      57.     {
      58.         float4 color;
      59.     color.rgb = i.color.rgb;
      60.     color.a = tex2D(_MainTexSampler, i.uv).a + i.color.rgb;
      61.     return color;
      62.     }
      63.         ENDCG
      64.     }
      65.     }
      66. }
      67.  
      68.  
      69. };

    note that the image i select on the inspector is not a white square is a cloud, that i need to clamp in just horizontal.

    if someone can point me in some direction i will apreciate it much... sorry by my english btw..
    thanks in advance.
     
    Last edited: May 1, 2017
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Just saturate the X component of your UV's.
     
  3. kosukito

    kosukito

    Joined:
    Sep 6, 2014
    Posts:
    8
    thanks a lot man!, i'm pretty new on shaders, i woulded take ages to figurate it by myself. thanks again!