Search Unity

Question The shadow of a tree

Discussion in 'General Graphics' started by jo82, Jan 14, 2024.

  1. jo82

    jo82

    Joined:
    Dec 3, 2015
    Posts:
    47
    I have limited knowledge on all the wonderful things Unity does in the background for me. This includes how it creates and project shadows.

    Let's say I have a 3d tree and I want it to project it's shadow on the ground.

    I personally see that 3d model as a complex object that Unity has to figure out before creating/projecting it's shadow. This includes all the overlapping parts such as leaves and branches.

    Is it normal to believe that using another 3d model (flat shaped) that grossly imitates the tree's 3d general shape to project a fake shadow instead of the tree itself would have a difference performance wise since the flat shape is in my opinion much simpler to calculate than a tree and it's overlapping objects?

    See picture for what I mean. The white flat surface would be aligned to the center of the tree and marked as cast shadow only of course.

    Maybe It's not worth it and I'm complicating things too much and I should only mark cast shadow on the tree model itself.

    What's your take on that?

    From the tests that I have done so far I don't see much of a difference between the two but before going further I thought asking experts their opinion would be a good idea.
     

    Attached Files:

  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,631
    Sure. It's called a shadow proxy object.

    You can take your simplified mesh and, on the mesh renderer component, set the "cast shadows" setting to "shadows only". On the complicated mesh, just set it to "off".
     
    DevDunk and jo82 like this.
  3. jo82

    jo82

    Joined:
    Dec 3, 2015
    Posts:
    47
    Thanks I didn't know the term.
     
  4. Sluggy

    Sluggy

    Joined:
    Nov 27, 2012
    Posts:
    982
    To go into a bit more detail about your question, the way most game engines since, I dunno, 2003 and on render shadows is to use something called shadowmapping. This includes Unity. Effectively, for each light the scene is rendered from the point of view from that light and the results are written to a special texture called a depthmap. This can later be sampled for the normal camera rendering to determine if a particular area is in shadow or not relative to each light.

    The overall takeaway from this is that geometric complexity really isn't going to have an impact on the performance of your shadows. Yes, technically in order to render that shadowmap you need to transform all of the verts of the mesh but vertcount/polycount simply isn't an issue on any modern non-VR, non-mobile platform these days. The quality of the shadowmap and the fillrate it requires is going to be the big factor.
     
  5. jo82

    jo82

    Joined:
    Dec 3, 2015
    Posts:
    47
    Thanks for an in depth explanation. Gives me a better idea.

    Much appreciated.