Hi
I am a newbie in CG. I was making a program in the fragment shader that picks up a texel and try to find the texel more similar in a “piece of” other texture. here is the source:
void main(float4 i_color : COLOR,
float4 texCoord : TEXCOORD0,
out float4 color : COLOR,
uniform sampler2D texture_left,
uniform sampler2D texture_right
)
{
const float desloc = 1/512; //Window size 512x512
float melhor_dif = float(1073741824.0); //smallest diference… (2^30)
float2 melhor_dif_coord = float2(0.0, 0.0); //smallest difference coords.
float4 leftColor = tex2D(texture_left, texCoord.xy); //original texel
float2 aux;
float4 dif_aux;
float soma_dif;
float2 i;
i.y = -4;
for (i.x = -4; i.x< 4; i.x++) {
aux.x = i.xdesloc;
aux.y = i.ydesloc;
if ((i.x+1) > 4 && (i.y+1) < 4) {
i.y++;
i.x = -4;
}
//picking up a new texel to compare
float4 rightColor = tex2D(texture_right, (texCoord.xy+aux));
//calculating the diference
dif_aux = pow((leftColor - rightColor), 2);
soma_dif = dif_aux[0] + dif_aux[1] + dif_aux[2] + dif_aux[3];
//if this is the smallest difference, keep it!!
if (soma_dif < melhor_dif) {
melhor_dif_coord = aux;
melhor_dif = soma_dif;
}
}
//drawing a texture to see the results…
aux.x = pow(melhor_dif_coord.x, 2);
aux.y = pow(melhor_dif_coord.y, 2);
i.x = pow((aux.x + aux.y), 0.5);
color = float4(i.x, i.x, i.x, i.x);
}
I belive there is an error, I compiled with cgc fp40 on NVIDIA 6800, but all I got was a black screen… am I doing any unsuported action?
thanks in advance