Search Unity

Particles shader struggling

Discussion in 'Shaders' started by elpie89, Nov 19, 2017.

  1. elpie89

    elpie89

    Joined:
    Jun 30, 2014
    Posts:
    32
    Hello,

    I'm having some problems with a particles shader.
    I just would like to extend a quad relative to the uv mapping.
    So if the uv.v of the vertex is 0 no offset is added, if it's 1 then add an offset that I set externally.
    I actually achieved the result on a non particles mesh.
    But when I apply the shader to a particles seems like he coordinates space change.
    And actually I read that the vertex position in Particles is worldSpace.

    https://forum.unity.com/threads/particle-world-space-coords.82640/

    So how can I achieve this on particle shader?

    This is done my vertex shader.

    Code (CSharp):
    1.  
    2. float uvV = v.uv.y;
    3. //(x >= y) ? 1 : 0
    4. //step(y,x)
    5. int isFarEdge = step(0.9, uvV);
    6.  
    7. float zlerp = lerp(v.vertex.z _ZAdd, isFarEdge);
    8. v.vertex.z = zlerp ;
    9. o.vertex = UnityObjectToClipPos(v.vertex);
    10.  
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Line 7 looks wrong... you're not actually doing any math.
     
  3. elpie89

    elpie89

    Joined:
    Jun 30, 2014
    Posts:
    32
    I actually missed a comma on that line.
    But the principle is the same, if isfaredge is 1 then z.lerp is zAdd
    otherwise zlerp is always v.vertex
    Am I wrong?
     
  4. elpie89

    elpie89

    Joined:
    Jun 30, 2014
    Posts:
    32
    I just opened the scene with an old Unity version , and the result is correct.
    Something is changed in Unity 2017 but I can't understand what exactly.
     
  5. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    Yeah something is still ocasionaly wrong with HLSL. Just last week it wouldn't let me use
    Code (CSharp):
    1. asuint( floatVar )
    so I could check for NaN. Had to do some messy stuff like
    Code (CSharp):
    1. return floatVar == sqrt(-1);
    (Don't ask why NaN check was written the way it was. Error was thrown in a script that unity documentation pointed to)
     
  6. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    So, because your particles are batched, you're lerping those verts from whatever position they are at to a fixed number...

    I assumed from you saying "offset" you wanted something like:
    Code (csharp):
    1. float zlerp = lerp(v.vertex.z, v.vertex.z + _ZAdd, isFarEdge);