How to orthogonalize to non-orthogonal matrix using HLSL

Started by
1 comment, last by aprilspirit89 11 years, 2 months ago

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));
}

Advertisement

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?

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.

This topic is closed to new replies.

Advertisement