Orientation of the texture co-ordinate system for CgFX shaders

When the CgFX plug-in compiles a CgFX shader, it sets either the compilation macro MAYA_TEXCOORD_ORIENTATION_OPENGL or MAYA_TEXCOORD_ORIENTATION_DIRECTX to 1 to specify the orientation used for the texture co-ordinate system.

Set the MAYA_TEXCOORD_ORIENTATION environment variable to either OPENGL or DIRECTX to define the MAYA_TEXCOORD_ORIENTATION_OPENGL or MAYA_TEXCOORD_ORIENTATION_DIRECTX macros respectively. When the macro is defined, it is set to 1.

OPENGL
Specifies that the OpenGL convention is used, where the origin of the texture is at the bottom-left corner of the texture.
DIRECTX
Specifies that the DirectX convention is used, where the origin of the texture is at the top-left corner of the texture.

By default, the MAYA_TEXCOORD_ORIENTATION_OPENGL macro is set to 1. You can change this by setting the environment variable MAYA_TEXCOORD_ORIENTATION to DIRECTX before starting Maya Creative.

Setting the MAYA_TEXCOORD_ORIENTATION environment variable to DIRECTX may be useful when using shaders that have been written for previous versions of Maya and that have not been modified to support the OPENGL texture coordinate orientation. When the MAYA_TEXCOORD_ORIENTATION environment variable is set to DIRECTX, the following occurs:

This changes both the generation of the UV co-ordinates and the loading of the texture image such that if a shader uses UV coordinates to sample a texture, then the rendered image will be the same in both coordinate systems. However, when UVs procedurally generated by the shader (as opposed to ones coming from a UV source stream generated by Maya Creative) are used to sample a texture, the plug-in must be able to handle both conventions. The brix.cgfx example included in $(MAYA_ROOT)/presets/CgFX/example provides an example of how this should be done:

/******************** pixel shader *********************/
#ifdef MAYA_TEXCOORD_ORIENTATION_OPENGL
     float GBalanceCorr = 1.0f - GBalance;
 #else     
     float GBalanceCorr = GBalance;
#endif
    
    float v = ((float4)tex2D(stripeSampler,float2(IN.BrickUV.x,0.5))).x;
    float4 dColor1 = lerp(SurfColor1,SurfColor2,v);
    v = ((float4)tex2D(stripeSampler,float2(IN.BrickUV.x*2,GBalanceCorr))).x;   
    dColor1 = lerp(GroutColor,dColor1,v);
    v = ((float4)tex2D(stripeSampler,float2(IN.BrickUV.x+0.25,0.5))).x;  
    float4 dColor2 = lerp(SurfColor1,SurfColor2,v);
    v = ((float4)tex2D(stripeSampler,float2((IN.BrickUV.x+0.25)*2,GBalanceCorr))).x;
    dColor2 = lerp(GroutColor,dColor2,v);
    v = ((float4)tex2D(stripeSampler,float2(IN.BrickUV.y,0.5))).x;
    float4 brix = lerp(dColor1,dColor2,v);
    v = ((float4)tex2D(stripeSampler,float2(IN.BrickUV.y*2,GBalanceCorr))).x;  
    brix = lerp(GroutColor,brix,v);
       return IN.DCol * brix;
}