Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Added mask input to Color Balance, Hue Saturation, Invert, Levels.
Browse files Browse the repository at this point in the history
  • Loading branch information
ttddee committed Feb 10, 2022
1 parent 8a36fc6 commit 767a94d
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 23 deletions.
11 changes: 10 additions & 1 deletion shaders/colorbalance.comp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ layout(set = 0, binding = 3) uniform InputBuffer
layout(offset = 4) float balG;
layout(offset = 8) float balB;
layout(offset = 12) float presLuma;
layout(offset = 16) float useMask;
} sb;

void main()
Expand All @@ -22,7 +23,10 @@ void main()

ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy);

vec4 pixel = imageLoad(inputBack, pixelCoords).rgba;
vec4 pixel = imageLoad(inputBack, pixelCoords).rgba;
float mask = imageLoad(inputFront, pixelCoords).a;

vec4 original = pixel;

float luma = dot(pixel.rgb, vec3(.25, .5, .25));
pixel.r *= 1.0 + sb.balR;
Expand All @@ -31,6 +35,11 @@ void main()
if (sb.presLuma > 0.5) {
pixel.rgb *= luma / dot(pixel.rgb, vec3(.25, .5, .25));
}

if (sb.useMask > 0.5)
{
pixel = mix(original, pixel, mask);
}

imageStore(resultImage, pixelCoords, pixel);

Expand Down
Binary file modified shaders/colorbalance_comp.spv
Binary file not shown.
7 changes: 6 additions & 1 deletion shaders/huesat.comp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ layout(set = 0, binding = 3) uniform InputBuffer
layout(offset = 4) float sat;
layout(offset = 8) float invertLuma;
layout(offset = 12) float invertChroma;
layout(offset = 16) float useMask;
} sb;

#define TWO_PI 6.28318530718
Expand All @@ -25,6 +26,7 @@ void main()
ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy);

vec4 pixel = imageLoad(inputBack, pixelCoords).rgba;
float mask = imageLoad(inputFront, pixelCoords).a;

// The hue is expected to be in radians,
// so we stretch the 0.0 --> 1.0 value here
Expand Down Expand Up @@ -53,7 +55,10 @@ void main()

vec4 result = vec4((luma + chroma * sb.sat * inv), pixel.a);


if (sb.useMask > 0.5)
{
result = mix(pixel, result, mask);
}

imageStore(resultImage, pixelCoords, result);

Expand Down
Binary file modified shaders/huesat_comp.spv
Binary file not shown.
10 changes: 9 additions & 1 deletion shaders/invert.comp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ layout(set = 0, binding = 3) uniform InputBuffer
layout(offset = 4) float bGreen;
layout(offset = 8) float bBlue;
layout(offset = 12) float bAlpha;
layout(offset = 16) float useMask;
} sb;

void main()
{
ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy);

vec4 rgba = imageLoad(inputImage, pixelCoords).rgba;
vec4 rgba = imageLoad(inputImage, pixelCoords).rgba;
float mask = imageLoad(inputImage, pixelCoords).a;
vec4 original = rgba;

if (sb.bRed > 0.0)
{
Expand All @@ -54,6 +57,11 @@ void main()
{
rgba.a = 1.0 - rgba.a;
}

if (sb.useMask > 0.5)
{
rgba = mix(original, rgba, mask);
}

imageStore(resultImage, pixelCoords, rgba);
}
Binary file modified shaders/invert_comp.spv
Binary file not shown.
22 changes: 14 additions & 8 deletions shaders/levels.comp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ layout (binding = 2, rgba32f) uniform image2D resultImage;

layout(set = 0, binding = 3) uniform InputBuffer
{
layout(offset = 0) float aRed;
layout(offset = 4) float aGreen;
layout(offset = 8) float aBlue;
layout(offset = 16) float bRed;
layout(offset = 20) float bGreen;
layout(offset = 24) float bBlue;
layout(offset = 32) float gamma;
layout(offset = 0) float inBlack;
layout(offset = 4) float inWhite;
layout(offset = 8) float gamma;
layout(offset = 12) float outBlack;
layout(offset = 16) float outWhite;
layout(offset = 20) float lumaOnly;
layout(offset = 24) float useMask;
} sb;

void main()
Expand All @@ -26,6 +26,8 @@ void main()
ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy);

vec4 pixel = imageLoad(inputBack, pixelCoords).rgba;
float mask = pixel.a;
vec4 original = pixel;

if (sb.lumaOnly < 0.5)
{
Expand All @@ -43,7 +45,11 @@ void main()
luma = luma * (sb.outWhite - sb.outBlack) + sb.outBlack;
pixel.rgb = luma + chroma;
}

if (sb.useMask > 0.5)
{
pixel = mix(original, pixel, mask);
}

