Skip to content

Commit

Permalink
tr2: use hybrid OpenGL/DirectX rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Dec 11, 2024
1 parent 09f7ec6 commit 22a9433
Show file tree
Hide file tree
Showing 93 changed files with 9,312 additions and 12,473 deletions.
76 changes: 76 additions & 0 deletions data/tr2/ship/shaders/2d.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#ifdef VERTEX
// Vertex shader

#ifdef OGL33C
out vec2 vertTexCoords;
out vec2 vertCoords;
#else
varying vec2 vertTexCoords;
varying vec2 vertCoords;
#endif

layout(location = 0) in vec2 inPosition;
layout(location = 1) in vec2 inTexCoords;

void main(void) {
gl_Position = vec4(inPosition * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0);
vertCoords = inPosition;
vertTexCoords = inTexCoords;
}

#else
// Fragment shader

#define EFFECT_NONE 0
#define EFFECT_VIGNETTE 1

uniform sampler2D texMain;
uniform sampler1D texPalette;
uniform sampler2D texAlpha;
uniform bool paletteEnabled;
uniform bool alphaEnabled;
uniform int effect;

#ifdef OGL33C
#define OUTCOLOR outColor
#define TEXTURE2D texture
#define TEXTURE1D texture

in vec2 vertTexCoords;
in vec2 vertCoords;
out vec4 outColor;
#else
#define OUTCOLOR gl_FragColor
#define TEXTURE2D texture2D
#define TEXTURE1D texture1D

varying vec2 vertTexCoords;
varying vec2 vertCoords;
#endif

void main(void) {
vec2 uv = vertTexCoords;

if (alphaEnabled) {
float alpha = TEXTURE2D(texAlpha, uv).r;
if (alpha < 0.5) {
discard;
}
}

if (paletteEnabled) {
float paletteIndex = TEXTURE2D(texMain, uv).r;
OUTCOLOR = TEXTURE1D(texPalette, paletteIndex);
} else {
OUTCOLOR = TEXTURE2D(texMain, uv);
}

if (effect == EFFECT_VIGNETTE) {
float x_dist = vertCoords.x - 0.5;
float y_dist = vertCoords.y - 0.5;
float light = 256 - sqrt(x_dist * x_dist + y_dist * y_dist ) * 300.0;
light = clamp(light, 0, 255) / 255;
OUTCOLOR *= vec4(light, light, light, 1);
}
}
#endif // VERTEX
77 changes: 77 additions & 0 deletions data/tr2/ship/shaders/3d.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#ifdef VERTEX
// Vertex shader

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inTexCoords;
layout(location = 2) in vec4 inColor;

uniform mat4 matProjection;
uniform mat4 matModelView;

#ifdef OGL33C
out vec4 vertColor;
out vec3 vertTexCoords;
#else
varying vec4 vertColor;
varying vec3 vertTexCoords;
#endif

void main(void) {
gl_Position = matProjection * matModelView * vec4(inPosition, 1);
vertColor = inColor / 255.0;
vertTexCoords = inTexCoords;
}

#else
// Fragment shader

uniform sampler2D tex0;
uniform bool texturingEnabled;
uniform bool smoothingEnabled;
uniform bool colorKeyEnabled;

#ifdef OGL33C
#define OUTCOLOR outColor
#define TEXTURESIZE textureSize
#define TEXTURE texture
#define TEXELFETCH texelFetch

in vec4 vertColor;
in vec3 vertTexCoords;
out vec4 OUTCOLOR;
#else
#define OUTCOLOR gl_FragColor
#define TEXTURESIZE textureSize2D
#define TEXELFETCH texelFetch2D
#define TEXTURE texture2D

varying vec4 vertColor;
varying vec3 vertTexCoords;
#endif

void main(void) {
OUTCOLOR = vertColor;

if (texturingEnabled) {
#if defined(GL_EXT_gpu_shader4) || defined(OGL33C)
if (colorKeyEnabled && smoothingEnabled) {
// do not use smoothing for chroma key
ivec2 size = TEXTURESIZE(tex0, 0);
int tx = int((vertTexCoords.x / vertTexCoords.z) * size.x) % size.x;
int ty = int((vertTexCoords.y / vertTexCoords.z) * size.y) % size.y;
vec4 texel = TEXELFETCH(tex0, ivec2(tx, ty), 0);
if (texel.a == 0.0) {
discard;
}
}
#endif

vec4 texColor = TEXTURE(tex0, vertTexCoords.xy / vertTexCoords.z);
if (colorKeyEnabled && texColor.a == 0.0) {
discard;
}

OUTCOLOR = vec4(OUTCOLOR.rgb * texColor.rgb, texColor.a);
}
}
#endif // VERTEX
25 changes: 25 additions & 0 deletions data/tr2/ship/shaders/fade.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifdef VERTEX
// Vertex shader

layout(location = 0) in vec2 inPosition;

void main(void) {
gl_Position = vec4(inPosition * vec2(2.0, -2.0) + vec2(-1.0, 1.0), 0.0, 1.0);
}

#else
// Fragment shader

uniform float opacity;

#ifdef OGL33C
#define OUTCOLOR outColor
out vec4 outColor;
#else
#define OUTCOLOR gl_FragColor
#endif

void main(void) {
OUTCOLOR = vec4(0, 0, 0, opacity);
}
#endif // VERTEX
38 changes: 38 additions & 0 deletions data/tr2/ship/shaders/fbo.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifdef VERTEX
// Vertex shader

layout(location = 0) in vec2 inPosition;

#ifdef OGL33C
out vec2 vertTexCoords;
#else
varying vec2 vertTexCoords;
#endif

void main(void) {
vertTexCoords = inPosition;
gl_Position = vec4(vertTexCoords * vec2(2.0, 2.0) + vec2(-1.0, -1.0), 0.0, 1.0);
}

