Mercurial > hg > Game > Cerium
changeset 1144:e068c1269292 draft
light fix
author | Yutaka_Kinjyo |
---|---|
date | Sat, 19 Feb 2011 03:54:12 +0900 |
parents | 786e800abfb4 |
children | 4e898dca4ab9 |
files | Renderer/Engine/spe/DrawSpan.cc Renderer/Engine/task/DrawSpan.cc Renderer/Engine/viewer.cc Renderer/Test/ball_bound.cc Renderer/Test/gaplant.cc |
diffstat | 5 files changed, 19 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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); }
--- 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); }
--- 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)
--- 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);
--- 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);