This post has been edited countless times. It contains the newest version of this effect. The explanation for how it works is somewhere in the posts below. The package file contains both effects.
Webplayer:Unity Web Player - ShadowRangesLocal
Old version below, which is the same kind of shader, but as a full-screen image effect.
I thought, “what the hell, interesting problem”
So I made something, which I think is at least a good start. Now you can look at this, and say if it is not exactly it.
Webplayer:Unity Web Player - ShadowRanges
I included the package with a demo scene.
The smart stuff is in two new image effects placed on the camera
The first image effect simply takes the brightness of the screen, and puts that into the alpha channel
The second image effect uses the alpha channel as a key to select different textures.
You set up an array, where each entry contains
- The start and the end of the range
- A pattern texture to use for this range
- the scaling of the pattern texture
- A tint colour for the texture. This colour can be partly transparent to allow the original image to show through
Up to two ranges are allowed to overlap at a time so for example it is ok if range 1 overlaps with range 2, range 2 overlaps with range 3, etc.
If two ranges overlap, they will interpolate smoothly between the start of the second range and the end of the first range
If a range does not overlap with others, a bit of performance is saved (2 texture lookups per range instead of 3)
Start with the darkest texture first, and then add the lighter textures in the following ranges.
My textures are pretty crappy, and don’t even wrap properly, but they should demonstrate the concept.
Edit to v. 0.02; package updated with transparency effect
Edit to v. 0.03: tint colours and blending between ranges
73982–2808–$shadowranges_742.unitypackage (363 KB)