Skip to content

Commit

Permalink
Merge pull request #13 from papadanku/dev
Browse files Browse the repository at this point in the history
cBlend: Implemented blending alpha-channels
  • Loading branch information
papadanku authored Oct 26, 2024
2 parents fb9eee0 + f8c09d6 commit 6afce50
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 43 deletions.
52 changes: 21 additions & 31 deletions shaders/cBlend.fx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
[Shader Options]
*/

uniform int _Blend <
ui_label = "Blend Mode";
#include "shared/cColor.fxh"

uniform int _ColorBlend <
ui_label = "Color Blend Mode";
ui_type = "combo";
ui_items = "Normal\0Multiply\0Screen\0Overlay\0Darken\0Lighten\0Color Dodge\0Color Burn\0Hard Light\0Soft Light\0Difference\0Exclusion\0";
> = 0;

uniform int _AlphaBlend <
ui_label = "Alpha Blend Mode";
ui_type = "combo";
ui_items = "Add\0Subtract\0Multiply\0Min\0Max\0Screen\0";
ui_items = "Normal\0Multiply\0Screen\0Overlay\0Darken\0Lighten\0Color Dodge\0Color Burn\0Hard Light\0Soft Light\0Difference\0Exclusion\0";
> = 0;

uniform float3 _SrcFactor <
Expand Down Expand Up @@ -44,37 +52,19 @@ float4 PS_Copy(CShade_VS2PS_Quad Input) : SV_TARGET0

float4 PS_Blend(CShade_VS2PS_Quad Input) : SV_TARGET0
{
float4 Src = tex2D(SampleSrcTex, Input.Tex0) * float4(_SrcFactor, 1.0);
float4 Dest = tex2D(SampleDestTex, Input.Tex0) * float4(_DestFactor, 1.0);
float4 Src = tex2D(SampleSrcTex, Input.Tex0);
float4 Dest = tex2D(SampleDestTex, Input.Tex0);

float4 OutputColor = 0.0;
Src.rgb *= _SrcFactor;
Dest.rgb *= _DestFactor;

switch(_Blend)
{
case 0: // Add
OutputColor = Src + Dest;
break;
case 1: // Subtract
OutputColor = Src - Dest;
break;
case 2: // Multiply
OutputColor = Src * Dest;
break;
case 3: // Min
OutputColor = min(Src, Dest);
break;
case 4: // Max
OutputColor = max(Src, Dest);
break;
case 5: // Screen
OutputColor = (Src + Dest) - (Src * Dest);
break;
default:
OutputColor = Dest;
break;
}
float3 SrcAlpha = Src.a;
float3 DestAlpha = Dest.a;

float3 ColorBlend = CColor_Blend(Dest.rgb, Src.rgb, _ColorBlend);
float AlphaBlend = CColor_Blend(DestAlpha, SrcAlpha, _AlphaBlend).r;

return OutputColor;
return float4(ColorBlend, AlphaBlend);
}

technique CShade_CopyBuffer < ui_tooltip = "Create CBlend's copy texture"; >
Expand Down
4 changes: 2 additions & 2 deletions shaders/cRaySchism.fx
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ uniform float _GradeBalance <
ui_category = "Color Grading | Split Toning";
ui_label = "Balance";
ui_type = "slider";
ui_min = -100.0;
ui_max = 100.0;
ui_min = -1.0;
ui_max = 1.0;
> = 0.0;

uniform float3 _GradeMixRed <
Expand Down
22 changes: 12 additions & 10 deletions shaders/shared/cColor.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
return CColor_BlendDifference(B, S);
case 11: // Exclusion
return CColor_BlendExclusion(B, S);
default:
return CColor_BlendNormal(B, S);
}
}

Expand Down Expand Up @@ -349,22 +351,22 @@

static const float3x3 CColor_OKLABfromRGB_M1 = float3x3
(
float3(0.4122214708, +0.5363325363, +0.0514459929),
float3(0.2119034982, +0.6806995451, +0.1073969566),
float3(0.0883024619, +0.2817188376, +0.6299787005)
float3(+0.4122214708, +0.5363325363, +0.0514459929),
float3(+0.2119034982, +0.6806995451, +0.1073969566),
float3(+0.0883024619, +0.2817188376, +0.6299787005)
);

static const float3x3 CColor_OKLABfromRGB_M2 = float3x3
(
float3(0.2104542553, +0.7936177850f, -0.0040720468),
float3(1.9779984951, -2.4285922050f, +0.4505937099),
float3(0.0259040371, +0.7827717662f, -0.8086757660)
float3(+0.2104542553, +0.7936177850f, -0.0040720468),
float3(+1.9779984951, -2.4285922050f, +0.4505937099),
float3(+0.0259040371, +0.7827717662f, -0.8086757660)
);

float3 CColor_GetOKLABfromRGB(float3 Color)
{
float3 LMS = mul(CColor_OKLABfromRGB_M1, Color);
LMS = pow(LMS, 1.0 / 3.0);
LMS = pow(abs(LMS), 1.0 / 3.0);
LMS = mul(CColor_OKLABfromRGB_M2, LMS);
return LMS;
};
Expand Down Expand Up @@ -531,8 +533,8 @@
float Temperature, // [-1.0, 1.0); default = 0.0
float Tint, // [-1.0, 1.0); default = 0.0
float3 Shadows, // [0.0, 1.0); default = float3(0.5, 0.5, 0.5)
float3 HighLights, // [0.0, 1.0); default = float3(0.5, 0.5, 0.5)
float Balance, // [-100.0, 100.0); default = 0.0
float3 Highlights, // [0.0, 1.0); default = float3(0.5, 0.5, 0.5)
float Balance, // [-1.0, 1.0); default = 0.0
float3 MixRed, // [0.0, 1.0); default = float3(1.0, 0.0, 0.0)
float3 MixGreen, // [0.0, 1.0); default = float3(0.0, 1.0, 0.0)
float3 MixBlue, // [0.0, 1.0); default = float3(0.0, 0.0, 1.0)
Expand Down Expand Up @@ -593,7 +595,7 @@
Color = pow(abs(Color), 1.0 / 2.2);
float T = saturate(CColor_GetLuma(Color, 0) + Balance);
float3 SplitShadows = lerp(0.5, Shadows, 1.0 - T);
float3 SplitHighlights = lerp(0.5, HighLights, T);
float3 SplitHighlights = lerp(0.5, Highlights, T);
Color = CColor_BlendSoftLight(Color, SplitShadows);
Color = CColor_BlendSoftLight(Color, SplitHighlights);
Color = pow(abs(Color), 2.2);
Expand Down

0 comments on commit 6afce50

Please sign in to comment.