How to create Optimal Terrains for Light Mapping?

Hello.

I’ve recently had a thought but no real solution to solve it. I realize this must be a very beginner question but let me just throw it out here and detail the subject below. How do you create a terrain for a game, for optimal light mapping (in the free Unity version)?

I’m mainly interested in burning shadows from objects into the terrain texture, using my 3D application of course. Now, from what I understand, it’s better to work with smaller resolutions on textures to allow for less processing, faster loading and so on. But the terrain itself is a pretty important asset so it might be a good idea to use bigger resolutions. How big can you go? Because the smaller resolutions only work on small terrains, the bigger your terrain gets, the smaller UV space the shadows will occupy and the less detailed they will be. No matter how much I crank up the settings to render these shadows onto the texture, they will always occupy the same space, so they won’t look any better.

Let me provide a perfect example. I’ve quicky set up a small scene with placeholders to demonstrate. In the first picture, the terrain is too small to include two villages and some surrounding areas. In the second picture, it’s big enough to fit them all but the shadows lose their quality because they occupy less UV space now (even thought I raised the resolution a bit).

Texture Resolution
1024x1024 <<<<|>>>> 2048x2048
Terrain Scale
01x <<<<|>>>> 10x

(click the separate pictures for full sizes)

The only solution that crossed my mind is this: create the terrain in tiles. Separate, smaller models, that when they’re put together they form the final, big terrain. That way, each section can have good shadows. The problem I fear is putting these tiles together. Will there be a collision problem if they’re separate objects? Or any other issue I should be aware of? Or is there a completely different way of creating the terrain that I don’t know about?

Many thanks in advance for any helpful replies. ^^

Terrain of unity is very optimize for lightmapping, I always to use.

But can I use shadows in the free Unity? I thought they we’re a PRO-only feature. And I prefer modeling my own terrains in my 3D application of choice as opposed to using Unity’s tools for terrain editing. I know there’s a script that converts any 3D model into a Unity terrain, but do you recommend using it? Does it have any drawbacks? How does it distribute UV space? Will my custom made ground texture (grass, dirt, sand) work correctly after converting my model into this Unity terrain?

You can use baked soft shadows in Unity Free.

A cool idea someone nudged me onto with a past failed RPG project was using a 2x2 black pixel with controllable strength to ‘paint’ shadows onto terrain for some things (such as trees, structures…those nasty static things.) I’ve actually found hand-painting shadows can be a bit faster and depending on how you do it can provide a higher degree of style to your scenes.

…Of course, I also suck with 3D art! So, ‘higher degree of style’ in my case specifically means, ‘better ability to hide craptacular programmer art.’ However, if you’re more art-minded, well, I’m sure you could do something clever with that…

Easiest solution is to break it up into smaller tiles. As long as they snap together vertex to vertex, you should be fine but it’s a huge pain from a management point of view.

You will also create seams where a shadow crosses from one tile to another. Render settings, object placement and a bit of work in Photoshop can fix the seams.

Sometimes you will want to fake your shadow locations for art or design purposes. You can do a lot of fudging in Photoshop.

Use vertex lighting wherever you can to save memory. If the player can’t touch the ground in an area, you shouldn’t put a lightmap there.

I used a lot of custom scripting in 3DS Max when I did this sort of stuff. You’re going to be repeating the same tasks over and over, so you need to automate almost everything.

Its a lot of work. Make your world as small as possible.

Lightmapping resolution is always going to be a problem and AFAIK there is nothing special in Unity terrains that makes it work better ( i.e. the only way for it to be better would be to split up the terrain into tiles so each can reference a unique lightmap, but where you don’t have to have all the lightmaps for the entire world loaded at once).

In your example the problem is that you’ve increased the size of your terrain by x10, but the lightmap by x2, so obviously its going to have far less resolution. The only way to fix this is to increase the lightmap resolution or decrease the size of the terrain. However it should be noted that generally lightmap resolution is often much less than typical textures, partly because you can’t really justify making it the same density, but also as its modulated with other textures and bi-linearly filtered the low resolution (usually) isn’t as noticeable.

Of course the best solution here is to have PRO and use dynamic shadows as that would address all the issues in the most simple way possible. Although that also makes far more demands on gpu power. If you have to stick with lightmapping as you don’t own PRO or can’t afford the performance overhead of dynamic shadows then the only alternative is to tile the terrain as previously suggested.

@Fishman92:
Good thing you pointed that out to me. I selected the shadows option in the light’s attributes and it immediately told me I need Unity PRO for those so I stopped considering that option.

@Asvarduil:
While this is a great idea, I have no background in painting and I’m probably the worst painter you’ll ever see. 2D art has always been a field I enjoyed appreciating but never could advance in. It may be assumed that 3D artists have good knowledge of more traditional art styles, and I know a ton of great people who do, but alas I don’t fit in with that crowd. Even if I could paint, I’d essentially be painting those shadows on the same texture resolution which would yield, more or less, the same results. It’s not a problem of how the 3D software renders the shadows, I can play with the settings to make them even realistic, but more of a UV space/texture size issue. Just like noisecrime pointed out in the post above this, it relates directly to the size of the texture. And I think even 2048x2048 is already a lot for a single lightmap texture, let alone higher resolutions.

@RyanB:
Smaller tiles sounds like the way to go. Not sure why there would be seams between tiles. I could render a huge lightmap with shadows (for the entire terrain) and break that into the amount of terrain tiles I have, to be used as separate textures. But if I’d have to render smaller tile-sized lightmaps then sure, fixing would be needed. By vertex lighting, do you mean bake the light/shadow info in vertex colors? If so, that’s a brilliant idea, although potentially problematic in low-poly models. I’m planning to build this “world” as light as I can (mid-resolution textures, low poly models, and hopefully some code optimizations).

@noisecrime:
I did scale the terrain more than the texture resolution, that’s a valid point, but I’m afraid of loading higher textures than 2048x2048 in a scene like this considering it will be filled with more complex models, animations and all those that will bring it alive. High-res texture mods for games like Skyrim and Oblivion have 2048x2048 texture sizes, I cannot and will not achieve the complexity of a game like that. Just hoping there’s a way to cut back on the loading times when transitioning between tiny areas. Tiles seem to be the best idea so far though. The graphics that I’m hoping to achieve will end up looking like this (much less complex though, I’m tackling one thing at a time):

I’m really curious how do they do it professionally in the big game titles. :face_with_spiral_eyes:

If you can create a script to render a huge map and then cut it into pieces, go for it. But, rendering one huge map is a huge hassle.

One issue is how to UV unwrap a massive terrain. You might have tiling textures for dirt/grass/sand etc. plus some blending. Now, you need a new UV map channel that is unwrapped for the lightmap. You will have a lot of areas that are height transitions, junctions and intersections that aren’t going to unwrap easily.

And one more thing: if you have one big massive terrain, you can’t divide the world up into manageable scene file sizes. Loading up one massive file is a nightmare. You need your data in reasonable sized chunks.

There are a lot of other issues that will pop up: model quality, lightmap distortion vs maximum UV space utilization, optimizing individual map sizes, compressing lightmaps, shaders, dynamic range of texture maps, and on and on.

But yeah, bake as much lighting into the vertex colours as you can. Saves massive amounts of time and memory. Go with an art direction that allows you to get away with smooth gradients instead of sharp detail.

A real consideration is how much your time is worth. $1500 for Unity Pro and real-time shadows. If you can get a job paying $10 an hour, you can buy it in a month. $20 an hour…two weeks. Its going to take you at least a month just to write the scripts to do this work efficiently.

I would happily pay $1500 to never lightmap/shadowmap an open world game again.