-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Higher quality lightmap sampling #16740
base: main
Are you sure you want to change the base?
Conversation
imo this should be optional (with at least linear being the other option). Try with a low res light map to see the effect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good modulo a little inaccuracy.
I could go either way on exposing an option for bilinear, and I won't block the PR on that. A quote from the Bakery author's blog post: https://ndotl.wordpress.com/2018/08/29/baking-artifact-free-lightmaps/
Bicubic interpolation. If you are not shipping on mobile, there are exactly 0 reasons to not use bicubic interpolation for lightmaps. Many UE3 games in the past did that, and it is a great trick. But some engines (Unity, I’m looking at you) still think they can get away with a single bilinear tap in 2018. Bicubic hides low resolution and makes jagged lines appear smooth. Sometimes I see people fixing jagged sharp shadows by super-sampling during bake, but it feels like a waste of lightmapping time to me.
See the post for a screenshot comparison.
The "if you are not shipping on mobile" comment is 6 years old, so it may well just be time to say bicubic everywhere.
let p0 = (vec2(iuv.x + h0x, iuv.y + h0y) - 0.5) * texel_size; | ||
let p1 = (vec2(iuv.x + h1x, iuv.y + h0y) - 0.5) * texel_size; | ||
let p2 = (vec2(iuv.x + h0x, iuv.y + h1y) - 0.5) * texel_size; | ||
let p3 = (vec2(iuv.x + h1x, iuv.y + h1y) - 0.5) * texel_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Odd indentation here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy+pasted tabs :/. Fixed.
} | ||
|
||
fn h1_approx(a: f32) -> f32 { | ||
return 1.0 + a * (0.24 * a - 0.04); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 1.0 + a * (0.24 * a - 0.04); | |
return 1.00158 + a * (0.230963 * a - 0.0353001); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plugged it into desmos. Both yours and my h1 approx have inaccuracies. The difference is whether it occurs before or after the midpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I replaced the - with a +! Sign error. Ignore my comment, your code is fine the way it is
} | ||
|
||
fn h0_approx(a: f32) -> f32 { | ||
return 0.2 + a * (0.24 * a - 0.44); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on these images from @pcwalton I don't think bicubic is correct: https://discord.com/channels/691052431525675048/743663924229963868/1316259592308527134 |
Objective
Solution
Testing
Changelog