# How to determine the pos of texcoord is odd or even in CG

I want to know the x pos of texture coord is odd or even in a CG program,such as the 0,2,4,…is even pos,1,3,5,…is odd pos.I write a code to test,in my code,I check the remainder of x divited by a number is less then a small number or not, if true it is even pos,otherwise it is odd pos.But I fail,and I can’t find out what problem is.Below is my code:

float4 main{float2 texCoord : TEXCOORD0,
uniform sampler2DoriginTex
} : COLOR
{
//the size of texture is 1024x1024,so
//every 2 pixels’ space is below:
static float xSpace = 2.0f/1024.0f;

//fmod() is the CG’s remainder calculation function
if(fmod(texCoord.x,xSpace) < 0.00001f)
return float4{1,0,0,1}; //even line is red
else
return float4{0,1,0,1}; //odd line is green
}

In my guess,the result bitmap should be red green interleaved,but what I see is all green.What’s wrong with my shader?Is it possible to determine the texcoord is odd or even?

What ? texture coordinates are generally not integers so they can’t be odd or even. Or may I missed something about what you wrote ?
You might refer to pixels or texels maybe.

Yes,I mean is the pixels pos of textures is odd or even,such as 0.25 is the second pixel pos of a 4x4 textures,it is odd pos,0.5 is the 3rd pixel pos,it is even.

So what’s the problem if you know how to check if it is odd or even ?

You’ve been mistaken with determining the oddness. The thing, what you wrote, will do the red pixel only for 512/200000 of all the pixels )))

Try to change if expression:
if (frac(texCoord.x * 512.f) < 0.5f)