Search Unity

How to change shader's behaviour while rendering within a reflection probe

Discussion in 'Shaders' started by Zergling103, Sep 13, 2018.

  1. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    In our game we have a custom LOD system for rendering the environment. A lowpoly mesh with a very large view distance is rendered around the camera, but fragments near the camera progressively fade out as they get closer so they may be replaced by their highpoly counterparts.

    This is appropriate for the main view, but when rendering a reflection proble we want this lowpoly version of the environment to be visible at any distance without fading. Otherwise there are visible holes in the cubemap where the skybox leaks through.

    In order to do this we'd need the material to somehow change depending on whether or not it is being rendered within a reflection probe.

    One possible way might be to use a multi compile shader feature that is enabled while rendering a reflection probe. Does unity provide such a shader preprocessor that we can leverage?

    If Unity doesn't provide one, we could set it ourselves with a callback that happens before reflection probe rendering begins and after reflection probe rendering ends. Within these callbacks we can disable and then re-enable our fading feature in the material. Do these callbacks exist anywhere?

    If neither a preprocessor nor a callback exists for reflection probes, how else may we achieve this goal?

    A particularly S***ty way to do it would be to duplicate the renderers and put them in different layers, one layer with fading and another without, then differentiate them on the camera's and reflection probes' layer masks. But this is kind of S***ty and I'm hoping we don't have to resort to this approach.

    Thanks.