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 can I get the vertex position in the last frame in shader?

Discussion in 'Shaders' started by Dragon_Baby, Sep 13, 2020.

  1. Dragon_Baby

    Dragon_Baby

    Joined:
    Apr 19, 2020
    Posts:
    7
    Is there any approaches to get the vertex data in the last frame?The only thing I know is that I can use the C# script to get the mesh's vertices,and I can pass some information to the property in shader with C# script.But I just want to get the vertex position in current frame and the last frame at the same time, and then I can calculate the vertex's direction of movement.I'd appreciate if there're some other ways to achieve it.
     
  2. Namey5

    Namey5

    Joined:
    Jul 5, 2013
    Posts:
    188
    You would need to pass in the object's transformation matrices from the previous frame (specifically the model matrix, i.e. transform.localToWorldMatrix). From there, you just need to multiply the object space vertex coords by both matrices and subtract them to get world space motion.
     
    JSmithIR and Dragon_Baby like this.
  3. Dragon_Baby

    Dragon_Baby

    Joined:
    Apr 19, 2020
    Posts:
    7
    Thanks a lot! I'll try that.
     
  4. zhanglan23

    zhanglan23

    Joined:
    Nov 11, 2021
    Posts:
    1
    How did you do? May I See your code?