-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[3.x] Make blinn and phong specular consider albedo and specular amount #51410
Conversation
aee3612
to
64be9ad
Compare
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 don't know enough about the internals of PBR so I'll take you're word on this being more accurate.
As for the choice whether to do this or not, I'm all for it.
I missed the discussion last night as it was late here, but I'd also say give it a try in some betas, and see if we get anyone complaining. Aside from the backward compatibility, my only concern (being a performance guy) is when you say it runs slower, is to make sure we always have a cheap and cheerful diffuse and specular mode available that runs as fast as humanly possible, and doesn't care about PBR accuracy etc. Because that's what it boils down to in most cases, people want to be able to choose between 'looks good' and 'runs fast'. Myself I try and tweak the settings to have as fast as possible, or often just run an entirely custom shader for this reason. |
From my perspective, having shaders that are more realistic, or do things as normal light, is quite important . .
I often wondered why they were there, I just use the default one, assuming it's best . . . maybe they are important shaders, for historical purposes . . reg. speed, it's an issue whether current hardware is optimized for one, or the other, about speed . . . I sort-of rather wish, there was an explanation for why even to use them . . . one down-side for them looking is identical is, why not just delete the two slower one's, and have the fastest / best one . . . The pre-view images are amazing, one can see how the color of the reflection light, becomes more like GGX ( accurate ? ) . . Amazing, hope you can make it run fast, and look good . . . . |
Blinn and Phong are still cheaper than the GGX mode, they just aren't as cheap as they were before (this PR adds a handful of multiplications and 2 lerps). For most cases, they probably won't be slower because the difference is so small, but in theory more instructions leads to worse performance. One problem with the current implementation is that it is halfway between old Diffuse/Specular and PBR. Without this change, specular ignores albedo. Since Godot materials cannot specify diffuse_color and specular_color, all materials using Blinn/Phong implicitly use a pure white specular_color. Which is of course a huge problem both for a PBR workflow and for a Diffuse/Specular workflow. IMO the workflow that makes sense is having Blinn and Phong look like simplified versions of GGX (but cheaper of course). That is the workflow that this PR enforces. |
@lawnjelly Another option would be to meet in the middle. We could remove the Fresnel term completely and make the assumption that Actually, that may be the best option here. If we do that we can substantially reduce the instruction count while maintaining a consistent behaviour Code below for reference (tested in the online editor while I am at work :P)
This removes the Fresnel term completely (the Fresnel term is responsible for making all surfaces appear reflective at a glancing angle) and introduces albedo and specular amount into the terms. This way the materials will behave consistently (but not physically correct) and it introduces minimal calculations, thus keeping them as cheap as possible. |
64be9ad
to
c0f35ed
Compare
c0f35ed
to
f92a600
Compare
Okay, I have updated the PR to not go full-PBR. Instead it maintains some aspects of the old Diffuse/Specular model. Results are similar but not quite as close to GGX as they were before. I suggest we approve and merge like this as it should impact existing users less and still provides the same benefits. |
Thanks! |
Fixes: #50455 and fixes #34257
4.0 version: #51411
This PR adds in the
specular
amount andalbedo
into the calculation of specular lighting for Blinn and Phong modes. This is not physically based, however, it comes close to mirroring the old Specular/Diffuse lighting that was around before PBR. In discussions with other contributors it is clear that we want to maintain the Blinn and Phong modes for performance reasons and for compatibility with older workflows. The main difference between this and the old Specular/Diffuse lighting model is that this only provides one albedo colour. The older workflow always specified a specular colour and a diffuse colour, here we use albedo for specular and diffuse. Essentially we have gone from:to:
This PR should be slightly improve performance in theory. But in practice there will be a negligible difference.
Visual comparison
All comparisons use the same layout. GGX in the upper right, Blinn in the lower left, and Phong in the lower right
Smooth metal
old
new: note the color around the specular highlight
0.5 rough metal
old
new: note the colored specular highlight
rough metal
old
new
This PR should result in as little change as possible for existing materials while allowing more cohesiveness when using Blinn and Phong. Users that appreciated having the overblown specular on darker materials can still achieve the same look by boosting specular with the
specular
property.Old notes
This PR adds a Fresnel term and geometric term to both the Blinn and Phong specular modes. The Fresnel term scales the specular intensity quite strongly and removes the overbright specular reflections when roughness is high.By way of background, BRDF's typically share 3 terms D (normalized density function) G (geometric term) F (Fresnel term). The Blinn BRDF is
D*G*F / 4 * NdotL * nDotV
(see https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf) . Godot has been using a more simplified model which ignored the G and F terms (and had a mistake in the D term):D` / 4 * NdotL * nDotV
. This simplified model is naturally simpler to compute, but was totally broken (hence #33836 which didn't actually fully fix Blinn).This PR restores the G and F terms. The G term for Blinn-Phong is equal to
NdotL * nDotV
and so it cancels out theNdotL * nDotV
in the BRDF. We are left withD * F / 4
which is what this PR uses.Visual comparison
All comparisons use the same layout. GGX in the upper right, Blinn in the lower left, and Phong in the lower right
Smooth metal
old
new: note the color around the specular highlight
0.5 rough metal
old
new: note the colored specular highlight
rough metal
old
new
edit: references for future reference
http://www.thetenthplanet.de/archives/255
https://seblagarde.wordpress.com/2011/08/17/hello-world/
https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf
https://slideplayer.com/slide/1507561/