Hi, I found a lot of CG shader programs has a float4 variable with the name _MainTex_ST. Is this just for the helper function TRANSFORM_TEX in the UnityCG.cginc? And the TRANSFORM_TEX is defined as: Code (csharp): #define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw) Then can I think all _ST parameters are provided by Unity engine? Or maybe the xy means tilting and zw means offset? Thanks a lot!
Yes, 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).
And how does Unity compute what values to put into this scale and offset variable? Is this only needed for usage of texRECT, where texture coordinates in [0,1]x[0,1] have to be mapped to integer coordinates in [0, texWidth]x[0, texHeight]? I stumbled over it in SSAO code...
I would assume from the offset and tiling values on the material as they represent texture scale and texture offset
What is the smallest appropriate data type for `_MainTex_ST` for mobile platform? Is it appropriate to use `half4` instead of `float4`?
Can someone give an example of how to use that key word ? Unity is throwing : Shader error in 'Geometry/DistanceGeomCut': '_MainTex_ST' : undeclared identifier; 'xy' : vector field selection out of range; 'zw' : vector field selection out of range at line 110 (on opengl) And I think it's because I don't use TRANSFORM_TEX properly. Thanks !
Found this : http://answers.unity3d.com/questions/644345/tweak-alpha-on-custom-fragment-shader.html For everyone with the same issue : you need to declare a _{varName}_ST to use TRANSFORM_TEX
hey @Aras, how would you recommend going about programming a keyframe animation for _MainTex_ST. I'm trying this out, but can't seem to get about the 'Object' limitation. AnimationClip clip = new AnimationClip(); EditorCurveBinding binding = new EditorCurveBinding(); binding.type = typeof(MeshRenderer); binding.path = ""; binding.propertyName = textureManager.materialGroups[0].texturePropertyName + "_ST"; ObjectReferenceKeyframe[] keyFrames = new ObjectReferenceKeyframe[Data.Length]; for (int i = 0; i < (Data.Length); i++) { Vector2 value = Data.textureOffset;// Stores a Vector2 of the material offset I want to save in an animation. keyFrames = new ObjectReferenceKeyframe(); keyFrames.time = Data.time; keyFrames.value = value; // a Vector2 is obviously not a UnityEngine.Object. } AnimationUtility.SetObjectReferenceCurve(clip, binding, keyFrames);