Skip to content

Commit

Permalink
style: 🎨 apply clang-format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanluciano authored and github-actions[bot] committed Aug 1, 2023
1 parent 94ccd9f commit 6d04a1c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 121 deletions.
90 changes: 40 additions & 50 deletions package/Shaders/ISDepthOfField.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState ImageSampler : register(s0);
SamplerState BlurredSampler : register(s1);
SamplerState DepthSampler : register(s2);
SamplerState AvgDepthSampler : register(s3);
SamplerState MaskSampler : register(s4);

Texture2D<float4> ImageTex : register(t0);
Texture2D<float4> BlurredTex : register(t1);
Texture2D<float4> DepthTex : register(t2);
Texture2D<float4> AvgDepthTex : register(t3);
Texture2D<float4> MaskTex : register(t4);

cbuffer PerGeometry : register(b2)
SamplerState ImageSampler : register(s0);
SamplerState BlurredSampler : register(s1);
SamplerState DepthSampler : register(s2);
SamplerState AvgDepthSampler : register(s3);
SamplerState MaskSampler : register(s4);

Texture2D<float4> ImageTex : register(t0);
Texture2D<float4> BlurredTex : register(t1);
Texture2D<float4> DepthTex : register(t2);
Texture2D<float4> AvgDepthTex : register(t3);
Texture2D<float4> MaskTex : register(t4);

cbuffer PerGeometry : register(b2)
{
float4 invScreenRes : packoffset(c0); // inverse render target width and height in xy
float4 params : packoffset(c1); // DOF near range in x, far range in y
float4 params2 : packoffset(c2); // DOF near blur in x, far blur in w
float4 params3 : packoffset(c3); // 1 / (far - near) in z, near / (far - near) in w
float4 params4 : packoffset(c4);
float4 params5 : packoffset(c5);
float4 params6 : packoffset(c6);
float4 params7 : packoffset(c7);
float4 invScreenRes : packoffset(c0); // inverse render target width and height in xy
float4 params : packoffset(c1); // DOF near range in x, far range in y
float4 params2 : packoffset(c2); // DOF near blur in x, far blur in w
float4 params3 : packoffset(c3); // 1 / (far - near) in z, near / (far - near) in w
float4 params4 : packoffset(c4);
float4 params5 : packoffset(c5);
float4 params6 : packoffset(c6);
float4 params7 : packoffset(c7);
};

