Reading a color from an image

Hello all,

I'm on the free version of Unity, so I'm faking my shadows with lightmaps (baking them to UV textures in Blender). While this approach is great for buildings and rooms, moving objects aren't shadowed by static objects, and I'd like some way to fake this. For instance: while I'm standing outside in sunlight, my viewmodel should be brightly illuminated, and while indoors, it should switch to a dimmer, more subtle light.

So I was wondering if this would be a plausible solution: have a image which represents which areas of my map should be brightly lit and which should be darker, then while my character walks around the map, read individual pixel values from this image at certain coordinates corresponding to my characters location, and use those values to change the lighting on the viewmodel? Is there a way to do this in Unity?

I'm going for the type of effect seen in CounterStrike 1.6, which doesn't have dynamic lighting on viewmodels, but dims weapons when you're standing in the shade.

You can use raycasting down from the character's position to get the color of the lightmap texture at that point. This (somewhat old, hopefully it still works) example makes the ball shadowed or not as you shoot it around the room and it goes in and out of the lightmap shadows.

yourTexture.GetPixel(x, y); http://unity3d.com/support/documentation/ScriptReference/Texture2D.GetPixel.html

also useful is GetPixelBilinear, which grabs a pixel using 0-1 normalized values for x and y: http://unity3d.com/support/documentation/ScriptReference/Texture2D.GetPixelBilinear.html