Add RenoDX DLSS5 Addon for OpenGL Reshade

This commit is contained in:
D4rkl1ght3r
2026-09-02 22:07:05 +02:00
parent fc30dc8aaa
commit c105e73c74
21 changed files with 4990 additions and 0 deletions
@@ -0,0 +1,252 @@
/*
========================================================================
Copyright (c) Afzaal. All rights reserved.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
========================================================================
GitHub : https://github.com/umar-afzaal/LumeniteFX
Discord : https://discord.gg/deXJrW2dx6
Filename : lumenite_ColorManagement.fxh
Version : 2026.05.05
Author : Afzaal (Kaidō)
Description: Provides color management including color space detection,
color space transfers and tonemapping.
Supported colorbuffers:
- SDR (sRGB)
- HDR (scRGB / Linear)
- HDR (PQ / ST.2084)
- HDR (HLG)
License : AGNYA License (https://github.com/nvb-uy/AGNYA-License)
========================================================================
*/
#pragma once
/*-------------------.
| :: PREPROCESSOR :: |
'-------------------*/
#ifndef HDR_WHITELEVEL
#define HDR_WHITELEVEL 203
#endif
#if BUFFER_COLOR_SPACE > 0
//already defined by ReShade
#else
#if BUFFER_COLOR_BIT_DEPTH == 8
#undef BUFFER_COLOR_SPACE
#define BUFFER_COLOR_SPACE 1 //sRGB
#elif BUFFER_COLOR_BIT_DEPTH == 16
#undef BUFFER_COLOR_SPACE
#define BUFFER_COLOR_SPACE 2 //scRGB
#elif __RENDERER__ < 0xb000
#undef BUFFER_COLOR_SPACE
#define BUFFER_COLOR_SPACE 1 //D3D9/10 usually SDR
#endif
#endif
/*------------------.
| :: UI UNIFORMS :: |
'------------------*/
// uniform int SHOW_COLOR_SPACE <
// ui_category = "Color Management";
// ui_type = "combo";
// ui_label = "Colorspace";
// ui_tooltip = "Shows the detected color space.\n1=sRGB, 2=scRGB, 3=PQ, 4=HLG";
// hidden = true;
// #if BUFFER_COLOR_SPACE == 1
// ui_items = "sRGB (Detected)\0";
// #elif BUFFER_COLOR_SPACE == 2
// ui_items = "scRGB (Detected)\0";
// #elif BUFFER_COLOR_SPACE == 3
// ui_items = "PQ / ST.2084 (Detected)\0";
// #elif BUFFER_COLOR_SPACE == 4
// ui_items = "HLG (Detected)\0";
// #else
// ui_items = "Unknown (Defaulting to sRGB)\0";
// #endif
// > = 0;
#if BUFFER_COLOR_BIT_DEPTH > 8 || BUFFER_COLOR_SPACE > 1
#define COLORSPACE_CONVERSION 1 //use approx. transfer function; 0 for accurate
#else
#define COLORSPACE_CONVERSION 2 //N/A for 8-bit
#endif
#if BUFFER_COLOR_SPACE == 1
#define TONEMAPPER 1 //reinhard tonemapper workflow for SDR (sRGB) colorbuffer; 0 for None
#else
#define TONEMAPPER 0
#endif
/*-------------------------.
| :: TRANSFER FUNCTIONS :: |
'-------------------------*/
//sRGB
float3 sRGBtoLinearAccurate(float3 r) {
return (r <= 0.04045) ? (r / 12.92) : pow(abs(r + 0.055) / 1.055, 2.4);
}
float3 sRGBtoLinearFast(float3 r) {
return max(r / 12.92, r * r); //gamma 2.0 approx
}
float3 sRGBtoLinear(float3 r) {
if (COLORSPACE_CONVERSION == 1) return sRGBtoLinearFast(r);
else return sRGBtoLinearAccurate(r);
}
float3 linearToSRGBAccurate(float3 r) {
return (r <= 0.0031308) ? (r * 12.92) : (1.055 * pow(abs(r), 1.0 / 2.4) - 0.055);
}
float3 linearToSRGBFast(float3 r) {
return min(r * 12.92, sqrt(r)); //gamma 2.0 approx
}
float3 linearToSRGB(float3 r) {
if (COLORSPACE_CONVERSION == 1) return linearToSRGBFast(r);
else return linearToSRGBAccurate(r);
}
//PQ (ST.2084)
float3 PQtoLinearAccurate(float3 r) {
const float m1 = 1305.0/8192.0;
const float m2 = 2523.0/32.0;
const float c1 = 107.0/128.0;
const float c2 = 2413.0/128.0;
const float c3 = 2392.0/128.0;
float3 powr = pow(max(r, 0), 1.0/m2);
r = pow(max(max(powr - c1, 0) / (c2 - c3 * powr), 0), 1.0/m1);
//scale 10,000 nits down so Paper White (HDR_WHITELEVEL) maps to 1.0
return r * 10000.0 / HDR_WHITELEVEL;
}
float3 PQtoLinearFast(float3 r) {
float3 square = r * r;
float3 quad = square * square;
float3 oct = quad * quad;
r = max(max(square / 340.0, quad / 6.0), oct);
return r * 10000.0 / HDR_WHITELEVEL;
}
float3 PQtoLinear(float3 r) {
if (COLORSPACE_CONVERSION == 1) return PQtoLinearFast(r);
else return PQtoLinearAccurate(r);
}
float3 linearToPQAccurate(float3 r) {
const float m1 = 1305.0/8192.0;
const float m2 = 2523.0/32.0;
const float c1 = 107.0/128.0;
const float c2 = 2413.0/128.0;
const float c3 = 2392.0/128.0;
r = r * (HDR_WHITELEVEL / 10000.0); //rescale 1.0 back to nits
float3 powr = pow(max(r, 0), m1);
r = pow(max((c1 + c2 * powr) / (1 + c3 * powr), 0), m2);
return r;
}
float3 linearToPQFast(float3 r) {
r = r * (HDR_WHITELEVEL / 10000.0);
float3 squareroot = sqrt(r);
float3 quadroot = sqrt(squareroot);
float3 octroot = sqrt(quadroot);
r = min(octroot, min(sqrt(sqrt(6.0))*quadroot, sqrt(340.0)*squareroot));
return r;
}
float3 linearToPQ(float3 r) {
if (COLORSPACE_CONVERSION == 1) return linearToPQFast(r);
else return linearToPQAccurate(r);
}
//HLG (Hybrid Log Gamma)
float3 linearToHLG(float3 r) {
r = r * HDR_WHITELEVEL / 1000.0;
const float a = 0.17883277;
const float b = 0.28466892;
const float c = 0.55991073;
float3 s = sqrt(3 * r);
return (s < 0.5) ? s : (log(12 * r - b) * a + c);
}
float3 HLGtoLinear(float3 r) {
const float a = 0.17883277;
const float b = 0.28466892;
const float c = 0.55991073;
r = (r < 0.5) ? (r * r / 3.0) : ((exp((r - c) / a) + b) / 12.0);
return r * 1000.0 / HDR_WHITELEVEL;
}
//YCoCg
float3 linearToYCoCg(float3 r) {
float y = (r.r + 2.0 * r.g + r.b) * 0.25;
float co = (r.r - r.b) * 0.5;
float cg = (r.g - (r.r + r.b) * 0.5) * 0.5;
return float3(y, co, cg);
}
float3 YCoCgToLinear(float3 r) {
float y = r.x;
float co = r.y;
float cg = r.z;
float g = y + cg;
float rOut = y + co - cg;
float b = y - co - cg;
return float3(rOut, g, b);
}
/*--------------.
| :: HELPERS :: |
'--------------*/
float3 ToLinearColorspace(float3 r, bool tonemap) {
if (BUFFER_COLOR_SPACE == 2) r = r * (80.0 / HDR_WHITELEVEL); //scRGB
else if (BUFFER_COLOR_SPACE == 3) r = PQtoLinear(r);
else if (BUFFER_COLOR_SPACE == 4) r = HLGtoLinear(r);
else {
r = sRGBtoLinear(r);
if (TONEMAPPER == 1 && tonemap) r = r / max(1.0 - r, 0.001); //inverse reinhard
}
return r;
}
float3 ToOutputColorspace(float3 r, bool tonemap) {
if (BUFFER_COLOR_SPACE == 2) r = r * (HDR_WHITELEVEL / 80.0); //scRGB
else if (BUFFER_COLOR_SPACE == 3) r = linearToPQ(r);
else if (BUFFER_COLOR_SPACE == 4) r = linearToHLG(r);
else {
if (TONEMAPPER == 1 && tonemap) r = r / (1.0 + r); //forward reinhard
r = linearToSRGB(r);
}
return r;
}
//read the theoretical max value of the buffer (in linear scale)
float GetMaxColorValue() {
if (BUFFER_COLOR_SPACE == 4) return 1000.0 / HDR_WHITELEVEL;
if (BUFFER_COLOR_SPACE >= 2) return 10000.0 / HDR_WHITELEVEL;
return 1.0;
}
float GetLuminance(float3 color)
{
return dot(color, float3(0.2126, 0.7152, 0.0722));
}
float3 GetLinearColor(float2 uv, bool tonemap)
{
float3 color = tex2Dlod(ReShade::BackBuffer, float4(uv, 0, 0)).rgb;
return ToLinearColorspace(color, tonemap);
}
@@ -0,0 +1,54 @@
/*
========================================================================
Copyright (c) Afzaal. All rights reserved.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
========================================================================
GitHub : https://github.com/umar-afzaal/LumeniteFX
Discord : https://discord.gg/deXJrW2dx6
Filename : lumenite_Compute.fxh
Version : 2026.05.09
Author : Afzaal (Kaidō)
Description: Header file for supporting compute enabled platforms.
License : AGNYA License (https://github.com/nvb-uy/AGNYA-License)
========================================================================
*/
#pragma once
#include "ReShade.fxh"
/*------------------.
| :: DEFINITIONS :: |
'------------------*/
#define D3D9 0x9000
#define D3D10 0xa000
#define D3D11 0xb000
#define D3D12 0xc000
#define OPENGL 0x10000
#define VULKAN 0x20000
#if __RENDERER__ >= D3D11
#define _COMPUTE_ENABLED_ 1
#else
#define _COMPUTE_ENABLED_ 0
#endif
struct CSInput
{
uint3 dispatchID : SV_DispatchThreadID; //global pixel coord (x, y, 0)
uint3 groupID : SV_GroupID; //which tile/group in grid
uint3 localID : SV_GroupThreadID; //thread inside group [0..CS_W-1]
uint flatIndex : SV_GroupIndex; //localID flattened: y*CS_W + x
};
@@ -0,0 +1,94 @@
/*
========================================================================
Copyright (c) Afzaal. All rights reserved.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
========================================================================
GitHub : https://github.com/umar-afzaal/LumeniteFX
Discord : https://discord.gg/deXJrW2dx6
Filename : lumenite_Helpers.fxh
Version : 2026.05.30
Author : Afzaal (Kaidō)
Description: Helper functions for Lumenite shaders.
License : AGNYA License (https://github.com/nvb-uy/AGNYA-License)
========================================================================
*/
#pragma once
#include "ReShade.fxh"
/*------------------.
| :: DEFINITIONS :: |
'------------------*/
#define PI 3.14159265359
#define EPSILON 1e-6
//R2 sequence constants
static const float PHI_2 = 1.324717957244746;
static const float2 R2_CONSTANT = float2(1.0/PHI_2, 1.0/(PHI_2*PHI_2));
/*--------------.
| :: UNIFORMS ::|
'--------------*/
uniform float TIMER < source = "timer"; >; //ms since launch
uniform float FRAME_TIME < source = "frametime"; >; //ms last frame
uniform uint FRAME_COUNT < source = "framecount"; >;
uniform float2 MOUSE_POS < source = "mousepoint"; >; //in screen px
uniform bool MOUSE_DOWN < source = "mousebutton"; min = 0; max = 0; >;
/*--------------.
| :: HELPERS :: |
'--------------*/
bool CheckerboardSkip(uint2 currentPos, float scale)
{
//map current buffer pixel to full screen pixel.
//floor() to ensure we snap to the integer grid of the full screen
uint2 fullScreenPos = uint2(floor(currentPos.x * scale), floor(currentPos.y * scale));
return (((fullScreenPos.x + fullScreenPos.y + (FRAME_COUNT & 1)) & 1) == 1);
}
float GetDepth(float2 uv)
{
return ReShade::GetLinearizedDepth(uv);
}
bool IsOOB(float2 uv) {
return any(uv < 0.0) || any(uv > 1.0);
}
//QUASI-MONTE CARLO SEQUENCE
//fast Hilbert curve math (a 1D index from 2D coords)
uint HilbertIndex(uint x, uint y) {
uint index = 0;
[unroll] for (uint s = 64 / 2; s > 0; s /= 2) {
uint rx = (x & s) > 0;
uint ry = (y & s) > 0;
index += s * s * ((3 * rx) ^ ry);
if (ry == 0) {
if (rx == 1) {
x = 64 - 1 - x;
y = 64 - 1 - y;
}
uint t = x; x = y; y = t;
}
}
return index;
}
float2 GetStratifiedNoise(float2 vpos) {
uint2 screenPos = uint2(vpos.xy) % 64; //64x64 tiled pixel coords
uint hIndex = HilbertIndex(screenPos.x, screenPos.y); //Hilbert index (spatial)
uint totalIndex = hIndex + (uint(FRAME_COUNT % 64) * 288); //temporal offset: 288 (same as Intel XeGTAO implementation)
return frac(float(totalIndex) * R2_CONSTANT);
}
@@ -0,0 +1,96 @@
/*
========================================================================
Copyright (c) Afzaal. All rights reserved.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
========================================================================
GitHub : https://github.com/umar-afzaal/LumeniteFX
Discord : https://discord.gg/deXJrW2dx6
Filename : lumenite_Projections.fxh
Version : 2026.04.11
Author : Afzaal (Kaidō)
Description: Camera projection functions for Lumenite shaders.
License : AGNYA License (https://github.com/nvb-uy/AGNYA-License)
========================================================================
*/
#pragma once
#include "ReShade.fxh"
/*--------------.
| :: HELPERS :: |
'--------------*/
//VERTEX SHADER
struct VSOUT
{
float4 vpos : SV_Position;
float2 uv : TEXCOORD0;
float tan_half_fov_x : TEXCOORD1;
float tan_half_fov_y : TEXCOORD2;
float inv_tan_half_fov_x : TEXCOORD3;
float inv_tan_half_fov_y : TEXCOORD4;
float near_ratio : TEXCOORD5;
float diff_ratio : TEXCOORD6;
};
#define TAN_HALF_FOV_Y tan(radians(FOV * 0.5))
#define ASPECT_RATIO_X_OVER_Y ((float)BUFFER_WIDTH / (float)BUFFER_HEIGHT)
#define TAN_HALF_FOV_X TAN_HALF_FOV_Y * ASPECT_RATIO_X_OVER_Y
#define INV_TAN_HALF_FOV_X rcp(TAN_HALF_FOV_X)
#define INV_TAN_HALF_FOV_Y rcp(TAN_HALF_FOV_Y)
VSOUT VS(uint id : SV_VertexID)
{
VSOUT o;
o.uv.x = (id == 2) ? 2.0 : 0.0;
o.uv.y = (id == 1) ? 2.0 : 0.0;
o.vpos = float4(mad(o.uv.x, 2.0, -1.0), mad(o.uv.y, -2.0, 1.0), 0.0, 1.0);
o.tan_half_fov_x = TAN_HALF_FOV_X;
o.tan_half_fov_y = TAN_HALF_FOV_Y;
o.inv_tan_half_fov_x = INV_TAN_HALF_FOV_X;
o.inv_tan_half_fov_y = INV_TAN_HALF_FOV_Y;
o.near_ratio = NEAR_PLANE / RESHADE_DEPTH_LINEARIZATION_FAR_PLANE;
o.diff_ratio = 1.0 - o.near_ratio; //lerp(a,b,t) = (a+t * (b-a)), precompute (b-a) or (1.0-near_ratio) here
return o;
}
//PROJECTION FUNCTIONS
//normalized frustum
//left-handed viewspace
//normals point outwards
//Z+ goes into the screen
float3 UVToViewSpace(float2 uv, float linear_depth_vs, VSOUT ps_input)
{
float projection_scale = mad(linear_depth_vs, ps_input.diff_ratio, ps_input.near_ratio); //faster lerp: a+t * diff
float3 view_pos;
float ndc_x = mad(uv.x, 2.0, -1.0);
float ndc_y = mad(uv.y, -2.0, 1.0);
view_pos.x = ndc_x * ps_input.tan_half_fov_x * projection_scale;
view_pos.y = ndc_y * ps_input.tan_half_fov_y * projection_scale;
view_pos.z = linear_depth_vs;
return view_pos;
}
float2 ViewSpaceToUV(float3 view_pos, VSOUT ps_input)
{
float inv_projection_scale = rcp(mad(view_pos.z, ps_input.diff_ratio, ps_input.near_ratio));
float2 ndc;
ndc.x = view_pos.x * ps_input.inv_tan_half_fov_x * inv_projection_scale;
ndc.y = view_pos.y * ps_input.inv_tan_half_fov_y * inv_projection_scale;
float2 uv;
uv.x = mad(ndc.x, 0.5, 0.5);
uv.y = mad(ndc.y, -0.5, 0.5);
return uv;
}