changeset 17:a0c0087a27f8

CreateSpan done. Texture operation not yet.
author tkaito
date Mon, 31 Jan 2011 06:02:27 +0900
parents 9caa1df62bda
children 16df4adaa528
files paper/cerium.tex paper/images/polygonpack.bb paper/images/polygonpack.graffle paper/images/polygonpack.pdf paper/images/sep-polygon.bb paper/images/sep-polygon.graffle paper/images/sep-polygon.pdf paper/images/spanpack-rendering.bb paper/images/spanpack-rendering.graffle paper/images/spanpack-rendering.pdf paper/images/spanpack.bb paper/images/spanpack.graffle paper/images/spanpack.pdf
diffstat 13 files changed, 171 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/paper/cerium.tex	Mon Jan 31 03:01:54 2011 +0900
+++ b/paper/cerium.tex	Mon Jan 31 06:02:27 2011 +0900
@@ -528,7 +528,8 @@
 
 \section{Rendering Engine} \label{sec:cerium_renderingengine}
 
-Rendering Engine は主に CreatePolygon, CreateSpan, DrawSpan という 
+Rendering Engine は主に CreatePolygonFromSceneGraph(\ref{createpolygonfromscenegraph}), 
+CreateSpan(\ref{createspan}), DrawSpan(\ref{drawspan}) という 
 3 つの Task から構成されている。Span とは、ポリゴンに対するある特定の Y 
 座標に関するデータを抜き出したものである( \figref{inst_span} )。
 
@@ -563,7 +564,7 @@
     // 法線ベクトルの情報
     NormalPack normal1, normal2, normal3;
 
