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. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Not easily done at the moment. Currently accomplished via the template shader and the shader generator for the Master Node/Shader type (Unlit, Lit, etc.).
     
  2. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Yes something like that, Thanks
     
  3. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Please make it possible to access the w component of the mesh Tangent. Currently the mesh Tangent is only accessible as a Vector3 but in the mesh mesh data it is a Vector4, and I need the w component.

    Is this a known issue?
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    @wyatttt template shader? Am I missing something?

    If you mean there is a template for custom master nodes, then I would very much appreciate a link!
     
  5. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Hi I was working with Shader Graph lately and ran into this issue that I think you might be aware of:

    The preview for graph isn't updating correctly in Unity 2018.3.0f1 and SG 4.3.0-preview, changing mesh and the original render is still there.

    I am on macOS 10.13.6 with Intel Iris Graphics 6100, using Metal API.

    (This can be reproduced just by creating a new graph, but let me know if you need me to open a case with samples.)

    Screen Shot 2018-12-11 at 20.57.08.png
     
  6. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    One thing we really really miss is the ability to double-click the material and open the Shader Graph. Hope it can be added someday.
     
    MlleBun and wyattt_ like this.
  7. tweedie

    tweedie

    Joined:
    Apr 24, 2013
    Posts:
    311

    See my post here: https://forum.unity.com/threads/feedback-wanted-shader-graph.511960/page-33#post-3933781

    Our Prefix pass is a pass that gets drawn before the graph
     
    jackytop, wyattt_ and webjeff like this.
  8. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    (Updated to LWRP and SG 4.6.0-preview, issue can still be reliably reproduced in even brand new projects; BUT I tried ShaderGraph ExampleLibrary, using the same Unity and SG version, and I can't reproduce this issue. I am at a lost on why this could happen, so here is a case number 1108669)

    Screen Shot 2018-12-11 at 23.55.22.png
     
    MlleBun, P_Jong and wyattt_ like this.
  9. tweedie

    tweedie

    Joined:
    Apr 24, 2013
    Posts:
    311
    It'd be useful to get some info around the Multiply blend mode on graphs (at least in HDRP). It doesn't seem to be purely multiplicative, which is quite odd. A graph set to multiply, whose colour is supplied by a grayscale texture, will not straight-up multiply on top of whatever is behind it. There is some interplay going on with Alpha. Would appreciate some info on this
     
  10. tweedie

    tweedie

    Joined:
    Apr 24, 2013
    Posts:
    311
    Last edited: Dec 13, 2018
  11. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    @alexandral_unity Has this been fixed yet? I'm currently on 2018.3.0f1 with Shader Graph 4.6.0 and it seems it still doesn't work yet with that version.
     
    P_Jong likes this.
  12. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    do you also have it plugged into something that's part of the fragment shader ie color, emission, alpha, etc? basically anything that isn't the position port on the master node
     
  13. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    @wyatttt Yeah, my sub-graph has multiple outputs (one for color, one for emission, one for alpha, and one for position). The only one that won't connect correctly is the position. And I made sure not to use any Texture 2D nodes in my position calculations. All I have is a bunch of math nodes to calculate a special position. I am able to connect it to the position slot if I put it all directly in the main graph instead of using a sub-graph, so I would assume it isn't to do with incompatible nodes or such.
     
  14. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Ah ok. That'll be the problem. At the moment, the graph state is either in VertexStage or FragmentStage and you can't mix the two unfortunately. We plan on fixing this. Until then you will have to keep those parts of your graph separate.

    You can still read the Position from the FragmentStage but just can't assign it. So if you are doing some color/emission ops based on position that will still work. You just can't try to assign the vertex position in that same connected graph.

    That's why doing the position stuff outside your subgraph works which is what you'll have to do. Subgraphs to Position port will work as long as the shader Stages don't get muddied.

    If you had first plugged in the Position out port to the Master Node's Position In port, you wouldnt be able to assign the Color from the Subgraph to the Color of the Master node
     
  15. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    @wyatttt Ohhh ok, I understand. Thanks for the details!

    One other thing while we're talking about modifying positions... I posted this a page or so back. Could that be a bug or (more likely) I'm just doing something stupid? :p
     
  16. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Finally there is some UT interaction at the Shader Graph forum again. Unfortunately my posts about the missing W component of the Tangent Vector are systematically ignored.

    On the positive side, I do have some interaction with someone from QA about this issue via email but they are reluctant to change it, quoting "this is not the intended use". Thou shalt use Tangent for a tangent and Color for a color? Mind you, a regular shader does not have these manually imposed limitations. You can use semantics for anything you like, which makes it so powerful.

    Looking at the code, the W component is extracted from the mesh and then subsequently hard coded to 0. I just don't where this reluctance to change it comes from. It is so easy to fix and doesn't have any unwanted side effects.

    So there you have it. Something which is possible in a handwritten shader is not possible in Shader Graph.
     
    Last edited: Dec 13, 2018
    P_Jong likes this.
  17. SGFX

    SGFX

    Joined:
    Mar 25, 2014
    Posts:
    24
    quick note, a "minimize" button would be a good thing like in Amplify shader

    After the lastest update my PBR graphs are all totally broken. Upload here:
    https://hostr.co/IY7yWLonENj1


    My biggest gripe with shader graph is that it does not automatically create the external outputs after creating the (texture etc) nodes, in amplify shader or shader forge or others they are linked automatically. Also the reference name is not set despite you naming your nodes.These 2 things (mainly the missing output links) make working with shader graph far more cumbersome and slower than amplify shader and I enjoy it much less as a cause, it feels like a drag creating those.
     
    Last edited: Dec 14, 2018
  18. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    @Elecman Yeah, it would be nice if there was a dedicated forum for Shader Graph or something. I imagine it is pretty hard to stay on top of feedback here all in one thread. Wait a day and a post you made is already a page back and less likely to be seen.

    @SGFX Yeah I agree. Well, that is, if you are referring to the same thing I requested here I mean.



    I just found another issue btw... It seems when making custom nodes (using CodeFunctionNode) the "hidden" boolean in the Slot attribute is ignored if you use any binding option besides "none". Like, if you use "Binding.None,true" then the slot is properly hidden, but if you use for example "Binding.ObjectSpacePosition,true" the slot is not hidden.
    Is this intended or a bug? IMO we should be able to hide slots even if they use different bindings.
    Oh and another thing is you can't seem to specify default values AND the hidden boolean at the same time. Guess maybe another constructor overload needs to be added to the slot attribute class?
     
  19. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I was trying to convert from World to Object space (as in, mul(UNITY_MATRIX_M, position)), but the Transformation Matrix Node doesn't have dropdown values I'd expect to find according to the docs:

    https://github.com/Unity-Technologies/ScriptableRenderPipeline/wiki/Transformation-Matrix-Node

    I don't see ObjectToWorld or WorldToObject in the dropdown under 4.6. Is there a new way to convert between object and world?

    I saw some code in the GitHub repo that implies that Model = UNITY_MATRIX_M and inverse model is UNITY_MATRIX_I_M, but it doesn't seem to work as I'd expect. If I plug this into my Position output, the object isn't at the correct position.

    upload_2018-12-13_23-17-3.png
     
    Last edited: Dec 14, 2018
  20. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    What you are doing is correct. And it does work for me. Make a new scene with test object and take a screenshot to isolate the issue better.
     
  21. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Initial setup is a capsule sitting on a plane, with the capsule at (5,1,5), using default HDRP material:

    upload_2018-12-14_0-11-53.png

    Now I drop this test material on it:

    upload_2018-12-14_0-12-31.png

    Now the capsule goes off into a weird place, where it's always at the same position on the screen. It moves if I rotate the scene view, but it doesn't move if I move up/down/left/right in the scene view. Here I am just moving around in the scene view.

    World.gif

    So it really seems like what I'm getting is something that's based on the current View, not the object or world position.
     
  22. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Tested the same, couldn't reproduce it.

    Screen Shot 2018-12-14 at 13.26.35.png Screen Shot 2018-12-14 at 13.26.28.png

    You want to double-check you are indeed using Shader Graph 4.6.0 (Hopefully you are using Package Manager release and on Unity 2018.3), try not to rely on LWRP/HDRP to implicitly import it, explicitly installed Shader Graph package yourself.
     
    URocks likes this.
  23. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Pretty strange. I appreciate the time testing that out. I'm on 2018.3.0f2, with ShaderGraph 4.6, installed explicitly. I guess I'll keep playing around/reinstalling stuff... Thanks again.

    Edit: I started a brand new project, brought in HDRP and Shader Graph clean, and found this was still happening. So I submitted a bug with that test project (1109465).

    Interestingly, the following works fine. I start with Object position, transform it to World, and then transform it back to Object again. Plugging this into the position output renders the object where it belongs:

    upload_2018-12-14_10-56-34.png

    But starting with the World position, the object ends up in some very weird place on the screen:

    upload_2018-12-14_10-58-5.png

    It seems the World output of the position node isn't giving me the same value as I get multiplying Object by the Model transformation matrix. I actually went back to 2018.2 and HDRP 2 to see if it was happening there, and it was. So, this appears to have been an issue for a while now. I still have no idea why it would behave differently for me than for others.

    I uploaded a quick video showing the steps of setting up the shader, and the final effect that's happening. Skip to 1:20 to see the effect:

     
    Last edited: Dec 14, 2018
    URocks, P_Jong and noio like this.
  24. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    P_Jong, wyattt_ and MadeFromPolygons like this.
  25. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    It should work like that. Can you share an image of your graph?
     
  26. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Thanks for submitting the report. Off the top of my head, I think HDRP world positions are camera relative so you might have to add the camera position to that and then do the transformation. But that wouldn't make a whole lot of sense if it's working correctly for @bitinn

    I'll take a look at the project
     
    Last edited: Dec 15, 2018
  27. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Interesting. That does appear to fix the issue for me:

    upload_2018-12-14_14-56-20.png

    But now it raises a question of what "World" position actually means now, and how that differs from View if it takes the camera's position into account... I guess I figured World position would always represent a value in the world coordinate system.
     
    easycardgame, URocks and P_Jong like this.
  28. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    I looked at the code generation and it appears to be correct when feeding a World Position port and Inverse Model Matrix into a Multiply node and plugging that into Position. Camera relative offset is applied before the space transformation to convert it to world space via GetAbsolutePosWS(position). This either returns position if camera relative positions are disabled or returns the camera relative corrected position (actual world space) if enabled

    So you shouldn't have to account for that offset in your graph but I am still getting the same issue you are
     
  29. Hideous

    Hideous

    Joined:
    Apr 20, 2015
    Posts:
    1
    Is there any way to do terrain stuff in shader graph? Now that HDRP has support for terrains it seems like an oversight to not be able to do custom terrain shaders here. I want to do my tesselated snow, damnit! :D
     
  30. MythrilMan51

    MythrilMan51

    Joined:
    Apr 24, 2017
    Posts:
    146
    I'm late to the party... But what's up with the premultiplied blend mode? It's just Alpha Blend now.
     
    Last edited: Dec 15, 2018
  31. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    429
    Reroute node please.
     
  32. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Does shader graph support shader keywords and how to setup them?
     
  33. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,503
    I'm working on my custom node for VertExmotion
    It worked on ShaderGraph 3.0.0

    Code (CSharp):
    1.  
    2. float4 wrldPos = mul(unity_ObjectToWorld, vpos);
    3.     float w = 0;
    4.     wrldPos = VertExmotionBase(wrldPos, col, w);
    5.     vpos = mul(unity_WorldToObject, wrldPos);
    6.     return vpos;
    but in 4.6.0 I can't use the matrix directly (unity_ObjectToWorld),
    so I've changed the code to :

    Code (CSharp):
    1. float4 wrldPos = mul(UNITY_MATRIX_M, vpos);
    2.     float w = 0;
    3.     wrldPos = VertExmotionBase(wrldPos, col, w);
    4.     vpos = mul(UNITY_MATRIX_I_M, wrldPos);
    5.     return vpos;
    But it doesn't work, the world position is wrong...
    Does the matrix unity_ObjectToWorld and UNITY_MATRIX_M are different ?
    I did the test in 3.0.0, first version works, second version not.
     
  34. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Something like that is on our todo list. Thanks!
     
    TextusGames likes this.
  35. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Not at the moment
     
  36. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Can you post a vid/gif of the mesh in the Scene View as you move the camera around? And which Render Pipeline are you using?
     
  37. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,503
    It works when I use the Matrix nodes and the camera sub trick...
    It works... but that's really weird :confused:

    ShaderGraph 4.6.0 :
    Code (CSharp):
    1. //VertExmotion node 4.6.0
    2.     float w = 0;
    3.     return VertExmotionBase(vpos, col, w);



    ShaderGraph 3.0.0:

    Code (CSharp):
    1. //VertExmotion node 3.0.0
    2.     float4 wrldPos = mul(unity_ObjectToWorld, vpos);
    3.     float w = 0;
    4.     wrldPos = VertExmotionBase(wrldPos, col, w);
    5.     vpos = mul(unity_WorldToObject, wrldPos);
    6.     return vpos;
     
    Last edited: Dec 16, 2018
    URocks likes this.
  38. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,503
    I'm using HDRP 4.6.0

    Here what it looks like when it works :



    When it doesn't work, there's no animation, because it rely on world position distances.
     
    Last edited: Dec 16, 2018
    Lurking-Ninja likes this.
  39. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    I set my keyword as a boolean variable in the shader graph (not exposed).
    Then turn it on/off with Shader.SetGlobalInt("_kwd", 1/0) and it works.
     
  40. Jick87

    Jick87

    Joined:
    Oct 21, 2015
    Posts:
    124
    @wyatttt Actually now that I think about it, I think what I need is the pre-modified position (i.e. the position as it is before it is changed by nodes that are plugged into the Position slot).

    In a hand-made shader I would have a float3 in the output struct of the vertex function which I would assign the raw vertex position to first and then apply the modification to the position after that. Then in the fragment function I could access that float3 that I assigned in the vertex function in order to get the raw unmodified position.

    Here is a bit of pseudo code to hopefully help explain what I mean:
    Code (CSharp):
    1. Shader "MyShader"
    2. {
    3.     SubShader
    4.     {
    5.         Pass
    6.         {
    7.             CGPROGRAM
    8.                 #pragma vertex vert
    9.                 #pragma fragment frag
    10.  
    11.                 struct appdata_t
    12.                 {
    13.                     float4 vertex : POSITION;
    14.                 };
    15.  
    16.                 struct v2f
    17.                 {
    18.                     UNITY_POSITION(pos);
    19.                     float3 rawPos : TEXCOORD0;
    20.                 };
    21.  
    22.                 v2f vert( appdata_t v )
    23.                 {
    24.                     v2f o;
    25.  
    26.                     // Store the raw unmodified vertex position to pass to the fragment function
    27.                     o.rawPos = v.vertex.xyz;
    28.  
    29.                     // NOW modify the vertex position
    30.                     v.vertex = {SOMETHING_THAT_MODIFIES_THE_VERTEX_POSITION};
    31.                     o.pos = UnityObjectToClipPos( v.vertex );
    32.  
    33.                     return o;
    34.                 }
    35.  
    36.                 half4 frag( v2f i ) : SV_Target
    37.                 {
    38.                     i.rawPos // This is the unmodified position
    39.                     i.pos // This is the modified position
    40.  
    41.                     return half4(1,1,1,1);
    42.                 }
    43.             ENDCG
    44.         }
    45.     }
    46. }

    So basically, is there a way to do this in Shader Graph? From what I can tell there is no way to get at the "raw" position. Once you plug something into the Position slot on the master node that is the position used everywhere and you don't have a way to get the unmodified position after that. Or maybe I'm missing something?

    Thanks!
     
  41. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Hi all, I need some quick advise on these 2 things:

    - How can I rename a Shader Graph? I want to duplicate a graph but I can't rename it easily, I can copy all the nodes but it doesn't setup the material properties.

    - I have successfully recreated Simple Lit with Unlit master but realize it doesn't have a bake "Lighting" pass, since multi-pass and custom master node templates are not coming anytime soon, is my best bet just export and write the lighting pass?

    (I know these things are going to be possible in future, but I am on Unity 2018.3 and SG 4.6.0, not moving to 2019 due to project requirement, love to see any workarounds...)
     
  42. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    This has been asked before but I don't think I've seen staff reply... Will there ever be support for value arrays? It's a pretty basic and very useful part of making shaders.

    I know one of the issues is that there is no editor support for serializing the array data on materials (as far as I'm aware), but surely this could be a candidate for something to add in 2019.1? Even just having it being only ShaderGraph serialized values that you can input for testing the results in shadergraph would be fine, as most of the time with data arrays in shaders, you're setting this stuff at runtime, so only simple verification of functionality is needed in the graph.

    Doesn't renaming the file change the shader name for you? (You have to rename it in Unity Editor, not through your file explorer, so that the pipeline can catch the change and update the internal shader name)
     
    bitinn likes this.
  43. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    I'm trying to replicate what you did but without luck.

    Can you share the settings of the shader in the main node, please?
     
    Jick87 likes this.
  44. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    You can duplicate the ShaderGraph asset and rename it. The default path for it will be the file name (the path you see when assigning a shader to a material via the dropdown menu) but you can override the category like this:

    6ed5c71666b0a3ca90d6fab0f1615db9.gif
     
    P_Jong and bitinn like this.
  45. wyattt_

    wyattt_

    Unity Technologies

    Joined:
    May 9, 2018
    Posts:
    424
    Ya. For now you'll have to author that yourself and combine it with the generated code from the Shader Graph, unfortunately.
     
    P_Jong and bitinn like this.
  46. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Oh I miss this entirely, I keep double-clicking on the title hoping for an input field :)
     
  47. elettrozero

    elettrozero

    Joined:
    Jun 19, 2016
    Posts:
    216
    I managed to reproduce your result and it's brilliant! (thank you so much for this)

    My Screen Hack values were a bit different but, at this point, how can we calculate correctly those values?

    Is there a way to debug the numbers?
     
  48. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    802
    Is there any ETA for instanced properties and global properties? Shader Graph feels severely limited without that right now. I'm not able to convert any of my shaders that were using GPU Instancing and DrawMeshInstanced.
     
    Last edited: Dec 17, 2018
  49. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    - All properties are instanced by default now (wrapped in CBUFFER_START and END).
    - Set your graph property to "not exposed" and use SetGlobalFloat.

    If you run into issues, do report back with details, for me they work in SG 4.6.0-preview:

    Screen Shot 2018-12-18 at 14.28.28.png Screen Shot 2018-12-18 at 14.29.48.png Screen Shot 2018-12-18 at 14.30.18.png
     
  50. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Sorry to double-post, but if Unity team got an answer for this weird discrepancy between emission colors, please let me know. I have read the SimpleLit / LightweightFragmentBlinnPhong / SampleEmission functions back and forth, I believe I have a correct implementation of emission, but they just doesn't look the same under Bloom when [HDR] attribute is set. (and they do look the same when [HDR] is removed...)

    Screen Shot 2018-12-18 at 14.38.32.png Screen Shot 2018-12-18 at 14.39.42.png Screen Shot 2018-12-18 at 14.46.28.png Screen Shot 2018-12-18 at 14.42.56.png

    (Left Cube is SimpleLit emission, Right Cube is my implementation through SG Unlit master; 1st image is when emission tint property is set to "HDR" mode, 2nd image is when emission tint property is set to "Default" mode, that's the only difference, emission value remains the same. Note that SimpleLit shader don't use "HDR" attribute. My problem is, I don't know what to blame for this discrepancy...)

    ref: https://forum.unity.com/threads/shader-graph-hdr-color-texturepropertywithhdrcolor.599626/
     
    P_Jong likes this.
Thread Status:
Not open for further replies.