- Home /
Changing ambient light color during runtime with baked ambient occlusion
I'd like to be able to change the ambient light color in realtime, while using beast's baked ambient occlusion. So what I do is set my light to realtime only and the ambient light to white, which effectively creates a nice ambient occlusion bake.
The problem is that changing ambient lighting afterwards won't affect a thing - makes sense since normally you would have baked shadows / reflected light etc. in the lightmap, meaning you need to rebake when changing ambient light.
Is there any way to access the lightmap in the shader so i just can multiply the albedo with the lightmap color and ignore lightmapping during light calculation? I played around with using renderer.lightmapIndex and renderer.lightmapTilingOffset and putting the corresponding lightmap texture as a separate texture in the shader using the secondary uvs (they are the ones for lightmapping i suppose, turned on generate lightmap uvs in the importer), but the results are wrong - any ideas how to access it in the surface shader, or is there another way?
Answer by Dreamora · Jul 19, 2011 at 03:48 PM
if you explicitely implement the lightmap support and don't let the auto add of surface shaders do it, then yes you could overwrite it. But as long as you rely on auto addition no, as it will not exist for your access in the surface shader code you write.
ehm could you clarify what you mean by auto addition? or could you point me in a direction how to access the lightmap directly in a surface shader? many thanks for the answer
surface shaders, when compiled, get a host of extra coded added for the lightmap handling. In the docs you find a pragma that allows you to prevent that from happening if I recall right, which would allow you to write the whole code for lightmap handling yourself.
you can add a #pragma debug to make it generate the inbetween code for you so you can look at it