imageStore(resultImage, pixelCoords, pixel);

}
Binary file modified shaders/levels_comp.spv
Binary file not shown.
32 changes: 20 additions & 12 deletions src/nodedefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,15 +597,17 @@ namespace Cascade
NODE_TYPE_INVERT,
nodeStrings[NODE_TYPE_INVERT],
NODE_CATEGORY_COLOR,
{ NODE_INPUT_TYPE_RGB_BACK },
{ NODE_INPUT_TYPE_RGB_BACK,
NODE_INPUT_TYPE_ALPHA },
{ NODE_OUTPUT_TYPE_RGB },
{
{ UI_ELEMENT_TYPE_PROPERTIES_HEADING, nodeStrings[NODE_TYPE_INVERT] },
{ UI_ELEMENT_TYPE_CHANNEL_SELECT, "0" }
{ UI_ELEMENT_TYPE_CHANNEL_SELECT, "0" },
{ UI_ELEMENT_TYPE_CHECKBOX, "Use Mask,0," }
},
FRONT_INPUT_ALWAYS_CLEAR,
BACK_INPUT_RENDER_UPSTREAM_OR_CLEAR,
ALPHA_INPUT_ALWAYS_CLEAR,
ALPHA_INPUT_RENDER_UPSTREAM_OR_CLEAR,
OUTPUT_RENDER_UPSTREAM_OR_CLEAR,
":/shaders/invert_comp.spv",
1
Expand Down Expand Up @@ -831,18 +833,20 @@ namespace Cascade
NODE_TYPE_COLOR_BALANCE,
nodeStrings[NODE_TYPE_COLOR_BALANCE],
NODE_CATEGORY_COLOR,
{ NODE_INPUT_TYPE_RGB_BACK },
{ NODE_INPUT_TYPE_RGB_BACK,
NODE_INPUT_TYPE_ALPHA },
{ NODE_OUTPUT_TYPE_RGB },
{
{ UI_ELEMENT_TYPE_PROPERTIES_HEADING, nodeStrings[NODE_TYPE_COLOR_BALANCE] },
{ UI_ELEMENT_TYPE_SLIDER_BOX_DOUBLE, "Red,-1.0,1.0,0.01,0.0" },
{ UI_ELEMENT_TYPE_SLIDER_BOX_DOUBLE, "Green,-1.0,1.0,0.01,0.0" },
{ UI_ELEMENT_TYPE_SLIDER_BOX_DOUBLE, "Blue,-1.0,1.0,0.01,0.0" },
{ UI_ELEMENT_TYPE_CHECKBOX, "Preserve Luminance,0," }
{ UI_ELEMENT_TYPE_CHECKBOX, "Preserve Luminance,0," },
{ UI_ELEMENT_TYPE_CHECKBOX, "Use Mask,0," }
},
FRONT_INPUT_ALWAYS_CLEAR,
BACK_INPUT_RENDER_UPSTREAM_OR_CLEAR,
ALPHA_INPUT_ALWAYS_CLEAR,
ALPHA_INPUT_RENDER_UPSTREAM_OR_CLEAR,
OUTPUT_RENDER_UPSTREAM_OR_CLEAR,
":/shaders/colorbalance_comp.spv",
1
Expand All @@ -853,18 +857,20 @@ namespace Cascade
NODE_TYPE_HUE_SATURATION,
nodeStrings[NODE_TYPE_HUE_SATURATION],
NODE_CATEGORY_COLOR,
{ NODE_INPUT_TYPE_RGB_BACK },
{ NODE_INPUT_TYPE_RGB_BACK,
NODE_INPUT_TYPE_ALPHA },
{ NODE_OUTPUT_TYPE_RGB },
{
{ UI_ELEMENT_TYPE_PROPERTIES_HEADING, nodeStrings[NODE_TYPE_HUE_SATURATION] },
{ UI_ELEMENT_TYPE_SLIDER_BOX_DOUBLE, "Hue,0.0,1.0,0.01,0.0" },
{ UI_ELEMENT_TYPE_SLIDER_BOX_DOUBLE, "Saturation,0.0,5.0,0.01,1.0" },
{ UI_ELEMENT_TYPE_CHECKBOX, "Invert Luminance,0," },
{ UI_ELEMENT_TYPE_CHECKBOX, "Invert Chroma,0," }
{ UI_ELEMENT_TYPE_CHECKBOX, "Invert Chroma,0," },
{ UI_ELEMENT_TYPE_CHECKBOX, "Use Mask,0," }
},
FRONT_INPUT_ALWAYS_CLEAR,
BACK_INPUT_RENDER_UPSTREAM_OR_CLEAR,
ALPHA_INPUT_ALWAYS_CLEAR,
ALPHA_INPUT_RENDER_UPSTREAM_OR_CLEAR,
OUTPUT_RENDER_UPSTREAM_OR_CLEAR,
":/shaders/huesat_comp.spv",
1
Expand All @@ -875,7 +881,8 @@ namespace Cascade
NODE_TYPE_LEVELS,
nodeStrings[NODE_TYPE_LEVELS],
NODE_CATEGORY_COLOR,
{ NODE_INPUT_TYPE_RGB_BACK },
{ NODE_INPUT_TYPE_RGB_BACK,
NODE_INPUT_TYPE_ALPHA },
{ NODE_OUTPUT_TYPE_RGB },
{
{ UI_ELEMENT_TYPE_PROPERTIES_HEADING, nodeStrings[NODE_TYPE_LEVELS] },
Expand All @@ -884,11 +891,12 @@ namespace Cascade
{ UI_ELEMENT_TYPE_SLIDER_BOX_DOUBLE, "Gamma,0.2,5.0,0.01,1.0" },
{ UI_ELEMENT_TYPE_SLIDER_BOX_DOUBLE, "Out Black,0.0,1.0,0.01,0.0" },
{ UI_ELEMENT_TYPE_SLIDER_BOX_DOUBLE, "Out White,0.0,1.0,0.01,1.0" },
{ UI_ELEMENT_TYPE_CHECKBOX, "Luminance Only,0," }
{ UI_ELEMENT_TYPE_CHECKBOX, "Luminance Only,0," },
{ UI_ELEMENT_TYPE_CHECKBOX, "Use Mask,0," }
},
FRONT_INPUT_ALWAYS_CLEAR,
BACK_INPUT_RENDER_UPSTREAM_OR_CLEAR,
ALPHA_INPUT_ALWAYS_CLEAR,
ALPHA_INPUT_RENDER_UPSTREAM_OR_CLEAR,
OUTPUT_RENDER_UPSTREAM_OR_CLEAR,
":/shaders/levels_comp.spv",
1
Expand Down

0 comments on commit 767a94d

Please sign in to comment.