annoying offset

Posted By: jenGs

annoying offset - 07/29/14 23:45

I use bmap_process a lot.
Here my question, why do I have an offset coming with the input Texture coordinates.

Code:
float4 process_bmap(float2 Tex: TEXCOORD0): COLOR 
{
	float4 color;
	if(vecSkill1[2] >= Tex.x)
	{
		color = float4(1, 0, 0, 1);
	}
	else
	{
		color = float4(0, 0, 0, 1);
	}
	
	return color;
}



TEXCOORD0 comes with an offset between -0.05 and -0.06
That means the texture coordinates are not in between 0.0 - 1.0 range

I guess it is a bug in bmap_process. But I am not a shader expert so this could have a simple different reason.

I know that my code above is an example of bad shader programming. But I did that to eliminate all hlsl functions and just debug "Tex".
Posted By: Kartoffel

Re: annoying offset - 07/30/14 08:13

try using VPOS (the coordinate in pixels, that's why you have to add a half-pixel offset and divide it by the resolution)

Code:
void PShader(in float4 vPos : VPOS, ....
{
	float2 tex = (vPos.xy + 0.5) / vecViewPort.xy;

Posted By: jenGs

Re: annoying offset - 07/30/14 09:47

Thank you, that worked.

Is there a special reason why there is a half pixel offset?
Posted By: Kartoffel

Re: annoying offset - 07/30/14 10:12

the top left pixel has the position 0, 0 (oops, actually it's 1, 1)
in shaders however, the sample point needs to be in the middle of the pixel

But that's just needed for VPOS, I don't know why TEXCOORD0 is so inaccurate.
© 2024 lite-C Forums