Skip to content

Commit

Permalink
Merge branch 'clshortfuse:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
marat569 authored Oct 15, 2024
2 parents 8ae3f90 + 98cdec2 commit aaef09e
Show file tree
Hide file tree
Showing 14 changed files with 548 additions and 193 deletions.
36 changes: 8 additions & 28 deletions src/games/gow2018/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@
#include <deps/imgui/imgui.h>
#include <include/reshade.hpp>

#include <embed/0x279D11F6.h> // Game BT.2020 Conversion + PQ Encoding w/ DLSS/FSR
#include <embed/0x279D11F6.h> // Tonemap + PQ w/ DLSS/FSR
#include <embed/0x6FE3FEEA.h> // LUT w/ TAA
#include <embed/0x7818463E.h> // LUT w/ DLSS/FSR
#include <embed/0xB59D6558.h> // Gamma Slider + Paper White + Tonemap
#include <embed/0xF4EFA04D.h> // Game BT.2020 Conversion + PQ Encoding w/ TAA
#include <embed/0xF4EFA04D.h> // Tonemap + PQ w/ TAA


#include <include/reshade.hpp>
#include "../../mods/shader.hpp"
#include "../../mods/swapchain.hpp"
// #include "../../mods/swapchain.hpp"
#include "../../utils/settings.hpp"
#include "./shared.h"

