Scriptable Variable Options

Node-based Shader Editor

Scriptable Variable Options

Postby jpac » Fri Dec 29, 2017 4:00 pm

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!
jpac
 
Posts: 1
Joined: Fri Dec 29, 2017 3:43 pm

Re: Scriptable Variable Options

Postby Amplify_Borba » Fri Dec 29, 2017 5:09 pm

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.
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!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am

Re: Scriptable Variable Options

Postby exerion » Wed Feb 07, 2018 8:53 am

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.
exerion
 
Posts: 11
Joined: Tue Aug 29, 2017 5:25 am

Re: Scriptable Variable Options

Postby Amplify_Borba » Wed Feb 07, 2018 10:06 am

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.


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:We're using Unity's MaterialPropertyBlock.SetMatrix to pass in a matrix to our materials.


Thank you for sharing this, it's also a valid approach!
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!
User avatar
Amplify_Borba
 
Posts: 1239
Joined: Mon Jul 24, 2017 9:50 am


Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 71 guests