mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-24 15:16:38 +00:00
Add color fade
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "DrawQuad.h"
|
||||
#include "DrawQuadPixelConstants.h"
|
||||
#include "Functions.h"
|
||||
|
||||
SamplerState nearestNeighborSampler : register(s0);
|
||||
Texture2D<uint> surfaceTexture : register(t0);
|
||||
@@ -20,7 +21,10 @@ SDrawQuadPixelOutput PSMain(SDrawQuadPixelInput input)
|
||||
{
|
||||
SDrawQuadPixelOutput result;
|
||||
int2 pixelCoordinate = int2(floor(input.texCoord.xy));
|
||||
result.color = ApplyFlicker(pixelCoordinate, float4(SamplePixel(int2(floor(input.texCoord.xy))), 1.0) * constants_Modulation);
|
||||
result.color = float4(SamplePixel(int2(floor(input.texCoord.xy))), 1.0);
|
||||
result.color *= constants_Modulation;
|
||||
result.color = ApplyFlicker(pixelCoordinate, constants_FlickerStartThreshold, constants_FlickerEndThreshold, result.color * constants_Modulation);
|
||||
result.color = ApplyDesaturation(constants_Desaturation, result.color);
|
||||
|
||||
if (result.color.a <= 0.0)
|
||||
discard;
|
||||
|
@@ -5,15 +5,7 @@ cbuffer SDrawQuadPixelConstants : register(b0)
|
||||
int2 constants_FlickerAxis;
|
||||
int constants_FlickerStartThreshold;
|
||||
int constants_FlickerEndThreshold;
|
||||
|
||||
float constants_Desaturation;
|
||||
float3 constants_Unused;
|
||||
};
|
||||
|
||||
float4 ApplyFlicker(int2 coordinate, float4 color)
|
||||
{
|
||||
int flickerTotal = dot(constants_FlickerAxis, coordinate);
|
||||
if (flickerTotal < constants_FlickerStartThreshold)
|
||||
return float4(0, 0, 0, 0);
|
||||
else if (flickerTotal >= constants_FlickerEndThreshold)
|
||||
return color;
|
||||
else
|
||||
return float4(1, 1, 1, 1);
|
||||
}
|
||||
|
59
ShaderSrc/Functions.h
Normal file
59
ShaderSrc/Functions.h
Normal file
@@ -0,0 +1,59 @@
|
||||
float SRGBToLinear(float v)
|
||||
{
|
||||
if (v <= 0.04045)
|
||||
return v * (1.0 / 12.92);
|
||||
else
|
||||
return pow(((v + 0.055) * (1.0 / 1.055)), 2.4);
|
||||
}
|
||||
|
||||
float2 SRGBToLinear(float2 v)
|
||||
{
|
||||
return float2(SRGBToLinear(v.x), SRGBToLinear(v.y));
|
||||
}
|
||||
|
||||
float3 SRGBToLinear(float3 v)
|
||||
{
|
||||
return float3(SRGBToLinear(v.x), SRGBToLinear(v.y), SRGBToLinear(v.z));
|
||||
}
|
||||
|
||||
float LinearToSRGB(float v)
|
||||
{
|
||||
if (v <= 0.0031308)
|
||||
return 12.92 * v;
|
||||
else
|
||||
return 1.055 * pow(v, 1.0 / 2.4) - 0.055;
|
||||
}
|
||||
|
||||
float2 LinearToSRGB(float2 v)
|
||||
{
|
||||
return float2(LinearToSRGB(v.x), LinearToSRGB(v.y));
|
||||
}
|
||||
|
||||
float3 LinearToSRGB(float3 v)
|
||||
{
|
||||
return float3(LinearToSRGB(v.x), LinearToSRGB(v.y), LinearToSRGB(v.z));
|
||||
}
|
||||
|
||||
float4 ApplyFlicker(int2 coordinate, int startThreshold, int endThreshold, float4 color)
|
||||
{
|
||||
int flickerTotal = dot(constants_FlickerAxis, coordinate);
|
||||
if (flickerTotal < startThreshold)
|
||||
return float4(0, 0, 0, 0);
|
||||
else if (flickerTotal >= endThreshold)
|
||||
return color;
|
||||
|
||||
return float4(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
float4 ApplyDesaturation(float desaturation, float4 color)
|
||||
{
|
||||
if (desaturation == 0.0)
|
||||
return color;
|
||||
|
||||
float3 srgbColor = LinearToSRGB(color.rgb);
|
||||
float grayLevel = dot(srgbColor, float3(3.0, 6.0, 1.0) / 10.0);
|
||||
|
||||
srgbColor = srgbColor * (1.0 - desaturation) + float3(grayLevel, grayLevel, grayLevel) * desaturation;
|
||||
|
||||
return float4(SRGBToLinear(srgbColor), color.a);
|
||||
}
|
Reference in New Issue
Block a user