- change the light math and some defaults

This commit is contained in:
Magnus Norddahl 2018-10-29 18:32:50 +01:00
parent 2539d137a3
commit 6acea159f7
7 changed files with 190 additions and 42 deletions

View file

@ -597,7 +597,7 @@ void FProcessor::BuildNodes()
void FProcessor::BuildLightmaps(const char *configFile) void FProcessor::BuildLightmaps(const char *configFile)
{ {
LMBuilder.ambience = 0.0f; LMBuilder.ambience = 0.0f;
LMBuilder.samples = 64; LMBuilder.samples = 8;
LMBuilder.textureWidth = LIGHTMAP_MAX_SIZE; LMBuilder.textureWidth = LIGHTMAP_MAX_SIZE;
LMBuilder.textureHeight = LIGHTMAP_MAX_SIZE; LMBuilder.textureHeight = LIGHTMAP_MAX_SIZE;

View file

@ -98,6 +98,14 @@ kexVec3 kexBBox::Center() const
(max.z + min.z) * 0.5f); (max.z + min.z) * 0.5f);
} }
kexVec3 kexBBox::Extents() const
{
return kexVec3(
(max.x - min.x) * 0.5f,
(max.y - min.y) * 0.5f,
(max.z - min.z) * 0.5f);
}
// //
// kexBBox::Radius // kexBBox::Radius
// //

View file

