Skip to content

Commit

Permalink
feat: imagespace shaders support. (#359)
Browse files Browse the repository at this point in the history
* feat: imagespace shaders support.

* style: 🎨 apply clang-format changes

* chore: includes update.

* fix: removed test code erroneously disabling all imagespace shaders except ISHDR.

* fix: fixed ISSAOMinify compilation.

* fix: fixed supported imagespace shaders selection.

* style: 🎨 apply clang-format changes

* feat: ISSAOComposite shader added,

* style: 🎨 apply clang-format changes

* feat: ISSAOCameraZ added.

* style: 🎨 apply clang-format changes

* feat: ISSILComposite shader added.

* style: 🎨 apply clang-format changes

* feat: ISSnowSSS shader added.

* style: 🎨 apply clang-format changes

* feat: ISSAOBlur shader added.

* style: 🎨 apply clang-format changes

* chore: clib reset to dev.

---------

Co-authored-by: Ilya Perapechka <i_perapechka@wargaming.net>
Co-authored-by: Jonahex <Jonahex@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 4, 2024
1 parent 1cbcc82 commit 7e71792
Show file tree
Hide file tree
Showing 34 changed files with 2,602 additions and 28 deletions.
83 changes: 83 additions & 0 deletions package/Shaders/ISAlphaBlend.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "Common/DummyVSTexCoord.hlsl"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState TintMask0Sampler : register(s0);
SamplerState TintMask1Sampler : register(s1);
SamplerState TintMask2Sampler : register(s2);
SamplerState TintMask3Sampler : register(s3);
SamplerState TintMask4Sampler : register(s4);
SamplerState TintMask5Sampler : register(s5);
SamplerState TintMask6Sampler : register(s6);
SamplerState TintMask7Sampler : register(s7);
SamplerState TintMask8Sampler : register(s8);
SamplerState TintMask9Sampler : register(s9);
SamplerState TintMask10Sampler : register(s10);
SamplerState TintMask11Sampler : register(s11);
SamplerState TintMask12Sampler : register(s12);
SamplerState TintMask13Sampler : register(s13);
SamplerState TintMask14Sampler : register(s14);
SamplerState TintMask15Sampler : register(s15);

Texture2D<float4> TintMask0Tex : register(t0);
Texture2D<float4> TintMask1Tex : register(t1);
Texture2D<float4> TintMask2Tex : register(t2);
Texture2D<float4> TintMask3Tex : register(t3);
Texture2D<float4> TintMask4Tex : register(t4);
Texture2D<float4> TintMask5Tex : register(t5);
Texture2D<float4> TintMask6Tex : register(t6);
Texture2D<float4> TintMask7Tex : register(t7);
Texture2D<float4> TintMask8Tex : register(t8);
Texture2D<float4> TintMask9Tex : register(t9);
Texture2D<float4> TintMask10Tex : register(t10);
Texture2D<float4> TintMask11Tex : register(t11);
Texture2D<float4> TintMask12Tex : register(t12);
Texture2D<float4> TintMask13Tex : register(t13);
Texture2D<float4> TintMask14Tex : register(t14);
Texture2D<float4> TintMask15Tex : register(t15);

cbuffer PerGeometry : register(b2)
{
float4 Color[16] : packoffset(c0);
};

float3 BlendAlpha(Texture2D<float4> tintMaskTex, SamplerState tintMaskSamplerState, float2 texCoord, float4 blendColor, float3 color)
{
float tintMask = tintMaskTex.Sample(tintMaskSamplerState, texCoord).x;
return blendColor.xyz * (1 - tintMask * blendColor.w) + (blendColor.w * tintMask) * color;
}

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

float3 color = 0.5.xxx;

color = BlendAlpha(TintMask0Tex, TintMask0Sampler, input.TexCoord, Color[0], color);
color = BlendAlpha(TintMask1Tex, TintMask1Sampler, input.TexCoord, Color[1], color);
color = BlendAlpha(TintMask2Tex, TintMask2Sampler, input.TexCoord, Color[2], color);
color = BlendAlpha(TintMask3Tex, TintMask3Sampler, input.TexCoord, Color[3], color);
color = BlendAlpha(TintMask4Tex, TintMask4Sampler, input.TexCoord, Color[4], color);
color = BlendAlpha(TintMask5Tex, TintMask5Sampler, input.TexCoord, Color[5], color);
color = BlendAlpha(TintMask6Tex, TintMask6Sampler, input.TexCoord, Color[6], color);
color = BlendAlpha(TintMask7Tex, TintMask7Sampler, input.TexCoord, Color[7], color);
color = BlendAlpha(TintMask8Tex, TintMask8Sampler, input.TexCoord, Color[8], color);
color = BlendAlpha(TintMask9Tex, TintMask9Sampler, input.TexCoord, Color[9], color);
color = BlendAlpha(TintMask10Tex, TintMask10Sampler, input.TexCoord, Color[10], color);
color = BlendAlpha(TintMask11Tex, TintMask11Sampler, input.TexCoord, Color[11], color);
color = BlendAlpha(TintMask12Tex, TintMask12Sampler, input.TexCoord, Color[12], color);
color = BlendAlpha(TintMask13Tex, TintMask13Sampler, input.TexCoord, Color[13], color);
color = BlendAlpha(TintMask14Tex, TintMask14Sampler, input.TexCoord, Color[14], color);
color = BlendAlpha(TintMask15Tex, TintMask15Sampler, input.TexCoord, Color[15], color);

psout.Color = float4(color, 1);

return psout;
}
#endif
45 changes: 45 additions & 0 deletions package/Shaders/ISApplyReflections.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsli"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float3 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState SSRSourceSampler : register(s0);
SamplerState WaterMaskSampler : register(s1);
SamplerState MainBufferSampler : register(s2);

