Search Unity

Custom Vertex Streams TEXCOORD assignment

Discussion in 'Shaders' started by Mimimi_Flo, Oct 12, 2017.

  1. Mimimi_Flo

    Mimimi_Flo

    Joined:
    Apr 25, 2017
    Posts:
    6
    Is it somehow possible to "force" a Custom Vertex Stream to write to a specific TEXCOORD?
    Because i'm working on a custom particle shader with quite a few shader features. Depending on what options are selected in the material i need a different number of components to be set in the Custom Data tab of the particle system.

    For example:
    Option A,B and C each require an animated value. In the vertex shader i'd have samething like this:
    o.customData.xy = v.texcoord0.zw;
    o.customData.z = v.texcoord1.x;
    If A,B,C are all checked it would work as intended but if only C is selected and there is only one value animated in the Custom Data tab the C value would be written to TEXCOORD0.z and missused in the shader.

    Of course i could #ifdef the heck out of these options and cover all possible combinations but thats a bit of an overkill when it comes to shader variants. I'd prefer to handle this in the custom inspector script and tell the particle system where to write its custom data.

    Would really appreciate the insight or advice how to tackle this issue =)
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
  3. Mimimi_Flo

    Mimimi_Flo

    Joined:
    Apr 25, 2017
    Posts:
    6
    I did look at this but as far as i could see it does the "assigning" in the shader, which i'd like to avoid. So its not possible to let a Custom Data variable to write to TEXCOORD1.y for example if TEXCOORD1.x is not written to?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Ah, I misunderstood what you wanted. My understanding is there is not a way to do what you want exactly as described. But if the issue is you want the same data layout for multiple shaders, why not actually use the same data layout? There's no real harm in having custom data assigned to 0.zw 1.x all of the time.
     
  5. Mimimi_Flo

    Mimimi_Flo

    Joined:
    Apr 25, 2017
    Posts:
    6
    Np, thank you for answering =)
    Hm, isn't that some significant overhead? I mean i could use fixed float values to minimize the cost but still...
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    A fixed float vs. "skipping" a value is essentially the same thing.
     
  7. Mimimi_Flo

    Mimimi_Flo

    Joined:
    Apr 25, 2017
    Posts:
    6
    That makes sense =D Thanks for your help!