void CheckOffsetDepth(float2 center, float2 offset, inout float crossSection,
Expand All @@ -42,8 +42,7 @@ void CheckOffsetDepth(float2 center, float2 offset, inout float crossSection,
.x;

float crossSectionDelta = 0;
if (depth > 0.999998987)
{
if (depth > 0.999998987) {
crossSectionDelta = (1. / 9.);
}
crossSection += crossSectionDelta;
Expand All @@ -67,32 +66,30 @@ PS_OUTPUT main(PS_INPUT input)
float mask = 1;
float4 dofParams = params;
float4 dofParams2 = params2;
#if defined(MASKED)
# if defined(MASKED)
mask = MaskTex.Sample(MaskSampler, adjustedTexCoord).x;
dofParams = lerp(params, params6, mask);
dofParams2 = lerp(params2, params7, mask);
#endif
# endif

float2 dofBlurRange = float2(dofParams2.x, dofParams.x);
float focusDistance = dofParams.y;

#if !defined(MASKED)
if (params3.z > 0)
{

# if !defined(MASKED)
if (params3.z > 0) {
focusDistance = AvgDepthTex.Sample(AvgDepthSampler, 0).x;
float depthFactor = saturate(focusDistance * params3.z - params3.w);
dofBlurRange = lerp(float2(params2.x, params.x), float2(params2.w, params.y), depthFactor);
}
#endif
# endif

float depthCC =
DepthTex.Sample(DepthSampler, GetDynamicResolutionAdjustedScreenPosition(input.TexCoord)).x;

float crossSection = 0;
float avgDepth = depthCC;
bool isTooDeep = false;
if (dofParams2.w != 0 && depthCC > 0.999998987)
{
if (dofParams2.w != 0 && depthCC > 0.999998987) {
crossSection = 1. / 9.;
float totalDepth = depthCC;
CheckOffsetDepth(input.TexCoord, float2(-3, -3), crossSection, totalDepth);
Expand All @@ -110,45 +107,38 @@ PS_OUTPUT main(PS_INPUT input)

float blurFactor = 0;
float finalDepth = avgDepth;
if (!isTooDeep && avgDepth > 1e-5)
{
if (!isTooDeep && avgDepth > 1e-5) {
float depth, near, far;
if (avgDepth <= 0.01)
{
if (avgDepth <= 0.01) {
depth = 100 * avgDepth;
near = params3.x;
far = params3.y;
}
else
{
} else {
depth = 1.01 * avgDepth - 0.01;
near = dofParams.z;
far = dofParams.w;
}
finalDepth = GetFinalDepth(depth, near, far);

float dofStrength = 0;
#if defined(DISTANT_BLUR)
# if defined(DISTANT_BLUR)
dofStrength = (finalDepth - focusDistance) / dofBlurRange.y;
#elif defined(DOF)
if ((focusDistance > finalDepth || mask == 0) && dofParams2.y != 0)
{
# elif defined(DOF)
if ((focusDistance > finalDepth || mask == 0) && dofParams2.y != 0) {
dofStrength = (focusDistance - finalDepth) / dofBlurRange.y;
}
else if (finalDepth > focusDistance && dofParams2.z != 0)
{
} else if (finalDepth > focusDistance && dofParams2.z != 0) {
dofStrength = (finalDepth - focusDistance) / dofBlurRange.y;
}
#endif
# endif

blurFactor = saturate(dofStrength) * (dofBlurRange.x * (1 - 0.5 * crossSection));
}

float3 finalColor = lerp(imageColor, blurColor, blurFactor);
#if defined(FOGGED)
# if defined(FOGGED)
float fogFactor = (params4.w * saturate((finalDepth - params5.y) / (params5.x - params5.y))) * mask;
finalColor = lerp(finalColor, params4.xyz, fogFactor);
#endif
# endif

psout.Color = float4(finalColor, 1);

Expand Down
97 changes: 43 additions & 54 deletions package/Shaders/ISHDR.hlsl
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/Color.hlsl"
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsl"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState ImageSampler : register(s0);
#if defined(DOWNSAMPLE)
SamplerState AdaptSampler : register(s1);
#elif defined(TONEMAP)
SamplerState BlendSampler : register(s1);
#endif
SamplerState AvgSampler : register(s2);
SamplerState ImageSampler : register(s0);
# if defined(DOWNSAMPLE)
SamplerState AdaptSampler : register(s1);
# elif defined(TONEMAP)
SamplerState BlendSampler : register(s1);
# endif
SamplerState AvgSampler : register(s2);

Texture2D<float4> ImageTex : register(t0);
#if defined(DOWNSAMPLE)
Texture2D<float4> AdaptTex : register(t1);
#elif defined(TONEMAP)
Texture2D<float4> BlendTex : register(t1);
#endif
Texture2D<float4> AvgTex : register(t2);
Texture2D<float4> ImageTex : register(t0);
# if defined(DOWNSAMPLE)
Texture2D<float4> AdaptTex : register(t1);
# elif defined(TONEMAP)
Texture2D<float4> BlendTex : register(t1);
# endif
Texture2D<float4> AvgTex : register(t2);

cbuffer PerGeometry : register(b2)
cbuffer PerGeometry : register(b2)
{
float4 Flags : packoffset(c0);
float4 TimingData : packoffset(c1);
float4 Param : packoffset(c2);
float4 Cinematic : packoffset(c3);
float4 Tint : packoffset(c4);
float4 Fade : packoffset(c5);
float4 BlurScale : packoffset(c6);
float4 BlurOffsets[16] : packoffset(c7);
float4 Flags : packoffset(c0);
float4 TimingData : packoffset(c1);
float4 Param : packoffset(c2);
float4 Cinematic : packoffset(c3);
float4 Tint : packoffset(c4);
float4 Fade : packoffset(c5);
float4 BlurScale : packoffset(c6);
float4 BlurOffsets[16] : packoffset(c7);
};

float GetTonemapFactorReinhard(float luminance)
Expand All @@ -54,62 +54,51 @@ PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

#if defined(DOWNSAMPLE)
# if defined(DOWNSAMPLE)
float3 downsampledColor = 0;
for (int sampleIndex = 0; sampleIndex < SAMPLES_COUNT; ++sampleIndex)
{
for (int sampleIndex = 0; sampleIndex < SAMPLES_COUNT; ++sampleIndex) {
float2 texCoord = BlurOffsets[sampleIndex].xy * BlurScale.xy + input.TexCoord;
if (Flags.x > 0.5)
{
if (Flags.x > 0.5) {
texCoord = GetDynamicResolutionAdjustedScreenPosition(texCoord);
}
float3 imageColor = ImageTex.Sample(ImageSampler, texCoord).xyz;
#if defined(LUM)
# if defined(LUM)
imageColor = imageColor.x;
#elif defined(RGB2LUM)
# elif defined(RGB2LUM)
imageColor = RGBToLuminance(imageColor);
#endif
# endif
downsampledColor += imageColor * BlurOffsets[sampleIndex].z;
}
#if defined(LIGHT_ADAPT)
# if defined(LIGHT_ADAPT)
float2 adaptValue = AdaptTex.Sample(AdaptSampler, input.TexCoord).xy;
if (isnan(downsampledColor.x) || isnan(downsampledColor.y) || isnan(downsampledColor.z))
{
if (isnan(downsampledColor.x) || isnan(downsampledColor.y) || isnan(downsampledColor.z)) {
downsampledColor.xy = adaptValue;
}
else
{
} else {
float2 adaptDelta = downsampledColor.xy - adaptValue;
downsampledColor.xy =
sign(adaptDelta) * clamp(abs(Param.wz * adaptDelta), 0.00390625, abs(adaptDelta)) +
adaptValue;
}
#endif
# endif
psout.Color = float4(downsampledColor, BlurScale.z);

#elif defined(TONEMAP)
# elif defined(TONEMAP)
float2 adjustedTexCoord = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord);
float3 blendColor = BlendTex.Sample(BlendSampler, adjustedTexCoord).xyz;
float3 imageColor = 0;
if (Flags.x > 0.5)
{
if (Flags.x > 0.5) {
imageColor = ImageTex.Sample(ImageSampler, adjustedTexCoord).xyz;
}
else
{
} else {
imageColor = ImageTex.Sample(ImageSampler, input.TexCoord).xyz;
}
float2 avgValue = AvgTex.Sample(AvgSampler, input.TexCoord).xy;

float luminance = max(1e-5, RGBToLuminance(blendColor));
float exposureAdjustedLuminance = (avgValue.y / avgValue.x) * luminance;
float blendFactor;
if (Param.z > 0.5)
{
if (Param.z > 0.5) {
blendFactor = GetTonemapFactorHejlBurgessDawson(exposureAdjustedLuminance);
}
else
{
} else {
blendFactor = GetTonemapFactorReinhard(exposureAdjustedLuminance);
}

Expand All @@ -122,12 +111,12 @@ PS_OUTPUT main(PS_INPUT input)
blendedLuminance * Tint, Tint.w),
Cinematic.z);
float4 srgbColor = float4(ToSRGBColor(saturate(linearColor.xyz)), linearColor.w);
#if defined (FADE)
# if defined(FADE)
srgbColor = lerp(srgbColor, Fade, Fade.w);
#endif
# endif
psout.Color = srgbColor;

#endif
# endif

return psout;
}
Expand Down
21 changes: 9 additions & 12 deletions package/Shaders/ISRefraction.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState Src0Sampler : register(s0);
SamplerState Src1Sampler : register(s1);
SamplerState Src0Sampler : register(s0);
SamplerState Src1Sampler : register(s1);

Texture2D<float4> Src0Tex : register(t0);
Texture2D<float4> Src1Tex : register(t1);
Texture2D<float4> Src0Tex : register(t0);
Texture2D<float4> Src1Tex : register(t1);

cbuffer PerGeometry : register(b2)
cbuffer PerGeometry : register(b2)
{
float4 Tint : packoffset(c0);
float4 Tint : packoffset(c0);
};

PS_OUTPUT main(PS_INPUT input)
Expand All @@ -41,13 +41,10 @@ PS_OUTPUT main(PS_INPUT input)
float4 src01 = Src0Tex.Sample(Src0Sampler, adjustedTexCoord1);
float4 src0 = unk1 != 0 ? src01 : src00;

if (src1.w > 0.8 && src1.w < 1)
{
if (src1.w > 0.8 && src1.w < 1) {
psout.Color.xyz =
(1 - Tint.w) * src0.xyz + Tint.xyz * (Tint.w * RGBToLuminance2(src01.xyz));
}
else
{
} else {
psout.Color.xyz = src0.xyz;
}

Expand Down
8 changes: 4 additions & 4 deletions src/ShaderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ namespace SIE
std::array<int8_t, MaxOffsetsSize>& constantOffsets,
uint64_t& vertexDesc,
ShaderClass shaderClass, const RE::BSShader& shader, uint32_t descriptor)
{
{
RE::BSShader::Type shaderType = shader.shaderType.get();
D3D11_SHADER_DESC desc;
if (FAILED(reflector.GetDesc(&desc))) {
Expand Down Expand Up @@ -1223,8 +1223,8 @@ namespace SIE
{
const auto type = shader.shaderType.get();
const auto name = shader.shaderType == RE::BSShader::Type::ImageSpace ?
std::string_view(static_cast<const RE::BSImagespaceShader&>(shader).originalShaderName.c_str()) :
shader.fxpFilename;
std::string_view(static_cast<const RE::BSImagespaceShader&>(shader).originalShaderName.c_str()) :
shader.fxpFilename;
const std::wstring path = GetShaderPath(name);

std::array<D3D_SHADER_MACRO, 64> defines;
Expand Down Expand Up @@ -1328,7 +1328,7 @@ namespace SIE

std::unique_ptr<RE::BSGraphics::VertexShader> CreateVertexShader(ID3DBlob& shaderData,
const RE::BSShader& shader, uint32_t descriptor)
{
{
auto type = shader.shaderType.get();
static const auto device = REL::Relocation<ID3D11Device**>(RE::Offset::D3D11Device);
static const auto perTechniqueBuffersArray =
Expand Down
Loading

0 comments on commit 6d04a1c

Please sign in to comment.