Search Unity

_MainTex_ST , what is _ST???

Discussion in 'Shaders' started by aubergine, Jan 26, 2011.

  1. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    I see in some sample shaders theres a sampler2d _MainTex and theres a float4 _MainTex_ST although i dont see it being used anywhere. What does _ST do, where in the documents is such stuff explained i looked everywhere.
     
    fardinhaque92 likes this.
  2. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    Okay, after some deepsearch _ST is used in the TRANSFORM_TEX function in UnityCG.cginc

    / Transforms float2 UV by scale/bias property
    #define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)

    I think the shaderlab needs better documentation about the include files and tidying up on related topics.
     
  3. pilypala

    pilypala

    Joined:
    Jan 13, 2011
    Posts:
    8
    This is used to specify tiling and offset for each texture. See the tiling and offset parameters next to each texture box? Their values are contained in this _ST variable to be used in TRANSFORM_TEX.
     
    NAZLIM likes this.
  4. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    i see, thanks alot for clearing that up.
     
  5. gtoledo3

    gtoledo3

    Joined:
    Aug 3, 2010
    Posts:
    2
    S and T are commonly used variables for texturing in a variety of shader languages.

    If each element in 3D space has an x/y/z coordinate, there's a corresponding 2D S/T coordinate.... this is also often termed UV. S goes across the X axis typically, and T would go along the Y axis.
     
    fardinhaque92 and chillam69 like this.
  6. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,878
    Okay, i get it. It was confusing at first. Finally, this _ST thing is only used in one specific unity function TRANSFORM_TEX which just multiplies the uv with tiling and offset values as pilyala already mentioned.
    Thanks.
     
  7. gtoledo3

    gtoledo3

    Joined:
    Aug 3, 2010
    Posts:
    2
    That kind of makes sense...but ST is usually screenspace and UV is model (not talking about Unity, just generally). Hmm. Interesting that it's set up like that.
     
    Last edited: Jan 31, 2011
  8. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    S and T are just more consecutive letters in the alphabet. They often get used for texture space, or parameterized surface space, but they do not have a standard definition. In this case, they're two numbers that get applied to UV coordinates, so they get the next two letters.
     
    fardinhaque92, wedgiebee and Reynarz like this.