Skip to content

Commit

Permalink
Merge pull request #38 from jeanluciano/Imagespace
Browse files Browse the repository at this point in the history
Imagespace
  • Loading branch information
doodlum authored Aug 2, 2023
2 parents b6ec9be + 6d04a1c commit 9a78102
Show file tree
Hide file tree
Showing 30 changed files with 2,081 additions and 15 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.hlsl"

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
68 changes: 68 additions & 0 deletions package/Shaders/ISBLensFlare.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsl"

typedef VS_OUTPUT PS_INPUT;

struct PS_OUTPUT
{
float4 Color : SV_Target0;
};

#if defined(PSHADER)
SamplerState DownScaledBlurredHDRSampler : register(s0);
SamplerState RampsSampler : register(s1);
SamplerState MasksSampler : register(s2);

Texture2D<float4> DownScaledBlurredHDRTex : register(t0);
Texture2D<float4> RampsTex : register(t1);
Texture2D<float4> MasksTex : register(t2);

cbuffer PerGeometry : register(b2)
{
float lensCount : packoffset(c0.x);
float flareDispersal : packoffset(c0.y);
float lightsRangeDownshift : packoffset(c0.z);
float invLightsRangeDownshift : packoffset(c0.w);
float lateralRepeat : packoffset(c1.x);
float channelsDistortionRed : packoffset(c1.y);
float channelsDistortionGreen : packoffset(c1.z);
float channelsDistortionBlue : packoffset(c1.w);
float texelOffsetX : packoffset(c2.x);
float texelOffsetY : packoffset(c2.y);
float haloFetch : packoffset(c2.z);
float haloWidthPow : packoffset(c2.w);
float dynamicSource : packoffset(c3.x);
float globalIntensity : packoffset(c3.y);
};

float4 GetSampleColor(float2 texCoord)
{
float4 color = DownScaledBlurredHDRTex.Sample(DownScaledBlurredHDRSampler, texCoord);
if (saturate(color.x - lightsRangeDownshift) + saturate(color.y - lightsRangeDownshift) +
saturate(color.z - lightsRangeDownshift) <=
0) {
return 0;
}
return saturate(color);
}

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

float4 lensColor = 0;
for (int sampleIndex = -asint(lateralRepeat); sampleIndex <= asint(lateralRepeat); ++sampleIndex) {
float4 sampleColor;
if (dynamicSource > 0.5) {
sampleColor = GetSampleColor(GetDynamicResolutionAdjustedScreenPosition(
input.TexCoord + float2(texelOffsetX * sampleIndex, 0)));
} else {
sampleColor = GetSampleColor(input.TexCoord + float2(texelOffsetX * sampleIndex, 0));
}
lensColor += sampleColor;
}
psout.Color = globalIntensity * lensColor;

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.hlsl"
#include "Common/DummyVSTexCoord.hlsl"
#include "Common/FrameBuffer.hlsl"

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.hlsl"

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.hlsl"

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
Loading

0 comments on commit 9a78102

Please sign in to comment.