WHERE is the exposed Gradient node property in Shadergraph

Sorry if this isn’t the right place to ask or whatever, but it seemed appropriate to me.

Why can’t you expose the Gradient property in the Shader Graph? I am using one of the latest versions of Unity, 2020.1.0a9 and still, there is no “expose” option for the Gradient property. What is even the point of being able to convert it to the property if I can’t even change it in the editor? I understand I can change the value of it in a script using its ID, or whatever that string of numbers and letters are, but that changes the property for all the materials that use that shader, doesn’t it? I really think the devs should have completely finished the Shader Graph before releasing it because we are missing quite a few major features. There aren’t any tesselation options (from what I could find on it at least) and half the time, the scene depth and other camera-related nodes miss-function or just don’t work at all. And let’s not forget that a lot of the node arrangments that work in LWRP/URP don’t work in HDRP or vice versa. Don’t get me wrong, I think the Shader graph is a great idea, but it has been implemented half done and it is starting to get annoying. I wouldn’t mind if the unity dev team didn’t continue to try and push out new features and tools and just fixed up the ones that are dearly in need of repair.

Anyway, I’ve gotten a little off-topic. Can someone please tell me if there is any way to expose the Gradient property or at least warn me once the devs implement it.

5 Likes

I feel your pain.
We need the Gradient to be exposable, otherwise it is not really much use for a Game Developer.

Keep up the good work Unity team.

3 Likes

Properes that are exposed do have a matching datatype in the shader language.
Gradients is not a datatype in the shader language.
Unity would have to generate a large number of vector properties to represent the gradient.

6 Likes

ok. thx for the answer

1 Like

Then why is it so easily accesible in a Particle Effect?

And is it even a large number of vectors? Isn’t it just a lerp between two Vector4s?

Also - why are you then even able to convert it to a Property?

1 Like

Do you mean the particle system? That is running on the CPU side and just updating the color data via vertext colors per particle per frame… so its never trainsfering the whol gradient to the shader.

its more then just two Vector4s you can look in the compiled shader and see what unity is generating so its has a representation of the graindient in the shader.

im not saying its impossible to do it but unity decided against it for the moment.

2 Likes

How create gradient witout gradien in shader graph ?)
Very needed

It’ stupid that you cannot expose Gradients…


However, a simple 2-Color-Gradient can be achieved with Lerp, as @C4ro already said.
Then simply expose the 2 Colors:

4 Likes

Okay, I got fed up with this and went with the simplest solution I could think of without going too deep in the source code of Unity’s graphics.
I created a custom shader that takes in colours and positions (much like a gradient definition but with more objects). Then created a custom subgraph using that shader. It is basically the same thing as SampleGradient, but using colours and position directly.

Limitations, I hardcoded it to be for 7 colours. If you need more or less, just change the code and custom node.

Hope that helps.
Elliot

The shader code is the following goes in an hlsl file :

// Shader to replace the SampleGradient node

void SampleGradient_float(float inputValue,
                   float4 color1,
                   float4 color2,
                   float4 color3,
                   float4 color4,
                   float4 color5,
                   float4 color6,
                   float4 color7,
                   float location1,
                   float location2,
                   float location3,
                   float location4,
                   float location5,
                   float location6,
                   float location7,
                   out float4 outFloat)
{
    if(inputValue<location1)
    {
        outFloat = color1;
    }
    else if(inputValue<location2)
    {
        float pos = (inputValue-location1)/(location2-location1);
        outFloat = lerp(color1, color2, pos);
    }
    else if(inputValue<location3)
    {
        float pos = (inputValue-location2)/(location3-location2);
        outFloat = lerp(color2, color3, pos);
    }
    else if(inputValue<location4)
    {
        float pos = (inputValue-location3)/(location4-location3);
        outFloat = lerp(color3, color4, pos);
    }
    else if(inputValue<location5)
    {
        float pos = (inputValue-location4)/(location5-location4);
        outFloat = lerp(color4, color5, pos);
    }
    else if(inputValue<location6)
    {
        float pos = (inputValue-location5)/(location6-location5);
        outFloat = lerp(color5, color6, pos);
    }
    else if(inputValue<location7)
    {
        float pos = (inputValue-location6)/(location7-location6);
        outFloat = lerp(color6, color7, pos);
    }
    else
    {
        outFloat = color7;
    }
}

The node itself looks like this :

Here it is in action for a procedural planet where I can change the colours of the different height :

9 Likes

No news about this? Gradients are still not exposable :frowning:
I saw this Tweet about using a Gradient Asset, but i cannot find where to get it…
https://twitter.com/MatthewDean3D/status/951420363115724800

2 Likes

This was made before they crippled custom nodes by locking you into a node that has to conform to their new custom node standard. Keijiro made one as well but it’s using all deprecated custom node shader graph code now.

1 Like

Not only gradient. There are some other property that cannot be exposed. Like Matrix. I don’t know why unity need to make our life harder here

1 Like

pls add

Keep in mind there is no exact representation of a gradient node value in shader code. It is technically possible to make a translation from a UI to shader code with limited number of control points but it’s another layer that has not been implemented by Unity at the moment.

3 Likes

Seriously the lack of gradient interface defeats the purpose of having this in shader code.
You can always use something like 16x16 texture and use UV coords to get the colors for multistage gradient.

Nice avatar

1 Like

as @qoobit mentioned, it’s 100% possible, Shader Graph just does not yet have support for this. Visual Effect Graph (like Shader Graph, also essentially generates HLSL shader code and some C#) already has Gradient as an exposable type and many other types that shader graph does not support as exposable. Gradient | Visual Effect Graph | 12.0.0

Visual Effect Graph even allows for Custom Property Binders providing an API to extend and map any C# type or struct to the Visual Effect Graph compatible types: Property Binders | Visual Effect Graph | 12.0.0

This divergence is because these graph tools were largely built in isolation from eachother to get them off the ground quickly with vastly different feature scopes, so they have a lot of puzzling differences. Shader Graph’s development was broader and slower: It had many more targets / platforms to support, resulting in longer testing and development iteration, so it’s behind on a lot of nice “quality of life” features that the Visual Effect Graph team was able to develop much faster as they only needed to target HDRP and compute capable platforms during initial development. But these features are not easily transferrable to Shader Graph as they don’t share much in terms of common components and APIs. The framework to unify them to share more common ground is called Graph Tools Foundation and is currently under development. Some features may arrive sooner, but I imagine some may not come until after the Shader Graph front end is ported to use Graph Tools Foundation:

https://docs.unity3d.com/Packages/com.unity.graphtools.foundation@latest/

4 Likes

2022.1.0a12

  • Serialization: Added: Added SerializedProperty.gradientValue to the public API

Not sure if it added in UI yet

4 Likes

Honestly, this is just unacceptable on Unity’s end. If you can make it a Material Property in Shader Graph, the resulting Materials SHOULD expose the property in the Inspector. They’ve had perfectly fine inspector drawers for Gradients for years, I fail to see how it could be so hard to use this in Material Drawers.

It is shit like this that makes me consider switching engines time and time again.
The only thing keeping me from doing that is knowing that the grass is always greener until you get there.

Shadergraph markdown, has a nice gradient drawer function. It creates a 2d texture gradient that u can sample via the X tiling coordinate. Works pretty well.

Thanks so much! After a couple hours of head scratching, I was able to implement this, and, with a few modifications, got it to fit my purpose perfectly!

1 Like