Enabling shadows ads more tris/vertices in the rendering

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?

1 Like

You need to render the polygons of the meshes that is added to the shadowmap.

sorry, I don’t get it, do I need to change something or what you say is why the tris are added

This is why you get extra polygons. It is normal.

1 Like

is there a workaround it or some kind of prebake that I could do in order to spare those triangles?
Directional light is realtime

No. with the realtime light you can not.

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…

In order to create the shadow mask you need to render the triangles again from the “direction” of the light.

2 Likes

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:

3 Likes

thanks to both of you for the info! So there is no avoiding the extra triangles added…

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.

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

1 Like

hi, have you drop the triangle count from 45k to 28k with shadow at last ?

no, you can not avoid using shadows and having those extra triangles. they come hand by hand