From c9aad9d2cea8ed6aa67447681bde9f4a6d1aa2d1 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Wed, 6 Apr 2016 11:43:52 -0600 Subject: [PATCH] light: Refactor CalcPoints, store whether a point is occluded --- include/light/light.h | 1 + light/ltface.c | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/light/light.h b/include/light/light.h index e1e8355e..12c92d6a 100644 --- a/include/light/light.h +++ b/include/light/light.h @@ -190,6 +190,7 @@ typedef struct { int numpoints; vec3_t *points; // malloc'ed array of numpoints vec3_t *normals; // malloc'ed array of numpoints + bool *occluded; // malloc'ed array of numpoints /* raw ambient occlusion amount per sample point, 0-1, where 1 is diff --git a/light/ltface.c b/light/ltface.c index f80aed35..0bc3aef7 100644 --- a/light/ltface.c +++ b/light/ltface.c @@ -595,10 +595,6 @@ __attribute__((noinline)) static void CalcPoints(const modelinfo_t *modelinfo, const vec3_t offset, const texorg_t *texorg, lightsurf_t *surf, const bsp2_t *bsp, const bsp2_dface_t *face) { - int s, t; - int width, height; - vec_t *point, *norm; - /* * Fill in the surface points. The points are biased towards the center of * the surface to help avoid edge cases just inside walls @@ -606,8 +602,8 @@ CalcPoints(const modelinfo_t *modelinfo, const vec3_t offset, const texorg_t *te TexCoordToWorld(surf->exactmid[0], surf->exactmid[1], texorg, surf->midpoint); VectorAdd(surf->midpoint, offset, surf->midpoint); - width = (surf->texsize[0] + 1) * oversample; - height = (surf->texsize[1] + 1) * oversample; + const int width = (surf->texsize[0] + 1) * oversample; + const int height = (surf->texsize[1] + 1) * oversample; surf->starts = (surf->texmins[0] - 0.5 + (0.5 / oversample)) * surf->lightmapscale; surf->startt = (surf->texmins[1] - 0.5 + (0.5 / oversample)) * surf->lightmapscale; surf->st_step = surf->lightmapscale / oversample; @@ -616,10 +612,14 @@ CalcPoints(const modelinfo_t *modelinfo, const vec3_t offset, const texorg_t *te surf->numpoints = width * height; surf->points = calloc(surf->numpoints, sizeof(vec3_t)); surf->normals = calloc(surf->numpoints, sizeof(vec3_t)); - point = surf->points[0]; - norm = surf->normals[0]; - for (t = 0; t < height; t++) { - for (s = 0; s < width; s++, point += 3, norm += 3) { + surf->occluded = (bool *)calloc(surf->numpoints, sizeof(bool)); + + for (int t = 0; t < height; t++) { + for (int s = 0; s < width; s++) { + const int i = t*width + s; + vec_t *point = surf->points[i]; + vec_t *norm = surf->normals[i]; + const vec_t us = surf->starts + s * surf->st_step; const vec_t ut = surf->startt + t * surf->st_step; @@ -1684,6 +1684,9 @@ void LightFaceShutdown(struct ltface_ctx *ctx) if (ctx->lightsurf.occlusion) free(ctx->lightsurf.occlusion); + if (ctx->lightsurf.occluded) + free(ctx->lightsurf.occluded); + free(ctx); }