I've got simple shader that is masking main texture with mask texture: Code (CSharp): Shader "MaskedTexture" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _Mask ("Culling Mask", 2D) = "white" {} _Cutoff ("Alpha cutoff", Range (0,1)) = 0.1 } SubShader { Tags {"Queue"="Transparent"} Lighting Off ZWrite Off Blend SrcAlpha OneMinusSrcAlpha AlphaTest GEqual [_Cutoff] Pass { SetTexture [_Mask] {combine texture} SetTexture [_MainTex] {combine texture, previous} } } } works great but i need to be able to change tiling value of "_MainTex". As i understood tiling is stored in "_MainTex_ST" but i got no idea how to include it into shader so i can reference to it via script.
This is a fixed function style shader for use with GPUs that Unity no longer supports. Unity no longer supports using fixed function shaders and they are considered deprecated, though they still "work" by treating them as vertex fragment shader generators rather than trying to use the shader code directly. So the above shader is automatically turned into a vertex fragment shader that the engine actually uses. You can select the shader in the project view and click on "Show Generated Code" to see what it outputs, but it looks like this: Code (csharp): Shader "MaskedTexture" { Properties { _MainTex ("Base (RGB)", 2D) = "white" { } _Mask ("Culling Mask", 2D) = "white" { } _Cutoff ("Alpha cutoff", Range(0.000000,1.000000)) = 0.100000 } SubShader { Tags { "QUEUE"="Transparent" } Pass { Tags { "QUEUE"="Transparent" } ZWrite Off Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma target 2.0 #include "UnityCG.cginc" #pragma multi_compile_fog #define USING_FOG (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)) // uniforms float4 _Mask_ST; float4 _MainTex_ST; // vertex shader input data struct appdata { float3 pos : POSITION; float3 uv0 : TEXCOORD0; UNITY_VERTEX_INPUT_INSTANCE_ID }; // vertex-to-fragment interpolators struct v2f { fixed4 color : COLOR0; float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; #if USING_FOG fixed fog : TEXCOORD2; #endif float4 pos : SV_POSITION; UNITY_VERTEX_OUTPUT_STEREO }; // vertex shader v2f vert (appdata IN) { v2f o; UNITY_SETUP_INSTANCE_ID(IN); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); half4 color = half4(0,0,0,1.1); float3 eyePos = mul (UNITY_MATRIX_MV, float4(IN.pos,1)).xyz; half3 viewDir = 0.0; o.color = saturate(color); // compute texture coordinates o.uv0 = IN.uv0.xy * _Mask_ST.xy + _Mask_ST.zw; o.uv1 = IN.uv0.xy * _MainTex_ST.xy + _MainTex_ST.zw; // fog #if USING_FOG float fogCoord = length(eyePos.xyz); // radial fog distance UNITY_CALC_FOG_FACTOR_RAW(fogCoord); o.fog = saturate(unityFogFactor); #endif // transform position o.pos = UnityObjectToClipPos(IN.pos); return o; } // textures sampler2D _Mask; sampler2D _MainTex; fixed _Cutoff; // fragment shader fixed4 frag (v2f IN) : SV_Target { fixed4 col; fixed4 tex, tmp0, tmp1, tmp2; // SetTexture #0 tex = tex2D (_Mask, IN.uv0.xy); col = tex; // SetTexture #1 tex = tex2D (_MainTex, IN.uv1.xy); col.rgb = tex; col.a = col.a; // alpha test if (col.a < _Cutoff) clip(-1); // fog #if USING_FOG col.rgb = lerp (unity_FogColor.rgb, col.rgb, IN.fog); #endif return col; } // texenvs //! TexEnv0: 01010000 01010000 [_Mask] //! TexEnv1: 01010000 01040004 [_MainTex] ENDCG } } } Notice _MainTex_ST is already being used, so the tiling and offset should already work.
Sorry for bothering again. So i managed modify tiling in this shader via script. Now i'm trying to do the same with rotation of the main texture. So i need to insert this snippet into above shader: Code (CSharp): struct v2f { float2 uv : TEXCOORD0; float4 pos : SV_POSITION; }; float4x4 _TextureRotation; v2f vert (float4 pos : POSITION, float2 uv : TEXCOORD0) { v2f o; o.pos = UnityObjectToClipPos(pos); o.uv = mul(_TextureRotation, float4(uv,0,1)).xy; return o; } But as a shader noob i've got no idea how to do it(
There are several threads on rotating UVs on the forum. Search for one of those. Or read up on 2D rotations.