summaryrefslogtreecommitdiffstatshomepage
path: root/hlsl
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2015-12-25 20:02:47 +0100
committer ImJezze <jezze@gmx.net>2015-12-25 20:02:47 +0100
commit1b373eb812d11dfeb0fead627f7df4e827e27f8f (patch)
treea99b38395c8ba5a6706c9340bf9b3cb9430de571 /hlsl
parent099f547d05856238f5879803c794ea3a233c5d55 (diff)
Extended Shadow Mask and Bloom functionality
- added shadow mask type option to choose between "Screen" and "Source" tile mode ("Screen" is the default as before) - added bloom type option to choose between "Addition" and "Darken" blend mode ("Addition" is the default as before) - the alpha channel of a shadow mask is now filled with the background color of the screen by the amount of the inverted alpha value - added monochrome-matrix.png which can be used in combination with "Source" tile mode and "Darken" blend mode to simulate a STN LCD, for example
Diffstat (limited to 'hlsl')
-rw-r--r--hlsl/bloom.fx113
-rw-r--r--hlsl/color.fx26
-rw-r--r--hlsl/post.fx20
3 files changed, 102 insertions, 57 deletions
diff --git a/hlsl/bloom.fx b/hlsl/bloom.fx
index 0bd981ae0e7..61ffa4091f8 100644
--- a/hlsl/bloom.fx
+++ b/hlsl/bloom.fx
@@ -240,7 +240,9 @@ uniform float4 Level0123Weight;
uniform float4 Level4567Weight;
uniform float3 Level89AWeight;
-uniform float3 OverdriveWeight;
+uniform int BloomType = 1; // blend mode: 0 addition, 1 darken
+uniform float BloomScale;
+uniform float3 BloomOverdrive;
float3 GetNoiseFactor(float3 n, float random)
{
@@ -262,43 +264,78 @@ float4 ps_main(PS_INPUT Input) : COLOR
float3 texel9 = tex2D(DiffuseSampler9, Input.TexCoord89.zw).rgb;
float3 texelA = tex2D(DiffuseSamplerA, Input.TexCoordA).rgb;
- texel0 = texel0 * Level0123Weight.x;
- texel1 = texel1 * Level0123Weight.y;
- texel2 = texel2 * Level0123Weight.z;
- texel3 = texel3 * Level0123Weight.w;
- texel4 = texel4 * Level4567Weight.x;
- texel5 = texel5 * Level4567Weight.y;
- texel6 = texel6 * Level4567Weight.z;
- texel7 = texel7 * Level4567Weight.w;
- texel8 = texel8 * Level89AWeight.x;
- texel9 = texel9 * Level89AWeight.y;
- texelA = texelA * Level89AWeight.z;
-
- float3 bloom = float3(
- texel1 +
- texel2 +
- texel3 +
- texel4 +
- texel5 +
- texel6 +
- texel7 +
- texel8 +
- texel9 +
- texelA);
-
- float3 bloomOverdrive = max(0.0f, texel0 + bloom - 1.0f) * OverdriveWeight;
-
- bloom.r += bloomOverdrive.g * 0.5f;
- bloom.r += bloomOverdrive.b * 0.5f;
- bloom.g += bloomOverdrive.r * 0.5f;
- bloom.g += bloomOverdrive.b * 0.5f;
- bloom.b += bloomOverdrive.r * 0.5f;
- bloom.b += bloomOverdrive.g * 0.5f;
-
- float2 NoiseCoord = Input.TexCoord01.xy;
- float3 NoiseFactor = GetNoiseFactor(bloom, random(NoiseCoord));
-
- return float4(texel0 + bloom * NoiseFactor, 1.0f);
+ float3 blend;
+
+ // addition
+ if (BloomType == 0)
+ {
+ texel0 *= Level0123Weight.x;
+ texel1 *= Level0123Weight.y;
+ texel2 *= Level0123Weight.z;
+ texel3 *= Level0123Weight.w;
+ texel4 *= Level4567Weight.x;
+ texel5 *= Level4567Weight.y;
+ texel6 *= Level4567Weight.z;
+ texel7 *= Level4567Weight.w;
+ texel8 *= Level89AWeight.x;
+ texel9 *= Level89AWeight.y;
+ texelA *= Level89AWeight.z;
+
+ float3 bloom = float3(
+ texel1 +
+ texel2 +
+ texel3 +
+ texel4 +
+ texel5 +
+ texel6 +
+ texel7 +
+ texel8 +
+ texel9 +
+ texelA) * BloomScale;
+
+ float3 bloomOverdrive = max(0.0f, texel0 + bloom - 1.0f) * BloomOverdrive;
+
+ bloom.r += bloomOverdrive.g * 0.5f;
+ bloom.r += bloomOverdrive.b * 0.5f;
+ bloom.g += bloomOverdrive.r * 0.5f;
+ bloom.g += bloomOverdrive.b * 0.5f;
+ bloom.b += bloomOverdrive.r * 0.5f;
+ bloom.b += bloomOverdrive.g * 0.5f;
+
+ float2 NoiseCoord = Input.TexCoord01.xy;
+ float3 NoiseFactor = GetNoiseFactor(bloom, random(NoiseCoord));
+
+ blend = texel0 + bloom * NoiseFactor;
+ }
+
+ // darken
+ else
+ {
+ texel1 = min(texel0, texel1);
+ texel2 = min(texel0, texel2);
+ texel3 = min(texel0, texel3);
+ texel4 = min(texel0, texel4);
+ texel5 = min(texel0, texel5);
+ texel6 = min(texel0, texel6);
+ texel7 = min(texel0, texel7);
+ texel8 = min(texel0, texel8);
+ texel9 = min(texel0, texel9);
+ texelA = min(texel0, texelA);
+
+ blend = texel0 * Level0123Weight.x;
+ blend = lerp(blend, texel1, Level0123Weight.y * BloomScale);
+ blend = lerp(blend, texel2, Level0123Weight.z * BloomScale);
+ blend = lerp(blend, texel3, Level0123Weight.w * BloomScale);
+ blend = lerp(blend, texel4, Level4567Weight.x * BloomScale);
+ blend = lerp(blend, texel5, Level4567Weight.y * BloomScale);
+ blend = lerp(blend, texel6, Level4567Weight.z * BloomScale);
+ blend = lerp(blend, texel7, Level4567Weight.w * BloomScale);
+ blend = lerp(blend, texel8, Level89AWeight.x * BloomScale);
+ blend = lerp(blend, texel9, Level89AWeight.y * BloomScale);
+ blend = lerp(blend, texelA, Level89AWeight.z * BloomScale);
+ }
+
+ return float4(blend, 1.0f);
}
//-----------------------------------------------------------------------------
diff --git a/hlsl/color.fx b/hlsl/color.fx
index 53404726699..7724eeb10f7 100644
--- a/hlsl/color.fx
+++ b/hlsl/color.fx
@@ -49,20 +49,20 @@ struct PS_INPUT
uniform float2 ScreenDims;
uniform float2 SourceDims;
-uniform float YIQEnable;
-
VS_OUTPUT vs_main(VS_INPUT Input)
{
VS_OUTPUT Output = (VS_OUTPUT)0;
-
- float2 invDims = 1.0f / SourceDims;
+
Output.Position = float4(Input.Position.xyz, 1.0f);
Output.Position.xy /= ScreenDims;
- Output.Position.y = 1.0f - Output.Position.y;
- Output.Position.xy -= 0.5f;
- Output.Position *= float4(2.0f, 2.0f, 1.0f, 1.0f);
+ Output.Position.y = 1.0f - Output.Position.y; // flip y
+ Output.Position.xy -= 0.5f; // center
+ Output.Position.xy *= 2.0f; // zoom
+
+ Output.TexCoord = Input.TexCoord;
+ Output.TexCoord += 0.5f / SourceDims; // half texel offset correction (DX9)
+
Output.Color = Input.Color;
- Output.TexCoord = Input.TexCoord + 0.5f * invDims;
return Output;
}
@@ -84,17 +84,17 @@ float4 ps_main(PS_INPUT Input) : COLOR
float3 OutRGB = BaseTexel.rgb;
- // -- RGB Tint & Shift --
+ // RGB Tint & Shift
float ShiftedRed = dot(OutRGB, RedRatios);
float ShiftedGrn = dot(OutRGB, GrnRatios);
float ShiftedBlu = dot(OutRGB, BluRatios);
- // -- RGB Offset & Scale --
+ // RGB Scale & Offset
float3 OutTexel = float3(ShiftedRed, ShiftedGrn, ShiftedBlu) * Scale + Offset;
- // -- Saturation --
- float3 Gray = float3(0.3f, 0.59f, 0.11f);
- float OutLuma = dot(OutTexel, Gray);
+ // Saturation
+ float3 Grayscale = float3(0.299f, 0.587f, 0.114f);
+ float OutLuma = dot(OutTexel, Grayscale);
float3 OutChroma = OutTexel - OutLuma;
float3 Saturated = OutLuma + OutChroma * Saturation;
diff --git a/hlsl/post.fx b/hlsl/post.fx
index c794d0b01af..eed41168d33 100644
--- a/hlsl/post.fx
+++ b/hlsl/post.fx
@@ -127,13 +127,16 @@ VS_OUTPUT vs_main(VS_INPUT Input)
uniform float2 ScreenScale = float2(1.0f, 1.0f);
uniform float2 ScreenOffset = float2(0.0f, 0.0f);
-uniform float ScanlineAlpha = 1.0f;
+uniform float ScanlineAlpha = 0.0f;
uniform float ScanlineScale = 1.0f;
uniform float ScanlineBrightScale = 1.0f;
uniform float ScanlineBrightOffset = 1.0f;
uniform float ScanlineOffset = 1.0f;
uniform float ScanlineHeight = 1.0f;
+uniform float3 BackColor = float3(0.0f, 0.0f, 0.0f);
+
+uniform int ShadowType = 0; // tile mode: 0 based on screen dimension, 1 based on source dimension
uniform float ShadowAlpha = 0.0f;
uniform float2 ShadowCount = float2(6.0f, 6.0f);
uniform float2 ShadowUV = float2(0.25f, 0.25f);
@@ -161,6 +164,7 @@ float2 GetAdjustedCoords(float2 coord, float2 centerOffset)
float4 ps_main(PS_INPUT Input) : COLOR
{
float2 ScreenTexelDims = 1.0f / ScreenDims;
+ float2 SourceTexelDims = 1.0f / SourceDims;
float2 HalfSourceRect = PrepareVector
? float2(0.5f, 0.5f)
@@ -191,7 +195,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
// ? shadowUV.yx
// : shadowUV.xy;
- float2 screenCoord = ScreenCoord;
+ float2 screenCoord = ShadowType == 0 ? ScreenCoord : BaseCoord;
screenCoord = xor(OrientationSwapXY, RotationSwapXY)
? screenCoord.yx
: screenCoord.xy;
@@ -201,7 +205,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
? shadowCount.yx
: shadowCount.xy;
- float2 shadowTile = (ScreenTexelDims * shadowCount);
+ float2 shadowTile = ((ShadowType == 0 ? ScreenTexelDims : SourceTexelDims) * shadowCount);
shadowTile = xor(OrientationSwapXY, RotationSwapXY)
? shadowTile.yx
: shadowTile.xy;
@@ -213,10 +217,14 @@ float4 ps_main(PS_INPUT Input) : COLOR
// ? ShadowCoord.yx
// : ShadowCoord.xy;
- float3 ShadowColor = tex2D(ShadowSampler, ShadowCoord).rgb;
- ShadowColor = lerp(1.0f, ShadowColor, ShadowAlpha);
+ float4 ShadowColor = tex2D(ShadowSampler, ShadowCoord);
+ float3 ShadowMaskColor = lerp(1.0f, ShadowColor.rgb, ShadowAlpha);
+ float ShadowMaskClear = (1.0f - ShadowColor.a) * ShadowAlpha;
- BaseColor.rgb *= ShadowColor;
+ // apply shadow mask color
+ BaseColor.rgb *= ShadowMaskColor;
+ // clear shadow mask by background color
+ BaseColor.rgb = lerp(BaseColor.rgb, BackColor, ShadowMaskClear);
}
// Color Compression (may not affect bloom)