Point sprites in XNA
I was wondering if i would be possible to display point sprites (in 3D) using the BasicEffect? When I specify the position and the texture, I see colored points where the sprites should be (really the size of pixels). I guess the BasicEffect doesn't support point sprites, but because I cannot find the PointScaleA-C renderstates in XNA, I still have some hope. I found the PointSpriteEnable renderstate remained functional: setting this to false would draw black pixels at the position of my point sprites.
[538 byte] By [
riemerg] at [2007-12-26]
Riemer - since there was no answers from MS you might want to put this in as a bug?
hey zman thanks for answering
I'll first bump this once more, because I'm not too sure if it's a bug: probably it's just me that cannot find how to set the falloff constants from XNA, maybe it's just the basiceffect that cannot handle pointsprites.
I'll also try to write a shader that should be able to display point sprites (if I find some time). If that doesn't work too, i'll report it as a bug.
To draw point sprites, you need to set the PointSpriteEnable
renderstate, and output a value with the PSIZE0 semantic from your
vertex shader to control the point size.
Because XNA is a shader platform, the point size must be calculated in
your vertex shader: the old fixed function falloff renderstates are
gone.
BasicEffect doesn't compute or output a point size, so you can't use that for drawing point sprites.
Point sprites are also not 100% consistent between Windows and Xbox.
You can still make them work on Xbox, but you have to do some things a
little differently in your pixel shader.
thanks shawn for the reply
I'll try to code a shader that handles point sprites, haven't been there before but I have some books that should contain enough info. I'll let you know when I got something.
Try something like this as a starting point:
float4x4 View; float4x4 Projection;
texture Texture;
sampler Sampler = sampler_state
{
Texture = (Texture);
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float Size : PSIZE0;
};
VS_OUTPUT VertexShader(float4 position : POSITION0)
{
VS_OUTPUT output;
output.Position = mul(mul(position, View), Projection);
output.Size = 64;
return output;
}
float4 PixelShader(float2 texCoord : TEXCOORD0) : COLOR0
{
return tex2D(Sampler, texCoord);
}
technique
{
pass
{
VertexShader = compile vs_1_1 VertexShader();
PixelShader = compile ps_1_1 PixelShader();
}
}
For a real program you'd probably want to compute the point size in the
vertex shader, or pass it in as part of your vertex data, rather than
just using a hard-coded constant size.
you know it took me 2 hours yesterday to figure out the texcoords were simply generated by the rasterizer? While your response was only 15 minutes after my post...
Anyway, it's working now and I'm glad point sprites are still supported by XNA.
Thanks again!
I've been trying to get point sprites to work on my XBox. The shader example you give works fine on XP but when I run it on the XBox it just shows up as black boxes. Any idea what I need to do differently in the the pixel shader to get it to work on the XBox?
I've just managed to get point sprites to work on the XBox. I didn't actually use PointSpriteEnable, but instead I used VPOS to get screen coordinates. From the vertex shader I send the vertex position in screen position and the point size. In the pixel shader I can use this information to create the texture coordinates.
But I've no been able to get the PointSpriteEnable to work in the XBox. I would be interrested to hear if someone has solved this differently.
hordurj wrote: |
| I've just managed to get point sprites to work on the XBox. I didn't actually use PointSpriteEnable, but instead I used VPOS to get screen coordinates. From the vertex shader I send the vertex position in screen position and the point size. In the pixel shader I can use this information to create the texture coordinates. But I've no been able to get the PointSpriteEnable to work in the XBox. I would be interrested to hear if someone has solved this differently. |
|
I don't have an XBox so I cannot test this, but I have seen some shaders include "PointSpriteEnable = true;" in the pass' definition of pointsprite-related techniques:
technique MyTechnique
{
pass
{
PointSpriteEnable = true;
VertexShader = compile vs_2_0 VertexShader();
PixelShader = compile ps_2_0 PixelShader();
}
}
Maybe it helps ...