From: John Tsiombikas Date: Tue, 28 Aug 2018 13:44:48 +0000 (+0300) Subject: backdrop X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosrtxon;a=commitdiff_plain;h=6952fc3d7981a73ffbabeca5dca741fd790949cc backdrop --- diff --git a/src/noise.c b/src/noise.c new file mode 100644 index 0000000..7c1debd --- /dev/null +++ b/src/noise.c @@ -0,0 +1,459 @@ +#include +#include +#include "noise.h" + +/* ---- Ken Perlin's implementation of noise ---- */ +#define B 0x100 +#define BM 0xff +#define N 0x1000 +#define NP 12 /* 2^N */ +#define NM 0xfff + +#define s_curve(t) (t * t * (3.0f - 2.0f * t)) + +#define setup(elem, b0, b1, r0, r1) \ + do { \ + float t = elem + N; \ + b0 = ((int)t) & BM; \ + b1 = (b0 + 1) & BM; \ + r0 = t - (int)t; \ + r1 = r0 - 1.0f; \ + } while(0) + +#define setup_p(elem, b0, b1, r0, r1, p) \ + do { \ + float t = elem + N; \ + b0 = (((int)t) & BM) % p; \ + b1 = ((b0 + 1) & BM) % p; \ + r0 = t - (int)t; \ + r1 = r0 - 1.0f; \ + } while(0) + + +static int perm[B + B + 2]; /* permuted index from g_n onto themselves */ +static float grad3[B + B + 2][3]; /* 3D random gradients */ +static float grad2[B + B + 2][2]; /* 2D random gradients */ +static float grad1[B + B + 2]; /* 1D random ... slopes */ +static int tables_valid; + +#define init_once() if(!tables_valid) init_noise() + +#define SQ(x) ((x) * (x)) +#define LERP(a, b, t) ((a) + ((b) - (a)) * (t)) + +static void init_noise() +{ + int i; + float len; + + /* calculate random gradients */ + for(i=0; i #include #include +#include +#include #include "demo.h" #include "3dgfx.h" #include "screen.h" #include "cfgopt.h" #include "polyfill.h" #include "imago2.h" +#include "util.h" #include "gfxutil.h" #include "mesh.h" +#include "noise.h" static int init(void); static void destroy(void); @@ -33,6 +37,16 @@ static const char *cartex_fname[2] = {"data/ldiablo.png", 0}; static struct g3d_mesh mesh_car[2]; static struct pimage tex_car[2]; +#define BGCOL_SIZE 128 +#define BGOFFS_SIZE 1024 +static uint16_t bgcol[BGCOL_SIZE]; +static uint16_t bgcol_mir[BGCOL_SIZE]; +static int bgoffs[BGOFFS_SIZE]; +static const int colzen[] = {98, 64, 192}; +static const int colhor[] = {128, 80, 64}; +static const int colmnt[] = {16, 9, 24}; +static uint16_t mountcol, mountcol_mir; + static int shading = G3D_TEX_GOURAUD; static int do_clip = 1; @@ -45,6 +59,25 @@ struct screen *rtxonoff_screen(void) static int init(void) { int i; + int col[3]; + + mountcol = PACK_RGB16(colmnt[0], colmnt[1], colmnt[2]); + mountcol_mir = PACK_RGB16(colmnt[0] / 2, colmnt[1] / 2, colmnt[2] / 2); + + for(i=0; i> 8); + col[1] = colhor[1] + ((colzen[1] - colhor[1]) * t >> 8); + col[2] = colhor[2] + ((colzen[2] - colhor[2]) * t >> 8); + bgcol[i] = PACK_RGB16(col[0], col[1], col[2]); + bgcol_mir[i] = PACK_RGB16(col[0] / 2, col[1] / 2, col[2] / 2); + } + + for(i=0; i fb_height) hory = fb_height; + + if(hory > 0) { + fbptr = fb_pixels + (hory - 1) * fb_width; + cidx = offs; + i = 0; + while(fbptr >= fb_pixels) { + pcol = bgcol[cidx < 0 ? 0 : (cidx >= BGCOL_SIZE ? BGCOL_SIZE - 1 : cidx)]; + for(j=0; j= BGCOL_SIZE ? BGCOL_SIZE - 1 : cidx)]; + for(j=0; j