Sign in to follow this  
Capoeirista

Point Sprites & Shaders

Recommended Posts

Hey people, I'm having some issues with the DirectX point structure at the moment and was wondering if any of you could lend a hand. My problem is this - I'm writing a particle system editor and am using the an array of points to render the particles; I want to keep it this way as I'm rendering upwards of 6000 particles at a time and using billboarded quads simply isn't fast enough. Since I want the particles to be textured I have D3DRS_POINTSPRITEENABLE set to true. This hasn't been a problem up until now. I want to do most of the effects and lighting calculations for the particle system in the vertex and pixel shaders, but the problem is that setting D3DRS_POINTSPRITEENABLE to TRUE means that after the vertex shader has done it's thing, all of the texture stages are wiped and I only get the texture coordinates for the selected texture coming through to the pixel shader. This means that in the pixel shader I can't get access to normals or any of the lighting calculations performed in the vertex shader. I've tried specifying specific stages in both the vertex format declaration, the structures I'm using to pass output from the vertex shader to the pixel shader and specificially disabling texture stages I want to use in the shaders; nothing seems to work though. I know i can use the COLOR0 and COLOR1 outputs, but COLOR0 is usually taken up with the colour of the vertex and I often need to pass more than two parameters to the pixel shader. Do any of you have any idea how to use point sprites with texture coordinate generation and still be able to use the texture stages in shaders? Your help would be greatly appreciated!

Share this post


Link to post
Share on other sites
Couldn't seem to get around the point sprite texture coordinate generation wiping all of the texture stages unfortunately.

Got around the problem by rendering the particles as a triangle list, using six vertices for each particle.

This works reasonably well if you set all six vertices to the same position and then offset them in the vertex shader using the texture coordinates and particle size.

Share this post


Link to post
Share on other sites
The NORMAL semantic marked values shouldn't get reassigned new values when using PointSprites. I'm not too sure what you mean by "Texture Stages getting wiped out", but I assume you mean that the texcoords get overwritten.

As for triangle lists, if you're drawing quads, use Indexed Triangle Lists, they'll give you a nice speed gain.

Share this post


Link to post
Share on other sites
Quote:

The NORMAL semantic marked values shouldn't get reassigned new values when using PointSprites. I'm not too sure what you mean by "Texture Stages getting wiped out", but I assume you mean that the texcoords get overwritten.


Yeah I didn't think that normals would be wiped, but I couldn't compile any of the shaders when I tried to pass a normal in to the pixel shader? Should pixel shaders be able to accept normals as aguments?

By texture stages I mean TEXCOORD0-8, I think they're called stages in good old DirectX... but I've been wrong before :)

Quote:

As for triangle lists, if you're drawing quads, use Indexed Triangle Lists, they'll give you a nice speed gain.


I'm definitly drawing quads and using an indexed triangle list was going to be my next step. I guess it means I wouldn't have to double up vertex declarations.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Capoeirista
By texture stages I mean TEXCOORD0-8, I think they're called stages in good old DirectX... but I've been wrong before :)


TEXCOORDs are sets of texture coordinates in the vertex data.
Texture stages (texture stage states, SetTextureStageState) are stages of the fixed-functionality pipeline's texture/shading cascade. The stage states involve controlling the sources and outputs of various stages as well as the actual blending,etc. operations performed in those stages.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
TEXCOORDs are sets of texture coordinates in the vertex data.
Texture stages (texture stage states, SetTextureStageState) are stages of the fixed-functionality pipeline's texture/shading cascade. The stage states involve controlling the sources and outputs of various stages as well as the actual blending,etc. operations performed in those stages.

Cheers!

Share this post


Link to post
Share on other sites
Quote:

As for triangle lists, if you're drawing quads, use Indexed Triangle Lists, they'll give you a nice speed gain.

That worked really well, using an indexed triangle list and doing all of the billboarding in the shader means that there's hardly any difference performance wise over using point sprites.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this