Search Unity

Lerp Vertex position in Shader

Discussion in 'Shaders' started by Alcolepone, Jan 6, 2016.

  1. Alcolepone

    Alcolepone

    Joined:
    Jan 28, 2013
    Posts:
    30
    I'm trying to blend the position of the verts in my object from their object position to a arbitrary position defined within the shader, For simplicity sake i'll use 0,0,0.
    So the idea is to have all verts move to that point. I was hoping to use a simple lerp function ala

    v.vertex = lerp(v.vertex, float4(0,0,0,0),_Amount);

    but this doesn't work. nothing happens while the amount is less than 1, and the mesh disappears (i presume all verts go to 0, when the amount is above 1)

    Anyone know why you cant lerp the vert positions?
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Try just lerping the xyz... the w component should remain 1 for matrix multiplication's sake.

    Code (csharp):
    1. v.vertex.xyz = lerp(v.vertex.xyz, float3(0,0,0),_Amount);
     
  3. Alcolepone

    Alcolepone

    Joined:
    Jan 28, 2013
    Posts:
    30
    awesome, cheers, getting some result now :D