Terrain Lightmapper with shadows for Unity Indie/free

Reflection is really great!
You can access all sorts of hidden functions and variables from ordinary editor scripts.

Here I have modified the Pixel Lightmapper on the wiki to lightmap the terrain, with shadows.
I have also added anti-aliasing.

And the best thing is that it works in unity indie/free!

Take a look around here: http://www.arongranberg.com/wp-content/uploads/forumDemos/lightmapping.html

Here’s some pictures showing the difference of the built-in lightmapper and this lightmapper (sorry, no shadows from the trees yet).


where is it?

Oh, yeah, forgot to post the code.

The PixelLightMapper.cs script should be placed in the Assets/Editor folder in you project.

Attach the TerrainLightmapper script to your terrain gameObject to be able to lightmap it.

331328–11672–$pixellightmappercs_871.zip (6.16 KB)
331328–11673–$terrainlightmappercs_170.zip (723 Bytes)

If you figure out shadows from trees, you’ll have a winner. That’s the one thing that is missing from almost all the lightmapper scripts that have been posted over the years.

The screenshots look great, but i’m having a few problems getting the scripts to work. When i Generate the lightmap unity gives me a few errors in the PixelLightMapper script:

Array size must be at least width*height
UnityEngine.Texture2D:SetPixels(Int32, Int32, Int32, Int32, Color[], Int32)

on the 2 lines that say

 lightmap2.SetPixels (pixels);

and then an error about calling GUI functions in the wrong place (this could just be a knock-on error from the previous problem)

Any ideas? :slight_smile:

I Second that

Found out why it was crashing, my existing Lightmap was a 1024 and i was generating a 512 :slight_smile:

I wish the trees would work :slight_smile:

Doesn’t Beast come free with Indie this summer??

I believe so, but it lacks GI from what i’ve heard.

Wow, excellent work! I can’t believe the difference! If Beast can’t do this then I think it should be included in Unity3 :slight_smile:

I dont have and Editor folder. Do I need to create one?

Do I have to have the terrain lightmapper too - or can I just use Pixelmapper???

Its no longer needed. Unity 3.3 has global lightmapping that just works, terrain lightmapping as such no longer exists in U3. open the lightmapping from windows to see it

it bakes the shadows too.
But its pretty tricky to set up lightmapping while not overdoing the VRAM waste.

You need a very high lightmap size or a correspondingly small terrain cause it gets stretched over the surface logically.

Realtime shadows compensate for that in the form that you just don’t try to get somewhere correct lightmap replicas of the trees but something more or less diffuse and leave it to the realtime shadows to make the detailed tree shadows as you get closer

Yes you can bake static shadows. What you cant do in indie is bake GI (and thus no self-illum based texture lights either)

Can you bake Tree shadows with U3.3 (indie) as well? I would download and find out myself but I’m on quite a slow connection here.

EDIT: Ok apparently you can in 3.2… I can’t believe I didn’t just check