#else
// Fragment shader

uniform sampler2D tex0;

#ifdef OGL33C
#define OUTCOLOR outColor
#define TEXTURE texture

in vec2 vertTexCoords;
out vec4 OUTCOLOR;
#else
#define OUTCOLOR gl_FragColor
#define TEXTURE texture2D

varying vec2 vertTexCoords;
#endif

void main(void) {
OUTCOLOR = TEXTURE(tex0, vertTexCoords);
}
#endif // VERTEX
23 changes: 18 additions & 5 deletions docs/tr2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr2-0.6...develop) - ××××-××-××
- switched to OpenGL rendering
- changed fullscreen behavior to use windowed desktop mode
- added an option for 1-2-3-4× pixel upscaling (available under the F1/Shift-F1 key)
- added the ability to use the window border option at all times (available under the F2/Shift-F2 key)
- added the ability to toggle between the SWR/HWR renderer at runtime (available under the F12 key)
- added fade effects to the HWR renderer
- changed the SWR to use the picture's palette for the background pictures
- replaced fully the Windows Registry configuration with .json files
- removed setup dialog support (using `Tomb2.exe -setup` will have no effect on TR2X)
- removed unused detail level option
- removed triple buffering option
- removed dither option
- added toggle wireframe option (available with `/set` console command and with Shift+F7)
- added support for custom levels to enforce values for any config setting (#1846)
- added an option to fix inventory item usage duplication (#1586)
- added optional automatic key/puzzle inventory item pre-selection (#1884)
- added a search feature to the config tool (#1889)
- added an option to fix rotation on some pickup items to better suit 3D pickup mode (#1613)
- added an ability to use the game sizer at all times
- changed config to store certain values in the .json file rather than Windows registry
- music volume
- sound volume
- game sizer
- added ability to turn fade effects on/off
- fixed a crash relating to audio decoding (#1895)
- fixed depth problems when drawing certain rooms (#1853, regression from 0.6)
- fixed Lara getting stuck in her hit animation if she is hit while mounting the boat or skidoo (#1606)
Expand All @@ -35,6 +44,10 @@
- fixed Lara's left arm becoming stuck if a flare is drawn just before the final cutscene in Home Sweet Home (#1992)
- fixed game crash when trying to draw too many rooms at once (#1998)
- fixed resizing game window on the stats dialog cloning the UI elements, eventually crashing the game (#1999)
- fixed exiting the game with Alt+F4 not immediately working in cutscenes
- fixed game freezing when starting demo/credits/inventory offscreen
- fixed controllers dialog missing background in the software renderer mode (#1978, regression from 0.6)
- fixed distant rooms sometimes not appearing, causing the skybox to be visible when it shouldn't (#2000)
- removed unused detail level option

## [0.6](https://github.com/LostArtefacts/TRX/compare/tr2-0.5...tr2-0.6) - 2024-11-06
Expand Down
22 changes: 17 additions & 5 deletions docs/tr2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ decompilation process. We recognize that there is much work to be done.
- fixed a potential crash if Lara is on the skidoo in a room with many other adjoining rooms
- fixed a softlock in Home Sweet Home if the final cutscene is triggered while Lara is on water surface
- fixed Lara's left arm becoming stuck if a flare is drawn just before the final cutscene in Home Sweet Home
- fixed game freezing when starting demo/credits/inventory offscreen
- fixed exiting the game with Alt+F4 not immediately working in cutscenes
- fixed a crash when trying to draw too many rooms at once
- fixed the following floor data issues:
- **Opera House**: fixed the trigger under item 203 to trigger it rather than item 204
- **Wreck of the Maria Doria**: fixed room 98 not having water
Expand All @@ -62,6 +65,7 @@ decompilation process. We recognize that there is much work to be done.
#### Input
- added additional custom control schemes
- added customizable controller support
- added ability to hold forward/back to move through menus more quickly
- fixed setting user keys being very difficult
- fixed skipping FMVs triggering inventory
- fixed skipping credits working too fast
Expand All @@ -70,14 +74,19 @@ decompilation process. We recognize that there is much work to be done.
- fixed the dragon counting as more than one kill if allowed to revive
- fixed enemies that are run over by the skidoo not being counted in the statistics

#### Input
- added ability to hold forward/back to move through menus more quickly

#### Visuals
- added support for HD FMVs
- added wireframe mode
- added an option for 1-2-3-4× pixel upscaling
- added the ability to use the window border option at all times
- added the ability to toggle between the software/hardware renderer at runtime
- added fade effects to the hardware renderer
- changed the software renderer to use the picture's palette for the background pictures
- fixed fullscreen issues
- fixed TGA screenshots crashing the game
- fixed the camera being cut off after using the gong hammer in Ice Palace
- fixed Lara's underwater hue being retained when re-entering a boat
- fixed distant rooms sometimes not appearing, causing the skybox to be visible when it shouldn't
- improved FMV mode behavior - stopped switching screen resolutions
- improved vertex movement when looking through water portals

Expand All @@ -94,10 +103,13 @@ decompilation process. We recognize that there is much work to be done.
- added .jpeg/.png screenshots
- added ability to skip FMVs with both the Action key
- added ability to skip end credits with the Action and Escape keys
- ported audio decoding library to ffmpeg
- ported video decoding library to ffmpeg
- ported audio output library to SDL
- ported input method to SDL
- ported input backend to SDL
- ported audio backend to SDL
- ported video backend to SDL
- fixed screenshots not working in windowed mode
- fixed screenshots key not getting debounced
- changed screenshots to be put in the screenshots/ directory
- changed saves to be put in the saves/ directory
- removed `-setup` dialog
Loading

0 comments on commit 22a9433

Please sign in to comment.