Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions .github/workflows/build_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ jobs:
# We only build publishing and test for now, development builds can be built locally by devs (with the exclusion of the Generic and Graphics Analyzer mod, which can also be used to quickly download a dev/debug environment)
if: matrix.config == 'Publishing-Release' || matrix.config == 'Test-Release' || matrix.config == 'Development-Release'
run: |

# Scan vcxproj files to find projects that use NGX (DLSS)
$ngxProjects = @()
$vcxprojFiles = Get-ChildItem -Path "Source/Games" -Filter "*.vcxproj" -Recurse
foreach ($vcxproj in $vcxprojFiles) {
$content = Get-Content $vcxproj.FullName -Raw
if ($content -match 'nvsdk_ngx') {
$projectName = [System.IO.Path]::GetFileNameWithoutExtension($vcxproj.Name)
$ngxProjects += $projectName
Write-Host "Found NGX project: $projectName"
}
}
Write-Host "NGX projects: $($ngxProjects -join ', ')"

# Find the addon file in the build folder (adjust path accordingly)
$addonDir = "Binaries\${{ matrix.platform }}-${{ matrix.config }}"
$addonFiles = Get-ChildItem -Path $addonDir -Filter "Luma-*.addon"
Expand Down Expand Up @@ -199,18 +211,8 @@ jobs:
Write-Host "ReShade file not found at $rsSrc — skipping"
}

