Global delta

  • Posts: 56
8 months 2 weeks ago - 2 weeks 2 days ago #1 by crabshank
Allows global increase and decrease of a channel:


That middle point goes up and down the dashed line, meaning that every value in the channel is higher or lower than it otherwise would be, except 0 and 1.
0 and 1 stay fixed where they are.

You can chose to not apply RGB adjustments to to certain hue ranges.
#include "ReShadeUI.fxh";

uniform float redDeltaAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = -1.0; ui_max=1.0;
> = 0;

uniform float greenDeltaAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = -1.0; ui_max=1.0;
> = 0;

uniform float blueDeltaAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = -1.0; ui_max=1.0;
> = 0;
	
uniform bool avoid_grey <> = true;

uniform bool Red <ui_category="Select_color";> = true;
uniform bool Orange <ui_category="Select_color";> = true;
uniform bool Yellow <ui_category="Select_color";> = true;
uniform bool Chartreuse_Lime <ui_category="Select_color";> = true;
uniform bool Green <ui_category="Select_color";> = true;
uniform bool Spring_green <ui_category="Select_color";> = true;
uniform bool Cyan <ui_category="Select_color";> = true;
uniform bool Azure__Sky_blue <ui_category="Select_color";> = true;
uniform bool Blue <ui_category="Select_color";> = true;
uniform bool Violet__Purple <ui_category="Select_color";> = true;
uniform bool Magenta__Pink <ui_category="Select_color";> = true;
uniform bool Reddish_pink <ui_category="Select_color";> = true;

#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 delta(float color, float dlt){
dlt=-0.5*dlt+0.5;
float2 midp=float2(lerp(0,1,dlt),lerp(1,0,dlt));
float relx=color/midp.x;
float relxInv=(1-color)/(1-midp.x);

float newyLow=lerp(0,midp.y,relx);
float newyHi=lerp(1,midp.y,relxInv);

color=(color<=midp.x)?newyLow:newyHi;

return color;
}


float4 change(float4 c0){

float3 colorHSV=rgb2hsv(c0.rgb);

c0.rgb=(c0.rgb > 0.0404482362771082)?pow(abs((c0.rgb+0.055)/1.055),2.4):c0.rgb/12.92;

float4 c0Lin=c0;

c0.r=(redDeltaAmnt==0)?c0.r:delta(c0.r,redDeltaAmnt);

c0.g=(greenDeltaAmnt==0)?c0.g:delta(c0.g,greenDeltaAmnt);

c0.b=(blueDeltaAmnt==0)?c0.b:delta(c0.b,blueDeltaAmnt);

c0.rgb=(avoid_grey==true)?lerp(c0Lin.rgb,c0.rgb,colorHSV.y*colorHSV.z):c0.rgb;

c0.rgb=( c0.rgb > 0.00313066844250063 )?1.055 * pow(abs(c0.rgb),1/2.4) - 0.055:12.92 *c0.rgb;

return c0;

}

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

float4 c0=tex2D(ReShade::BackBuffer, texcoord);
float3 c0_hsv=rgb2hsv(c0.rgb);

float4 c1=change(c0);

int hue=floor(c0_hsv.x*3600);
int grey=(((c0.r==c0.g)&&(c0.g==c0.b))||(c0_hsv.y==0))?1:0;

[flatten]if((hue>=3535)||(((hue>=0) && (hue<75))&&(grey==0))){
c1.rgb=(Red==true)?c1.rgb:c0.rgb;
}else if((hue>=75) && (hue<375)){
c1.rgb=(Orange==true)?c1.rgb:c0.rgb;
}else if((hue>=375) && (hue<675)){
c1.rgb=(Yellow==true)?c1.rgb:c0.rgb;
}else if((hue>=675) && (hue<975)){
c1.rgb=(Chartreuse_Lime==true)?c1.rgb:c0.rgb;
}else if((hue>=975) && (hue<1275)){
c1.rgb=(Green==true)?c1.rgb:c0.rgb;
}else if((hue>=1275) && (hue<1575)){
c1.rgb=(Spring_green==true)?c1.rgb:c0.rgb;
}else if((hue>=1575) && (hue<1875)){
c1.rgb=(Cyan==true)?c1.rgb:c0.rgb;
}else if((hue>=1875) && (hue<2175)){
c1.rgb=(Azure__Sky_blue==true)?c1.rgb:c0.rgb;
}else if((hue>=2175) && (hue<2475)){
c1.rgb=(Blue==true)?c1.rgb:c0.rgb;
}else if((hue>=2475) && (hue<3075)){
c1.rgb=(Violet__Purple==true)?c1.rgb:c0.rgb;
}else if((hue>=3075) && (hue<3375)){
c1.rgb=(Magenta__Pink==true)?c1.rgb:c0.rgb;
}else if((hue>=3375) && (hue<3535)){
c1.rgb=(Reddish_pink==true)?c1.rgb:c0.rgb;
}

return c1;

}

technique Global_delta
{
	pass
	{
		VertexShader = PostProcessVS;
		PixelShader = deltaPass;
	}
}

HLSL version here
The following user(s) said Thank You: jas01, Faustus86

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

  • Posts: 56
8 months 4 days ago #2 by crabshank
I figured out that the best use of this shader is for tint removal after using the White Point shader, as there have been many occasions where there has been a red tint even with an an optimal white point.

I also suggest using Distance_to_grey.fx after this one to act as a debugging/calibration tool.

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

  • Posts: 53
8 months 4 days ago #3 by Faustus86

crabshank wrote: I figured out that the best use of this shader is for tint removal after using the White Point shader, as there have been many occasions where there has been a red tint even with an an optimal white point.

I also suggest using Distance_to_grey.fx after this one to act as a debugging/calibration tool.


Exactly what i need right now. Thank you =)
The following user(s) said Thank You: crabshank

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

  • Posts: 56
6 months 2 weeks ago #4 by crabshank
Update: Linearises the RGB before adjustment and re-gamma corrects it afterwards.

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

  • Posts: 56
4 months 13 hours ago - 2 months 1 week ago #5 by crabshank
UPDATE: Included "avoid_grey" option which makes the shader have less of an effect as the chroma decreases. Makes the result look better when using rgbDeltaAmnt and greyDeltaAmnt. I have aslo removed split because Before and After work fine.

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

  • Posts: 56
2 weeks 2 days ago #6 by crabshank
Now just an RGB adjustment shader, but allows application on certain hue ranges (as in my Colour Isolate shader).

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