Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback Wanted: Shader Graph

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

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

    darkydoodle

    Joined:
    Oct 27, 2018
    Posts:
    64
    This is not working with vector arrays. I have groups of "trees" in different tiles, each tree can have a different wind coefficient. I'm passing a vector array in a materialpropertyblock and with the legacy engine, I wrote a custom shader that accessed this array for each instance id (like explained in the documentation). With Shader Graph, this is currently not possible.
     
    fherbst likes this.
  2. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    @bitinn @darkydoodle Exactly. DrawMeshInstanced requires an array of instanced properties, and this doesn't work at all right now. Setting "simple" properties seems to not work though, which makes all but the most basic procedural instancing code impossible to implement...
     
    DongJooByun likes this.
  3. intouchmatt

    intouchmatt

    Joined:
    Dec 4, 2018
    Posts:
    16
    Are there any 3d noise functions? I want to make a displacement vertex shader, but the 2d UV based noise functions are problematic because the noise value for adjacent might be wildly different if they cross a UV seam (for instance with a sphere mesh). I would prefer to have a noise function that takes a float3 (along with some parameters like scale, octaves, etc) and returns a float that I can use to displace a vertex.
     
  4. intouchmatt

    intouchmatt

    Joined:
    Dec 4, 2018
    Posts:
    16
    I found a shader over at Shader Toy that looks like it might do what I want: https://www.shadertoy.com/view/XtBGDG
    I created a CodeFunctionNode, but I am not sure how to make nodes that are more that one liners in the HLSL. This code (neverminding that its GLSL) defines and uses multiple functions.

    Can you give me any pointers on converting this example to a CodeFunctionNode?
     
  5. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,976
    From looking at the functions in that, you would not make the entire function (lets use "simplex3d" as a example) into a single node. You would instead remake it within the graph. Most of what it is doing is multiplying or adding etc values and you already have nodes for that. You also have nodes for noise generation btw
     
  6. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    From the sound of it you just want a repeating/tileable 2d noise? You might find this example worth looking at:

    https://github.com/keijiro/NoiseTools
    https://github.com/keijiro/NoiseShader

    I wouldn't recommend generate 3d noise on the fly, it's quite slow if you want any large dimensions. It would be better to generate them offline into a 3d texture and mutate them with 2d noise.

    (Depends on what you are doing I guess, for real-time volumetric effects, I haven't seen AAA games generate 3d texture on the fly.)
     
    Last edited: Dec 19, 2018
    jackytop likes this.
  7. intouchmatt

    intouchmatt

    Joined:
    Dec 4, 2018
    Posts:
    16
    @GameDevCouple_I "You also have nodes for noise generation btw" which nodes are you talking about? I have only found Noise Sine Wave, Gradient Noise, and Simple noise, none of which appear to make continuous noise through a 3d space, which I need to prevent tearing in the displaced model.

    @bitinn I don't want it for volumetric effects, I want it for mesh displacement where I would only be displacing something like two thousands vertices. Still the 3d texture approach you mentioned sounds interesting. Can you elaborate on the notion? How can I generate a 3d texture in c# and make it available to the shader graph?
     
    Last edited: Dec 19, 2018
  8. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    If you just want to displace vertices on a sphere that blend across uv seems, there are many examples out there.

    Look at my posted examples about generating tileable noise and figure out how to displace 2 flat planes without showing seams between them, then move onto your sphere.

    TIP: sphere also map to a surface when you uv it, you don't need 3d noise (and you want normal vectors.)

    Screen Shot 2018-12-20 at 0.00.01.png

    EDIT: by the way, for specifics about how to displace a sphere mesh, this thread isn't the best place to ask. the Shader forum have people that can help you better.
     
    Last edited: Dec 19, 2018
  9. intouchmatt

    intouchmatt

    Joined:
    Dec 4, 2018
    Posts:
    16
    Thanks for your help @bitinn, but I am not looking for 2d solutions, that involve UV's even if the texture is tileable. I only mentioned the sphere as an example. I am looking for a general purpose solution that works in arbitrary 3d space and with Shader Graph. Near as I can tell that requires a node that actually calculates in true 3 dimensions. Precalculating it as @GameDevCouple_I suggested seems like a reasonable solution, if a method can be found to make it work with Shader Graph. However, I would prefer a solution that is as self contained as possible so that its easy to work with.
     
    MadeFromPolygons likes this.
  10. MythrilMan51

    MythrilMan51

    Joined:
    Apr 24, 2017
    Posts:
    146
    upload_2018-12-19_13-11-2.png
    I ask before, but I might need to ask again... Anybody know what's going on with Premultiply? It's acting more like alpha blend than it should.
     
  11. kustaa53

    kustaa53

    Joined:
    Dec 20, 2018
    Posts:
    1
    Hi,
    Using wacom pen which obviously doesnt have scroll wheel is there a way to zoom in/out except the "F" key?

    Thank you!
    Kustaa
     
    hippocoder likes this.
  12. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,976
    You could always make that graph, then save it as a subgraph so you effectively end up with a single node :)
     
  13. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    It would be super nice to have a way to insert shader stripping keyword, so we can simulate those boolean toggles from built-in shaders, my custom graph now has quite a few branches which are always ran (unecessarily).

    (ASE also have this though I am not saying SG need to match its feature 1-to-1)
     
  14. intouchmatt

    intouchmatt

    Joined:
    Dec 4, 2018
    Posts:
    16
    That is a good idea, I tried it. The sub graph thing is pretty cool. I wish we could use sub graphs inside of sub graphs so that we could have the equivalent of utility functions.

    Unfortunately, while building up the full function in the graph, Unity operations progressively got slower. It now takes most operations like adding or connecting a node around 30 seconds to complete, even in the shader that uses the sub graph, but doesnt actually display it. Generally speaking it is unusable.

    While building it I did really wish I had the ability to group things into boxes, and leave comments, similar to what you can do in the Vfx graph

    It would also be nifty to take big chunks of HLSL shaders like the 3d noise stuff here and wrap them in a node instead of having to recreate them to line by line, which I can now say is rather time consuming. This is especially appealing given the huge number of existing shaders that are available online.
     

    Attached Files:

    Last edited: Dec 20, 2018
  15. Jesus

    Jesus

    Joined:
    Jul 12, 2010
    Posts:
    502
    You can create nodes - though they belong in the package manager folder with the other nodes.
     
  16. intouchmatt

    intouchmatt

    Joined:
    Dec 4, 2018
    Posts:
    16
    I looked at the nodes in the package manager and all the ones I came across were CodeFunctioNode's. Is there a way to define functions in the shader with them? Near as I can tell everything must be wrapped in a { ... } closure and sub functions aren't allowed.
     
  17. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Depends on your SG version, for 4.6.0, yes; for 5.x I believe they are changing the API so it's currently not working.

    Here is a custom node example:

    https://gist.github.com/bitinn/72922a0a69f6d723d94e94f2fc21230e

    Here is a document on it:

    https://bitinn.github.io/ScriptableRenderPipeline/ShaderGraph/Custom-Nodes-With-CodeFunctionNode/
     
  18. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    976
    I think a custom expression node akin to the one in amplify shader editor would be convenient. That and a way to include custom cginc files (whose functions you'd be able to call from the custom expression node).
     
    Last edited: Dec 21, 2018
  19. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    You can make a custom function node that makes use of multi-line HLSL but it all has to be within the scope of a function.

    We have node groups in the works. Not sure when those will land in a Shader Graph package
     
  20. Grimreaper358

    Grimreaper358

    Joined:
    Apr 8, 2013
    Posts:
    789
    Will this be something like functions? If not, what would be the difference between node groups and sub-graphs?
     
  21. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961

    One thing might be interesting: allow users to include an external hlsl script globally, so they can reuse any helper functions in it with CodeFunctionNode. This could greatly reduce the lines of code in custom code and perhaps make serialization faster?
     
    Last edited: Dec 22, 2018
    wyattt_ likes this.
  22. dan-kostin

    dan-kostin

    Joined:
    Oct 19, 2018
    Posts:
    22
    4.6.0 preview
    1. Problem
    upload_2018-12-25_13-5-42.png

    My expectations:
    upload_2018-12-25_13-4-10.png


    2. Also I have problems here:
    upload_2018-12-25_13-8-9.png
    If I change X in Divide 10, 50, 500, 1000 and save it has unpredictable behaviour. 10 can be equal 1000 or 500 on the same image.

    3. Please add the drag hand to Shader Graph window, because draging screen on a laptop touchpad with zooming is awful.
    upload_2018-12-25_13-12-17.png
     
  23. dan-kostin

    dan-kostin

    Joined:
    Oct 19, 2018
    Posts:
    22
    4. Set Cube in Shader Preview window and rotate, it render sphere also.
    upload_2018-12-25_14-6-22.png
     
    P_Jong likes this.
  24. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    A strange question: I am seeing some of my more complex shader graph shaders aren't being included in the actual build. They work fine in Editor, and are referenced by static game object's static material in the scene, so it seems unlikely they are stripped. And Simpler shader graph shader appear to work fine.

    I even tried exporting the shader graph to a plain shader, and it still got ignored by build, without causing any warning.

    The editor vs result:

    Screen Shot 2018-12-26 at 19.37.35.png Screen Shot 2018-12-26 at 19.37.52.png

    Anyone faced this before?
     
  25. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    I manage to reproduce this bug even with a simple unlit shader. Not sure intended or not, but if you name your shader with a string containing "Debug", like "Test-Debug", somehow Unity straight up ignore the shader from the build.

    Yeah, crazy (white cube is built-in unlit, blue cube is unlit master node; in build, they either fallback or simply doesn't render):

    Screen Shot 2018-12-26 at 23.51.00.png Screen Shot 2018-12-26 at 23.50.52.png

    Not sure if this is limited to macOS 10.14 and Unity 2018.3.0f2, but I opened a case (1112983)
     
    Last edited: Dec 27, 2018
    P_Jong likes this.
  26. sugarrush2009

    sugarrush2009

    Joined:
    Dec 25, 2018
    Posts:
    2
    Hello i was wondering if someone could help me with the graph editor. I'm trying to texture my large terrain using rgb to display each terrain texture. I've tried what i could but i can't seen to get textures to display properly. it looks like the alignment is off and the textures are too stretched out. i would like to be able to control how the texture is tiled and make sure the textures are aligned properly or scaled properly. i am using lwrp
     

    Attached Files:

  27. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,694
    all my unlit (hdrp)graphs fail to compile. they do work in the editor tho
     
  28. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    P_Jong likes this.
  29. Mister-D

    Mister-D

    Joined:
    Dec 6, 2011
    Posts:
    1,694
  30. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    It appears that the Object Space Position value that you get in Shader Graph when having instancing enabled is incorrect. Is there a way to get the correct value? It seems the value you get is actually the position of whichever object Unity picks as the "first" object among all the instances. Is it possible to get the "actual" position? Like, the position you would get if instancing was turned off?
     
  31. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    AFAIK, this could be a bug? (reported previously)

    But I am not able to reproduce on macOS with Metal API. See my example:

    Screen Shot 2018-12-28 at 11.44.13.png Screen Shot 2018-12-28 at 11.44.03.png Screen Shot 2018-12-28 at 11.48.02.png

    Code (CSharp):
    1.             SurfaceDescription PopulateSurfaceData(SurfaceDescriptionInputs IN)
    2.             {
    3.                 SurfaceDescription surface = (SurfaceDescription)0;
    4.                 float3 _Remap_AA4CA392_Out;
    5.                 Unity_Remap_float3(IN.WorldSpacePosition, float2 (-10,10), float2 (0,1), _Remap_AA4CA392_Out);
    6.                 float _Split_D81C45E6_R = _Remap_AA4CA392_Out[0];
    7.                 float _Split_D81C45E6_G = _Remap_AA4CA392_Out[1];
    8.                 float _Split_D81C45E6_B = _Remap_AA4CA392_Out[2];
    9.                 float _Split_D81C45E6_A = 0;
    10.                 float3 _Vector3_E82E8830_Out = float3(_Split_D81C45E6_R,_Split_D81C45E6_G,_Split_D81C45E6_B);
    11.                 surface.Color = _Vector3_E82E8830_Out;
    12.                 surface.Alpha = 1;
    13.                 surface.AlphaClipThreshold = 0;
    14.                 return surface;
    15.             }
    Also note that WorldSpacePosition is from vertex shader, not an instanced property.

    Code (CSharp):
    1.             CBUFFER_START(UnityPerMaterial)
    2.             CBUFFER_END

    Code (CSharp):
    1.                 // Vertex transformations performed by graph
    2.                 float3 WorldSpacePosition = mul(UNITY_MATRIX_M,v.vertex).xyz;
     
    Last edited: Dec 28, 2018
  32. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    In my case I'm doing things inside a custom node using Binding.ObjectSpacePosition but as far as I can tell that also ultimately points to IN.ObjectSpacePosition, so there shouldn't be a difference I would think...

    Oh and thanks for the link. I didn't notice that post before. Not sure how I missed it, I have another post shortly after it. :p

    I'll do some more testing to see if I still have the issue with a reduced case.
     
  33. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    Ok, so even modifying my custom node code to directly output the object space position (and not modifying it or doing anything else) and then plugging that into the base color on my master node shows the issue. So, it has to be an issue with the position that the custom node is given.

    Also, one thing I noticed in your example is that you were using world space position. In my code I'm using object space position. Perhaps that is why you were not seeing the issue? Also, you have to move the objects around to really see the issue in my case.
     
    Last edited: Dec 28, 2018
  34. P_Jong

    P_Jong

    Joined:
    Jun 14, 2017
    Posts:
    58
    They were not exactly the same. bitinn used a Lit Master node , and dgoyette used a PBR master node. Other than that the graphs look the same but give different results. I think the problem is with the PBR master node. Which seems to be fixed by subtracting the camera position as you suggested. Can't wait to try this out myself.
     
  35. P_Jong

    P_Jong

    Joined:
    Jun 14, 2017
    Posts:
    58
    Hi dan-kostin. I did get it to look like what you were expecting, but only when x on the multiply is close to 2.68.

    upload_2018-12-28_21-34-8.png


    As for #4 I've seen it reported by a few others here. And I also get it as well. I don't know if a ticket is opened on it, but I hope so. And even better if there is a fix.
     

    Attached Files:

  36. spartawhy117

    spartawhy117

    Joined:
    Apr 25, 2018
    Posts:
    1
    according to my using experience :1,4 seems that does not support, and 6 maybe can achieve by customer node. others i haven't known. so do you have answers now?
     
  37. FelinaLain

    FelinaLain

    Joined:
    Aug 21, 2013
    Posts:
    14
    Anyone knows how to get polybrush to work with shader graph?
    Because for me, if I use shader graph, polybrush material are pink-bugged, so I can't use them
    And if I try use render-pipeline materials in polybrush I can't paint with them
     
  38. dan-kostin

    dan-kostin

    Joined:
    Oct 19, 2018
    Posts:
    22
    Thank you, it works with 3.14 like in UE4 with 0.5(1.57). It is Sine certainly, Cosine works the same way and is different.
     
    P_Jong likes this.
  39. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    It's just a way of organizing your graph. Group and label one collection of nodes as your "Albedo Calculations" and another group as "Vertex Offsets" or something like that. Then you can drag the Group without selecting all the nodes and move the nodes within the group to change the layout

    Subgraphs are more like functions
     
  40. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    No promises, but this is something we are considering for the API
     
    bitinn likes this.
  41. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Are you using LWRP or HDRP? If LWRP, try disabling dynamic batching. There is a separate option on the LWRP Asset to enable/disable that feature in addition to the one that is in Graphics Settings (Not entirely sure but this option might just be for the built-in renderer)
     
    bitinn likes this.
  42. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    @wyatttt I'm using HDRP. I don't see any option for that in the HDRP asset. Maybe I'm just missing it though? I also tried changing the option in the Graphics Settings and that didn't seem to make any difference.
     
  43. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Thanks for pointing that difference out. I will take another look at the code generation
     
  44. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    what does it look like in the scene view when you feed the object position to the albedo port?
     
  45. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    One thing I would really like to see happen:

    Support template shader like Shader Forge and Amplify Shader Editor.

    I have tried multiple times to come up with a custom master node by duplicating unlit master code, but are unable to get pass the tightly coupled structure (using 4.6.0), the farthest I got is to create a shader graph file with my custom master node, but I couldn't open it due to the graph still want to call default LightWeightUnlitSubShader when OnOpenAsset is invoked (instead of my custom LightWeightUnlitSubShader).

    To be honest I much prefer Shader Graph just offer me some templating language that allow me a write dumb template shader instead of understanding elegant C# code.

    I know Unity team is working on major rewrite for 5.x (which matches Unity 2019+), but for 4.x and Unity 2018 users, is it possible to get any solution for master node? template language? CodeFunctionNode?

    My shader graphs are mostly based on unlit master node, which is different from LWRP Unlit shader:

    - Unlit Graph has these passes: StandardUnlit, ShadowCaster, DepthOnly
    - LWRP Unlit has these passes: Unlit, DepthOnly, Meta

    So besides exporting to plain shader and rewrite it myself, I can either get shadow or lightmap baking, but never both.

    This is the only reason I goes back to ASE to some of my shaders, because I can create a custom template shader and change this once and for all...

    I know there are many goals Shader Graph team want to meet, but I think not having a custom master node is a real blocker for me.

    Thx and Regards.
     
    MadeFromPolygons likes this.
  46. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    @wyatttt I made a minimal test project here. I'm not sure if it shows the issue exactly, but I think it does. With the instancing checkbox enabled on the material, if you move the cubes around one at a time you can see the colors on the other cubes change as well. If you then disable the instancing checkbox and move cubes again you can see that the other cubes don't change. This behavior (with instancing disabled) is what I would expect even with instancing enabled. I would think the object-space position should be correct per-object either way. Or am I assuming incorrectly?
     
  47. imphenzia

    imphenzia

    Joined:
    Jun 28, 2011
    Posts:
    413
    Now, 3 days away from it being a year since original post, I must admit that I have postponed diving into ShaderGraph because when I looked at it during Unite Berlin '18 the preview was still lacking a lot of basic features. Now I am revisiting the topic and do I understand it correctly that there is still no lighting nodes or graph-way to implement any lighting?

    The ShaderGraph material preview is showing a lit sphere of my material, but in my scene the directional light has no effect. I saw a previous post in this thread that someone mentioned using a Vector3 input as direction light, and another one mentioned copying code from the included lit shaders as a workaround until a node exists - I suppose this is still the case?

    I also tried to search for ShaderGraph roadmap, it would be useful to know when preview features aim to go from preview to general availability.
     
    noio likes this.
  48. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,976
    I am also finding the lack of a master node is making it difficult to test this for most things. Not everything can be made with the default master node, and its annoying that you cannot create a custom shader easily via coding currently.
     
  49. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Not to put more pressure on Shader Graph team, but I recently did some performance test with Shader Graph and Amplify Shader Editor on Metal API with macOS, and found these stats.

    Setup: rendering to 2560x1600 but with render scale 0.5, so effectively 720p

    Screen Shot 2019-01-07 at 22.37.18.png

    The cakes are textured using the same set of 4 textures (Albedo, Normal, Emission and a packed map with Metallic/Smoothness/Occlusion), and each pair of cakes use the same material with GPU instancing enabled.

    Results are following (collected via Xcode and Intel GPA):

    Shader Name: No. of Instructions (vertex and fragment), Time Elapsed on GPU

    - LWRP Lit Shader: vertex 138, fragment 316, 128μs
    - ASE PBR (default template): vertex 136, fragment 337, 122μs
    - ASE PBR (custom template): vertex 153, fragment 319, 127μs
    - SG Lit Master: vertex 169, fragment 342, 260μs

    At first I thought the difference in performance will eventually normalized when the shader become more complex, but it didn't. SG shader are consistently 100+μs slower, and since they appear to take the same resources in Xcode (same textures etc.), the only reason I could come up with is that SG always use up to TEXCOORD8 (and do it for ShadowCaster and DepthOnly pass too, where they aren't needed), while any other solution use up to TEXCOORD7 (due to packing view direction into other TEXCOORD's w channel, and use much less in other passes).

    I think the argument for a custom shader template is strong, if we want to gain a comparable performance to LWRP Lit shader and other existing solutions.
     
  50. Muffty

    Muffty

    Joined:
    Nov 4, 2016
    Posts:
    8
Thread Status:
Not open for further replies.