summaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-08-04 15:34:05 +1000
committerquou <quou@disroot.org>2024-08-04 15:34:05 +1000
commitb0a5f59fe3bea9aab8f52016a90b6cbbcaea4571 (patch)
tree83b4e6f4b0d02646de888eeaff25d485e12ef73c /render.c
parent9c2f9a59096b5ec449c7557afb3220ed2597c4ea (diff)
WIP lightmap baking
Diffstat (limited to 'render.c')
-rw-r--r--render.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/render.c b/render.c
index 3e5758b..f50dd04 100644
--- a/render.c
+++ b/render.c
@@ -785,12 +785,29 @@ void ren_map(
int t = ((2 * x) << (fbits * 2)) / w - f1;
int coordc = x + y * r->vp[0];
int coordf = x + ((hhi - y) + hhi) * r->vp[0];
- int ifloor[2];
+ int ifloor[2], mc[2];
+ const Map_Fragment* light;
+ Colour c;
t = (t + f1) / 2;
ifloor[0] = floor[0] + ((t * (floor[2] - floor[0])) >> fbits);
ifloor[1] = floor[1] + ((t * (floor[3] - floor[1])) >> fbits);
- r->t[coordc] = sample_tex(ceiling, ifloor[0], ifloor[1]);
- r->t[coordf] = sample_tex(floort, ifloor[0], ifloor[1]);
+ mc[0] = ifloor[0] >> fbits;
+ mc[1] = ifloor[1] >> fbits;
+ if (mc[0] < 0) continue;
+ if (mc[1] < 0) continue;
+ if (mc[0] >= map->w) continue;
+ if (mc[1] >= map->h) continue;
+ light = sample_map_light(
+ map,
+ mc[0],
+ mc[1],
+ ifloor[0],
+ ifloor[1]
+ );
+ c = sample_tex(ceiling, ifloor[0], ifloor[1]);
+ r->t[coordc] = col_mul(c, light->u);
+ c = sample_tex(floort, ifloor[0], ifloor[1]);
+ r->t[coordf] = col_mul(c, light->d);
}
}
for (x = r->clip[0]; x < r->clip[2]; x++) {
@@ -819,17 +836,19 @@ void ren_map(
dside[1] = (((mp[1] << fbits) + f1 - pos[1]) * delta[1]) >> fbits;
}
while (1) {
- int dist, u;
+ int dist, u, side;
if (dside[0] < dside[1]) {
dside[0] += delta[0];
mp[0] += step[0];
dist = dside[0] - delta[0];
u = pos[1] + ((dist * d[1]) >> fbits);
+ side = d[0] < 0;
} else {
dside[1] += delta[1];
mp[1] += step[1];
dist = dside[1] - delta[1];
u = pos[0] + ((dist * d[0]) >> fbits);
+ side = 2 + (d[1] < 0);
}
if (mp[0] < 0) break;
if (mp[1] < 0) break;
@@ -845,6 +864,14 @@ void ren_map(
int coord = x + y * r->vp[0];
int v = ((y - sy) << fbits) / (ey - sy);
Colour c = sample_tex(texture, u, v);
+ const Map_Fragment* light = sample_map_light(
+ map,
+ mp[0],
+ mp[1],
+ u,
+ v
+ );
+ c = col_mul(c, light->side[side]);
r->d[coord] = dist;
r->t[coord] = c;
}