Search Unity

Question Is it possible to render DOTS incompatible shaders using hybrid renderer?

Discussion in 'Graphics for ECS' started by Krooq, Jan 10, 2022.

  1. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    196
    Ok so I know it sounds like a dumb question but hear me out...

    I often buy assets with custom shaders and most of the time they don't work with DOTS because the author doesn't want to deal with updating them to keep up with DOTS changes (fair).
    I really wish in these cases that the normal URP pipeline can just take over and render the shader normally.
    This method works if the shader lives on a GameObject, so clearly it's not out of the realm of possibility, i.e. DOTS and normal GameObject stuff can coexist fine.

    So is it possible to do this on an Entity?
     
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    This is not currently possible. The Hybrid Renderer requires the DOTS_INSTANCING_ON shader keyword to be supported by the shader, as the entire rendering pipeline of Hybrid Renderer relies on it.

    If this is a large problem, then depending on the shader, it could be simple to add support yourself:
    • You need a subshader with #pragma target 4.5
    • The subshader needs to use #pragma multi_compile _ DOTS_INSTANCING_ON
    • The shader needs to specify DOTS instanced property definitions for any properties that will be read from entity data, e.g. transform matrices. This is typically done by #including some shared headers.
    • You can look at the example shader in the Hybrid Renderer package for a simple example, or URP/Lit and URP/Unlit for a full fledged example.
     
    Krooq likes this.
  3. Krooq

    Krooq

    Joined:
    Jan 30, 2013
    Posts:
    196
    Last edited: Jan 11, 2022