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
15 changes: 15 additions & 0 deletions Luma.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Heavy Rain", "Source\Games\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mafia II Definitive Edition", "Source\Games\Mafia II Definitive Edition\Mafia II Definitive Edition.vcxproj", "{5605BCCC-4F89-4AF3-984F-991105C32602}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Mafia Definitive Edition", "Source\Games\Mafia Definitive Edition\Mafia Definitive Edition.vcxproj", "{D414969A-65FC-484F-84B9-FC73CC74876B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "INSIDE", "Source\Games\INSIDE\INSIDE.vcxproj", "{12A5D475-264C-35B7-7C7F-EA9C310C41BB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dying Light 2", "Source\Games\Dying Light 2\Dying Light 2.vcxproj", "{F4605338-43D9-473F-AD3E-A95380C8AD56}"
Expand Down Expand Up @@ -271,6 +273,18 @@ Global
{890ED9C4-668B-65B3-D953-37D85DF155AC}.Test-Release|Win32.ActiveCfg = Test-Release|x64
{890ED9C4-668B-65B3-D953-37D85DF155AC}.Test-Release|x64.ActiveCfg = Test-Release|x64
{890ED9C4-668B-65B3-D953-37D85DF155AC}.Test-Release|x64.Build.0 = Test-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Development-Debug|Win32.ActiveCfg = Development-Debug|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Development-Debug|x64.ActiveCfg = Development-Debug|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Development-Debug|x64.Build.0 = Development-Debug|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Development-Release|Win32.ActiveCfg = Development-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Development-Release|x64.ActiveCfg = Development-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Development-Release|x64.Build.0 = Development-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Publishing-Release|Win32.ActiveCfg = Publishing-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Publishing-Release|x64.ActiveCfg = Publishing-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Publishing-Release|x64.Build.0 = Publishing-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Test-Release|Win32.ActiveCfg = Test-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Test-Release|x64.ActiveCfg = Test-Release|x64
{D414969A-65FC-484F-84B9-FC73CC74876B}.Test-Release|x64.Build.0 = Test-Release|x64
{163BA26C-1EA0-EB05-F492-C8AF046A1F46}.Development-Debug|Win32.ActiveCfg = Development-Debug|x64
{163BA26C-1EA0-EB05-F492-C8AF046A1F46}.Development-Debug|x64.ActiveCfg = Development-Debug|x64
{163BA26C-1EA0-EB05-F492-C8AF046A1F46}.Development-Debug|x64.Build.0 = Development-Debug|x64
Expand Down Expand Up @@ -1002,6 +1016,7 @@ Global
{8EF11F8D-FD8B-45E1-888E-CEEA5FFB316E} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{D58EB0ED-8EFA-4DB0-B2AD-B2D2A098873E} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{5605BCCC-4F89-4AF3-984F-991105C32602} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{D414969A-65FC-484F-84B9-FC73CC74876B} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{12A5D475-264C-35B7-7C7F-EA9C310C41BB} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{F4605338-43D9-473F-AD3E-A95380C8AD56} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{9DD802E8-588E-4955-9FF8-21A0F5B06F48} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
Expand Down
24 changes: 22 additions & 2 deletions Shaders/Global/Luma_DisplayComposition.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,25 @@ float3 ComposeUI(float3 pos, float3 linearSceneColor, float gamePaperWhite, floa
#endif
}

// What the SDR display composition does with the game's final SDR image ("SDR_OUTPUT_TRANSFORM").
//
// 0 (legacy): decode sRGB to linear. Only correct when the container encodes on write, i.e. "_SRGB"
// views and scRGB, which is what Luma's own scRGB swapchain upgrade relies on. On a plain UNORM
// container the OS applies the sRGB transfer function itself, so stopping at linear displays the
// picture one decode too dark: over contrasted, over saturated, "richer" than vanilla.
// 1: pass the value through untouched. Correct for any plain UNORM container (the game wrote sRGB
// encoded values, so identity), and equally for an "_SRGB" container (the game wrote linear values,
// the view encodes on write, so identity again). In other words this is the safe mode whenever the
// game was not forced through a swapchain format upgrade.
float3 SDRGameOutputToContainer(float3 srgbEncodedColor)
{
#if SDR_OUTPUT_TRANSFORM == 1
return srgbEncodedColor;
#else
return gamma_sRGB_to_linear(srgbEncodedColor, GCT_NONE);
#endif
}

// Custom Luma shader to apply the display (or output) transfer function from a linear input (or apply custom gamma correction)
float4 main(float4 pos : SV_Position) : SV_Target0
{
Expand Down Expand Up @@ -389,7 +408,7 @@ float4 main(float4 pos : SV_Position) : SV_Target0
if (LumaSettings.DisplayMode <= 0)
{
// The SDR display will (usually) linearize with gamma 2.2, hence applying the usual gamma mismatch, so we don't correct gamma here
color.rgb = gamma_sRGB_to_linear(color.rgb, GCT_NONE);
color.rgb = SDRGameOutputToContainer(color.rgb);
}
// HDR (we assume this is the default case for Luma users/devs, this isn't an officially supported case anyway) (we ignore "GAMMA_CORRECTION_RANGE_TYPE" and "VANILLA_ENCODING_TYPE" here, it doesn't matter)
else
Expand Down Expand Up @@ -489,7 +508,8 @@ float4 main(float4 pos : SV_Position) : SV_Target0
// we linearize with sRGB because scRGB HDR buffers (Luma) in SDR are re-encoded with sRGB and then (likely) linearized by the display with 2.2, which would then apply the gamma correction.
// For any user that wanted to play in sRGB, they'd need to have an sRGB monitor.
// We could theoretically add a mode that fakes sRGB output on scRGB->2.2 but it wouldn't really be useful as the game was likely designed for 2.2 displays (unconsciously).
color.rgb = ColorGradingLUTTransferFunctionOut(color.rgb, LUT_EXTRAPOLATION_TRANSFER_FUNCTION_SRGB, false);
// Note: "SDRGameOutputToContainer" leaves the value alone when the swapchain is a plain UNORM buffer (see "SDR_OUTPUT_TRANSFORM").
color.rgb = SDRGameOutputToContainer(color.rgb);
#endif // POST_PROCESS_SPACE_TYPE == 1

#if 0 // For linux support (somehow scRGB is not interpreted as linear when in SDR) //TODOFT4: expose?
Expand Down
8 changes: 8 additions & 0 deletions Shaders/Mafia Definitive Edition/Includes/Common.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Always include this instead of the global "Common.hlsl" if you made any changes to the game shaders/cbuffers

// Define the game custom cbuffer structs
#include "GameCBuffers.hlsl"
// Global common
#include "../../Includes/Common.hlsl"
// Game specific settings
#include "Settings.hlsl"
26 changes: 26 additions & 0 deletions Shaders/Mafia Definitive Edition/Includes/GameCBuffers.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef LUMA_GAME_CB_STRUCTS
#define LUMA_GAME_CB_STRUCTS

#ifdef __cplusplus
// This include is needed to allow reading shader types from c++.
#include "../../../Source/Core/includes/shader_types.h"
#endif

// Mirrors c++ name spaces.
namespace CB
{
// Define the game specific cbuffer settings here. They don't need 4 bytes alignment.
struct LumaGameSettings
{
float GameSetting01;
uint GameSetting02;
};

// Define the game specific cbuffer (instance/pass) data here
struct LumaGameData
{
float Dummy; // hlsl doesn't support empty structs
};
}

#endif // LUMA_GAME_CB_STRUCTS
13 changes: 13 additions & 0 deletions Shaders/Mafia Definitive Edition/Includes/Settings.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef SRC_GAME_SETTINGS_HLSL
#define SRC_GAME_SETTINGS_HLSL

// Include this after the global "Settings.hlsl" file

/////////////////////////////////////////
// Template LUMA advanced settings
// (note that the defaults might be mirrored in c++, the shader values will be overridden anyway)
/////////////////////////////////////////

#define EXAMPLE_TEMPLATE_DEFINE 1

#endif // SRC_GAME_SETTINGS_HLSL
29 changes: 29 additions & 0 deletions Shaders/Mafia Definitive Edition/Luma_MafiaDE_Sharpen.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RCAS sharpening for Mafia: Definitive Edition.
//
// Drawn immediately after our DLSS / DLAA output has been written into the game's AA render
// target. DLAA is well documented to come out slightly *softer* than a good TAA on static
// images (it trades sharpness for the absence of ghosting), and this game's own sharpening
// pass (0x747C6210) is tuned for the blurrier TAA it normally runs after. This adds a
// properly tuned RCAS pass on top, which is exactly what Luma's Mafia III mod does - its
// README lists "adds AMD RCAS sharpening" as part of why the image improves.
//
// Runs in the HDR buffer (R16G16B16A16_FLOAT, pre tonemap). paperWhite = 1.0 and
// dynamicSharpening = false; RCAS_LIMIT inside the include bounds the lobe so HDR highlights
// do not over-sharpen.

#include "../Includes/RCAS.hlsl"

cbuffer SharpenCB : register(b0)
{
float4 SharpenParams; // (width, height, sharpness[0..1], unused)
}

Texture2D<float4> tex0 : register(t0); // SR output (HDR)
Texture2D<float2> dummyMV : register(t1); // unused, dynamicSharpening = false

float4 sharpen_ps(float4 pos : SV_Position) : SV_Target
{
int2 p = int2(pos.xy);
int2 maxPixel = int2((int)SharpenParams.x - 1, (int)SharpenParams.y - 1);
return RCAS(p, int2(0, 0), maxPixel, SharpenParams.z, tex0, dummyMV, 1.0, false, (float4)0, false);
}
2 changes: 2 additions & 0 deletions Source/Core/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ namespace
// Sadly most games encoded with sRGB (or used linear sRGB buffers, similar thing), so that's the default here
{"VANILLA_ENCODING_TYPE", '0', true, DEVELOPMENT ? false : true, "0 - sRGB\n1 - Gamma 2.2"},
{"GAMMA_CORRECTION_TYPE", '1', true, false, "(HDR only) Emulates a specific SDR transfer function\nThis is best left to \"1\" (Gamma 2.2) unless you have crushed blacks or overly saturated colors\n0 - sRGB\n1 - Gamma 2.2\n2 - sRGB (color hues) with gamma 2.2 luminance (corrected by channel)\n3 - sRGB (color hues) with gamma 2.2 luminance (corrected by luminance)\n4 - Gamma 2.2 (corrected by luminance) with per channel correction chrominance"},
{"SDR_OUTPUT_TRANSFORM", '0', true, false, "What the SDR display composition does with the game's final SDR image.\nHistorically it always decoded sRGB to linear, which is only correct when the swapchain container encodes on write (\"_SRGB\" views, scRGB) - for a plain UNORM container (R8G8B8A8_UNORM, R10G10B10A2_UNORM, ...) the OS applies the sRGB transfer function itself, so the image arrives one decode too dark (over contrasted, over saturated).\n0 - Decode sRGB to linear (legacy, correct for scRGB and for SDR-in-HDR on a scRGB container)\n1 - Pass through untouched (correct for any plain UNORM container, and for \"_SRGB\" containers whose values are already linear)\nOnly affects SDR output (Display Mode 0).", 1},
{"GAMUT_MAPPING_TYPE", '0', true, DEVELOPMENT ? false : true, "The type of gamut mapping that is needed by the game.\nIf rendering and post processing don't generate any colors beyond the target gamut, there's no need to do gamut mapping.\n0 - None\n1 - Auto (SDR/HDR)\n2 - SDR (BT.709)\n3 - HDR (BT.2020)"},
{"UI_DRAW_TYPE", '0', true, DEVELOPMENT ? false : true, "Describes how the UI draws in\n0 - Raw (original linear to linear or gamma to gamma draws) (no custom UI paper white control)\n1 - Direct Custom (gamma to linear adapted blends)\n2 - Direct (inverse scene brightness draws)\n3 - Separate (renders the UI on a separate texture, allows tonemapping of UI background)", 3},
#if DEVELOPMENT
Expand All @@ -756,6 +757,7 @@ namespace
constexpr uint32_t EARLY_DISPLAY_ENCODING_HASH = char_ptr_crc32("EARLY_DISPLAY_ENCODING");
constexpr uint32_t VANILLA_ENCODING_TYPE_HASH = char_ptr_crc32("VANILLA_ENCODING_TYPE");
constexpr uint32_t GAMMA_CORRECTION_TYPE_HASH = char_ptr_crc32("GAMMA_CORRECTION_TYPE");
constexpr uint32_t SDR_OUTPUT_TRANSFORM_HASH = char_ptr_crc32("SDR_OUTPUT_TRANSFORM");
constexpr uint32_t GAMUT_MAPPING_TYPE_HASH = char_ptr_crc32("GAMUT_MAPPING_TYPE");
constexpr uint32_t UI_DRAW_TYPE_HASH = char_ptr_crc32("UI_DRAW_TYPE");
constexpr uint32_t TEST_SDR_HDR_SPLIT_VIEW_MODE_NATIVE_IMPL_HASH = char_ptr_crc32("TEST_SDR_HDR_SPLIT_VIEW_MODE_NATIVE_IMPL");
Expand Down
Loading