Nvidia Freestyle Adjustment.yfx to Reshade
- YF
- Topic Author
Less
More
10 months 1 week ago - 10 months 1 week ago #1
by YF
Nvidia Freestyle Adjustment.yfx to Reshade was created by YF
Adjustment.yfx
#include "ReShade.fxh"
uniform float g_sldBrightness <
ui_label = "Brightness";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.5;
uniform float g_sldContrast <
ui_label = "Contrast";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.5;
uniform float g_sldVibrance <
ui_label = "Vibrance";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.5;
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);
}
float3 ColormodPass( float3 color )
{
#define ColormodChroma 1.0 // Saturation
#define ColormodGammaR 1.0 // Gamma for Red color channel
#define ColormodGammaG 1.0 // Gamma for Green color channel
#define ColormodGammaB 1.0 // Gamma for Blue color channel
#define ColormodContrastR 1.0 // Contrast for Red color channel
#define ColormodContrastG 1.0 // ...
#define ColormodContrastB 1.0 // ...
#define ColormodBrightnessR 0.0 // Brightness for Red color channel
#define ColormodBrightnessG 0.0 // ...
#define ColormodBrightnessB 0.0 // ...
#define g_sldGamma 0.5
float brightnessTerm = 2.0f * g_sldBrightness - 1.0f;
const float contrastMin = -1.6094379124341003746007593332262; //ln(0.2)
const float contrastMax = 1.6094379124341003746007593332262; //ln(5.0)
float contrastFactor = exp(contrastMin + g_sldContrast * (contrastMax - contrastMin));
//float contrastFactor = g_sldContrast <= 0.5f ? (0.5f - g_sldContrast) * -2.0f + 1.0f : (g_sldContrast - 0.5f) * 10.0f + 1.0f;
color.xyz = (color.xyz - dot(color.xyz, 0.333)) * ColormodChroma + dot(color.xyz, 0.333);
color.xyz = clamp(color.xyz,0.0,1.0);
color.x = (pow(color.x, 2.0 * (1.0 - g_sldGamma) * ColormodGammaR) - 0.5) * ColormodContrastR * contrastFactor + 0.5 + brightnessTerm;
color.y = (pow(color.y, 2.0 * (1.0 - g_sldGamma) * ColormodGammaG) - 0.5) * ColormodContrastG * contrastFactor + 0.5 + brightnessTerm;
color.z = (pow(color.z, 2.0 * (1.0 - g_sldGamma) * ColormodGammaB) - 0.5) * ColormodContrastB * contrastFactor + 0.5 + brightnessTerm;
return color;
}
float3 vibrance(float3 color)
{
// Original had double precision
float3 hsv;
float m, v, h, s, vm_diff, f, p, q, t;
float r, g, b;
int in_val;
r = color.r;
g = color.g;
b = color.b;
// convert rgb to hsv
hsv = rgb2hsv(color.rgb);
// perform gamma [0..2] enhancement
// if intensity is over 0.0 (mapped to 0.5) - saturation increases exponentionally
// otherwise - decreases linearly
if (g_sldVibrance > 0.5)
{
hsv.y = pow(hsv.y, 1.0 / (g_sldVibrance * 2.0));
}
else
{
hsv.y *= g_sldVibrance * 2.0;
}
// convert hsv to rgb
color.rgb = hsv2rgb(hsv);
return color;
}
float4 PS_Vibrance(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float4 color = tex2D(ReShade::BackBuffer,texcoord.xy);
if (
0.499 < g_sldBrightness && g_sldBrightness < 0.501 &&
0.499 < g_sldContrast && g_sldContrast < 0.501 &&
0.499 < g_sldVibrance && g_sldVibrance < 0.501
)
{
// Sliders are in default mode - color shouldn't be changed or processed in any way
return color;
}
color.xyz = ColormodPass(color.xyz);
color.xyz = vibrance(color.xyz);
return color;
}
technique Nvdia_Adjustment
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_Vibrance;
}
}
Warning: Spoiler!
#include "ReShade.fxh"
uniform float g_sldBrightness <
ui_label = "Brightness";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.5;
uniform float g_sldContrast <
ui_label = "Contrast";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.5;
uniform float g_sldVibrance <
ui_label = "Vibrance";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.5;
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);
}
float3 ColormodPass( float3 color )
{
#define ColormodChroma 1.0 // Saturation
#define ColormodGammaR 1.0 // Gamma for Red color channel
#define ColormodGammaG 1.0 // Gamma for Green color channel
#define ColormodGammaB 1.0 // Gamma for Blue color channel
#define ColormodContrastR 1.0 // Contrast for Red color channel
#define ColormodContrastG 1.0 // ...
#define ColormodContrastB 1.0 // ...
#define ColormodBrightnessR 0.0 // Brightness for Red color channel
#define ColormodBrightnessG 0.0 // ...
#define ColormodBrightnessB 0.0 // ...
#define g_sldGamma 0.5
float brightnessTerm = 2.0f * g_sldBrightness - 1.0f;
const float contrastMin = -1.6094379124341003746007593332262; //ln(0.2)
const float contrastMax = 1.6094379124341003746007593332262; //ln(5.0)
float contrastFactor = exp(contrastMin + g_sldContrast * (contrastMax - contrastMin));
//float contrastFactor = g_sldContrast <= 0.5f ? (0.5f - g_sldContrast) * -2.0f + 1.0f : (g_sldContrast - 0.5f) * 10.0f + 1.0f;
color.xyz = (color.xyz - dot(color.xyz, 0.333)) * ColormodChroma + dot(color.xyz, 0.333);
color.xyz = clamp(color.xyz,0.0,1.0);
color.x = (pow(color.x, 2.0 * (1.0 - g_sldGamma) * ColormodGammaR) - 0.5) * ColormodContrastR * contrastFactor + 0.5 + brightnessTerm;
color.y = (pow(color.y, 2.0 * (1.0 - g_sldGamma) * ColormodGammaG) - 0.5) * ColormodContrastG * contrastFactor + 0.5 + brightnessTerm;
color.z = (pow(color.z, 2.0 * (1.0 - g_sldGamma) * ColormodGammaB) - 0.5) * ColormodContrastB * contrastFactor + 0.5 + brightnessTerm;
return color;
}
float3 vibrance(float3 color)
{
// Original had double precision
float3 hsv;
float m, v, h, s, vm_diff, f, p, q, t;
float r, g, b;
int in_val;
r = color.r;
g = color.g;
b = color.b;
// convert rgb to hsv
hsv = rgb2hsv(color.rgb);
// perform gamma [0..2] enhancement
// if intensity is over 0.0 (mapped to 0.5) - saturation increases exponentionally
// otherwise - decreases linearly
if (g_sldVibrance > 0.5)
{
hsv.y = pow(hsv.y, 1.0 / (g_sldVibrance * 2.0));
}
else
{
hsv.y *= g_sldVibrance * 2.0;
}
// convert hsv to rgb
color.rgb = hsv2rgb(hsv);
return color;
}
float4 PS_Vibrance(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float4 color = tex2D(ReShade::BackBuffer,texcoord.xy);
if (
0.499 < g_sldBrightness && g_sldBrightness < 0.501 &&
0.499 < g_sldContrast && g_sldContrast < 0.501 &&
0.499 < g_sldVibrance && g_sldVibrance < 0.501
)
{
// Sliders are in default mode - color shouldn't be changed or processed in any way
return color;
}
color.xyz = ColormodPass(color.xyz);
color.xyz = vibrance(color.xyz);
return color;
}
technique Nvdia_Adjustment
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_Vibrance;
}
}
Last edit: 10 months 1 week ago by YF.
The following user(s) said Thank You: sanek7814, odikzz2, b1es
Please Log in or Create an account to join the conversation.
- YF
- Topic Author
Less
More
color.yfx
#include "ReShade.fxh"
uniform float g_sldVibrance <
ui_label = "Vibrance";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
uniform float g_sldColor <
ui_label = "Color Enhancer";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
float3 colorEnhancer(float3 color)
{
float3 clr = color;
float3 clr_out = float3(0.5954f * clr.r, 0.58f * clr.g, 0.3487f * clr.b);
float3 clr2 = clr * clr;
clr_out += float3(-1.492f * clr2.r, -3.916f * clr2.g, -1.835f * clr2.b);
float3 clr3 = clr2 * clr;
clr_out += float3(19.17f * clr3.r, 26.03f * clr3.g, 12.92f * clr3.b);
float3 clr4 = clr2 * clr2;
clr_out += float3(-45.04f * clr4.r, -50.52 * clr4.g, -19.09 * clr4.b);
float3 clr5 = clr3 * clr2;
clr_out += float3(41.23f * clr5.r, 41.09 * clr5.g, 9.679 * clr5.b);
float3 clr6 = clr4 * clr2;
clr_out += float3(-13.47f * clr6.r, -12.28 * clr6.g, -1.066 * clr6.b);
return lerp(color, saturate(clr_out), g_sldColor);
}
float4 PS_SmartSat(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float4 color = tex2D(ReShade::BackBuffer,texcoord.xy);
float4 satcolor = pow(color,exp2(g_sldVibrance));
color = satcolor * dot(color.rgb,float3(0.299,0.587,0.114)) / (dot(satcolor.rgb,float3(0.299,0.587,0.114)) + 1e-6);
color.rgb = colorEnhancer(color.rgb);
return color;
}
technique Nvdia_Color
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_SmartSat;
}
}
Exposure.yfx
#include "ReShade.fxh"
uniform float g_sldExposure <
ui_label = "Exposure";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
uniform float g_sldHighlightsIntensity <
ui_label = "Highlights";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
uniform float g_sldShadowsIntensity <
ui_label = "Shadows";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
float GetToneCurve(float x, float exposureV, float highlightsV, float shadowsV)
{
float shadows = smoothstep(0.666,0.0,x);
float highlights = smoothstep(0.333,1.0,x);
float rest = saturate(1.0 - shadows - highlights);
x = pow(saturate(x * exposureV), exp2(shadows * shadowsV + highlights * highlightsV + rest - 1));
return x;
}
float4 PS_Exposure(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float4 color = tex2D(ReShade::BackBuffer,texcoord.xy);
float exposureV = exp2(g_sldExposure); //-100%: exposure of 0.5, 100%: gamma of 2
float highlightsV = exp2(-g_sldHighlightsIntensity);
float shadowsV = exp2(-g_sldShadowsIntensity);
//apply modifications. Need to be per channel, otherwise shadows etc weights won't work.
color.r = GetToneCurve(color.r,exposureV,highlightsV,shadowsV);
color.g = GetToneCurve(color.g,exposureV,highlightsV,shadowsV);
color.b = GetToneCurve(color.b,exposureV,highlightsV,shadowsV);
return color;
}
technique Nvdia_Exposure
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_Exposure;
}
}
Warning: Spoiler!
#include "ReShade.fxh"
uniform float g_sldVibrance <
ui_label = "Vibrance";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
uniform float g_sldColor <
ui_label = "Color Enhancer";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
float3 colorEnhancer(float3 color)
{
float3 clr = color;
float3 clr_out = float3(0.5954f * clr.r, 0.58f * clr.g, 0.3487f * clr.b);
float3 clr2 = clr * clr;
clr_out += float3(-1.492f * clr2.r, -3.916f * clr2.g, -1.835f * clr2.b);
float3 clr3 = clr2 * clr;
clr_out += float3(19.17f * clr3.r, 26.03f * clr3.g, 12.92f * clr3.b);
float3 clr4 = clr2 * clr2;
clr_out += float3(-45.04f * clr4.r, -50.52 * clr4.g, -19.09 * clr4.b);
float3 clr5 = clr3 * clr2;
clr_out += float3(41.23f * clr5.r, 41.09 * clr5.g, 9.679 * clr5.b);
float3 clr6 = clr4 * clr2;
clr_out += float3(-13.47f * clr6.r, -12.28 * clr6.g, -1.066 * clr6.b);
return lerp(color, saturate(clr_out), g_sldColor);
}
float4 PS_SmartSat(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float4 color = tex2D(ReShade::BackBuffer,texcoord.xy);
float4 satcolor = pow(color,exp2(g_sldVibrance));
color = satcolor * dot(color.rgb,float3(0.299,0.587,0.114)) / (dot(satcolor.rgb,float3(0.299,0.587,0.114)) + 1e-6);
color.rgb = colorEnhancer(color.rgb);
return color;
}
technique Nvdia_Color
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_SmartSat;
}
}
Exposure.yfx
Warning: Spoiler!
#include "ReShade.fxh"
uniform float g_sldExposure <
ui_label = "Exposure";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
uniform float g_sldHighlightsIntensity <
ui_label = "Highlights";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
uniform float g_sldShadowsIntensity <
ui_label = "Shadows";
ui_type = "slider";
ui_min = 0.0; ui_max = 1.0;
ui_step = 0.01;
> = 0.0;
float GetToneCurve(float x, float exposureV, float highlightsV, float shadowsV)
{
float shadows = smoothstep(0.666,0.0,x);
float highlights = smoothstep(0.333,1.0,x);
float rest = saturate(1.0 - shadows - highlights);
x = pow(saturate(x * exposureV), exp2(shadows * shadowsV + highlights * highlightsV + rest - 1));
return x;
}
float4 PS_Exposure(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target
{
float4 color = tex2D(ReShade::BackBuffer,texcoord.xy);
float exposureV = exp2(g_sldExposure); //-100%: exposure of 0.5, 100%: gamma of 2
float highlightsV = exp2(-g_sldHighlightsIntensity);
float shadowsV = exp2(-g_sldShadowsIntensity);
//apply modifications. Need to be per channel, otherwise shadows etc weights won't work.
color.r = GetToneCurve(color.r,exposureV,highlightsV,shadowsV);
color.g = GetToneCurve(color.g,exposureV,highlightsV,shadowsV);
color.b = GetToneCurve(color.b,exposureV,highlightsV,shadowsV);
return color;
}
technique Nvdia_Exposure
{
pass
{
VertexShader = PostProcessVS;
PixelShader = PS_Exposure;
}
}
The following user(s) said Thank You: sanek7814, odikzz2, b1es
Please Log in or Create an account to join the conversation.
- sanek7814
Less
More
10 months 1 week ago #3
by sanek7814
Replied by sanek7814 on topic Nvidia Freestyle Adjustment.yfx to Reshade
Just a wonderful job, thank you. By the way, I tested literally 5 minutes of these shaders in HL2 Episode One. For the most part, these shaders are responsible for gamma. I turned a very dark picture into a light one in a second and it was very realistic and playable.
The following user(s) said Thank You: odikzz2
Please Log in or Create an account to join the conversation.