Vertex Shader for Billboards

Started by
1 comment, last by MJP 15 years, 10 months ago
Hi guys! I'm currently working on a little vertex shader (cgFX) for rendering billboards. All it should do is to rotate the quads I pass in towards the camera (along all axis). But somehow I can't get it to work... the code must actually be pretty simple ;-) Can anyone give me a hint or ssome sample code? thx!
Advertisement
I'm not sure myself, but it looks like this is helpful:

http://www.gamedev.net/community/forums/topic.asp?topic_id=154890
Assuming your billboards are already oriented in object space such that they're facing forward, you don't need to rotate them at all. All you need to do is not rotate them when you transform them to view-space.

float4x4 matWorldView = mul(matWorld, matView);float3 vPositionVS = in_vPositionOS + float3(matWorldView._41, matWorldView._42, matWorldView._43);out_vPositionVS = mul(float4(vPositionVS, 1.0f), matProj);


This is assuming column-major matrices, for row-major you'd have to flip the mul's and use the ._11, ._21, and ._31 elements of the worldView matrix.

This topic is closed to new replies.

Advertisement