# HG changeset patch # User e065725@yutaka.st.ie.u-ryukyu.ac.jp # Date 1244533440 -32400 # Node ID a7ff291104749e9e3e1abcde54ff13e03eb8b81c # Parent 2ddf79a7c5fbe7095e927d67e3823689f9b00646 add pre light diff -r 2ddf79a7c5fb -r a7ff29110474 TaskManager/Test/test_render/Span.h --- a/TaskManager/Test/test_render/Span.h Tue Jun 09 01:22:11 2009 +0900 +++ b/TaskManager/Test/test_render/Span.h Tue Jun 09 16:44:00 2009 +0900 @@ -45,6 +45,9 @@ float tex_x2; float tex_y1; float tex_y2; + float normal_x; + float normal_y; + float normal_z; #if 0 TileInfoListPtr tilelist; diff -r 2ddf79a7c5fb -r a7ff29110474 TaskManager/Test/test_render/polygon_pack.h --- a/TaskManager/Test/test_render/polygon_pack.h Tue Jun 09 01:22:11 2009 +0900 +++ b/TaskManager/Test/test_render/polygon_pack.h Tue Jun 09 16:44:00 2009 +0900 @@ -15,6 +15,12 @@ float tex_y; } VertexPack, *VertexPackPtr; // 20 +typedef struct NormalPack { + float x; + float y; + float z; +} NormalPack, *NormalPackPtr; // 12 + typedef struct TriTexInfo { uint32 *addr; int width; @@ -27,11 +33,14 @@ VertexPack ver1; VertexPack ver2; VertexPack ver3; + NormalPack normal1; + NormalPack normal2; + NormalPack normal3; } TrianglePack, *TrianglePackPtr; typedef struct PolygonPack { - struct PORIGON_info { + struct POLYGON_info { int size; int light_pos[3]; int light_rgb[3]; diff -r 2ddf79a7c5fb -r a7ff29110474 TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp --- a/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp Tue Jun 09 01:22:11 2009 +0900 +++ b/TaskManager/Test/test_render/task/CreatePolygonFromSceneGraph.cpp Tue Jun 09 16:44:00 2009 +0900 @@ -59,6 +59,13 @@ CreatePolygonFromSceneGraph::run(void *rbuf, void *wbuf) { float xyz1[4], xyz2[4], xyz3[4]; + /* + *頂点毎に法線ベクトルがある + *面毎じゃない + *なにかに使うのかな?わからないから、一応とっておく。 + *by yutaka + */ + float normal1[4],normal2[4],normal3[4]; SceneGraphPtr sg_top = (SceneGraphPtr)smanager->get_param(0); SceneGraphPtr sg = sg_top; @@ -148,6 +155,39 @@ triangle->ver3.z = xyz3[2]; triangle->ver3.tex_x = sg->coord_tex[(i+2)*3]; triangle->ver3.tex_y = sg->coord_tex[(i+2)*3+1]; + + //法線もApplyMatrixとかするのかな?一応値をとっておくby yutaka + + normal1[0] = sg->normal[(i+0)*3]; + normal1[1] = sg->normal[(i+0)*3+1]; + normal1[2] = sg->normal[(i+0)*3+2]; + normal1[3] = 1.0f; + + normal2[0] = sg->normal[(i+1)*3]; + normal2[1] = sg->normal[(i+1)*3+1]; + normal2[2] = sg->normal[(i+1)*3+2]; + normal2[3] = 1.0f; + + normal3[0] = sg->normal[(i+2)*3]; + normal3[1] = sg->normal[(i+2)*3+1]; + normal3[2] = sg->normal[(i+2)*3+2]; + normal3[3] = 1.0f; + + //ここでpolygonに法線ベクトルの情報がわたったby yutaka + + triangle->normal1.x = normal1[0]; + triangle->normal1.y = normal1[1]; + triangle->normal1.z = normal1[2]; + + triangle->normal2.x = normal2[0]; + triangle->normal2.y = normal2[1]; + triangle->normal2.z = normal2[2]; + + triangle->normal3.x = normal3[0]; + triangle->normal3.y = normal3[1]; + triangle->normal3.z = normal3[2]; + + triangle->tex_info.addr = sg->texture_info.pixels; triangle->tex_info.width = sg->texture_info.t_w; diff -r 2ddf79a7c5fb -r a7ff29110474 TaskManager/Test/test_render/task/CreateSpan.cpp --- a/TaskManager/Test/test_render/task/CreateSpan.cpp Tue Jun 09 01:22:11 2009 +0900 +++ b/TaskManager/Test/test_render/task/CreateSpan.cpp Tue Jun 09 16:44:00 2009 +0900 @@ -31,7 +31,8 @@ */ static void make_vertex(TrianglePack *triPack, - VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax) + VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax, + NormalPackPtr *normal1, NormalPackPtr *normal2, NormalPackPtr *normal3) { if (triPack->ver1.y <= triPack->ver2.y) { if (triPack->ver2.y <= triPack->ver3.y) { @@ -62,6 +63,11 @@ *vMax = &triPack->ver1; } } + + *normal1 = &triPack->normal1; + *normal2 = &triPack->normal2; + *normal3 = &triPack->normal3; + } static void @@ -193,6 +199,7 @@ int charge_y_top, int charge_y_end, TriangleTexInfoPtr tex_info, VertexPack *vMin,VertexPack *vMid,VertexPack *vMid10, + NormalPack *normal1, NormalPack *normal2, NormalPack *normal3, int length_y, float tex_y_len) { float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; @@ -372,6 +379,13 @@ span->tex_x2 = end_tex_x; span->tex_y1 = start_tex_y; span->tex_y2 = end_tex_y; + /*ここで頂点分法線ベクトルがあったんだけど、 + * 一つだけ取り出して、spanに一つの法線ベクトルを持たしている + *by yutaka + */ + span->normal_x = normal1->x; + span->normal_y = normal1->y; + span->normal_z = normal1->z; float tex_x_len = span->tex_x2 - span->tex_x1; @@ -417,7 +431,7 @@ VertexPackPtr vMin, vMid, vMax; VertexPackPtr vMid10 = (VertexPackPtr)smanager->allocate(sizeof(VertexPack)); - + NormalPackPtr normal1,normal2, normal3; SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1); spack = (SpanPackPtr)smanager->get_input(2); send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); @@ -443,7 +457,7 @@ TriangleTexInfoPtr tri_tex_info = &triPack->tex_info; - make_vertex(triPack, &vMin, &vMid, &vMax); + make_vertex(triPack, &vMin, &vMid, &vMax, &normal1, &normal2, &normal3); make_vMid10(vMid10, vMin, vMid, vMax); /** @@ -468,9 +482,11 @@ */ half_triangle(spackList, charge_y_top, charge_y_end, tri_tex_info, vMin, vMid, vMid10, + normal1,normal2,normal3, (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); half_triangle(spackList, charge_y_top, charge_y_end, tri_tex_info, vMax, vMid, vMid10, + normal1,normal2,normal3, (int)(vMax->y - vMin->y), vMax->tex_y - vMin->tex_y); } diff -r 2ddf79a7c5fb -r a7ff29110474 TaskManager/Test/test_render/task/CreateSpan.h --- a/TaskManager/Test/test_render/task/CreateSpan.h Tue Jun 09 01:22:11 2009 +0900 +++ b/TaskManager/Test/test_render/task/CreateSpan.h Tue Jun 09 16:44:00 2009 +0900 @@ -22,6 +22,7 @@ int charge_y_top, int charge_y_end, TriangleTexInfoPtr tex_info, VertexPack *vMin,VertexPack *vMid,VertexPack *vMid1, + NormalPack *normal1, NormalPack *normal2, NormalPack *normal3, int length_y, float tex_y_len); }; diff -r 2ddf79a7c5fb -r a7ff29110474 TaskManager/Test/test_render/task/DrawSpan.cpp --- 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); diff -r 2ddf79a7c5fb -r a7ff29110474 TaskManager/Test/test_render/task/DrawSpan.h --- a/TaskManager/Test/test_render/task/DrawSpan.h Tue Jun 09 01:22:11 2009 +0900 +++ b/TaskManager/Test/test_render/task/DrawSpan.h Tue Jun 09 16:44:00 2009 +0900 @@ -42,7 +42,7 @@ void writebuffer(unsigned int display, int width, int height, int screen_width); void updateBuffer(float zpos, int rangex, int x, int y, - int tex_x, int tex_y, uint32 *tex_addr); + int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z, uint32 *tex_addr); void reboot(SpanPackPtr spack, int cur_span_x); @@ -51,6 +51,7 @@ void drawDot2(SpanPtr span, int startx, int endx, int js, int wait_tag); int drawLine1(SpanPtr span, int startx, int endx, int wait_tag); void drawLine2(SpanPtr span, int startx, int endx, int js, int wait_tag); + int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z); }; typedef struct {