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

Fix to msdf chunk to handle gamma space correctly #7325

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/scene/shader-lib/chunks/common/frag/msdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ varying vec2 shadow_offset;
#endif

vec4 applyMsdf(vec4 color) {

// Convert to linear space before processing
// TODO: ideally this would receive the color in linear space, but that would require larger changes
// on the engine side, with the way premultiplied alpha is handled as well.
color.rgb = gammaCorrectInput(color.rgb);

// sample the field
vec3 tsample = texture2D(texture_msdfMap, vUv0).rgb;
vec2 uvShdw = vUv0 - shadow_offset;
Expand Down Expand Up @@ -61,6 +67,9 @@ vec4 applyMsdf(vec4 color) {

vec4 scolor = (shadow > outline) ? shadow * vec4(shadow_color.a * shadow_color.rgb, shadow_color.a) : tcolor;
tcolor = mix(scolor, tcolor, outline);

// Convert back to gamma space before returning
tcolor.rgb = gammaCorrectOutput(tcolor.rgb);

return tcolor;
}
Expand Down