Hi,
I was trying to figure out how to add a Matrix4x4 as a node option, I see it's only global or constant. I know you can't have a property of type Matrix, but in code you can define a matrix and then in c# you can do material.SetMatrix(). Is there a way to do a node that is like that type of a variable? Like a 'scriptable matrix property' or something?
If not, is this something you will add in the future? This would be helpful for all types, Matrix, Textures, floats, etc. I know the node editor won't have any way of 'live editing' the value, but it would be helpful.
My case in particular is that I'm trying to pass a matrix in for a Texture Matrix. I can do this with separate math for translation, rotation, etc. I'd prefer to do a matrix.
Thanks!
Scriptable Variable Options
- Amplify_Borba
- Posts: 1239
- Joined: Mon Jul 24, 2017 9:50 am
Re: Scriptable Variable Options
Hello jpac, thank you for getting in touch!jpac wrote:Hi,
I was trying to figure out how to add a Matrix4x4 as a node option, I see it's only global or constant. I know you can't have a property of type Matrix, but in code you can define a matrix and then in c# you can do material.SetMatrix(). Is there a way to do a node that is like that type of a variable? Like a 'scriptable matrix property' or something?
If not, is this something you will add in the future? This would be helpful for all types, Matrix, Textures, floats, etc. I know the node editor won't have any way of 'live editing' the value, but it would be helpful.
My case in particular is that I'm trying to pass a matrix in for a Texture Matrix. I can do this with separate math for translation, rotation, etc. I'd prefer to do a matrix.
Thanks!
In shaders, matrices can only be set as global shader variables, not properties, so you may only set them within the editor or via script, since Unity does not recognize matrices as properties and, as a result, they can't be exposed in the material inspector.
The only means of achieving what you intend is via script, which will allow for live editing of the matrices via the script component in the game object, and through the following code as long as the Matrix Nodeit's set to Global in the Node Properties:
Shader.SetGlobalMatrix( "_MyMatrix", matrix );
myMaterial.SetGlobalMatrix( "_MyMatrix", matrix );
Please let us know if this information was useful, we would be happy to elaborate.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Re: Scriptable Variable Options
Hi,
You could previously mark a Matrix as a property, it looks like under the hood is was just a global variable though.
We're using Unity's MaterialPropertyBlock.SetMatrix to pass in a matrix to our materials.
You could previously mark a Matrix as a property, it looks like under the hood is was just a global variable though.
We're using Unity's MaterialPropertyBlock.SetMatrix to pass in a matrix to our materials.
- Amplify_Borba
- Posts: 1239
- Joined: Mon Jul 24, 2017 9:50 am
Re: Scriptable Variable Options
Hello, this was indeed the case, we have fixed it in a previous build as it was unintended for users to set Matrices as properties since it's not possible to use them as such.exerion wrote:Hi,
You could previously mark a Matrix as a property, it looks like under the hood is was just a global variable though.
Thank you for sharing this, it's also a valid approach!exerion wrote:We're using Unity's MaterialPropertyBlock.SetMatrix to pass in a matrix to our materials.
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!