Welcome to MSDN Blogs Sign in | Join | Help

Point sprites on Xbox

Those of you who have tried to render point sprites on Xbox will have noticed they don't work quite the same as on Windows.

We are working on updating the XNA documentation to cover the various Xbox HLSL extensions, but in the meantime, here's what you need to know to make point sprites work.

First a reminder of the things that are common to both platforms. To draw point sprites, you need to set the PointSpriteEnable renderstate to true. In your vertex shader you must write the sprite center position to the POSITION0 output semantic, and the sprite size to the PSIZE0 semantic.

On Windows, your pixel shader will typically take a float2 input parameter using the TEXCOORD0 semantic. But on Xbox, you should use the SPRITETEXCOORD semantic, and the parameter type is float4. The coordinate values you want will be in the Z and W fields, and may be negative. Crazy, huh?

Here is a typical point sprite pixel shader that will work the same on both Windows and Xbox:

    struct PS_INPUT
    {
        #ifdef XBOX
            float4 TexCoord : SPRITETEXCOORD;
        #else
            float2 TexCoord : TEXCOORD0;
        #endif
        
        float4 Color : COLOR0;
    };

    float4 PixelShader(PS_INPUT input) : COLOR0
    {
        float2 texCoord;

        #ifdef XBOX
            texCoord = abs(input.TexCoord.zw);
        #else
            texCoord = input.TexCoord.xy;
        #endif

        return tex2D(Sampler, texCoord) * input.Color;
    }

One final gotcha may occur if you are using dynamic vertex buffers to render point sprite particles. On Windows that is typically done using the Discard vertex buffer locking semantic, which is not supported on Xbox. The best way to render dynamic geometry on Xbox is using the GraphicsDevice.DrawUserPrimitives method (which works on Windows as well).

Published Wednesday, January 03, 2007 11:26 AM by ShawnHargreaves

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Wednesday, January 03, 2007 3:46 PM by snprbob86

# re: Point sprites on Xbox

DrawUserPrimitives is typically considered a performance no-no on Windows. On the Xbox, I'd assume it is still slower than DrawPrimatives, correct?

I'm curious about this... are the User methods OK because of the 360's shared memory architecture?

Wednesday, January 03, 2007 3:54 PM by ShawnHargreaves

# re: Point sprites on Xbox

On Xbox, user primitives are not only the fastest way to do this, they're the only way! Without a discard locking semantic, you just can't get any kind of performance from dynamic vertex buffers.

On Windows, user primitives are only slow because of crappy drivers. They're generally a lot faster now than they used to be a few years ago, anyway: fast enough that I wouldn't have any qualms about using them in a real game.

Wednesday, January 03, 2007 4:29 PM by Ultrahead

# re: Point sprites on Xbox

Does anybody know whether a GeForce 6600 GT card supports pointsprites or not? I cannot run XNA games that use them, and I have found no info confirming one thing or the other.

Thursday, January 04, 2007 10:46 AM by CatalinZima

# re: Point sprites on Xbox

I can confirm point sprites work on GeForce 6600 GT.

Thursday, January 04, 2007 10:08 PM by snprbob86

# re: Point sprites on Xbox

Interesting, thanks for the clarifcation.

Tuesday, January 16, 2007 4:52 PM by Ultrahead

# re: Point sprites on Xbox

"I can confirm point sprites work on GeForce 6600 GT."

Me too, now!

I've found an old MDX 1 example that uses Point Sprites and everything runs just perfect.

Thanks Catalin ...

Tuesday, February 20, 2007 11:17 AM by redneon

# re: Point sprites on Xbox

I don't suppose anyone has an example implementation of the above shader?

I want to implement point sprites in my game but I'm not sure how to do it.

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker