1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[]> 2<html xml:lang="en-US" lang="en-US"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <meta http-equiv="Content-Style-Type" content="text/css" /> 6 <link rel="stylesheet" href="../../../css/document.css" type="text/css" /> 7 <title>Graphix Library (gfx) Sample Demos</title> 8 </head> 9 <body> 10 <h1>ProjectionShadowDemo</h1> 11 12 <div class="section"><img src="images/ProjectionShadowDemo.png" border="0" width="400" height="240" /></div> 13 14 <h2>Overview</h2> 15 <p> 16 Demo for applying shadows by projecting rendered results as a texture from the direction of the light. 17 </p> 18 19 <h2>How to Use</h2> 20 <p> 21 <ul> 22 <li>Demo-specific operations</li> 23 <ul> 24 <li>None.</li> 25 </ul> 26 <li>Common Operations</li> 27 <ul> 28 <li>Slide pad: Rotate the camera</li> 29 <li>Slide pad + A Button: Move the camera back and forth</li> 30 <li>Slide pad + B Button: Move the camera in parallel</li> 31 <li>Slide pad + Y Button: Move the camera up and down</li> 32 <li>X Button: Reset the camera position</li> 33 <li>START Button: Restart the demo.</li> 34 </ul> 35 </ul> 36 </p> 37 38 <h2>Description</h2> 39 <p> 40 Rendering is performed in two passes to achieve projected texture shadows.<BR> In this demo, shadow settings are inserted by a callback using <a href="../../../nw/gfx/RenderCommand/Overview.html">RenderCommand</a>. This is set using the layer ID so that rendering is performed in the following order.<BR> StartShadowRenderCommand → Render first pass → EndShadowRenderCommand → StartRenderCommand → Render second pass → EndRenderCommand 41 </p> 42 <p> 43 On the first pass, rendering is performed from the light direction toward the texture.<BR> Beforehand, SHADOW_CASTER defined in the demo is set for objects that cast shadows in UserParameter.<BR> On the first pass, a function object is set for SubmitView and only SHADOW_CASTER is added to the RenderQueue. Before rendering in the first pass, material settings for shadows are made using StartShadoRenderCommand. 44 </p> 45 <p class="info"> 46 StartShadowRenderCommand makes the following settings. 47 </p> 48 <h3>Switching to the offscreen buffer</h3> 49 <p>Switches to an offscreen buffer already created for rendering to textures.</p> 50 <h3>Switching to materials for shadows</h3> 51 <p> 52 Materials for shadows include the following settings.<BR> - A shader that outputs vertex and color only<br />- A combiner that uses vertex shader output<br />- Invalidates the depth text<br />- Sets the shadow color (the diffuse color) 53 </p> 54 <h3>Setting the shadow camera as the rendering camera</h3> 55 <p>First, create a shadow camera pointed in the light direction.</p> 56 <h3>Switching to a rendering mode that does not use material settings</h3> 57 <p> 58 Set using <a href="../../../nw/gfx/RenderContext/SetRenderMode.html">SetRenderMode</a> so that material settings by the model are ignored.<br /> This carries out rendering using the shadow settings set initially. 59 </p> 60 <p class="info">After models for which SHADOW_CASTER has been set, cancel shadow settings by calling EndShadowRenderCommand.</p> 61 <p> 62 ・Restore the regular render mode using <a href="../../../nw/gfx/RenderContext/SetRenderMode.html">SetRenderMode</a>.<br /> ・Reset the state of RenderContext using <a href="../../../nw/gfx/RenderContext/ResetState.html">ResetState</a>.<BR>Re-configure the active camera for SceneEnvironment because once the state is reset, active camera settings become invalid. 63 </p> 64 <p> 65 On the second pass, textures created in the first pass are applied to models that cast shadows and then rendered.<BR> Shadow textures are set for models that cast shadows in the order given below. 66 </p> 67 <h3>A dummy texture is attached to texture 0 when the model is created</h3> 68 <p> 69 In SampleData\Graphics\Intermediate\shadow_sample\male.cmdl, dummy.ctex has been attached to texture 0.<br /> Projection mapping is applied to the dummy texture at this time. 70 </p> 71 <h3>Swap the dummy texture and shadow texture at setup time</h3> 72 <p> 73 Use <span>ne::gfx::res::ResPixelBasedTextureMapper::SetTexture</span> to dynamically switch to the created shadow texture. 74 </p> 75 <hr><p>CONFIDENTIAL</p></body> 76</html> 77 78