@ -215,12 +215,15 @@ public:
float Dot(const kexVec3 &vec) const; float Dot(const kexVec3 &vec) const;
static float Dot(const kexVec3 &vec1, const kexVec3 &vec2); static float Dot(const kexVec3 &vec1, const kexVec3 &vec2);
kexVec3 Cross(const kexVec3 &vec) const; kexVec3 Cross(const kexVec3 &vec) const;
kexVec3 &Cross(const kexVec3 &vec1, const kexVec3 &vec2); static kexVec3 Cross(const kexVec3 &vec1, const kexVec3 &vec2);
float UnitSq() const; float UnitSq() const;
float Unit() const; float Unit() const;
float DistanceSq(const kexVec3 &vec) const; float LengthSq() const { return UnitSq(); }
float Length() const { return Unit(); }
float DistanceSq(const kexVec3 &vec) const;
float Distance(const kexVec3 &vec) const; float Distance(const kexVec3 &vec) const;
kexVec3 &Normalize(); kexVec3 &Normalize();
static kexVec3 Normalize(kexVec3 a);
kexAngle PointAt(kexVec3 &location) const; kexAngle PointAt(kexVec3 &location) const;
kexVec3 Lerp(const kexVec3 &next, float movement) const; kexVec3 Lerp(const kexVec3 &next, float movement) const;
kexVec3 &Lerp(const kexVec3 &start, const kexVec3 &next, float movement); kexVec3 &Lerp(const kexVec3 &start, const kexVec3 &next, float movement);
@ -238,8 +241,10 @@ public:
kexVec3 operator+(const kexVec3 &vec); kexVec3 operator+(const kexVec3 &vec);
kexVec3 operator+(const kexVec3 &vec) const; kexVec3 operator+(const kexVec3 &vec) const;
kexVec3 operator+(kexVec3 &vec); kexVec3 operator+(kexVec3 &vec);
kexVec3 operator-() const; kexVec3 operator+(const float val) const;
kexVec3 operator-(const kexVec3 &vec) const; kexVec3 operator-() const;
kexVec3 operator-(const float val) const;
kexVec3 operator-(const kexVec3 &vec) const;
kexVec3 operator*(const kexVec3 &vec); kexVec3 operator*(const kexVec3 &vec);
kexVec3 operator*(const float val); kexVec3 operator*(const float val);
kexVec3 operator*(const float val) const; kexVec3 operator*(const float val) const;
@ -251,8 +256,10 @@ public:
kexVec3 &operator=(const kexVec3 &vec); kexVec3 &operator=(const kexVec3 &vec);
kexVec3 &operator=(const float *vecs); kexVec3 &operator=(const float *vecs);
kexVec3 &operator+=(const kexVec3 &vec); kexVec3 &operator+=(const kexVec3 &vec);
kexVec3 &operator-=(const kexVec3 &vec); kexVec3 &operator+=(const float val);
kexVec3 &operator*=(const kexVec3 &vec); kexVec3 &operator-=(const kexVec3 &vec);
kexVec3 &operator-=(const float val);
kexVec3 &operator*=(const kexVec3 &vec);
kexVec3 &operator*=(const float val); kexVec3 &operator*=(const float val);
kexVec3 &operator/=(const kexVec3 &vec); kexVec3 &operator/=(const kexVec3 &vec);
kexVec3 &operator/=(const float val); kexVec3 &operator/=(const float val);
@ -277,16 +284,35 @@ class kexVec4
public: public:
kexVec4(); kexVec4();
explicit kexVec4(const float x, const float y, const float z, const float w); explicit kexVec4(const float x, const float y, const float z, const float w);
explicit kexVec4(const kexVec3 &v, const float w);
void Set(const float x, const float y, const float z, const float w); void Set(const float x, const float y, const float z, const float w);
void Clear(); void Clear();
float *ToFloatPtr(); float *ToFloatPtr();
static float Dot(const kexVec4 &a, const kexVec4 &b) { return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w; }
const kexVec3 &ToVec3() const; const kexVec3 &ToVec3() const;
kexVec3 &ToVec3(); kexVec3 &ToVec3();
kexVec4 operator|(const kexMatrix &mtx); kexVec4 operator|(const kexMatrix &mtx);
kexVec4 &operator|=(const kexMatrix &mtx); kexVec4 &operator|=(const kexMatrix &mtx);
float operator[](int index) const; kexVec4 operator+(const kexVec4 &vec) const;
kexVec4 operator+(const float val) const;
kexVec4 operator-(const kexVec4 &vec) const;
kexVec4 operator-(const float val) const;
kexVec4 operator*(const kexVec4 &vec) const;
kexVec4 operator*(const float val) const;
kexVec4 operator/(const kexVec4 &vec) const;
kexVec4 operator/(const float val) const;
kexVec4 &operator+=(const kexVec4 &vec);
kexVec4 &operator+=(const float val);
kexVec4 &operator-=(const kexVec4 &vec);
kexVec4 &operator-=(const float val);
kexVec4 &operator*=(const kexVec4 &vec);
kexVec4 &operator*=(const float val);
kexVec4 &operator/=(const kexVec4 &vec);
kexVec4 &operator/=(const float val);
float operator[](int index) const;
float &operator[](int index); float &operator[](int index);
float x; float x;
@ -332,6 +358,9 @@ public:
kexMatrix &operator=(const float *m); kexMatrix &operator=(const float *m);
kexMatrix operator|(const kexMatrix &matrix); kexMatrix operator|(const kexMatrix &matrix);
float operator[](size_t i) const { return vectors[i >> 2][i & 3]; }
float &operator[](size_t i) { return vectors[i >> 2][i & 3]; }
kexVec4 vectors[4]; kexVec4 vectors[4];
}; };
@ -436,7 +465,8 @@ public:
void Clear(); void Clear();
kexVec3 Center() const; kexVec3 Center() const;
float Radius() const; kexVec3 Extents() const;
float Radius() const;
void AddPoint(const kexVec3 &vec); void AddPoint(const kexVec3 &vec);
bool PointInside(const kexVec3 &vec) const; bool PointInside(const kexVec3 &vec) const;
bool IntersectingBox(const kexBBox &box) const; bool IntersectingBox(const kexBBox &box) const;

View file

