I'm trying to interpolate between integer pixel coordinates instead of between 0-1, because I'm using point sampling, so I'm not interested in fractions of pixels, but the texture coordinates are still coming into the pixel shader as float2 even though the data type is int2.
pixelSize is 1 divided by texture size
matrix WorldViewProjection;
float2 pixelSize;
Texture2D SpriteTexture;
sampler2D SpriteTextureSampler = sampler_state
{
Texture = <SpriteTexture>;
AddressU = clamp;
AddressV = clamp;
magfilter = POINT;
minfilter = POINT;
mipfilter = POINT;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float4 Color : COLOR0;
int2 TextureCoordinates : TEXCOORD0;
};
VertexShaderOutput SpriteVertexShader(float4 position : POSITION0, float4 color : COLOR0, float2 texCoord : TEXCOORD0)
{
VertexShaderOutput output;
output.Position = mul(position, WorldViewProjection);
output.Color = color;
output.TextureCoordinates = texCoord * (1 / pixelSize);
return output;
}
float4 SpritePixelShader(VertexShaderOutput input) : COLOR
{
float2 texCoords = input.TextureCoordinates * pixelSize;
return tex2D(SpriteTextureSampler, texCoords) * input.Color;
}
technique SpriteDrawing
{
pass P0
{
VertexShader = compile vs_2_0 SpriteVertexShader();
PixelShader = compile ps_2_0 SpritePixelShader();
}
};
pixelSize
is already one divided by the texture size, you should not divide it again at computing the texture coordinate. So it should beoutput.TextureCoordinates = texCoord * pixelSize;
– Gnietschow* pixelSize
in the pixel shader. I thought your vertex data contains integer texture coordinates. What is your problem exactly? In the post is no question and I don't see the point of converting the texCoord into integer and back to float without doing anything between. – Gnietschow