S-curves

  • crabshank
  • Topic Author
More
4 years 8 months ago - 4 years 3 months ago #1 by crabshank S-curves was created by crabshank
UPDATE:
Made shader a two stage one, adjusting high/lowlights and mids semi-separately:

#include "ReShadeUI.fxh";

uniform float hueRotateAmnt < __UNIFORM_SLIDER_FLOAT1
	ui_min = -360.000; ui_max=360.000;
> = 0;

uniform float satChangeAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.000; ui_max=5.000; ui_category="High_lowlights";
> = 1;

uniform float valChangeAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="High_lowlights";
> = 1;

uniform float redChangeAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="High_lowlights";
> = 1;

uniform float greenChangeAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="High_lowlights";
> = 1;

uniform float blueChangeAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="High_lowlights";
> = 1;

uniform float rgbChangeAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="High_lowlights";
> = 1;

uniform float greyChangeAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="High_lowlights";
> = 1;

uniform float satChangeAmntMd < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.000; ui_max=5.000; ui_category="Mids";
> = 1;

uniform float valChangeAmntMd < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="Mids";
> = 1;

uniform float redChangeAmntMd < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="Mids";
> = 1;

uniform float greenChangeAmntMd < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="Mids";
> = 1;

uniform float blueChangeAmntMd < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="Mids";
> = 1;

uniform float rgbChangeAmntMd < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="Mids";
> = 1;

uniform float greyChangeAmntMd < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0; ui_category="Mids";
> = 1;

uniform bool Split <> = false;

uniform bool Flip_split <> = false;

uniform float Split_position < __UNIFORM_SLIDER_FLOAT1
	ui_min = 0; ui_max =1;
	ui_tooltip = "0 is on the far left, 1 on the far right.";
> = 0.5;


#include "ReShade.fxh";


	float3 rgb2hsv(float3 c)
{
    float4 K = float4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
    float4 p = lerp(float4(c.bg, K.wz), float4(c.gb, K.xy), step(c.b, c.g));
    float4 q = lerp(float4(p.xyw, c.r), float4(c.r, p.yzx), step(p.x, c.r));
 
    float d = q.x - min(q.w, q.y);
    float e = 1.0e-10;
    return float3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
}


float3 hsv2rgb(float3 c)
{
    float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
    float3 p = abs(frac(c.xxx + K.xyz) * 6.0 - K.www);
    return c.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
//Source: http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl

float s_curver(float color, int mid, float gamma){
color*=2;
[flatten]if(mid==1){
color=(color<1)?0.5*(1-pow(abs(1-color),gamma)):0.5*(pow(abs(color-1),gamma)+1);
}else{
color=(color<1)?pow(abs(0.5*color),gamma):0.5*(2-pow(abs(2-color),gamma));
}
return color;
}


float hue_rotate(float hue, float deg){

deg*=pow(360,-1);

float r=hue+deg;

float r1=(r<=1)?r:r-1;
hue=(r<0)?1+r:r1;

return hue;
}


float4 sCurve(float4 c0, float2 tex, float mids){
float3 colorHSV=rgb2hsv(c0.rgb);
float3 colorHSVOg=colorHSV;
float c0Max=max(c0.r,max(c0.g,c0.b));
	

[branch]if(mids==1){

colorHSV.y=(satChangeAmntMd==1)?colorHSV.y:s_curver(colorHSV.y,1,satChangeAmntMd);

colorHSV.z=(valChangeAmntMd==1)?colorHSV.z:s_curver(colorHSV.z,1,valChangeAmntMd);
	
c0.rgb=(colorHSVOg==colorHSV)?c0.rgb:hsv2rgb(colorHSV);

c0.r =(redChangeAmntMd==1)?c0.r:s_curver(c0.r,1,redChangeAmntMd);

c0.g =(greenChangeAmntMd==1)?c0.g:s_curver(c0.g,1,greenChangeAmntMd);

c0.b =(blueChangeAmntMd==1)?c0.b:s_curver(c0.b,1,blueChangeAmntMd);

c0.rgb =(rgbChangeAmntMd==1)?c0.rgb:float3(s_curver(c0.r,1,rgbChangeAmntMd),s_curver(c0.g,1,rgbChangeAmntMd),s_curver(c0.b,1,rgbChangeAmntMd));

c0.rgb =(greyChangeAmntMd==1)?c0.rgb:saturate(s_curver(c0Max,1,greyChangeAmntMd)*(c0.rgb/c0Max));

}else{

colorHSV.y=(satChangeAmnt==1)?colorHSV.y:s_curver(colorHSV.y,0,satChangeAmnt);

colorHSV.z=(valChangeAmnt==1)?colorHSV.z:s_curver(colorHSV.z,0,valChangeAmnt);
	
c0.rgb=(colorHSVOg==colorHSV)?c0.rgb:hsv2rgb(colorHSV);

c0.r =(redChangeAmnt==1)?c0.r:s_curver(c0.r,0,redChangeAmnt);

c0.g =(greenChangeAmnt==1)?c0.g:s_curver(c0.g,0,greenChangeAmnt);

c0.b =(blueChangeAmnt==1)?c0.b:s_curver(c0.b,0,blueChangeAmnt);

c0.rgb =(rgbChangeAmnt==1)?c0.rgb:float3(s_curver(c0.r,0,rgbChangeAmnt),s_curver(c0.g,0,rgbChangeAmnt),s_curver(c0.b,0,rgbChangeAmnt));

c0.rgb =(greyChangeAmnt==1)?c0.rgb:saturate(s_curver(c0Max,0,greyChangeAmnt)*(c0.rgb/c0Max));

}
return c0;
}

float4 ScurvePass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
	
float4 c0=tex2D(ReShade::BackBuffer, texcoord);

float3 colorHSV=rgb2hsv(c0.rgb);
float3 colorHSVOg=colorHSV;

colorHSV.x=(hueRotateAmnt==0)?colorHSV.x:hue_rotate(colorHSV.x,hueRotateAmnt);

c0.rgb=(colorHSVOg==colorHSV)?c0.rgb:hsv2rgb(colorHSV);
float4 c1=c0;

c1=sCurve(c1, texcoord,0);
c1.rgb=(c0.rgb==c1.rgb)?c0.rgb:lerp(c0.rgb,c1.rgb,2*abs(0.5-c1.rgb));
float4 colHL=c1;

c1=sCurve(c1, texcoord,1);
c1.rgb=(c1.rgb==colHL.rgb)?colHL.rgb:lerp(c1.rgb,c0.rgb,2*abs(0.5-c1.rgb));

float4 c2=(texcoord.x>=Split_position*Split)?c1:c0;
float4 c3=(texcoord.x<=Split_position*Split)?c1:c0;

float4 c4=(Flip_split ==1 && Split==1)?c3:c2;

float divLine = abs(texcoord.x - Split_position) < BUFFER_RCP_WIDTH;
c4 =(Split==0)?c4: c4*(1.0 - divLine); //invert divline

return c4;
}

