Search Unity

How to Change UV word position

Discussion in 'Shaders' started by gurkan, Jun 11, 2021.

  1. gurkan

    gurkan

    Joined:
    Jul 4, 2013
    Posts:
    23
    hi everyone,
    I find this shader code. this is working. but, how change base texture to word space UV.
    (only base texture)
    this my code (URP):
    Code (CSharp):
    1. Shader "Custom/test_mat2"
    2. {
    3. Properties {
    4.      _AlphaVal ("AlphaVal", Range (0,1) ) = 1.0
    5.      _MainTex ("MainTex (Sprite)", 2D) = "white" {}  ///this texture change
    6.      _AlphaTex ("AlphaTex (R)", 2D) = "white" {}
    7. }
    8. SubShader {
    9.      Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    10.      LOD 100
    11.    
    12.      ZWrite Off
    13.      Blend SrcAlpha OneMinusSrcAlpha
    14.    
    15.      Pass {
    16.          CGPROGRAM
    17.              #pragma vertex vert
    18.              #pragma fragment frag
    19.            
    20.              #include "UnityCG.cginc"
    21.              struct appdata_t {
    22.                  float4 vertex : POSITION;
    23.                  float2 texcoord : TEXCOORD0;
    24.                  float2 texcoordA : TEXCOORD1; // alpha uv
    25.              };
    26.              struct v2f {
    27.                  float4 vertex : SV_POSITION;
    28.                  half2 texcoord : TEXCOORD0;
    29.                  half2 texcoordA : TEXCOORD1; // alpha uv
    30.              };
    31.              sampler2D _MainTex;
    32.              sampler2D _AlphaTex;
    33.              float _AlphaVal;
    34.            
    35.              float4 _MainTex_ST;
    36.              float4 _AlphaTex_ST; // alpha uv
    37.            
    38.              v2f vert (appdata_t v)
    39.              {
    40.                  v2f o;
    41.                  o.vertex = UnityObjectToClipPos(v.vertex);
    42.                  o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    43.                  o.texcoordA = TRANSFORM_TEX(v.texcoordA, _AlphaTex); // alpha uv
    44.                  return o;
    45.              }
    46.            
    47.              fixed4 frag (v2f i) : SV_Target
    48.              {
    49.                  fixed4 main = tex2D(_MainTex, i.texcoord);
    50.                  fixed4 alph = tex2D(_AlphaTex, i.texcoordA); // alpha uv
    51.                
    52.                  return fixed4(main.r, main.g, main.b, (main.a*alph.r*_AlphaVal));
    53.              }
    54.          ENDCG
    55.      }
    56. }
    57. }