Skip to content

Commit

Permalink
- Replaced lerp usage from hlsl.
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbie committed Apr 19, 2022
1 parent 283873b commit 3fc5def
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ScreenCapture/CaptureClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace
BOOL HDRtoSDR;
FLOAT HDRBrightness;
FLOAT Vibrance;
FLOAT Saturate;
FLOAT Saturation;
FLOAT RedChannel;
FLOAT GreenChannel;
FLOAT BlueChannel;
Expand All @@ -37,7 +37,7 @@ namespace
FLOAT HDRBrightness;
FLOAT SDRWhiteLevel;
FLOAT Vibrance;
FLOAT Saturate;
FLOAT Saturation;
FLOAT RedChannel;
FLOAT GreenChannel;
FLOAT BlueChannel;
Expand Down
2 changes: 1 addition & 1 deletion ScreenCapture/CaptureInitialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ namespace
shaderVariables.HDRBrightness = vCaptureSettings.HDRBrightness;
shaderVariables.SDRWhiteLevel = vCaptureDetails.SDRWhiteLevel;
shaderVariables.Vibrance = vCaptureSettings.Vibrance;
shaderVariables.Saturate = vCaptureSettings.Saturate;
shaderVariables.Saturation = vCaptureSettings.Saturation;
shaderVariables.RedChannel = vCaptureSettings.RedChannel;
shaderVariables.GreenChannel = vCaptureSettings.GreenChannel;
shaderVariables.BlueChannel = vCaptureSettings.BlueChannel;
Expand Down
18 changes: 10 additions & 8 deletions ScreenCapture/Shaders/PixelShader.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cbuffer _shaderVariables : register(b0)
float HDRBrightness;
float SDRWhiteLevel;
float Vibrance;
float Saturate;
float Saturation;
float RedChannel;
float GreenChannel;
float BlueChannel;
Expand All @@ -32,15 +32,17 @@ float4 AdjustVibrance(float4 color)
if (Vibrance == 0.0F) { return color; }
float maxColor = max(color.r, max(color.g, color.b));
float minColor = min(color.r, min(color.g, color.b));
return lerp(minColor, color, 1.0F / pow(maxColor, Vibrance));
float powColor = 1.0F / pow(maxColor, Vibrance);
float adjustPow = 1.0F - powColor;
return minColor * adjustPow + color * powColor;
}

float4 AdjustSaturate(float4 color)
float4 AdjustSaturation(float4 color)
{
if (Saturate == 1.0F) { return color; }
float adjustSaturate = 1.0F - Saturate;
if (Saturation == 1.0F) { return color; }
float adjustSaturation = 1.0F - Saturation;
float adjustLuminance = (color.r + color.g + color.b) / 3.0F;
return color * Saturate + adjustSaturate * adjustLuminance;
return color * Saturation + adjustSaturation * adjustLuminance;
}

float4 AdjustColorChannels(float4 color)
Expand Down Expand Up @@ -100,8 +102,8 @@ float4 main(PS_INPUT input) : SV_TARGET
//Adjust vibrance
color = AdjustVibrance(color);

//Adjust saturate
color = AdjustSaturate(color);
//Adjust saturation
color = AdjustSaturation(color);

//Adjust color channels
color = AdjustColorChannels(color);
Expand Down
4 changes: 2 additions & 2 deletions ScreenCapturePreview/CaptureClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public CaptureSettings()
HDRtoSDR = true;
HDRBrightness = 70.0F;
Vibrance = 0.0F;
Saturate = 1.0F;
Saturation = 1.0F;
RedChannel = 1.0F;
GreenChannel = 1.0F;
BlueChannel = 1.0F;
Expand All @@ -22,7 +22,7 @@ public CaptureSettings()
public bool HDRtoSDR { get; set; }
public float HDRBrightness { get; set; }
public float Vibrance { get; set; }
public float Saturate { get; set; }
public float Saturation { get; set; }
public float RedChannel { get; set; }
public float GreenChannel { get; set; }
public float BlueChannel { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions ScreenCapturePreview/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<TextBlock x:Name="text_Vibrance" Tag="Vibrance:" Foreground="White" Margin="0,5,0,0"/>
<Slider x:Name="slider_Vibrance" Value="0.00" Minimum="-2.00" Maximum="2.00" ValueChanged="slider_ValueChanged"/>

<TextBlock x:Name="text_Saturate" Tag="Saturate:" Foreground="White" Margin="0,5,0,0"/>
<Slider x:Name="slider_Saturate" Value="1.00" Minimum="0.00" Maximum="2.00" ValueChanged="slider_ValueChanged"/>
<TextBlock x:Name="text_Saturation" Tag="Saturation:" Foreground="White" Margin="0,5,0,0"/>
<Slider x:Name="slider_Saturation" Value="1.00" Minimum="0.00" Maximum="2.00" ValueChanged="slider_ValueChanged"/>

<TextBlock x:Name="text_RedChannel" Tag="Red channel:" Foreground="White" Margin="0,5,0,0"/>
<Slider x:Name="slider_RedChannel" Value="1.00" Minimum="0.00" Maximum="2.00" ValueChanged="slider_ValueChanged"/>
Expand Down
6 changes: 3 additions & 3 deletions ScreenCapturePreview/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private async Task<bool> InitializeScreenCapture(int delayTime)
HDRtoSDR = true,
HDRBrightness = (float)slider_HDRBrightness.Value,
Vibrance = (float)slider_Vibrance.Value,
Saturate = (float)slider_Saturate.Value,
Saturation = (float)slider_Saturation.Value,
RedChannel = (float)slider_RedChannel.Value,
GreenChannel = (float)slider_GreenChannel.Value,
BlueChannel = (float)slider_BlueChannel.Value,
Expand Down Expand Up @@ -181,7 +181,7 @@ private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<d
//Update slider text
text_HDRBrightness.Text = text_HDRBrightness.Tag + " " + slider_HDRBrightness.Value.ToString("0.0000");
text_Vibrance.Text = text_Vibrance.Tag + " " + slider_Vibrance.Value.ToString("0.0000");
text_Saturate.Text = text_Saturate.Tag + " " + slider_Saturate.Value.ToString("0.0000");
text_Saturation.Text = text_Saturation.Tag + " " + slider_Saturation.Value.ToString("0.0000");
text_RedChannel.Text = text_RedChannel.Tag + " " + slider_RedChannel.Value.ToString("0.0000");
text_GreenChannel.Text = text_GreenChannel.Tag + " " + slider_GreenChannel.Value.ToString("0.0000");
text_BlueChannel.Text = text_BlueChannel.Tag + " " + slider_BlueChannel.Value.ToString("0.0000");
Expand All @@ -197,7 +197,7 @@ private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<d
HDRtoSDR = true,
HDRBrightness = (float)slider_HDRBrightness.Value,
Vibrance = (float)slider_Vibrance.Value,
Saturate = (float)slider_Saturate.Value,
Saturation = (float)slider_Saturation.Value,
RedChannel = (float)slider_RedChannel.Value,
GreenChannel = (float)slider_GreenChannel.Value,
BlueChannel = (float)slider_BlueChannel.Value,
Expand Down

0 comments on commit 3fc5def

Please sign in to comment.