technique Scurve
{
	pass
	{
		VertexShader = PostProcessVS;
		PixelShader = ScurvePass;
	}
}

Version for videos here .
Last edit: 4 years 3 months ago by crabshank. Reason: Changed mids formula
The following user(s) said Thank You: Wicked Sick, jas01, andrew, Ryukou36, Viper_Joe, Marty, Raughie, Faustus86

Please Log in or Create an account to join the conversation.

  • jas01
More
4 years 8 months ago #2 by jas01 Replied by jas01 on topic S-curves
I really like your dynamic debug/ split-screen options. I wish it could be used with other shaders as well.

Please Log in or Create an account to join the conversation.

  • crabshank
  • Topic Author
More
4 years 8 months ago #3 by crabshank Replied by crabshank on topic S-curves
I can make any shader have that cos I have a template I use.
The following user(s) said Thank You: Faustus86

Please Log in or Create an account to join the conversation.

  • crabshank
  • Topic Author
More
4 years 8 months ago #4 by crabshank Replied by crabshank on topic S-curves
Adjusted S-curves because grey dither was inherently lossy, it's lossless now so make sure to download the update.
The following user(s) said Thank You: jas01, Faustus86

Please Log in or Create an account to join the conversation.

  • crabshank
  • Topic Author
More
4 years 8 months ago #5 by crabshank Replied by crabshank on topic S-curves
Optimised ^. Now includes hue rotation.
The following user(s) said Thank You: jas01, Faustus86

Please Log in or Create an account to join the conversation.

  • crabshank
  • Topic Author
More
4 years 7 months ago #6 by crabshank Replied by crabshank on topic S-curves
UPDATE:
I have a new setting "Curve_mids" that affects the darks and highlights less and less as they approach 0 and 1 and thus only curves the mids.
The following user(s) said Thank You: Wicked Sick, jas01, Faustus86

Please Log in or Create an account to join the conversation.

  • crabshank
  • Topic Author
More
4 years 7 months ago #7 by crabshank Replied by crabshank on topic S-curves
UPDATE:
I semi-separated S-curves on the high/lowlights and on the mids in an effort to get that 'looking at the action through a window' look. Before, certain parts looked blown out and now this is much reduced.
The following user(s) said Thank You: jas01, Faustus86

Please Log in or Create an account to join the conversation.

  • Faustus86
More
4 years 7 months ago - 4 years 7 months ago #8 by Faustus86 Replied by Faustus86 on topic S-curves
Hey =)

I have just downloaded all your shaders and now i am testing with them.
Usually i am using photoshop + LUT Maps for color grading wich is pretty awesome but most often i still need a lot of fine tuning ingame by using Lightroom by Marty + HSLShift. After some testing i have to say your shader's are truly awesome and the splitscreen option is very helpful too, thank you so much =)

I hope crosire will add them to the standard shaders, i find them extremely helpful to get rid of tinting, fine tune shadows and change specific color values. Saves a lot of time and effort switching between photoshop and reshade, i can tell you that =)
Last edit: 4 years 7 months ago by Faustus86.
The following user(s) said Thank You: crabshank

Please Log in or Create an account to join the conversation.

  • crabshank
  • Topic Author
More
4 years 7 months ago #9 by crabshank Replied by crabshank on topic S-curves
Thanks man. Make sure you try out my updated grey gamma shader for more control over the dynamic range.

Please Log in or Create an account to join the conversation.

  • crabshank
  • Topic Author
More
4 years 6 months ago #10 by crabshank Replied by crabshank on topic S-curves
I have fixed an issue that made all my shaders incompatible with OpenGL and I have removed a random empty function from this one.
The following user(s) said Thank You: jas01

Please Log in or Create an account to join the conversation.

  • Wicked Sick
More
4 years 6 months ago #11 by Wicked Sick Replied by Wicked Sick on topic S-curves
Man, thanks for updating this shader!
The following user(s) said Thank You: crabshank

Please Log in or Create an account to join the conversation.

  • crabshank
  • Topic Author
More
4 years 3 months ago #12 by crabshank Replied by crabshank on topic S-curves
UPDATE: Changed mids formula.

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.