@ -631,13 +631,9 @@ kexVec3 kexVec3::Cross(const kexVec3 &vec) const
// kexVec3::Cross // kexVec3::Cross
// //
kexVec3 &kexVec3::Cross(const kexVec3 &vec1, const kexVec3 &vec2) kexVec3 kexVec3::Cross(const kexVec3 &vec1, const kexVec3 &vec2)
{ {
x = vec2.z * vec1.y - vec1.z * vec2.y; return vec1.Cross(vec2);
y = vec2.x * vec1.z - vec1.x * vec2.z;
z = vec1.x * vec2.y - vec2.x * vec1.y;
return *this;
} }
// //
@ -690,6 +686,12 @@ kexVec3 &kexVec3::Normalize()
return *this; return *this;
} }
kexVec3 kexVec3::Normalize(kexVec3 a)
{
a.Normalize();
return a;
}
// //
// kexVec3::PointAt // kexVec3::PointAt
// //
@ -860,6 +862,11 @@ kexVec3 kexVec3::operator+(const kexVec3 &vec) const
return kexVec3(x + vec.x, y + vec.y, z + vec.z); return kexVec3(x + vec.x, y + vec.y, z + vec.z);
} }
kexVec3 kexVec3::operator+(const float val) const
{
return kexVec3(x + val, y + val, z + val);
}
// //
// kexVec3::operator+ // kexVec3::operator+
// //
@ -881,6 +888,14 @@ kexVec3 &kexVec3::operator+=(const kexVec3 &vec)
return *this; return *this;
} }
kexVec3 &kexVec3::operator+=(const float val)
{
x += val;
y += val;
z += val;
return *this;
}
// //
// kexVec3::operator- // kexVec3::operator-
// //
@ -890,6 +905,11 @@ kexVec3 kexVec3::operator-(const kexVec3 &vec) const
return kexVec3(x - vec.x, y - vec.y, z - vec.z); return kexVec3(x - vec.x, y - vec.y, z - vec.z);
} }
kexVec3 kexVec3::operator-(const float val) const
{
return kexVec3(x - val, y - val, z - val);
}
// //
// kexVec3::operator- // kexVec3::operator-
// //
@ -911,6 +931,14 @@ kexVec3 &kexVec3::operator-=(const kexVec3 &vec)
return *this; return *this;
} }
kexVec3 &kexVec3::operator-=(const float val)
{
x -= val;
y -= val;
z -= val;
return *this;
}
// //
// kexVec3::operator* // kexVec3::operator*
// //
@ -1168,6 +1196,11 @@ kexVec4::kexVec4(const float x, const float y, const float z, const float w)
Set(x, y, z, w); Set(x, y, z, w);
} }
kexVec4::kexVec4(const kexVec3 &v, const float w)
{
Set(v.x, v.y, v.z, w);
}
// //
// kexVec4::Set // kexVec4::Set
// //
@ -1216,6 +1249,94 @@ float *kexVec4::ToFloatPtr()
return reinterpret_cast<float*>(&x); return reinterpret_cast<float*>(&x);
} }
kexVec4 kexVec4::operator+(const kexVec4 &vec) const
{
return kexVec4(x + vec.x, y + vec.y, z + vec.z, w + vec.w);
}
kexVec4 kexVec4::operator+(const float val) const
{
return kexVec4(x + val, y + val, z + val, w + val);
}
kexVec4 kexVec4::operator-(const kexVec4 &vec) const
{
return kexVec4(x - vec.x, y - vec.y, z - vec.z, w - vec.w);
}
kexVec4 kexVec4::operator-(const float val) const
{
return kexVec4(x - val, y - val, z - val, w - val);
}
kexVec4 kexVec4::operator*(const kexVec4 &vec) const
{
return kexVec4(x * vec.x, y * vec.y, z * vec.z, w * vec.w);
}
kexVec4 kexVec4::operator*(const float val) const
{
return kexVec4(x * val, y * val, z * val, w * val);
}
kexVec4 kexVec4::operator/(const kexVec4 &vec) const
{
return kexVec4(x / vec.x, y / vec.y, z / vec.z, w / vec.w);
}
kexVec4 kexVec4::operator/(const float val) const
{
return kexVec4(x / val, y / val, z / val, w / val);
}
kexVec4 &kexVec4::operator+=(const kexVec4 &vec)
{
x += vec.x; y += vec.y; z += vec.z; w += vec.w;
return *this;
}
kexVec4 &kexVec4::operator+=(const float val)
{
x += val; y += val; z += val; w += val;
return *this;
}
kexVec4 &kexVec4::operator-=(const kexVec4 &vec)
{
x -= vec.x; y -= vec.y; z -= vec.z; w -= vec.w;
return *this;
}
kexVec4 &kexVec4::operator-=(const float val)
{
x -= val; y -= val; z -= val; w -= val;
return *this;
}
kexVec4 &kexVec4::operator*=(const kexVec4 &vec)
{
x *= vec.x; y *= vec.y; z *= vec.z; w *= vec.w;
return *this;
}
kexVec4 &kexVec4::operator*=(const float val)
{
x *= val; y *= val; z *= val; w *= val;
return *this;
}
kexVec4 &kexVec4::operator/=(const kexVec4 &vec)
{
x /= vec.x; y /= vec.y; z /= vec.z; w /= vec.w;
return *this;
}
kexVec4 &kexVec4::operator/=(const float val)
{
x /= val; y /= val; z /= val; w /= val;
return *this;
}
// //
// kexVec4::operator| // kexVec4::operator|
// //

View file

