Search Unity

Feedback Wanted: Shader Graph

Discussion in 'Graphics Experimental Previews' started by Kink3d, Jan 10, 2018.

Thread Status:
Not open for further replies.
  1. FlorentFal

    FlorentFal

    Joined:
    Nov 20, 2015
    Posts:
    34
    Hello,

    I love shader graph, here's 2 idea of improvement:
    • Expose texture {TextureName}_ST via property ref or custom node , usefull when dealing with an atlas on a Sprite Renderer MainTex.
    • Enable user to decorate its graph with comments , create area with a title and maybe a colored outline or background. Stuffs to improve readability and maintanibility of a graph.
     
    Last edited: Mar 18, 2019
  2. 479813005

    479813005

    Joined:
    Mar 18, 2015
    Posts:
    39
    hi,how to set file path, shadergraph show faild to open souce file?
     
  3. darkydoodle

    darkydoodle

    Joined:
    Oct 27, 2018
    Posts:
    45
    Dépends where your files ares. For me : Assets/Resources/shaders/CUSTOM_FUNCTION/AGShaderFunctions.hlsl
    That's an exemple.
    Careful : shader graph put a "_float" after the functions.
    So, if I put "myfunction" in shader graph, I have to put "void myfunction_float(…)" in my file.
     
    479813005 likes this.
  4. pit-travis

    pit-travis

    Joined:
    Sep 17, 2018
    Posts:
    12
    Hi,

    I wonder if there is already some standard way to deal with the 'UV size' of the object that a shader will be applied to? Imagine I do some shadery stuff on a source texture, and that texture ends up being a huge texture atlas with hundreds or thousands of subtextures in it. Which textures of it are actually rendered on an object is determined by the UV coordinates.

    If you hypothetically looked all the vertices of that object and their UV coordinates, you could compute a 'UV area' that tells you how much area in the texture that object covers. It would be cool if you could scale your shader to adapt to that UV space size that an object covers in order to make effects look consistent on differently sized objects.

    As a simple example, imagine I want to scale a noise node such that the underlying noise looks the same 'size' regardless of how much uv space of the source texture is used. I think I can use DDX/DDY for this but actually trying this out it seems pretty bothersome: E.g. I work with pixel art stuff that is only a few pixels in size in either direction, while the atlas itself can be 4k by 4k pixels. Using DDXY to change the scale of the noise I have to multiply DDXY by some ludicrous value found by trial and error (it ends up being around 10 million) to get a decent looking noise space and routing that to the noise scale. It seems it would be an awesome addition to have a node that allows me to adapt to these kinds of sizing changes automatically somehow.
     
  5. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    483
    Sample Texture2D LOD, the LOD node is what you want, from memory. I don't know why this hasn't just replaced the normal SampleT2D (at least in 4.10) but there you go.
     
  6. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    106
    I want to create a fuzzy effect. Similar to DOF but for textures and such. i.e. take a reflection and make it blurry. How would I do that in SG for LWRP?

    There doesn't seem to be a way to do it.

    It would be very helpful in order to make SG more artist friendly to think more in the way of Effects compositor software, and Photoshop. Offering ready to use, efficient, high level nodes such as Blur, Hue Shift etc.

    Artists understand the concept of layering effects and filters and colors much easier than thinking in terms of math. Making SG both tech artist and artist friendly would offer the best of both worlds, especially since good tech artists are so hard to find this would definitely offer a huge advantage.
     
    Last edited: Mar 20, 2019
  7. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    483
    Hue shift is easy enough, there's a RGB-to-HSV node, you mess with the H value, by adding, subtracting, etc, then you use the HSV-to-RGB node once you're done.

    There's also a Saturation node i believe.

    Blur is a bit different. You can sample lower-quality textures from mip maps, with the Texture2D into Sample Texture2D LOD nodes. That's a very very basic blur. Otherwise you have to sample things multiple times, and without a buffer it can get a bit messy.
     
    soleron likes this.
  8. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    524
    Hello,

    I'm testing Shader graph for the first time and I struggle trying to set an object position to all the materials that used that shader. In the sahder I have declared an exposed property, a Vector3, and then, using a script I set its value using:

    Code (CSharp):
    1.  
    2. Shader.SetGlobalVector("_myPropertyname",target.transform.position);
    3.  
    It seems that it does not work. Instead, if I place that script on a GameOject that contains the Material and get that material reference I can set the property value using :

    Code (CSharp):
    1. m_renderer.material.SetVector("_myPropertyname",target.transform.position);
    But it would means to add this script on all objects which is painfull that's why I wanted to set it "globally".

    Is that possible ?

    Thanks
     
  9. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    119
  10. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,607
    Oh your kidding me- so now we can't write simple lit shaders by hand without inheriting all the pain of the unity lighting pipeline, and we can't extend the shader graph with our own nodes either?

    I literally just wrote this last night and submitted it to the asset store, and now it's obsolete.

     
    GameDevCouple_I, ecurtz, ph_ and 2 others like this.
  11. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,292
    I need to add a #pragma to a shader made with the shader graph. Is there any way to do this?
     
  12. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,474
    Yes use custom function node and use HLSL file.
     
  13. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,292
    I do think you can have #pragmas in include files. They are not evaluated then.
     
  14. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,474
    Does the included HDRP shader + subgraph + hlsl file work for VSP nodes? I didn't get chance to test it fully in the end but it should show pragma is working for you or give an indication?
     

    Attached Files:

    • VSP.zip
      File size:
      4.3 KB
      Views:
      44
  15. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,292
    I think it would just ignore the pragma running the indirect setup code. I did not test it now but have done some tests before.

    Lennart
     
  16. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Hi, I'm trying to create a shader that puts sand or snow on top of the model, which also would put the sand on top even if the object is rotated. I'm using the world's normals, modified with the normal map so the sand goes into the cracks to produce nice effect.

    However, in Unity's shader graph, I'm running into an issue: the normal map does modify the world space normal, however, turning the object on its head does not turn where the sand is placed.
    autoTexBug4.jpg
    (See the sand is on top correctly on both, but one has the sand on top of the screws, and when turned, the sand goes under the screws)

    In a similar shader I made in Amplify Shader Graph, there is an input slot for the World Normal node, and I think it allows the software to modify the world normals with a normal map, processed correctly.
    autoTexBug2.jpg

    In Unity's shader graph, there is no input slot for the node, which probably means that when I blend the World Normal with the normal map, the world normal will adapt to the rotation of the object, but the normal map is not. Its green (vertical) channel faces the same way no matter the orientation of the object!
    autoTexBug3.jpg

    So my question/feedback is: can we correctely modify the world normals with a standard tangent-space normal map, like in Amplify Shader Graph? (And that information adapts when you turn the model)
     
  17. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    483
    Initial thoughts are it might be something to do with the normap map being in tangent space, so the normal blend isn't going to like blending TS and WS normals.

    Maybe convert the normal from WS to TS, normal blend with the normal map, convert to WS, then use that? Just thinking out loud here.

    The node you're after is a "Perturbed Normal Map" like the one Shader Forge has (Normal Dir, with a toggle for perturbed or not).
     
  18. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    I'm also in agreement that the normal map is tangent, I've searched for a way to convert the TS normal map into a WS, for the application of the sand. I still want to keep the actual texture in TS, because the model uses the normal map as usual, and the whole point of this system is to be able to place props and rotate them around, but they are still covered with sand.

    My search was not fruitful, is there a node that allows the transformation of a TS map into a WS?
     
  19. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,607
    I'm not sure familiar with Unity's shader graph, but if they expose the TBN matrix (tangent to world) then you can get the transpose of that to convert world to tangent. Shader code would be:

    Code (CSharp):
    1.  
    2. float3x3 TBN = float3x3(vertexTangent, cross(vertexTangent, vertexNormal), vertexNormal);
    3. float3 worldNormal = mul(TBN, normal);
    4. float3 tangentNormal = mul(transpose(TBN), worldNormal);
    5.  
     
  20. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    3,607
    BTW, my Stochastic Texture Sampling node for the Unity Shader Graph is out on the asset store. Hopefully Unity will have a replacement for the custom shader nodes before 2019.1 ships and I'll be able to keep it working.
     
    Horus_Sungod42 and ph_ like this.
  21. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Thanks for the answer, I'll check that out. The texture sampling node look interesting too, I'll buy it and play with it. I saw a couple of shaders on ShaderToy that break the texture's tiling, but it was not immediately compatible with the Unity Shader Graph.
     
    Last edited: Mar 27, 2019
  22. Spacew00t

    Spacew00t

    Joined:
    Mar 24, 2013
    Posts:
    19
    Is it just me or are SubGraphs super useless? I'm going to stop using them because changing them seems to break them completely, and they're not even able to be nested within each other. Changes often stop being updated in other shaders that use them, and if you change their inputs it can break other shaders in a way that seems only fixable by mucking around in the JSON. I can't believe how fragile they are.
     
  23. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    106
    Thanks a lot Jesus. But that is exactly what I didn't mean by Artist friendly.
    It is not about me and you.

    The vast majority of Artists are used to the concept of layers, and filters.

    In this case, "filters" could be a set of precomposed shader nodes (in the same way Substance offers smart components such as dirt, etc,) i.e. Blur node, or HSV Shift node, etc. to get someone started fast instead of turning someone into a technical artist, wrangling with mipmap channels and adding subtracting and multiplying HSV values and whatnot.


    Most artists don't even know how mipmaps work.
    A good example of a node like that, is the Blend/Layer node which works in the same way Photoshop does it.

    Think more of Substance Painter, instead of Substance Designer.
     
  24. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    483
    100% get what you're saying, but it's a technical issue for things like blur.

    I actually released some blur shader for Shader Forge, and even though my method was intuitive and cunning, it's not suitable to be put in the middle of a node graph.

    Think of it this way, you get a blur by making 9 copies of something, in a 3x3 grid, and averaging out the samples. That means you need 9 samples of everything you've got up to that point, and the ability to alter their UV coordinates a tiny bit.

    It's doable if you only have a single texture before that part, easy in fact. But if you've got 20 nodes with trigonometry, blending, etc, it becomes very a complex and large shader for the GPU.

    That's why, even in programs that use a blur node, like MapMagic terrain generator, or photoshop, it grabs a frozen reference of what it's about to blur, then uses that as each sample.


    As for the other filters, Hue Offset, I think, might already be a node or could become one. Don't quote me on that, but it seems like something that might exist now or at some point soon.
     
  25. DigitalSalmon

    DigitalSalmon

    Joined:
    Jul 29, 2013
    Posts:
    39
    I appriciate all the work that has gone into this system, but I really feel like it's pretty awkward seeing people stand up at GDC and talk about how ShaderGraph is allowing artists to create amazing work, when as soon as you get into anything more complex than a few nodes you spend a significant amount of time watching the shader compile.

    Create a node? Compile. Connect to a node? Compile. Accidently touch a connection? Compile. Name a new variable? Compile.

    Could allowing optional compilation please be at the very top of the list of features? The user experience for Shader Graph right now is just awful; It's so difficult to defend to a team of artists who are all asking why we have to use Shader Graph when third party tools did such a better job years ago.
     
  26. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    550
    This will be addressed in the next release of Shader Graph. It now has Async Compile, so you won't be seeing the compiling dialog anymore.
    https://github.com/Unity-Technologi...mmit/3b28421204badded8c0d14315f10c256de3345a0
    upload_2019-3-29_9-36-30.png
     
  27. DigitalSalmon

    DigitalSalmon

    Joined:
    Jul 29, 2013
    Posts:
    39
    ༼ つ ◕_◕ ༽つ
     
    Reanimate_L and Horus_Sungod42 like this.
  28. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Next release as in 2019.1?
     
    ph_ likes this.
  29. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    119
    yes
     
  30. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,145
    Well, next release of the Shader Graph package which is not directly linked to new Unity version releases, but of which the current latest version 5.10 is already 2019.1+ only and has been for a few releases.
     
    ph_ likes this.
  31. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,145
    Or just swap the order of the mul to be:
    float3 tangentNormal = mul(worldNormal, TBN);

    They generally compile to identical shaders, though the transpose can be some extra instructions if the compiler doesn't catch that it can do the above optimization.
     
    Horus_Sungod42 likes this.
  32. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Is this the kind of thing that'd be placed inside a custom node? Like a world space multiply for normal maps?
     
  33. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,145
    Place a Tangent Vector node, Bitangent Vector node, and Normal Vector node, all in world space, and pipe them into a Matrix Constructor node (in that order). Pipe the 3x3 output into a Multiply node as the B input and a world space normal into the A normal to transform it into tangent space. If you want to transform a tangent space vector into world space, swap the multiply node inputs, or switch the Matrix Constructor from Row to Column mode.
     
    Horus_Sungod42 likes this.
  34. Snorkel

    Snorkel

    Joined:
    Dec 3, 2012
    Posts:
    36
    @Kiupe
    I've found the solution! (had same problem, took quite some time to figure it out :p)
    But when you uncheck "Exposed" and make sure the reference name matches it works.

     
    Kiupe likes this.
  35. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Thanks! That seems to have done the trick! I was also trying to use the transform node, which should transform from tangent to world (tried position and direction), but I could not get it to work. The normal map works correctly, but the side of my object was coated with sand, as if the X axis was contaminated somehow.
     
  36. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Feedback/Improvement

    A useful feature I've seen in the Unreal shader editor is the ability to see the number of operations and texture samples, as a very basic way for artists to see how performant their shaders are (especially if some nodes take a lot of operations, so an artist would not be able to tell if a shader if performant solely by the number of nides present).

    If this already exists, I apologize for being a dummy. :) (And would like to know how to see the number of operations in the shadergraph/in unity proper, without cracking open the code).
     
  37. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    1,890
    This is probably the best suggestion yet. There is something similar in substance designer and it is a godsend being able to see how much ms something adds to the overall computation time.
     
    bradscott and Horus_Sungod42 like this.
  38. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Question about performance (and Feedback depending on answers)

    If I have a material with Branches (like a checkbox that if checked in, there is a Simple Noise multiplied on the albedo, for example), if the checkbox is unchecked, what happens to the shader's complexity?

    - I assume the shader still builds everything, in case the checkbox is activated by code at runtime.
    - When the checkbox is unchecked, does the part of the shader with the noise, from my example, become basically comment in code?
    - Does a texture sample in a part of the shader that is unused (because of a checkbox and a logic node) still count toward the 16 sample limit?

    Basically, I'm checking how efficient it is to make a shader with a bunch of choices with checkboxes to add optional functions, but I don't want to create a shader that's heavy when the options are not in use.

    EDIT: I've been told that shader variants remove the bits of unused code, though such variants have a memory cost. Does that seem right?
     
    Last edited: Apr 4, 2019
    bradscott likes this.
  39. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,145
    Branch is perhaps the worst named node in all of Shader Graph. The term "branch" brings with it a bunch of expectations about what it should do beyond just choosing between A and B, and the Branch node fulfills almost none of them.

    The code for a branch node is this:
    Out = lerp(False, True, Predicate);


    It's just a lerp. It's not an if, or a fast conditional ?, or a #if defined(), just a lerp. And because it takes a bool, it's slower than a lerp that takes a float (as the shader has to convert the bool back to a float value). The only thing that's true about the Branch node is if you just check the box attached and don't hook up the predicate to another node the shader compiler will (probably) not include the code from the unused branch. But that happens with any lerp with a constant 0.0 or 1.0 input, and isn't something you can change at runtime.

    The short version is, if you have a bunch of Branch nodes and they're tied to material properties, assume all of the attached nodes are running all of the time. This means:
    Nope, it's still being calculated.
    Yes, it still counts.
    There's currently no way to make a Shader Graph with a bunch of material property checkbox options efficient. Their tool currently lacks the functionality required to add useful true branches (the scariness of which is overblown).
    Nor does Shader Graph support custom variants.

    The short version is you have to make multiple Shader Graphs if you want to disable features. You could slightly reduce the overhead of this by making a Sub Graph with most of your shader's functionality and Boolean inputs that you set in the Shader Graph.
     
    Last edited: Apr 4, 2019
    Tartiflette and Horus_Sungod42 like this.
  40. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Thank you, perhaps adding true switches or branches could be useful to implement.
     
  41. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,145
    Agreed. I'd love if the Branch node was at the very least a fast conditional ? (which is used in other nodes, like all of the comparison nodes) rather than a lerp. I believe a few people have added a real if node as well, which most shader compilers will smartly convert to a fast conditional or true branch as needed. The static switch from Unreal materials would be a welcome addition, those work much like #pragma shader_feature variants in Unity, but that might require a more significant change to how they're doing Shader Graph shader generation.
     
    Horus_Sungod42 likes this.
  42. Horus_Sungod42

    Horus_Sungod42

    Joined:
    Oct 30, 2014
    Posts:
    66
    Possible Bug (weird if it is intended)

    I've briefly checked the shader graph QA database, so it might be there but I might've missed it.

    I'm in 2018.3.6

    In the Blackboard, when you create Vector (numbers) parameters for the shader, if I put a default value that's not a whole number like 0 or 1 (if I put 0.5 for example), the shader won't compile at all!

    The same applies when I make a slider parameter and I set one of the slider's limits to a non-whole number (like a slider that goes from 0 to 0.5). Won't compile, creating a pink shader.

    I can't imagine that's actually intended, that's it's integer only
    bug.jpg
     
  43. DuvE

    DuvE

    Joined:
    May 22, 2016
    Posts:
    109
  44. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,145
    Nope. Shader Graph does currently appear to have instancing enabled by default, but only for basic renderer component instancing, which is not compatible with the Shuriken particle system instancing, or the new VFX Graph instancing. Those both require hand written shaders.
     
  45. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    96
  46. james_unity988

    james_unity988

    Joined:
    Aug 10, 2018
    Posts:
    71
    I would really like instancing support in Shader Graph ASAP! Otherwise Pure ECS is basically worthless to me.
     
    thelebaron likes this.
  47. Gollunk

    Gollunk

    Joined:
    Oct 19, 2014
    Posts:
    41
    Please, does Shader Graph work with the HDRP now ? I'm hitting this type of error after importing the shader graph package :

    Library\PackageCache\com.unity.render-pipelines.high-definition@4.1.0-preview\Editor\Material\PBR\ShaderGraph\HDPBRSubShader.cs(562,34): error CS7036: There is no argument given that corresponds to the required formal parameter 'pipeline' of 'SurfaceMaterialTags.GetTags(ShaderStringBuilder, string)'

    Thanks !
     
  48. Gollunk

    Gollunk

    Joined:
    Oct 19, 2014
    Posts:
    41
    Ok, it seems that i needed to update the HDRP package. If you have the same issue you probably need to reimport both of HDRP and Shader Graph packages.
     
  49. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,474
    alexandral_unity likes this.
Thread Status:
Not open for further replies.