Sign in to follow this  
Viik

Fast way to construct TranslationRotation matrix in shader

Recommended Posts

Viik    252
What I'm dealing with right now is a need to construct arbitrary TranslationRotation matrix in a shader during real time. Basically, I have a lot of virtual lights, each of them has a position and direction, these should be used to create virtual light's TranslationRotation matrix. During shading I need to convert position of current fragment into space of one of this virtual lights. I can't prepare TranslationRotation matrices of virtual lights upfront so I'm looking for a way how to do this in shader manually for each fragment. One of the tips I've already found is to build only Rotation matrix and instead of constructing Transaltion matrix just add traslation. So basically operation of moving fragment into virtual light space will be to multiply fragment position with lights Rotation matrix and then simply add lights Translation vector: vec_VPL_frag_pos = mul(vec_frag_world_pos, mat_VPL_Rotation) + vec_VPL_Translation I do realise that this should be simple, but just not sure how to correctly make rotation matrix from a single directional vector. Any advise? [Edited by - Viik on May 1, 2010 8:31:22 AM]

Share this post


Link to post
Share on other sites
jyk    2094
If the problem is simply how to build a rotation matrix from a direction vector, then that's fairly straightforward. It's been discussed quite a bit here on the forums, so I'd suggest searching the forum archives for terms such as 'billboard', 'aim at', 'aim at target', 'align with normal', and so on.

Share this post


Link to post
Share on other sites

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