Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL Shading Language TRANSFORM_TEX

Tags:

unity3d

shader

In unity3d there is a piece of code for a vertex shader :

v2f vert(appdata_full v) {
    v2f o;

    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);   
    o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    o.vertexColor = v.color * _TintColor;

    return o; 
}

In lines below :

o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

what is the main task of TRANSFORM_TEX function and what is it's equiavalent in CgFx !

like image 667
S.A.Parkhid Avatar asked Feb 18 '13 17:02

S.A.Parkhid


1 Answers

It's just a Unity3D specific macro, there's no Cg equivalent. You can find this macro definition in the file:

Unity\Editor\Data\CGIncludes\UnityCG.inc

It's defined this way:

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

It scales and offsets texture coordinates. XY values controls the texture tiling and ZW the offset.

like image 165
Heisenbug Avatar answered Sep 24 '22 14:09

Heisenbug