Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Src: Tone mapping shaders clean up #28084

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,24 +168,32 @@ vec3 AgXToneMapping( vec3 color ) {
// https://modelviewer.dev/examples/tone-mapping

vec3 NeutralToneMapping( vec3 color ) {
float startCompression = 0.8 - 0.04;
float desaturation = 0.15;

const float StartCompression = 0.8 - 0.04;
const float Desaturation = 0.15;

color *= toneMappingExposure;

float x = min(color.r, min(color.g, color.b));
float x = min( color.r, min( color.g, color.b ) );

float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;

color -= offset;

float peak = max(color.r, max(color.g, color.b));
if (peak < startCompression) return color;
float peak = max( color.r, max( color.g, color.b ) );

if ( peak < StartCompression ) return color;

float d = 1. - StartCompression;

float newPeak = 1. - d * d / ( peak + d - StartCompression );

float d = 1. - startCompression;
float newPeak = 1. - d * d / (peak + d - startCompression);
color *= newPeak / peak;

float g = 1. - 1. / (desaturation * (peak - newPeak) + 1.);
return mix(color, newPeak * vec3(1, 1, 1), g);
float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );

return mix( color, vec3( newPeak ), g );

}

vec3 CustomToneMapping( vec3 color ) { return color; }
Expand Down