namespace {

renodx::mods::shader::CustomShaders custom_shaders = {

CustomShaderEntry(0x7818463E), // LUT w/ DLSS/FSR
CustomShaderEntry(0x6FE3FEEA), // LUT w/ TAA
CustomShaderEntry(0x279D11F6), // Game BT.2020 Conversion + PQ Encoding w/ DLSS/FSR
CustomShaderEntry(0xF4EFA04D), // Game BT.2020 Conversion + PQ Encoding w/ TAA
CustomShaderEntry(0xB59D6558), // Gamma Slider + Paper White + Tonemap
CustomShaderEntry(0x7818463E), // LUT w/ DLSS/FSR
CustomShaderEntry(0xF4EFA04D), // Tonemap + PQ w/ TAA
CustomShaderEntry(0x279D11F6), // Tonemap + PQ w/ DLSS/FSR
};

ShaderInjectData shader_injection;
Expand Down Expand Up @@ -73,18 +71,6 @@ renodx::utils::settings::Settings settings = {
.max = 500.f,
.is_enabled = []() { return shader_injection.toneMapType != 0; },
},
new renodx::utils::settings::Setting{
.key = "toneMapUINits",
.binding = &shader_injection.toneMapUINits,
.default_value = 203.f,
.can_reset = false,
.label = "UI Brightness",
.section = "Tone Mapping",
.tooltip = "Sets the brightness of UI and HUD elements in nits",
.min = 48.f,
.max = 500.f,
.is_enabled = []() { return shader_injection.toneMapType != 0; },
},
new renodx::utils::settings::Setting{
.key = "toneMapHueCorrection",
.binding = &shader_injection.toneMapHueCorrection,
Expand Down Expand Up @@ -170,7 +156,7 @@ renodx::utils::settings::Settings settings = {
new renodx::utils::settings::Setting{
.key = "colorGradeLUTScaling",
.binding = &shader_injection.colorGradeLUTScaling,
.default_value = 100.f,
.default_value = 75.f,
.label = "LUT Scaling",
.section = "Color Grading",
.tooltip = "Scales the color grade LUT to full range when size is clamped.",
Expand All @@ -184,7 +170,6 @@ void OnPresetOff() {
renodx::utils::settings::UpdateSetting("toneMapType", 0);
renodx::utils::settings::UpdateSetting("toneMapPeakNits", 1000.f);
renodx::utils::settings::UpdateSetting("toneMapGameNits", 203.f);
renodx::utils::settings::UpdateSetting("toneMapUINits", 203.f);
renodx::utils::settings::UpdateSetting("colorGradeExposure", 1.f);
renodx::utils::settings::UpdateSetting("toneMapHueCorrection", 0.f);
renodx::utils::settings::UpdateSetting("colorGradeHighlights", 50.f);
Expand All @@ -210,10 +195,6 @@ BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
renodx::mods::shader::force_pipeline_cloning = true;
renodx::mods::shader::expected_constant_buffer_index = 11;

renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({.old_format = reshade::api::format::r10g10b10a2_unorm,
.new_format = reshade::api::format::r16g16b16a16_float,
.index = 0});

if (!reshade::register_addon(h_module)) return FALSE;

break;
Expand All @@ -223,7 +204,6 @@ BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
}

renodx::utils::settings::Use(fdw_reason, &settings, &OnPresetOff);
renodx::mods::swapchain::Use(fdw_reason); // scRGB swapchain
renodx::mods::shader::Use(fdw_reason, custom_shaders, &shader_injection);

return TRUE;
Expand Down
35 changes: 0 additions & 35 deletions src/games/gow2018/final_gamma_0xB59D6558.ps_5_0.hlsl

This file was deleted.

29 changes: 9 additions & 20 deletions src/games/gow2018/game_pq_0x279D11F6.ps_5_0.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "./shared.h"
#include "./tonemapper.hlsl"

// ---- Created with 3Dmigoto v1.3.16 on Fri Aug 30 19:53:29 2024
Texture2D<float4> t16 : register(t16);
Expand All @@ -14,21 +15,6 @@ cbuffer cb0 : register(b0) {
// 3Dmigoto declarations
#define cmp -

float ColorGradeSmoothClamp(float x) {
const float u = 0.525;

float q = (2.0 - u - 1.0 / u + x * (2.0 + 2.0 / u - x / u)) / 4.0;

return (abs(1.0 - x) < u) ? q : saturate(x);
}
float3 ColorGradeSmoothClamp(float3 color) {
float3 outputColor;
outputColor.r = ColorGradeSmoothClamp(color.r);
outputColor.g = ColorGradeSmoothClamp(color.g);
outputColor.b = ColorGradeSmoothClamp(color.b);
return outputColor;
}

void main(
float4 v0: SV_POSITION0,
float2 v1: TEXCOORD0,
Expand Down Expand Up @@ -82,12 +68,16 @@ void main(
injectedData.toneMapHueCorrection, // hue correction
renodx::tonemap::uncharted2::BT709(r0.rgb));

r0.xyz = renodx::color::correct::GammaSafe(r0.xyz); // linearize with 2.2 instead of srgb
r0.xyz = renodx::color::correct::GammaSafe(r0.xyz); // linearize with 2.2 instead of srgb

if (injectedData.toneMapType == 2) { // DICE tonemap
r0.rgb = applyDICE(r0.rgb);
}

r0.xyz = renodx::color::bt2020::from::BT709(r0.xyz); // Convert to BT.2020
r0.xyz = max(0, r0.xyz); // Clamp needed to prevent artifacts
r0.xyz *= injectedData.toneMapGameNits / injectedData.toneMapUINits;
o0.xyz = renodx::color::pq::Encode(r0.xyz, 306.f); // Set paper white to match UI
} else { // Original BT.2020 + PQ code
o0.xyz = renodx::color::pq::Encode(r0.xyz, injectedData.toneMapGameNits);
} else { // Original BT.2020 + PQ code
r0.xyz = max(float3(0, 0, 0), r0.xyz);
// BT.2020
r0.w = dot(float3(0.627403915, 0.329283029, 0.0433130674), r0.xyz);
Expand All @@ -114,7 +104,6 @@ void main(
r2.xyz = r0.xyz * r2.xyz + float3(10668.4043, 10668.4043, 10668.4043);
r0.xyz = r0.xyz * r2.xyz + float3(1, 1, 1);
o0.xyz = r1.xyz / r0.xyz;
o0.xyz = saturate(o0.xyz); // previously clamped by unorm
}
o0.w = 1;
return;
Expand Down
13 changes: 9 additions & 4 deletions src/games/gow2018/game_pq_taa_0xF4EFA04D.ps_5_0.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "./shared.h"
#include "./tonemapper.hlsl"

// ---- Created with 3Dmigoto v1.3.16 on Sun Oct 13 15:49:48 2024
Texture2D<float4> t16 : register(t16);
Expand Down Expand Up @@ -106,12 +107,16 @@ void main(
injectedData.toneMapHueCorrection, // hue correction
renodx::tonemap::uncharted2::BT709(r0.rgb));

r0.xyz = renodx::color::correct::GammaSafe(r0.xyz); // linearize with 2.2 instead of srgb
r0.xyz = renodx::color::correct::GammaSafe(r0.xyz); // linearize with 2.2 instead of srgb

if (injectedData.toneMapType == 2) { // DICE tonemap
r0.rgb = applyDICE(r0.rgb);
}

r0.xyz = renodx::color::bt2020::from::BT709(r0.xyz); // Convert to BT.2020
r0.xyz = max(0, r0.xyz); // Clamp needed to prevent artifacts
r0.xyz *= injectedData.toneMapGameNits / injectedData.toneMapUINits;
o0.xyz = renodx::color::pq::Encode(r0.xyz, 306.f); // Set paper white to match UI
} else { // Original BT.2020 + PQ code
o0.xyz = renodx::color::pq::Encode(r0.xyz, injectedData.toneMapGameNits);
} else { // Original BT.2020 + PQ code
r0.xyz = max(float3(0, 0, 0), r0.xyz);
r0.w = dot(float3(0.627403915, 0.329283029, 0.0433130674), r0.xyz);
r1.x = dot(float3(0.069097288, 0.919540405, 0.0113623161), r0.xyz);
Expand Down
107 changes: 49 additions & 58 deletions src/games/gow2018/lut_0x7818463E.ps_5_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -155,71 +155,62 @@ void main(
r0.z = cmp(0 != cb0[0].w);
r1.xyz = r0.zzz ? float3(0, 0, 0) : r1.xyz;

float3 lutInputColor = r1.xyz;
if (injectedData.toneMapType == 0) {
// convert arri logc800
r2.xyz = cmp(float3(0.0105910003, 0.0105910003, 0.0105910003) < r1.xyz);
r3.xyzw = r1.xxyy * float4(5.55555582, 5.3676548, 5.55555582, 5.3676548) + float4(0.0522719994, 0.0928089991, 0.0522719994, 0.0928089991);
r1.xy = log2(r3.xz);
r1.xy = r1.xy * float2(0.0744116008, 0.0744116008) + float2(0.385536999, 0.385536999);
r3.xy = r2.xy ? r1.xy : r3.yw;
r1.xy = r1.zz * float2(5.55555582, 5.3676548) + float2(0.0522719994, 0.0928089991);
r0.z = log2(r1.x);
r0.z = r0.z * 0.0744116008 + 0.385536999;
r3.z = r2.z ? r0.z : r1.y;
// Sample 64x64x64 LUT
r1.xyz = r3.xyz * float3(0.984375, 0.984375, 0.984375) + float3(0.0078125, 0.0078125, 0.0078125);
r1.xyz = t0.SampleLevel(s1_s, r1.xyz, 0).xyz;
// back to linear
r2.xyz = cmp(float3(0.149658203, 0.149658203, 0.149658203) < r1.xyz);
r3.xyzw = float4(-0.385536999, -0.0928089991, -0.385536999, -0.0928089991) + r1.xxyy;
r3.xyzw = float4(13.4387865, 0.186301097, 13.4387865, 0.186301097) * r3.xyzw;
r1.xy = exp2(r3.xz);
r1.xy = float2(-0.0522719994, -0.0522719994) + r1.xy;
r1.xy = float2(0.179999992, 0.179999992) * r1.xy;
r3.xy = r2.xy ? r1.xy : r3.yw;
r1.xy = float2(-0.385536999, -0.0928089991) + r1.zz;
r1.xy = float2(13.4387865, 0.186301097) * r1.xy;
r0.z = exp2(r1.x);
r0.z = -0.0522719994 + r0.z;
r0.z = 0.179999992 * r0.z;
r3.z = r2.z ? r0.z : r1.y;

r3.xyz = lerp(lutInputColor, r3.xyz, injectedData.colorGradeLUTStrength); // LUT Strength
r1.xyz = max(0, r3.xyz);
} else {
lutInputColor = renodx::color::grade::UserColorGrading(
lutInputColor,
if (injectedData.toneMapType != 0) {
r1.xyz = renodx::color::grade::UserColorGrading(
r1.xyz,
injectedData.colorGradeExposure, // exposure
injectedData.colorGradeHighlights, // highlights
injectedData.colorGradeShadows, // shadows
injectedData.colorGradeContrast, // contrast
1.f, // saturation, applied later
0.f); // dechroma, applied later

renodx::lut::Config lut_config = renodx::lut::config::Create(
s1_s,
1.f, // do LUT strength after
0.f, // do LUT scaling after
renodx::lut::config::type::ARRI_C800,
renodx::lut::config::type::ARRI_C800,
64);
float3 lutOutputColor = renodx::lut::Sample(t0, lut_config, lutInputColor);

// Cleans up raised black floor
if (injectedData.colorGradeLUTScaling && injectedData.colorGradeLUTStrength) {
float3 minBlack = renodx::color::arri::logc::c800::Decode(t0.SampleLevel(s1_s, renodx::color::arri::logc::c800::Encode((0.f).xxx), 0.0f).rgb);
const float lutMinY = renodx::color::y::from::BT709(max(0, minBlack));
if (lutMinY > 0) {
float3 correctedBlack = renodx::lut::CorrectBlack(lutInputColor, lutOutputColor, lutMinY, 0.f);
lutOutputColor = lerp(lutOutputColor, correctedBlack, injectedData.colorGradeLUTScaling);
}
}

r1.xyz = lerp(lutInputColor, lutOutputColor, injectedData.colorGradeLUTStrength);
0.f, // dechroma, applied later
0.f); // hue correction, applied later
}
float3 lutInputColor = r1.xyz;

r1.xyz = max(0, r1.xyz); // DLSS/FSR clamps to BT.709
// convert arri logc800
r2.xyz = cmp(float3(0.0105910003, 0.0105910003, 0.0105910003) < r1.xyz);
r3.xyzw = r1.xxyy * float4(5.55555582, 5.3676548, 5.55555582, 5.3676548) + float4(0.0522719994, 0.0928089991, 0.0522719994, 0.0928089991);
r1.xy = log2(r3.xz);
r1.xy = r1.xy * float2(0.0744116008, 0.0744116008) + float2(0.385536999, 0.385536999);
r3.xy = r2.xy ? r1.xy : r3.yw;
r1.xy = r1.zz * float2(5.55555582, 5.3676548) + float2(0.0522719994, 0.0928089991);
r0.z = log2(r1.x);
r0.z = r0.z * 0.0744116008 + 0.385536999;
r3.z = r2.z ? r0.z : r1.y;
// Sample 64x64x64 LUT
r1.xyz = r3.xyz * float3(0.984375, 0.984375, 0.984375) + float3(0.0078125, 0.0078125, 0.0078125);
r1.xyz = t0.SampleLevel(s1_s, r1.xyz, 0).xyz;
// back to linear
r2.xyz = cmp(float3(0.149658203, 0.149658203, 0.149658203) < r1.xyz);
r3.xyzw = float4(-0.385536999, -0.0928089991, -0.385536999, -0.0928089991) + r1.xxyy;
r3.xyzw = float4(13.4387865, 0.186301097, 13.4387865, 0.186301097) * r3.xyzw;
r1.xy = exp2(r3.xz);
r1.xy = float2(-0.0522719994, -0.0522719994) + r1.xy;
r1.xy = float2(0.179999992, 0.179999992) * r1.xy;
r3.xy = r2.xy ? r1.xy : r3.yw;
r1.xy = float2(-0.385536999, -0.0928089991) + r1.zz;
r1.xy = float2(13.4387865, 0.186301097) * r1.xy;
r0.z = exp2(r1.x);
r0.z = -0.0522719994 + r0.z;
r0.z = 0.179999992 * r0.z;
r3.z = r2.z ? r0.z : r1.y;

r1.xyz = max(0, r3.xyz);

float3 lutOutputColor = r1.xyz;

if (injectedData.toneMapType != 0 && injectedData.colorGradeLUTScaling > 0 && injectedData.colorGradeLUTStrength > 0) {
float3 minBlack = renodx::color::arri::logc::c800::Decode(t0.SampleLevel(s1_s, renodx::color::arri::logc::c800::Encode((0.f).xxx), 0.0f).rgb);

float lutMinY = renodx::color::y::from::BT709(max(0, minBlack));
if (lutMinY > 0) {
float3 correctedBlack = renodx::lut::CorrectBlack(lutInputColor, lutOutputColor, lutMinY, 0.f);
lutOutputColor = lerp(lutOutputColor, correctedBlack, injectedData.colorGradeLUTScaling);
}
}
r1.xyz = lerp(lutInputColor.rgb, lutOutputColor, injectedData.colorGradeLUTStrength); // LUT Strength
r1.xyz = max(0, r1.xyz); // DLSS/FSR clamps to BT.709 anyway

r0.z = max(r1.y, r1.z);
r0.z = max(r1.x, r0.z);
Expand Down
1 change: 0 additions & 1 deletion src/games/gow2018/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct ShaderInjectData {
float toneMapType;
float toneMapPeakNits;
float toneMapGameNits;
float toneMapUINits;
float toneMapHueCorrection;
float colorGradeExposure;
float colorGradeHighlights;
Expand Down
13 changes: 13 additions & 0 deletions src/games/gow2018/tonemapper.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "./DICE.hlsl"
#include "./shared.h"

float3 applyDICE(float3 untonemapped) {
DICESettings config = DefaultDICESettings();
config.Type = 3u;
config.ShoulderStart = 0.5f;

const float paperWhite = injectedData.toneMapGameNits / renodx::color::srgb::REFERENCE_WHITE;
const float peakWhite = injectedData.toneMapPeakNits / renodx::color::srgb::REFERENCE_WHITE;

return DICETonemap(untonemapped * paperWhite, peakWhite, config) / paperWhite;
}
5 changes: 5 additions & 0 deletions src/games/thetownoflight/X_Final_0xFFFFFFFD.vs_5_0.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
void main(uint id: SV_VERTEXID, out float4 pos: SV_POSITION, out float2 uv: TEXCOORD0) {
uv.x = (id == 1) ? 2.0 : 0.0;
uv.y = (id == 2) ? 2.0 : 0.0;
pos = float4(uv * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}
17 changes: 17 additions & 0 deletions src/games/thetownoflight/X_Final_0xFFFFFFFE.ps_5_0.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "./shared.h"

SamplerState sourceSampler_s : register(s0);
Texture2D<float4> sourceTexture : register(t0);

void main(
float4 vpos: SV_Position,
float2 texcoord: TEXCOORD,
out float4 output: SV_Target0) {
float4 color = sourceTexture.Sample(sourceSampler_s, texcoord.xy);

// Linearize with 2.2 Gamma and scale paper white
float3 linearizedColor = renodx::color::gamma::DecodeSafe(color.rgb, 2.2);
linearizedColor *= injectedData.toneMapUINits / renodx::color::srgb::REFERENCE_WHITE;

output.rgba = float4(linearizedColor, color.a);
}
Loading

0 comments on commit aaef09e

Please sign in to comment.