From 727c5bf72483935d3ba62dca1139d05afc0aa871 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 7 Feb 2023 20:24:15 +0100 Subject: [PATCH] Tweaked light sampling a bit more, should be more accurate to Quake's original implementation now (though it hardly makes any difference in practice) --- lighting.cpp | 17 +++++++++++------ lighting.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lighting.cpp b/lighting.cpp index b8dd0a3..54a0f1d 100644 --- a/lighting.cpp +++ b/lighting.cpp @@ -9,14 +9,14 @@ bool sample_lightmap(const world_t* world, const face_t* face, const FaceBound& Vec3 minBounds = (bounds.lightmapBounds.min / 16).floor(); Vec3 maxBounds = (bounds.lightmapBounds.max / 16).ceil(); - int width = (int)((maxBounds.x - minBounds.x) * 16.f); // extents[0] - int height = (int)((maxBounds.y - minBounds.y) * 16.f); // extents[1] - - minBounds = minBounds * 16.f; // texturemins.xy + int width = ((int)maxBounds.x - (int)minBounds.x) * 16; // extents[0] + int height = ((int)maxBounds.y - (int)minBounds.y) * 16; // extents[1] + int minX = (int)minBounds.x * 16; // texturemins[0] + int minY = (int)minBounds.y * 16; // texturemins[1] Vec3 uv = bounds.lightmapTransform.TransformPoint(point); - int u = (int)(uv.x - minBounds.x); - int v = (int)(uv.y - minBounds.y); + int u = (int)uv.x - minX; + int v = (int)uv.y - minY; if (u < 0 || v < 0 || u > width || v > height) return false; @@ -312,6 +312,11 @@ SurfaceList group_surfaces(const world_t* world, const VertexFaces& vertexFaces) return surfaces; } +unsigned char compute_faceVertex_light3(const world_t* world, const face_t* refFace, const FaceBounds& faceBounds, Vec3 point) +{ + return sample_lightmap(world, refFace, faceBounds.find(refFace)->second, point); +} + unsigned char compute_faceVertex_light4(const world_t* world, const face_t* refFace, const FaceBounds& faceBounds, Vec3 point) { if (refFace->lightmap < 0) diff --git a/lighting.h b/lighting.h index 375489f..5cf2bf8 100644 --- a/lighting.h +++ b/lighting.h @@ -48,5 +48,6 @@ unsigned char compute_faceVertex_light(const world_t* world, const face_t* face, unsigned char compute_faceVertex_light2(const world_t* world, const face_t* face, unsigned short vertexIndex, const FaceBounds& faceBounds, const VertexFaces& vertexFaces); SurfaceList group_surfaces(const world_t* world, const VertexFaces& vertexFaces); +unsigned char compute_faceVertex_light3(const world_t* world, const face_t* refFace, const FaceBounds& faceBounds, Vec3 point); unsigned char compute_faceVertex_light4(const world_t* world, const face_t* refFace, const FaceBounds& faceBounds, Vec3 point); unsigned char compute_faceVertex_light5(const world_t* world, const face_t* refFace, const FaceBounds& faceBounds, Vec3 point);