Using lightmaps and lights at the same time?

On our levels, we’re using lightmaps (lightmap shaders) in conjunction with pixel lights. The side-effects of this are the following:

-Faces facing the light are lit like you expect.

-Faces facing AWAY from the light are darker.

-As a result of the above, lightmapped areas on lit faces are lightened up, and faces away are darkened.

Now what’s really frustrating is that pure black on the lightmap is not pure black on the lightmap - in many cases, you can’t even tell a lightmap has been applied, resulting in something that looks washed out. The darkening of faces looking away means that we don’t get the nice bounce light and ambient that’s baked into the lightmaps, which is also annoying but not as annoying as the washing out! Is there any way we can tweak the lightmapped shaders to have them apply in a different way than they currently do, so pure black remains pure black?

Hmm, have you tried culling the objects with lightmaps applied so they no longer interact with pixel lights in the scene? Another possibility might be adjusting the ambient light of the scene to insure that dark areas still contain some base (just realized it would be cool if a scene’s Ambient Light setting could also be culled per layer) . Also adjusting the Main Color attribute of the lightmapped objects could help.

Other than that I’m not sure if it’s possible to create a shader that receives lighting on front faces but ignores it on back faced polygons in relation to the light source.

Ethan

When i was using the pro demo recently, I found in order to have shadows, I had to have light. Having shadows on a lightmapped surface meant illuminating a lightmapped surface, so I was left with the conclusion that you could have lightmaps and no character shadows(using the culling Ethan suggested), or real shadows and no lightmaps, but both together was daft, and messy, yet the only way to have a character shadow fall on a lightmapped surface.

I hope I was doing it wrong, but I tried everthing I could think of at the time.

AC

Maybe that can help:

http://forum.unity3d.com/viewtopic.php?t=5115

I’ve made a shader that only adds specular highlights to the object without touching the illumination of the object that comes from the lightmap…

Is that what you need?

I think there are two ways to do this:

  1. Use lightmaps as the basis for lighting with global illumination to give you nice ambience, use one directional light with shadows on top, so you get moving shadows from the main character.

  2. Use lightmap with all lights baked in. Use projector or manually generated shadow planes to subtract shadows.
    There is a package on the wiki that has the full projector setup to render a character into a RenderTexture and subtract it from the ground surface.

Velociraptor Safari for example used manually created shadow planes they just move over the terrain.

Thanks for the replies! We CAN do it where the light doesn’t affect the level, and blob shadows could work, but then we want the option of having realtime shadows for people with systems that can handle it which would break everything. What would be GREAT is if you can have a material or object receive shadows from a light, but not the light itself.

Ok, I think a different way of looking at this is that… the lightmaps are applied BEFORE the physical light lights the geometry/texture… rather than afterwards (as would make sense to me).

I am far from an expert at understanding how the pipline works for shaders and lighting, but I would have thought that a lightmap would be applied last (like an overlay) to ensure it’s effectiveness considering it it’s designed to add light and shade based on pre-rendered images and applying them last seems (to me) the most accurate and method to use them.

Is this something that can done at a shader level? or is this going to just stay the way it is due to internal way Unity does it’s stuff?

Well, light in a real world is additive. So if there’s a light, it adds illumination. Now, if you don’t add light, then there’s no way to display it’s shadow - as nothing is added to illumination anyway!

That is, of course, the physical model. If you really want to, you could make a shader that does subtractive or multiplicative lighting, essentially darkening the image where there’s a shadow, and not changing it where there is light.

But then Joe’s suggestion is probably better - bake everything except direct illumination from primary light into the lightmap. And use primary light with shadows.

Lightmapped shaders in Unity do additive lighting (just like the rest of shaders). Lightmap contains illumination that “just is there”, and any in-game lights add on top. Now, because it’s additive, it does not matter whether lightmaps are added last or first (a+b == b+a… usually :)).

If you want to, you can write a shader that applies the lightmap after the lights. But if it were additive, it would not make any difference. If for whatever reason you want it not be additive, then you can do that of course.