Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

GPU instancing and Projector

Discussion in 'General Graphics' started by sylon, Sep 30, 2017.

  1. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    242
    Hi.

    I suddenly noticed that GPU instanced objects are ignored by my Projector.
    I am rendering the object with DrawMeshInstanced.
    I checked my layers, my ignore layers, which are fine.

    The same objects, with the same shader, when placed in the scene manually, do get influenced.

    Anyone else encounter this?
     
  2. TeohRIK

    TeohRIK

    Joined:
    Jan 22, 2014
    Posts:
    89
    I have similar problem before, but for my case it was cause by the light probe I place in the level, so I set the light probes to off from the mesh filter then the GPU Instancing work again
     
  3. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    242
    Thanks for your reply.
    I have no gameobjects, but draw them with code. So i also have no MeshFilter...
    I guess that's the whole problem. Unity doesn't seem to know these objects are there, as it would if they were regular gameobjects.
    But maybe someone knows a workaround or shader trick?
     
  4. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    242
    Still haven't found a solution.
    I am using a projector for simple blob-shadows. Works fine on regular gameObjects, but when i draw the same object, with the same shader, with DrawMeshInstanced, it ignores the projector.
    But shouldn't this be handled in the shader?
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    7,253
    Unity's built in projector system does a lot of of the hard work on the CPU. It does an overlap test of the projector's frustum and the bounds of renderer components in the scene and draws any object it touches again with the projector's material and projector's UV projection matrices.

    Several of the "Graphics.Draw" functions get their extra efficiency by skipping several of Unity's internal CPU side rendering steps. That projector overlap test is going to be one of them. It's plausible they would be "enabled" as part of either the shadow casting or shadow receiving flags in the DrawMeshInstanced call. More likely you may need to handle this on your own and manually do the overlap tests and calculating the projection matrices you need then calling DrawMeshInstanced with only those meshes affected and using the projector's material.

    Alternatively you might look at doing something akin to deferred decals.
     
  6. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    242
    That clears things up a bit. Thanks!
    I've tried drawing things with shadow flags enabled, but that didn't help.
    I'll see what other solution i can cook up :)