Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Terrain Lightmapper with shadows for Unity Indie/free

Discussion in 'Made With Unity' started by TowerOfBricks, Jun 23, 2010.

  1. TowerOfBricks

    TowerOfBricks

    Joined:
    Oct 20, 2007
    Posts:
    969
    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).
     

    Attached Files:

  2. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    where is it?
     
  3. TowerOfBricks

    TowerOfBricks

    Joined:
    Oct 20, 2007
    Posts:
    969
    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.
     

    Attached Files:

  4. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,040
    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.
     
  5. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    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:

    Code (csharp):
    1. Array size must be at least width*height
    2. UnityEngine.Texture2D:SetPixels(Int32, Int32, Int32, Int32, Color[], Int32)
    on the 2 lines that say
    Code (csharp):
    1.  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? :)
     
  6. sueds

    sueds

    Joined:
    Sep 18, 2009
    Posts:
    46
    I Second that
     
  7. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    Found out why it was crashing, my existing Lightmap was a 1024 and i was generating a 512 :)
     
  8. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    I wish the trees would work :)

    Doesn't Beast come free with Indie this summer??
     
  9. platonia96

    platonia96

    Joined:
    Mar 10, 2010
    Posts:
    225
    I believe so, but it lacks GI from what i've heard.
     
  10. Vert

    Vert

    Joined:
    Mar 23, 2010
    Posts:
    1,093
    Wow, excellent work! I can't believe the difference! If Beast can't do this then I think it should be included in Unity3 :)
     
  11. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    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???
     
  12. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    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
     
  13. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    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
     
  14. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,603
    Yes you can bake static shadows. What you cant do in indie is bake GI (and thus no self-illum based texture lights either)
     
  15. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    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
     
    Last edited: Apr 21, 2011
unityunity