Jump to content

  • Log In with Google      Sign In   
  • Create Account


inverse transformation of the world matrix


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 afraidofdark   Members   -  Reputation: 242

Like
1Likes
Like

Posted 08 January 2013 - 03:55 PM

hello,

In a vertex shader program, I've got world transformation matrix and a point. I think that if I take inverse transformation matrix of the world matrix and multiply it by the point, I transform point from world space to object space.

 

psudecode: 

 

Matrix worldm; // I only have these two variables

float4 point;

 

Matrix invWorl = inverseTransform(worldm);

float4 objectSpacePoint = invWorld * point; // I want this

 

How can I do this in hlsl ?


www.lostchamber.com

Sponsor:

#2 Matthew Meeks   Members   -  Reputation: 210

Like
2Likes
Like

Posted 08 January 2013 - 04:00 PM

Why not pass the inverse of the world matrix as a variable to your shader?

And normally you would be multiplying the point by the world, view, and projection matrices to transform from object space to world space.  Is that what you mean to do?

 

EDIT: If you still intend to invert the matrix, it would get very slow to invert the matrix for every vertex, every frame.  The best way to go about this is to pass the preinverted matrix to the shader once.


Edited by Matthew Meeks, 08 January 2013 - 04:03 PM.


#3 afraidofdark   Members   -  Reputation: 242

Like
0Likes
Like

Posted 08 January 2013 - 04:04 PM

isn't there a way to find inverse transformation matrix of the world matrix in the hlsl shader ? passing it as a parameter is a solution but not my first choice :)


www.lostchamber.com

#4 Matthew Meeks   Members   -  Reputation: 210

Like
1Likes
Like

Posted 08 January 2013 - 04:11 PM

You could try transpose. http://msdn.microsoft.com/en-us/library/windows/desktop/bb509701(v=vs.85).aspx

This will give the inverse of any orthogonal matrix.



#5 Jason Z   Crossbones+   -  Reputation: 4905

Like
2Likes
Like

Posted 08 January 2013 - 07:46 PM

isn't there a way to find inverse transformation matrix of the world matrix in the hlsl shader ? passing it as a parameter is a solution but not my first choice smile.png

 

It is usually possible to do this in a shader, but then you will be re-calculating the inverse for every vertex that gets processed.  If you calculate it once on the CPU, and pass it as a constant parameter, then you are much better off.  In addition, you would likely only be able to calculate the inverse within a shader if you know how the transformation was created - i.e. if you know the rotation amounts, the translation amount, and the (uniform) scaling amount.  Even so, it isn't a good idea to recalculate it in the shader program!

 

You could try transpose. http://msdn.microsoft.com/en-us/library/windows/desktop/bb509701(v=vs.85).aspx

This will give the inverse of any orthogonal matrix.

 

Typically the transformation has some translation component, so that probably wouldn't work for him.  @afraidofdark: can you describe what type of transform you are using?



#6 mhagain   Crossbones+   -  Reputation: 7807

Like
1Likes
Like

Posted 08 January 2013 - 08:34 PM

I can only support the recommendations to do it once on the CPU then pass it as a constant.  Inverting a matrix can potentially be an expensive operation and is definitely not one that you want to be running once per-vertex.

 

Your local friendly matrix library should contain a routine for inverting any 4x4 matrix, look at D3DXMatrixInverse or XMMatrixInverse, for example.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 afraidofdark   Members   -  Reputation: 242

Like
0Likes
Like

Posted 09 January 2013 - 04:36 PM

I solve this by passing inverse matrix as a constant parameter. It works fine :)


www.lostchamber.com




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS