Hi everyone, long time since my last tutorial.
Well I was playing around with the editor, and found a new GI combination that can work really well for open world levels.
So, normally we have a bunch of GI solutions, like VoxelGI
, ReflectionProbes
, LightmapGI
and of course SDFGI
.
this last one is what I recommended for open levels, though it has performance issues and looks bad, and is due to be replaced eventually.
In the meantime, we need a GI solution for open levels, and ReflectionProbes
, while good, still have their issues, and VoxelGI is not enough.
The problem with LightmapGI
is that, on top of being static, requires a long time to bake, a UV2, and an image. So if you have, say, a desert, a big chunk of the geometry would be used in the map, and it would still have light artifacts due to the low resolution.
Here’s where I realized that, we only need GI to add shadows to closed spaces like buildings and caves, the terrain doesn’t need it.
Well turns out you can combine static geometry with a terrain illuminated by dynamic shadows, and the results are very good looking:
What I did was use a LightmapGI, but only bake the objects that need it, like buildings, and the rest of the world continues to react to dynamic shadows!
The tutorial
We start by adding our terrain, and we set it to GI mode disabled
then we add our Environment
, DirectionalLight
and LightmapGI
.
We will set our sun to static
, and enable shadows.
In out Environment all we do is set Sky Contribution
to 0.5
, but we can leave it as it is.
what we will do is copy the Sky.
Finally on our LightmapGI, we can enable Supersampling
for better quality, and Directional
.
And we will go to the
Environment
part, set the mode
to Custom Sky
and paste our Sky:the reason for this is to guarantee a correct bake, and so we can change
Sky Contribution
in environment to any value. I found that using background resulted in incorrect lighting.
then we add our building, with UV2s already set, and we can change the Lightmap size in mesh to a higher value.
after baking, you will notice that lightprobes are only generated around the building, this is very good:
you will also notice that they cast a shadow on the terrain from to the sun.
and when we look at the lightmap, this is very small in size. we are making a very efficient use of the space and baking times are reduced as well:
I hope this helps someone!
Edit: I’ve continued testing and came into some troubles, for which I then found solutions.
Multiple buildings
The first thing I noticed was that when adding multiple buildings, the probes would be placed very far away from each other, resulting in only 1 probe per building. this was bad.
after some testing, I found a solution, which consists on creating each “building” as its own scene with a LightMapGI, and a sun for baking. after baking, the sun can be hidden or deleted.
then we instantiate the scene into our level.
Dynamic shadows
Another problem was that objects were not casting shadows on the baked surfaces. This was due to the sun being set to static
.
a solution is to change this to dynamic
(we have a single sun in our level now). this allows shadows to be cast on things like characters, items, or even trees. it is however less performant and it creates a slight edge on the baked shadows.
keep in mind that baked lightmaps do cast shadows on dynamic meshes, it’s just that these do not have shadows of their own, which we might want for interior lights, or in this case, for the sun.