Page 1 of 1

How do I connect game obj translates to shader property?

PostPosted: Tue Jul 24, 2018 6:29 am
by joedanimation
Hello, I have a shader with properties that I would like to drive by the translates of an empty game object in my scene. Is there a way to draw that data into my shader?

I'm essentially recreating this shader I made in Maya (view at 23 sec into the video):
https://vimeo.com/220420802

Any help would be much appreciated :D

Re: How do I connect game obj translates to shader property?

PostPosted: Tue Jul 24, 2018 10:32 am
by Amplify_Borba
Hello, thank you for getting in touch!

Although it's possible to achieve this through ASE, you'll require some additional scripting in order to pass property values to the shader.

We do provide some samples which involve scripting, such as the Smear and the ForceShield, that you can examine for reference. In the Smear sample, the Smear.cs script passes the current and previous position through two global variables in the shader, while in the ForceShield sample the ForceShieldImpactDetection.cs passes the Hit Position data for the shader to know where to produce the hit effect, and the Hit Time to control when the effect starts.

Also, in the shader you can get the position for the object to which the shader is being applied to through Vertex / World Position, but if you want information from other objects, you'll need to pass it as a property.

Re: How do I connect game obj translates to shader property?

PostPosted: Tue Jul 24, 2018 7:04 pm
by joedanimation
Thanks so much for the fast reply. That helped get me going in the right direction, and I was able to get it working just like I wanted.

Would it be possible to have Get/Set Global variable nodes in ASE?

Re: How do I connect game obj translates to shader property?

PostPosted: Wed Jul 25, 2018 2:09 pm
by Ricardo Teixeira
joedanimation wrote:Thanks so much for the fast reply. That helped get me going in the right direction, and I was able to get it working just like I wanted.
Would it be possible to have Get/Set Global variable nodes in ASE?


Awesome, happy to hear it!

What exactly do you have in mind?

You can set your variables to Global and have them be controlled via script; this defines a static variable that is shared between all shaders that use it, it's useful when you need to change a value globally.

Global Variables can be set to:
-Create: Property and/or global variable is created in the shader
-Fetch: No variable nor property is registered on shader, useful when you need to use global variables declared in a included cginc

Let me know, I would be happy to elaborate.