simple CG task

Hello everyone.

I’m very very hope you’ll help me. Thanks in advance.

I have 3 components of color in different texture ( for the sake simplicity, let it be R G & B).
And finally I want to have one RGB texture and display it. It’s simple task and I have solved it by means of CG . Here is a simple code.

float4 my_prog(float2 texcoord : TEXCOORD0,
			      uniform samplerRECT image,
			      uniform samplerRECT image2,
			      uniform samplerRECT image3
		      ) : COLOR
	float4 c1 = texRECT(image, texcoord);
	float4 c2 = texRECT(image2, texcoord);
	float4 c3 = texRECT(image3, texcoord);
	return float4( c1.x, c2.x, c3.x, 0); 

But how should I change it if image2 and image3 are not the same size as image. In my case image2.windh = image3.width = image.width / 2 . In other words horizontal size of image23 is 2 times smaller than image.

( There is some color scheme H2V1 in witch on two horizontal pixels from image there is just one pixel from image2 & image3 ).

In other words to obtain pixel in result texture with horizontal coordinate X, I should take in account pixel from image2 with horizontal coordinate X/2.

Result[x,y] = F ( image(x,y) , image2(x/2,y), image3(x/2,y));

The question is how is it possible to change my_prog function ?

In the case if it’s important I give you example of code, which uses my_prog.
This code is successfully used for the case the textures are the same size.

// perform a rendering pass with given fragment program and source and destination buffers
void Pass(
					CGprogram prog, 
					RenderTexture *src, 
					RenderTexture *src2, 
					RenderTexture *src3, 
					RenderTexture *dest)
    if (src2) {

	if (src3) {

    DrawQuad(dest->GetWidth(), dest->GetHeight(), width, height);

    if (src2) src2->Release();
	if (src3) src3->Release();

void DrawQuad(int w, int h, int tw, int th)
    glTexCoord2i(0, 0); glVertex2i(0, 0);
    glTexCoord2i(tw, 0); glVertex2i(w, 0);
    glTexCoord2i(tw, th); glVertex2i(w, h);
    glTexCoord2i(0, th); glVertex2i(0, h);

Cg and glsl does not care about texture size as all texture coordinates are in the 0.0-1.0 range.
So if you use two textures with different sizes but with the same texture coordinates one of them will look slightly stretched or blurred compared to the other, the textures will however cover the same area.

That’s only with regular textures. With RECT textures, just divide the texture coordinates by 2.

Originally posted by Overmind:
That’s only with regular textures. With RECT textures, just divide the texture coordinates by 2.
Was it the answer to zeoverlord ?
If it is how can I divide only horisontal coordinates by 2 ? Can you, please, type one code row ?