Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Enabling shadows ads more tris/vertices in the rendering

Discussion in 'General Graphics' started by martinasenovdev, Dec 3, 2017.

  1. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    I recently noticed that enabling shadows (hard shadows only, low resolution, close fit, no cascades) increases the triangles/vertices count by 60-70%. Initially I have like 25k triangles on stage and upon enabling shadows they become 39k. Same applies to vertices, they increase too.

    The only lights that are there is 1 directional light and also global illumination with gradient.

    This is viewed in the "Stats" popup in the Unity editor.

    As far as I know, shadows should create a shadow map that is applied onto the meshes that receive the shadows. I have no clue why it increases the tris/vertices count.

    Is there something that I miss?
     
    AntonioModer likes this.
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    You need to render the polygons of the meshes that is added to the shadowmap.
     
  3. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    sorry, I don't get it, do I need to change something or what you say is why the tris are added
     
  4. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    This is why you get extra polygons. It is normal.
     
    theANMATOR2b likes this.
  5. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    is there a workaround it or some kind of prebake that I could do in order to spare those triangles?
    Directional light is realtime
     
  6. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    No. with the realtime light you can not.
     
  7. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    so that means from what you say that those triangles are first rendered normally and then on a second pass they are rendered with the shadow on them. Why is this redundant operation or the engine doesn't have a way to know...
     
  8. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    In order to create the shadow mask you need to render the triangles again from the "direction" of the light.
     
    dghsiba and martinasenovdev like this.
  9. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    So you first render the object from the perspective of the light to determine the distance. (Or multiple times if you have cascaded shadow maps.) Then you use this information during the normal rendering.

    Some of the basics:
    https://en.wikipedia.org/wiki/Shadow_mapping
     
  10. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    thanks to both of you for the info! So there is no avoiding the extra triangles added....
     
  11. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Why are you asking about avoiding the extra triangles?
    Is it possible you are experiencing some lag or frame drops?

    If yes - consider optimizing in a different areas of the game. Increasing 20-30% polygon/vertices is very minimal with respect to your example provided, so there are some other areas where the game can be optimized to increase performance - if in fact this is why you are asking about extra triangles.
     
  12. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    Thanks for your advice! I already optimized in lots of places, but given the triangles rise from 28k to 45k just due to shadows is concerning to me. That's why I posted the thread. Cheers
     
    theANMATOR2b likes this.
  13. wangunity

    wangunity

    Joined:
    Sep 25, 2013
    Posts:
    12
    hi, have you drop the triangle count from 45k to 28k with shadow at last ?
     
  14. martinasenovdev

    martinasenovdev

    Joined:
    May 7, 2017
    Posts:
    67
    no, you can not avoid using shadows and having those extra triangles. they come hand by hand