Skip to content

Commit 30bbbe4

Browse files
jhi721Filoppi
authored andcommitted
Sunset Overdrive: Add the Luma mod
1 parent 45dca94 commit 30bbbe4

26 files changed

Lines changed: 4083 additions & 0 deletions

‎Luma.sln‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Snowbreak Containment Zone"
143143
EndProject
144144
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NieR Replicant", "Source\Games\NieR Replicant\NieR Replicant.vcxproj", "{D7DCEC3D-3209-4370-8CED-8CF6A4D34D78}"
145145
EndProject
146+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Sunset Overdrive", "Source\Games\Sunset Overdrive\Sunset Overdrive.vcxproj", "{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}"
147+
EndProject
146148
Global
147149
GlobalSection(SolutionConfigurationPlatforms) = preSolution
148150
Development-Debug|Win32 = Development-Debug|Win32
@@ -1003,6 +1005,18 @@ Global
10031005
{D7DCEC3D-3209-4370-8CED-8CF6A4D34D78}.Test-Release|Win32.ActiveCfg = Test-Release|x64
10041006
{D7DCEC3D-3209-4370-8CED-8CF6A4D34D78}.Test-Release|x64.ActiveCfg = Test-Release|x64
10051007
{D7DCEC3D-3209-4370-8CED-8CF6A4D34D78}.Test-Release|x64.Build.0 = Test-Release|x64
1008+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Development-Debug|Win32.ActiveCfg = Development-Debug|x64
1009+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Development-Debug|x64.ActiveCfg = Development-Debug|x64
1010+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Development-Debug|x64.Build.0 = Development-Debug|x64
1011+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Development-Release|Win32.ActiveCfg = Development-Release|x64
1012+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Development-Release|x64.ActiveCfg = Development-Release|x64
1013+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Development-Release|x64.Build.0 = Development-Release|x64
1014+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Publishing-Release|Win32.ActiveCfg = Publishing-Release|x64
1015+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Publishing-Release|x64.ActiveCfg = Publishing-Release|x64
1016+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Publishing-Release|x64.Build.0 = Publishing-Release|x64
1017+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Test-Release|Win32.ActiveCfg = Test-Release|x64
1018+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Test-Release|x64.ActiveCfg = Test-Release|x64
1019+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30}.Test-Release|x64.Build.0 = Test-Release|x64
10061020
EndGlobalSection
10071021
GlobalSection(SolutionProperties) = preSolution
10081022
HideSolutionNode = FALSE
@@ -1075,6 +1089,7 @@ Global
10751089
{A6A0EC5F-AFD4-4699-B489-A621FB82C431} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
10761090
{A8505E49-DA6F-4C05-ADF0-3480DC27B3FC} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
10771091
{D7DCEC3D-3209-4370-8CED-8CF6A4D34D78} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
1092+
{3A6C5692-A5DE-46AE-8E7A-1838642DDC30} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
10781093
EndGlobalSection
10791094
GlobalSection(ExtensibilityGlobals) = postSolution
10801095
SolutionGuid = {8B799422-BA66-3174-B21F-B9FA07C4B2E3}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// PS_BinkNV12: Y' plane (R8, t5) and interleaved CbCr (R8G8, t6), opaque. See "Includes/Video.hlsl".
2+
3+
#include "Includes/Video.hlsl"
4+
5+
SamplerState g_BinkMap0Sampler : register(s5);
6+
SamplerState g_BinkMap1Sampler : register(s6);
7+
Texture2D<float4> g_BinkMap0 : register(t5);
8+
Texture2D<float4> g_BinkMap1 : register(t6);
9+
10+
void main(float4 v0 : SV_POSITION0, float2 v1 : TEXCOORD0, out float4 o0 : SV_TARGET0)
11+
{
12+
const float2 cbcr = g_BinkMap1.Sample(g_BinkMap1Sampler, v1).xy;
13+
const float y = g_BinkMap0.Sample(g_BinkMap0Sampler, v1).x;
14+
o0 = float4(VideoOutput(YUVtoRGB(y, cbcr.y, cbcr.x, 3)), 1.0);
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// PS_BinkYCbCrA: four R8 planes (Y' t5, Cr t6, Cb t7, alpha t8), all scaled by g_BinkConst. See "Includes/Video.hlsl".
2+
3+
#include "Includes/Video.hlsl"
4+
5+
cbuffer PSBinkAlphaCB : register(b2)
6+
{
7+
float4 g_BinkConst;
8+
}
9+
10+
SamplerState g_BinkMap0Sampler : register(s5);
11+
SamplerState g_BinkMap1Sampler : register(s6);
12+
SamplerState g_BinkMap2Sampler : register(s7);
13+
SamplerState g_BinkMap3Sampler : register(s8);
14+
Texture2D<float4> g_BinkMap0 : register(t5);
15+
Texture2D<float4> g_BinkMap1 : register(t6);
16+
Texture2D<float4> g_BinkMap2 : register(t7);
17+
Texture2D<float4> g_BinkMap3 : register(t8);
18+
19+
void main(float4 v0 : SV_POSITION0, float2 v1 : TEXCOORD0, out float4 o0 : SV_TARGET0)
20+
{
21+
const float cb = g_BinkMap2.Sample(g_BinkMap2Sampler, v1).x;
22+
const float cr = g_BinkMap1.Sample(g_BinkMap1Sampler, v1).x;
23+
const float y = g_BinkMap0.Sample(g_BinkMap0Sampler, v1).x;
24+
const float alpha = g_BinkMap3.Sample(g_BinkMap3Sampler, v1).x;
25+
o0 = float4(YUVtoRGB(y, cr, cb, 3), alpha) * g_BinkConst;
26+
o0.rgb = VideoOutput(o0.rgb);
27+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// PS_BinkYCbCr: three A8 planes (Y' t5, Cr t6, Cb t7), opaque. See "Includes/Video.hlsl".
2+
3+
#include "Includes/Video.hlsl"
4+
5+
SamplerState g_BinkMap0Sampler : register(s5);
6+
SamplerState g_BinkMap1Sampler : register(s6);
7+
SamplerState g_BinkMap2Sampler : register(s7);
8+
Texture2D<float4> g_BinkMap0 : register(t5);
9+
Texture2D<float4> g_BinkMap1 : register(t6);
10+
Texture2D<float4> g_BinkMap2 : register(t7);
11+
12+
void main(float4 v0 : SV_POSITION0, float2 v1 : TEXCOORD0, out float4 o0 : SV_TARGET0)
13+
{
14+
const float y = g_BinkMap0.Sample(g_BinkMap0Sampler, v1).w;
15+
const float cr = g_BinkMap1.Sample(g_BinkMap1Sampler, v1).w;
16+
const float cb = g_BinkMap2.Sample(g_BinkMap2Sampler, v1).w;
17+
o0 = float4(VideoOutput(YUVtoRGB(y, cr, cb, 3)), 1.0);
18+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "Includes/Common.hlsl"
2+
3+
// PS_CopyBuffer is a plain copy, which the engine also uses outside the frame end. Its draw of the scene onto the swapchain (scaled to
4+
// the window, before the UI) is flagged through LumaData.CustomData1, and is where the scene gets its UI paper white pre-scale and its
5+
// one dither.
6+
7+
SamplerState g_CopyBufferMapSampler_s : register(s6);
8+
Texture2D<float4> g_CopyBufferMap : register(t6);
9+
10+
void main(float4 v0 : SV_POSITION0, float2 v1 : TEXCOORD0, out float4 o0 : SV_TARGET0)
11+
{
12+
o0 = g_CopyBufferMap.Sample(g_CopyBufferMapSampler_s, v1);
13+
14+
if (LumaData.CustomData1 == 0)
15+
{
16+
return;
17+
}
18+
o0.rgb = PreScaleForUIPaperWhite(o0.rgb);
19+
if (LumaSettings.GameSettings.Dithering <= 0.5)
20+
{
21+
return;
22+
}
23+
// One step of the output quantizer: an 8 bit code in SDR, 10 bit BT.2020 PQ in HDR and SDR on HDR.
24+
// The value is the game's sRGB-encoded color, which the display composition decodes with gamma 2.2 and scales by the UI paper white
25+
// (after the pre-scale above).
26+
[branch] if (LumaSettings.DisplayMode != 0)
27+
{
28+
// The PQ code steps sit where the composition maps 1 to that paper white
29+
const float pqScale = max(UI_DRAW_TYPE >= 2 ? UIPaperWhiteNits : GamePaperWhiteNits, 1.0) / HDR10_MaxWhiteNits;
30+
float3 pq = Linear_to_PQ(BT709_To_BT2020(gamma_to_linear(o0.rgb, GCT_MIRROR) * pqScale), GCT_MIRROR);
31+
ApplyDithering(pq, v1, true, 1.0, 10u, LumaSettings.FrameIndex, true);
32+
o0.rgb = linear_to_gamma(BT2020_To_BT709(PQ_to_Linear(pq, GCT_MIRROR)) / pqScale, GCT_MIRROR);
33+
}
34+
else
35+
{
36+
ApplyDithering(o0.rgb, v1, true, 1.0, 8u, LumaSettings.FrameIndex, true);
37+
}
38+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Always include this instead of the global "Common.hlsl" if you made any changes to the game shaders/cbuffers
2+
3+
// Define the game custom cbuffer structs
4+
#include "GameCBuffers.hlsl"
5+
// Global common
6+
#include "../../Includes/Common.hlsl"
7+
// Game specific settings
8+
#include "Settings.hlsl"
9+
10+
// The display composition's transfer functions
11+
#include "../../Includes/ColorGradingLUT.hlsl"
12+
13+
// The scene and the full-screen videos reach the swapchain scaled by GamePaperWhite / UIPaperWhite (UI_DRAW_TYPE 2), so the Scaleform
14+
// UI blended on top of them lands at UIPaperWhite once the display composition rescales the whole buffer by it. The scale goes through
15+
// the composition's own decode (gamma 2.2 within 0-1, sRGB beyond), so the scene keeps its level exactly.
16+
float3 PreScaleForUIPaperWhite(float3 encoded)
17+
{
18+
#if UI_DRAW_TYPE >= 2
19+
[branch] if (GamePaperWhiteNits != UIPaperWhiteNits)
20+
{
21+
const float3 composed = ColorGradingLUTTransferFunctionOutCorrected(encoded, VANILLA_ENCODING_TYPE, GAMMA_CORRECTION_TYPE);
22+
encoded = ColorGradingLUTTransferFunctionInCorrected(composed * (GamePaperWhiteNits / max(UIPaperWhiteNits, 1.0)), GAMMA_CORRECTION_TYPE, VANILLA_ENCODING_TYPE);
23+
}
24+
#endif
25+
return encoded;
26+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#ifndef SRC_DEPTH_EDGES_HLSL
2+
#define SRC_DEPTH_EDGES_HLSL
3+
4+
// SMAA predication signal from depth: deviation from the local tangent plane, a slope-adjusted second difference with a
5+
// depth-proportional tolerance (the math of XeGTAO_CalculateEdges; SVGF, Schied et al. 2017; Emil Persson 2009).
6+
// A plain depth difference cannot work: a plane's own per-pixel change grows with distance.
7+
//
8+
// Each one-sided delta is compared against the slope implied by the opposite neighbour and the smaller is kept: on a plane
9+
// (any orientation) the two agree and cancel to ~0, at a depth discontinuity neither does. Taking the min also means a
10+
// garbage opposite tap (off the texture) can only shrink the result, never invent an edge.
11+
//
12+
// Returns edge-ness in [0,1] against the LEFT and TOP neighbours only: SMAA compares centre-vs-left and centre-vs-top, so a
13+
// one-sided measure jumps 0 -> 1 exactly across a silhouette (a symmetric one would difference to 0 there), and
14+
// SMAA_PREDICATION_THRESHOLD is 0.5. "tolerance" is the plane deviation counted as a full edge, in the depth's units
15+
// (normally a fraction of the centre's view depth).
16+
float PlaneDeviationEdgeness(float center, float left, float right, float top, float bottom, float tolerance)
17+
{
18+
float4 edgesLRTB = float4(left, right, top, bottom) - center;
19+
const float slopeLR = (edgesLRTB.y - edgesLRTB.x) * 0.5;
20+
const float slopeTB = (edgesLRTB.w - edgesLRTB.z) * 0.5;
21+
edgesLRTB = min(abs(edgesLRTB), abs(edgesLRTB + float4(slopeLR, -slopeLR, slopeTB, -slopeTB)));
22+
return saturate(max(edgesLRTB.x, edgesLRTB.z) / tolerance);
23+
}
24+
25+
// PlaneDeviationEdgeness for a compute-shader texel whose five depth values are already loaded. Out-of-bounds Loads return
26+
// 0 (D3D11-defined), so the left/top neighbour is replaced by the centre on the first column/row: a flat border instead of a
27+
// false edge rim. Right/bottom stay as loaded (a garbage opposite tap can only shrink the result); a caller that wants them
28+
// mirrored too passes the centre itself.
29+
float PlaneDeviationEdgenessMirrored(uint2 pixel, float center, float left, float right, float top, float bottom, float tolerance)
30+
{
31+
return PlaneDeviationEdgeness(center, (pixel.x > 0) ? left : center, right, (pixel.y > 0) ? top : center, bottom, tolerance);
32+
}
33+
34+
// The depth-proportional tolerance of the DepthExtract passes: "relativeTolerance" (fraction of the centre's depth) with a
35+
// floor on both factors so sky / zero depth keeps a nonzero tolerance.
36+
float DepthExtractTolerance(float center, float relativeTolerance)
37+
{
38+
return max(center, 1e-3) * max(relativeTolerance, 1e-4);
39+
}
40+
41+
// A value proportional to linear view depth from a device depth d with a standard (1 - d ~ near / z) or reversed
42+
// (d ~ near / z) projection: the relative tolerance cancels the unknown near plane, so no camera constants are needed.
43+
// The sky (0 after the flip) clamps at 2^-24.
44+
float RelativeViewDepth(float deviceDepth, bool reversedZ)
45+
{
46+
return rcp(max(reversedZ ? deviceDepth : 1.0 - deviceDepth, 1.0 / 16777216.0));
47+
}
48+
49+
// One predication texel straight from a device depth texture. "relativeTolerance" is the plane deviation counted as a
50+
// full edge, as a fraction of view depth (TW2's validated 0.02).
51+
float DepthPredicationEdgeness(Texture2D<float> depth, uint2 pixel, bool reversedZ, float relativeTolerance = 0.02)
52+
{
53+
const int3 p = int3(pixel, 0);
54+
const float centerZ = RelativeViewDepth(depth.Load(p), reversedZ);
55+
const float leftZ = RelativeViewDepth(depth.Load(p - int3(1, 0, 0)), reversedZ);
56+
const float rightZ = RelativeViewDepth(depth.Load(p + int3(1, 0, 0)), reversedZ);
57+
const float topZ = RelativeViewDepth(depth.Load(p - int3(0, 1, 0)), reversedZ);
58+
const float bottomZ = RelativeViewDepth(depth.Load(p + int3(0, 1, 0)), reversedZ);
59+
return PlaneDeviationEdgenessMirrored(pixel, centerZ, leftZ, rightZ, topZ, bottomZ, centerZ * relativeTolerance);
60+
}
61+
62+
#endif // SRC_DEPTH_EDGES_HLSL
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef LUMA_GAME_CB_STRUCTS
2+
#define LUMA_GAME_CB_STRUCTS
3+
4+
#ifdef __cplusplus
5+
// This include is needed to allow reading shader types from c++.
6+
#include "../../../Source/Core/includes/shader_types.h"
7+
#endif
8+
9+
// Mirrors c++ name spaces.
10+
namespace CB
11+
{
12+
struct LumaGameSettings
13+
{
14+
float Dithering; // 0/1
15+
float ColorGradingIntensity; // 1 = vanilla, 0 = no 3D LUT
16+
float BloomIntensity; // 1 = vanilla
17+
float FilmGrainIntensity; // 1 = vanilla
18+
float Exposure; // Scene multiplier, 1 = vanilla
19+
float Contrast; // HDR, 1 = vanilla
20+
float Saturation; // HDR, 1 = vanilla
21+
float VideoAutoHDREnable; // 0/1
22+
float VideoAutoHDRBoost; // 0 = SDR peak, 1 = full AutoHDR peak
23+
};
24+
25+
struct LumaGameData
26+
{
27+
float Dummy;
28+
};
29+
} // namespace CB
30+
31+
#endif // LUMA_GAME_CB_STRUCTS

0 commit comments

Comments
 (0)