summaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c101
1 files changed, 75 insertions, 26 deletions
diff --git a/map.c b/map.c
index d1dcbb8..19612bf 100644
--- a/map.c
+++ b/map.c
@@ -86,7 +86,7 @@ int trace_ray(
step_ray(&r);
}
end:
- return vec_dist(w, pos, t, 3) < 100;
+ return vec_dist(w, pos, t, 3) < 2;
}
void init_tile(Map* m, int tx, int ty, Map_Light_Tile* t) {
@@ -109,6 +109,68 @@ void init_tile(Map* m, int tx, int ty, Map_Light_Tile* t) {
}
}
+Colour bake_pixel(
+ Map* m,
+ Colour src,
+ const int* fr,
+ const Map_Light* light,
+ int tx,
+ int ty,
+ int x,
+ int y,
+ int side
+) {
+ int to[3];
+ switch (side) {
+ case 0: /* ceiling */
+ to[0] = (tx + x * 32);
+ to[1] = (ty + y * 32);
+ to[2] = f1;
+ break;
+ case 1: /* floor */
+ to[0] = (tx + x * 32);
+ to[1] = (ty + y * 32);
+ to[2] = 0;
+ break;
+ case 2:
+ to[0] = ty + f1;
+ to[1] = tx + f1 - x * 32;
+ to[2] = f1 - (y * 32);
+ break;
+ case 3:
+ to[0] = ty + x * 32;
+ to[1] = tx + f1;
+ to[2] = f1 - (y * 32);
+ break;
+ case 4:
+ to[0] = tx + f1;
+ to[1] = ty + f1 - x * 32;
+ to[2] = f1 - (y * 32);
+ break;
+ case 5:
+ to[0] = tx + x * 32;
+ to[1] = ty + f1;
+ to[2] = f1 - (y * 32);
+ break;
+ default: return make_white();
+ }
+ if (trace_ray(m, fr, to)) {
+ int w[3];
+ int atten = vec_dist(w, fr, to, 3);
+ atten = mini(
+ (f1 << fbits) / maxi(1, (atten * atten) >> fbits),
+ f1
+ ) - 1;
+ atten = (atten * light->brightness) >> fbits;
+ return col_add(src, col_scl(
+ light->c,
+ (unsigned char)(atten / 2)
+ ));
+ return make_white();
+ }
+ return src;
+}
+
void bake_tile(
Map* m,
int tx,
@@ -116,36 +178,23 @@ void bake_tile(
Map_Light_Tile* t,
const Map_Light* light
) {
- int i, x, y, fr[3], w[3];
- Map_Tile wall = map_tilesc(m)[tx + ty * m->w];
+ int i, x, y, fr[3];
tx <<= fbits;
ty <<= fbits;
fr[0] = light->x;
fr[1] = light->y;
- fr[2] = f1/2;
+ fr[2] = light->z;
for (i = y = 0; y < map_light_tile_size; y++) {
for (x = 0; x < map_light_tile_size; x++, i++) {
- int to[3];
- int atten;
- Colour c;
- to[0] = tx + x * 32;
- to[1] = ty + y * 32;
- to[2] = f1;
- atten = vec_dist(w, fr, to, 3);
- atten /= 5;
- atten = mini(
- (f1 << fbits) / maxi(1, (atten * atten) >> fbits),
- f1
- ) - 1;
- c = col_scl(
- light->c,
- (unsigned char)(atten / 2)
- );
- if (trace_ray(m, fr, to))
- t->fragments[i].u = c;
- to[2] = 0;
- if (trace_ray(m, fr, to))
- t->fragments[i].d = c;
+ Map_Fragment* f = &t->fragments[i];
+#define bp(t, s) \
+ f->t = bake_pixel(m, f->t, fr, light, tx, ty, x, y, s);
+ bp(u, 0);
+ bp(d, 1);
+ bp(side[0], 2);
+ bp(side[1], 3);
+ bp(side[2], 4);
+ bp(side[3], 5);
}
}
}
@@ -161,7 +210,7 @@ void bake_light(Map* m, const Map_Light* light) {
}
void bake_map(Map* m) {
- Map_Light l = { f1 * 3, f1 * 3, f1, { 0xff, 0xff, 0xff, 0xff } };
+ Map_Light l = { f1 * 2 + 100, f1 * 2, f1/4, f1, { 0xff, 0xff, 0xff, 0xff } };
bake_light(m, &l);
}