comparison 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
comparison
equal deleted inserted replaced
1143:786e800abfb4 1144:e068c1269292
395 { 395 {
396 396
397 397
398 unsigned char rgb[4]; 398 unsigned char rgb[4];
399 int light_rgb; 399 int light_rgb;
400 int flag;
401 float normal_vector[4] = {normal_x,normal_y,normal_z,0}; 400 float normal_vector[4] = {normal_x,normal_y,normal_z,0};
402 float light_vector[4]; 401 float light_vector[4];
403 float inner_product;
404 float *light_xyz = (float*)smanager->global_get(Light); 402 float *light_xyz = (float*)smanager->global_get(Light);
405 403
406 normalize(normal_vector, normal_vector); 404 normalize(normal_vector, normal_vector);
407 405
408 // 引数で受け取った color の rgb 情報の抜き出し 406 // 引数で受け取った color の rgb 情報の抜き出し
418 rgb[0] = (color & 0x000000ff); 416 rgb[0] = (color & 0x000000ff);
419 #endif 417 #endif
420 418
421 int tmp_rgb[3] = {0,0,0}; 419 int tmp_rgb[3] = {0,0,0};
422 int light_num = 4; 420 int light_num = 4;
421 float inner_product = 0.2; // 0.2 は環境光ってことにしてみた。
423 for (int i = 0; i < light_num; i++) { 422 for (int i = 0; i < light_num; i++) {
424
425 423
426 light_vector[0] = world_x - light_xyz[i*4]; 424 light_vector[0] = world_x - light_xyz[i*4];
427 light_vector[1] = world_y - light_xyz[i*4+1]; 425 light_vector[1] = world_y - light_xyz[i*4+1];
428 light_vector[2] = light_xyz[i*4+2] - world_z; 426 light_vector[2] = light_xyz[i*4+2] - world_z;
429 light_vector[3] = light_xyz[i*4+3]; 427 light_vector[3] = light_xyz[i*4+3];
430 428
431 normalize(light_vector, light_vector); 429 normalize(light_vector, light_vector);
432 430
431 float tmp_inner_product = 0;
432
433 // 法線ベクトルと光源ベクトルとの内積をとる 433 // 法線ベクトルと光源ベクトルとの内積をとる
434 inner_product = innerProduct1(normal_vector,light_vector); 434 tmp_inner_product = innerProduct1(normal_vector,light_vector);
435
436 //printf("inner_product %f\n",inner_product);
437 435
438 // 内積がマイナスの場合は色がない。 436 // 内積がマイナスの場合は色がない。
439 flag = (inner_product > 0); 437 if (inner_product < tmp_inner_product) {
438 inner_product = tmp_inner_product;
439 }
440 440
441 // 内積を rgb にかけていく 441 // 内積を rgb にかけていく
442 442
443 tmp_rgb[0] += (unsigned char)(rgb[0]*inner_product*flag); 443 tmp_rgb[0] = (unsigned char)(rgb[0]*inner_product);
444 tmp_rgb[1] += (unsigned char)(rgb[1]*inner_product*flag); 444 tmp_rgb[1] = (unsigned char)(rgb[1]*inner_product);
445 tmp_rgb[2] += (unsigned char)(rgb[2]*inner_product*flag); 445 tmp_rgb[2] = (unsigned char)(rgb[2]*inner_product);
446 446
447 } 447 }
448 448
449 int rgb_flag[3]; 449 int rgb_flag[3];
450 for (int i = 0; i < 3; i++) { 450 for (int i = 0; i < 3; i++) {