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>Rendering Order</title>
8  </head>
9  <body>
10    <h1>Rendering Order</h1>
11    <div class="section">
12
13      <p>When rendering models or other objects using NW4C, data is sorted at the level of meshes making up the model to determine the rendering order for each mesh.</p>
14
15      <p class="info">The term <EM>mesh</EM> used above refers to the polygon sets that divide the model at the material level.</p>
16
17      <p>Use the following classes when sorting elements to be rendered.</p>
18
19      <ul>
20        <li><a href="../../nw/gfx/RenderQueue.html">nw::gfx::RenderQueue</a> (<a href="../../nw/gfx/BasicRenderQueue/Overview.html">nw::gfx::BasicRenderQueue</a>)</li>
21        <li><a href="../../nw/gfx/RenderKeyFactory.html">nw::gfx::RenderKeyFactory</a> (<a href="../../nw/gfx/BasicRenderKeyFactory/Overview.html">nw::gfx::BasicRenderKeyFactory</a>)</li>
22        <li><a href="../../nw/gfx/RenderElementCompare/Overview.html"><CODE>nw::gfx::RenderElementCompare</CODE></a></li>
23      </ul>
24
25      <p>RenderQueue stores render targets.</p>
26
27    </div>
28
29    <h2>Specific Example of Controlling Rendering Order</h2>
30    <div class="section">
31
32      <p>Refer to the implementation of the following method in the demo library for information on how to control rendering order.</p>
33
34      <ul>
35        <li><a href="../../nw/demo/RenderSystem/SetRenderSortMode.html">nw::demo::RenderSystem::SetRenderSortMode</a></li>
36        <li><span>nw::demo::SceneSystem::SubmitView</span></li>
37      </ul>
38
39      <p>If you want a display equivalent to a render sort under CreativeStudio where mesh base is used for translucent objects and model base is used for opaque objects, set OPAQUE_MESH_BASE_AND_TRANSLUCENT_MODEL_BASE_SORT of <a href="../../nw/gfx/ISceneUpdater/RenderSortMode.html">nw::gfx::ISceneUpdater::RenderSortMode</a> in <a href="../../nw/demo/RenderSystem/SetRenderSortMode.html">nw::demo::RenderSystem::SetRenderSortMode</a>.</p>
40
41    </div>
42
43    <h2>Render Order Sort</h2>
44    <div class="section">
45
46      <p>To sort render targets, follow the procedure described below.</p>
47
48      <ol>
49        <li>Create RenderQueue and RenderKeyFactory</li>
50        <li>Set <CODE>RenderKeyFactor</CODE> for <CODE>RenderQueue</CODE>.</li>
51        <li>Register render targets in RenderQueue.</li>
52        <li>Sort the render targets in <CODE>RenderQueue</CODE> using <CODE>std::sort</CODE> and <CODE>RenderElementCompare</CODE>.</li>
53      </ol>
54
55      <p>Sort using <CODE>std::sort</CODE> or other sort algorithm using 64-bit integer values as keys for model sort. Use <CODE>RenderElementCompare</CODE> for key comparison during sort. Examples are shown below.</p>
56
57      <pre>
58      std::sort(
59          this-&gt;m_RenderQueue-&gt;Begin(),
60          this-&gt;m_RenderQueue-&gt;End(),
61          nw::gfx::RenderElementCompare());</pre>
62
63      <p>You may also use a sort algorithm other than <CODE>std::sort</CODE>.</p>
64
65    </div>
66
67    <h2>Keys Used for Sorting Render Targets</h2>
68    <div class="section">
69
70      <p>Keys used to determine rendering order are primarily created based on the following factors.</p>
71
72      <ul>
73        <li><b>Layer ID</b> set by the programmer</li>
74        <ul>
75          <li>Layer ID set by <a href="../../nw/gfx/ISceneUpdater/SubmitView.html">nw::gfx::ISceneUpdater::SubmitView</a></li>
76          <li>Layer ID set by <a href="../../nw/gfx/Model/SetLayerId.html">nw::gfx::Model::SetLayerId</a></li>
77          <li>The two layer IDs given above are combined using a logical OR before key creation.</li>
78        </ul>
79        <li><b>Render layer (translucency)</b> of model data</li>
80        <li><b>Material render priority</b> of model data</li>
81        <li><b>Material ID</b> of model data</li>
82        <li><b>Z depth</b> in the screen coordinate system of the mesh</li>
83      </ul>
84
85      <p>Keys used for sorting are created by packing the above information into a 64-bit integer value. The resulting integer value is called a <EM>render key</EM>.</p>
86
87      <p>The following types of embedded render keys have been prepared.</p>
88
89      <ul>
90        <li>PriorMaterialRenderKey</li>
91          <ul><li>Material priority render key.</li></ul>
92        <li>PriorMaterialReverseDepthRenderKey</li>
93          <ul><li>Render key for rendering from the back based on material priority.</li></ul>
94        <li>PriorDepthRenderKey</li>
95          <ul><li>Depth priority render key.</li></ul>
96        <li>PriorDepthReverseDepthRenderKey</li>
97          <ul><li>Render key for rendering from the back based on depth priority.</li></ul>
98        <li>TopPriorDepthRenderKey</li>
99          <ul><li>Depth priority render key.</li></ul>
100        <li>TopPriorDepthReverseDepthRenderKey</li>
101          <ul><li>Render key for rendering from the back based on top depth priority.</li></ul>
102      </ul>
103
104      <img src="images/RenderKey.png" />
105
106      <p class="info">The bar figures represent a 64-bit integer value. Values below the above figures represent bit width.</p>
107
108    </div>
109
110    <h2>Creating Render Keys</h2>
111    <div class="section">
112
113      <p>Use a sub-class of the <a href="../../nw/gfx/BasicRenderKeyFactory/Overview.html">BasicRenderKeyFactory</a> to create keys. These are called <EM>render key factories</EM>.</p>
114
115      <p>Use the following function to create a render key factory class.</p>
116
117      <ul>
118        <li><a href="../../nw/gfx/CreatePriorMaterialRenderKeyFactory.html">nw::gfx::CreatePriorMaterialRenderKeyFactory</a></li>
119        <ul><li>Creates a factory that creates render keys, giving priority to materials.</li></ul>
120        <li><a href="../../nw/gfx/CreatePriorMaterialReverseDepthRenderKeyFactory.html">nw::gfx::CreatePriorMaterialReverseDepthRenderKeyFactory</a></li>
121        <ul><li>Creates a factory that creates render keys that are rendered starting from the background, giving priority to materials.</li></ul>
122        <li><a href="../../nw/gfx/CreatePriorDepthRenderKeyFactory.html">nw::gfx::CreatePriorDepthRenderKeyFactory</a></li>
123        <ul><li>Creates a factory that creates render keys, giving priority to depths.</li></ul>
124        <li><a href="../../nw/gfx/CreatePriorDepthReverseDepthRenderKeyFactory.html">nw::gfx::CreatePriorDepthReverseDepthRenderKeyFactory</a></li>
125        <ul><li>Creates a factory that creates render keys that are rendered starting from the background, giving priority to depths.</li></ul>
126        <li><a href="../../nw/gfx/CreateTopPriorDepthRenderKeyFactory.html">nw::gfx::CreateTopPriorDepthRenderKeyFactory</a></li>
127        <ul><li>Creates a factory that creates render keys with highest priority given to depth.</li></ul>
128        <li><a href="../../nw/gfx/CreateTopPriorDepthReverseDepthRenderKeyFactory.html">nw::gfx::CreateTopPriorDepthReverseDepthRenderKeyFactory</a></li>
129        <ul><li>Creates a factory that creates render keys that are rendered starting from the background, with highest priority given to depth.</li></ul>
130      </ul>
131
132      <p class="info">In addition to the above, you can also create your own key factory by inheriting the RenderKeyFactory class.</p>
133
134      <p>Set the key factory created for the <CODE>RenderQueue</CODE> using <a href="../../nw/gfx/BasicRenderQueue/Reset.html">nw::gfx::BasicRenderQueue::Reset</a>.</p>
135    </div>
136
137    <h2 id="render_command">Interrupt Processes During Rendering</h2>
138    <div class="section">
139
140      <p>Use <a href="../../nw/gfx/RenderCommand/Overview.html">nw::gfx::RenderCommand</a> to interrupt an original processing midway through the <CODE>RenderQueue</CODE>.</p>
141
142      <p>Use <a href="../../nw/gfx/BasicRenderQueue/EnqueueCommand.html">nw::gfx::BasicRenderQueue::EnqueueCommand</a> to insert a render command in the <CODE>RenderQueue</CODE>. Once inserted, you can interrupt the processing during mesh rendering (<a href="../../nw/gfx/MeshRenderer/RenderMesh.html">nw::gfx::MeshRenderer::RenderMesh</a>) as shown in the figure below.</p>
143
144        <img src="images/callback.png" />
145
146    </div>
147
148  <hr><p>CONFIDENTIAL</p></body>
149</html>
150