Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: switched to using in-game imagespace shader defines. #409

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions package/Shaders/ISBlur.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,45 @@ cbuffer PerGeometry : register(b2)
float4 BlurOffsets[16] : packoffset(c3);
};

float4 GetImageColor(float2 texCoord, float blurScale)
{
return ImageTex.Sample(ImageSampler, texCoord) * float4(blurScale.xxx, 1);
}

PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

float4 color = 0.0.xxxx;
float4 color = 0;

float blurRadius = BLUR_RADIUS;
float2 blurScale = BlurScale.zw;
# if BLUR_RADIUS == 0
blurRadius = BlurRadius;
# if defined(TEXTAP)
int blurRadius = TEXTAP;
# else
uint blurRadius = asuint(BlurRadius);
# endif
# if BLUR_RADIUS == 0 || defined(BLUR_NON_HDR)
blurScale = 1.0.xx;
float2 blurScale = BlurScale.zw;
# if !defined(TEXTAP) || !defined(COLORRANGE)
blurScale = 1;
# 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 = 0;
[branch] if (BlurScale.x < 0.5)
{
imageColor = GetImageColor(GetDynamicResolutionAdjustedScreenPosition(screenPosition), blurScale.y);
}
else
{
imageColor = GetImageColor(screenPosition, blurScale.y);
}
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);
# if defined(BRIGHTPASS)
imageColor = BlurBrightPass.y * max(0, -BlurBrightPass.x + imageColor);
# endif
color += imageColor * BlurOffsets[blurIndex].z;
}

