• 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.

6 replies to this topic

### #1afraidofdark  Members

278
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

### #2Matthew Meeks  Members

218
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.

### #3afraidofdark  Members

278
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

### #4Matthew Meeks  Members

218
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.

### #5Jason Z  Members

6417
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

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?

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #6mhagain  Members

12440
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.

### #7afraidofdark  Members

278
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.