Search Unity

_Object2World and dynamic batching

Discussion in 'Shaders' started by kereyroper, Jun 26, 2013.

  1. kereyroper

    kereyroper

    Joined:
    Aug 16, 2012
    Posts:
    13
    I was tweaking a shader for a volumetric fog effect, and I ran into an issue with the _Object2World matrix and dynamic batching.

    At first, the shader was using a Material property for the position of the object, which did not allow for dynamic batching. I corrected this by deriving the object origin from the _Object2World matrix in the vertex shader instead, but once dynamic batching kicks in, (verified by monitoring draw calls in Statistics) the _Object2World matrix seems to be constant across different objects.

    Is this an expected side-effect of dynamic batching? I've reviewed the following documentation and found nothing related to this issue:
    http://docs.unity3d.com/Documentation/Manual/DrawCallBatching.html
    http://docs.unity3d.com/Documentation/Components/SL-BuiltinValues.html
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    It's the identity matrix when batching occurs. Not allowing us to use our own vertex transform for batching is a serious problem.
     
    SunnySunshine likes this.
  3. kereyroper

    kereyroper

    Joined:
    Aug 16, 2012
    Posts:
    13
    Thanks Jessy. Such a fundamental limitation should be documented somewhere. Any word from Unity folks if this will be corrected anytime soon?
     
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I don't think many people are affected by the limitation, but I agree.

    I've never heard mention of it. I bet that scripting this would kill a lot of the performance gained from batching, however.

    You can work around it.
     
  5. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Glad I spotted this thread. Good info!