Skip to content

Commit

Permalink
output: add reflections
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 12, 2024
1 parent 02fe364 commit 1cb8ae9
Show file tree
Hide file tree
Showing 25 changed files with 440 additions and 79 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [Unreleased](https://github.com/LostArtefacts/TR1X/compare/stable...develop) - ××××-××-××
- added `/exit` command (#1462)
- added reflections to Midas Hand death animation and savegame crystals (#154)
- fixed `/play`, `/load`, `/demo` and similar commands not working in stats, credits, cinematics and fmvs (#1477)
- fixed console commands being able to interfere with demos, cutscenes and the title screen (#1489, regression from 3.0)
- fixed reopening the compass not resetting its needle (#1472, regression from 4.0)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ Not all options are turned on by default. Refer to `TR1X_ConfigTool.exe` for det
- added contextual arrows to menu options
- added support for animated room sprites, which also restores intended behavior in, for example, The Cistern room 0
- added skybox support, with a default option provided for Lost Valley, Colosseum and Obelisk of Khamoon; custom level builders can use object slot `184`
- added reflections of Midas Hand death animation and savegame crystals
- changed the Scion in The Great Pyramid from spawning blood when hit to a richochet effect
- fixed thin black lines between polygons
- fixed black screen flashing when navigating the inventory
Expand Down
1 change: 1 addition & 0 deletions data/ship/cfg/TR1X_gameflow.json5
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@
"DETAIL_FPS": "FPS",
"DETAIL_PERSPECTIVE": "Perspective",
"DETAIL_PRETTY_PIXELS": "Pretty pixels",
"DETAIL_REFLECTIONS": "Reflections",
"DETAIL_BILINEAR": "Bilinear",
"DETAIL_TEXTURE_FILTER": "Texture filter",
"DETAIL_FBO_FILTER": "FBO filter",
Expand Down
1 change: 1 addition & 0 deletions data/ship/cfg/TR1X_gameflow_demo_pc.json5
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"DETAIL_FPS": "FPS",
"DETAIL_PERSPECTIVE": "Perspective",
"DETAIL_PRETTY_PIXELS": "Pretty pixels",
"DETAIL_REFLECTIONS": "Reflections",
"DETAIL_BILINEAR": "Bilinear",
"DETAIL_TEXTURE_FILTER": "Texture filter",
"DETAIL_FBO_FILTER": "FBO filter",
Expand Down
1 change: 1 addition & 0 deletions data/ship/cfg/TR1X_gameflow_ub.json5
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"DETAIL_FPS": "FPS",
"DETAIL_PERSPECTIVE": "Perspective",
"DETAIL_PRETTY_PIXELS": "Pretty pixels",
"DETAIL_REFLECTIONS": "Reflections",
"DETAIL_BILINEAR": "Bilinear",
"DETAIL_TEXTURE_FILTER": "Texture filter",
"DETAIL_FBO_FILTER": "FBO filter",
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ typedef struct {
float anisotropy_filter;
int32_t turbo_speed;
bool pretty_pixels;
bool enable_reflections;
} rendering;

struct {
Expand Down
1 change: 1 addition & 0 deletions src/config_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ CFG_DOUBLE(g_Config, rendering.wireframe_width, 2.5)
CFG_BOOL(g_Config, rendering.enable_perspective_filter, true)
CFG_BOOL(g_Config, rendering.enable_vsync, true)
CFG_BOOL(g_Config, rendering.pretty_pixels, true)
CFG_BOOL(g_Config, rendering.enable_reflections, true)
CFG_INT32(g_Config, music_volume, 8)
CFG_INT32(g_Config, sound_volume, 8)
CFG_INT32(g_Config, input.layout, 0)
Expand Down
5 changes: 3 additions & 2 deletions src/game/collide.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "config.h"
#include "game/items.h"
#include "game/output.h"
#include "game/room.h"
#include "global/const.h"
#include "global/types.h"
Expand Down Expand Up @@ -514,7 +515,7 @@ int32_t Collide_GetSpheres(ITEM_INFO *item, SPHERE *ptr, int32_t world_space)
ptr->x = x + (g_MatrixPtr->_03 >> W2V_SHIFT);
ptr->y = y + (g_MatrixPtr->_13 >> W2V_SHIFT);
ptr->z = z + (g_MatrixPtr->_23 >> W2V_SHIFT);
ptr->r = objptr[3];
ptr->r = DISABLE_REFLECTION_BIT(objptr[3]);
ptr++;
Matrix_Pop();

Expand Down Expand Up @@ -547,7 +548,7 @@ int32_t Collide_GetSpheres(ITEM_INFO *item, SPHERE *ptr, int32_t world_space)
ptr->x = x + (g_MatrixPtr->_03 >> W2V_SHIFT);
ptr->y = y + (g_MatrixPtr->_13 >> W2V_SHIFT);
ptr->z = z + (g_MatrixPtr->_23 >> W2V_SHIFT);
ptr->r = objptr[3];
ptr->r = DISABLE_REFLECTION_BIT(objptr[3]);
Matrix_Pop();

ptr++;
Expand Down
16 changes: 16 additions & 0 deletions src/game/game/game_draw.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "game/game.h"

#include "config.h"
#include "game/camera.h"
#include "game/interpolation.h"
#include "game/lara/lara_draw.h"
#include "game/lara/lara_hair.h"
#include "game/output.h"
#include "game/overlay.h"
Expand All @@ -20,11 +22,25 @@ void Game_DrawScene(bool draw_overlay)

if (g_Objects[O_LARA].loaded) {
Room_DrawAllRooms(g_Camera.interp.room_num, g_Camera.target.room_num);

if (g_Config.rendering.enable_reflections) {
Output_FillEnvironmentMap();
}

if (g_RoomInfo[g_LaraItem->room_num].flags & RF_UNDERWATER) {
Output_SetupBelowWater(g_Camera.underwater);
} else {
Output_SetupAboveWater(g_Camera.underwater);
}

Lara_Draw(g_LaraItem);

if (draw_overlay) {
Overlay_DrawGameInfo();
} else {
Overlay_HideGameInfo();
}

} else {
// cinematic scene
for (int i = 0; i < g_RoomsToDrawCount; i++) {
Expand Down
1 change: 1 addition & 0 deletions src/game/game_string.def
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ GS_DEFINE(DETAIL_LEVEL_LOW, "Low")
GS_DEFINE(DETAIL_FPS, "FPS")
GS_DEFINE(DETAIL_PERSPECTIVE, "Perspective")
GS_DEFINE(DETAIL_PRETTY_PIXELS, "Pretty pixels")
GS_DEFINE(DETAIL_REFLECTIONS, "Reflections")
GS_DEFINE(DETAIL_BILINEAR, "Bilinear")
GS_DEFINE(DETAIL_TEXTURE_FILTER, "Texture filter")
GS_DEFINE(DETAIL_FBO_FILTER, "FBO filter")
Expand Down
20 changes: 10 additions & 10 deletions src/game/lara/lara_hair.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void Lara_Hair_Control(void)
sphere[0].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[0].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[0].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[0].r = objptr[3];
sphere[0].r = DISABLE_REFLECTION_BIT(objptr[3]);
Matrix_Pop_I();

// torso
Expand All @@ -165,7 +165,7 @@ void Lara_Hair_Control(void)
sphere[1].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[1].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[1].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[1].r = objptr[3];
sphere[1].r = DISABLE_REFLECTION_BIT(objptr[3]);
Matrix_Pop_I();

// right arm
Expand All @@ -180,7 +180,7 @@ void Lara_Hair_Control(void)
sphere[3].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[3].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[3].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[3].r = (int32_t)objptr[3] * 3 / 2;
sphere[3].r = (int32_t)DISABLE_REFLECTION_BIT(objptr[3]) * 3 / 2;
Matrix_Pop_I();

// left arm
Expand All @@ -195,7 +195,7 @@ void Lara_Hair_Control(void)
sphere[4].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[4].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[4].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[4].r = (int32_t)objptr[3] * 3 / 2;
sphere[4].r = (int32_t)DISABLE_REFLECTION_BIT(objptr[3]) * 3 / 2;
Matrix_Pop_I();

// head
Expand All @@ -213,7 +213,7 @@ void Lara_Hair_Control(void)
sphere[2].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[2].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[2].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[2].r = objptr[3];
sphere[2].r = DISABLE_REFLECTION_BIT(objptr[3]);
Matrix_Pop_I();

Matrix_TranslateRel_I(HAIR_OFFSET_X, HAIR_OFFSET_Y, HAIR_OFFSET_Z);
Expand All @@ -231,7 +231,7 @@ void Lara_Hair_Control(void)
sphere[0].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[0].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[0].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[0].r = objptr[3];
sphere[0].r = DISABLE_REFLECTION_BIT(objptr[3]);
Matrix_Pop();

// torso
Expand All @@ -247,7 +247,7 @@ void Lara_Hair_Control(void)
sphere[1].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[1].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[1].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[1].r = objptr[3];
sphere[1].r = DISABLE_REFLECTION_BIT(objptr[3]);
Matrix_Pop();

// right arm
Expand All @@ -260,7 +260,7 @@ void Lara_Hair_Control(void)
sphere[3].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[3].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[3].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[3].r = (int32_t)objptr[3] * 3 / 2;
sphere[3].r = (int32_t)DISABLE_REFLECTION_BIT(objptr[3]) * 3 / 2;
Matrix_Pop();

// left arm
Expand All @@ -273,7 +273,7 @@ void Lara_Hair_Control(void)
sphere[4].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[4].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[4].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[4].r = (int32_t)objptr[3] * 3 / 2;
sphere[4].r = (int32_t)DISABLE_REFLECTION_BIT(objptr[3]) * 3 / 2;
Matrix_Pop();

// head
Expand All @@ -289,7 +289,7 @@ void Lara_Hair_Control(void)
sphere[2].x = g_MatrixPtr->_03 >> W2V_SHIFT;
sphere[2].y = g_MatrixPtr->_13 >> W2V_SHIFT;
sphere[2].z = g_MatrixPtr->_23 >> W2V_SHIFT;
sphere[2].r = objptr[3];
sphere[2].r = DISABLE_REFLECTION_BIT(objptr[3]);
Matrix_Pop();

Matrix_TranslateRel(HAIR_OFFSET_X, HAIR_OFFSET_Y, HAIR_OFFSET_Z);
Expand Down
4 changes: 4 additions & 0 deletions src/game/lara/lara_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "game/items.h"
#include "game/lara.h"
#include "game/lara/lara_look.h"
#include "game/objects/common.h"
#include "game/objects/effects/twinkle.h"
#include "game/room.h"
#include "game/sound.h"
Expand Down Expand Up @@ -678,6 +679,8 @@ void Lara_State_DieMidas(ITEM_INFO *item, COLL_INFO *coll)
coll->enable_spaz = 0;
coll->enable_baddie_push = 0;

Object_SetReflective(O_LARA_EXTRA, true);

int frm = item->frame_num - g_Anims[item->anim_num].frame_base;
switch (frm) {
case 5:
Expand Down Expand Up @@ -745,6 +748,7 @@ void Lara_State_DieMidas(ITEM_INFO *item, COLL_INFO *coll)
break;

case 225:
Object_SetReflective(O_HAIR, true);
g_Lara.mesh_effects |= (1 << LM_HEAD);
Lara_SwapSingleMesh(LM_HEAD, O_LARA_EXTRA);
break;
Expand Down
62 changes: 62 additions & 0 deletions src/game/objects/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,65 @@ void Object_DrawUnclippedItem(ITEM_INFO *item)
g_PhdRight = right;
g_PhdBottom = bottom;
}

void Object_SetMeshReflective(
const GAME_OBJECT_ID object_id, const int32_t mesh_idx, const bool enabled)
{
const OBJECT_INFO *const object = &g_Objects[object_id];
if (!object->loaded) {
return;
}
int16_t *obj_ptr = g_Meshes[object->mesh_index + mesh_idx];

TOGGLE_REFLECTION_ENABLED(obj_ptr[3], enabled);

obj_ptr += 5;
int32_t vertex_count = *obj_ptr++;
obj_ptr += vertex_count * 3;
vertex_count = *obj_ptr++;
if (vertex_count > 0) {
obj_ptr += vertex_count * 3;
} else {
obj_ptr += vertex_count;
}

// textured quads
int32_t num = *obj_ptr++;
for (int32_t i = 0; i < num; i++) {
// skip vertices
obj_ptr += 4;
TOGGLE_REFLECTION_ENABLED(*obj_ptr++, enabled);
}

// textured triangles
num = *obj_ptr++;
for (int32_t i = 0; i < num; i++) {
// skip vertices
obj_ptr += 3;
TOGGLE_REFLECTION_ENABLED(*obj_ptr++, enabled);
}

// color quads
num = *obj_ptr++;
for (int32_t i = 0; i < num; i++) {
// skip vertices
obj_ptr += 4;
TOGGLE_REFLECTION_ENABLED(*obj_ptr++, enabled);
}

// color triangles
num = *obj_ptr++;
for (int32_t i = 0; i < num; i++) {
// skip vertices
obj_ptr += 3;
TOGGLE_REFLECTION_ENABLED(*obj_ptr++, enabled);
}
}

void Object_SetReflective(const GAME_OBJECT_ID object_id, const bool enabled)
{
const OBJECT_INFO *const object = &g_Objects[object_id];
for (int32_t i = 0; i < object->nmeshes; i++) {
Object_SetMeshReflective(object_id, i, enabled);
}
}
3 changes: 3 additions & 0 deletions src/game/objects/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ void Object_DrawSpriteItem(ITEM_INFO *item);
void Object_DrawPickupItem(ITEM_INFO *item);
void Object_DrawAnimatingItem(ITEM_INFO *item);
void Object_DrawUnclippedItem(ITEM_INFO *item);
void Object_SetMeshReflective(
GAME_OBJECT_ID object_id, int32_t mesh_idx, bool enabled);
void Object_SetReflective(GAME_OBJECT_ID object_id, bool enabled);
1 change: 1 addition & 0 deletions src/game/objects/general/save_crystal.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void SaveCrystal_Setup(OBJECT_INFO *obj)
obj->save_flags = 1;
}
obj->bounds = SaveCrystal_Bounds;
Object_SetReflective(O_SAVEGAME_ITEM, true);
}

void SaveCrystal_Initialise(int16_t item_num)
Expand Down
28 changes: 27 additions & 1 deletion src/game/option/option_graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ typedef enum GRAPHICS_OPTION_NAME {
OPTION_RESOLUTION,
OPTION_PERSPECTIVE,
OPTION_PRETTY_PIXELS,
OPTION_REFLECTIONS,
OPTION_NUMBER_OF,
OPTION_MIN = OPTION_FPS,
OPTION_MAX = OPTION_PRETTY_PIXELS,
OPTION_MAX = OPTION_REFLECTIONS,
} GRAPHICS_OPTION_NAME;

typedef struct GRAPHICS_OPTION_ROW {
Expand Down Expand Up @@ -85,6 +86,7 @@ static const GRAPHICS_OPTION_ROW m_GfxOptionRows[] = {
{ OPTION_RESOLUTION, GS_DETAIL_RESOLUTION, GS_DETAIL_RESOLUTION_FMT },
{ OPTION_PERSPECTIVE, GS_DETAIL_PERSPECTIVE, GS_MISC_ON },
{ OPTION_PRETTY_PIXELS, GS_DETAIL_PRETTY_PIXELS, GS_MISC_ON },
{ OPTION_REFLECTIONS, GS_DETAIL_REFLECTIONS, GS_MISC_ON },
// end
{ OPTION_NUMBER_OF, 0, 0 },
};
Expand Down Expand Up @@ -302,6 +304,10 @@ static void Option_Graphics_UpdateArrows(
m_HideArrowLeft = !g_Config.rendering.pretty_pixels;
m_HideArrowRight = g_Config.rendering.pretty_pixels;
break;
case OPTION_REFLECTIONS:
m_HideArrowLeft = !g_Config.rendering.enable_reflections;
m_HideArrowRight = g_Config.rendering.enable_reflections;
break;

case OPTION_NUMBER_OF:
default:
Expand Down Expand Up @@ -447,6 +453,12 @@ static void Option_Graphics_ChangeTextOption(
break;
}

case OPTION_REFLECTIONS: {
bool is_enabled = g_Config.rendering.enable_reflections;
Text_ChangeText(value_text, is_enabled ? GS(MISC_ON) : GS(MISC_OFF));
break;
}

case OPTION_NUMBER_OF:
default:
break;
Expand Down Expand Up @@ -557,6 +569,13 @@ void Option_Graphics(INVENTORY_ITEM *inv_item)
}
break;

case OPTION_REFLECTIONS:
if (!g_Config.rendering.enable_reflections) {
g_Config.rendering.enable_reflections = true;
reset = OPTION_REFLECTIONS;
}
break;

case OPTION_NUMBER_OF:
default:
break;
Expand Down Expand Up @@ -644,6 +663,13 @@ void Option_Graphics(INVENTORY_ITEM *inv_item)
}
break;

case OPTION_REFLECTIONS:
if (g_Config.rendering.enable_reflections) {
g_Config.rendering.enable_reflections = false;
reset = OPTION_REFLECTIONS;
}
break;

case OPTION_NUMBER_OF:
default:
break;
Expand Down
Loading

0 comments on commit 1cb8ae9

Please sign in to comment.