# if defined(BLUR_BRIGHT_PASS)
# if defined(BRIGHTPASS)
float avgLum = RGBToLuminance(AvgLumTex.Sample(AvgLumSampler, input.TexCoord.xy).xyz);
color.w = avgLum;
# endif
Expand Down
6 changes: 3 additions & 3 deletions package/Shaders/ISCopy.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ PS_OUTPUT main(PS_INPUT input)
{
PS_OUTPUT psout;

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions package/Shaders/ISDepthOfField.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ PS_OUTPUT main(PS_INPUT input)
finalDepth = GetFinalDepth(depth, near, far);

float dofStrength = 0;
# if defined(DISTANT_BLUR)
# if defined(DISTANT)
dofStrength = (finalDepth - focusDistance) / dofBlurRange.y;
# elif defined(DOF)
# else
if ((focusDistance > finalDepth || mask == 0) && dofParams2.y != 0) {
dofStrength = (focusDistance - finalDepth) / dofBlurRange.y;
} else if (finalDepth > focusDistance && dofParams2.z != 0) {
Expand Down
6 changes: 3 additions & 3 deletions package/Shaders/ISDownsample.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ PS_OUTPUT main(PS_INPUT input)
float luminance = 0;
for (uint sampleIndex = 0; sampleIndex < asuint(SamplesCount); ++sampleIndex) {
float2 texCoord = OffsetsAndWeights[sampleIndex].xy * TexelSize.xy + input.TexCoord;
# if defined(IGNORE_BRIGHTEST)
# if defined(DYNAMIC_SOURCE)
texCoord = GetDynamicResolutionAdjustedScreenPosition(texCoord);
# endif
float4 sourceColor = SourceTex.Sample(SourceSampler, texCoord);
# if defined(IGNORE_BRIGHTEST)
# if defined(DYNAMIC_SOURCE)
downsampledColor += sourceColor;
# else
float sampleLuminance = RGBToLuminanceAlternative(sourceColor.xyz);
Expand All @@ -48,7 +48,7 @@ PS_OUTPUT main(PS_INPUT input)
}
# endif
}
# if defined(IGNORE_BRIGHTEST)
# if defined(DYNAMIC_SOURCE)
psout.Color = downsampledColor / asuint(SamplesCount);
# else
if (CompensateJittering) {
Expand Down
16 changes: 8 additions & 8 deletions package/Shaders/ISHDR.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ struct PS_OUTPUT
SamplerState ImageSampler : register(s0);
# if defined(DOWNSAMPLE)
SamplerState AdaptSampler : register(s1);
# elif defined(TONEMAP)
# elif defined(BLEND)
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)
# elif defined(BLEND)
Texture2D<float4> BlendTex : register(t1);
# endif
Texture2D<float4> AvgTex : register(t2);
Expand Down Expand Up @@ -56,20 +56,20 @@ PS_OUTPUT main(PS_INPUT input)

# if defined(DOWNSAMPLE)
float3 downsampledColor = 0;
for (int sampleIndex = 0; sampleIndex < SAMPLES_COUNT; ++sampleIndex) {
for (int sampleIndex = 0; sampleIndex < DOWNSAMPLE; ++sampleIndex) {
float2 texCoord = BlurOffsets[sampleIndex].xy * BlurScale.xy + input.TexCoord;
if (Flags.x > 0.5) {
texCoord = GetDynamicResolutionAdjustedScreenPosition(texCoord);
}
float3 imageColor = ImageTex.Sample(ImageSampler, texCoord).xyz;
# if defined(LUM)
imageColor = imageColor.x;
# elif defined(RGB2LUM)
# if defined(RGB2LUM)
imageColor = RGBToLuminance(imageColor);
# elif (defined(LUM) || defined(LUMCLAMP)) && !defined(DOWNADAPT)
imageColor = imageColor.x;
# endif
downsampledColor += imageColor * BlurOffsets[sampleIndex].z;
}
# if defined(LIGHT_ADAPT)
# if defined(DOWNADAPT)
float2 adaptValue = AdaptTex.Sample(AdaptSampler, input.TexCoord).xy;
if (isnan(downsampledColor.x) || isnan(downsampledColor.y) || isnan(downsampledColor.z)) {
downsampledColor.xy = adaptValue;
Expand All @@ -82,7 +82,7 @@ PS_OUTPUT main(PS_INPUT input)
# endif
psout.Color = float4(downsampledColor, BlurScale.z);

# elif defined(TONEMAP)
# elif defined(BLEND)
float2 adjustedTexCoord = GetDynamicResolutionAdjustedScreenPosition(input.TexCoord);
float3 blendColor = BlendTex.Sample(BlendSampler, adjustedTexCoord).xyz;
float3 imageColor = 0;
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/ISIBLensFlare.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cbuffer PerGeometry : register(b2)
float haloFetch : packoffset(c2.z);
float haloWidthPow : packoffset(c2.w);
float dynamicSource : packoffset(c3.x);
float globalIntensity : packoffset(c3.y);
float globalIntensity : packoffset(c4.x);
};

float4 GetSampleColor(float2 texCoord)
Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/ISLightingComposite.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ PS_OUTPUT main(PS_INPUT input)
float4 specular = SpecularTex.Sample(SpecularSampler, input.TexCoord);
float4 albedo = AlbedoTex.Sample(AlbedoSampler, input.TexCoord);

# if !defined(NO_DIRECTIONAL_LIGHT)
# if defined(DIRECTIONALLIGHT)
float4 dirDiffuse = DirDiffuseTex.Sample(DirDiffuseSampler, input.TexCoord);
float4 dirSpecular = DirSpecularTex.Sample(DirSpecularSampler, input.TexCoord);
# else
Expand Down
4 changes: 2 additions & 2 deletions package/Shaders/ISRadialBlur.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ PS_OUTPUT main(PS_INPUT input)
GetCircleParam(centerDistance, Center.z, Params.w)));

