1 // Bump effect (not moving yet of course, I have many ideas on this to commit before it's ready)
12 static int init(void);
13 static void destroy(void);
14 static void start(long trans_time);
15 static void stop(long trans_time);
16 static void draw(void);
18 static struct screen scr = {
27 static unsigned long startingTime;
29 static unsigned char *heightmap;
30 static unsigned short *lightmap;
31 static int *bumpOffset;
33 struct screen *bump_screen(void)
40 const int numBlurs = 3;
42 int fb_size = fb_width * fb_height;
46 heightmap = malloc(sizeof(*heightmap) * fb_size);
47 lightmap = malloc(sizeof(*lightmap) * fb_size);
48 bumpOffset = malloc(sizeof(*bumpOffset) * fb_size);
50 memset(lightmap, 0, fb_size);
51 memset(bumpOffset, 0, fb_size);
54 for (i = 0; i < fb_size; i++)
55 heightmap[i] = rand() & 255;
58 for (j = 0; j < numBlurs; j++)
59 for (i = 0; i < fb_size; i++)
60 heightmap[i] = (heightmap[abs((i - 1) % fb_size)] + heightmap[abs((i + 1) % fb_size)] + heightmap[abs((i - fb_width) % fb_size)] + heightmap[abs((i + fb_width) % fb_size)]) >> 2;
62 // Inclination precalculation
64 for (y = 0; y < fb_height; y++)
66 for (x = 0; x < fb_width; x++)
68 const float offsetPower = 2.0f;
71 dx = (int)((heightmap[i] - heightmap[i + 1]) * offsetPower);
72 dy = (int)((heightmap[i] - heightmap[i + fb_width]) * offsetPower);
76 if (xp > fb_width - 1) xp = fb_width - 1;
80 if (yp > fb_height - 1) yp = fb_height - 1;
82 bumpOffset[i++] = yp * fb_width + xp;
86 // Lightmap test (this will be replaced by code in the main loop later on, the idea is you can render moving lights and other light geometry or sprites in light buffer and the bumpOffset will catch them)
88 for (y = 0; y < fb_height; y++)
90 int yc = y - (fb_height >> 1);
91 for (x = 0; x < fb_width; x++)
93 int xc = x - (fb_width >> 1);
94 int c = (int)sqrt(xc * xc + yc * yc) << 1;
98 lightmap[i++] = ((r >> 4) << 11) | ((r >> 3) << 5) | (r >> 3);
105 static void destroy(void)
109 static void start(long trans_time)
111 startingTime = time_msec;
114 static void stop(long trans_time)
118 static void draw(void)
121 unsigned short *vram = (unsigned short*)fb_pixels;
122 for (i = 0; i < fb_width * fb_height; i++)
124 unsigned short c = lightmap[bumpOffset[i]];
128 drawFps((unsigned short*)fb_pixels);