changeset 1325:d4f83f5d2d32 draft

add gouraud shading.. not work yet.
author Yutaka_Kinjyo <yutaka@cr.ie.u-ryukyu.ac.jp>
date Tue, 20 Dec 2011 01:34:59 +0900
parents ada0b6ff6575
children 64b54c99d895
files Renderer/Engine/Span.h Renderer/Engine/task/CreatePolygonFromSceneGraph.cc Renderer/Engine/task/CreateSpan.cc Renderer/Engine/task/DrawSpan.cc
diffstat 4 files changed, 50 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/Span.h	Mon Dec 19 17:45:00 2011 +0900
+++ b/Renderer/Engine/Span.h	Tue Dec 20 01:34:59 2011 +0900
@@ -44,6 +44,12 @@
     float normal_y;
     float normal_z;
 
+    //test
+    float diffuse_l;
+    float diffuse_r;
+    int pad[2];
+
+
 #if 0
     TileInfoListPtr tilelist;
 #endif
--- a/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Mon Dec 19 17:45:00 2011 +0900
+++ b/Renderer/Engine/task/CreatePolygonFromSceneGraph.cc	Tue Dec 20 01:34:59 2011 +0900
@@ -67,6 +67,7 @@
  * @return diffuse
  */
 
+// test
 static float
 lighting(const float *vertex, const float *normal, const float *light) {
     
@@ -128,6 +129,7 @@
     float *light_xyz = (float*)smanager->global_get(Light);
     int *light_switch = (int*)smanager->global_get(LightSwitch);
     int light_num = 4;
+    // test
     float diffuse1 = 1;
     float diffuse2 = 1;
     float diffuse3 = 1;
@@ -178,6 +180,7 @@
       ApplyMatrix(normal2, normal_matrix);
       ApplyMatrix(normal3, normal_matrix);
 
+      // test
       for (int j = 0; j < light_num; j++) {
           // 光源のスイッチが入ってたら 
           if (light_switch[j] == 1) {
@@ -234,6 +237,7 @@
       triangle->ver1.z = xyz1[2];
       triangle->ver1.tex_x = tri.ver1.tex_x;
       triangle->ver1.tex_y = tri.ver1.tex_y;
+      // test
       triangle->ver1.diffuse = diffuse1;      
 
       triangle->ver2.x = xyz2[0];
@@ -241,6 +245,7 @@
       triangle->ver2.z = xyz2[2];
       triangle->ver2.tex_x = tri.ver2.tex_x;
       triangle->ver2.tex_y = tri.ver2.tex_y;
+      // test
       triangle->ver2.diffuse = diffuse2;      
       
       triangle->ver3.x = xyz3[0];
@@ -248,6 +253,7 @@
       triangle->ver3.z = xyz3[2];
       triangle->ver3.tex_x = tri.ver3.tex_x;
       triangle->ver3.tex_y = tri.ver3.tex_y;
+      // test
       triangle->ver3.diffuse = diffuse3;      
 
       triangle->normal1.x = normal1[0];
--- a/Renderer/Engine/task/CreateSpan.cc	Mon Dec 19 17:45:00 2011 +0900
+++ b/Renderer/Engine/task/CreateSpan.cc	Tue Dec 20 01:34:59 2011 +0900
@@ -111,6 +111,7 @@
     v->x      = calc(vMax->x - vMin->x, d, d1, vMin->x);
     v->y      = vMid->y;
     v->z      = calc(vMax->z - vMin->z, d, d1, vMin->z);
+    // test
     v->diffuse = calc(vMax->diffuse - vMin->diffuse, d, d1, vMin->diffuse);
 
 }
@@ -217,14 +218,20 @@
 
     float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2;
     float tmp_xpos,tmp_end,tmp_zpos;
+    float tmp_diffuse_l,tmp_diffuse_r;
     float start_z, end_z;
     float start_tex_x, end_tex_x, start_tex_y, end_tex_y;
+    float diffuse_l, diffuse_r;
+
     int x,length;
 
     tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x);
     tmp_end  = calc(vMid->x  - vMin->x ,div_y, i, vMin->x);
     tmp_z    = calc(vMid10->z - vMin->z ,div_y, i, vMin->z);
     tmp_zpos = calc(vMid->z  - vMin->z ,div_y, i, vMin->z);
+    // test
+    tmp_diffuse_l = calc(vMid10->diffuse  - vMin->diffuse, div_y, i, vMin->diffuse);
+    tmp_diffuse_r = calc(vMid->diffuse  - vMin->diffuse, div_y, i, vMin->diffuse);
     
     length = (tmp_xpos > tmp_end)
         ? (int)tmp_xpos - (int)tmp_end : (int)tmp_end - (int)tmp_xpos;
@@ -251,6 +258,9 @@
         end_tex_x = tmp_tex1;
         start_tex_y = tmp_tey2;
         end_tex_y = tmp_tey1;
+        // test
+        diffuse_l = tmp_diffuse_l;
+        diffuse_r = tmp_diffuse_r;
     } else {
         x = (int)tmp_xpos;
         length = (int)(tmp_end)-(int)(tmp_xpos)+1;
@@ -260,6 +270,9 @@
         end_tex_x = tmp_tex2;
         start_tex_y = tmp_tey1;
         end_tex_y = tmp_tey2;
+        // test
+        diffuse_l = tmp_diffuse_r;
+        diffuse_r = tmp_diffuse_l;
     }
     
     // ここいる? load してその後必ず、wait してるように見える。
