Search Unity

Feedback Three things I wish Shader Graph would support

Discussion in 'General Graphics' started by PhilSA, Sep 12, 2019.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    (edit: meant to post this in Shader Graph forum. Can we move it?)

    ________________________________________________________

    Hi,
    So I've been using ShaderGraph a lot lately, and it's shaping up into a fantastic tool, but there are still things I wish it supported:

    1. Make it possible to create SG shaders for Graphics.DrawProcedural()
    DrawProcedural() is by very far the most powerful rendering technique for performance. More powerful than any batching or instancing, for objects that don't move. The problem is that it is a pain to use, because it requires you to write your own shaders completely with a custom vertex shader. Would it be possible to have a "ProceduralPBR" MasterNode in shadergraph? This node would basically generate a shader where users are responsible for setting buffers of positions, normals, tangents, uvs, etc... Basically, the generated shader would be exactly like standard PBR, except its vertex shader would look like this:
    Code (CSharp):
    1. StructuredBuffer<float3> vOSPositions;
    2. StructuredBuffer<float3> vOSNormals;
    3. StructuredBuffer<float3> vOSTangents;
    4. StructuredBuffer<float2> vUV1;
    5. StructuredBuffer<float2> vUV2;
    6. StructuredBuffer<float2> vUV3;
    7. StructuredBuffer<float2> vUV4;
    8. StructuredBuffer<float3> vColor;
    9.  
    10.  
    11. // Vertex input attributes
    12. struct Attributes
    13. {
    14.     uint vertexID : SV_VertexID;
    15.     UNITY_VERTEX_INPUT_INSTANCE_ID
    16. };
    17.  
    18. // Custom vertex shader
    19. PackedVaryingsType CustomVert(Attributes input)
    20. {
    21.     uint t_idx = input.vertexID / 3;           // Triangle index
    22.     uint v_idx = input.vertexID - t_idx * 3;   // Vertex index
    23.  
    24.     // Imitate a common vertex input.
    25.     AttributesMesh am;
    26.     am.positionOS = vOSPositions[v_idx];
    27. #ifdef ATTRIBUTES_NEED_NORMAL
    28.     am.normalOS = vOSNormals[v_idx];
    29. #endif
    30. #ifdef ATTRIBUTES_NEED_TANGENT
    31.     am.tangentOS = vOSTangents[v_idx];
    32. #endif
    33. #ifdef ATTRIBUTES_NEED_TEXCOORD0
    34.     am.uv0 = vUV1[v_idx];
    35. #endif
    36. #ifdef ATTRIBUTES_NEED_TEXCOORD1
    37.     am.uv1 = vUV2[v_idx];
    38. #endif
    39. #ifdef ATTRIBUTES_NEED_TEXCOORD2
    40.     am.uv2 = vUV3[v_idx];
    41. #endif
    42. #ifdef ATTRIBUTES_NEED_TEXCOORD3
    43.     am.uv3 = vUV4[v_idx];
    44. #endif
    45. #ifdef ATTRIBUTES_NEED_COLOR
    46.     am.color = vColor[v_idx];
    47. #endif
    48.     UNITY_TRANSFER_INSTANCE_ID(input, am);
    49.  
    50.     // Throw it into the default vertex pipeline.
    51.     VaryingsType varyingsType;
    52.     varyingsType.vmesh = VertMesh(am);
    53.     return PackVaryingsType(varyingsType);
    54. }

    Here is an example of it in action: this is 50 milion tris being rendered at only 6ms per frame. This would make the most powerful grass/vegetation system ever, if only SG had a "ProceduralPBR" MasterNode.
    https://i.gyazo.com/994460687b3077df31f8cee3a8d2ca37.mp4

    Here is a simple project demonstrating how to use it for HDRP: https://github.com/keijiro/NoiseBall4

    -----

    2. Make it possible to declare and use StructuredBuffers in SG shaders
    Right now, SG doesn't allow you to make shaders that communicate efficiently with compute shaders. All we'd need to solve this is the ability to declare and use StructuredBuffers in SG

    With this, we could make highly efficient dynamic ocean systems, snow tracks shaders, etc, etc....

    -----

    3. Tesselation

    I assume this is coming eventually. Any new on that?

    ------


    I really don't mind if any of these things would necessitate a CustomFunction node with code in it. That would be absolutely fine, as long as we at least have an option to author shaders in shadergraph that can support all this cool stuff
     
    Last edited: Sep 12, 2019
    bb8_1, Pedrocabelo04, ESLewie and 8 others like this.