mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-30 23:33:02 +00:00
filters/color-grading: Fix Gamma function and improve code readability
Fixes #510
This commit is contained in:
parent
fd3d514a20
commit
27c3420f31
1 changed files with 20 additions and 15 deletions
|
@ -55,10 +55,7 @@ float3 grade_lift(float3 v) { // same as grade_offset?
|
||||||
};
|
};
|
||||||
|
|
||||||
float3 grade_gamma(float3 v) {
|
float3 grade_gamma(float3 v) {
|
||||||
float3 s = sign(v); // Store sign for later use.
|
return pow(abs(v), pGamma.rgb * pGamma.a) * sign(v);
|
||||||
float3 u = abs(v); // Remove sign
|
|
||||||
u.rgb = pow(pow(u.rgb, pGamma.rgb), pGamma.a);
|
|
||||||
return u * s; // Restore sign.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
float3 grade_gain(float3 v) {
|
float3 grade_gain(float3 v) {
|
||||||
|
@ -112,22 +109,30 @@ float3 grade_colorcorrection(float3 v) {
|
||||||
v1.b *= pCorrection.b; // Lightness Multiplier
|
v1.b *= pCorrection.b; // Lightness Multiplier
|
||||||
float3 v2 = HSVtoRGB(v1);
|
float3 v2 = HSVtoRGB(v1);
|
||||||
|
|
||||||
// Contrast
|
|
||||||
v2.rgb = ((v2.rgb - 0.5) * max(pCorrection.a, 0)) + 0.5;
|
|
||||||
|
|
||||||
return v2;
|
return v2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
float3 grade_contrast(float3 v) {
|
||||||
|
v -= .5;
|
||||||
|
v *= pCorrection.a;
|
||||||
|
v += .5;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
float4 PSDraw(VertexData vtx) : TARGET {
|
float4 PSDraw(VertexData vtx) : TARGET {
|
||||||
float4 v1 = image.Sample(PointClampSampler, vtx.uv);
|
float4 vo = image.Sample(PointClampSampler, vtx.uv);
|
||||||
float3 v2 = grade_lift(v1.rgb);
|
float3 v = vo.rgb;
|
||||||
float3 v3 = grade_gamma(v2);
|
|
||||||
float3 v4 = grade_gain(v3);
|
v = grade_lift(v);
|
||||||
float3 v5 = grade_offset(v4);
|
v = grade_gamma(v);
|
||||||
float3 v6 = grade_tint(v5);
|
v = grade_gain(v);
|
||||||
float3 v7 = grade_colorcorrection(v6);
|
v = grade_offset(v);
|
||||||
float3 vf = v7;
|
v = grade_tint(v);
|
||||||
return float4(vf, v1.a);
|
v = grade_colorcorrection(v);
|
||||||
|
v = grade_contrast(v);
|
||||||
|
|
||||||
|
return float4(v, vo.a);
|
||||||
};
|
};
|
||||||
|
|
||||||
technique Draw
|
technique Draw
|
||||||
|
|
Loading…
Reference in a new issue