Jump to content
  • Advertisement
Sign in to follow this  
brekehan

inverse a matrix in HLSL

This topic is 3511 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Believe it or not Google didn't show me much for this. How do I inverse a 2x2 matrix in HLSL? How about a 4x4? I found the math, but don't know the HLSL code. I am trying to do this. I ended up with this:
//--------------------------------------------------------------------------------------
// Geometry Shader
//--------------------------------------------------------------------------------------

[maxvertexcount(3)]
void main(triangle GS_INPUT input[3] : SV_POSITION, inout TriangleStream<PS_INPUT> stream ) 
{
   // Calculate tangent frame
   float3 q1  = input[1].position - input[0].position;
   float3 q2  = input[2].position - input[0].position;

   float2x2 s;
   s[0] = float2(input[1].texCoord.x - input[0].texCoord.x, input[1].texCoord.y - input[0].texCoord.y);
   s[1] = float2(input[2].texCoord.x - input[0].texCoord.x, input[2].texCoord.y - input[0].texCoord.y);

// ...stumped


Share this post


Link to post
Share on other sites
Advertisement
If the matrix is orthogonal, you can just transpose it. What are you using the matrix for?

Share this post


Link to post
Share on other sites
I am on day 4 of trying to do per pixel lighting.
I made a series of posts a few days ago. The result seemed to be that

I need to calculate a tangent frame in a geometry shader.

I beleve I need the tangent frame in order to get my view direction and light direction in the pixel shader.

There was also talk of using a normal map, but I am not sure if I can do that anymore, because software exports normal maps in 3dsmax space instead of directx space.

I am just confused out of my mind, so if nothing else, I want a code snippet that can get the tangent frame in the geometry shader. Then I planned on trying to decide if I actually need it or not :P I am sure I will need it sometimes if not now.

Share this post


Link to post
Share on other sites
Ok, I've just got too many posts and too many questions.
Let's start over.

I'll make a new post going from the light equation backwards and nothing more until questions are resolved. Let's toss normal mapping and every confusing factor out the window. Maybe people can understand my problems easier when it is more clear what I need, instead of going from the vertex shader foward when they don't understand what I need.

[Edited by - brekehan on April 30, 2009 6:43:35 PM]

Share this post


Link to post
Share on other sites
I think the part your looking at is probably this:

"It is safe to assume, however, that the three vectors will at least be close to orthogonal, so using the Gram-Schmidt algorithm to orthogonalize them should not cause any unacceptable distortions. Using this process, new (still unnormalized) tangent vectors T′ and B′ are given by..."

I would think then that you could use this approach and once your matrix is orthogonal, you could then use the transpose instead of an inverse. Does anyone else agree?

Wikipidia has suedo code that looks pretty simple for doing the Gram-Schmidt algorithm.
http://en.wikipedia.org/wiki/Gram-Schmidt_process

This gamedev post discusses good ways to do a matrix inversion on a 3x3.
http://www.gamedev.net/community/forums/topic.asp?topic_id=464489

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!