# Add DLSS for the projects that need it (ideally we'd have a binary dependencies folder with all the dependencies needed by each project, but git would duplicate the files and that's a shame, so we do it manually)
if (
$projectName -like '*Prey*' `
-or $projectName -like '*Mafia III*' `
-or $projectName -like '*Dishonored 2*' `
-or $projectName -like '*Final Fantasy VII Remake*' `
-or $projectName -like '*Final Fantasy XV*' `
-or $projectName -like '*Trine 5*' `
-or $projectName -like '*Just Cause 3*' `
-or $projectName -like '*Unreal Engine' `
-or $projectName -like '*Granblue Fantasy Relink*' `
-or $projectName -like '*Persona 5*') {
# Add DLSS for the projects that need it based on vcxproj analysis
if ($ngxProjects -contains $projectName) {
# Source path for NGX DLSS DLL

if (("${{ matrix.config }}" -eq "Development-Debug") -or ("${{ matrix.config }}" -eq "Development-Release")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Tonemap pass (hudless output) for Output_HDR shader split.
// TONEMAP_PASS and the permutation hash define (_922A71D1 etc.)
// are set via ShaderDefinition::defines_data at compile time.
#include "Output_HDR_0x########.ps_5_0.hlsl"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// UI Composition pass for Output_HDR shader split.
// UI_COMPOSITION_PASS and the permutation hash define (_922A71D1 etc.)
// are set via ShaderDefinition::defines_data at compile time.
#include "Output_HDR_0x########.ps_5_0.hlsl"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Tonemap pass (hudless output) for Output_SDR shader split.
// TONEMAP_PASS and the permutation hash define (_506D5998 etc.)
// are set via ShaderDefinition::defines_data at compile time.
#include "Output_SDR_0x########.ps_5_0.hlsl"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// UI Composition pass for Output_SDR shader split.
// UI_COMPOSITION_PASS and the permutation hash define (_506D5998 etc.)
// are set via ShaderDefinition::defines_data at compile time.
#include "Output_SDR_0x########.ps_5_0.hlsl"
25 changes: 20 additions & 5 deletions Shaders/Final Fantasy VII Remake/Output_HDR_0x########.ps_5_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ void main(
float2 pixelPos = r1.xy;
float2 uvCoord = r1.zw;

#if !UI_COMPOSITION_PASS
r2.xyz = colorTex.SampleLevel(colorSampler, uvCoord, 0).xyz;
if (LumaData.GameData.DrewUpscaling && LumaSettings.GameSettings.can_sharpen != 0.f) {
r2.xyz = RCAS(int2(v0.xy), 0, 0x7FFFFFFF, LumaSettings.GameSettings.custom_sharpness_strength, colorTex, dummyFloat2Texture, 1.f, true , float4(r2.xyz, 1.0f)).rgb;
Expand Down Expand Up @@ -651,9 +652,9 @@ void main(

#if _3A4D858E // Chapter 2 specific effect?
r0.w = SampleNoiseTexture(gradedAces, v0);
r3.xyz = gradedAces * r0.www;
r2.w = dot(r3.xyz, float3(0.262699991,0.677999973,0.0593000017));
// r2.xyz = r2.xyz * r0.www + -r2.www;
r2.xyz = r2.xyz * r0.www; // pre-apply noise to tonemapped result
r2.w = dot(r2.xyz, float3(0.262699991,0.677999973,0.0593000017));
r0.w = 1;
#elif _6846FF90
// HDR overlay + monochrome mask branch
r2.xyz = ApplyOverlay(r2.xyz, overlayTex, overlaySampler, pixelPos.xy);
Expand Down Expand Up @@ -687,6 +688,20 @@ void main(

#endif //3 lut branch

#if TONEMAP_PASS
// --- Pass 1 output (hudless tonemapped PQ) ---
o0.xyz = Linear_to_PQ(r2.xyz / HDR10_MaxWhiteNits);
o0.w = 1;
return;
#endif // TONEMAP_PASS
#else // UI_COMPOSITION_PASS
// --- Pass 2 input: read hudless tonemapped PQ from colorTex (rebound by C++ to intermediate RT) ---
float3 pqScene = colorTex.SampleLevel(colorSampler, uvCoord, 0).xyz;
r2.xyz = PQ_to_Linear(pqScene) * HDR10_MaxWhiteNits;
r2.w = dot(r2.xyz, float3(0.262699991,0.677999973,0.0593000017));
r0.w = 1;
#endif // !UI_COMPOSITION_PASS

r1.xyzw = uiTex.SampleLevel(uiSampler, pixelPos.xy, 0).xyzw;
// r2.w = dot(r3.xyz, float3(0.262699991,0.677999973,0.0593000017));
r2.xyz = r2.xyz * r0.www + -r2.www;
Expand Down Expand Up @@ -749,8 +764,8 @@ void main(
r0.x = r0.x * 0.000977517106 + r0.w;
color.z = saturate(r0.y ? r0.x : r0.w);
}
#if EARLY_DISPLAY_ENCODING //scRGB OUTPUT

#if DEVELOPMENT && EARLY_DISPLAY_ENCODING //scRGB OUTPUT
color = PQ_to_Linear(color);
color *= (HDR10_MaxWhiteNits / sRGB_WhiteLevelNits);
color = BT2020_To_BT709(color);
Expand Down
22 changes: 18 additions & 4 deletions Shaders/Final Fantasy VII Remake/Output_SDR_0x########.ps_5_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ void main(
float2 pixelPos = r1.xy;
float2 uvCoord = r1.zw;

#if !UI_COMPOSITION_PASS
r2.xyz = colorTex.SampleLevel(colorSampler, uvCoord, 0).xyz;
if (LumaData.GameData.DrewUpscaling && LumaSettings.GameSettings.can_sharpen != 0.f) {
r2.xyz = RCAS(int2(v0.xy), 0, 0x7FFFFFFF, LumaSettings.GameSettings.custom_sharpness_strength, colorTex, dummyFloat2Texture, 1.f, true , float4(r2.xyz, 1.0f)).rgb;
Expand Down Expand Up @@ -449,11 +450,24 @@ void main(

#if _506D5998
float noise = SampleNoiseTexture(r3.xyz, v0);
r0.w = noise;
r3.xyz = r2.xyz * r0.www;
// r0.w = 1;
r2.xyz = r2.xyz * noise; // pre-apply noise to tonemapped result
r3.xyz = r2.xyz;
r0.w = 1;
#endif

#if TONEMAP_PASS
// --- Pass 1 output (hudless tonemapped SDR, linear [0,1]) ---
o0.xyz = r2.xyz;
o0.w = 1;
return;
#endif // TONEMAP_PASS
#else // UI_COMPOSITION_PASS
// --- Pass 2 input: read hudless tonemapped from colorTex (rebound by C++ to intermediate RT) ---
r2.xyz = colorTex.SampleLevel(colorSampler, uvCoord, 0).xyz;
r3.xyz = r2.xyz;
r0.w = 1;
#endif // !UI_COMPOSITION_PASS

r1.xyzw = uiTex.SampleLevel(uiSampler, pixelPos, 0).xyzw;
r2.w = dot(r3.xyz, float3(0.212599993,0.715200007,0.0722000003));
r2.xyz = r2.xyz * r0.www + -r2.www;
Expand Down Expand Up @@ -490,7 +504,7 @@ void main(
color.xyz = saturate(r0.yzw ? r2.xyz : r1.xyz);
}

#if EARLY_DISPLAY_ENCODING
#if DEVELOPMENT && EARLY_DISPLAY_ENCODING
color.xyz = gamma_to_linear(color.xyz, GCT_MIRROR, 2.2f);
#endif

Expand Down
53 changes: 15 additions & 38 deletions Shaders/Final Fantasy VII Remake/includes/Tonemap.hlsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include "renodx/tonemap.hlsl"
#include "renodx/effects.hlsl"
#include "renodx/hermite_spline.hlsl"
#include "renodx/neutwo.hlsl"
#include "../../Includes/Color.hlsl"
#include "../../Includes/Oklab.hlsl"
#include "../../Includes/DarktableUCS.hlsl"
#include "../../Includes/ACES.hlsl"
#include "../../Includes/Reinhard.hlsl"

float UpgradeToneMapRatio(float ap1_color_hdr, float ap1_color_sdr, float ap1_post_process_color) {
Expand Down Expand Up @@ -107,7 +106,7 @@ float3 UpgradeToneMapPerChannel(float3 color_hdr, float3 color_sdr, float3 post_
float3 color_scaled = max(0, ap1_post_process * ratio);
color_scaled = AP1_To_BT709(color_scaled);
float peak_correction = saturate(1.f - GetLuminance(ap1_post_process, CS_AP1));
color_scaled = RestoreHueAndChrominance(color_scaled, post_process_color, peak_correction, 1.f);
color_scaled = RestoreHueAndChrominance(color_scaled, post_process_color, peak_correction, 0.75f);
return lerp(color_hdr, color_scaled, post_process_strength);
}

Expand Down Expand Up @@ -192,6 +191,7 @@ float3 ApplyExposureContrastFlareHighlightsShadowsByLuminance(float3 untonemappe
float3 color = untonemapped;

color *= config.exposure;
y *= config.exposure;

// contrast & flare
const float y_normalized = y / mid_gray;
Expand Down Expand Up @@ -277,10 +277,6 @@ float3 ApplyHermiteSplineByMaxChannel(float3 input, float diffuse_nits, float pe
float3 extractColorGradeAndApplyTonemap(float3 ungraded_bt709, float3 lutOutputColor_bt2020, float midGray, float2 position) {
// normalize LUT output paper white and convert to BT.709
// ungraded_bt709 = ungraded_bt709 * 1.5f;
float tonemap_type = 1.f;
#if TEST || DEVELOPMENT
tonemap_type = LumaSettings.GameSettings.tonemap_type;
#endif
if (LumaSettings.GameSettings.tonemap_type == 0.f) {
return lutOutputColor_bt2020;
}
Expand All @@ -289,7 +285,6 @@ float3 extractColorGradeAndApplyTonemap(float3 ungraded_bt709, float3 lutOutputC
float ACES_MIN;
float aces_min;
float aces_max;
float3 graded_bt709;
float3 tonemapped_bt709;
float3 pq_color;

Expand All @@ -304,34 +299,14 @@ float3 extractColorGradeAndApplyTonemap(float3 ungraded_bt709, float3 lutOutputC
cg_config.hue_correction_strength = LumaSettings.GameSettings.hue_correction_strength;
cg_config.blowout = -1.f * (LumaSettings.GameSettings.highlight_saturation - 1.f);

if (LumaSettings.GameSettings.tonemap_type == 1.f) {
float3 reference_tonemap_bt709 = Reinhard::ReinhardScalable(ungraded_bt709, 1000.f / 250.f, 0.f, 0.18f, 0.18f);
float3 graded_untonemapped_bt709 = UpgradeToneMapPerChannel(ungraded_bt709, reference_tonemap_bt709, graded_aces_bt709, 1.f);
float y = GetLuminance(graded_untonemapped_bt709, CS_BT709);
float3 graded_bt709 = ApplyExposureContrastFlareHighlightsShadowsByLuminance(graded_untonemapped_bt709, y, cg_config);
graded_bt709 = ApplySaturationBlowoutHueCorrectionHighlightSaturation(graded_bt709, graded_aces_bt709, y, cg_config);
tonemapped_bt709 = graded_bt709;
if (LumaSettings.GameSettings.custom_lut_strength != 1.f) {
tonemapped_bt709 = lerp(ungraded_bt709, tonemapped_bt709, LumaSettings.GameSettings.custom_lut_strength);
}
}
else {
ungraded_bt709 = ungraded_bt709 * 1.5f;
ACES_MIN = 0.0001f;
aces_min = ACES_MIN / LumaSettings.GamePaperWhiteNits;
aces_max = (LumaSettings.PeakWhiteNits / LumaSettings.GamePaperWhiteNits);
graded_bt709 = ApplyExposureContrastFlareHighlightsShadowsByLuminance(ungraded_bt709, GetLuminance(ungraded_bt709, CS_BT709), cg_config, 0.18f);
graded_bt709 = max(0, graded_bt709);
float y_in = GetLuminance(graded_bt709, CS_BT709);
float y_out = ACES::ODTToneMap(y_in, aces_min * 48.f, aces_max * 48.f) / 48.f;

// float3 channel_tonemappe_ap1 = ACES::ODTToneMap(graded_bt709, aces_min * 48.f, aces_max * 48.f) / 48.f;
float3 luminance_tonemapped_ap1 = RestoreLuminance(graded_bt709, y_out);
luminance_tonemapped_ap1 = BT709_To_AP1(RestoreHueAndChrominance(AP1_To_BT709(luminance_tonemapped_ap1), (graded_bt709), 1.f, 0.f));
float lum = GetLuminance(luminance_tonemapped_ap1, CS_AP1);
tonemapped_bt709 = AP1_To_BT709(lerp(luminance_tonemapped_ap1, BT709_To_AP1(graded_bt709), saturate(lum / 1.f)));
tonemapped_bt709 = ApplySaturationBlowoutHueCorrectionHighlightSaturation(tonemapped_bt709, graded_bt709, GetLuminance(graded_bt709, CS_BT709), cg_config);

float3 reference_tonemap_bt709 = Reinhard::ReinhardScalable(ungraded_bt709, 1000.f / 250.f, 0.f, 0.18f, 0.18f);
float3 graded_untonemapped_bt709 = UpgradeToneMapPerChannel(ungraded_bt709, reference_tonemap_bt709, graded_aces_bt709, 1.f);
float y = GetLuminance(graded_untonemapped_bt709, CS_BT709);
float3 graded_bt709 = ApplyExposureContrastFlareHighlightsShadowsByLuminance(graded_untonemapped_bt709, y, cg_config);
graded_bt709 = ApplySaturationBlowoutHueCorrectionHighlightSaturation(graded_bt709, graded_aces_bt709, y, cg_config);
tonemapped_bt709 = graded_bt709;
if (LumaSettings.GameSettings.custom_lut_strength != 1.f) {
tonemapped_bt709 = lerp(ungraded_bt709, tonemapped_bt709, LumaSettings.GameSettings.custom_lut_strength);
}

if (LumaSettings.GameSettings.custom_film_grain_strength != 0) {
Expand All @@ -343,11 +318,13 @@ float3 extractColorGradeAndApplyTonemap(float3 ungraded_bt709, float3 lutOutputC
1.f);
}

// tonemapped_bt709 = convertColorSpace(tonemapped_bt709);
float peak_ratio = LumaSettings.PeakWhiteNits / LumaSettings.GamePaperWhiteNits;

tonemapped_bt709 = renodx::tonemap::neutwo::MaxChannel(tonemapped_bt709, peak_ratio);

float3 tonemapped_bt2020 = BT709_To_BT2020(tonemapped_bt709);

tonemapped_bt2020 = ApplyHermiteSplineByMaxChannel(tonemapped_bt2020, LumaSettings.GamePaperWhiteNits, LumaSettings.PeakWhiteNits);
// tonemapped_bt2020 = ApplyHermiteSplineByMaxChannel(tonemapped_bt2020, LumaSettings.GamePaperWhiteNits, LumaSettings.PeakWhiteNits);

return tonemapped_bt2020 * (LumaSettings.GamePaperWhiteNits);
// return lutOutputColor_bt2020;
Expand Down
Loading
Loading