@ -328,8 +328,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
} }
// accumulate results // accumulate results
color = color.Lerp(tl->rgb, colorAdd); color += tl->rgb * colorAdd;
kexMath::Clamp(color, 0, 1);
tracedTexels++; tracedTexels++;
} }
@ -342,8 +341,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
dist = (dist * 4); dist = (dist * 4);
kexMath::Clamp(dist, 0, 1); kexMath::Clamp(dist, 0, 1);
color = color.Lerp(map->GetSunColor(), dist); color += map->GetSunColor() * dist;
kexMath::Clamp(color, 0, 1);
tracedTexels++; tracedTexels++;
} }
@ -362,11 +360,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
if(surfaceLight->TraceSurface(map, trace, surface, origin, &dist)) if(surfaceLight->TraceSurface(map, trace, surface, origin, &dist))
{ {
dist = (dist * surfaceLight->Intensity()); color += surfaceLight->GetRGB() * kexMath::Pow(dist * surfaceLight->Intensity(), surfaceLight->FallOff());
kexMath::Clamp(dist, 0, 1);
color = color.Lerp(surfaceLight->GetRGB(), kexMath::Pow(dist, surfaceLight->FallOff()));
kexMath::Clamp(color, 0, 1);
tracedTexels++; tracedTexels++;
} }
@ -503,7 +497,7 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
bool bShouldLookupTexture = false; bool bShouldLookupTexture = false;
trace.Init(*map); trace.Init(*map);
memset(colorSamples, 0, sizeof(colorSamples)); //memset(colorSamples, 0, sizeof(colorSamples));
sampleWidth = surface->lightmapDims[0]; sampleWidth = surface->lightmapDims[0];
sampleHeight = surface->lightmapDims[1]; sampleHeight = surface->lightmapDims[1];
@ -535,16 +529,18 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
#endif #endif
// accumulate color samples // accumulate color samples
colorSamples[i][j] += LightTexelSample(trace, pos, surface); kexVec3 c = LightTexelSample(trace, pos, surface);
// if nothing at all was traced and color is completely black // if nothing at all was traced and color is completely black
// then this surface will not go through the extra rendering // then this surface will not go through the extra rendering
// step in rendering the lightmap // step in rendering the lightmap
if(colorSamples[i][j].UnitSq() != 0) if (c.x > 0.0f || c.y > 0.0f || c.z > 0.0f)
{ {
bShouldLookupTexture = true; bShouldLookupTexture = true;
} }
}
colorSamples[i][j] = c;
}
} }
#ifdef EXPORT_TEXELS_OBJ #ifdef EXPORT_TEXELS_OBJ

View file

@ -288,8 +288,7 @@ void kexLightSurface::Subdivide(const float divide)
// kexLightSurface::TraceSurface // kexLightSurface::TraceSurface
// //
bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surface_t *surf, bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surface_t *surf, const kexVec3 &origin, float *dist)
const kexVec3 &origin, float *dist)
{ {
kexVec3 normal; kexVec3 normal;
kexVec3 lnormal; kexVec3 lnormal;
@ -415,17 +414,10 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
float d = origin.Distance(center); float d = origin.Distance(center);
if(d <= 0) curDist = 1.0f - d / distance;
{ if (curDist < 0.0f) curDist = 0.0f;
// this origin point must be right on the light surface so just mark it as
// full bright if that's the case
curDist = 1;
}
else
{
curDist = distance / d;
}
/*
if(curDist >= 1) if(curDist >= 1)
{ {
curDist = 1; curDist = 1;
@ -453,6 +445,7 @@ bool kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surfa
curDist *= angle; curDist *= angle;
} }
} }
*/
if(curDist > *dist) if(curDist > *dist)
{ {

View file

@ -567,8 +567,8 @@ void FLevel::ParseConfigFile(const char *file)
surfaceLight.outerCone = 1.0f; surfaceLight.outerCone = 1.0f;
surfaceLight.innerCone = 0; surfaceLight.innerCone = 0;
surfaceLight.falloff = 1.0f; surfaceLight.falloff = 1.0f;
surfaceLight.intensity = 10.0f; surfaceLight.intensity = 1.0f;
surfaceLight.distance = 150.0f; surfaceLight.distance = 1000.0f;
surfaceLight.bIgnoreCeiling = false; surfaceLight.bIgnoreCeiling = false;
surfaceLight.bIgnoreFloor = false; surfaceLight.bIgnoreFloor = false;
surfaceLight.bNoCenterPoint = false; surfaceLight.bNoCenterPoint = false;