float4 color = 0;
for (float sampleIndex = -SAMPLES_COUNT; sampleIndex <= SAMPLES_COUNT; ++sampleIndex) {
for (float sampleIndex = -NUM_STEPS; sampleIndex <= NUM_STEPS; ++sampleIndex) {
float2 texCoord = input.TexCoord + sampleDelta * sampleIndex;
float2 adjustedTexCoord = GetDynamicResolutionAdjustedScreenPosition(texCoord);
float4 currentColor = ImageTex.SampleLevel(ImageSampler, adjustedTexCoord, 0);
color += currentColor;
}
color *= (1. / (2. * SAMPLES_COUNT + 1.));
color *= (1. / (2. * NUM_STEPS + 1.));

psout.Color = color;

Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/ISSAOMinify.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ PS_OUTPUT main(PS_INPUT input)

float4 color = sourceTex.Sample(sourceSampler, finalTexCoord);

# if defined(CONTRAST)
# if defined(APPLY_CENTER_CONTRAST)
int contrastIndex = (int)(5 * input.TexCoord.x) + (int)(5 * input.TexCoord.y) * 5;
float contrastFactor = ContrastValues[contrastIndex] * g_ContrastParams.x;
color *= contrastFactor;
Expand Down
4 changes: 2 additions & 2 deletions package/Shaders/ISSimpleColor.hlsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(DISPLAY_DEPTH)
# include "Common/DummyVSTexCoord.hlsl"
#elif defined(SIMPLE_COLOR)
#else
# include "Common/DummyVS.hlsl"
#endif

Expand Down Expand Up @@ -41,7 +41,7 @@ PS_OUTPUT main(PS_INPUT input)
float screenDepth = saturate((-Color.x + depth) / (Color.y - Color.x));
psout.Color.xyz = (screenDepth * -2 + 3) * (screenDepth * screenDepth);
psout.Color.w = 1;
# elif defined(SIMPLE_COLOR)
# else
psout.Color = Color;
# endif

Expand Down
16 changes: 8 additions & 8 deletions package/Shaders/ISWaterDisplacement.hlsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if defined(SMOOTH_HEIGHTMAP) || defined(RAIN_HEIGHTMAP) || defined(WADING_HEIGHTMAP)
#if defined(HEIGHTMAP_SMOOTH) || defined(HEIGHTMAP_RAIN) || defined(HEIGHTMAP_WADING)
# define HEIGHTMAP
#endif

Expand Down Expand Up @@ -51,7 +51,7 @@ SamplerState HeightMap01Sampler : register(s0);
SamplerState HeightMap02Sampler : register(s1);
# elif defined(NORMALS)
SamplerState DisplaceMapSampler : register(s0);
# elif defined(TEX_OFFSET)
# elif defined(TEXCOORD_OFFSET)
SamplerState DisplaySamplerSampler : register(s0);
# elif defined(HEIGHTMAP)
SamplerState HeightMapSampler : register(s0);
Expand All @@ -62,7 +62,7 @@ Texture2D<float4> HeightMap01Tex : register(t0);
Texture2D<float4> HeightMap02Tex : register(t1);
# elif defined(NORMALS)
Texture2D<float4> DisplaceMapTex : register(t0);
# elif defined(TEX_OFFSET)
# elif defined(TEXCOORD_OFFSET)
Texture2D<float4> DisplaySamplerTex : register(t0);
# elif defined(HEIGHTMAP)
Texture2D<float4> HeightMapTex : register(t0);
Expand Down Expand Up @@ -142,18 +142,18 @@ PS_OUTPUT main(PS_INPUT input)

psout.Color = float4(normalize(float3(-valueRL, valueTB, 1)), 1) * 0.5 + 0.5;

# elif defined(RAIN_RIPPLE) || defined(WADING_RIPPLE)
# elif defined(RIPPLE_MAKER_RAIN) || defined(RIPPLE_MAKER_WADING)
psout.Color = float4(1, 0.5, 0.5, 0.5);
# elif defined(TEX_OFFSET)
# elif defined(TEXCOORD_OFFSET)
float lerpFactor = saturate(10 * (-0.4 + length(input.TexCoord - 0.5)));
float4 displayColor = DisplaySamplerTex.Sample(DisplaySamplerSampler, TextureOffset + input.TexCoord);
psout.Color.xy = displayColor.xy;
psout.Color.zw = lerp(displayColor.zw, 0.5, lerpFactor);
# elif defined(SMOOTH_HEIGHTMAP)
# elif defined(HEIGHTMAP_SMOOTH)
psout.Color = HeightMapTex.Sample(HeightMapSampler, input.TexCoord);
# elif defined(RAIN_HEIGHTMAP)
# elif defined(HEIGHTMAP_RAIN)
psout.Color = GetHeight(input, RainVars);
# elif defined(WADING_HEIGHTMAP)
# elif defined(HEIGHTMAP_WADING)
psout.Color = GetHeight(input, WadingVars);
# endif

Expand Down
2 changes: 1 addition & 1 deletion package/Shaders/ISWorldMap.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ PS_OUTPUT main(PS_INPUT input)

float depthFactor = DepthParams.w / ((1 - depth) * DepthParams.z + DepthParams.y);
float offsetDelta = min(TexelSize.y, TexelSize.z * abs(depthFactor - TexelSize.x));
# if defined(NO_SKY_BLUR)
# if defined(NO_SKY)
if (1 - depth <= 1e-4) {
offsetDelta = 0;
}
Expand Down
Loading
Loading