source: OGRE/trunk/ogrenew/Docs/manual/manual_59.html @ 657

Revision 657, 12.9 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1<HTML>
2<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3<!-- Created on , 12 2006 by texi2html 1.64 -->
4<!--
5Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
6            Karl Berry  <karl@freefriends.org>
7            Olaf Bachmann <obachman@mathematik.uni-kl.de>
8            and many others.
9Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
10Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
11 
12-->
13<HEAD>
14<TITLE>OGRE Manual v1.0.7: Texture-based Shadows</TITLE>
15
16<META NAME="description" CONTENT="OGRE Manual v1.0.7: Texture-based Shadows">
17<META NAME="keywords" CONTENT="OGRE Manual v1.0.7: Texture-based Shadows">
18<META NAME="resource-type" CONTENT="document">
19<META NAME="distribution" CONTENT="global">
20<META NAME="Generator" CONTENT="texi2html 1.64">
21<LINK TYPE="text/css" rel="stylesheet" href="../style.css"> 
22</HEAD>
23
24<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
25
26<A NAME="SEC222"></A>
27<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
28<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_58.html#SEC215"> &lt; </A>]</TD>
29<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_57.html#SEC212"> Up </A>]</TD>
30<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_60.html#SEC233"> &gt; </A>]</TD>
31<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
32<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD>
33<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
34<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD>
35</TR></TABLE>
36<HR SIZE=1>
37<H2> 7.2 Texture-based Shadows </H2>
38<!--docid::SEC222::-->
39<P>
40
41Texture shadows involve rendering shadow casters from the point of view of the light into a texture, which is then projected onto shadow casters while rendering the standard view. The main advantage of texture shadows as opposed to <A HREF="manual_58.html#SEC215">7.1 Stencil Shadows</A> is that the overhead of increasing the geometric detail is far lower, since there is no need to perform per-triangle calculations. Most of the work in rendering texture shadows is done by the graphics card, meaning the technique scales well when taking advantage of the latest cards, which are at present outpacing CPUs in terms of their speed of development.<BR><BR>
42</P><P>
43
44The main disadvantage to texture shadows is that, because they are simply a texture, they have a fixed resolution which means if stretched, the pixellation of the texture becomes obvious. Filtering can reduce this, but the problem still remains. In addition, because these shadows require a render to texture in the direction of the light, omnidirectional lights (point lights) would require 8 renders to totally cover all the directions shadows might be cast. For this reason, Ogre only supports directional lights and spotlights for generating texture shadows; you should turn off shadow casting for point lights if you're using texture shadows.<BR><BR>
45</P><P>
46
47<A NAME="SEC223"></A>
48<H3> Directional Lights </H3>
49<!--docid::SEC223::-->
50Directional lights in theory shadow the entire scene from an infinitely distant light. Now, since we only have a finite texture which will look very poor quality if stretched over the entire scene, clearly a simplification is required. Ogre places a shadow texture over the area immediately in front of the camera, and moves it as the camera moves (although it rounds this movement to multiples of texels so that the slight 'swimming shadow' effect caused by moving the texture is minimised). The range to which this shadow extends, and the offset used to move it in front of the camera, are configurable (See section <A HREF="manual_59.html#SEC226">Configuring Texture Shadows</A>). At the far edge of the shadow, Ogre fades out the shadow based on other configurable parameters so that the termination of the shadow is softened.
51<P>
52
53<A NAME="SEC224"></A>
54<H3> Spotlights </H3>
55<!--docid::SEC224::-->
56Spotlights are much easier to represent as renderable shadow textures than directional lights, since they are naturally a frustum. Ogre represents spotlight directly by rendering the shadow from the light position, in the direction of the light cone; the field-of-view of the texture camera is adjusted based on the spotlight falloff angles. In addition, to hide the fact that the shadow texture is square and has definite edges which could show up outside the spotlight, Ogre uses a second texture unit when projecting the shadow onto the scene which fades out the shadow gradually in a projected circle around the spotlight.
57<P>
58
59<A NAME="SEC225"></A>
60<H3> Shadow Casters and Shadow Receivers </H3>
61<!--docid::SEC225::-->
62To enable texture shadows, use the shadow technique SHADOWTYPE_TEXTURE_MODULATIVE; as the name suggests this produces <A HREF="manual_60.html#SEC233">7.3 Modulative Shadows</A>. Because the texture is merely projected onto shadow casters, a shadow caster cannot also be a shadow receiver, so self-shadowing is not possible using this method (there is an alternative method called depth shadowmapping which can do this using similar techniques as modulative shadow textures, but these are not supported by Ogre yet).<BR><BR>
63Ogre divides shadow casters and receivers into 2 disjoint groups. Simply by turning off shadow casting on an object, you automatically make it a shadow receiver (although this can be disabled by setting the 'receive_shadows' option to 'false' in a material script. Similarly, if an object is set as a shadow caster, it cannt receive shadows. If you need more complex shadowing you would be advised to look at <A HREF="manual_58.html#SEC215">7.1 Stencil Shadows</A>, but this simplified approach can work well in a lot of situations for a pretty low cost.
64<P>
65
66<A NAME="Configuring Texture Shadows"></A>
67<A NAME="SEC226"></A>
68<H2> Configuring Texture Shadows </H2>
69<!--docid::SEC226::-->
70There are a number of settings which will help you configure your texture-based shadows so that they match your requirements.
71<P>
72
73<UL>
74<LI><A HREF="manual_59.html#SEC227">Maximum number of shadow textures</A>
75<LI><A HREF="manual_59.html#SEC228">Shadow texture size</A>
76<LI><A HREF="manual_59.html#SEC229">Shadow far distance</A>
77<LI><A HREF="manual_59.html#SEC230">Shadow texture offset (Directional Lights)</A>
78<LI><A HREF="manual_59.html#SEC231">Shadow fade settings</A>
79</UL>
80<P>
81
82<A NAME="Maximum number of shadow textures"></A>
83<A NAME="SEC227"></A>
84<H3> Maximum number of shadow textures </H3>
85<!--docid::SEC227::-->
86Shadow textures take up texture memory, and to avoid stalling the rendering pipeline Ogre does not reuse the same shadow texture for multiple lights within the same frame. This means that each light which is to cast shadows must have its own shadow texture. In practice, if you have a lot of lights in your scene you would not wish to incur that sort of texture overhead.<BR><BR>
87You can adjust this manually by simply turning off shadow casting for lights you do not wish to cast shadows. In addition, you can set a maximum limit on the number of shadow textures Ogre is allowed to use by calling SceneManager::setShadowTextureCount. Each frame, Ogre determines the lights which could be affecting the frustum, and then allocates the number of shadow textures it is allowed to use to the lights on a first-come-first-served basis. Any additional lights will not cast shadows that frame.
88<BR><BR>Note that you can set the number of shadow textures and their size at the same time by using the SceneManager::setShadowTextureSettings method; this is useful because both the individual calls require the potential creation / destruction of texture resources.
89<P>
90
91<A NAME="Shadow texture size"></A>
92<A NAME="SEC228"></A>
93<H3> Shadow texture size </H3>
94<!--docid::SEC228::-->
95<P>
96
97The size of the textures used for rendering the shadow casters into can be altered; clearly using larger textures will give you better quality shadows, but at the expense of greater memory usage. Changing the texture size is done by calling SceneManager::setShadowTextureSize - textures are assumed to be square and you must specify a texture size that is a power of 2. Be aware that each modulative shadow texture will take size*size*3 bytes of texture memory. <BR><BR>
98<STRONG>Important</STRONG>: if you use the GL render system your shadow texture size cannot be larger (in either dimension) than the size of your primary window surface. That means that for window resolutions lower than 1280x1024 your maximum shadow texture size is 512. If you create a shadow texture larger than this, only the area the size of the primary window surface will be updated, causing severe shadowing artefacts. Direct3D does not suffer from this limitation, so if you intend to use Direct3D only you are free to use whatever shadow texture size you want, subject to texture memory constraints.
99</P><P>
100
101<A NAME="Shadow far distance"></A>
102<A NAME="SEC229"></A>
103<H3> Shadow far distance </H3>
104<!--docid::SEC229::-->
105<P>
106
107This determines the distance at which shadows are terminated; it also determines how far into the distance the texture shadows for directional lights are stretched - by reducing this value, or increasing the texture size, you can improve the quality of shadows from directional lights at the expense of closer shadow termination or increased memory usage, respectively.
108</P><P>
109
110<A NAME="Shadow texture offset (Directional Lights)"></A>
111<A NAME="SEC230"></A>
112<H3> Shadow texture offset (Directional Lights) </H3>
113<!--docid::SEC230::-->
114As mentioned above in the directional lights section, the rendering of shadows for directional lights is an approximation that allows us to use a single render to cover a largeish area with shadows. This offset parameter affects how far from the camera position the center of the shadow texture is offset, as a proprtion of the shadow far distance. The greater this value, the more of the shadow texture is 'useful' to you since it's ahead of the camera, but also the further you offset it, the more chance there is of accidentally seeing the edge of the shadow texture at more extreme angles. You change this value by calling SceneManager::setShadowDirLightTextureOffset, the default is 0.6.
115<P>
116
117<A NAME="Shadow fade settings"></A>
118<A NAME="SEC231"></A>
119<H3> Shadow fade settings </H3>
120<!--docid::SEC231::-->
121<P>
122
123Shadows fade out before the shadow far distance so that the termination of shadow is not abrupt. You can configure the start and end points of this fade by calling the SceneManager::setShadowTextureFadeStart and SceneManager::setShadowTextureFadeEnd methods, both take distances as a proportion of the shadow far distance. Because of the inaccuracies caused by using a square texture and a radial fade distance, you cannot use 1.0 as the fade end, if you do you'll see artefacts at the extreme edges. The default values are 0.7 and 0.9, which serve most purposes but you can change them if you like.
124</P><P>
125
126<A NAME="SEC232"></A>
127<H2> Texture shadows and vertex programs </H2>
128<!--docid::SEC232::-->
129When rendering shadow casters into a modulative shadow texture, Ogre turns off all textures, and all lighting contributions except for ambient light, which it sets to the colour of the shadow (<A HREF="manual_60.html#SEC234">Shadow Colour</A>). This is enough to render shadow casters for fixed-function material techniques, however where a vertex program is used Ogre doesn't have so much control. If you use a vertex program in the <STRONG>first pass</STRONG> of your technique, then you must also tell ogre which vertex program you want it to use when rendering the shadow caster; see <A HREF="manual_20.html#SEC92">Shadows and Vertex Programs</A> for full details.
130<P>
131
132<A NAME="Modulative Shadows"></A>
133<HR SIZE=1>
134<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
135<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_58.html#SEC215"> &lt; </A>]</TD>
136<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_57.html#SEC212"> Up </A>]</TD>
137<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_60.html#SEC233"> &gt; </A>]</TD>
138<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
139<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_toc.html#SEC_Contents">Contents</A>]</TD>
140<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
141<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="manual_abt.html#SEC_About"> ? </A>]</TD>
142</TR></TABLE>
143<BR> 
144<FONT SIZE="-1">
145This document was generated
146by <I>Steve Streeting</I> on <I>, 12 2006</I>
147using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
148"><I>texi2html</I></A>
149
150</BODY>
151</HTML>
Note: See TracBrowser for help on using the repository browser.