Shadows

From ActiveWiki
Revision as of 06:48, 20 May 2007 by Legion (talk | contribs) (+cat Category: Terminology and Category: Avatars)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Shadows

A shadow is a region of darkness where light is blocked. It occupies all of the space behind an opaque object with light in front of it. The cross section (geometry)of a shadow is a two-dimensional silhouette, or reverse projection of the object blocking the light.
(Source Wikipedia[1])


Preamble

Since build 972 of the browser avatar shadows can be enabled in the Option Settings Performance tab. As individual real-time shadow rendering can be a CPU expensive (look at Avatar Shadows for details), this feature is disabled by default.

Avatar Shadows

  • Only a single rendering camera is needed to create these projection images for the shadows. You can imagine a queue of Avatars waiting at the photographer to get a photo taken.
  • The whole process is optimized for speed. For example, the photographer only takes a photo of the Avatar when the Avatar moves, else Step 1 to Step 3 are skipped and the shadow geometry is just rendered from the cached geometry buffer.
  • Another optimization method for speed is applied, that skips rendering shadows outside the browser's main camera frustum, means outside the visible view shown in the 3D window.
  • Note, that because of these optimization applied, shadows are not redrawn automatically after switching from 1st person view to 3rd person view until the avatar moves again.
  • A restriction is applied to shadows, the amount of triangles used to generate the shadow geometry. It is limited to 600 triangles for each shadow. That's quite a lot, though it can happen the underlaying geometry is too complex and the shadow renderer stops when reaching the limit. This may result in incomplete shadows, or no visible shadow at all.
  • Shadows are not thrown onto the Avatar itself, as well the current implementation for shadows in the browser does not throw shadows onto other Avatars either.
  • A slight z-buffering artifact might occur, while the rendered shadow is close above the underlaying surface, in particular when T&L is switched off and the older DirectX 7 interface is used.
  • If you encounter low framerates when shadows are enabled, you might want to reduce the amount of fully rendered avatars in the Menu/Options/Settings/Chat tab. The default is set to 25, the max is 50, and a good value might be 12, depending on the power of your PC's hardware.

Considerations when making models

Modelers are challenged to make good and well working models, more than before. Models require proper vertex normals in order to get shadows working correctly. These vertex normals can be either provided by the model file, or can be calculated by the browser at the time it loads the geometry the first time.

Reason for shadows not working on certain models might include:

  • The model has too many triangles (faces) that would take the shadow;
  • The model has double sided faces;
  • The model has odd texture coordinates (i.e.rock*.rwx);
  • The model has incorrect vertex normals (i.e.rock*.rwx);
  • The model's faces show in opposite direction yet sharing the same vertices and thereby the same vertex normals;
  • The model has a tiled texture applied and covers more than 16 cells (old fashioned ground objects);
  • The model is off center and its max distance to its center is more than about 40 meters;

Notes

The same rules apply to material effects that depend on proper vertex normals and texture coordinates of the model.

Conclusions

Before getting too enthusiastic about new features, please verify if the model set you are using applies to up-to-date standards.

Pre Step

Shadow rendering technique used

Shadows are parallel projections seen from the direction of the directional light source, projected onto the underlaying geometry in a world.

Pre Step: Before calculating a shadow it is to check if the objects is within the current 3D view (within the camera frustum) and if the geometry is hidden by any other geometry in direction of the light. The image to the right shows the light rays from the light source to the hit target (avatar or object). If any other object would cover directional light along this line, no shadow will be drawn. This is in particular useful when the object is underground or within a closed building.

Step 1: As the first step a camera is taking an image of the Avatar (could be any object in world) from the described perspective rendering a white silhouette onto a black background. The first picture below shows the internal image that is taken. If this image would be rendered to screen, already considering Step 3 and Step 4, we would get a white silhouette of the Avatar.

Step 2: In the second step this 'photo' is inverted to black on white. We already can see the finally projected content of the shadow.

Step 3: Scanning the underlaying geometry for triangles facing towards the directional light source. This is done by checking triangle's face normal direction and the exact location of the corresponding vertices. Once a triangle was found to match all criteria, the triangle is copied into a temporary buffer and texture coordinates for the shadow image are calculated and applied. At the end of Step 3 we get a geometry of the shadow surface.

Step 4: Finally, our resulting geometry of the shadow silhouette is rendered into the 3D scene with the shadow image as its texture, on top of the original geometry. The last picture below shows the final result.

Shadow configuration for the browser

Shadow rendering can be enabled or disabled in the Menu/Options/Settings/Performance tab any time, or manually in the aworld.ini file using notepad by setting the shadows option to 0 or 1 to switch shadows off or on respectively.

 [performance]
 lifeforms=1
 avatars=1
 mipmaps=1
 subrender=1
 shadows=1

Additionally, the appearance of shadows can be tweaked by adding a "shadows" section to aworld.ini.

 [shadows]
 resolution=8
 strength=0.5
 blur=2
 anti_alias=0
 fade=1

This example will noticeably increase the resolution of shadows. But be warned that it may reduce performance with many avatars on-screen. An explanation of the individual options follows:

 resolution ... 6=64px, 7=128px, 8=256px, etc
 strength   ... transparency (0.1 to 1.0)
 blur       ... count of blur-passes (CPU extensive!)
 anti_alias ... de-pixelize (0=off, 1=on)
 fade       ... by distance above ground (max/height by 3.5)