diff Renderer/Engine/task/DrawSpan.cc @ 1144:e068c1269292 draft

light fix
author Yutaka_Kinjyo
date Sat, 19 Feb 2011 03:54:12 +0900
parents b99abedb5523
children 4e898dca4ab9
line wrap: on
line diff
--- a/Renderer/Engine/task/DrawSpan.cc	Sat Feb 19 01:59:14 2011 +0900
+++ b/Renderer/Engine/task/DrawSpan.cc	Sat Feb 19 03:54:12 2011 +0900
@@ -397,10 +397,8 @@
 
     unsigned char rgb[4];
     int light_rgb;
-    int flag;
     float normal_vector[4] = {normal_x,normal_y,normal_z,0};
     float light_vector[4];
-    float inner_product;
     float *light_xyz = (float*)smanager->global_get(Light);
 
     normalize(normal_vector, normal_vector);
@@ -420,9 +418,9 @@
 
     int tmp_rgb[3] = {0,0,0};
     int light_num = 4;
+    float inner_product = 0.2; // 0.2 は環境光ってことにしてみた。
     for (int i = 0; i < light_num; i++) {
 
-
       light_vector[0] = world_x - light_xyz[i*4];
       light_vector[1] = world_y - light_xyz[i*4+1];
       light_vector[2] = light_xyz[i*4+2] - world_z;
@@ -430,19 +428,21 @@
 
       normalize(light_vector, light_vector);
 
+      float tmp_inner_product = 0;
+
       // 法線ベクトルと光源ベクトルとの内積をとる
-      inner_product = innerProduct1(normal_vector,light_vector);
-
-      //printf("inner_product %f\n",inner_product);
+      tmp_inner_product = innerProduct1(normal_vector,light_vector);
 
       // 内積がマイナスの場合は色がない。
-      flag = (inner_product > 0);      
+      if (inner_product < tmp_inner_product) {
+	inner_product = tmp_inner_product;
+      }
 
       // 内積を rgb にかけていく
 
-      tmp_rgb[0] += (unsigned char)(rgb[0]*inner_product*flag);
-      tmp_rgb[1] += (unsigned char)(rgb[1]*inner_product*flag);
-      tmp_rgb[2] += (unsigned char)(rgb[2]*inner_product*flag);
+      tmp_rgb[0] = (unsigned char)(rgb[0]*inner_product);
+      tmp_rgb[1] = (unsigned char)(rgb[1]*inner_product);
+      tmp_rgb[2] = (unsigned char)(rgb[2]*inner_product);
 
     }