Sign in to follow this  

Billboards with vertexshader (HLSL)

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to be able to batch a lot of billboards (more than 1000) and render the whole bunch at once (with a single DrawPrimitive call, all facing the camera). Is using a vertexshader (HLSL) the only way to go or is there any other way? If that's the case, what will the shader look like? Thanks in advance!

Share this post


Link to post
Share on other sites
You can use shaders with D3DXSprites, I do the same thing in my engine with wind and such..

Just draw the sprites inside an effect pass, and use the
D3DXSPRITE_DONOTMODIFY_RENDERSTATE when you begin the sprite interface.

Share this post


Link to post
Share on other sites
Theres quite a few problems with sprites for billboards;
- they're only square
- not all cards can support different sizes within a batch
- you cant rotate them

In my particle system, i used quads in a shader - i filled a vertex buffer with 4 copies of each point, and an index, then used that index to offset the point into a quad.
The 4 view-aligned quad points were passed in as constants

so, my buffer looked like;
position1, 0, position1, 1, position1, 2, position1, 3, position2, 0, position2, 1, position2, 2, position2, 3, position3, 0 ...

then in the shader, i used;


dcl_position v0 // position
dcl_blendindices v1 // quad index in x

mov a0.x, v1.x
add r0, c[QUADS + a0.x], v0
m4x4 oPos, r0, c[TRANSFORM]



where the transform and quads are constants - the quads are just;
[-0.5, -0.5, 0, 0], [0.5, -0.5, 0, 0] etc
then transformed to the view each frame.

Note, i actually passed texture coordinates in as well as the quad, and indexed those as well (with the same index).

Wyzfen

Share this post


Link to post
Share on other sites
I think I could do it with D3DXSprite, but if I use D3DXSPRITE_DONOTMODIFY_RENDERSTATE.. wouldn't it defeat the purpose of D3DXSprite that sets up everything so simple?

- Also, isn't it so that you CAN rotate D3DXSprite and they don't have to be square?

Share this post


Link to post
Share on other sites
Yes, ID3DXSprite allow you to specify a transformation matrix for each sprite. So they can be rectangular, rotated, etc. They can even not face the camera ^^

And that's why I don't use them often. When I don't need all those options, I use my own minimal sprite system which uses a shader. It's faster thant using ID3DXSprites since I do only what I need.

Share this post


Link to post
Share on other sites

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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