Search Unity

Feedback Please allow ref as inout in CodeFunctionNode

Discussion in 'Shader Graph' started by Thaina, Apr 6, 2019.

  1. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    Code (CSharp):
    1.     public CustomGlobeUV()
    2.     {
    3.         name = "CustomGlobeUV";
    4.     }
    5.  
    6.     protected override MethodInfo GetFunctionToConvert()
    7.     {
    8.         return GetType().GetMethod(nameof(GenUV),BindingFlags.Static | BindingFlags.NonPublic);
    9.     }
    10.  
    11.     static string GenUV(
    12.         [Slot(0,Binding.ObjectSpacePosition,ShaderStageCapability.Fragment)] DynamicDimensionVector position,
    13.         [Slot(3,Binding.None,0,0,1,0,0)] Vector2 offset,
    14.         [Slot(4,Binding.MeshUV0)] ref Vector2 UV)
    15.     {
    Will generated

    Code (CSharp):
    1.  
    2.     void GenUV_float(float3 position, float2 offset, float2 UV)
    3.  
    But I expect
    Code (CSharp):
    1.  
    2.     void GenUV_float(float3 position, float2 offset, inout float2 UV)
    3.  
     
    ph_ likes this.
  2. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    232
    Thaina likes this.
  3. Kink3d

    Kink3d

    Joined:
    Nov 16, 2015
    Posts:
    45
    Hi, thanks for the suggestion.

    As ph_ notes, we have removed this API as of 2019.1. I will bring up this suggestion with the team to discuss implementing it via the Custom Function node but, honestly, I doubt we would implement this.

    How would you imagine this works on a one-way data flow graph system? If you do this you are writing to the value of the input port. In your case you want to specifically modify the base UVs but I dont think this is ever something we would want to allow as it results in complex, order-dependent graphs (if that value is used elsewhere, how we do decide which nodes are calculated first?).

    What I see as a more valid way of doing the same thing is us implementing custom interpolators (which are already on our backlog), then you could calculate custom UVs and use them in fragment without complex two-way graph logic.
     
  4. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    @Kink3d I don't think it has any problem in graph. Just has a input point with the same name as output point

    If there was a problem about order dependent, we could transpile the graph to just copy variable before put in ref if there is dependency of that value (and if that value have no dependency then it shouldn't need to be copied)

    I don't have specific require for transforming the same variable. I just want to have compact code and reduce variable slot