Point sprite scaling in XNA
Today, to my horror, I realized after creating a point-sprite based particle system for Cosmopolis that XNA does not seem to support point-sprite scaling. Meaning that if you set your point sprite to be of size 100, it will occupy 100 pixels on your screen whether you are viewing it up close, or miles away. After a decent session of googling I found a solution which involves setting renderstates that the XNA does not allow you to set in code. You instead need to set them in the HLSL shader pass definition (which I normally do not like to do for various reasons). This will suffice (and set up a “correct” scale according to the previously linked article):
1 2 3 4 5 6 7 8 9 10 11 12 | pass Pass0
{
VertexShader = compile vs_1_1 VS_Particles();
PixelShader = compile ps_1_1 PS_Particles();
POINTSCALEENABLE= TRUE;
POINTSCALE_A = 0.0f;
POINTSCALE_B = 0.0f;
POINTSCALE_C = 1.0f;
POINTSIZE_MIN = 0.0f;
POINTSIZE_MAX = 9999.0f;
} |
Just be aware that you can not set these renderstates back through XNA, although it shouldn’t affect anything else.