mirror of
https://github.com/ZDoom/ZDRay.git
synced 2025-02-03 13:11:04 +00:00
- remove kexTrace class
This commit is contained in:
parent
e5dbc83bc9
commit
e89aa8a5d4
9 changed files with 34 additions and 120 deletions
|
@ -150,7 +150,6 @@ set( SOURCES
|
||||||
src/lightmap/lightmap.cpp
|
src/lightmap/lightmap.cpp
|
||||||
src/lightmap/lightsurface.cpp
|
src/lightmap/lightsurface.cpp
|
||||||
src/lightmap/surfaces.cpp
|
src/lightmap/surfaces.cpp
|
||||||
src/lightmap/trace.cpp
|
|
||||||
src/lightmap/worker.cpp
|
src/lightmap/worker.cpp
|
||||||
src/lightmap/collision.cpp
|
src/lightmap/collision.cpp
|
||||||
src/math/angle.cpp
|
src/math/angle.cpp
|
||||||
|
@ -183,7 +182,6 @@ set( HEADERS
|
||||||
src/lightmap/lightmap.h
|
src/lightmap/lightmap.h
|
||||||
src/lightmap/lightsurface.h
|
src/lightmap/lightsurface.h
|
||||||
src/lightmap/surfaces.h
|
src/lightmap/surfaces.h
|
||||||
src/lightmap/trace.h
|
|
||||||
src/lightmap/worker.h
|
src/lightmap/worker.h
|
||||||
src/lightmap/collision.h
|
src/lightmap/collision.h
|
||||||
src/math/mathlib.h
|
src/math/mathlib.h
|
||||||
|
|
|
@ -305,6 +305,14 @@ enum mapFlags_t
|
||||||
#define NO_SIDE_INDEX -1
|
#define NO_SIDE_INDEX -1
|
||||||
#define NO_LINE_INDEX 0xffffffff
|
#define NO_LINE_INDEX 0xffffffff
|
||||||
|
|
||||||
|
struct LevelTraceHit
|
||||||
|
{
|
||||||
|
kexVec3 start;
|
||||||
|
kexVec3 end;
|
||||||
|
surface_t *hitSurface;
|
||||||
|
float fraction;
|
||||||
|
};
|
||||||
|
|
||||||
struct FLevel
|
struct FLevel
|
||||||
{
|
{
|
||||||
FLevel ();
|
FLevel ();
|
||||||
|
@ -362,6 +370,8 @@ struct FLevel
|
||||||
void CreateLights();
|
void CreateLights();
|
||||||
void CleanupThingLights();
|
void CleanupThingLights();
|
||||||
|
|
||||||
|
LevelTraceHit Trace(const kexVec3 &startVec, const kexVec3 &endVec);
|
||||||
|
|
||||||
const kexVec3 &GetSunColor() const;
|
const kexVec3 &GetSunColor() const;
|
||||||
const kexVec3 &GetSunDirection() const;
|
const kexVec3 &GetSunDirection() const;
|
||||||
IntSector *GetFrontSector(const IntSideDef *side);
|
IntSector *GetFrontSector(const IntSideDef *side);
|
||||||
|
|
|
@ -368,3 +368,15 @@ void FLevel::CleanupThingLights()
|
||||||
delete thingLights[i];
|
delete thingLights[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LevelTraceHit FLevel::Trace(const kexVec3 &startVec, const kexVec3 &endVec)
|
||||||
|
{
|
||||||
|
TraceHit hit = TriangleMeshShape::find_first_hit(CollisionMesh.get(), startVec, endVec);
|
||||||
|
|
||||||
|
LevelTraceHit trace;
|
||||||
|
trace.start = startVec;
|
||||||
|
trace.end = endVec;
|
||||||
|
trace.fraction = hit.fraction;
|
||||||
|
trace.hitSurface = (trace.fraction < 1.0f) ? surfaces[hit.surface] : nullptr;
|
||||||
|
return trace;
|
||||||
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
#include "math/mathlib.h"
|
#include "math/mathlib.h"
|
||||||
#include "surfaces.h"
|
#include "surfaces.h"
|
||||||
#include "trace.h"
|
|
||||||
#include "level/level.h"
|
#include "level/level.h"
|
||||||
#include "lightmap.h"
|
#include "lightmap.h"
|
||||||
#include "lightsurface.h"
|
#include "lightsurface.h"
|
||||||
|
@ -174,7 +173,7 @@ kexBBox kexLightmapBuilder::GetBoundsFromSurface(const surface_t *surface)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traces to the ceiling surface. Will emit light if the surface that was traced is a sky
|
// Traces to the ceiling surface. Will emit light if the surface that was traced is a sky
|
||||||
bool kexLightmapBuilder::EmitFromCeiling(kexTrace &trace, const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color)
|
bool kexLightmapBuilder::EmitFromCeiling(const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color)
|
||||||
{
|
{
|
||||||
float attenuation = normal.Dot(map->GetSunDirection());
|
float attenuation = normal.Dot(map->GetSunDirection());
|
||||||
|
|
||||||
|
@ -184,7 +183,7 @@ bool kexLightmapBuilder::EmitFromCeiling(kexTrace &trace, const surface_t *surfa
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace.Trace(origin, origin + (map->GetSunDirection() * 32768.0f));
|
LevelTraceHit trace = map->Trace(origin, origin + (map->GetSunDirection() * 32768.0f));
|
||||||
|
|
||||||
if (trace.fraction == 1.0f)
|
if (trace.fraction == 1.0f)
|
||||||
{
|
{
|
||||||
|
@ -220,7 +219,7 @@ static float radians(float degrees)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traces a line from the texel's origin to the sunlight direction and against all nearby thing lights
|
// Traces a line from the texel's origin to the sunlight direction and against all nearby thing lights
|
||||||
kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &origin, surface_t *surface)
|
kexVec3 kexLightmapBuilder::LightTexelSample(const kexVec3 &origin, surface_t *surface)
|
||||||
{
|
{
|
||||||
kexPlane plane = surface->plane;
|
kexPlane plane = surface->plane;
|
||||||
kexVec3 color(0.0f, 0.0f, 0.0f);
|
kexVec3 color(0.0f, 0.0f, 0.0f);
|
||||||
|
@ -275,7 +274,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trace.Trace(lightOrigin, origin);
|
LevelTraceHit trace = map->Trace(lightOrigin, origin);
|
||||||
|
|
||||||
if (trace.fraction != 1)
|
if (trace.fraction != 1)
|
||||||
{
|
{
|
||||||
|
@ -297,7 +296,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
|
||||||
if (surface->type != ST_CEILING)
|
if (surface->type != ST_CEILING)
|
||||||
{
|
{
|
||||||
// see if it's exposed to sunlight
|
// see if it's exposed to sunlight
|
||||||
if (EmitFromCeiling(trace, surface, origin, plane.Normal(), color))
|
if (EmitFromCeiling(surface, origin, plane.Normal(), color))
|
||||||
tracedTexels++;
|
tracedTexels++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +305,7 @@ kexVec3 kexLightmapBuilder::LightTexelSample(kexTrace &trace, const kexVec3 &ori
|
||||||
{
|
{
|
||||||
kexLightSurface *surfaceLight = map->lightSurfaces[i];
|
kexLightSurface *surfaceLight = map->lightSurfaces[i];
|
||||||
|
|
||||||
float attenuation = surfaceLight->TraceSurface(map, trace, surface, origin);
|
float attenuation = surfaceLight->TraceSurface(map, surface, origin);
|
||||||
if (attenuation > 0.0f)
|
if (attenuation > 0.0f)
|
||||||
{
|
{
|
||||||
color += surfaceLight->GetRGB() * surfaceLight->Intensity() * attenuation;
|
color += surfaceLight->GetRGB() * surfaceLight->Intensity() * attenuation;
|
||||||
|
@ -424,12 +423,9 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
|
||||||
kexVec3 tDelta;
|
kexVec3 tDelta;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
kexTrace trace;
|
|
||||||
uint16_t *currentTexture;
|
uint16_t *currentTexture;
|
||||||
bool bShouldLookupTexture = false;
|
bool bShouldLookupTexture = false;
|
||||||
|
|
||||||
trace.Init(*map);
|
|
||||||
|
|
||||||
sampleWidth = surface->lightmapDims[0];
|
sampleWidth = surface->lightmapDims[0];
|
||||||
sampleHeight = surface->lightmapDims[1];
|
sampleHeight = surface->lightmapDims[1];
|
||||||
|
|
||||||
|
@ -463,7 +459,7 @@ void kexLightmapBuilder::TraceSurface(surface_t *surface)
|
||||||
(surface->lightmapSteps[0] * multisamplePos.x) +
|
(surface->lightmapSteps[0] * multisamplePos.x) +
|
||||||
(surface->lightmapSteps[1] * multisamplePos.y);
|
(surface->lightmapSteps[1] * multisamplePos.y);
|
||||||
|
|
||||||
c += LightTexelSample(trace, pos, surface);
|
c += LightTexelSample(pos, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
c /= multisampleCount;
|
c /= multisampleCount;
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
|
|
||||||
#define LIGHTMAP_MAX_SIZE 1024
|
#define LIGHTMAP_MAX_SIZE 1024
|
||||||
|
|
||||||
class kexTrace;
|
|
||||||
class FWadWriter;
|
class FWadWriter;
|
||||||
|
|
||||||
class kexLightmapBuilder
|
class kexLightmapBuilder
|
||||||
|
@ -60,8 +59,8 @@ private:
|
||||||
void NewTexture();
|
void NewTexture();
|
||||||
bool MakeRoomForBlock(const int width, const int height, int *x, int *y, int *num);
|
bool MakeRoomForBlock(const int width, const int height, int *x, int *y, int *num);
|
||||||
kexBBox GetBoundsFromSurface(const surface_t *surface);
|
kexBBox GetBoundsFromSurface(const surface_t *surface);
|
||||||
kexVec3 LightTexelSample(kexTrace &trace, const kexVec3 &origin, surface_t *surface);
|
kexVec3 LightTexelSample(const kexVec3 &origin, surface_t *surface);
|
||||||
bool EmitFromCeiling(kexTrace &trace, const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color);
|
bool EmitFromCeiling(const surface_t *surface, const kexVec3 &origin, const kexVec3 &normal, kexVec3 &color);
|
||||||
|
|
||||||
FLevel *map;
|
FLevel *map;
|
||||||
std::vector<uint16_t*> textures;
|
std::vector<uint16_t*> textures;
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
|
|
||||||
#include "math/mathlib.h"
|
#include "math/mathlib.h"
|
||||||
#include "level/level.h"
|
#include "level/level.h"
|
||||||
#include "trace.h"
|
|
||||||
#include "lightsurface.h"
|
#include "lightsurface.h"
|
||||||
|
|
||||||
kexLightSurface::kexLightSurface()
|
kexLightSurface::kexLightSurface()
|
||||||
|
@ -241,7 +240,7 @@ void kexLightSurface::Subdivide(const float divide)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surface_t *surf, const kexVec3 &origin)
|
float kexLightSurface::TraceSurface(FLevel *map, const surface_t *surf, const kexVec3 &origin)
|
||||||
{
|
{
|
||||||
// light surface will always be fullbright
|
// light surface will always be fullbright
|
||||||
if (surf == surface)
|
if (surf == surface)
|
||||||
|
@ -302,7 +301,7 @@ float kexLightSurface::TraceSurface(FLevel *doomMap, kexTrace &trace, const surf
|
||||||
|
|
||||||
// trace the origin to the center of the light surface. nudge by the normals in
|
// trace the origin to the center of the light surface. nudge by the normals in
|
||||||
// case the start/end points are directly on or inside the surface
|
// case the start/end points are directly on or inside the surface
|
||||||
trace.Trace(center + lnormal, origin + normal);
|
LevelTraceHit trace = map->Trace(center + lnormal, origin + normal);
|
||||||
|
|
||||||
if (trace.fraction < 1.0f)
|
if (trace.fraction < 1.0f)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
struct FLevel;
|
struct FLevel;
|
||||||
struct surfaceLightDef;
|
struct surfaceLightDef;
|
||||||
class kexTrace;
|
|
||||||
|
|
||||||
class kexLightSurface
|
class kexLightSurface
|
||||||
{
|
{
|
||||||
|
@ -42,7 +41,7 @@ public:
|
||||||
void Init(const surfaceLightDef &lightSurfaceDef, surface_t *surface, const bool bWall);
|
void Init(const surfaceLightDef &lightSurfaceDef, surface_t *surface, const bool bWall);
|
||||||
void Subdivide(const float divide);
|
void Subdivide(const float divide);
|
||||||
void CreateCenterOrigin();
|
void CreateCenterOrigin();
|
||||||
float TraceSurface(FLevel *doomMap, kexTrace &trace, const surface_t *surface, const kexVec3 &origin);
|
float TraceSurface(FLevel *doomMap, const surface_t *surface, const kexVec3 &origin);
|
||||||
|
|
||||||
const float Distance() const { return distance; }
|
const float Distance() const { return distance; }
|
||||||
const float Intensity() const { return intensity; }
|
const float Intensity() const { return intensity; }
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Note: this is a modified version of dlight. It is not the original software.
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Copyright (c) 2013-2014 Samuel Villarreal
|
|
||||||
// svkaiser@gmail.com
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied
|
|
||||||
// warranty. In no event will the authors be held liable for any damages
|
|
||||||
// arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it
|
|
||||||
// freely, subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
// claim that you wrote the original software. If you use this software
|
|
||||||
// in a product, an acknowledgment in the product documentation would be
|
|
||||||
// appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
// misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source
|
|
||||||
// distribution.
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// DESCRIPTION: General class module for handling ray tracing of the
|
|
||||||
// world geometry. Ideally, all of this needs to be revisited...
|
|
||||||
//
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include "math/mathlib.h"
|
|
||||||
#include "level/level.h"
|
|
||||||
#include "trace.h"
|
|
||||||
|
|
||||||
void kexTrace::Init(FLevel &doomMap)
|
|
||||||
{
|
|
||||||
map = &doomMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
void kexTrace::Trace(const kexVec3 &startVec, const kexVec3 &endVec)
|
|
||||||
{
|
|
||||||
start = startVec;
|
|
||||||
end = endVec;
|
|
||||||
|
|
||||||
TraceHit hit = TriangleMeshShape::find_first_hit(map->CollisionMesh.get(), start, end);
|
|
||||||
fraction = hit.fraction;
|
|
||||||
if (fraction < 1.0f)
|
|
||||||
hitSurface = surfaces[hit.surface];
|
|
||||||
else
|
|
||||||
hitSurface = nullptr;
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Note: this is a modified version of dlight. It is not the original software.
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Copyright (c) 2013-2014 Samuel Villarreal
|
|
||||||
// svkaiser@gmail.com
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied
|
|
||||||
// warranty. In no event will the authors be held liable for any damages
|
|
||||||
// arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it
|
|
||||||
// freely, subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
// claim that you wrote the original software. If you use this software
|
|
||||||
// in a product, an acknowledgment in the product documentation would be
|
|
||||||
// appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
// misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source
|
|
||||||
// distribution.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
struct FLevel;
|
|
||||||
|
|
||||||
class kexTrace
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void Init(FLevel &doomMap);
|
|
||||||
void Trace(const kexVec3 &startVec, const kexVec3 &endVec);
|
|
||||||
|
|
||||||
kexVec3 start;
|
|
||||||
kexVec3 end;
|
|
||||||
surface_t *hitSurface;
|
|
||||||
float fraction;
|
|
||||||
|
|
||||||
private:
|
|
||||||
FLevel *map = nullptr;
|
|
||||||
};
|
|
Loading…
Reference in a new issue