Search Unity

Draw counts with hard shadows.

Discussion in 'General Graphics' started by Shudrum, Jan 12, 2015.

  1. Shudrum

    Shudrum

    Joined:
    Apr 3, 2011
    Posts:
    63
    Hi all !

    I know that hard shadow increase the draw counts, by I am not sure of the results I get on my trial version. With just a simple scene with a directionnal light and a cube I get :
    • 4 draw calls,
    • 2 shadow casters.
    If I duplicate this cube, I get :
    • 5 draw calls,
    • 3 batched,
    • 4 shadow casters.
    Example :

    Is it a normal behavior ? So many draw calls for two objects, and two shadow casters by object ?

    Thank you !

    edit : I'm a little bit worried because I have optimized my environnements (like the ground, trees and others) : 1 draw call, but I want to create a tower defense, so I have to get many, many units, each with some gameobjetcs ... sooooo many shadows ...
     
    Last edited: Jan 12, 2015
  2. Shudrum

    Shudrum

    Joined:
    Apr 3, 2011
    Posts:
    63
    A little bump ! Nothing really important (can't buy the pro version when the trial stop), but I really want to know :)

    Thank you !
     
  3. maxwelldoggums

    maxwelldoggums

    Joined:
    Sep 8, 2008
    Posts:
    157
    The "magic" behind the Unity lighting system is really quite clever, but it often produces seemingly unexpected results.

    In the Forward Rendering pipeline, Unity will start by rendering the brightest directional light first. In this "Base Pass", both of your objects will be rendered with the ambient scene light, and per-pixel lighting from the brightest directional light. At this point, the draw call count is up to 2.

    Next, we need to figure out where our shadows go. Unity will create a "shadow buffer", essentially a texture containing information about what parts of your scene are exposed to light. In order to do this, each of your objects needs to be rendered again into the shadow buffer. This will create two more draw-calls, so now we're up to 4.

    Last, we have to apply our shadow-maps to the cubes. This is the final pass in the typical forward rendering pipeline, and will require an additional draw call for each object receiving shadows. Now there's 6.

    Bear in mind that your skybox (even just the color blue) requires an additional draw call, so we're now at 7.

    Your example scene has draw-call batching enabled. Because your cubes share a material, some of their draw calls may be batched together, however the manual states that "Objects that receive real-time shadows can not be batched". I'm using Unity Free at the moment, so I can't test that to find out what's going on, but if you think about how the batching system works, the rest of your draw calls make sense.

    If three draw calls are batched into one, your 7 draw calls would become 5. (three would turn to 1, so 7 - 3 => 4 + 1)


    I'm not really sure which of your draw calls are being batched, but assuming the Stats window is to be believed, the math adds up. The manual doesn't yet provide an explanation for what constitutes a "Shadow Caster", so I can't speak for that portion of the render stats, but hopefully that answers some of your questions.

    Cheers!
    -Andrew

    Some sources I used:
     
    Last edited: Jan 15, 2015
  4. Shudrum

    Shudrum

    Joined:
    Apr 3, 2011
    Posts:
    63
    Hey ! Thank you for your answer.

    I haven't really understand the draw calls count, so it really help me !

    So ... I'll search some answers for the shadow casters and post the results of my search here.