summaryrefslogtreecommitdiffstatshomepage
path: root/hlsl/primary.fx
diff options
context:
space:
mode:
author Westley M. Martinez <anikom15@gmail.com>2018-10-07 08:42:30 -0700
committer R. Belmont <rb6502@users.noreply.github.com>2018-10-07 11:42:30 -0400
commitb5a54b761c94c543ce950dee0bc4aa0610ba8cba (patch)
tree9593e366a3f3da82074dec2b431c3dc8ada08d1c /hlsl/primary.fx
parent7b42e2f79950adc1dd6d3c07df5513eda87b507c (diff)
HLSL Color Transforms and 3D LUT (#4043)
* Remove broken scanline uniform from post_pass * Add 3D LUT to HLSL * Allow individual LUTs for screen and UI * WIP: Port 3D LUT to BGFX * Finish porting LUT to BGFX * Add individual phosphor color conversion for HLSL new file: hlsl/chroma.fx Shader for converting xyY3 to sRGB modified: hlsl/phosphor.fx Minor changes to emphasize idea that phosphors are color agnostic modified: hlsl/post.fx Conversion from signal RGB to xyY3 modified: src/osd/modules/render/d3d/d3dhlsl.cpp modified: src/osd/modules/render/d3d/d3dhlsl.h modified: src/osd/windows/winmain.cpp modified: src/osd/windows/winmain.h * Add phosphor examples and update presets * Port phosphor color shaders to BGFX * Fix missing newlines at EOF
Diffstat (limited to 'hlsl/primary.fx')
-rw-r--r--hlsl/primary.fx51
1 files changed, 49 insertions, 2 deletions
diff --git a/hlsl/primary.fx b/hlsl/primary.fx
index 839ebbf8bf0..998a4b8716a 100644
--- a/hlsl/primary.fx
+++ b/hlsl/primary.fx
@@ -1,14 +1,23 @@
// license:BSD-3-Clause
-// copyright-holders:Ryan Holtz
+// copyright-holders:Ryan Holtz, W. M. Martinez
//-----------------------------------------------------------------------------
// Primary 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
//-----------------------------------------------------------------------------
@@ -49,7 +87,7 @@ struct PS_INPUT
// Primary Vertex Shaders
//-----------------------------------------------------------------------------
-static const float Epsilon = 1.0e-7f;
+//static const float Epsilon = 1.0e-7f;
uniform float2 ScreenDims;
uniform float2 TargetDims;
@@ -112,10 +150,15 @@ VS_OUTPUT vs_ui_main(VS_INPUT Input)
// Primary Pixel Shaders
//-----------------------------------------------------------------------------
+uniform bool LutEnable;
+uniform bool UiLutEnable;
+
float4 ps_screen_main(PS_INPUT Input) : COLOR
{
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
+ if (LutEnable)
+ BaseTexel.rgb = apply_lut(BaseTexel.rgb);
return BaseTexel;
}
@@ -123,6 +166,8 @@ float4 ps_vector_buffer_main(PS_INPUT Input) : COLOR
{
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
+ if (LutEnable)
+ BaseTexel.rgb = apply_lut(BaseTexel.rgb);
return BaseTexel;
}
@@ -131,6 +176,8 @@ float4 ps_ui_main(PS_INPUT Input) : COLOR
float4 BaseTexel = tex2D(DiffuseSampler, Input.TexCoord);
BaseTexel *= Input.Color;
+ if (UiLutEnable)
+ BaseTexel.rgb = apply_lut(BaseTexel.rgb);
return BaseTexel;
}