Welcome, Guest.
Username: Password: Remember me

TOPIC: S-curves

S-curves 2 weeks 3 days ago #1

Used drag instead of sliders for input for greater sensitivity.


#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;
> = 1;

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

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

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

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

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

uniform float greyChangeAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = 0.0; ui_max = 5.0;
> = 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, float gamma){

color*=2;
color=(color<0.5)?pow(abs(0.5*color),gamma):1-(0.5*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){
float3 colorHSV=rgb2hsv(c0.rgb);
float3 colorHSVOg=colorHSV;
float c0Max=max(c0.r,max(c0.g,c0.b));

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

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

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

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

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

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

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

return c0;

}


float4 ScurvePass(float4 vpos : SV_Position, float2 texcoord : TexCoord) : SV_Target
{

float4 c0=tex2D(ReShade::BackBuffer, texcoord);

float4 c1=sCurve(c0, texcoord);

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

float4 c4=(Flip_split*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: 2 days 11 hours ago by crabshank.
The administrator has disabled public write access.
The following user(s) said Thank You: Wicked Sick, jas01, andrew, Ryukou36, Viper_Joe, Raughie

S-curves 2 weeks 3 days ago #2

I really like your dynamic debug/ split-screen options. I wish it could be used with other shaders as well.
The administrator has disabled public write access.

S-curves 2 weeks 2 days ago #3

I can make any shader have that cos I have a template I use.
The administrator has disabled public write access.

S-curves 1 week 2 days ago #4

Adjusted S-curves because grey dither was inherently lossy, it's lossless now so make sure to download the update.
The administrator has disabled public write access.
The following user(s) said Thank You: jas01

S-curves 2 days 11 hours ago #5

Optimised ^. Now includes hue rotation.
The administrator has disabled public write access.