Welcome, Guest.
Username: Password: Remember me

TOPIC: Global delta

Global delta 2 months 2 weeks ago #1

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.


#include "ReShadeUI.fxh";


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

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


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 float rgbDeltaAmnt < __UNIFORM_DRAG_FLOAT1
	ui_min = -1.0; ui_max=1.0;
> = 0;


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

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 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, float2 tex){
float3 colorHSV=rgb2hsv(c0.rgb);
float3 colorHSVOg=colorHSV;



colorHSV.y=(satDeltaAmnt==0)?colorHSV.y:delta(colorHSV.y,satDeltaAmnt);

colorHSV.z=(valDeltaAmnt==0)?colorHSV.z:delta(colorHSV.z,valDeltaAmnt);
	
c0.rgb=(colorHSVOg==colorHSV)?c0.rgb:hsv2rgb(colorHSV);

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

float c0Max=max(c0.r,max(c0.g,c0.b));

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=(rgbDeltaAmnt==0)?c0.rgb:float3(delta(c0.r,rgbDeltaAmnt),delta(c0.g,rgbDeltaAmnt),delta(c0.b,rgbDeltaAmnt));

c0.rgb=(greyDeltaAmnt==0)?c0.rgb:saturate(delta(c0Max,greyDeltaAmnt)*(c0.rgb/c0Max));

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);

float4 c1=change(c0, texcoord);

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 Global_delta
{
	pass
	{
		VertexShader = PostProcessVS;
		PixelShader = deltaPass;
	}
}
Last Edit: 1 week 4 days ago by crabshank. Reason: Linearises RGB beforehand
The administrator has disabled public write access.
The following user(s) said Thank You: jas01, Faustus86

Global delta 2 months 13 hours ago #2

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.
The administrator has disabled public write access.

Global delta 2 months 8 hours ago #3

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 administrator has disabled public write access.
The following user(s) said Thank You: crabshank

Global delta 1 week 4 days ago #4

Update: Linearises the RGB before adjustment and re-gamma corrects it afterwards.
The administrator has disabled public write access.