I'm trying to draw camera-facing sprites in my scene using only a pixel shader and one screen aligned quad. I want to draw all the sprites in the scene, given 3d world position data. I basically have it working, but there is something not quite right in my coordinates…i will show some code (HLSL)..the issue is I'm not sure the scaling is done right, and the y positioning seems a bit off (all the sprites textures are 64*64 and scaled to a specific value, they are also all supposed to be at the same y position…
float2 aspect = float2(1.0f, screenres.x / screenres.y);
float2 texcoord = In.Tex * 2 - 1;
texcoord.x *= -1;
float spritescale = 1;
for (int i = 0; i < numsprites; i++)
{
spritescale = 64 * spriteData[i].z;
float4 spritecoord = float4(spriteData[i].x, spritescale/2, spriteData[i].y, 1.0f);
spritecoord = mul(matView, spritecoord);
spritecoord = mul(matProj, spritecoord);
spritecoord.xy /= spritecoord.w;
if (spritecoord.z < 1.0f){continue;}
//skip if behind viewer
spritecoord.xy = (spritecoord.xy/aspect) + (texcoord / aspect);
float4 sprite=spritetex.SampleLevel(standard_samp, spritecoord.xy * (spritecoord.w / spritescale), 0);
color.rgb = lerp(color.rgb, sprite.rgb, sprite.a);
}