Billboards with vertexshader (HLSL)

Started by
6 comments, last by Matt Aufderheide 17 years, 10 months ago
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!
Advertisement
Use the D3DXSprite interface...this allows you to do exactly what you want easily.
Hmm.. I don't really think D3DXSprite will cut it, because later I want to add a effect where my billboards (grass) is moving in the wind.
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.
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      // positiondcl_blendindices v1  // quad index in xmov a0.x, v1.xadd r0, c[QUADS + a0.x], v0m4x4 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

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?
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.
Yes you can do a lot of with D3DXSprite, and its very well-optimized. I reccomend it to anyone who wants to draw a large number of sprites with shaders and individual transforms.

This topic is closed to new replies.

Advertisement