- Home /
Swapping terrain lightmaps does not affect grass?
Hi all,
For our project we have a section where the sky will darken to create a moody atmosphere towards the end of our level. I've got the skybox fading between two textures and i'm controlling the intensity of our directional light, the sun. However we still had the problem of the terrain being unaffected.
Digging around i've discovered how to duplicate the terrain's lightmap and i've recalculated a darker version with the sunlight intensity lower. At the moment i've got a simple script which swaps between the two lightmaps when you press a key, but the grass decoration remains at it's current illumination. It does change to match each individual lightmap when I use them individually, but not when swapping between them.
One of the comments in this post suggests that grass and detail objects should be affected by the terrain lightmap, and even that in a realtime scenario multiple lightmaps could be used, but it's not working for me. Is it a Unity Pro only feature? We only have access to Indie at the moment.
I've also read in the docs about the 'Lightmap Factor' setting in the texture dialogue for the grass to control how much it is affected by the lightmap - what should this be set to? It's currently set at 1 but I don't know what the range is. 100 bleaches the grass to yellow.
I've heard that using multiple lightmaps in this scenario is not very efficient (although it will only be a brief transition, not a full day/night cycle) and I still have this script for blending lightmaps to try. But i'm getting the impression that it's not possible to have grass details affected by the terrain lightmap? I've read about exporting the terrain to a modelling package to lightmap the trees etc (that will be my next little adventure), but I don't see a solution with the grass.
It may be that I'll have to settle for tweaking the grass tint and/or ambient light levels to make the change less noticeable although the contrast is meant to be quite stark. I'll have to have another go when I get home later today.
If anyone has any ideas in the meantime, I would be very, very grateful.
@straydogstrut, remember to upvote good answers, not just checkmark one. :)
Answer by jonas-echterhoff · Mar 04, 2010 at 09:36 AM
Light maps should affect terrain details (grass, etc). However, once these details are generated, they are cached, so changing the light map will not immediately updated the detail shading.
Try calling the undocumented Terrain.Flush() method after changing the light map, to force it to regenerate the details.
Thanks Jonas, i'll try that tonight. If it's undocumented, is there any chance of it stopping working in the future? I only ask because this is a coursework project so it kinda has to work=S
Yes, there is a certain risk, as we do not guarantee that any undocumented functions will keep working the same way in future releases. This is only relevant for web content, though, as standalone games will always run with the runtime they have been published with.
Well that method works except it's slow and it doesn't export correctly to the webplayer as you mentioned. I suppose our only other option is to use detail meshes for the grass but i'll have to have a word with the $$anonymous$$m since this will increase the poly count.
Thank you very much for your help though, I really appreciate it.