Search Unity

Question Is shader graph support compute buffer ?

Discussion in 'Shader Graph' started by Gaoyu2020, Oct 1, 2019.

  1. Gaoyu2020

    Gaoyu2020

    Joined:
    Aug 25, 2014
    Posts:
    19
    I want to use shader graph,but some data come from compute buffer. I often use instance render, custom compute buffer.
    Thanks in advance.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Not yet, no.

    No support for defining structure buffers. No support for getting SV_InstanceID, SV_VertexID, or SV_PrimitveID. No support for really any of the things needed for instancing.

    You can still use Shader Graph, but only for setting up the initial shader as you want it in the broad strokes. Then you have to hand modify the generated shader code.
     
    GameDeveloper1111 likes this.
  3. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    You can define and use structured buffer using a function node.
    Unfortunately it's not correctly bound when SRP batcher is used but this might be a workaround while waiting for official support.
     
    randomdragon and LooperVFX like this.
  4. mephistonight

    mephistonight

    Joined:
    Dec 14, 2016
    Posts:
    75
    I don't suppose you'd mind sharing an example of this would you? I'm having trouble wrapping my head around the Custom Function node.
     
  5. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
  6. mephistonight

    mephistonight

    Joined:
    Dec 14, 2016
    Posts:
    75
    Yeah. I found that blog post quite useful. I was trying to use the Custom Function node for something similar to what is being discussed here:

    https://forum.unity.com/threads/problem-with-drawmeshinstance-with-hdrp-or-lwrp.646723/

    But even when using file mode, trying to use:

    Code (CSharp):
    1.  
    2. #define unity_ObjectToWorld unity_ObjectToWorld
    3. #define unity_WorldToObject unity_WorldToObject
    4.  
    In a custom function just doesn't seem to work. I've yet to figure out a way to get drawmeshinstancedindirect working in the HDRP via shadergraph.
     
    JoRouss likes this.
  7. oobartez

    oobartez

    Joined:
    Oct 12, 2016
    Posts:
    167
  8. oobartez

    oobartez

    Joined:
    Oct 12, 2016
    Posts:
    167
  9. chantey

    chantey

    Joined:
    Mar 5, 2017
    Posts:
    49
    The Custom Function Node page of the documentation does a good job of explaining how to include your own uniform variables. Not sure about vertex id etc, but the old chestnut of baking ids into UV2 etc could work for some use cases.


     
  10. randomdragon

    randomdragon

    Joined:
    Feb 11, 2020
    Posts:
    31
    An example with structure buffer:
    Code (hlsl):
    1. #ifndef VOXEL_MESH_INFO
    2. #define VOXEL_MESH_INFO
    3. StructuredBuffer<float> volume;
    4.  
    5. void MyFunctionA_float(float i,out float v)
    6. {
    7.     v=volume[(int)i];
    8. }
    9. #endif
    The custom function setting:
    upload_2022-2-15_22-29-47.png
     
  11. fenderrex

    fenderrex

    Joined:
    Sep 9, 2015
    Posts:
    4
    wow all that work maybe I backed the wrong game engine 4 years still not added
     
    funnymanwin likes this.
  12. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    353
    Can it be written with string type of custom function?
     
    nasos_333 likes this.
  13. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,355
    Hi, what would be the input in the i from the Graph side ?

    Thanks
     
  14. KYL3R

    KYL3R

    Joined:
    Nov 16, 2012
    Posts:
    135
    that would be the instanceID