-
Notifications
You must be signed in to change notification settings - Fork 247
Fixed a bug where NdotV can be >1.0 #80
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
Conversation
I think I've seen that black spot... Do you know how to reproduce it? |
shaders/pbr-frag.glsl
Outdated
@@ -254,7 +254,7 @@ void main() | |||
vec3 reflection = -normalize(reflect(v, n)); | |||
|
|||
float NdotL = clamp(dot(n, l), 0.001, 1.0); | |||
float NdotV = abs(dot(n, v)) + 0.001; | |||
float NdotV = min(abs(dot(n, v)) + 0.001, 1.0); |
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.
Any reason to not use clamp
here, just to be consistent with the surrounding code?
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.
To preserve existing behavior and keep the changes to a minimum.
Should it be clamp(abs(dot(n, v))+0.001, 0.0, 1.0);
or clamp(abs(dot(n, v)), 0.001, 1.0);
?
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 like the 0.001
is there to prevent a divide-by-zero, so yes I would think that clamp(abs(dot(n, v)), 0.001, 1.0);
is the correct one.
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.
Changed to clamp(abs(dot(n, v)), 0.001, 1.0);
. That's actually what I decided to use in my project after thinking why that 0.001
is here.
/cc @snagy |
Current implementation uses this code for diffuse:
If we go to https://github.com/KhronosGroup/glTF-WebGL-PBR and replace the code above with this fragment
The black circle will appear. |
… with Burley diffuse
shaders/pbr-frag.glsl
Outdated
@@ -147,7 +147,11 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection) | |||
float mipCount = 9.0; // resolution of 512x512 | |||
float lod = (pbrInputs.perceptualRoughness * mipCount); | |||
// retrieve a scale and bias to F0. See [1], Figure 3 | |||
#ifdef USE_TEX_LOD | |||
vec3 brdf = SRGBtoLINEAR(texture2DLodEXT(u_brdfLUT, vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness), 0)).rgb; |
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.
This is a separate bug, not sure if you intended to address it as part of this PR. Is there some better way to do this, maybe turn off mipmapping at the WebGL level, rather than just always asking for a particular mip level?
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.
Indeed. Removed from here and will be put into a separate PR.
Setting filtering to GL_LINEAR
should solve the problem as well and sounds like a better solution.
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 to me. @snagy Do you want to take a peek before merge?
added initial version of xmp UI
Fixed a bug where
NdotV
can be>1.0
resulting in a black spot if used with the diffuse term from "Disney implementation of diffuse from Physically-Based Shading at Disney" by Brent Burley.The term
1.0-pbrInputs.NdotV
will become negative.