Texture2D<float4> SSRSourceTex : register(t0);
Texture2D<float4> WaterMaskTex : register(t1);
Texture2D<float4> MainBufferTex : register(t2);

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

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

float2 adjustedScreenPosition = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord.xy);

float2 waterMask = WaterMaskTex.SampleLevel(WaterMaskSampler, adjustedScreenPosition, 0).zw;
float3 mainColor = MainBufferTex.Sample(MainBufferSampler, adjustedScreenPosition).xyz;

float3 colorOffset = 0.0.xxx;
if (waterMask.x >= 1e-5 && waterMask.y > 1e-5) {
float4 ssrSourceColor = SSRSourceTex.Sample(SSRSourceSampler, adjustedScreenPosition);
colorOffset = clamp(SSRParams.x * (ssrSourceColor.xyz * ssrSourceColor.w),
0, SSRParams.y * mainColor);
}

psout.Color = colorOffset + mainColor;

return psout;
}
#endif
24 changes: 24 additions & 0 deletions package/Shaders/ISBasicCopy.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "Common/DummyVSTexCoord.hlsl"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState SourceSampler : register(s0);

Texture2D<float4> SourceTex : register(t0);

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

float4 srcColor = SourceTex.Sample(SourceSampler, input.TexCoord);
psout.Color = srcColor;

return psout;
}
#endif
63 changes: 63 additions & 0 deletions package/Shaders/ISBlur.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "Common/Color.hlsli"
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsli"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState ImageSampler : register(s0);
SamplerState AvgLumSampler : register(s1);

Texture2D<float4> ImageTex : register(t0);
Texture2D<float4> AvgLumTex : register(t1);

cbuffer PerGeometry : register(b2)
{
float4 BlurBrightPass : packoffset(c0);
float4 BlurScale : packoffset(c1);
float BlurRadius : packoffset(c2);
float4 BlurOffsets[16] : packoffset(c3);
};

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

float4 color = 0.0.xxxx;

float blurRadius = BLUR_RADIUS;
float2 blurScale = BlurScale.zw;
# if BLUR_RADIUS == 0
blurRadius = BlurRadius;
# endif
# if BLUR_RADIUS == 0 || defined(BLUR_NON_HDR)
blurScale = 1.0.xx;
# endif

for (int blurIndex = 0; blurIndex < blurRadius; ++blurIndex) {
float2 screenPosition = BlurOffsets[blurIndex].xy + input.TexCoord.xy;
if (BlurScale.x < 0.5) {
screenPosition = GetDynamicResolutionAdjustedScreenPosition(screenPosition);
}
float4 imageColor = ImageTex.Sample(ImageSampler, screenPosition) * float4(blurScale.yyy, 1);
# if defined(BLUR_BRIGHT_PASS)
imageColor = BlurBrightPass.y * max(0.0.xxxx, -BlurBrightPass.x + imageColor);
# endif
color += imageColor * BlurOffsets[blurIndex].z;
}

# if defined(BLUR_BRIGHT_PASS)
float avgLum = RGBToLuminance(AvgLumTex.Sample(AvgLumSampler, input.TexCoord.xy).xyz);
color.w = avgLum;
# endif

psout.Color = color * float4(blurScale.xxx, 1);

return psout;
}
#endif
44 changes: 44 additions & 0 deletions package/Shaders/ISCompositeLensFlareVolumetricLighting.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsli"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float3 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState VLSourceSampler : register(s0);
SamplerState LFSourceSampler : register(s1);

Texture2D<float4> VLSourceTex : register(t0);
Texture2D<float4> LFSourceTex : register(t1);

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

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

float3 color = 0.0.xxx;

# if defined(VOLUMETRIC_LIGHTING)
float2 screenPosition = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord);
float volumetricLightingPower = VLSourceTex.Sample(VLSourceSampler, screenPosition).x;
color += VolumetricLightingColor.xyz * volumetricLightingPower;
# endif

# if defined(LENS_FLARE)
float3 lensFlareColor = LFSourceTex.Sample(LFSourceSampler, input.TexCoord).xyz;
color += lensFlareColor;
# endif

psout.Color = color;

return psout;
}
#endif
45 changes: 45 additions & 0 deletions package/Shaders/ISCopy.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsli"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState ImageSampler : register(s0);

Texture2D<float4> ImageTex : register(t0);

cbuffer PerGeometry : register(b2)
{
float4 RotationMatrix : packoffset(c0);
float4 ColorSelect : packoffset(c1);
float4 ScaleBias : packoffset(c2);
};

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

# if !defined(DYNAMIC_FETCH_DISABLED)
float2 screenPosition = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord);
# else
float2 screenPosition = input.TexCoord;
# endif

float4 color = ImageTex.Sample(ImageSampler, screenPosition);

# if defined(GRAY_SCALE)
color = float4(dot(color, ColorSelect).xxx, color.w);
# elif defined(TEXTURE_MASK)
color.w = 1 - color.x;
# endif

psout.Color = color;

return psout;
}
#endif
28 changes: 28 additions & 0 deletions package/Shaders/ISDebugSnow.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "Common/DummyVSTexCoord.hlsl"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState snowAlphaSpecSampler : register(s0);
SamplerState sceneSampler : register(s1);

Texture2D<float4> snowAlphaSpecTex : register(t0);
Texture2D<float4> sceneTex : register(t1);

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

float snowAlphaSpec = snowAlphaSpecTex.Sample(snowAlphaSpecSampler, input.TexCoord).y;
float4 sceneColor = sceneTex.Sample(sceneSampler, input.TexCoord);

psout.Color = sceneColor + float4(snowAlphaSpec, 0, 0, 1);

return psout;
}
#endif
Loading

0 comments on commit 7e71792

Please sign in to comment.