Search Unity

How does Unity deal with trail ribbons in multiple views?

Discussion in 'General Graphics' started by Dorodo, Jun 10, 2021.

  1. Dorodo

    Dorodo

    Joined:
    Mar 8, 2015
    Posts:
    44
    I've been taking a look at building my own trail solution in order to add more features and understand the tech behind the idea.

    I took a straightforward approach on the mesh generation, creating a custom mesh renderer and aligning it based on the camera view and trail direction, which gives me a similar solution like the example below:



    The issue I'm having right now, however, is that the mesh billboard visualization is limited for a single camera, unlike the default trail renderer which renders a custom billboard for each camera looking at the mesh. Currently, I have to choose either Camera.main or SceneView.currentDrawingSceneView to make it align to the game or scene view, but not both at the same time.

    How could I implement this functionality? I thought about doing this on the shader, since the gpu would automatically deal with the different view matrices for each view, but I'd like to understand how Unity deals with it under the hood on the CPU. Does unity create a renderer for each camera?

    Thank you in advance.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Unity builds the camera-facing geometry for each camera that needs it, on the CPU. It’s done in native code, but it’s somewhat comparable to building it in Camera.OnPreRender.

    Indeed a better solution would be to do the camera facing logic in a shader, but the unity trail renderer doesn’t use dedicated shaders so we can’t put that logic onto the GPU.

    The Visual Effect Graph does its trail logic on the GPU, though, because it’s newer and smarter ;)
     
    Dorodo likes this.