Sign in to follow this  
aprilspirit89

How to orthogonalize to non-orthogonal matrix using HLSL

Recommended Posts

aprilspirit89    160

Hi,I'm just wondering whether this can be done in ps shader.I have an non-orthogonal matrix and need to orthogonalize it and using inverse-?transpose result.I turned to matlab for help,only found their instructions a bit of complicated for shaders.It might influence the performance.So is there a solution yet?Thanks for any reply:)

 

PS:Image below shows the result of using origin matrix and do lighting in world space.

[attachment=13379:Right.png]

And this is the wrong result of orthogonalize the origin matrix and then using the inverse-transpose one and do lighting in tangent space.

[attachment=13380:wrong.jpg]

And here is my Orthogonalization code.

float3x3 Orthogonalization_Schmidt(float3x3 OrginMatrix)
{
	float3 a1 = OrginMatrix[0];
	float3 a2 = OrginMatrix[1];
	float3 a3 = OrginMatrix[2];

	float3 b1 = a1;
	float3 b2 = a2 - dot(a2,b1)/dot(b1,b1)*b1;
	float3 b3 = a3 - dot(a3,b1)/dot(b1,b1)*b1 - dot(a3,b2)/dot(b2,b2)*b2;

	return float3x3(normalize(b1),normalize(b2),normalize(b3));
}

 

 

Share this post


Link to post
Share on other sites
hdxpete    512

you have the matrix you are sending to the shader right? can't you do it in C++ code and send the resulting matrix as an extra parameter to the shader?

Share this post


Link to post
Share on other sites
aprilspirit89    160

you have the matrix you are sending to the shader right? can't you do it in C++ code and send the resulting matrix as an extra parameter to the shader?

I can't.The matrix itself was generate in shader.In fact, I 'm trying to do normal mapping without precomputed tangent attribute in vertex buffer.The technique can be found in ShaderX5, Chapter2.6.It provides a non-orthogonal tangent-to-local matrix,so I'm trying to get the local-to-tangent matrix so that I can do lighting calculations in tangent space.

Edited by Tunisia hawker

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