Shadow Bias

Of what possible use the Blender’s Shadow Bias is for? All it does is it gives me extra work to doodle the shadows to look correct.

Or is it just buggy version of what it should be? If you put a pencil standing on the table, the shadow always starts straight from the bottom of the pencil, but the farther away the shadow gets from the pencil, the more “blurred” it is.

wait a second, I don’t have to think, I brought the blender guide (to school) today…

oh yeah, that is not very clear.

shadow calculation overview:
a zbuffer (depth buffer) is calculated from the point of view of the shadow lamp, and for each pixel rendered on the screen it is tested wether or not, in the aformentioned zbuffer, it comes closer to the lamp (or the same distance fron), or further from the lamp than the closest shadow casting face. The pixels further from aren’t lit by the lamp (shadow), the pixels closer to, or equal with are lit by the lamp (no shadow).

I’d imagine that the bias is the tolerance for wether or not something is closer to or equal with. Setting it higher seems to make the shadows casted by one object on a nearer one less ‘dark’, and higher seems to make it more ‘dark’ where the distance from the lamp for each place doesn’t vary much. If the Bias is too low the error in the zbuffer (it is only accurate to a fixed amount) will create odd shadow effects such as banding.

I think I shall try and refine this after class.

so, I think the problem with the above is that it is in more technical terms.

Shadow Casting Spot lamp Implementation

Zbuffering
Essentially an image is rendered (at a size you specify) from the point of view of the lamp. The process of rendering this image, (and most other opengl images) are about as follows

Calculate where each vertex will appear on the screen (the lamp has it’s own screen)
For each face, calculate the pixels it uses on the screen.
For each of these pixels, store the distance they are from the screen (the zbuffer). Only do this if the distance is less (the pixel is closer) than the one that is already there.
(not for lamps) calculate the colors of the verticies, the lighting, and the textures and apply them to the previous

now each pixel (element if you wish to call it that) of the zbuffer contains the distance of the CLOSEST point on a face.

To the Image Render:
now, when each pixel is rendered, and shadows are enabled, calculations are done to see where the pixel on the screen lies on the screen of the lamp. (imagine a picture of an apple being taken, and calculating where for each point on the apple (say the stem) it appears on a picture taken from another point of view (the lamp)). If the point is closer to or equal with the corresponding point in the lamp’s zbuffer, it is being lit by that lamp. Otherwise it is not.*

The Answer to the question
Since the depth buffer is only so accurate (24 bits, or 16777216 values?), it is quite possible that a pixel will be wrongly in shadow, or wrongly in light. The Bias value will determine the tolerance between the two. I think that it will fade between being in shadow, and not, for values bias/2 distance from the value stored in the depth buffer. If the bias is set lower, it is more likely that something will be improperly lit by a shadow lamp. If it is too high, it is likely that the shadow will not be dark enough, because of the fading I mentioned.

More shadow information:
the zbuffer is not calculated 'from the pov of the lamp to 16777215 units away. It is the distance from clipStart, where 0 is the distance of clipStart, and the highest value is the value of clipEnd.** (in the lamp buttons) To reduce the error more, it is a good idea to have clipStart as high as possible (places closer will be fully lit, and not cast shadows), and clipEnd as low as possible (places further will be in shadow)

UPDATED: … and the Soft setting determines the offset of the different samples. A higer value will spread out the different shadow samples, which will make a softer shadow. It does not (as far as I can tell) make more crisp shadows when the shadow casting object, and the shadow recieving object are closer, and vice versa.

*This is for a single sample (samples: 1), but blender allows multiple samples in about a N by N grid where N is the number of samples. EIther way, the edge of each sample is always aliased. Oh, when you have multiple samples, they must all overlap to be complete shadow (not lit by the lamp). The opactiy of each shadow sample is 1 divided by the total number of shadow samples.
** I may be wrong and have reversed the direction of the zbuffer. This really only matters to the programmer, which must get the ‘closer’ ‘farther’ relationship correct.

Some times shadows can have a banding effect (Moire pattern), light and dark lines in the shadow, the ‘Bias’ is used to adjust them out, that and setting the ‘Clip Start’ and ‘Clip End’ to the shortest possible settings for your scene. The fuzzy edges, are the ‘Soft’ setting.
What settings are you using for shadows?