Skip to content

Commit

Permalink
Use HSV color-space for chroma
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Apr 21, 2024
1 parent dcd9daa commit 9dadc01
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion shaders/cBlockMatching.fx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace cBlockMatching
float2 PS_Normalize(VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
return GetSphericalRG(Color);
return RGBtoHS(Color);
}

float4 PS_Copy_0(VS2PS_Quad Input) : SV_TARGET0
Expand Down
2 changes: 1 addition & 1 deletion shaders/cChromaticity.fx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ float4 PS_Chromaticity(VS2PS_Quad Input) : SV_TARGET0
Chromaticity.rg = GetRatioRG(Color);
break;
case 9: // Sphere (XY)
Chromaticity.rg = GetSphericalRG(Color);
Chromaticity.rg = RGBtoHS(Color);
break;
case 10: // CoCg (XY)
Chromaticity.rg = GetCoCg(Gamma);
Expand Down
2 changes: 1 addition & 1 deletion shaders/cMotionBlur.fx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace cMotionBlur
float2 PS_Normalize(VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
return GetSphericalRG(Color);
return RGBtoHS(Color);
}

float2 PS_HBlur_Prefilter(VS2PS_Quad Input) : SV_TARGET0
Expand Down
2 changes: 1 addition & 1 deletion shaders/cOpticalFlow.fx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace cOpticalFlow
float2 PS_Normalize(VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
return GetSphericalRG(Color);
return RGBtoHS(Color);
}

float2 PS_HBlur_Prefilter(VS2PS_Quad Input) : SV_TARGET0
Expand Down
2 changes: 1 addition & 1 deletion shaders/kDatamosh.fx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace kDatamosh
float2 PS_Normalize(VS2PS_Quad Input) : SV_TARGET0
{
float3 Color = tex2D(CShade_SampleColorTex, Input.Tex0).rgb;
return GetSphericalRG(Color);
return RGBtoHS(Color);
}

float2 PS_HBlur_Prefilter(VS2PS_Quad Input) : SV_TARGET0
Expand Down
39 changes: 39 additions & 0 deletions shaders/shared/cImageProcessing.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,43 @@
float2 P = (DotC == 0.0) ? White : acos(abs(Color.xz * rsqrt(DotC)));
return saturate(P * IHalfPi);
}

/*
Color-space conversion
---
https://github.com/colour-science/colour
---
Copyright 2013 Colour Developers
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/

float2 RGBtoHS(float3 Color)
{
float MinRGB = min(min(Color.r, Color.g), Color.b);
float MaxRGB = max(max(Color.r, Color.g), Color.b);
float DeltaRGB = MaxRGB - MinRGB;

// Calculate hue
float3 Hue = (Color.gbr - Color.brg) / DeltaRGB;
Hue = (Hue * (60.0 / 360.0)) + (float3(0.0, 120.0, 240.0) / 360.0);
float OutputHue = 0.0;
OutputHue = (MaxRGB == Color.r) ? Hue.r : OutputHue;
OutputHue = (MaxRGB == Color.g) ? Hue.g : OutputHue;
OutputHue = (MaxRGB == Color.b) ? Hue.b : OutputHue;
OutputHue = (DeltaRGB == 0.0) ? 0.0 : OutputHue;

float2 Output = 0.0;
Output.x = OutputHue;
Output.y = (DeltaRGB == 0.0) ? 0.0 : DeltaRGB / MaxRGB;
return Output;
}
#endif

0 comments on commit 9dadc01

Please sign in to comment.