Skip to content

Instantly share code, notes, and snippets.

@leegoonz
Created January 12, 2023 14:53
Show Gist options
  • Save leegoonz/35ee03f5de4e9994073d263531fc56f9 to your computer and use it in GitHub Desktop.
Save leegoonz/35ee03f5de4e9994073d263531fc56f9 to your computer and use it in GitHub Desktop.
//Propertices related of Tone map.
[Header(TONE MAPPER)]//// Neutral tonemapping (Hable/Hejl/Frostbite)
[Toggle] _toggleToneMapper("Tone Mapper" , FLOAT) = 0
_a("Segment A" , Range(0.1, 1)) = 0.2
_b("Segment B" , Range(0.1, 1)) = 0.29
_c("Segment C" , Range(0.1, 1)) = 0.24
_d("Segment D" , Range(0.1, 1)) = 0.272
_e("Segment E" , Range(0.01, 0.1)) = 0.02
_f("Segment F" , Range(0.1, 1)) = 0.3
_WhiteLevel("ToneMappe White Level" , Range(1.3, 5.3)) = 2.3
//====================================================================
//adding to variable for On off toggle
uniform half _toggleToneMapper;
//=====================================================================
// Neutral tonemapping (Hable/Hejl/Frostbite)
// Adding to Neutral tone map function inside shader.
FLOAT3 NeutralCurve(FLOAT3 x, FLOAT a, FLOAT b, FLOAT c, FLOAT d, FLOAT e, FLOAT f)
{
return ((x * (a * x + c * b) + d * e) / (x * (a * x + b) + d * f)) - e / f;
}
FLOAT3 NeutralTonemap(FLOAT3 x)
{
// Tonemap
const FLOAT a = _a;
const FLOAT b = _b;
const FLOAT c = _c;
const FLOAT d = _d;
const FLOAT e = _e;
const FLOAT f = _f;
const FLOAT whiteLevel = _WhiteLevel;
const FLOAT whiteClip = 1;
half3 whiteScale = (1.0).xxx / NeutralCurve(whiteLevel, a, b, c, d, e, f);
x = NeutralCurve(x * whiteScale, a, b, c, d, e, f);
x *= whiteScale;
// Post-curve white point adjustment
x /= whiteClip.xxx;
return x;
}
//=======================================================================================
// Use to if branch with NeutralTonemap function for last output result of finalColor.
if (_toggleToneMapper)
{
finalColor = NeutralTonemap(finalColor);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment