### World Space Displacement with MaterialX?

1399   3   1
Member
22 posts
Joined: 6月 2013
Offline
Hi everyone.
There is a neat feature of the Principaled Shader which lets you input a vector displacement and switch it to world space.
I was wondering if the same can be done with MaterialX.

MtlX displacement input can be a float (so it displaces along the normal), or a vector, in which case it looks like it does the displacement in tangent space.
Now, my simple understanding of the relationship is that if we multiply the tangent space vector with a matrix formed by the tangent, bitangent and normal we get the world-space vector. So, we have the world-space direction and all the above mentioned vectors as handy MtlX nodes (tangent, bitangent, normal), I thought it was as simple as making a matrix out of them, inverting the matrix (also an existing node) and then multiplying the world space vector with the resulting matrix.

And here is where I got stuck. I can't seem to find a way to make a matrix out of these 3 vectors, nor do I know if there is a node to multiply a vector with a 3x3 matrix (there is a mtlxtransformmatrix node but it doesn't seem to work).

So, is there a way to do this at the moment? Is my logic wrong or should the math work fine?
Edited by alexandru_p - 2023年1月29日 19:06:57
Member
7836 posts
Joined: 9月 2011
Offline
alexandru_p
And here is where I got stuck. I can't seem to find a way to make a matrix out of these 3 vectors, nor do I know if there is a node to multiply a vector with a 3x3 matrix (there is a mtlxtransformmatrix node but it doesn't seem to work).

there's the crux. doesn't seem possible to do anything with matrices yet, since there's no way to make them.

In my opinion, the displacement output node would be changed to take world space displacement, and a node added in for converting to/from tangent space. That would make things much simpler and not require doing matrix math for something so basic. I would still like to see proper matrix nodes in mtlx for the more advanced setups though.
Member
31 posts
Joined: 6月 2010
Offline
alexandru_p
Hi everyone.
There is a neat feature of the Principaled Shader which lets you input a vector displacement and switch it to world space.
I was wondering if the same can be done with MaterialX.

MtlX displacement input can be a float (so it displaces along the normal), or a vector, in which case it looks like it does the displacement in tangent space.
Now, my simple understanding of the relationship is that if we multiply the tangent space vector with a matrix formed by the tangent, bitangent and normal we get the world-space vector. So, we have the world-space direction and all the above mentioned vectors as handy MtlX nodes (tangent, bitangent, normal), I thought it was as simple as making a matrix out of them, inverting the matrix (also an existing node) and then multiplying the world space vector with the resulting matrix.

And here is where I got stuck. I can't seem to find a way to make a matrix out of these 3 vectors, nor do I know if there is a node to multiply a vector with a 3x3 matrix (there is a mtlxtransformmatrix node but it doesn't seem to work).

So, is there a way to do this at the moment? Is my logic wrong or should the math work fine?

I've asked them the same. Got answer it is possible to change space in which noise is generated. Unfortunately that doesn't solve it.We realized that materialx is not mature enough, and lacks many features vex shaders have.
Member
54 posts
Joined: 3月 2015
Offline
This was a bit of a tough one for me, but I think I figure out how to do world space displacement in MaterialX without using anything outside of the spec.

Trick is to use dot products instead of matrix.

Take your world space vector (Wind Direction in my case) and then do a dot with tangent, bitangent and normal and combine into a vector. This seems to work well so far.

Hope this helps someone else because this too me way too long to figure out! Thanks!

Attachments:
unnamed.png (52.3 KB)