summaryrefslogtreecommitdiffstatshomepage
path: root/hlsl
diff options
context:
space:
mode:
Diffstat (limited to 'hlsl')
-rw-r--r--hlsl/bloom.fx24
-rw-r--r--hlsl/color.fx48
-rw-r--r--hlsl/deconverge.fx8
-rw-r--r--hlsl/distortion.fx8
-rw-r--r--hlsl/downsample.fx12
-rw-r--r--hlsl/focus.fx11
-rw-r--r--hlsl/post.fx4
-rw-r--r--hlsl/prescale.fx31
-rw-r--r--hlsl/primary.fx36
-rw-r--r--hlsl/scanline.fx13
10 files changed, 143 insertions, 52 deletions
diff --git a/hlsl/bloom.fx b/hlsl/bloom.fx
index 42c65e6a45b..7b8443b4a0c 100644
--- a/hlsl/bloom.fx
+++ b/hlsl/bloom.fx
@@ -308,7 +308,7 @@ float3 GetNoiseFactor(float3 n, float random)
float4 ps_main(PS_INPUT Input) : COLOR
{
- float3 texel = tex2D(DiffuseSampler, Input.TexCoord).rgb;
+ float4 texel = tex2D(DiffuseSampler, Input.TexCoord);
float3 texelA = tex2D(BloomSamplerA, Input.BloomCoord.xy).rgb;
float3 texelB = tex2D(BloomSamplerB, Input.BloomCoord.xy).rgb;
@@ -346,7 +346,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
{
float3 bloom = float3(0.0f, 0.0f, 0.0f);
- texel *= Level0Weight;
+ texel.rgb *= Level0Weight;
if (!VectorScreen)
{
@@ -381,7 +381,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
bloom *= BloomScale;
- float3 bloomOverdrive = max(0.0f, texel + bloom - 1.0f) * BloomOverdrive;
+ float3 bloomOverdrive = max(0.0f, texel.rgb + bloom - 1.0f) * BloomOverdrive;
bloom.r += bloomOverdrive.g * 0.5f;
bloom.r += bloomOverdrive.b * 0.5f;
@@ -393,20 +393,20 @@ float4 ps_main(PS_INPUT Input) : COLOR
float2 NoiseCoord = Input.TexCoord;
float3 NoiseFactor = GetNoiseFactor(bloom, random(NoiseCoord));
- blend = texel + bloom * NoiseFactor;
+ blend = texel.rgb + bloom * NoiseFactor;
}
// darken
else
{
- texelA = min(texel, texelA);
- texelB = min(texel, texelB);
- texelC = min(texel, texelC);
- texelD = min(texel, texelD);
- texelE = min(texel, texelE);
- texelF = min(texel, texelF);
- texelG = min(texel, texelG);
- texelH = min(texel, texelH);
+ texelA = min(texel.rgb, texelA);
+ texelB = min(texel.rgb, texelB);
+ texelC = min(texel.rgb, texelC);
+ texelD = min(texel.rgb, texelD);
+ texelE = min(texel.rgb, texelE);
+ texelF = min(texel.rgb, texelF);
+ texelG = min(texel.rgb, texelG);
+ texelH = min(texel.rgb, texelH);
blend = texel * Level0Weight;
blend = lerp(blend, texelA, Level1Weight * BloomScale);
diff --git a/hlsl/color.fx b/hlsl/color.fx
index 79f55260d4f..78b20bbb904 100644
--- a/hlsl/color.fx
+++ b/hlsl/color.fx
@@ -1,14 +1,23 @@
// license:BSD-3-Clause
-// copyright-holders:Ryan Holtz
+// copyright-holders:Ryan Holtz, W. M. Martinez
//-----------------------------------------------------------------------------
// Color-Convolution Effect
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
+// Macros
+//-----------------------------------------------------------------------------
+
+#define LUT_TEXTURE_WIDTH 4096.0f
+#define LUT_SIZE 64.0f
+#define LUT_SCALE float2(1.0f / LUT_TEXTURE_WIDTH, 1.0f / LUT_SIZE)
+
+//-----------------------------------------------------------------------------
// Sampler Definitions
//-----------------------------------------------------------------------------
texture Diffuse;
+texture LutTexture;
sampler DiffuseSampler = sampler_state
{
@@ -21,6 +30,35 @@ sampler DiffuseSampler = sampler_state
AddressW = CLAMP;
};
+sampler2D LutSampler = sampler_state
+{
+ Texture = <LutTexture>;
+ MinFilter = LINEAR;
+ MagFilter = LINEAR;
+ MipFilter = LINEAR;
+ AddressU = CLAMP;
+ AddressV = CLAMP;
+ AddressW = CLAMP;
+};
+
+//-----------------------------------------------------------------------------
+// Utilities
+//-----------------------------------------------------------------------------
+
+float3 apply_lut(float3 color)
+{
+ // NOTE: Do not change the order of parameters here.
+ float3 lutcoord = float3((color.rg * (LUT_SIZE - 1.0f) + 0.5f) *
+ LUT_SCALE, color.b * (LUT_SIZE - 1.0f));
+ float shift = floor(lutcoord.z);
+
+ lutcoord.x += shift * LUT_SCALE.y;
+ color.rgb = lerp(tex2D(LutSampler, lutcoord.xy).rgb, tex2D(LutSampler,
+ float2(lutcoord.x + LUT_SCALE.y, lutcoord.y)).rgb,
+ lutcoord.z - shift);
+ return color;
+}
+
//-----------------------------------------------------------------------------
// Vertex Definitions
//-----------------------------------------------------------------------------
@@ -52,6 +90,7 @@ struct PS_INPUT
uniform float2 ScreenDims;
uniform float2 SourceDims;
+uniform float3 PrimTint = float3(1.0f, 1.0f, 1.0f);
VS_OUTPUT vs_main(VS_INPUT Input)
{
@@ -67,6 +106,7 @@ VS_OUTPUT vs_main(VS_INPUT Input)
Output.TexCoord += 0.5f / SourceDims; // half texel offset correction (DX9)
Output.Color = Input.Color;
+ Output.Color.rgb *= PrimTint;
return Output;
}
@@ -81,11 +121,15 @@ uniform float3 BluRatios = float3(0.0f, 0.0f, 1.0f);
uniform float3 Offset = float3(0.0f, 0.0f, 0.0f);
uniform float3 Scale = float3(1.0f, 1.0f, 1.0f);
uniform float Saturation = 1.0f;
+uniform bool LutEnable;
float4 ps_main(PS_INPUT Input) : COLOR
{
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
+ if (LutEnable)
+ BaseTexel.rgb = apply_lut(BaseTexel.rgb);
+
float3 OutRGB = BaseTexel.rgb;
// RGB Tint & Shift
@@ -102,7 +146,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
float3 OutChroma = OutTexel - OutLuma;
float3 Saturated = OutLuma + OutChroma * Saturation;
- return float4(Saturated, BaseTexel.a);
+ return float4(Saturated * Input.Color.rgb, BaseTexel.a);
}
//-----------------------------------------------------------------------------
diff --git a/hlsl/deconverge.fx b/hlsl/deconverge.fx
index f1cfa8fb686..1262426620e 100644
--- a/hlsl/deconverge.fx
+++ b/hlsl/deconverge.fx
@@ -108,11 +108,11 @@ VS_OUTPUT vs_main(VS_INPUT Input)
float4 ps_main(PS_INPUT Input) : COLOR
{
- float r = tex2D(DiffuseSampler, float2(Input.TexCoordX.x, Input.TexCoordY.x)).r;
- float g = tex2D(DiffuseSampler, float2(Input.TexCoordX.y, Input.TexCoordY.y)).g;
- float b = tex2D(DiffuseSampler, float2(Input.TexCoordX.z, Input.TexCoordY.z)).b;
+ float2 ra = tex2D(DiffuseSampler, float2(Input.TexCoordX.x, Input.TexCoordY.x)).ra;
+ float2 ga = tex2D(DiffuseSampler, float2(Input.TexCoordX.y, Input.TexCoordY.y)).ga;
+ float2 ba = tex2D(DiffuseSampler, float2(Input.TexCoordX.z, Input.TexCoordY.z)).ba;
- return float4(r, g, b, 1.0f);
+ return float4(ra.x, ga.x, ba.x, ra.y + ga.y + ba.y);
}
//-----------------------------------------------------------------------------
diff --git a/hlsl/distortion.fx b/hlsl/distortion.fx
index 3dd1dbd44b6..e121cd2ff64 100644
--- a/hlsl/distortion.fx
+++ b/hlsl/distortion.fx
@@ -152,7 +152,7 @@ float GetSpotAddend(float2 coord, float amount)
float2 spotOffset = float2(-0.25f, 0.25f);
// normalized screen canvas ratio
- float2 CanvasRatio = SwapXY
+ float2 CanvasRatio = SwapXY
? float2(1.0f, QuadDims.x / QuadDims.y)
: float2(1.0f, QuadDims.y / QuadDims.x);
@@ -284,13 +284,11 @@ float4 ps_main(PS_INPUT Input) : COLOR
if (BaseCoord.x < 0.0f - TexelDims.x || BaseCoord.y < 0.0f - TexelDims.y ||
BaseCoord.x > 1.0f + TexelDims.x || BaseCoord.y > 1.0f + TexelDims.y)
{
- // we don't use the clip function, because we don't clear the render target before
- return float4(0.0f, 0.0f, 0.0f, 1.0f);
+ return float4(0, 0, 0, 1);
}
// Color
float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
- BaseColor.a = 1.0f;
// Vignetting Simulation
float2 VignetteCoord = QuadCoord;
@@ -332,4 +330,4 @@ technique DefaultTechnique
VertexShader = compile vs_3_0 vs_main();
PixelShader = compile ps_3_0 ps_main();
}
-} \ No newline at end of file
+}
diff --git a/hlsl/downsample.fx b/hlsl/downsample.fx
index c069b0ad10e..866901cb4fe 100644
--- a/hlsl/downsample.fx
+++ b/hlsl/downsample.fx
@@ -91,14 +91,12 @@ VS_OUTPUT vs_main(VS_INPUT Input)
float4 ps_main(PS_INPUT Input) : COLOR
{
- float3 texel0 = tex2D(DiffuseSampler, Input.TexCoord01.xy).rgb;
- float3 texel1 = tex2D(DiffuseSampler, Input.TexCoord01.zw).rgb;
- float3 texel2 = tex2D(DiffuseSampler, Input.TexCoord23.xy).rgb;
- float3 texel3 = tex2D(DiffuseSampler, Input.TexCoord23.zw).rgb;
+ float4 texel0 = tex2D(DiffuseSampler, Input.TexCoord01.xy);
+ float4 texel1 = tex2D(DiffuseSampler, Input.TexCoord01.zw);
+ float4 texel2 = tex2D(DiffuseSampler, Input.TexCoord23.xy);
+ float4 texel3 = tex2D(DiffuseSampler, Input.TexCoord23.zw);
- float3 outTexel = (texel0 + texel1 + texel2 + texel3) / 4.0;
-
- return float4(outTexel, 1.0f);
+ return (texel0 + texel1 + texel2 + texel3) * 0.25;
}
//-----------------------------------------------------------------------------
diff --git a/hlsl/focus.fx b/hlsl/focus.fx
index 6758d51fdc3..edf855db152 100644
--- a/hlsl/focus.fx
+++ b/hlsl/focus.fx
@@ -82,7 +82,7 @@ uniform float2 Defocus = float2(0.0f, 0.0f);
// now this pass is applied only once with offsets of 0.25, 0.55, 1.0, 1.6 to achieve the same appearance as before till a maximum defocus of 2.0
static const float2 CoordOffset8[8] =
{
- // 0.075x² + 0.225x + 0.25
+ // 0.075x² + 0.225x + 0.25
float2(-1.60f, 0.25f),
float2(-1.00f, -0.55f),
float2(-0.55f, 1.00f),
@@ -100,16 +100,13 @@ float4 ps_main(PS_INPUT Input) : COLOR
float2 DefocusTexelDims = Defocus * TexelDims;
- float3 texel = tex2D(DiffuseSampler, Input.TexCoord).rgb;
- float samples = 1.0f;
-
+ float4 texel = tex2D(DiffuseSampler, Input.TexCoord);
for (int i = 0; i < 8; i++)
{
- texel += tex2D(DiffuseSampler, Input.TexCoord + CoordOffset8[i] * DefocusTexelDims).rgb;
- samples += 1.0f;
+ texel += tex2D(DiffuseSampler, Input.TexCoord + CoordOffset8[i] * DefocusTexelDims);
}
- return float4(texel / samples, 1.0f);
+ return texel / 9.0f;
}
//-----------------------------------------------------------------------------
diff --git a/hlsl/post.fx b/hlsl/post.fx
index ed9dfff9e30..10a8aada455 100644
--- a/hlsl/post.fx
+++ b/hlsl/post.fx
@@ -206,14 +206,12 @@ float4 ps_main(PS_INPUT Input) : COLOR
// Color
float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
- BaseColor.a = 1.0;
// clip border
if (BaseCoord.x < 0.0 || BaseCoord.y < 0.0 ||
BaseCoord.x > 1.0 || BaseCoord.y > 1.0)
{
- // we don't use the clip function, because we don't clear the render target before
- return float4(0.0, 0.0, 0.0, 1.0);
+ return float4(0.0f, 0.0f, 0.0f, 1.0f);
}
// Color Compression (may not affect bloom)
diff --git a/hlsl/prescale.fx b/hlsl/prescale.fx
index 3f52c20b464..1529fb08c5a 100644
--- a/hlsl/prescale.fx
+++ b/hlsl/prescale.fx
@@ -25,6 +25,17 @@ sampler DiffuseSampler = sampler_state
AddressW = CLAMP;
};
+sampler PointSampler = sampler_state
+{
+ Texture = <Diffuse>;
+ MipFilter = POINT;
+ MinFilter = POINT;
+ MagFilter = POINT;
+ AddressU = CLAMP;
+ AddressV = CLAMP;
+ AddressW = CLAMP;
+};
+
//-----------------------------------------------------------------------------
// Vertex Definitions
//-----------------------------------------------------------------------------
@@ -94,6 +105,15 @@ float4 ps_main(PS_INPUT Input) : COLOR
}
//-----------------------------------------------------------------------------
+// Pre-scale Pixel Shader (point sampling)
+//-----------------------------------------------------------------------------
+
+float4 ps_point_main(PS_INPUT Input) : COLOR
+{
+ return tex2D(PointSampler, Input.TexCoord);
+}
+
+//-----------------------------------------------------------------------------
// Pre-scale Technique
//-----------------------------------------------------------------------------
@@ -107,3 +127,14 @@ technique DefaultTechnique
PixelShader = compile ps_3_0 ps_main();
}
}
+
+technique PointTechnique
+{
+ pass Pass0
+ {
+ Lighting = FALSE;
+
+ VertexShader = compile vs_3_0 vs_main();
+ PixelShader = compile ps_3_0 ps_point_main();
+ }
+}
diff --git a/hlsl/primary.fx b/hlsl/primary.fx
index 998a4b8716a..82306d3d01f 100644
--- a/hlsl/primary.fx
+++ b/hlsl/primary.fx
@@ -30,6 +30,17 @@ sampler DiffuseSampler = sampler_state
AddressW = CLAMP;
};
+sampler DiffuseWrapSampler = sampler_state
+{
+ Texture = <Diffuse>;
+ MipFilter = LINEAR;
+ MinFilter = LINEAR;
+ MagFilter = LINEAR;
+ AddressU = WRAP;
+ AddressV = WRAP;
+ AddressW = WRAP;
+};
+
sampler2D LutSampler = sampler_state
{
Texture = <LutTexture>;
@@ -155,6 +166,11 @@ uniform bool UiLutEnable;
float4 ps_screen_main(PS_INPUT Input) : COLOR
{
+ return tex2D(DiffuseSampler, Input.TexCoord);
+}
+
+float4 ps_vector_buffer_main(PS_INPUT Input) : COLOR
+{
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
if (LutEnable)
@@ -162,18 +178,19 @@ float4 ps_screen_main(PS_INPUT Input) : COLOR
return BaseTexel;
}
-float4 ps_vector_buffer_main(PS_INPUT Input) : COLOR
+float4 ps_ui_main(PS_INPUT Input) : COLOR
{
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
+ BaseTexel *= Input.Color;
- if (LutEnable)
+ if (UiLutEnable)
BaseTexel.rgb = apply_lut(BaseTexel.rgb);
return BaseTexel;
}
-float4 ps_ui_main(PS_INPUT Input) : COLOR
+float4 ps_ui_wrap_main(PS_INPUT Input) : COLOR
{
- float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
+ float4 BaseTexel = tex2D(DiffuseWrapSampler, Input.TexCoord);
BaseTexel *= Input.Color;
if (UiLutEnable)
@@ -217,3 +234,14 @@ technique UiTechnique
PixelShader = compile ps_2_0 ps_ui_main();
}
}
+
+technique UiWrapTechnique
+{
+ pass Pass0
+ {
+ Lighting = FALSE;
+
+ VertexShader = compile vs_2_0 vs_ui_main();
+ PixelShader = compile ps_2_0 ps_ui_wrap_main();
+ }
+}
diff --git a/hlsl/scanline.fx b/hlsl/scanline.fx
index 5dd4869fe1c..ec9eaa8d9b2 100644
--- a/hlsl/scanline.fx
+++ b/hlsl/scanline.fx
@@ -116,17 +116,14 @@ float2 GetAdjustedCoords(float2 coord)
float4 ps_main(PS_INPUT Input) : COLOR
{
- float2 BaseCoord = GetAdjustedCoords(Input.TexCoord);
-
// Color
- float4 BaseColor = tex2D(DiffuseSampler, BaseCoord);
- BaseColor.a = 1.0f;
+ float4 BaseColor = tex2D(DiffuseSampler, Input.TexCoord);
// clip border
- if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f ||
- BaseCoord.x > 1.0f || BaseCoord.y > 1.0f)
+ if (Input.TexCoord.x < 0.0f || Input.TexCoord.y < 0.0f ||
+ Input.TexCoord.x > 1.0f || Input.TexCoord.y > 1.0f)
{
- // we don't use the clip function, because we don't clear the render target before
+ // return black for the area outside the screen
return float4(0.0f, 0.0f, 0.0f, 1.0f);
}
@@ -135,7 +132,7 @@ float4 ps_main(PS_INPUT Input) : COLOR
float ColorBrightness = 0.299f * BaseColor.r + 0.587f * BaseColor.g + 0.114 * BaseColor.b;
- float ScanlineCoord = BaseCoord.y;
+ float ScanlineCoord = Input.TexCoord.y;
ScanlineCoord += SwapXY
? QuadDims.x <= SourceDims.x * 2.0f
? 0.5f / QuadDims.x // uncenter scanlines if the quad is less than twice the size of the source