diff options
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 |
commit | b5a54b761c94c543ce950dee0bc4aa0610ba8cba (patch) | |
tree | 9593e366a3f3da82074dec2b431c3dc8ada08d1c /hlsl/post.fx | |
parent | 7b42e2f79950adc1dd6d3c07df5513eda87b507c (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/post.fx')
-rw-r--r-- | hlsl/post.fx | 122 |
1 files changed, 67 insertions, 55 deletions
diff --git a/hlsl/post.fx b/hlsl/post.fx index 0d3bf244a16..ed9dfff9e30 100644 --- a/hlsl/post.fx +++ b/hlsl/post.fx @@ -4,6 +4,10 @@ // Shadowmask Effect //----------------------------------------------------------------------------- +#define MONOCHROME 1 +#define DICHROME 2 +#define TRICHROME 3 + //----------------------------------------------------------------------------- // Sampler Definitions //----------------------------------------------------------------------------- @@ -64,8 +68,8 @@ struct PS_INPUT // Constants //----------------------------------------------------------------------------- -static const float PI = 3.1415927f; -static const float HalfPI = PI * 0.5f; +static const float PI = 3.1415927; +static const float HalfPI = PI * 0.5; //----------------------------------------------------------------------------- // Shadowmask Vertex Shader @@ -77,8 +81,8 @@ uniform float2 TargetDims; uniform float2 TargetScale; uniform float2 QuadDims; -uniform float2 ShadowDims = float2(32.0f, 32.0f); // size of the shadow texture (extended to power-of-two size) -uniform float2 ShadowUVOffset = float2(0.0f, 0.0f); +uniform float2 ShadowDims = float2(32.0, 32.0); // size of the shadow texture (extended to power-of-two size) +uniform float2 ShadowUVOffset = float2(0.0, 0.0); uniform bool SwapXY = false; @@ -89,16 +93,16 @@ VS_OUTPUT vs_main(VS_INPUT Input) { VS_OUTPUT Output = (VS_OUTPUT)0; - Output.Position = float4(Input.Position.xyz, 1.0f); + Output.Position = float4(Input.Position.xyz, 1.0); Output.Position.xy /= ScreenDims; - Output.Position.y = 1.0f - Output.Position.y; // flip y - Output.Position.xy -= 0.5f; // center - Output.Position.xy *= 2.0f; // zoom + Output.Position.y = 1.0 - Output.Position.y; // flip y + Output.Position.xy -= 0.5; // center + Output.Position.xy *= 2.0; // zoom Output.TexCoord = Input.TexCoord; Output.TexCoord += PrepareBloom - ? 0.0f // use half texel offset (DX9) to do the blur for first bloom layer - : 0.5f / TargetDims; // fix half texel offset (DX9) + ? 0.0 // use half texel offset (DX9) to do the blur for first bloom layer + : 0.5 / TargetDims; // fix half texel offset (DX9) Output.ScreenCoord = Input.Position.xy / ScreenDims; @@ -111,34 +115,37 @@ VS_OUTPUT vs_main(VS_INPUT Input) // Shadowmask Pixel Shader //----------------------------------------------------------------------------- -uniform float HumBarDesync = 60.0f / 59.94f - 1.0f; // difference between the 59.94 Hz field rate and 60 Hz line frequency (NTSC) -uniform float HumBarAlpha = 0.0f; +uniform float HumBarDesync = 60.0 / 59.94 - 1.0; // difference between the 59.94 Hz field rate and 60 Hz line frequency (NTSC) +uniform float HumBarAlpha = 0.0; -uniform float TimeMilliseconds = 0.0f; +uniform float TimeMilliseconds = 0.0; -uniform float2 ScreenScale = float2(1.0f, 1.0f); -uniform float2 ScreenOffset = float2(0.0f, 0.0f); +uniform float2 ScreenScale = float2(1.0, 1.0); +uniform float2 ScreenOffset = float2(0.0, 0.0); -uniform float3 BackColor = float3(0.0f, 0.0f, 0.0f); +uniform float3 BackColor = float3(0.0, 0.0, 0.0); uniform int ShadowTileMode = 0; // 0 based on screen (quad) 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); +uniform float ShadowAlpha = 0.0; +uniform float2 ShadowCount = float2(6.0, 6.0); +uniform float2 ShadowUV = float2(0.25, 0.25); + +uniform float3 Power = float3(1.0, 1.0, 1.0); +uniform float3 Floor = float3(0.0, 0.0, 0.0); -uniform float3 Power = float3(1.0f, 1.0f, 1.0f); -uniform float3 Floor = float3(0.0f, 0.0f, 0.0f); +uniform int ChromaMode = 3; +uniform float3 ConversionGain = float3(0.0, 0.0, 0.0); float2 GetAdjustedCoords(float2 coord) { // center coordinates - coord -= 0.5f; + coord -= 0.5; // apply screen scale coord *= ScreenScale; // un-center coordinates - coord += 0.5f; + coord += 0.5; // apply screen offset coord += ScreenOffset; @@ -158,8 +165,8 @@ float2 GetShadowCoord(float2 TargetCoord, float2 SourceCoord) ? TargetCoord + ShadowUVOffset / BaseTargetDims : SourceCoord + ShadowUVOffset / SourceDims; float2 canvasTexelDims = ShadowTileMode == 0 - ? 1.0f / BaseTargetDims - : 1.0f / SourceDims; + ? 1.0 / BaseTargetDims + : 1.0 / SourceDims; float2 shadowDims = ShadowDims; float2 shadowUV = ShadowUV; @@ -186,8 +193,8 @@ float2 GetShadowCoord(float2 TargetCoord, float2 SourceCoord) float2 shadowCoord = (shadowFrac * shadowUV); shadowCoord += ShadowTileMode == 0 - ? 0.5f / shadowDims // fix half texel offset (DX9) - : 0.0f; + ? 0.5 / shadowDims // fix half texel offset (DX9) + : 0.0; return shadowCoord; } @@ -199,29 +206,14 @@ float4 ps_main(PS_INPUT Input) : COLOR // Color float4 BaseColor = tex2D(DiffuseSampler, BaseCoord); - BaseColor.a = 1.0f; + BaseColor.a = 1.0; // clip border - if (BaseCoord.x < 0.0f || BaseCoord.y < 0.0f || - BaseCoord.x > 1.0f || BaseCoord.y > 1.0f) + 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.0f, 0.0f, 0.0f, 1.0f); - } - - // Mask Simulation (may not affect bloom) - if (!PrepareBloom && ShadowAlpha > 0.0f) - { - float2 ShadowCoord = GetShadowCoord(ScreenCoord, BaseCoord); - - float4 ShadowColor = tex2D(ShadowSampler, ShadowCoord); - float3 ShadowMaskColor = lerp(1.0f, ShadowColor.rgb, ShadowAlpha); - float ShadowMaskClear = (1.0f - ShadowColor.a) * ShadowAlpha; - - // apply shadow mask color - BaseColor.rgb *= ShadowMaskColor; - // clear shadow mask by background color - BaseColor.rgb = lerp(BaseColor.rgb, BackColor, ShadowMaskClear); + return float4(0.0, 0.0, 0.0, 1.0); } // Color Compression (may not affect bloom) @@ -236,16 +228,36 @@ float4 ps_main(PS_INPUT Input) : COLOR BaseColor.g = pow(BaseColor.g, Power.g); BaseColor.b = pow(BaseColor.b, Power.b); - // Scanline Simulation (may not affect bloom) - if (!PrepareBloom) + // Hum Bar Simulation (may not affect vector screen) + if (!PrepareBloom && !VectorScreen && HumBarAlpha > 0.0) { - // Hum Bar Simulation (may not affect vector screen) - if (!VectorScreen && HumBarAlpha > 0.0f) - { - float HumBarStep = frac(TimeMilliseconds * HumBarDesync); - float HumBarBrightness = 1.0 - frac(BaseCoord.y + HumBarStep) * HumBarAlpha; - BaseColor.rgb *= HumBarBrightness; - } + float HumBarStep = frac(TimeMilliseconds * HumBarDesync); + float HumBarBrightness = 1.0 - frac(BaseCoord.y + HumBarStep) * HumBarAlpha; + BaseColor.rgb *= HumBarBrightness; + } + + // Mask Simulation (may not affect bloom) + if (!PrepareBloom && ShadowAlpha > 0.0) + { + float2 ShadowCoord = GetShadowCoord(ScreenCoord, BaseCoord); + + float4 ShadowColor = tex2D(ShadowSampler, ShadowCoord); + float3 ShadowMaskColor = lerp(1.0, ShadowColor.rgb, ShadowAlpha); + float ShadowMaskClear = (1.0 - ShadowColor.a) * ShadowAlpha; + + // apply shadow mask color + BaseColor.rgb *= ShadowMaskColor; + // clear shadow mask by background color + BaseColor.rgb = lerp(BaseColor.rgb, BackColor, ShadowMaskClear); + } + + // Preparation for phosphor color conversion + if (ChromaMode == MONOCHROME) { + BaseColor.r = dot(ConversionGain, BaseColor.rgb); + BaseColor.gb = float2(BaseColor.r, BaseColor.r); + } else if (ChromaMode == DICHROME) { + BaseColor.r = dot(ConversionGain.rg, BaseColor.rg); + BaseColor.g = BaseColor.r; } return BaseColor; |