diff TaskManager/Test/test_render/task/DrawSpan.cpp @ 315:a7ff29110474

add pre light
author e065725@yutaka.st.ie.u-ryukyu.ac.jp
date Tue, 09 Jun 2009 16:44:00 +0900
parents 3e9c0039e15c
children 7efc5ede2c03
line wrap: on
line diff
--- a/TaskManager/Test/test_render/task/DrawSpan.cpp	Tue Jun 09 01:22:11 2009 +0900
+++ b/TaskManager/Test/test_render/task/DrawSpan.cpp	Tue Jun 09 16:44:00 2009 +0900
@@ -5,6 +5,7 @@
 #include "texture.h"
 #include "viewer_types.h"
 #include "Func.h"
+#include "sys.h"
 
 SchedDefineTask(DrawSpan);
 
@@ -262,19 +263,20 @@
  * @param tex_addr テクスチャのアドレス(MainMemory)
  */
 void
-DrawSpan::updateBuffer(float zpos, int rangex, int x, int y,
-		       int tex_x, int tex_y, uint32 *tex_addr)
+DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, int tex_x, int tex_y, 
+                       float normal_x, float normal_y, float normal_z, uint32 *tex_addr)
 {
 
-
-    int rgb = get_rgb(tex_x, tex_y, tex_addr);
+    int color = get_rgb(tex_x, tex_y, tex_addr);
     /*下位4bitを抽出*/
-    int alpha = rgb & 0x000F;
+    int alpha = color & 0x000F;
     /*完全に透けているか判断*/
     int flag = (alpha != 0);
 
+    color = infinity_light_calc(color,normal_x,normal_y,normal_z);
+
     zRow[x + (rangex*y)] = zpos*flag + zRow[x + (rangex*y)]*(1-flag);
-    linebuf[x + (rangex*y)] = rgb*flag + linebuf[x + (rangex*y)]*(1-flag);
+    linebuf[x + (rangex*y)] = color*flag + linebuf[x + (rangex*y)]*(1-flag);
 
 }
 
@@ -290,6 +292,11 @@
 {
     int rangex = endx - startx + 1;
 
+    float normal_x = span->normal_x;
+    float normal_y = span->normal_y;
+    float normal_z = span->normal_z;
+
+
     /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */
     int tex_xpos, tex_ypos;
 
@@ -332,7 +339,8 @@
 	}
 
 	updateBuffer(zpos, rangex, localx, localy,
-		     tex_localx, tex_localy, tex_addr);
+		     tex_localx, tex_localy, 
+                     normal_x,normal_y,normal_z,tex_addr);
     }
 
     return -1;
@@ -368,6 +376,11 @@
     int rangex = endx - startx + 1;
     int x_len = span->length_x;
 
+    float normal_x = span->normal_x;
+    float normal_y = span->normal_y;
+    float normal_z = span->normal_z;
+
+
     int js = (x < startx) ? startx - x : 0;
     int je = (x + x_len > endx) ? endx - x : x_len;
 
@@ -442,7 +455,8 @@
 	    }
 
 	    updateBuffer(tex_z, rangex, localx, localy,
-			 tex_localx, tex_localy, tex_addr);
+			 tex_localx, tex_localy, 
+                         normal_x, normal_y, normal_z,tex_addr);
 	}
     }
 
@@ -467,6 +481,11 @@
     int rangex = endx - startx + 1;
     int x_len = span->length_x;
 
+    float normal_x = span->normal_x;
+    float normal_y = span->normal_y;
+    float normal_z = span->normal_z;
+
+
     //int js = startx;
     int je = (x + x_len > endx) ? endx - x : x_len;
 
@@ -519,12 +538,52 @@
 	    tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL;
 
 	    updateBuffer(tex_z, rangex, localx, localy,
-			 tex_localx, tex_localy, tex_addr);
+			 tex_localx, tex_localy, 
+                         normal_x, normal_y, normal_z,tex_addr);
 	}
     }    
 }
 
 int
+DrawSpan::infinity_light_calc(int color,float normal_x, float normal_y, float normal_z)
+{
+    unsigned char rgb[4];
+    float normal_vector[3] = {normal_x,normal_y,normal_z};
+    //光のベクトル,きめうちしちゃった。どうにかする
+    float light_vector[3] = {0,1,0};
+    float inner_product;
+    int flag;
+    //内積の下限
+    int min_inner_product = 0.5;
+    int mask = 0xff000000;
+
+    //rgb情報の抜き出し
+    for (int i = 0; i < 4; i++) {
+        rgb[i] = (color & mask) >> (3 - i) * 8;
+        mask >>= 8;
+    }
+
+    //内積の計算
+    inner_product = innerProduct(normal_vector,light_vector);
+    //min_inner_productが下限。環境光ってやつ?
+    flag = (inner_product <= min_inner_product);
+
+    //内積をrgbにかけていく
+    for (int i = 0; i < 3; i++) {
+        rgb[i] = rgb[i]*inner_product + min_inner_product*rgb[i] * flag;
+    }
+
+    int light_rgb = rgb[0];
+    for (int i = 1; i < 4; i++) {
+        light_rgb <<= 8;
+        light_rgb |= rgb[i];
+    }
+    return light_rgb;
+}
+
+
+
+int
 DrawSpan::run(void *rbuf, void *wbuf)
 {
     SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0);