Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do you pass information from a vertex shader to a surf shader?

Discussion in 'Shaders' started by RibsNGibs, Apr 13, 2017.

  1. RibsNGibs

    RibsNGibs

    Joined:
    Jun 17, 2016
    Posts:
    15
    I'm trying to modify the unity builtin grass billboard shader, with pretty good luck so far, except that I would like to pass information from the vert shader to the surf shader.

    I know how to pass information from a vert shader to a frag shader, since the return type of the vert shader is the same as the input type to the frag shader, but it looks like (at least in the WavingGrassBillboard shader I'm looking at) that the vert shader has no return type, instead relying on an inout appdata_full.

    When I try to stash information in something like texcoord1 of appdata_full, it doesn't seem like I can get at it if I add an identically named input to the input struct of the surf shader.

    e.g. if I do

    Code (csharp):
    1.  
    2.   void WavingGrassBillboardVertKjl(inout appdata_full v)
    3.   {
    4.    v.vertex = <stuff>;
    5.    v.color = <stuff>;
    6.    v.texcoord1 = <some custom data I want to pass along>;
    7.   }
    8.  
    and then try to read that in the surf shader:

    Code (csharp):
    1.  
    2.    struct Input {
    3.     float2 uv_MainTex;
    4.     fixed4 color : COLOR;
    5.     float4 texcoord1 : TEXCOORD1;
    6.    };
    7.    
    8.    void surf (Input IN, inout SurfaceOutput o) {
    9.     fixed4 color = tex2D(_MainTex, IN.uv_MainTex) * IN.color;   //<-------- works
    10.     float something = texcoord1;   //<---- doesn't seem to hold anything real (looks like it has 1,0,0,0 in it always)
    11.  
    Is there a way that I can pass info from the vert to surf shader?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    TheDeveloper10 and RibsNGibs like this.
  3. RibsNGibs

    RibsNGibs

    Joined:
    Jun 17, 2016
    Posts:
    15
    Ah ha, thanks! I had looked at that page but hadn't found the relevant section. I'm currently neck deep in the "5 chrome windows open, each with 15-20 tabs of documentation" stage of learning/writing!
     
  4. TheDeveloper10

    TheDeveloper10

    Joined:
    Feb 1, 2017
    Posts:
    4