1 // Bump effect (not moving yet of course, I have many ideas on this to commit before it's ready)
11 static int init(void);
12 static void destroy(void);
13 static void start(long trans_time);
14 static void stop(long trans_time);
15 static void draw(void);
17 static struct screen scr = {
26 static unsigned long startingTime;
28 static unsigned char *heightmap;
29 static unsigned short *lightmap;
30 static int *bumpOffset;
32 struct screen *bump_screen(void)
39 const int numBlurs = 3;
41 int fb_size = fb_width * fb_height;
45 heightmap = malloc(sizeof(*heightmap) * fb_size);
46 lightmap = malloc(sizeof(*lightmap) * fb_size);
47 bumpOffset = malloc(sizeof(*bumpOffset) * fb_size);
49 memset(lightmap, 0, fb_size);
50 memset(bumpOffset, 0, fb_size);
53 for (i = 0; i < fb_size; i++)
54 heightmap[i] = rand() & 255;
57 for (j = 0; j < numBlurs; j++)
58 for (i = 0; i < fb_size; i++)
59 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;
61 // Inclination precalculation
63 for (y = 0; y < fb_height; y++)
65 for (x = 0; x < fb_width; x++)
67 const float offsetPower = 2.0f;
70 dx = (int)((heightmap[i] - heightmap[i + 1]) * offsetPower);
71 dy = (int)((heightmap[i] - heightmap[i + fb_width]) * offsetPower);
75 if (xp > fb_width - 1) xp = fb_width - 1;
79 if (yp > fb_height - 1) yp = fb_height - 1;
81 bumpOffset[i++] = yp * fb_width + xp;
85 // 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)
87 for (y = 0; y < fb_height; y++)
89 int yc = y - (fb_height >> 1);
90 for (x = 0; x < fb_width; x++)
92 int xc = x - (fb_width >> 1);
93 int c = (int)sqrt(xc * xc + yc * yc) << 1;
97 lightmap[i++] = ((r >> 4) << 11) | ((r >> 3) << 5) | (r >> 3);
104 static void destroy(void)
108 static void start(long trans_time)
110 startingTime = time_msec;
113 static void stop(long trans_time)
117 static void draw(void)
120 unsigned short *vram = (unsigned short*)fb_pixels;
121 for (i = 0; i < fb_width * fb_height; i++)
123 unsigned short c = lightmap[bumpOffset[i]];
127 drawFps((unsigned short*)fb_pixels);