Archived

This topic is now archived and is closed to further replies.

Cybird

Billboarding with vertex shaders

Recommended Posts

Currently, I use a dynamic VB wich I update every frame to transform each of my billboard. But this technique is costly when i have n > 1500 billboards. So is it faster using a vertex shader to transform them on the gpu? I dont really know how to implement them. Thanx for ur help

Share this post


Link to post
Share on other sites
You can do it on the GPU exactly the same way as you would on the CPU. The only difference is that for each vertex you must store an extra value indicating which corner of the billboard quad the vertex lies in.

Generally speaking offloading this to the GPU will be a good thing, but it depends on your CPU vs GPU load.

Share this post


Link to post
Share on other sites
quote:
I dont really know how to implement them.

For each billboard, store 4 vertices of the same position (the center of the billboard) and with each vertex, store a value that defines which corner of the billboard it should be (i.e. top-left, top-right, bottom-left, bottom-right).

Store the camera's up and right vectors, as well as the billboard width and height in the shader's constant table.
For each vertex (pseudo):
if top-left
pos += -camRight * billboardWidth + camUp * billboardHeight
elseif top-right
pos += camRight * billboardWidth + camUp * billboardHeight
elseif bottom-left
pos += -camRight * billboardWidth - camUp * billboardHeight
elseif bottom-right
pos += camRight * billboardWidth - camUp * billboardHeight
end


Cheers,
Muhammad Haggag

edit: fixed pseudo code

[edited by - Coder on May 4, 2003 12:00:28 AM]

Share this post


Link to post
Share on other sites