/**
 * S-Log3 Simulation
 * by moriz1
 */

#include "ReShade.fxh"

float3 SLog3(float4 position : SV_Position, float2 texcoord : TexCoord) : SV_Target {
	float3 color = tex2D(ReShade::BackBuffer, texcoord).rgb;
	float3 cutoff = float3(0.01125, 0.01125, 0.01125);
	
	if (color.r >= cutoff.r || color.g >= cutoff.g || color.b >= cutoff.b) {
        color.rgb = (420.0 + log10((color.rgb + 0.01) / (0.18 + 0.01)) * 261.5) / 1023.0;
    }
    else {
        color.rgb = (color.rgb * (171.2102946929 - 95.0) / 0.01125 + 95.0) / 1023.0;
    }
	
	return saturate(color);
}

technique SLogThree {
	pass ToSLogThree {
		VertexShader = PostProcessVS;
		PixelShader = SLog3;
	}
}