From 04e38c80d6c025efea7a212c6d9461f1595b9fc8 Mon Sep 17 00:00:00 2001 From: Emmanuel AYME Date: Mon, 5 Jan 2026 21:20:10 +0100 Subject: [PATCH] Add Reshade include --- external/reshade/shaders/ReShade.fxh | 124 +++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 external/reshade/shaders/ReShade.fxh diff --git a/external/reshade/shaders/ReShade.fxh b/external/reshade/shaders/ReShade.fxh new file mode 100644 index 0000000..e12b5ba --- /dev/null +++ b/external/reshade/shaders/ReShade.fxh @@ -0,0 +1,124 @@ +/* + * SPDX-License-Identifier: CC0-1.0 + */ + +#pragma once + +#if !defined(__RESHADE__) || __RESHADE__ < 30000 + #error "ReShade 3.0+ is required to use this header file" +#endif + +#ifndef RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN + #define RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN 0 +#endif +#ifndef RESHADE_DEPTH_INPUT_IS_REVERSED + #define RESHADE_DEPTH_INPUT_IS_REVERSED 1 +#endif +#ifndef RESHADE_DEPTH_INPUT_IS_MIRRORED + #define RESHADE_DEPTH_INPUT_IS_MIRRORED 0 +#endif +#ifndef RESHADE_DEPTH_INPUT_IS_LOGARITHMIC + #define RESHADE_DEPTH_INPUT_IS_LOGARITHMIC 0 +#endif + +#ifndef RESHADE_DEPTH_MULTIPLIER + #define RESHADE_DEPTH_MULTIPLIER 1 +#endif +#ifndef RESHADE_DEPTH_LINEARIZATION_FAR_PLANE + #define RESHADE_DEPTH_LINEARIZATION_FAR_PLANE 1000.0 +#endif + +// Above 1 expands coordinates, below 1 contracts and 1 is equal to no scaling on any axis +#ifndef RESHADE_DEPTH_INPUT_Y_SCALE + #define RESHADE_DEPTH_INPUT_Y_SCALE 1 +#endif +#ifndef RESHADE_DEPTH_INPUT_X_SCALE + #define RESHADE_DEPTH_INPUT_X_SCALE 1 +#endif +// An offset to add to the Y coordinate, (+) = move up, (-) = move down +#ifndef RESHADE_DEPTH_INPUT_Y_OFFSET + #define RESHADE_DEPTH_INPUT_Y_OFFSET 0 +#endif +#ifndef RESHADE_DEPTH_INPUT_Y_PIXEL_OFFSET + #define RESHADE_DEPTH_INPUT_Y_PIXEL_OFFSET 0 +#endif +// An offset to add to the X coordinate, (+) = move right, (-) = move left +#ifndef RESHADE_DEPTH_INPUT_X_OFFSET + #define RESHADE_DEPTH_INPUT_X_OFFSET 0 +#endif +#ifndef RESHADE_DEPTH_INPUT_X_PIXEL_OFFSET + #define RESHADE_DEPTH_INPUT_X_PIXEL_OFFSET 0 +#endif + +#define BUFFER_PIXEL_SIZE float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT) +#define BUFFER_SCREEN_SIZE float2(BUFFER_WIDTH, BUFFER_HEIGHT) +#define BUFFER_ASPECT_RATIO (BUFFER_WIDTH * BUFFER_RCP_HEIGHT) + +namespace ReShade +{ +#if defined(__RESHADE_FXC__) + float GetAspectRatio() { return BUFFER_WIDTH * BUFFER_RCP_HEIGHT; } + float2 GetPixelSize() { return float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); } + float2 GetScreenSize() { return float2(BUFFER_WIDTH, BUFFER_HEIGHT); } + #define AspectRatio GetAspectRatio() + #define PixelSize GetPixelSize() + #define ScreenSize GetScreenSize() +#else + // These are deprecated and will be removed eventually. + static const float AspectRatio = BUFFER_WIDTH * BUFFER_RCP_HEIGHT; + static const float2 PixelSize = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); + static const float2 ScreenSize = float2(BUFFER_WIDTH, BUFFER_HEIGHT); +#endif + + // Global textures and samplers + texture BackBufferTex : COLOR; + texture DepthBufferTex : DEPTH; + + sampler BackBuffer { Texture = BackBufferTex; }; + sampler DepthBuffer { Texture = DepthBufferTex; }; + + // Helper functions + float GetLinearizedDepth(float2 texcoord) + { +#if RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN + texcoord.y = 1.0 - texcoord.y; +#endif +#if RESHADE_DEPTH_INPUT_IS_MIRRORED + texcoord.x = 1.0 - texcoord.x; +#endif + texcoord.x /= RESHADE_DEPTH_INPUT_X_SCALE; + texcoord.y /= RESHADE_DEPTH_INPUT_Y_SCALE; +#if RESHADE_DEPTH_INPUT_X_PIXEL_OFFSET + texcoord.x -= RESHADE_DEPTH_INPUT_X_PIXEL_OFFSET * BUFFER_RCP_WIDTH; +#else // Do not check RESHADE_DEPTH_INPUT_X_OFFSET, since it may be a decimal number, which the preprocessor cannot handle + texcoord.x -= RESHADE_DEPTH_INPUT_X_OFFSET / 2.000000001; +#endif +#if RESHADE_DEPTH_INPUT_Y_PIXEL_OFFSET + texcoord.y += RESHADE_DEPTH_INPUT_Y_PIXEL_OFFSET * BUFFER_RCP_HEIGHT; +#else + texcoord.y += RESHADE_DEPTH_INPUT_Y_OFFSET / 2.000000001; +#endif + float depth = tex2Dlod(DepthBuffer, float4(texcoord, 0, 0)).x * RESHADE_DEPTH_MULTIPLIER; + +#if RESHADE_DEPTH_INPUT_IS_LOGARITHMIC + const float C = 0.01; + depth = (exp(depth * log(C + 1.0)) - 1.0) / C; +#endif +#if RESHADE_DEPTH_INPUT_IS_REVERSED + depth = 1.0 - depth; +#endif + const float N = 1.0; + depth /= RESHADE_DEPTH_LINEARIZATION_FAR_PLANE - depth * (RESHADE_DEPTH_LINEARIZATION_FAR_PLANE - N); + + return depth; + } +} + +// Vertex shader generating a triangle covering the entire screen +// See also https://www.reddit.com/r/gamedev/comments/2j17wk/a_slightly_faster_bufferless_vertex_shader_trick/ +void PostProcessVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD) +{ + texcoord.x = (id == 2) ? 2.0 : 0.0; + texcoord.y = (id == 1) ? 2.0 : 0.0; + position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0); +}