Skip to content

Commit

Permalink
output: improve vertex movement (LostArtefacts#1496)
Browse files Browse the repository at this point in the history
This allows locking specific vertices such that they don't move when
looked at through a water portal. We make use of an unused bit in
vertex shading, and ensure shading is clamped to the max value.

Resolves LostArtefacts#1493.
  • Loading branch information
lahm86 authored Sep 6, 2024
1 parent 245b2ad commit 858f13d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- improved level load times
- improved logs module names readability
- improved crash debug information on Windows
- improved vertex movement when looking through water portals (#1493)

## [4.3](https://github.com/LostArtefacts/TR1X/compare/4.2...4.3) - 2024-08-15
- added deadly water feature from TR2+ for custom levels (#1404)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ Not all options are turned on by default. Refer to `TR1X_ConfigTool.exe` for det
- **Temple of the Cat**: incorrect textures in rooms 50, 70, 71, 76, 78, 87 and 96, and a missing texture in 75
- **Atlantean Stronghold**: incorrect textures in rooms 2, 6, 7 and 75, and missing textures in rooms 5, 13, 19, 63 and 74
- **The Hive**: incorrect textures in room 8, 13 and 18
- improved vertex movement when looking through water portals

#### Audio
- added music during the credits
Expand Down
1 change: 1 addition & 0 deletions src/game/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,7 @@ static void Inject_AlterRoomVertex(INJECTION *injection)
*(data_ptr + 2) += y_change;
*(data_ptr + 3) += z_change;
*(data_ptr + 4) += shade_change;
CLAMPG(*(data_ptr + 4), MAX_LIGHTING);
}

static void Inject_RotateRoomFace(INJECTION *injection)
Expand Down
27 changes: 27 additions & 0 deletions src/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static void Level_LoadCinematic(VFILE *file);
static void Level_LoadDemo(VFILE *file);
static void Level_LoadSamples(VFILE *file);
static void Level_CompleteSetup(int32_t level_num);
static void Level_MarkWaterEdgeVertices(void);
static size_t Level_CalculateMaxVertices(void);

static void Level_LoadFromFile(
Expand Down Expand Up @@ -898,6 +899,8 @@ static void Level_CompleteSetup(int32_t level_num)

Inject_AllInjections(&m_LevelInfo);

Level_MarkWaterEdgeVertices();

// Must be called post-injection to allow for floor data changes.
Stats_ObserveRoomsLoad();

Expand Down Expand Up @@ -954,6 +957,30 @@ static void Level_CompleteSetup(int32_t level_num)
Benchmark_End(benchmark, NULL);
}

static void Level_MarkWaterEdgeVertices(void)
{
if (!g_Config.fix_texture_issues) {
return;
}

BENCHMARK *const benchmark = Benchmark_Start();
for (int32_t i = 0; i < g_RoomCount; i++) {
const ROOM_INFO *const room = &g_RoomInfo[i];
const int32_t y_test =
(room->flags & RF_UNDERWATER) ? room->max_ceiling : room->min_floor;
int16_t *data = room->data;
const int16_t num_vertices = *data++;
for (int32_t j = 0; j < num_vertices; j++) {
if (data[1] == y_test) {
data[3] |= NO_VERT_MOVE;
}
data += 4;
}
}

Benchmark_End(benchmark, NULL);
}

static size_t Level_CalculateMaxVertices(void)
{
BENCHMARK *const benchmark = Benchmark_Start();
Expand Down
8 changes: 4 additions & 4 deletions src/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,29 +342,29 @@ static const int16_t *Output_CalcRoomVertices(const int16_t *obj_ptr)
m_VBuf[i].xv = xv;
m_VBuf[i].yv = yv;
m_VBuf[i].zv = zv;
m_VBuf[i].g = obj_ptr[3];
m_VBuf[i].g = obj_ptr[3] & MAX_LIGHTING;

if (zv < Output_GetNearZ()) {
m_VBuf[i].clip = 0x8000;
} else {
int16_t clip_flags = 0;
int32_t depth = zv_int >> W2V_SHIFT;
if (depth > Output_GetDrawDistMax()) {
m_VBuf[i].g = 0x1FFF;
m_VBuf[i].g = MAX_LIGHTING;
if (!m_IsSkyboxEnabled) {
clip_flags |= 16;
}
} else if (depth) {
m_VBuf[i].g += Output_CalcFogShade(depth);
if (!m_IsWaterEffect) {
CLAMPG(m_VBuf[i].g, 0x1FFF);
CLAMPG(m_VBuf[i].g, MAX_LIGHTING);
}
}

double persp = g_PhdPersp / zv;
double xs = Viewport_GetCenterX() + xv * persp;
double ys = Viewport_GetCenterY() + yv * persp;
if (m_IsWibbleEffect) {
if (m_IsWibbleEffect && !(obj_ptr[3] & NO_VERT_MOVE)) {
xs += m_WibbleTable[(m_WibbleOffset + (int)ys) & 0x1F];
ys += m_WibbleTable[(m_WibbleOffset + (int)xs) & 0x1F];
}
Expand Down
2 changes: 2 additions & 0 deletions src/global/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
#define WIBBLE_SIZE 32
#define MAX_WIBBLE 2
#define MAX_SHADE 0x300
#define MAX_LIGHTING 0x1FFF
#define NO_VERT_MOVE 0x2000
#define MAX_EXPANSION 5
#define NO_BOX (-1)
#define BOX_NUMBER 0x7FFF
Expand Down

0 comments on commit 858f13d

Please sign in to comment.