diff --git a/src/games/rdr1/PSApplyHDR10PQGammaCorrect.0x56F79BAD.ps_6_0.hlsl b/src/games/rdr1/PSApplyHDR10PQGammaCorrect.0x56F79BAD.ps_6_0.hlsl new file mode 100644 index 00000000..c493e575 --- /dev/null +++ b/src/games/rdr1/PSApplyHDR10PQGammaCorrect.0x56F79BAD.ps_6_0.hlsl @@ -0,0 +1,37 @@ +#include "./shared.h" + +Texture2D g_textures2D[] : register(t0, space2); + +cbuffer Globals : register(b0) { + float HDRPeakNits : packoffset(c000.z); + float SDRPaperWhiteNits : packoffset(c000.w); + uint FullResMapSampler : packoffset(c025.y); + uint FullResMapSamplerSS : packoffset(c025.z); +}; + +SamplerState g_samplers[] : register(s0, space1); + +float4 main( + noperspective float4 SV_Position: SV_Position, + linear float4 TEXCOORD: TEXCOORD) + : SV_Target { + float gameNits; + if (HDRPeakNits == 196.0) { // round up to BT.2408 Reference White (203 nits) + gameNits = 203.0; + } else { + gameNits = HDRPeakNits; + } + + float3 gammaColor = g_textures2D[FullResMapSampler].Sample(g_samplers[FullResMapSamplerSS], TEXCOORD.xy).rgb; + + // UI brightness scale is a ratio of 500 + float UIBrightnessScale = SDRPaperWhiteNits / 500.0; + gammaColor *= UIBrightnessScale; + + // linearize + convert to BT.2020 PQ + float3 linearColor = renodx::color::gamma::DecodeSafe(gammaColor, 2.8); + float3 bt2020Color = renodx::color::bt2020::from::BT709(linearColor); + float3 pqEncodedColor = renodx::color::pq::Encode(bt2020Color, gameNits); + + return float4(pqEncodedColor, 1.0); +} \ No newline at end of file diff --git a/src/games/rdr1/PSMiniAdapt.0xE033AAAD.ps_6_0.hlsl b/src/games/rdr1/PSMiniAdapt.0xE033AAAD.ps_6_0.hlsl new file mode 100644 index 00000000..dabb5ace --- /dev/null +++ b/src/games/rdr1/PSMiniAdapt.0xE033AAAD.ps_6_0.hlsl @@ -0,0 +1,205 @@ +#include "./shared.h" +#include "./tonemaphelper.hlsl" + +Texture2D g_textures2D[] : register(t0, space2); + +cbuffer Globals : register(b0, space0) { + float gMotionBlurScalar; + float UsingHDR10; + float HDRPeakNits; + float SDRPaperWhiteNits; + float physicsmaterial; + float4 TexelSize; + float4 BlueShiftColor; + float4 BlueShiftParams; + float ElapsedTime; + float Frames; + float Lambda; + float4 BrightPassValues; + float White; + float IntensityBloom; + float4 brightPassParams; + float3 LUMINANCE; + float deSat; + float4 ConstAdd; + float4 ColorCorrect; + float Contrast; + float4 DofParams; + float3 NearFarClipPlaneQ; + float2 NearFarClipPaneScaleAndBias; + float4x4 gViewProjInverse; + float Gamma; + float LowerLimitAdaption; + float HigherLimitAdaption; + float distortionFreq; + float distortionScale; + float distortionRoll; + float4 SSAOProjectionParams; + float4 SSAOTweakParams; + float4 gScreenSize; + float ParticleHeatShimmerSeed; + int FullResMapSampler; + int FullResMapSamplerSS; + int RenderMapSampler; + int RenderMapSamplerSS; + int RenderMapPointSampler; + int RenderMapPointSamplerSS; + int RenderMapBilinearSampler; + int RenderMapBilinearSamplerSS; + int RenderMapAnisoSampler; + int RenderMapAnisoSamplerSS; + int DepthMapSampler; + int DepthMapSamplerSS; + int ToneMapSampler; + int ToneMapSamplerSS; + int AdaptedLuminanceMapSampler; + int AdaptedLuminanceMapSamplerSS; + int LightGlowTexSampler; + int LightGlowTexSamplerSS; + float AdaptedLuminance; + float2 horzTapOffs[7]; + float2 vertTapOffs[7]; + float4 TexelWeight[16]; + float3 Scale; + float DustOverlayStrength; + float SoftDofFalloffPower; + float SoftDofStrength; + float DofBackendPull; + float TotalTime; + float4 HeatShimmerParams; + float4 ColorScalar; + int DOFHelperSampler; + int DOFHelperSamplerSS; + int ParticleCompositeSampler; + int ParticleCompositeSamplerSS; + int GlowSampler; + int GlowSamplerSS; + int GlowSampler2; + int GlowSampler2SS; + float DisableVignette; + float AdditiveReducer; + float AdditiveReducer2; + float4 GlowColor2; + float4 GlowColor; + float FlareSize; + int DeathSampler; + int DeathSamplerSS; + float DeathMag; + float DeathDrip; + float DeathBlood; + float4 DeathColor; + float3 DeathEffect; + float4 InjuryDirections; + float4 InjuryTimes; + float4x4 WorldViewProjInverse; + float AverageHeight; + float4 LightStreakDirection; + float4 streakWeights; + float4 StreakParams; + float4 DuelColorCorrect; + float4 DuelConstAdd; + float DuelEnemyU; + float DuelEnemyWidth; + float DueldeSat; + float DuelContrast; +}; + +SamplerState g_samplers[] : register(s0, space1); + +float4 main( + noperspective float4 SV_Position: SV_Position, + linear float4 TEXCOORD0: TEXCOORD, + linear float4 TEXCOORD1: TEXCOORD1, + linear float4 TEXCOORD2: TEXCOORD2) + : SV_Target { + float3 _12 = g_textures2D[RenderMapBilinearSampler].Sample(g_samplers[RenderMapBilinearSamplerSS], TEXCOORD0.xy).rgb; + float _13 = _12.r; + float _14 = _12.g; + float _15 = _12.b; + + float clampedAdaptedLuminance = TEXCOORD1.x; + + // float _17 = BrightPassValues.z; + // float _18 = clampedAdaptedLuminance + 0.001; + // float _19 = _17 / _18; + + float scale = BrightPassValues.z / (clampedAdaptedLuminance + 0.001); + + float _20 = scale * _13; + float _21 = scale * _14; + float _22 = scale * _15; + + float3 color_scaled = float3(_20, _21, _22); + + float _24 = White; + float _25 = _20 / _24; + float _26 = _21 / _24; + float _27 = _22 / _24; + float _28 = _25 + 1.00000; + float _29 = _26 + 1.00000; + float _30 = _27 + 1.00000; + float _31 = _28 * _20; + float _32 = _29 * _21; + float _33 = _30 * _22; + float _34 = _20 + 1.00000; + float _35 = _21 + 1.00000; + float _36 = _22 + 1.00000; + float _37 = _31 / _34; + float _38 = _32 / _35; + float _39 = _33 / _36; + +#if 1 // blended reinhard with untonemapped + float3 vanillaColor = float3(_37, _38, _39); + + float midGrayScale = RDR1ReinhardMidgrayScale(White); + float3 untonemapped_scaled = color_scaled * midGrayScale; + + float3 blendedColor = lerp(vanillaColor, lerp(vanillaColor, untonemapped_scaled, 0.5), saturate(vanillaColor)); + + _37 = blendedColor.r; + _38 = blendedColor.g; + _39 = blendedColor.b; +#endif + + // Apply Color Correction + float _41 = ConstAdd.x; + float _42 = ConstAdd.y; + float _43 = ConstAdd.z; + float _44 = _41 + _37; + float _45 = _42 + _38; + float _46 = _43 + _39; + float _48 = ColorCorrect.x; + float _49 = ColorCorrect.y; + float _50 = ColorCorrect.z; + float _51 = _48 * 2.00000; + float _52 = _51 * _44; + float _53 = _49 * 2.00000; + float _54 = _53 * _45; + float _55 = _50 * 2.00000; + float _56 = _55 * _46; + + float3 colorCorrected = float3(_52, _54, _56); + + // Apply Desaturation - lerp to luminance + float blackAndWhite = dot(colorCorrected, LUMINANCE.xyz); + float3 desaturatedColorHDR = lerp(blackAndWhite, colorCorrected, deSat); + + // Apply Contrast + // done in SDR, causes broken colors on highlights otherwise + float3 desaturatedColorSDR = saturate(renodx::tonemap::dice::BT709(desaturatedColorHDR, 1.0)); + float3 contrastedColor = desaturatedColorSDR - (((desaturatedColorSDR * Contrast) * (desaturatedColorSDR - 1.0)) * (desaturatedColorSDR - 0.5)); + + float3 outputColor = contrastedColor; + +#if 1 // use upgradetonemap() to apply SDR contrast to HDR + float3 upgradedColor = renodx::tonemap::UpgradeToneMap(desaturatedColorHDR, desaturatedColorSDR, outputColor, 1.f); + + // blend vanillaColor back in to fix differences in contrast + float3 vanillaDesaturatedColor = saturate(desaturatedColorHDR); + float3 vanillaContrastedColor = vanillaDesaturatedColor - (((vanillaDesaturatedColor * Contrast) * (vanillaDesaturatedColor - 1.0)) * (vanillaDesaturatedColor - 0.5)); + outputColor = lerp(saturate(vanillaContrastedColor), upgradedColor, saturate(vanillaContrastedColor)); +#endif + + float3 gammaEncodedColor = renodx::color::gamma::Encode(max(0, outputColor), 2.2f); + return float4(gammaEncodedColor, IntensityBloom); +} diff --git a/src/games/rdr1/PSRDR2PostfxOptics_0xEEEE53C5.ps_6_0.hlsl b/src/games/rdr1/PSRDR2PostfxOptics_0xEEEE53C5.ps_6_0.hlsl new file mode 100644 index 00000000..4881c146 --- /dev/null +++ b/src/games/rdr1/PSRDR2PostfxOptics_0xEEEE53C5.ps_6_0.hlsl @@ -0,0 +1,319 @@ +#include "./shared.h" +#include "./tonemaphelper.hlsl" + +Texture2D g_textures2D[] : register(t0, space2); + +cbuffer Globals : register(b0, space0) { + float gMotionBlurScalar; + float UsingHDR10; + float HDRPeakNits; + float SDRPaperWhiteNits; + float physicsmaterial; + float4 TexelSize; + float4 BlueShiftColor; + float4 BlueShiftParams; + float ElapsedTime; + float Frames; + float Lambda; + float4 BrightPassValues; + float White; + float IntensityBloom; + float4 brightPassParams; + float3 LUMINANCE; + float deSat; + float4 ConstAdd; + float4 ColorCorrect; + float Contrast; + float4 DofParams; + float3 NearFarClipPlaneQ; + float2 NearFarClipPaneScaleAndBias; + float4x4 gViewProjInverse; + float Gamma; + float LowerLimitAdaption; + float HigherLimitAdaption; + float distortionFreq; + float distortionScale; + float distortionRoll; + float4 SSAOProjectionParams; + float4 SSAOTweakParams; + float4 gScreenSize; + float ParticleHeatShimmerSeed; + int FullResMapSampler; + int FullResMapSamplerSS; + int RenderMapSampler; + int RenderMapSamplerSS; + int RenderMapPointSampler; + int RenderMapPointSamplerSS; + int RenderMapBilinearSampler; + int RenderMapBilinearSamplerSS; + int RenderMapAnisoSampler; + int RenderMapAnisoSamplerSS; + int DepthMapSampler; + int DepthMapSamplerSS; + int ToneMapSampler; + int ToneMapSamplerSS; + int AdaptedLuminanceMapSampler; + int AdaptedLuminanceMapSamplerSS; + int LightGlowTexSampler; + int LightGlowTexSamplerSS; + float AdaptedLuminance; + float2 horzTapOffs[7]; + float2 vertTapOffs[7]; + float4 TexelWeight[16]; + float3 Scale; + float DustOverlayStrength; + float SoftDofFalloffPower; + float SoftDofStrength; + float DofBackendPull; + float TotalTime; + float4 HeatShimmerParams; + float4 ColorScalar; + int DOFHelperSampler; + int DOFHelperSamplerSS; + int ParticleCompositeSampler; + int ParticleCompositeSamplerSS; + int GlowSampler; + int GlowSamplerSS; + int GlowSampler2; + int GlowSampler2SS; + float DisableVignette; + float AdditiveReducer; + float AdditiveReducer2; + float4 GlowColor2; + float4 GlowColor; + float FlareSize; + int DeathSampler; + int DeathSamplerSS; + float DeathMag; + float DeathDrip; + float DeathBlood; + float4 DeathColor; + float3 DeathEffect; + float4 InjuryDirections; + float4 InjuryTimes; + float4x4 WorldViewProjInverse; + float AverageHeight; + float4 LightStreakDirection; + float4 streakWeights; + float4 StreakParams; + float4 DuelColorCorrect; + float4 DuelConstAdd; + float DuelEnemyU; + float DuelEnemyWidth; + float DueldeSat; + float DuelContrast; +}; + +SamplerState g_samplers[] : register(s0, space1); + +float4 main( + noperspective float4 SV_Position: SV_Position, + linear float4 TEXCOORD0: TEXCOORD, + linear float4 TEXCOORD1: TEXCOORD1, + linear float4 TEXCOORD2: TEXCOORD2) + : SV_Target { + float _1 = TEXCOORD2.x; + float _2 = TEXCOORD2.y; + float _3 = TEXCOORD2.z; + float _4 = TEXCOORD2.w; + float _5 = TEXCOORD0.x; + float _6 = TEXCOORD0.y; + + float _16 = g_textures2D[DepthMapSampler].Sample(g_samplers[DepthMapSamplerSS], TEXCOORD0.xy).x; // fix + + float _18 = NearFarClipPlaneQ.x; + float _19 = NearFarClipPlaneQ.z; + float _20 = _18 * _19; + float _21 = -_20; + float _22 = _16 - _19; + float _23 = _21 / _22; + + float4 fullResMap = g_textures2D[FullResMapSampler].Sample(g_samplers[FullResMapSamplerSS], TEXCOORD0.xy); // fix + + float _32 = fullResMap.x; + float _33 = fullResMap.y; + float _34 = fullResMap.z; + + float4 _42 = g_textures2D[RenderMapAnisoSampler].Sample(g_samplers[RenderMapAnisoSamplerSS], TEXCOORD0.xy); // fix + float _43 = _42.x; + float _44 = _42.y; + float _45 = _42.z; + float _46 = _42.w; + + float _47 = _43 * _43; + float _48 = _44 * _44; + float _49 = _45 * _45; + float _51 = IntensityBloom; + float _52 = _47 * _51; + float _53 = _48 * _51; + float _54 = _49 * _51; + float _55 = saturate(_46); + + float4 _64 = g_textures2D[RenderMapBilinearSampler].Sample(g_samplers[RenderMapBilinearSamplerSS], TEXCOORD0.xy); // fix + float _65 = _64.x; + float _66 = _64.y; + float _67 = _64.z; + + float _69 = DofParams.x; + float _70 = DofParams.y; + float _71 = _23 - _70; + float _72 = _71 * _69; + float _73 = saturate(_72); + bool _75 = (_23 < DofParams.z); + float _76 = _75 ? 1.0 : 0.0; + float _77 = max(_76 * _73, _55); + + float _78 = max(_77, _55); + + float AdaptedLuminance = g_textures2D[AdaptedLuminanceMapSampler].Sample(g_samplers[AdaptedLuminanceMapSamplerSS], float2(0, 0)).x; + float clampedAdaptedLuminance = clamp(AdaptedLuminance, LowerLimitAdaption, HigherLimitAdaption); + + float _94 = _65 - _32; + float _95 = _66 - _33; + float _96 = _67 - _34; + + float _97 = _78 * _94; + float _98 = _78 * _95; + float _99 = _78 * _96; + float _100 = _97 + _32; + float _101 = _98 + _33; + float _102 = _99 + _34; + + float4 _110 = g_textures2D[GlowSampler].Sample(g_samplers[GlowSamplerSS], TEXCOORD2.xy); // fix + float _111 = _110.x; + float _112 = _110.y; + float _113 = _110.z; + float _114 = _110.w; + + float4 _122 = g_textures2D[GlowSampler2].Sample(g_samplers[GlowSampler2SS], TEXCOORD2.zw); // fix + float _123 = _122.x; + float _124 = _122.y; + float _125 = _122.z; + float _126 = _122.w; + float _136 = 1.010 - renodx::color::y::from::BT601(float3(_100, _101, _102)); + float _141 = log2(abs(_136)); + float _142 = _141 * AdditiveReducer; + float _143 = _141 * AdditiveReducer2; + float _144 = exp2(_142); + float _145 = exp2(_143); + + float _146 = _114 * _111; + float _147 = _146 * GlowColor.x; + float _148 = _147 * _144; + float _149 = _114 * _112; + float _150 = _149 * GlowColor.y; + float _151 = _150 * _144; + float _152 = _114 * _113; + float _153 = _152 * GlowColor.z; + float _154 = _153 * _144; + + float _155 = _148 + _100; + float _156 = _151 + _101; + float _157 = _154 + _102; + + float _158 = _126 * _123; + float _159 = _158 * GlowColor2.x; + float _160 = _159 * _145; + float _161 = _126 * _124; + float _162 = _161 * GlowColor2.y; + float _163 = _162 * _145; + float _164 = _126 * _125; + float _165 = _164 * GlowColor2.z; + float _166 = _165 * _145; + + float _167 = _155 + _160; + float _168 = _156 + _163; + float _169 = _157 + _166; + + // float _171 = BrightPassValues.z; + // float _172 = clampedAdaptedLuminance + 0.001; + // float _173 = _171 / _172; + float scale = BrightPassValues.z / (clampedAdaptedLuminance + 0.001); + + float _174 = _167 * scale; + float _175 = _168 * scale; + float _176 = _169 * scale; + + float3 color_scaled = float3(_174, _175, _176); + + float _178 = White; + float _179 = _174 / _178; + float _180 = _175 / _178; + float _181 = _176 / _178; + + float _182 = _179 + 1.000; + float _183 = _180 + 1.000; + float _184 = _181 + 1.000; + + float _185 = _182 * _174; + float _186 = _183 * _175; + float _187 = _184 * _176; + + float _188 = _174 + 1.000; + float _189 = _175 + 1.000; + float _190 = _176 + 1.000; + + float _191 = _185 / _188; + float _192 = _186 / _189; + float _193 = _187 / _190; + +#if 1 // blended reinhard with untonemapped + float3 vanillaColor = float3(_191, _192, _193); + + float midGrayScale = RDR1ReinhardMidgrayScale(White); + float3 untonemapped_scaled = color_scaled * midGrayScale; + + float3 blendedColor = lerp(vanillaColor, lerp(vanillaColor, untonemapped_scaled, 0.5), saturate(vanillaColor)); + + _191 = blendedColor.r; + _192 = blendedColor.g; + _193 = blendedColor.b; +#endif + + // apply bloom + float _194 = _191 + _52; + float _195 = _192 + _53; + float _196 = _193 + _54; + + float _198 = ConstAdd.x; + float _199 = ConstAdd.y; + float _200 = ConstAdd.z; + + float _201 = _194 + _198; + float _202 = _195 + _199; + float _203 = _196 + _200; + + float _205 = ColorCorrect.x * 2.000; + float _206 = ColorCorrect.y * 2.000; + float _207 = ColorCorrect.z * 2.000; + + float _209 = _205 * _201; + float _210 = _206 * _202; + float _211 = _207 * _203; + + float3 colorCorrected = float3(_209, _210, _211); + + // Apply Desaturation - lerp to luminance + float blackAndWhite = dot(colorCorrected, LUMINANCE.xyz); + float3 desaturatedColorHDR = lerp(blackAndWhite, colorCorrected, deSat); + + // Apply Contrast + // done in SDR, causes broken colors on highlights otherwise + float3 desaturatedColorSDR = saturate(renodx::tonemap::dice::BT709(desaturatedColorHDR, 1.0)); + float3 contrastedColor = desaturatedColorSDR - (((desaturatedColorSDR * Contrast) * (desaturatedColorSDR - 1.0)) * (desaturatedColorSDR - 0.5)); + + float3 outputColor = contrastedColor; + +#if 1 // use upgradetonemap() to apply SDR contrast to HDR + float3 upgradedColor = renodx::tonemap::UpgradeToneMap(desaturatedColorHDR, desaturatedColorSDR, outputColor, 1.f); + + // blend vanillaColor back in to fix differences in contrast + float3 vanillaDesaturatedColor = saturate(desaturatedColorHDR); + float3 vanillaContrastedColor = vanillaDesaturatedColor - (((vanillaDesaturatedColor * Contrast) * (vanillaDesaturatedColor - 1.0)) * (vanillaDesaturatedColor - 0.5)); + outputColor = lerp(saturate(vanillaContrastedColor), upgradedColor, saturate(vanillaContrastedColor)); +#endif + + float3 gammaEncodedColor = renodx::color::gamma::Encode(max(0, outputColor), 2.2f); + + return float4(gammaEncodedColor, 1.0); +} diff --git a/src/games/rdr1/PSRDR2PostfxSoftCutsceneDof.0x9761FB07.ps_6_0.hlsl b/src/games/rdr1/PSRDR2PostfxSoftCutsceneDof.0x9761FB07.ps_6_0.hlsl new file mode 100644 index 00000000..f94bbd2c --- /dev/null +++ b/src/games/rdr1/PSRDR2PostfxSoftCutsceneDof.0x9761FB07.ps_6_0.hlsl @@ -0,0 +1,302 @@ +// shader hash : e7d616a26f49bfe3b3f320ee074c357e + +#include "./shared.h" +#include "./tonemaphelper.hlsl" + +Texture2D g_textures2D[] : register(t0, space2); + +cbuffer Globals : register(b0, space0) { + float gMotionBlurScalar; + float UsingHDR10; + float HDRPeakNits; + float SDRPaperWhiteNits; + float physicsmaterial; + float4 TexelSize; + float4 BlueShiftColor; + float4 BlueShiftParams; + float ElapsedTime; + float Frames; + float Lambda; + float4 BrightPassValues; + float White; + float IntensityBloom; + float4 brightPassParams; + float3 LUMINANCE; + float deSat; + float4 ConstAdd; + float4 ColorCorrect; + float Contrast; + float4 DofParams; + float3 NearFarClipPlaneQ; + float2 NearFarClipPaneScaleAndBias; + float4x4 gViewProjInverse; + float Gamma; + float LowerLimitAdaption; + float HigherLimitAdaption; + float distortionFreq; + float distortionScale; + float distortionRoll; + float4 SSAOProjectionParams; + float4 SSAOTweakParams; + float4 gScreenSize; + float ParticleHeatShimmerSeed; + int FullResMapSampler; + int FullResMapSamplerSS; + int RenderMapSampler; + int RenderMapSamplerSS; + int RenderMapPointSampler; + int RenderMapPointSamplerSS; + int RenderMapBilinearSampler; + int RenderMapBilinearSamplerSS; + int RenderMapAnisoSampler; + int RenderMapAnisoSamplerSS; + int DepthMapSampler; + int DepthMapSamplerSS; + int ToneMapSampler; + int ToneMapSamplerSS; + int AdaptedLuminanceMapSampler; + int AdaptedLuminanceMapSamplerSS; + int LightGlowTexSampler; + int LightGlowTexSamplerSS; + float AdaptedLuminance; + float2 horzTapOffs[7]; + float2 vertTapOffs[7]; + float4 TexelWeight[16]; + float3 Scale; + float DustOverlayStrength; + float SoftDofFalloffPower; + float SoftDofStrength; + float DofBackendPull; + float TotalTime; + float4 HeatShimmerParams; + float4 ColorScalar; + int DOFHelperSampler; + int DOFHelperSamplerSS; + int ParticleCompositeSampler; + int ParticleCompositeSamplerSS; + int GlowSampler; + int GlowSamplerSS; + int GlowSampler2; + int GlowSampler2SS; + float DisableVignette; + float AdditiveReducer; + float AdditiveReducer2; + float4 GlowColor2; + float4 GlowColor; + float FlareSize; + int DeathSampler; + int DeathSamplerSS; + float DeathMag; + float DeathDrip; + float DeathBlood; + float4 DeathColor; + float3 DeathEffect; + float4 InjuryDirections; + float4 InjuryTimes; + float4x4 WorldViewProjInverse; + float AverageHeight; + float4 LightStreakDirection; + float4 streakWeights; + float4 StreakParams; + float4 DuelColorCorrect; + float4 DuelConstAdd; + float DuelEnemyU; + float DuelEnemyWidth; + float DueldeSat; + float DuelContrast; +}; + +SamplerState g_samplers[] : register(s0, space1); + +// PSRDR2PostfxSoftCutsceneDof() +float4 main(float4 SV_Position: SV_POSITION, + float4 TEXCOORD0: TEXCOORD0, + float4 TEXCOORD1: TEXCOORD1, + float4 TEXCOORD2: TEXCOORD2) + : SV_Target { + float _1 = TEXCOORD0.x; + float _2 = TEXCOORD0.y; + + float _12 = g_textures2D[DepthMapSampler].Sample(g_samplers[DepthMapSamplerSS], TEXCOORD0.xy).x; + float _14 = NearFarClipPlaneQ.x; + float _15 = NearFarClipPlaneQ.z; + float _16 = _14 * _15; + float _17 = -0.000000 - _16; + float _18 = _12 - _15; + float _19 = _17 / _18; + + float3 fullResMap = g_textures2D[FullResMapSampler].Sample(g_samplers[FullResMapSamplerSS], TEXCOORD0.xy).rgb; + float _28 = fullResMap.r; + float _29 = fullResMap.g; + float _30 = fullResMap.b; + + float4 anisotropicSampler = g_textures2D[RenderMapAnisoSampler].Sample(g_samplers[RenderMapAnisoSamplerSS], TEXCOORD0.xy); + float _40 = anisotropicSampler.x; + float _41 = anisotropicSampler.y; + float _42 = anisotropicSampler.z; + float _43 = anisotropicSampler.w; + float _44 = _40 * _40; + float _45 = _41 * _41; + float _46 = _42 * _42; + // _dx.types.CBufRet.f32 _47 = { _0.White, _0.IntensityBloom, , }; // cbuffer = $Globals, byte_offset = 112 + float _48 = IntensityBloom; + float _49 = _44 * _48; + float _50 = _45 * _48; + float _51 = _46 * _48; + float _52 = saturate(_43); + // _dx.types.CBufRet.i32 _53 = { _0.RenderMapSamplerSS, _0.RenderMapPointSampler, _0.RenderMapPointSamplerSS, _0.RenderMapBilinearSampler }; // cbuffer = $Globals, byte_offset = 416 + int _54 = RenderMapBilinearSampler; + // _dx.types.CBufRet.i32 _55 = { _0.RenderMapBilinearSamplerSS, _0.RenderMapAnisoSampler, _0.RenderMapAnisoSamplerSS, _0.DepthMapSampler }; // cbuffer = $Globals, byte_offset = 432 + int _56 = RenderMapBilinearSamplerSS; + int _57 = RenderMapBilinearSampler; + // InitialiseHandle(g_textures2D[_57]); + int _59 = RenderMapBilinearSamplerSS; + // InitialiseHandle(g_samplers[_59]); + float3 _61 = g_textures2D[RenderMapBilinearSampler].Sample(g_samplers[RenderMapBilinearSamplerSS], TEXCOORD0.xy).rgb; + float _62 = _61.r; + float _63 = _61.g; + float _64 = _61.b; + // _dx.types.CBufRet.f32 _65 = { _0.DofParams.x, _0.DofParams.y, _0.DofParams.z, _0.DofParams.w }; // cbuffer = $Globals, byte_offset = 208 + float _66 = DofParams.y; + float _67 = DofParams.x; + float _68 = DofParams.z; + float _69 = DofParams.w; + float _70 = _66 - _19; + float _71 = abs(_70); + float _72 = _71 * _67; + float _73 = saturate(_72); + bool _74 = (_19 > _68); + float _75 = _74 ? 0.000000 : _73; + float _76 = _75 - _69; + float _77 = 1.00000 - _69; + float _78 = _76 / _77; + float _79 = saturate(_78); + // _dx.types.CBufRet.f32 _80 = { _0.SoftDofFalloffPower, _0.SoftDofStrength, _0.DofBackendPull, _0.TotalTime }; // cbuffer = $Globals, byte_offset = 976 + float _81 = SoftDofStrength; + float _82 = _81 * _79; + float _83 = max(_82, _52); + float _84 = _1 + -0.500000; + float _85 = _2 + -0.500000; + float _86 = dot(float2(_84, _85), float2(_84, _85)); + float _87 = 1.00000 - _86; + float _88 = _87 * _87; + // _dx.types.CBufRet.f32 _89 = { _0.DisableVignette, _0.AdditiveReducer, _0.AdditiveReducer2, }; // cbuffer = $Globals, byte_offset = 1056 + float _90 = DisableVignette; + float _91 = _88 + _90; + float _92 = saturate(_91); + float _93 = 1.00000 - _92; + float _94 = max(_83, _93); + + float _104 = g_textures2D[AdaptedLuminanceMapSampler].Sample(g_samplers[AdaptedLuminanceMapSamplerSS], float2(0, 0)).x; + // _dx.types.CBufRet.f32 _105 = { _0.Gamma, _0.LowerLimitAdaption, _0.HigherLimitAdaption, _0.distortionFreq }; // cbuffer = $Globals, byte_offset = 320 + float _106 = HigherLimitAdaption; + float _107 = LowerLimitAdaption; + float _108 = max(_104, _107); + float _109 = min(_108, _106); + float clampedAdaptedLuminance = _109; + float _110 = _62 - _28; + float _111 = _63 - _29; + float _112 = _64 - _30; + float _113 = _94 * _110; + float _114 = _94 * _111; + float _115 = _94 * _112; + float _116 = _113 + _28; + float _117 = _114 + _29; + float _118 = _115 + _30; + + // apply adaptation + // float _120 = BrightPassValues.z; + // float _121 = _109 + 0.001; + // float _122 = _120 / _121; + float scale = BrightPassValues.z / (clampedAdaptedLuminance + 0.001); + float _123 = scale * _116; + float _124 = scale * _117; + float _125 = scale * _118; + float3 color_scaled = float3(_123, _124, _125); + + float _127 = White; + float _128 = _123 / _127; + float _129 = _124 / _127; + float _130 = _125 / _127; + float _131 = _128 + 1.00000; + float _132 = _129 + 1.00000; + float _133 = _130 + 1.00000; + float _134 = _131 * _123; + float _135 = _132 * _124; + float _136 = _133 * _125; + float _137 = _123 + 1.00000; + float _138 = _124 + 1.00000; + float _139 = _125 + 1.00000; + float _140 = _134 / _137; + float _141 = _135 / _138; + float _142 = _136 / _139; + +#if 1 // blended reinhard with untonemapped + float3 vanillaColor = float3(_140, _141, _142); + + float midGrayScale = RDR1ReinhardMidgrayScale(White); + float3 untonemapped_scaled = color_scaled * midGrayScale; + + float3 blendedColor = lerp(vanillaColor, lerp(vanillaColor, untonemapped_scaled, 0.5), saturate(vanillaColor)); + + _140 = blendedColor.r; + _141 = blendedColor.g; + _142 = blendedColor.b; +#endif + + // Apply Bloom + float _143 = _140 + _49; + float _144 = _141 + _50; + float _145 = _142 + _51; + + float _147 = DisableVignette; + float _148 = 1.00000 - _147; + float _149 = _148 * 0.150000; + float _150 = _149 + 1.00000; + float _151 = _92 * 0.500000; + float _152 = _151 + 0.500000; + float _153 = _150 * _152; + + float _155 = ConstAdd.x; + float _156 = ConstAdd.y; + float _157 = ConstAdd.z; + float _158 = _143 + _155; + float _159 = _144 + _156; + float _160 = _145 + _157; + + // Apply Color Correction + float _162 = ColorCorrect.x; + float _163 = ColorCorrect.y; + float _164 = ColorCorrect.z; + float _165 = _162 * 2.00000; + float _166 = _165 * _158; + float _167 = _163 * 2.00000; + float _168 = _167 * _159; + float _169 = _164 * 2.00000; + float _170 = _169 * _160; + float3 colorCorrected = float3(_166, _168, _170); + + // Apply Desaturation - lerp to luminance + float blackAndWhite = dot(colorCorrected, LUMINANCE.xyz); + float3 desaturatedColorHDR = lerp(blackAndWhite, colorCorrected, deSat); + + // Apply Contrast + // done in SDR, causes broken colors on highlights otherwise + float3 desaturatedColorSDR = saturate(renodx::tonemap::dice::BT709(desaturatedColorHDR, 1.0)); + float3 contrastedColor = desaturatedColorSDR - (((desaturatedColorSDR * Contrast) * (desaturatedColorSDR - 1.0)) * (desaturatedColorSDR - 0.5)); + + float3 outputColor = contrastedColor; + +#if 1 // use upgradetonemap() to apply SDR contrast to HDR + float3 upgradedColor = renodx::tonemap::UpgradeToneMap(desaturatedColorHDR, desaturatedColorSDR, outputColor, 1.f); + + // blend vanillaColor back in to fix differences in contrast + float3 vanillaDesaturatedColor = saturate(desaturatedColorHDR); + float3 vanillaContrastedColor = vanillaDesaturatedColor - (((vanillaDesaturatedColor * Contrast) * (vanillaDesaturatedColor - 1.0)) * (vanillaDesaturatedColor - 0.5)); + outputColor = lerp(saturate(vanillaContrastedColor), upgradedColor, saturate(vanillaContrastedColor)); +#endif + + float3 gammaEncodedColor = renodx::color::gamma::Encode(max(0, outputColor), 2.2f); + + return float4(gammaEncodedColor, 1.0); +} diff --git a/src/games/rdr1/PSRDR2PostfxSoftCutsceneDofOptics.0x632ABCB2.ps_6_0.hlsl b/src/games/rdr1/PSRDR2PostfxSoftCutsceneDofOptics.0x632ABCB2.ps_6_0.hlsl new file mode 100644 index 00000000..adb81533 --- /dev/null +++ b/src/games/rdr1/PSRDR2PostfxSoftCutsceneDofOptics.0x632ABCB2.ps_6_0.hlsl @@ -0,0 +1,389 @@ +// shader hash: 4c769258f830157a2deb067e0c536bf0 + +#include "./shared.h" +#include "./tonemaphelper.hlsl" + +Texture2D g_textures2D[] : register(t0, space2); + +cbuffer Globals : register(b0, space0) { + float gMotionBlurScalar; + float UsingHDR10; + float HDRPeakNits; + float SDRPaperWhiteNits; + float physicsmaterial; + float4 TexelSize; + float4 BlueShiftColor; + float4 BlueShiftParams; + float ElapsedTime; + float Frames; + float Lambda; + float4 BrightPassValues; + float White; + float IntensityBloom; + float4 brightPassParams; + float3 LUMINANCE; + float deSat; + float4 ConstAdd; + float4 ColorCorrect; + float Contrast; + float4 DofParams; + float3 NearFarClipPlaneQ; + float2 NearFarClipPaneScaleAndBias; + float4x4 gViewProjInverse; + float Gamma; + float LowerLimitAdaption; + float HigherLimitAdaption; + float distortionFreq; + float distortionScale; + float distortionRoll; + float4 SSAOProjectionParams; + float4 SSAOTweakParams; + float4 gScreenSize; + float ParticleHeatShimmerSeed; + int FullResMapSampler; + int FullResMapSamplerSS; + int RenderMapSampler; + int RenderMapSamplerSS; + int RenderMapPointSampler; + int RenderMapPointSamplerSS; + int RenderMapBilinearSampler; + int RenderMapBilinearSamplerSS; + int RenderMapAnisoSampler; + int RenderMapAnisoSamplerSS; + int DepthMapSampler; + int DepthMapSamplerSS; + int ToneMapSampler; + int ToneMapSamplerSS; + int AdaptedLuminanceMapSampler; + int AdaptedLuminanceMapSamplerSS; + int LightGlowTexSampler; + int LightGlowTexSamplerSS; + float AdaptedLuminance; + float2 horzTapOffs[7]; + float2 vertTapOffs[7]; + float4 TexelWeight[16]; + float3 Scale; + float DustOverlayStrength; + float SoftDofFalloffPower; + float SoftDofStrength; + float DofBackendPull; + float TotalTime; + float4 HeatShimmerParams; + float4 ColorScalar; + int DOFHelperSampler; + int DOFHelperSamplerSS; + int ParticleCompositeSampler; + int ParticleCompositeSamplerSS; + int GlowSampler; + int GlowSamplerSS; + int GlowSampler2; + int GlowSampler2SS; + float DisableVignette; + float AdditiveReducer; + float AdditiveReducer2; + float4 GlowColor2; + float4 GlowColor; + float FlareSize; + int DeathSampler; + int DeathSamplerSS; + float DeathMag; + float DeathDrip; + float DeathBlood; + float4 DeathColor; + float3 DeathEffect; + float4 InjuryDirections; + float4 InjuryTimes; + float4x4 WorldViewProjInverse; + float AverageHeight; + float4 LightStreakDirection; + float4 streakWeights; + float4 StreakParams; + float4 DuelColorCorrect; + float4 DuelConstAdd; + float DuelEnemyU; + float DuelEnemyWidth; + float DueldeSat; + float DuelContrast; +}; + +SamplerState g_samplers[] : register(s0, space1); + +// PSRDR2PostfxSoftCutsceneDofOptics() +float4 main(float4 SV_Position: SV_POSITION, + float4 TEXCOORD0: TEXCOORD0, + float4 TEXCOORD1: TEXCOORD1, + float4 TEXCOORD2: TEXCOORD2) + : SV_Target { + float _1 = TEXCOORD2.x; + float _2 = TEXCOORD2.y; + float _3 = TEXCOORD2.z; + float _4 = TEXCOORD2.w; + float _5 = TEXCOORD0.x; + float _6 = TEXCOORD0.y; + + float _16 = g_textures2D[DepthMapSampler].Sample(g_samplers[DepthMapSamplerSS], TEXCOORD0.xy).x; + + float _18 = NearFarClipPlaneQ.x; + float _19 = NearFarClipPlaneQ.z; + float _20 = _18 * _19; + float _21 = -0.000000 - _20; + float _22 = _16 - _19; + float _23 = _21 / _22; + // _dx.types.CBufRet.i32 _24 = { _0.ParticleHeatShimmerSeed, _0.FullResMapSampler, _0.FullResMapSamplerSS, _0.RenderMapSampler }; // cbuffer = $Globals, byte_offset = 400 + int _25 = FullResMapSampler; + int _26 = FullResMapSamplerSS; + int _27 = FullResMapSampler; + int _29 = FullResMapSamplerSS; + float3 fullResMap = g_textures2D[FullResMapSampler].Sample(g_samplers[FullResMapSamplerSS], TEXCOORD0.xy).rgb; + float _32 = fullResMap.r; + float _33 = fullResMap.g; + float _34 = fullResMap.b; + + float4 anisotropicSampler = g_textures2D[RenderMapAnisoSampler].Sample(g_samplers[RenderMapAnisoSamplerSS], TEXCOORD0.xy); + float _44 = anisotropicSampler.x; + float _45 = anisotropicSampler.y; + float _46 = anisotropicSampler.z; + float _47 = anisotropicSampler.w; + float _48 = _44 * _44; + float _49 = _45 * _45; + float _50 = _46 * _46; + + float _52 = IntensityBloom; + float _53 = _48 * _52; + float _54 = _49 * _52; + float _55 = _50 * _52; + float _56 = saturate(_47); + + float3 _65 = g_textures2D[RenderMapBilinearSampler].Sample(g_samplers[RenderMapBilinearSamplerSS], TEXCOORD0.xy).rgb; + float _66 = _65.r; + float _67 = _65.g; + float _68 = _65.b; + float _70 = DofParams.y; + float _71 = DofParams.x; + float _72 = DofParams.z; + float _73 = DofParams.w; + float _74 = _70 - _23; + float _75 = abs(_74); + float _76 = _75 * _71; + float _77 = saturate(_76); + bool _78 = (_23 > _72); + float _79 = _78 ? 0.000000 : _77; + float _80 = _79 - _73; + float _81 = 1.00000 - _73; + float _82 = _80 / _81; + float _83 = saturate(_82); + + float _85 = SoftDofStrength; + float _86 = _85 * _83; + float _87 = max(_86, _56); + float _88 = _5 + -0.500000; + float _89 = _6 + -0.500000; + float _90 = dot(float2(_88, _89), float2(_88, _89)); + float _91 = 1.00000 - _90; + float _92 = _91 * _91; + + float _94 = DisableVignette; + float _95 = _92 + _94; + float _96 = saturate(_95); + float _97 = 1.00000 - _96; + float _98 = max(_87, _97); + + float _108 = g_textures2D[AdaptedLuminanceMapSampler].Sample(g_samplers[AdaptedLuminanceMapSamplerSS], float2(0, 0)).x; + // _dx.types.CBufRet.f32 _109 = { _0.Gamma, _0.LowerLimitAdaption, _0.HigherLimitAdaption, _0.distortionFreq }; // cbuffer = $Globals, byte_offset = 320 + float _110 = HigherLimitAdaption; + float _111 = LowerLimitAdaption; + float _112 = max(_108, _111); + float _113 = min(_112, _110); + float clampedAdaptedLuminance = _113; + float _114 = _66 - _32; + float _115 = _67 - _33; + float _116 = _68 - _34; + float _117 = _98 * _114; + float _118 = _98 * _115; + float _119 = _98 * _116; + float _120 = _117 + _32; + float _121 = _118 + _33; + float _122 = _119 + _34; + + float4 _130 = g_textures2D[GlowSampler].Sample(g_samplers[GlowSamplerSS], TEXCOORD2.xy); + float _131 = _130.r; + float _132 = _130.g; + float _133 = _130.b; + float _134 = _130.a; + // _dx.types.CBufRet.i32 _135 = { _0.GlowSampler, _0.GlowSamplerSS, _0.GlowSampler2, _0.GlowSampler2SS }; // cbuffer = $Globals, byte_offset = 1040 + int _136 = GlowSampler2; + int _137 = GlowSampler2SS; + int _138 = GlowSampler2; + int _140 = GlowSampler2SS; + float4 _142 = g_textures2D[GlowSampler2].Sample(g_samplers[GlowSampler2SS], TEXCOORD2.zw); + float _143 = _142.r; + float _144 = _142.g; + float _145 = _142.b; + float _146 = _142.a; + float _148 = GlowColor2.x; + float _149 = GlowColor2.y; + float _150 = GlowColor2.z; + float _152 = GlowColor.x; + float _153 = GlowColor.y; + float _154 = GlowColor.z; + float _155 = renodx::color::y::from::BT601(float3(_120, _121, _122)); + float _156 = 1.00000 - _155; + float _158 = AdditiveReducer; + float _159 = AdditiveReducer2; + float _160 = abs(_156); + float _161 = log2(_160); + float _162 = _161 * _158; + float _163 = _161 * _159; + float _164 = exp2(_162); + float _165 = exp2(_163); + float _166 = _134 * _131; + float _167 = _166 * _152; + float _168 = _167 * _164; + float _169 = _134 * _132; + float _170 = _169 * _153; + float _171 = _170 * _164; + float _172 = _134 * _133; + float _173 = _172 * _154; + float _174 = _173 * _164; + float _175 = _168 + _120; + float _176 = _171 + _121; + float _177 = _174 + _122; + float _178 = _146 * _143; + float _179 = _178 * _148; + float _180 = _179 * _165; + float _181 = _146 * _144; + float _182 = _181 * _149; + float _183 = _182 * _165; + float _184 = _146 * _145; + float _185 = _184 * _150; + float _186 = _185 * _165; + float _187 = _175 + _180; + float _188 = _176 + _183; + float _189 = _177 + _186; + + // apply adaptation + // float _191 = BrightPassValues.z; + // float _192 = _113 + 0.001; + // float _193 = _191 / _192; + float scale = BrightPassValues.z / (clampedAdaptedLuminance + 0.001); + float _194 = _187 * scale; + float _195 = scale * _188; + float _196 = scale * _189; + float3 color_scaled = float3(_194, _195, _196); + + float _198 = White; + float _199 = _194 / _198; + float _200 = _195 / _198; + float _201 = _196 / _198; + float _202 = _199 + 1.00000; + float _203 = _200 + 1.00000; + float _204 = _201 + 1.00000; + float _205 = _202 * _194; + float _206 = _203 * _195; + float _207 = _204 * _196; + float _208 = _194 + 1.00000; + float _209 = _195 + 1.00000; + float _210 = _196 + 1.00000; + float _211 = _205 / _208; + float _212 = _206 / _209; + float _213 = _207 / _210; + +#if 1 // blended reinhard with untonemapped + float3 vanillaColor = float3(_211, _212, _213); + + float midGrayScale = RDR1ReinhardMidgrayScale(White); + float3 untonemapped_scaled = color_scaled * midGrayScale; + + float3 blendedColor = lerp(vanillaColor, lerp(vanillaColor, untonemapped_scaled, 0.5), saturate(vanillaColor)); + + _211 = blendedColor.r; + _212 = blendedColor.g; + _213 = blendedColor.b; +#endif + + // Apply Bloom + float _214 = _211 + _53; + float _215 = _212 + _54; + float _216 = _213 + _55; + + float _217 = DisableVignette; + float _218 = 1.00000 - _217; + float _219 = _218 * 0.150000; + float _220 = _219 + 1.00000; + float _221 = _96 * 0.500000; + float _222 = _221 + 0.500000; + float _223 = _220 * _222; + + float _225 = ConstAdd.x; + float _226 = ConstAdd.y; + float _227 = ConstAdd.z; + float _228 = _214 + _225; + float _229 = _215 + _226; + float _230 = _216 + _227; + // _dx.types.CBufRet.f32 _231 = { _0.ColorCorrect.x, _0.ColorCorrect.y, _0.ColorCorrect.z, _0.ColorCorrect.w }; // cbuffer = $Globals, byte_offset = 176 + float _232 = ColorCorrect.x; + float _233 = ColorCorrect.y; + float _234 = ColorCorrect.z; + float _235 = _232 * 2.00000; + float _236 = _235 * _228; + float _237 = _233 * 2.00000; + float _238 = _237 * _229; + float _239 = _234 * 2.00000; + float _240 = _239 * _230; + float _241 = (_236); + float _242 = (_238); + float _243 = (_240); + float3 colorCorrected = float3(_236, _238, _240); + + // Apply Desaturation - lerp to luminance + // float _248 = dot(float3(_241, _242, _243), LUMINANCE.xyz); + // float _249 = deSat; + // float _250 = _241 - _248; + // float _251 = _242 - _248; + // float _252 = _243 - _248; + // float _253 = _249 * _250; + // float _254 = _249 * _251; + // float _255 = _249 * _252; + // float _256 = _253 + _248; + // float _257 = _254 + _248; + // float _258 = _255 + _248; + float blackAndWhite = dot(colorCorrected, LUMINANCE.xyz); + float3 desaturatedColorHDR = lerp(blackAndWhite, colorCorrected, deSat); + + // float _260 = Contrast; + // float _261 = _256 + -1.00000; + // float _262 = _257 + -1.00000; + // float _263 = _258 + -1.00000; + // float _264 = _256 + -0.500000; + // float _265 = _257 + -0.500000; + // float _266 = _258 + -0.500000; + // float _267 = _256 * _260; + // float _268 = _267 * _261; + // float _269 = _268 * _264; + // float _270 = _257 * _260; + // float _271 = _270 * _262; + // float _272 = _271 * _265; + // float _273 = _258 * _260; + // float _274 = _273 * _263; + // float _275 = _274 * _266; + // float _276 = _256 - _269; + // float _277 = _257 - _272; + // float _278 = _258 - _275; + float3 desaturatedColorSDR = saturate(renodx::tonemap::dice::BT709(desaturatedColorHDR, 1.0)); + float3 contrastedColor = desaturatedColorSDR - (((desaturatedColorSDR * Contrast) * (desaturatedColorSDR - 1.0)) * (desaturatedColorSDR - 0.5)); + + float3 outputColor = contrastedColor; + +#if 1 // use upgradetonemap() to apply SDR contrast to HDR + float3 upgradedColor = renodx::tonemap::UpgradeToneMap(desaturatedColorHDR, desaturatedColorSDR, outputColor, 1.f); + + // blend vanillaColor back in to fix differences in contrast + float3 vanillaDesaturatedColor = saturate(desaturatedColorHDR); + float3 vanillaContrastedColor = vanillaDesaturatedColor - (((vanillaDesaturatedColor * Contrast) * (vanillaDesaturatedColor - 1.0)) * (vanillaDesaturatedColor - 0.5)); + outputColor = lerp(saturate(vanillaContrastedColor), upgradedColor, saturate(vanillaContrastedColor)); +#endif + + float3 gammaEncodedColor = renodx::color::gamma::Encode(max(0, outputColor), 2.2f); + + return float4(gammaEncodedColor, 1.0); +} diff --git a/src/games/rdr1/PSRDR2PostfxSoftDof.0xCCC43328.ps_6_0.hlsl b/src/games/rdr1/PSRDR2PostfxSoftDof.0xCCC43328.ps_6_0.hlsl new file mode 100644 index 00000000..daf655cb --- /dev/null +++ b/src/games/rdr1/PSRDR2PostfxSoftDof.0xCCC43328.ps_6_0.hlsl @@ -0,0 +1,245 @@ +#include "./shared.h" +#include "./tonemaphelper.hlsl" + +Texture2D g_textures2D[] : register(t0, space2); + +cbuffer Globals : register(b0, space0) { + float gMotionBlurScalar; + float UsingHDR10; + float HDRPeakNits; + float SDRPaperWhiteNits; + float physicsmaterial; + float4 TexelSize; + float4 BlueShiftColor; + float4 BlueShiftParams; + float ElapsedTime; + float Frames; + float Lambda; + float4 BrightPassValues; + float White; + float IntensityBloom; + float4 brightPassParams; + float3 LUMINANCE; + float deSat; + float4 ConstAdd; + float4 ColorCorrect; + float Contrast; + float4 DofParams; + float3 NearFarClipPlaneQ; + float2 NearFarClipPaneScaleAndBias; + float4x4 gViewProjInverse; + float Gamma; + float LowerLimitAdaption; + float HigherLimitAdaption; + float distortionFreq; + float distortionScale; + float distortionRoll; + float4 SSAOProjectionParams; + float4 SSAOTweakParams; + float4 gScreenSize; + float ParticleHeatShimmerSeed; + int FullResMapSampler; + int FullResMapSamplerSS; + int RenderMapSampler; + int RenderMapSamplerSS; + int RenderMapPointSampler; + int RenderMapPointSamplerSS; + int RenderMapBilinearSampler; + int RenderMapBilinearSamplerSS; + int RenderMapAnisoSampler; + int RenderMapAnisoSamplerSS; + int DepthMapSampler; + int DepthMapSamplerSS; + int ToneMapSampler; + int ToneMapSamplerSS; + int AdaptedLuminanceMapSampler; + int AdaptedLuminanceMapSamplerSS; + int LightGlowTexSampler; + int LightGlowTexSamplerSS; + float AdaptedLuminance; + float2 horzTapOffs[7]; + float2 vertTapOffs[7]; + float4 TexelWeight[16]; + float3 Scale; + float DustOverlayStrength; + float SoftDofFalloffPower; + float SoftDofStrength; + float DofBackendPull; + float TotalTime; + float4 HeatShimmerParams; + float4 ColorScalar; + int DOFHelperSampler; + int DOFHelperSamplerSS; + int ParticleCompositeSampler; + int ParticleCompositeSamplerSS; + int GlowSampler; + int GlowSamplerSS; + int GlowSampler2; + int GlowSampler2SS; + float DisableVignette; + float AdditiveReducer; + float AdditiveReducer2; + float4 GlowColor2; + float4 GlowColor; + float FlareSize; + int DeathSampler; + int DeathSamplerSS; + float DeathMag; + float DeathDrip; + float DeathBlood; + float4 DeathColor; + float3 DeathEffect; + float4 InjuryDirections; + float4 InjuryTimes; + float4x4 WorldViewProjInverse; + float AverageHeight; + float4 LightStreakDirection; + float4 streakWeights; + float4 StreakParams; + float4 DuelColorCorrect; + float4 DuelConstAdd; + float DuelEnemyU; + float DuelEnemyWidth; + float DueldeSat; + float DuelContrast; +}; + +SamplerState g_samplers[] : register(s0, space1); + +float4 main(float4 SV_Position: SV_POSITION, + float4 TEXCOORD0: TEXCOORD0, + float4 TEXCOORD1: TEXCOORD1, + float4 TEXCOORD2: TEXCOORD2) + : SV_Target { + float _1 = TEXCOORD0.x; + float _2 = TEXCOORD0.y; + + float3 fullResMap = g_textures2D[FullResMapSampler].Sample(g_samplers[FullResMapSamplerSS], TEXCOORD0.xy).rgb; + float _11 = fullResMap.r; + float _12 = fullResMap.g; + float _13 = fullResMap.b; + + float4 anisotropicSampler = g_textures2D[RenderMapAnisoSampler].Sample(g_samplers[RenderMapAnisoSamplerSS], TEXCOORD0.xy); + float _23 = anisotropicSampler.r; + float _24 = anisotropicSampler.g; + float _25 = anisotropicSampler.b; + float _27 = _23 * _23; + float _28 = _24 * _24; + float _29 = _25 * _25; + float _31 = IntensityBloom; + float _32 = _27 * _31; + float _33 = _28 * _31; + float _34 = _29 * _31; + float _35 = saturate(anisotropicSampler.w); + + float3 DoFMap = g_textures2D[RenderMapBilinearSampler].Sample(g_samplers[RenderMapBilinearSamplerSS], TEXCOORD0.xy).rgb; + float _45 = DoFMap.r; + float _46 = DoFMap.g; + float _47 = DoFMap.b; + + float adaptedLuminance = g_textures2D[AdaptedLuminanceMapSampler].Sample(g_samplers[AdaptedLuminanceMapSamplerSS], float2(0, 0)).x; + float _57 = adaptedLuminance; + float _59 = HigherLimitAdaption; + float _60 = LowerLimitAdaption; + float _61 = max(_57, _60); + float _62 = min(_61, _59); + float clampedAdaptedLuminance = _62; + float _63 = _45 - _11; + float _64 = _46 - _12; + float _65 = _47 - _13; + float _66 = _63 * _35; + float _67 = _64 * _35; + float _68 = _65 * _35; + float _69 = _66 + _11; + float _70 = _67 + _12; + float _71 = _68 + _13; + + // float _73 = BrightPassValues.z; + // float _74 = _62 + 0.001; + // float _75 = _73 / _74; + float scale = BrightPassValues.z / (clampedAdaptedLuminance + 0.001); + float _76 = scale * _69; + float _77 = scale * _70; + float _78 = scale * _71; + float3 color_scaled = float3(_76, _77, _78); + + float _80 = White; + float _81 = _76 / _80; + float _82 = _77 / _80; + float _83 = _78 / _80; + float _84 = _81 + 1.00000; + float _85 = _82 + 1.00000; + float _86 = _83 + 1.00000; + float _87 = _84 * _76; + float _88 = _85 * _77; + float _89 = _86 * _78; + float _90 = _76 + 1.00000; + float _91 = _77 + 1.00000; + float _92 = _78 + 1.00000; + float _93 = _87 / _90; + float _94 = _88 / _91; + float _95 = _89 / _92; + +#if 1 // blended reinhard with untonemapped + float3 vanillaColor = float3(_93, _94, _95); + + float midGrayScale = RDR1ReinhardMidgrayScale(White); + float3 untonemapped_scaled = color_scaled * midGrayScale; + + float3 blendedColor = lerp(vanillaColor, lerp(vanillaColor, untonemapped_scaled, 0.5), saturate(vanillaColor)); + + _93 = blendedColor.r; + _94 = blendedColor.g; + _95 = blendedColor.b; +#endif + + // Apply Bloom + float _96 = _93 + _32; + float _97 = _94 + _33; + float _98 = _95 + _34; + + float _100 = ConstAdd.x; + float _101 = ConstAdd.y; + float _102 = ConstAdd.z; + float _103 = _96 + _100; + float _104 = _97 + _101; + float _105 = _98 + _102; + float _107 = ColorCorrect.x; + float _108 = ColorCorrect.y; + float _109 = ColorCorrect.z; + float _110 = _107 * 2.00000; + float _111 = _110 * _103; + float _112 = _108 * 2.00000; + float _113 = _112 * _104; + float _114 = _109 * 2.00000; + float _115 = _114 * _105; + float _116 = (_111); + float _117 = (_113); + float _118 = (_115); + + float3 colorCorrected = float3(_111, _113, _115); + + // Apply Desaturation - lerp to luminance + float blackAndWhite = dot(colorCorrected, float3(LUMINANCE.x, LUMINANCE.y, LUMINANCE.z)); + float3 desaturatedColorHDR = lerp(blackAndWhite, colorCorrected, deSat); + + // Apply Contrast - done in SDR + float3 desaturatedColorSDR = saturate(renodx::tonemap::dice::BT709(desaturatedColorHDR, 1.0)); + float3 contrastedColor = desaturatedColorSDR - (((desaturatedColorSDR * Contrast) * (desaturatedColorSDR - 1.0)) * (desaturatedColorSDR - 0.5)); + + float3 outputColor = contrastedColor; + +#if 1 // use upgradetonemap() to apply SDR contrast to HDR + float3 upgradedColor = renodx::tonemap::UpgradeToneMap(desaturatedColorHDR, desaturatedColorSDR, outputColor, 1.f); + + // blend vanillaColor back in to fix differences in contrast + float3 vanillaDesaturatedColor = saturate(desaturatedColorHDR); + float3 vanillaContrastedColor = vanillaDesaturatedColor - (((vanillaDesaturatedColor * Contrast) * (vanillaDesaturatedColor - 1.0)) * (vanillaDesaturatedColor - 0.5)); + outputColor = lerp(saturate(vanillaContrastedColor), upgradedColor, saturate(vanillaContrastedColor)); +#endif + + // allowing negatives adds no wcg while causing artifacts in pause menu + float3 gammaEncodedColor = renodx::color::gamma::Encode(max(0, outputColor), 2.2f); + + return float4(gammaEncodedColor, 1.0); +} diff --git a/src/games/rdr1/PSRDR2PostfxSoftDofOptics.0xE93AD74D.ps_6_0.hlsl b/src/games/rdr1/PSRDR2PostfxSoftDofOptics.0xE93AD74D.ps_6_0.hlsl new file mode 100644 index 00000000..7801389f --- /dev/null +++ b/src/games/rdr1/PSRDR2PostfxSoftDofOptics.0xE93AD74D.ps_6_0.hlsl @@ -0,0 +1,302 @@ +#include "./shared.h" +#include "./tonemaphelper.hlsl" + +Texture2D g_textures2D[] : register(t0, space2); + +cbuffer Globals : register(b0, space0) { + float gMotionBlurScalar; + float UsingHDR10; + float HDRPeakNits; + float SDRPaperWhiteNits; + float physicsmaterial; + float4 TexelSize; + float4 BlueShiftColor; + float4 BlueShiftParams; + float ElapsedTime; + float Frames; + float Lambda; + float4 BrightPassValues; + float White; + float IntensityBloom; + float4 brightPassParams; + float3 LUMINANCE; + float deSat; + float4 ConstAdd; + float4 ColorCorrect; + float Contrast; + float4 DofParams; + float3 NearFarClipPlaneQ; + float2 NearFarClipPaneScaleAndBias; + float4x4 gViewProjInverse; + float Gamma; + float LowerLimitAdaption; + float HigherLimitAdaption; + float distortionFreq; + float distortionScale; + float distortionRoll; + float4 SSAOProjectionParams; + float4 SSAOTweakParams; + float4 gScreenSize; + float ParticleHeatShimmerSeed; + int FullResMapSampler; + int FullResMapSamplerSS; + int RenderMapSampler; + int RenderMapSamplerSS; + int RenderMapPointSampler; + int RenderMapPointSamplerSS; + int RenderMapBilinearSampler; + int RenderMapBilinearSamplerSS; + int RenderMapAnisoSampler; + int RenderMapAnisoSamplerSS; + int DepthMapSampler; + int DepthMapSamplerSS; + int ToneMapSampler; + int ToneMapSamplerSS; + int AdaptedLuminanceMapSampler; + int AdaptedLuminanceMapSamplerSS; + int LightGlowTexSampler; + int LightGlowTexSamplerSS; + float AdaptedLuminance; + float2 horzTapOffs[7]; + float2 vertTapOffs[7]; + float4 TexelWeight[16]; + float3 Scale; + float DustOverlayStrength; + float SoftDofFalloffPower; + float SoftDofStrength; + float DofBackendPull; + float TotalTime; + float4 HeatShimmerParams; + float4 ColorScalar; + int DOFHelperSampler; + int DOFHelperSamplerSS; + int ParticleCompositeSampler; + int ParticleCompositeSamplerSS; + int GlowSampler; + int GlowSamplerSS; + int GlowSampler2; + int GlowSampler2SS; + float DisableVignette; + float AdditiveReducer; + float AdditiveReducer2; + float4 GlowColor2; + float4 GlowColor; + float FlareSize; + int DeathSampler; + int DeathSamplerSS; + float DeathMag; + float DeathDrip; + float DeathBlood; + float4 DeathColor; + float3 DeathEffect; + float4 InjuryDirections; + float4 InjuryTimes; + float4x4 WorldViewProjInverse; + float AverageHeight; + float4 LightStreakDirection; + float4 streakWeights; + float4 StreakParams; + float4 DuelColorCorrect; + float4 DuelConstAdd; + float DuelEnemyU; + float DuelEnemyWidth; + float DueldeSat; + float DuelContrast; +}; + +SamplerState g_samplers[] : register(s0, space1); + +float4 main( + noperspective float4 SV_Position: SV_Position, + linear float4 TEXCOORD0: TEXCOORD, + linear float4 TEXCOORD1: TEXCOORD1, + linear float4 TEXCOORD2: TEXCOORD2) + : SV_Target { + float _1 = TEXCOORD2.x; + float _2 = TEXCOORD2.y; + float _3 = TEXCOORD2.z; + float _4 = TEXCOORD2.w; + float _5 = TEXCOORD0.x; + float _6 = TEXCOORD0.y; + + float3 fullResMap = g_textures2D[FullResMapSampler].Sample(g_samplers[FullResMapSamplerSS], TEXCOORD0.xy).rgb; + float _15 = fullResMap.r; + float _16 = fullResMap.g; + float _17 = fullResMap.b; + + int _22 = RenderMapAnisoSampler; + int _24 = RenderMapAnisoSamplerSS; + float4 _26 = g_textures2D[RenderMapAnisoSampler].Sample(g_samplers[RenderMapAnisoSamplerSS], TEXCOORD0.xy); + float _27 = _26.x; + float _28 = _26.y; + float _29 = _26.z; + float _30 = _26.w; + float _31 = _27 * _27; + float _32 = _28 * _28; + float _33 = _29 * _29; + + float _35 = IntensityBloom; + float _36 = _31 * _35; + float _37 = _32 * _35; + float _38 = _33 * _35; + float _39 = saturate(_30); + + float3 _48 = g_textures2D[RenderMapBilinearSampler].Sample(g_samplers[RenderMapBilinearSamplerSS], TEXCOORD0.xy).rgb; + float _49 = _48.r; + float _50 = _48.g; + float _51 = _48.b; + + float _61 = g_textures2D[AdaptedLuminanceMapSampler].Sample(g_samplers[AdaptedLuminanceMapSamplerSS], float2(0, 0)).x; + float _63 = HigherLimitAdaption; + float _64 = LowerLimitAdaption; + float _65 = max(_61, _64); + float _66 = min(_65, _63); + float clampedAdaptedLuminance = _66; + float _67 = _49 - _15; + float _68 = _50 - _16; + float _69 = _51 - _17; + float _70 = _67 * _39; + float _71 = _68 * _39; + float _72 = _69 * _39; + float _73 = _70 + _15; + float _74 = _71 + _16; + float _75 = _72 + _17; + + float4 _83 = g_textures2D[GlowSampler].Sample(g_samplers[GlowSamplerSS], TEXCOORD2.xy); + float _84 = _83.x; + float _85 = _83.y; + float _86 = _83.z; + float _87 = _83.w; + + float4 _95 = g_textures2D[GlowSampler2].Sample(g_samplers[GlowSampler2SS], TEXCOORD2.zw); + float _96 = _95.x; + float _97 = _95.y; + float _98 = _95.z; + float _99 = _95.w; + float _101 = GlowColor2.x; + float _102 = GlowColor2.y; + float _103 = GlowColor2.z; + float _105 = GlowColor.x; + float _106 = GlowColor.y; + float _107 = GlowColor.z; + float _108 = renodx::color::y::from::BT601(float3(_73, _74, _75)); // float _108 = dot( { _73, _74, _75 }, { 0.299000, 0.587000, 0.114000 }); + float _109 = 1.00000 - _108; + + float _111 = AdditiveReducer; + float _112 = AdditiveReducer2; + float _113 = abs(_109); + float _114 = log2(_113); + float _115 = _114 * _111; + float _116 = _114 * _112; + float _117 = exp2(_115); + float _118 = exp2(_116); + float _119 = _87 * _84; + float _120 = _119 * _105; + float _121 = _120 * _117; + float _122 = _87 * _85; + float _123 = _122 * _106; + float _124 = _123 * _117; + float _125 = _87 * _86; + float _126 = _125 * _107; + float _127 = _126 * _117; + float _128 = _121 + _73; + float _129 = _124 + _74; + float _130 = _127 + _75; + float _131 = _99 * _96; + float _132 = _131 * _101; + float _133 = _132 * _118; + float _134 = _99 * _97; + float _135 = _134 * _102; + float _136 = _135 * _118; + float _137 = _99 * _98; + float _138 = _137 * _103; + float _139 = _138 * _118; + float _140 = _128 + _133; + float _141 = _129 + _136; + float _142 = _130 + _139; + + // float _144 = BrightPassValues.z; + // float _145 = _66 + 0.001; + // float _146 = _144 / _145; + float scale = BrightPassValues.z / (clampedAdaptedLuminance + 0.001); + float _147 = _140 * scale; + float _148 = scale * _141; + float _149 = scale * _142; + float3 color_scaled = float3(_147, _148, _149); + + float _151 = White; + float _152 = _147 / _151; + float _153 = _148 / _151; + float _154 = _149 / _151; + float _155 = _152 + 1.00000; + float _156 = _153 + 1.00000; + float _157 = _154 + 1.00000; + float _158 = _155 * _147; + float _159 = _156 * _148; + float _160 = _157 * _149; + float _161 = _147 + 1.00000; + float _162 = _148 + 1.00000; + float _163 = _149 + 1.00000; + float _164 = _158 / _161; + float _165 = _159 / _162; + float _166 = _160 / _163; + +#if 1 // blended reinhard with untonemapped + float3 vanillaColor = float3(_164, _165, _166); + + float midGrayScale = RDR1ReinhardMidgrayScale(White); + float3 untonemapped_scaled = color_scaled * midGrayScale; + + float3 blendedColor = lerp(vanillaColor, lerp(vanillaColor, untonemapped_scaled, 0.5), saturate(vanillaColor)); + + _164 = blendedColor.r; + _165 = blendedColor.g; + _166 = blendedColor.b; +#endif + + // Apply Bloom + float _167 = _164 + _36; + float _168 = _165 + _37; + float _169 = _166 + _38; + + // Apply Color Correction + float _171 = ConstAdd.x; + float _172 = ConstAdd.y; + float _173 = ConstAdd.z; + float _174 = _167 + _171; + float _175 = _168 + _172; + float _176 = _169 + _173; + float _178 = ColorCorrect.x; + float _179 = ColorCorrect.y; + float _180 = ColorCorrect.z; + float _181 = _178 * 2.00000; + float _182 = _181 * _174; + float _183 = _179 * 2.00000; + float _184 = _183 * _175; + float _185 = _180 * 2.00000; + float _186 = _185 * _176; + float3 colorCorrected = float3(_182, _184, _186); + + // Apply Desaturation - lerp to luminance + float blackAndWhite = dot(colorCorrected, LUMINANCE.xyz); + float3 desaturatedColorHDR = lerp(blackAndWhite, colorCorrected, deSat); + + // Apply Contrast + // done in SDR, causes broken colors on highlights otherwise + float3 desaturatedColorSDR = saturate(renodx::tonemap::dice::BT709(desaturatedColorHDR, 1.0)); + float3 contrastedColor = desaturatedColorSDR - (((desaturatedColorSDR * Contrast) * (desaturatedColorSDR - 1.0)) * (desaturatedColorSDR - 0.5)); + + float3 outputColor = contrastedColor; + +#if 1 // use upgradetonemap() to apply SDR contrast to HDR + float3 upgradedColor = renodx::tonemap::UpgradeToneMap(desaturatedColorHDR, desaturatedColorSDR, outputColor, 1.f); + + // blend vanillaColor back in to fix differences in contrast + float3 vanillaDesaturatedColor = saturate(desaturatedColorHDR); + float3 vanillaContrastedColor = vanillaDesaturatedColor - (((vanillaDesaturatedColor * Contrast) * (vanillaDesaturatedColor - 1.0)) * (vanillaDesaturatedColor - 0.5)); + outputColor = lerp(saturate(vanillaContrastedColor), upgradedColor, saturate(vanillaContrastedColor)); +#endif + + float3 gammaEncodedColor = renodx::color::gamma::Encode(max(0, outputColor), 2.2f); + return float4(gammaEncodedColor, 1.0); +} diff --git a/src/games/rdr1/PSRDR2Postfx_0x4EAF2BC7.ps_6_0.hlsl b/src/games/rdr1/PSRDR2Postfx_0x4EAF2BC7.ps_6_0.hlsl new file mode 100644 index 00000000..f55d5d26 --- /dev/null +++ b/src/games/rdr1/PSRDR2Postfx_0x4EAF2BC7.ps_6_0.hlsl @@ -0,0 +1,182 @@ +#include "./shared.h" +#include "./tonemaphelper.hlsl" + +Texture2D g_textures2D[] : register(t0, space2); + +cbuffer Globals : register(b0, space0) { + float gMotionBlurScalar; + float UsingHDR10; + float HDRPeakNits; + float SDRPaperWhiteNits; + float physicsmaterial; + float4 TexelSize; + float4 BlueShiftColor; + float4 BlueShiftParams; + float ElapsedTime; + float Frames; + float Lambda; + float4 BrightPassValues; + float White; + float IntensityBloom; + float4 brightPassParams; + float3 LUMINANCE; + float deSat; + float4 ConstAdd; + float4 ColorCorrect; + float Contrast; + float4 DofParams; + float3 NearFarClipPlaneQ; + float2 NearFarClipPaneScaleAndBias; + float4x4 gViewProjInverse; + float Gamma; + float LowerLimitAdaption; + float HigherLimitAdaption; + float distortionFreq; + float distortionScale; + float distortionRoll; + float4 SSAOProjectionParams; + float4 SSAOTweakParams; + float4 gScreenSize; + float ParticleHeatShimmerSeed; + int FullResMapSampler; + int FullResMapSamplerSS; + int RenderMapSampler; + int RenderMapSamplerSS; + int RenderMapPointSampler; + int RenderMapPointSamplerSS; + int RenderMapBilinearSampler; + int RenderMapBilinearSamplerSS; + int RenderMapAnisoSampler; + int RenderMapAnisoSamplerSS; + int DepthMapSampler; + int DepthMapSamplerSS; + int ToneMapSampler; + int ToneMapSamplerSS; + int AdaptedLuminanceMapSampler; + int AdaptedLuminanceMapSamplerSS; + int LightGlowTexSampler; + int LightGlowTexSamplerSS; + float AdaptedLuminance; + float2 horzTapOffs[7]; + float2 vertTapOffs[7]; + float4 TexelWeight[16]; + float3 Scale; + float DustOverlayStrength; + float SoftDofFalloffPower; + float SoftDofStrength; + float DofBackendPull; + float TotalTime; + float4 HeatShimmerParams; + float4 ColorScalar; + int DOFHelperSampler; + int DOFHelperSamplerSS; + int ParticleCompositeSampler; + int ParticleCompositeSamplerSS; + int GlowSampler; + int GlowSamplerSS; + int GlowSampler2; + int GlowSampler2SS; + float DisableVignette; + float AdditiveReducer; + float AdditiveReducer2; + float4 GlowColor2; + float4 GlowColor; + float FlareSize; + int DeathSampler; + int DeathSamplerSS; + float DeathMag; + float DeathDrip; + float DeathBlood; + float4 DeathColor; + float3 DeathEffect; + float4 InjuryDirections; + float4 InjuryTimes; + float4x4 WorldViewProjInverse; + float AverageHeight; + float4 LightStreakDirection; + float4 streakWeights; + float4 StreakParams; + float4 DuelColorCorrect; + float4 DuelConstAdd; + float DuelEnemyU; + float DuelEnemyWidth; + float DueldeSat; + float DuelContrast; +}; + +SamplerState g_samplers[] : register(s0, space1); + +// PSRDR2Postfx() +float4 main(float4 SV_Position: SV_POSITION, + float4 TEXCOORD0: TEXCOORD0, + float4 TEXCOORD1: TEXCOORD1, + float4 TEXCOORD2: TEXCOORD2) + : SV_Target { + // Anisotropic Sampler - DoF & Bloom + float4 anisotropicSampler = g_textures2D[RenderMapAnisoSampler].Sample(g_samplers[RenderMapAnisoSamplerSS], TEXCOORD0.xy); + + // Full Res Map Sampler - Scene Texture + float3 fullResMap = g_textures2D[FullResMapSampler].Sample(g_samplers[FullResMapSamplerSS], TEXCOORD0.xy).rgb; + + // Depth of Field (DoF) - Combines DoFMap and fullResMap + float3 DoFMap = g_textures2D[RenderMapBilinearSampler].Sample(g_samplers[RenderMapBilinearSamplerSS], TEXCOORD0.xy).rgb; + float depthMap = g_textures2D[DepthMapSampler].Sample(g_samplers[DepthMapSamplerSS], TEXCOORD0.xy).x; + float nearFarClipPlane = (-(NearFarClipPlaneQ.x * NearFarClipPlaneQ.z)) / (depthMap - NearFarClipPlaneQ.z); + float dofDepthDiff = nearFarClipPlane - DofParams.y; + float dofFocusFactor = saturate(dofDepthDiff * DofParams.x); + bool isBlurred = (nearFarClipPlane < DofParams.z); + float blurBlendFactor = max(isBlurred * dofFocusFactor, saturate(anisotropicSampler.w)); + float3 sceneColor = lerp(fullResMap, DoFMap, blurBlendFactor); + + // Eye Adaptation + Tonemap - Reinhard Extended + float adaptedLuminance = g_textures2D[AdaptedLuminanceMapSampler].Sample(g_samplers[AdaptedLuminanceMapSamplerSS], float2(0.0, 0.0)).x; + float clampedAdaptedLuminance = clamp(adaptedLuminance, LowerLimitAdaption, HigherLimitAdaption); + float scale = (BrightPassValues.z / (clampedAdaptedLuminance + 0.001)); + float3 color_scaled = sceneColor * scale; + float3 color_scaled_over_white_plus_one = (color_scaled / White) + 1; + float3 tonemappedColor = (color_scaled_over_white_plus_one * color_scaled) / (color_scaled + 1); + +#if 1 // blended reinhard with untonemapped + float3 vanillaColor = tonemappedColor; + + float midGrayScale = RDR1ReinhardMidgrayScale(White); + float3 untonemapped_scaled = color_scaled * midGrayScale; + + float3 blendedColor = lerp(vanillaColor, lerp(vanillaColor, untonemapped_scaled, 0.5), saturate(vanillaColor)); + + tonemappedColor = blendedColor; +#endif + + // Apply Bloom + float3 bloom = anisotropicSampler.rgb * anisotropicSampler.rgb; + float3 scaledBloom = IntensityBloom * bloom; + float3 bloomedColor = tonemappedColor + scaledBloom; + + // Apply Color Correction + float3 colorCorrected = (ColorCorrect.rgb * 2.0) * (bloomedColor + ConstAdd.xyz); + + // Apply Desaturation - lerp to luminance + float blackAndWhite = dot(colorCorrected, LUMINANCE.xyz); + float3 desaturatedColorHDR = lerp(blackAndWhite, colorCorrected, deSat); + + // Apply Contrast + // done in SDR, causes broken colors on highlights otherwise + float3 desaturatedColorSDR = saturate(renodx::tonemap::dice::BT709(desaturatedColorHDR, 1.0)); + float3 contrastedColor = desaturatedColorSDR - (((desaturatedColorSDR * Contrast) * (desaturatedColorSDR - 1.0)) * (desaturatedColorSDR - 0.5)); + + float3 outputColor = contrastedColor; + +#if 1 // use upgradetonemap() to apply SDR contrast to HDR + float3 upgradedColor = renodx::tonemap::UpgradeToneMap(desaturatedColorHDR, desaturatedColorSDR, outputColor, 1.f); + + // blend vanillaColor back in to fix differences in contrast + float3 vanillaDesaturatedColor = saturate(desaturatedColorHDR); + float3 vanillaContrastedColor = vanillaDesaturatedColor - (((vanillaDesaturatedColor * Contrast) * (vanillaDesaturatedColor - 1.0)) * (vanillaDesaturatedColor - 0.5)); + outputColor = lerp(saturate(vanillaContrastedColor), upgradedColor, saturate(vanillaContrastedColor)); +#endif + + // allowing negatives adds no wcg while causing artifacts in pause menu + float3 gammaEncodedColor = renodx::color::gamma::Encode(max(0, outputColor), 2.2f); + + return float4(gammaEncodedColor, 1.0); +} diff --git a/src/games/rdr1/addon.cpp b/src/games/rdr1/addon.cpp new file mode 100644 index 00000000..c42c6b12 --- /dev/null +++ b/src/games/rdr1/addon.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2024 Musa Haji + * Copyright (C) 2024 Carlos Lopez + * SPDX-License-Identifier: MIT + */ + +#include // PostFX +#include // PostFX - Optics + +#include // PostFX - Aiming +#include // PostFX - Aiming + Optics + +#include // PostFX - Cutscene DoF + Optics +#include // PostFX - Cutscene DoF + +#include // Mini Eye Adaptation + +#include // PQ Encoding + +#include +#include "../../mods/shader.hpp" + +namespace { + +renodx::mods::shader::CustomShaders custom_shaders = { + CustomShaderEntry(0x4EAF2BC7), // PostFX + CustomShaderEntry(0xEEEE53C5), // PostFX - Optics + + CustomShaderEntry(0xCCC43328), // PostFX - Aiming + CustomShaderEntry(0xE93AD74D), // PostFX - Aiming + Optics + + CustomShaderEntry(0x9761FB07), // PostFX - Cutscene DoF + CustomShaderEntry(0x632ABCB2), // PostFX - Cutscene DoF + Optics + + CustomShaderEntry(0xE033AAAD), // Mini Eye Adaptation + + CustomShaderEntry(0x56F79BAD), // PQ Encoding +}; + +} // namespace + +// NOLINTBEGIN(readability-identifier-naming) + +extern "C" __declspec(dllexport) const char* NAME = "RenoDX"; +extern "C" __declspec(dllexport) const char* DESCRIPTION = "RenoDX for Red Dead Redemption"; + +// NOLINTEND(readability-identifier-naming) + +BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) { + switch (fdw_reason) { + case DLL_PROCESS_ATTACH: + if (!reshade::register_addon(h_module)) return FALSE; + + break; + case DLL_PROCESS_DETACH: + reshade::unregister_addon(h_module); + break; + } + + renodx::mods::shader::Use(fdw_reason, custom_shaders); + + return TRUE; +} \ No newline at end of file diff --git a/src/games/rdr1/shared.h b/src/games/rdr1/shared.h new file mode 100644 index 00000000..ca02d359 --- /dev/null +++ b/src/games/rdr1/shared.h @@ -0,0 +1,8 @@ +#ifndef SRC_RDR1_SHARED_H_ +#define SRC_RDR1_SHARED_H_ + +#ifndef __cplusplus +#include "../../shaders/renodx.hlsl" +#endif + +#endif // SRC_RDR1_SHARED_H_ \ No newline at end of file diff --git a/src/games/rdr1/tonemaphelper.hlsl b/src/games/rdr1/tonemaphelper.hlsl new file mode 100644 index 00000000..e1bcffe3 --- /dev/null +++ b/src/games/rdr1/tonemaphelper.hlsl @@ -0,0 +1,43 @@ +/// Inverse of the Reinhard tonemapping function used in RDR1. +/// +/// Reconstructs the original linear HDR value from its Extended Reinhard +/// tone-mapped result. +/// Uses the positive root for a valid HDR value. +/// +/// @param x - The tone-mapped value. +/// @param whitePoint - The white point scaling factor. +/// @return The original linear HDR value. +float RDR1ReinardInverse(float x, float whitePoint) { + // Calculate the two roots of the inverse + float term1 = 0.5 * (whitePoint * x - whitePoint); + float term2 = 0.5 * sqrt(whitePoint) * sqrt((whitePoint * x * x) - (2.0 * whitePoint * x) + whitePoint + 4.0 * x); + + // Use the positive root, as it's the physically meaningful solution + return term1 + term2; +} + +/// Computes the mid-gray point for the Reinhard tonemapping function. +/// +/// This function calculates the linear HDR input value that corresponds to the +/// standard scene referred mid-gray (18%) in the Reinhard tone-mapped space. +/// This value is crucial for aligning the mid-gray points of untonemapped and +/// Reinhard-tonemapped images during blending. +/// +/// @param whitePoint - The white point scaling factor used in the tonemapping. +/// @return The linear HDR mid-gray value. +float RDR1ReinhardMidgray(float whitePoint) { + return RDR1ReinardInverse(0.18, whitePoint); +} + +/// Computes the scale factor for aligning mid-gray levels in RDR1. +/// +/// This function returns a scaling factor to map the untonemapped image's scene referred +/// mid-gray to align with the Reinhard tone-mapped's scene referred mid-gray. +/// This ensures that the blended result retains the original game's visual art direction +/// while enabling HDR highlights. +/// +/// @param whitePoint - The white point scaling factor used in the tonemapping. +/// @return The scale factor for aligning mid-gray levels. +float RDR1ReinhardMidgrayScale(float whitePoint) { + return RDR1ReinhardMidgray(whitePoint) / 0.18; +}