# HG changeset patch # User Yutaka_Kinjyo # Date 1298055252 -32400 # Node ID e068c126929212dba4dde0db50c4522289f3cffd # Parent 786e800abfb4f5a7a4fb19fd87930e9a5aa9c020 light fix diff -r 786e800abfb4 -r e068c1269292 Renderer/Engine/spe/DrawSpan.cc --- a/Renderer/Engine/spe/DrawSpan.cc Sat Feb 19 01:59:14 2011 +0900 +++ b/Renderer/Engine/spe/DrawSpan.cc Sat Feb 19 03:54:12 2011 +0900 @@ -452,7 +452,7 @@ int light_rgb; - float inner_product; + float inner_product = 0.2; normalize(normal_vector, normal_vector); @@ -466,7 +466,12 @@ if (light_switch[i] == 1) { light_vector = spu_sub(v_world[i],light_xyz[i]); normalize(light_vector, light_vector); - inner_product = innerProduct1(normal_vector,light_vector); + float tmp_inner_product = innerProduct1(normal_vector,light_vector); + + if (inner_product < tmp_inner_product) { + inner_product = tmp_inner_product; + } + v_inner = spu_splats(inner_product); vtmp_rgb = spu_madd(v_rgb,v_inner,vtmp_rgb); } diff -r 786e800abfb4 -r e068c1269292 Renderer/Engine/task/DrawSpan.cc --- 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); } diff -r 786e800abfb4 -r e068c1269292 Renderer/Engine/viewer.cc --- a/Renderer/Engine/viewer.cc Sat Feb 19 01:59:14 2011 +0900 +++ b/Renderer/Engine/viewer.cc Sat Feb 19 03:54:12 2011 +0900 @@ -92,7 +92,6 @@ if (spe_num == 0) spe_num = 1; sgroot = new SceneGraphRoot(this->width, this->height, manager); - //sgroot->tmanager = manager; int light_num = 4; int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4) diff -r 786e800abfb4 -r e068c1269292 Renderer/Test/ball_bound.cc --- a/Renderer/Test/ball_bound.cc Sat Feb 19 01:59:14 2011 +0900 +++ b/Renderer/Test/ball_bound.cc Sat Feb 19 03:54:12 2011 +0900 @@ -117,7 +117,7 @@ sgroot->createFromXMLfile("xml_file/Ball.xml"); - //sgroot->OnLightSysSwitch(); + sgroot->OnLightSysSwitch(); SceneGraphPtr light = sgroot->getLight(0); sgroot->OnLightSwitch(0); diff -r 786e800abfb4 -r e068c1269292 Renderer/Test/gaplant.cc --- a/Renderer/Test/gaplant.cc Sat Feb 19 01:59:14 2011 +0900 +++ b/Renderer/Test/gaplant.cc Sat Feb 19 03:54:12 2011 +0900 @@ -11,7 +11,7 @@ sgroot->createFromXMLfile("xml_file/gap_plane_test.xml"); sgroot->createFromXMLfile("xml_file/Ball.xml"); - //sgroot->OnLightSysSwitch(); + sgroot->OnLightSysSwitch(); back = sgroot->createSceneGraph(); back->set_move_collision(back_move, back_coll);