Amplifying your potential.
Page 1 of 1

Scriptable Variable Options

PostPosted: Fri Dec 29, 2017 4:00 pm
by jpac
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!

Re: Scriptable Variable Options

PostPosted: Fri Dec 29, 2017 5:09 pm
by Amplify_Borba
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!


Hello jpac, thank you for getting in touch!

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.