Search Unity

Resolved Leaving a "trail" from a stationary object, when the camera moves

Discussion in 'Visual Effect Graph' started by dgoyette, Dec 10, 2021.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I've been struggling to figure out a way to achieve an effect I'm working on. I know VFX graph has a nice Trails system, which leaves behind particles periodically as an object moves. However, what I'm trying to do is to create a "trail" more similar to looking at a bright light and moving your head.

    So, the object itself never moves in the world, it just moves on the screen as the player changes the look direction. So, let's say the bright object is at the center of the screen. Over the course of 1 second, the player looks 30 degrees to the right, and now the object is a few hundred pixels to the left of where it "started". Ideally, over the course of that time, I would spawn new particles at all the points between the original center of the screen and the new position.

    I just don't have a good sense of how to do this. I imagine I'd need to convert the world position to a screen position, which is simple. But then I'd need to convert the screen position back to a world position, and that's where I don't know how I'd get the correct depth/distance to spawn the particle at.

    Anyway, maybe someone knows of a clever/simple approach to this? I guess it's effectively a kind of motion blur.
     
  2. Pazzaar

    Pazzaar

    Joined:
    Jun 19, 2020
    Posts:
    15
    Haha, sorry to necro this thread, but did you ever find a method of generating this? I think the closest thing I've found has been the suggestions from this reddit thread but its not exactly what I'm looking for: How do I get this light trailing/light motion blur effect? Is there a shader for this? : Unity3D (reddit.com)

    I'm looking to replicate the spark effects that you see in Burnout 3, you can see it in this video
    (really at any point the camera moves). When the camera moves, the spark particles leave a trail. I believe the game does this so the sparks leave a trail for the player whilst the car is moving at very high speed, as the particles are inheriting the car's velocity and so with an ordinary trail renderer would leave trails going the opposite way (which yeah makes sense but imo looks less cool lol)

    I'm thinking I might need to create a custom shader that renders a particle pass to a texture, and then use a shader to draw either lines between particle points or slowly fade away the rendered texture to give a motion blur like effect.
     
  3. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    Usually the object velocity/distance is used to spawn particles, so spawn over distance should be good enough, or even just constant spawn rate. However if you need more control you can create custom spawning behaviour.
    Even when you move camera only, if you have local positions for spawning you can calculate offset in world space and still spawn particles.
     
  4. Pazzaar

    Pazzaar

    Joined:
    Jun 19, 2020
    Posts:
    15
    I've actually found this post about a custom simulation space here Custom Simulation Space for VFX Graph? - Unity Forum, and I've hooked that simulation space into my trail node and I get the effect I want (with the simulation space set to my camera)
    Unfortunately VFX graph doesn't have particle collisions like CPU particles do so I can't really use them. For the moment I'm back to using CPU particles with the simulation space set to my camera and I get an okay result.