Browse Source

Tweaked light sampling a bit more, should be more accurate to Quake's original implementation now (though it hardly makes any difference in practice)

master
Nico de Poel 3 years ago
parent
commit
727c5bf724
  1. 17
      lighting.cpp
  2. 1
      lighting.h

17
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)

1
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);
Loading…
Cancel
Save