@@ -277,6 +290,9 @@
     span->tex_x2     = end_tex_x;
     span->tex_y1     = start_tex_y;
     span->tex_y2     = end_tex_y;
+    // test
+    span->diffuse_l  = diffuse_l;
+    span->diffuse_r  = diffuse_r;
     
     /*
      * ここで頂点分法線ベクトルがあったんだけど、
--- a/Renderer/Engine/task/DrawSpan.cc	Mon Dec 19 17:45:00 2011 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Tue Dec 20 01:34:59 2011 +0900
@@ -67,9 +67,11 @@
 
 //static int getDrawParam(SchedTask *smanager, Gptr g, SpanPtr span, int localy, int startx, int endx, int index, int j, DrawParamPtr param);
 
-static    int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z,
-                                  SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z);
 
+static int infinity_light_calc(int color,float normal_x, float normal_y,
+                               float normal_z, SchedTask *smanager, int x, int y, float z,
+                               int world_x, int world_y, float world_z, 
+                               float diffuse_l, float diffuse_r, int rangex, int j);
 
 
 
@@ -203,7 +205,8 @@
 static void
 updateBuffer(Gptr g, float zpos, int rangex, int localx, int localy, int tex_x, int tex_y,
 	     float normal_x, float normal_y, float normal_z, TilePtr tile,
-	     int world_x, int world_y, float world_z, SchedTask *smanager)
+	     int world_x, int world_y, float world_z, SchedTask *smanager,
+             float diffuse_l, float diffuse_r, int j)
 {
 
     int color = get_rgb(tex_x, tex_y, tile);
@@ -223,7 +226,8 @@
     if ( *light_sysswitch == 1 && flag) {
         color = infinity_light_calc(color,normal_x,normal_y,normal_z,
 				    smanager,localx,localy,zpos,
-				    world_x,world_y,world_z);
+				    world_x,world_y,world_z,
+                                    diffuse_l, diffuse_r, rangex, j);
     }
 
     g->zRow[localx + (rangex*localy)] = zpos*flag + g->zRow[localx + (rangex*localy)]*(1-flag);
@@ -292,7 +296,8 @@
         updateBuffer(g, zpos, rangex, localx, localy,
                      tex_localx, tex_localy,
                      normal_x,normal_y,normal_z,tile,
-		     span->x, span->y, zpos, smanager);
+		     span->x, span->y, zpos, smanager,
+                     span->diffuse_l, span->diffuse_r, 0);
     }
 
     return -1;
@@ -389,6 +394,9 @@
     float normal_y = span->normal_y;
     float normal_z = span->normal_z;
 
+    // startx は DrawSpanTask の描画担当範囲の左端のx座標
+    // xは span の左端のx座標
+
     int js = (x < startx) ? startx - x : 0;
     int je = (x + x_len > endx) ? endx - x : x_len;
 
@@ -458,7 +466,8 @@
             updateBuffer(g, tex_z, rangex, localx, localy,
                          tex_localx, tex_localy,
                          normal_x, normal_y, normal_z, tile,
-			 span->x+j, span->y, world_z, smanager);
+			 span->x+j, span->y, world_z, smanager,
+                         span->diffuse_l, span->diffuse_r, j);
         }
     }
 
@@ -540,7 +549,8 @@
 static int
 infinity_light_calc(int color,float normal_x, float normal_y,
 		    float normal_z, SchedTask *smanager, int x, int y, float z,
-		    int world_x, int world_y, float world_z)
+		    int world_x, int world_y, float world_z, 
+                    float diffuse_l, float diffuse_r, int rangex, int j)
 
 {
 
@@ -602,6 +612,11 @@
       }
     }
 
+    //float diffuse = ( diffuse_r - diffuse_l ) / rangex * j + diffuse_l;
+    //tmp_rgb[0] = (unsigned char)(rgb[0]*diffuse);
+    //tmp_rgb[1] = (unsigned char)(rgb[1]*diffuse);
+    //tmp_rgb[2] = (unsigned char)(rgb[2]*diffuse);
+
     int rgb_flag[3];
     for (int i = 0; i < 3; i++) {
       rgb_flag[i] = (tmp_rgb[i] > 255);