-} TrianglePack, *TrianglePackPtr; // 112 (16 * 7) 
+} TrianglePack, *TrianglePackPtr;
 
 typedef struct PolygonPack {
 
@@ -587,10 +588,20 @@
 
 \item[NormalPack] は、ポリゴンの法線ベクトルの情報が格納されている
 
+\newpage
+
+\begin{figure}[htb]
+  \begin{center}
+    \includegraphics[scale=0.70]{./images/polygonpack.pdf}
+  \end{center}
+  \caption{PolygonPack(TrianglePack)}
+  \label{fig:polyonpack}
+\end{figure}
+
 \end{description}
 
 PolygonPack は光源やテクスチャ、頂点の情報から構成される。
-テクスチャの縮小率に関しては \ref{scale} で詳しく説明する。
+テクスチャの縮小率に関しては \ref{cerium_scale} で詳しく説明する。
 
 \subsubsection{SpanPack}
 
@@ -599,20 +610,155 @@
 \begin{verbatim}
 class Span {
 public:
+    // テクスチャ情報
     uint32 *tex_addr;
-    int tex_width;
-    int tex_height;
+    int tex_width, tex_height;
 
+    // span の開始 x 座標、y 座標、長さ
     int x, y, length_x;
 
+    // span の z 座標(開始、終了)
     float start_z, end_z;
+
+    // span に対応するテクスチャの座標
     float tex_x1, tex_x2, tex_y1, tex_y2;
 
+    // span の法線ベクトル
     float normal_x, normal_y, normal_z;
 };
 
+class SpanPack {
+public: /* fields */
+    struct SpanInfo {
+        int start;
+        int size;
+        int y_top;
+        int light_pos[3];
+        int light_rgb[3];
+    } info;
+    Span span[MAX_SIZE_SPAN];
+    SpanPack *next;
+};
 \end{verbatim}
 
+Span は、その座標と対応するテクスチャの座標を持つ(\figref{cerium_span})
+
+\begin{figure}[htb]
+  \begin{center}
+    \includegraphics[scale=0.80]{./images/spanpack.pdf}
+  \end{center}
+  \caption{Span の構造}
+  \label{fig:cerium_span}
+\end{figure}
+
+Renderting には SpanPack を用いる。
+
+ここからは、SceneGraph から Rendering までの流れを説明する。
+
+\subsection{CreatePolyogonFromSceneGraph} \label{createpolygonfromscenegraph}
+
+SceneGraph の move や collision を行い、各オブジェクトの変換行列
+を生成する。その後、SceneGraph が持つポリゴンの座標と法線ベクトルに
+変換行列をかけ、得られた座標を PolygonPack に格納していく。
+以下がそのコードである。
+
+\newpage
+
+\begin{verbatim}
+
+SceneGraphPtr sg_top = sg_draw_tree;
+
+// ポリゴンの1辺
+xyz1[0] = sg->coord_xyz[(i+0)*3];
+xyz1[1] = sg->coord_xyz[(i+0)*3+1];
+xyz1[2] = sg->coord_xyz[(i+0)*3+2]*-1.0f;
+xyz1[3] = 1.0f;
+
+/* xyz2, xyz3 は省略 */
+
+// ポリゴンの1辺の法線ベクトル
+normal1[0] = sg->normal[(i+0)*3];
+normal1[1] = sg->normal[(i+0)*3+1];
+normal1[2] = sg->normal[(i+0)*3+2]*-1.0f;
+
+/* normal2, normal3 は省略 */
+
+// sg->matrix = 回転行列*透視変換行列
+ApplyMatrix(xyz1, sg->matrix);
+ApplyMatrix(normal1, sg->real_matrix);
+
+// PolygonPack の TrianglePack に計算した値とテクスチャの座標を格納する
+PolygonPackPtr pp = new PolygonPack;
+TrianglePack *triangle = &pp->tri[pp->info.size++];
+
+triangle->ver1.x = xyz1[0];
+triangle->ver1.y = xyz1[1];
+triangle->ver1.z = xyz1[2];
+triangle->ver1.tex_x = sg->coord_tex[(i+0)*3];
+triangle->ver1.tex_y = sg->coord_tex[(i+0)*3+1];
+triangle->normal1.x = normal1[0];
+triangle->normal1.y = normal1[1];
+triangle->normal1.z = normal1[2];
+
+/* ver2, ver3, normal2. normal3 は省略 */
+
+// テクスチャのアドレス、幅、高さ、縮小率を格納する
+triangle->tex_info.addr   = sg->texture_info.pixels;
+triangle->tex_info.width  = sg->texture_info.t_w;
+triangle->tex_info.height = sg->texture_info.t_h;
+triangle->tex_info.scale_max = sg->texture_info.scale_max;
+\end{verbatim}
+
+これらの処理を全ての Scenegraph に行い、PolygonPack を生成していく。
+
+\subsection{CreateSpan} \label{createspan}
+
+生成された PolygonPack に格納されているポリゴンから、Span を抽出していく。
+Span は x 軸に平行な線分を表しているため、初めにポリゴンを水平に分割して
+二つの三角形 (Triangle1, Triangle2) を作り、それぞれに対してSpan を求める 
+\cite{akira} (\figref{sep-polygon})。
+
+\begin{figure}[htb]
+  \begin{center}
+    \includegraphics[scale=0.90]{./images/sep-polygon.pdf}
+  \end{center}
+  \caption{ポリゴンの分割と Span 生成}
+  \label{fig:sep-polygon}
+\end{figure}
+
+得られた Span を SpanPack に格納する場合、その SpanPack が持つ全ての Span の y 座標
+が一定範囲内に入るようにする。
+
+Rendering する場合、画面を複数の領域に分割し、それぞれを一つの Task で担当する。Cerium 
+では Rendering 時に Z Buffer を用いているため、同じ Task に違う領域の Span があると
+正常に描画できない。そこで、一つの SpanPack には決まった y 座標を持った Span だけを
+入れることにより、Rendering 時には独立して行うことができる。
+y の範囲は 8 としている(\figref{spanpack-rendering})。
+
+\newpage
+
+\begin{figure}[htb]
+  \begin{center}
+    \includegraphics[scale=0.80]{./images/spanpack-rendering.pdf}
+  \end{center}
+  \caption{SpanPack の割り当て(height = 1080)}
+  \label{fig:spanpack-rendering}
+\end{figure}
+
+\subsection{Rendering するための準備}
+
+画面に Rendering するためには、SpanPack の中の Span を辿り、対応する RGB 値をテクスチャイメージから取り出して
+ frame buffer に書きこむ必要がある。しかし、SPE のメモリ領域は 256KB しかないため、Span が詐称している
+テクスチャイメージ全てを SPE に送ることはできない。
+
+そこで我々は、テクスチャイメージに対して分割、Tile管理、縮小という操作を行うことでこの問題
+を解決した。
+
+\subsection{Texture の分割}
+\subsection{Texture の Tile 管理}
+\subsection{Texture の縮小}
+
+\subsection{DrawSpan} \label{drawspan}
 
 \begin{comment}
 \\ ###########################途中############################\\
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/images/polygonpack.bb	Mon Jan 31 06:02:27 2011 +0900
@@ -0,0 +1,5 @@
+%%Title: ./polygonpack.pdf
+%%Creator: extractbb 20090506
+%%BoundingBox: 0 0 499 226
+%%CreationDate: Mon Jan 31 03:38:15 2011
+
Binary file paper/images/polygonpack.graffle has changed
Binary file paper/images/polygonpack.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/images/sep-polygon.bb	Mon Jan 31 06:02:27 2011 +0900
@@ -0,0 +1,5 @@
+%%Title: ./sep-polygon.pdf
+%%Creator: extractbb 20090506
+%%BoundingBox: 0 0 345 261
+%%CreationDate: Mon Jan 31 05:44:07 2011
+
Binary file paper/images/sep-polygon.graffle has changed
Binary file paper/images/sep-polygon.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/images/spanpack-rendering.bb	Mon Jan 31 06:02:27 2011 +0900
@@ -0,0 +1,5 @@
+%%Title: ./spanpack-rendering.pdf
+%%Creator: extractbb 20090506
+%%BoundingBox: 0 0 541 340
+%%CreationDate: Mon Jan 31 05:44:07 2011
+
Binary file paper/images/spanpack-rendering.graffle has changed
Binary file paper/images/spanpack-rendering.pdf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paper/images/spanpack.bb	Mon Jan 31 06:02:27 2011 +0900
@@ -0,0 +1,5 @@
+%%Title: ./spanpack.pdf
+%%Creator: extractbb 20090506
+%%BoundingBox: 0 0 534 198
+%%CreationDate: Mon Jan 31 04:12:19 2011
+
Binary file paper/images/spanpack.graffle has changed
Binary file paper/images/spanpack.pdf has changed