diff --git a/haloo3d b/haloo3d index a30aea9..6472c00 160000 --- a/haloo3d +++ b/haloo3d @@ -1 +1 @@ -Subproject commit a30aea9dac005602b64d9591f906407bccbd88e2 +Subproject commit 6472c00bda48e7fc29508913e08c90cb801ceb25 diff --git a/terrain.c b/terrain.c index d195c9e..3ddb906 100644 --- a/terrain.c +++ b/terrain.c @@ -70,8 +70,9 @@ #define LANDCOL 0xF6D2 // 0xF4E1 #define FLANDCOL 0xF260 // 0xF3A0 // 0xF4E1 #define UWLANDCOL 0xF026 -#define SEACOL 0xF28D // 0xF26C -#define SKYCOL 0xFA7F // 0xF77F +#define SEACOL 0xF28D // 0xF26C +#define SKYCOL 0xF96E // 0xF77F +#define SKYCOL2 0xFFAF // 0xF77F #define CLOUDCOL 0xFFFF #define TREECOL 0xF070 #define TREETRUNKCOL 0xF950 @@ -79,7 +80,7 @@ #define YELLOWFLOWERCOL 0xFEE0 #define TOWERCOL 0xF111 #define LIGHTCOL 0xFF00 -#define TOWERLOW 0.758 // small changes to this make a huge difference +#define TOWERLOW 0.755 // small changes to this make a huge difference #define TOWERLIGHTMINSIZE (CHUNKSCALE * 0.1) #define TOWERLIGHTMAXSIZE (CHUNKSCALE * 0.5) #define TOWERLIGHTMINTRANS 0 @@ -453,6 +454,9 @@ void sys_rendercontext(ecs_rendercontext *erc, ecs_placement *p, tecs **ecs) { if (rc->windowclear & 0xF000) { haloo3d_fb_clear(&rc->window, rc->windowclear); } + if (rc->backtex) { + haloo3d_fb_fill_raw(&rc->window, rc->backtex, 0); + } // Precalc stuff for later object rendering rc->precalc_halfwidth = rc->window.width * H3DVF(0.5); rc->precalc_halfheight = rc->window.height * H3DVF(0.5); @@ -712,6 +716,58 @@ ecs_eid setup_sea(tecs *ecs, render_context *ctx, ecs_placement *playerpos, return seaid; } +void draw_gradient(haloo3d_fb *buf, uint16_t topcol, uint16_t botcol, + int height) { + // Precalc an array indicating the bands of color. + int row[64]; // not sure how many bands there can be but... + uint16_t col[64]; + int bandscount = 1; + row[0] = 0; + col[0] = topcol; + uint8_t dither[4]; + for (int y = 1; y < height; y++) { + uint16_t thiscol = + haloo3d_col_lerp(topcol, botcol, (float)y / (height - 1)); + if (thiscol != col[bandscount - 1]) { + row[bandscount] = y; + col[bandscount] = thiscol; + bandscount++; + } + } + for (int band = 0; band < bandscount - 1; band++) { + for (int r = row[band]; r < row[band + 1]; r++) { + haloo3d_getdither4x4((float)(r - row[band]) / (row[band + 1] - row[band]), + dither); + uint8_t df = dither[r & 3]; + for (int b = 0; b < 8; b++) { + haloo3d_fb_set(buf, b, r, (df & 1) ? col[band + 1] : col[band]); + df >>= 1; + // haloo3d_col_lerp(topcol, botcol, (float)y / (height - 1))); + } + uint16_t *bufstart = buf->buffer + r * buf->width; + // Then, a repeated growing copy to minimize copies? IDK + for (int size = 8; size < buf->width; size <<= 1) { + memcpy(bufstart + size, bufstart, + sizeof(uint16_t) * MIN(size, buf->width - size)); + } + } + } + // int band = 0; + // for (int y = 0; y < height; y++) { + // // Calculate dither between the two colors + // // Fill the initial section + // haloo3d_fb_set(buf, 0, y, + // haloo3d_col_lerp(topcol, botcol, (float)y / (height - + // 1))); + // uint16_t *bufstart = buf->buffer + y * buf->width; + // // Then, a repeated growing copy to minimize copies? IDK + // for (int size = 1; size < buf->width; size <<= 1) { + // memcpy(bufstart + size, bufstart, + // sizeof(uint16_t) * MIN(size, buf->width - size)); + // } + // } +} + // --------------------------------------------------- // MAIN FUNCTION // --------------------------------------------------- @@ -744,8 +800,16 @@ int main() { // int argc, char **argv) { haloo3d_easytimer_init(&drawtimer, AVGWEIGHT); haloo3d_easytimer_init(&sdltimer, AVGWEIGHT); + haloo3d_fb skygrad; + haloo3d_fb_init_tex(&skygrad, 1 << (int)ceil(log2(WIDTH)), + 1 << (int)ceil(log2(HEIGHT))); + haloo3d_fb_clear(&skygrad, SKYCOL2); + draw_gradient(&skygrad, SKYCOL, SKYCOL2, HEIGHT / 2); + eprintf("Sky texture size: %dx%d\n", skygrad.width, skygrad.height); + render_context context; - context.windowclear = SKYCOL; + context.backtex = &skygrad; + context.windowclear = 0; // SKYCOL; context.nearclip = INIT_NEARCLIP; context.farclip = INIT_FARCLIP; context.fov = INIT_FOV; diff --git a/terrain_ecstypes.h b/terrain_ecstypes.h index e2e2b29..2e6b2c0 100644 --- a/terrain_ecstypes.h +++ b/terrain_ecstypes.h @@ -21,6 +21,7 @@ typedef struct { mfloat_t farclip; // NOTE: aspect ratio calculated from window haloo3d_fb window; + haloo3d_fb *backtex; // Baseline render settings. Some of these settings will be applied to // each object associated with this context haloo3d_trirender rendersettings;