[HLSL CODE] RGBL Curve (Cubic Bezier)
Posted: 10 Sep 2018, 17:51
Hey... its me again. So i am slowly learing how to make basic Shaders. I trew a bunch of code together and rewrote it a little.
This allows Photoshop like curves in ENB. Preview: http://cubic-bezier.com/#.17,.67,.83,.67
I used parts of code from Prod80 and Ceejay.dk in this but it has mostly been rewritten. Thought ill mention it anyways.
Also i am still a noob with Shaders so feel free to correct me if i did something wrong.
i made this code with Sandvich Makers Macros viewtopic.php?f=6&t=5961
So you will need that or youll need to rewrite the UI on your own. This however allows you to also Let these work in DNI or else without mutch work (just change the "UI_FLOAT" to "UI_FLOAT_DNI")
so here the UI:
Afterwards The functions. Place these before the Pixel Shader:
In the end call the function in your pixel Shader
Feel free to use it freely anywere or change it however you want.
I don't mind if you don't credit me but it would be nice
https://discord.gg/PtCUgab lil discord :3
This allows Photoshop like curves in ENB. Preview: http://cubic-bezier.com/#.17,.67,.83,.67
I used parts of code from Prod80 and Ceejay.dk in this but it has mostly been rewritten. Thought ill mention it anyways.
Also i am still a noob with Shaders so feel free to correct me if i did something wrong.
i made this code with Sandvich Makers Macros viewtopic.php?f=6&t=5961
So you will need that or youll need to rewrite the UI on your own. This however allows you to also Let these work in DNI or else without mutch work (just change the "UI_FLOAT" to "UI_FLOAT_DNI")
so here the UI:
Code: Select all
#include "Reforged/ReforgedUI.fxh"
UI_INT(BlendMode, "Curve Blend Mode", 0.0, 13.0, 0.0)
#define UI_CATEGORY Mode
#define UI_PREFIX_MODE PREFIX
UI_MESSAGE(1, "1 = Darken, 2 = Multiply")
UI_MESSAGE(2, "3 = Linearburn, 4 = Colorburn")
UI_MESSAGE(3, "5 = Lighten, 6 = Screen")
UI_MESSAGE(4, "7 = Colordodge, 8 = Lineardodge")
UI_MESSAGE(5, "9 = Overlay, 10 = Softlight")
UI_MESSAGE(6, "11 = Vividlight, 12 = Linearlight")
UI_MESSAGE(7, "13 = Pinlight, 0 = Bypass")
UI_WHITESPACE(1)
#define UI_CATEGORY Luma
#define UI_PREFIX_MODE PREFIX
UI_SEPARATOR_CUSTOM ("Luminace Curve")
UI_FLOAT(CurveBlendL, "Curve Power", 0.0, 1.0, 0.0)
UI_FLOAT(LSP, "Curve Startpoint", -50.0, 50.0, 0.0)
UI_FLOAT(LCP1, "Curve Control Point 1", -50.0, 50.0, 0.0)
UI_FLOAT(LCP2, "Curve Control Point 2", -50.0, 50.0, 0.0)
UI_FLOAT(LEP, "Curve End Point", -50.0, 50.0, 1.0)
UI_WHITESPACE(2)
#define UI_CATEGORY Red
#define UI_PREFIX_MODE PREFIX
UI_SEPARATOR_CUSTOM ("Red Curve")
UI_FLOAT(CurveBlendR, "Curve Power", 0.0, 1.0, 0.0)
UI_FLOAT(RSP, "Curve Startpoint", -50.0, 50.0, 0.0)
UI_FLOAT(RCP1, "Curve Control Point 1", -50.0, 50.0, 0.0)
UI_FLOAT(RCP2, "Curve Control Point 2", -50.0, 50.0, 0.0)
UI_FLOAT(REP, "Curve End Point", -50.0, 50.0, 1.0)
UI_WHITESPACE(3)
#define UI_CATEGORY Green
#define UI_PREFIX_MODE PREFIX
UI_SEPARATOR_CUSTOM ("Green Curve")
UI_FLOAT(CurveBlendG, "Curve Power", 0.0, 1.0, 0.0)
UI_FLOAT(GSP, "Curve Startpoint", -50.0, 50.0, 0.0)
UI_FLOAT(GCP1, "Curve Control Point 1", -50.0, 50.0, 0.0)
UI_FLOAT(GCP2, "Curve Control Point 2", -50.0, 50.0, 0.0)
UI_FLOAT(GEP, "Curve End Point", -50.0, 50.0, 1.0)
UI_WHITESPACE(4)
#define UI_CATEGORY Blue
#define UI_PREFIX_MODE PREFIX
UI_SEPARATOR_CUSTOM ("Blue Curve")
UI_FLOAT(CurveBlendB, "Curve Power", 0.0, 1.0, 0.0)
UI_FLOAT(BSP, "Curve Startpoint", -50.0, 50.0, 0.0)
UI_FLOAT(BCP1, "Curve Control Point 1", -50.0, 50.0, 0.0)
UI_FLOAT(BCP2, "Curve Control Point 2", -50.0, 50.0, 0.0)
UI_FLOAT(BEP, "Curve End Point", -50.0, 50.0, 1.0)
Code: Select all
// Photoshop Blend modes (Needs LDR)
float3 darken(float3 c, float3 b) { return min(b, c);}
float3 multiply(float3 c, float3 b) { return c*b;}
float3 linearburn(float3 c, float3 b) { return max(c+b-1, 0);}
float3 colorburn(float3 c, float3 b) { return b==0 ? b:max((1-((1-c)/b)), 0);}
float3 lighten(float3 c, float3 b) { return max(b, c);}
float3 screen(float3 c, float3 b) { return 1-(1-c)*(1-b);}
float3 colordodge(float3 c, float3 b) { return b==1 ? b:min(c/(1-b), 1);}
float3 lineardodge(float3 c, float3 b) { return min(c+b, 1);}
float3 overlay(float3 c, float3 b) { return c<0.5 ? 2*c*b:(1-2*(1-c)*(1-b));}
float3 softlight(float3 c, float3 b) { return b<0.5 ? (2*c*b+c*c*(1-2*b)):(sqrt(c)*(2*b-1)+2*c*(1-b));}
float3 vividlight(float3 c, float3 b) { return b<0.5 ? colorburn(c, (2*b)):colordodge(c, (2*(b-0.5)));}
float3 linearlight(float3 c, float3 b) { return b<0.5 ? linearburn(c, (2*b)):lineardodge(c, (2*(b-0.5)));}
float3 pinlight(float3 c, float3 b) { return b<0.5 ? darken(c, (2*b)):lighten(c, (2*(b-0.5)));}
float Curve(float x, float4 CurveValues)
{
x = CurveValues.x*(1-x)*(1-x)*(1-x) + 3*CurveValues.y*(1-x)*(1-x)*x + 3*CurveValues.z*(1-x)*x*x + CurveValues.w*x*x*x;
return max(x, 0);
}
float3 CurveCombine(float3 Color)
{
// Calculate luma (grey)
float3 lumCoeff = float3(0.2126, 0.7152, 0.0722);
float Luma = dot(lumCoeff, Color.rgb);
// Calculate chroma
float3 Chroma = Color.rgb - Luma;
// Pack up tweakable values so we dont need 4 times the same function
float4 RedCurve, GreenCurve, BlueCurve, LumaCurve;
RedCurve.x = RSP, RedCurve.y = RCP1, RedCurve.z = RCP2, RedCurve.w = REP;
GreenCurve.x = GSP, GreenCurve.y = GCP1, GreenCurve.z = GCP2, GreenCurve.w = GEP;
BlueCurve.x = BSP, BlueCurve.y = BCP1, BlueCurve.z = BCP2, BlueCurve.w = BEP;
LumaCurve.x = LSP, LumaCurve.y = LCP1, LumaCurve.z = LCP2, LumaCurve.w = LEP;
// Apply
Chroma.r = lerp(Chroma.r, Curve(saturate(Chroma.r), RedCurve), CurveBlendR); // Red
Chroma.g = lerp(Chroma.g, Curve(saturate(Chroma.g), GreenCurve), CurveBlendG); // Green
Chroma.b = lerp(Chroma.b, Curve(saturate(Chroma.b), BlueCurve), CurveBlendB); // Blue
Luma = lerp(Luma, Curve(saturate(Luma), LumaCurve), CurveBlendL); // Luminace
return Chroma + Luma; // Combine
}
float3 CurveMixFinal(float3 Color)
{
Color = saturate(Color); // Cuz LDR right?
if (BlendMode==1) { Color = darken (Color, CurveCombine(Color)); }
if (BlendMode==2) { Color = multiply (Color, CurveCombine(Color)); }
if (BlendMode==3) { Color = linearburn (Color, CurveCombine(Color)); }
if (BlendMode==4) { Color = colorburn (Color, CurveCombine(Color)); }
if (BlendMode==5) { Color = lighten (Color, CurveCombine(Color)); }
if (BlendMode==6) { Color = screen (Color, CurveCombine(Color)); }
if (BlendMode==7) { Color = colordodge (Color, CurveCombine(Color)); }
if (BlendMode==8) { Color = lineardodge (Color, CurveCombine(Color)); }
if (BlendMode==9) { Color = overlay (Color, CurveCombine(Color)); }
if (BlendMode==10) { Color = softlight (Color, CurveCombine(Color)); }
if (BlendMode==11) { Color = vividlight (Color, CurveCombine(Color)); }
if (BlendMode==12) { Color = linearlight (Color, CurveCombine(Color)); }
if (BlendMode==13) { Color = pinlight (Color, CurveCombine(Color)); }
return Color;
}
Code: Select all
Color.rgb = CurveMixFinal(Color);
I don't mind if you don't credit me but it would be nice
https://discord.gg/PtCUgab lil discord :3