diff --git a/docs/modding_lua.txt b/docs/modding_lua.txt index faf4584..7c27984 100644 --- a/docs/modding_lua.txt +++ b/docs/modding_lua.txt @@ -293,6 +293,9 @@ px, py, pz = client.camera_get_pos() @ dx, dy, dz = client.camera_get_forward() @ gets the camera's forward vector +client.camera_shade_set(xn, yn, zn, xp, yp, zp) + sets the face shading levels per face (0 <= v <= 1) + pmf = common.model_new(bonemax = 5) @ creates a new model remember to free it when you're done diff --git a/include/common.h b/include/common.h index 751ed75..b7f74ff 100644 --- a/include/common.h +++ b/include/common.h @@ -19,7 +19,7 @@ #define VERSION_X 0 #define VERSION_Y 0 #define VERSION_A 0 -#define VERSION_Z 12 +#define VERSION_Z 13 // Remember to bump "Z" basically every time you change the engine! // Remember to bump the version in Lua too! // Remember to document API changes in a new version! @@ -438,6 +438,7 @@ extern int render_face_remain; #define FOG_INIT_DISTANCE 60.0f extern float fog_distance; extern uint32_t fog_color; +extern uint32_t cam_shading[6]; void render_vxl_redraw(camera_t *camera, map_t *map); void render_cubemap(uint32_t *pixels, int width, int height, int pitch, camera_t *camera, map_t *map); void render_pmf_bone(uint32_t *pixels, int width, int height, int pitch, camera_t *cam_base, diff --git a/pkg/base/version.lua b/pkg/base/version.lua index c5bd60e..85c8c48 100644 --- a/pkg/base/version.lua +++ b/pkg/base/version.lua @@ -16,9 +16,9 @@ ]] VERSION_ENGINE = { - cmp={0,0,0,0,12}, - num=12, - str="0.0-12", + cmp={0,0,0,0,13}, + num=13, + str="0.0-13", } VERSION_BUGS = { @@ -35,4 +35,6 @@ VERSION_BUGS = { {intro=nil, fix=10, msg="Immediate ceiling isn't drawn"}, {intro=nil, fix=11, msg="Blocks appear inverted in common cases"}, {intro=nil, fix=12, msg="TGA loader prone to crashing on unsanitised data"}, +{intro=nil, fix=13, msg="No per-face shading"}, +{intro=nil, fix=nil, msg="Per-face shading is only preliminary"}, } diff --git a/src/lua_camera.h b/src/lua_camera.h index 478066f..b6c8d2f 100644 --- a/src/lua_camera.h +++ b/src/lua_camera.h @@ -141,3 +141,23 @@ int icelua_fn_client_screen_get_dims(lua_State *L) return 2; } + +int icelua_fn_client_camera_shading_set(lua_State *L) +{ + int top = icelua_assert_stack(L, 6, 6); + + int i; + for(i = 0; i < 6; i++) + { + float v = lua_tonumber(L, i+1); + if(v < 0.0f) v = 0.0f; + if(v > 1.0f) v = 1.0f; + uint32_t s = v*255; + if(s >= 128) s++; + s *= 0x010001; + cam_shading[i] = s; + } + + return 0; +} + diff --git a/src/render.c b/src/render.c index ba52de3..e73ec9d 100644 --- a/src/render.c +++ b/src/render.c @@ -47,6 +47,15 @@ enum CM_MAX }; +int cam_shading_map[6][4] = { + {CM_PZ, CM_NZ, CM_PY, CM_NY}, + {CM_NX, CM_PX, CM_PZ, CM_NZ}, + {CM_NX, CM_PX, CM_PY, CM_NY}, + {CM_NZ, CM_PZ, CM_PY, CM_NY}, + {CM_PX, CM_NX, CM_NZ, CM_PZ}, + {CM_PX, CM_NX, CM_PY, CM_NY}, +}; + uint32_t *cubemap_color[CM_MAX]; float *cubemap_depth[CM_MAX]; int cubemap_size; @@ -60,6 +69,10 @@ int rtmp_width, rtmp_height, rtmp_pitch; camera_t *rtmp_camera; map_t *rtmp_map; +uint32_t cam_shading[6] = { + 0x000C0, 0x000A0, 0x000D0, 0x000E0, 0x00FF, 0x000D0, +}; + typedef struct raydata { int16_t x,y,z; int8_t gx,gz; @@ -632,7 +645,14 @@ void render_vxl_cube_vtrap(uint32_t *ccolor, float *cdepth, } } -void render_vxl_cube_sides(uint32_t *ccolor, float *cdepth, int x1, int y1, int x2, int y2, uint32_t color, float depth) +uint32_t render_shade(uint32_t color, int face) +{ + uint32_t fc = cam_shading[face]; + return (((((color&0x00FF00FF)*fc)>>8)&0x00FF00FF)) + |((((((color>>8)&0x00FF00FF)*fc))&0xFF00FF00))|0x01000000; +} + +void render_vxl_cube_sides(uint32_t *ccolor, float *cdepth, int x1, int y1, int x2, int y2, uint32_t color, float depth, int face) { int hsize = (cubemap_size>>1); @@ -647,7 +667,7 @@ void render_vxl_cube_sides(uint32_t *ccolor, float *cdepth, int x1, int y1, int if(x2 < x4) x2 = x4; if(y2 < y4) y2 = y4; - render_vxl_rect_ftb_fast(ccolor, cdepth, x1, y1, x2, y2, color, depth+0.5f); + render_vxl_rect_ftb_fast(ccolor, cdepth, x1, y1, x2, y2, render_shade(color, face), depth+0.5f); return; } @@ -656,32 +676,32 @@ void render_vxl_cube_sides(uint32_t *ccolor, float *cdepth, int x1, int y1, int int x4 = ((x2-hsize)*depth)/(depth+1.0f)+hsize; int y4 = ((y2-hsize)*depth)/(depth+1.0f)+hsize+1; - render_vxl_rect_ftb_fast(ccolor, cdepth, x1, y1, x2, y2, color, depth); + render_vxl_rect_ftb_fast(ccolor, cdepth, x1, y1, x2, y2, render_shade(color, face), depth); depth += 0.5f; if(y3 < y1) render_vxl_cube_htrap(ccolor, cdepth, x3, x4, y3, x1, x2, y1, - color, depth+1.0f); + render_shade(color, cam_shading_map[face][2]), depth+1.0f); else if(y2 < y4) render_vxl_cube_htrap(ccolor, cdepth, x1, x2, y2, x3, x4, y4, - color, depth+1.0f); + render_shade(color, cam_shading_map[face][3]), depth+1.0f); if(x3 < x1) render_vxl_cube_vtrap(ccolor, cdepth, x3, y3, y4, x1, y1, y2, - color, depth+1.0f); + render_shade(color, cam_shading_map[face][0]), depth+1.0f); else if(x2 < x4) render_vxl_cube_vtrap(ccolor, cdepth, x2, y1, y2, x4, y3, y4, - color, depth+1.0f); + render_shade(color, cam_shading_map[face][1]), depth+1.0f); } -void render_vxl_cube(uint32_t *ccolor, float *cdepth, int x1, int y1, int x2, int y2, uint32_t color, float depth) +void render_vxl_cube(uint32_t *ccolor, float *cdepth, int x1, int y1, int x2, int y2, uint32_t color, float depth, int face) { - render_vxl_cube_sides(ccolor, cdepth, x1, y1, x2, y2, color, depth); + render_vxl_cube_sides(ccolor, cdepth, x1, y1, x2, y2, color, depth, face); } void render_vxl_face_raycast(int blkx, int blky, int blkz, @@ -781,7 +801,7 @@ void render_vxl_face_raycast(int blkx, int blky, int blkz, render_vxl_cube(ccolor, cdepth, (int)px1, (int)py1, (int)px2, (int)py2, - xcolor, sz); + xcolor, sz, face); } }