首页 > 代码库 > What is _MainTex_ST ?

What is _MainTex_ST ?

What is _MainTex_ST ?

  在Unity自带的Unlit/Texture中,有引用到float4 _MainTex_ST,如下:

// Unlit shader. Simplest possible textured shader.// - no lighting// - no lightmap support// - no per-material colorShader "Unlit/Texture" {Properties {    _MainTex ("Base (RGB)", 2D) = "white" {}}SubShader {    Tags { "RenderType"="Opaque" }    LOD 100        Pass {          CGPROGRAM            #pragma vertex vert            #pragma fragment frag                        #include "UnityCG.cginc"            struct appdata_t {                float4 vertex : POSITION;                float2 texcoord : TEXCOORD0;            };            struct v2f {                float4 vertex : SV_POSITION;                half2 texcoord : TEXCOORD0;            };            sampler2D _MainTex;            float4 _MainTex_ST;                        v2f vert (appdata_t v)            {                v2f o;                o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);                o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);                return o;            }                        fixed4 frag (v2f i) : SV_Target            {                fixed4 col = tex2D(_MainTex, i.texcoord);                return col;            }        ENDCG    }}}
View Code

  TRANSFORM_TEX宏如下:

  

  indeed for any texture property, Unity provides value for float4 with "_ST" suffix. The x,y contains texture scale, and z,w contains translation (offset).

  _ST变量有4个值,xy是texture scale,zw是offset。

  

  在Material中可以设置的Tiling就是xy,Offset就是zw。

参考:http://forum.unity3d.com/threads/what-is-_maintex_st.24962/

What is _MainTex_ST ?