HLSL - Billboarding a mesh

Started by
13 comments, last by 8up tuotlo 10 years, 1 month ago

on my mind billboarding its placing triangle fefore screen without rotations(always to us)

just make WorldViewMatrix

Add to triangle WorldViewMatrix[3] - translation

and multiple it on projection

all

that what you doing is too much

Advertisement

Why would that accomplish not rotating it?

Because it undoes the rotation applied by the camera…


My new idea was to try making a billboarding view matrix which does the translation based on the real camera rotations, but for the rotation part of the view matrix, uses the inverse matrices.

Why don’t you just quickly make the WBP (world-billboard-projection) matrix and be done with all that ridiculous math?


XMMATRIX mBillboard;
XMMatrixInverse( &mBillboard, m_matView ); // m_matView is the inverse of another matrix, so instead of inverting it again you could just copy that matrix.
// Only keep the upper-left 3×3.
mBillboard._41 = mBillboard._42 = mBillboard._43 = 0.0f;  // Billboard matrix complete.


XMMATRIX mBillboardView = mBillboard * m_matView; // Can be used instead of the view matrix.
XMMATRIX mBillboardViewProjection = mBillboardView * m_matProj; // Can be used instead of the view-projection matrix.
Why make it so complicated?


L. Spiro

The reason it's all spread out is that it's not working yet, and this way I can experiment with changing individual elements.

I have tried everything suggested in this thread and it's still not working. Using your suggested method in the above quote, the mesh simply doesn't appear at all, the same as most other attempts..

Still the closest I've gotten is using the inverses of the rotation matrices, but the vertices translate all over the place in this case.. as shown in the video i linked.

Try to do so:

Get the transpose(float3x3(your WorldViewMatrix));

Get your mesh in local space, multiple him on this ^

And than multiple him as simple, no billboarded mesh;

and try to set culling mode off

Try to do so:

Get the transpose(float3x3(your WorldViewMatrix));

Get your mesh in local space, multiple him on this ^

And than multiple him as simple, no billboarded mesh;

and try to set culling mode off

I'm not quite following your description, sorry... but maybe this is going back to what you're referring to.. this and showing both sides of the mesh, I do get fairly close..


	// billboard?
	if( flags & PER_MESH_FLAG_BILLBOARD )
	{
		matrix worldViewMat = mul( worldMatrixInstance, viewMatrix );
		output.position = skinnedPos + float4( worldViewMat._41, worldViewMat._42, worldViewMat._43, 1.0f );
	}
	
	output.position = mul( output.position, projectionMatrix ); 

But as you can see, while the distance of the camera is accounted for fine.. the proper translation doesn't happen when the camera rotates on axes..

http://bh.polpo.org/billboard_rotate_issue.wmv

What's the reason for this?

Try to do so:

matrix worldViewMat = mul( worldMatrixInstance, viewMatrix );
output.position = mul(skinnedPos, worldViewMat );

output.position = mul(output.position, transpose(float3x3(worldViewMat)) );

or this:

matrix worldViewMat = mul( worldMatrixInstance, viewMatrix );

output.position = skinnedPos + mul(float4( worldViewMat._41, worldViewMat._42, worldViewMat._43, 1.0f ), worldViewMat );

This topic is closed to new replies.

Advertisement