瀏覽代碼

Fix incorrect metallic calculations in PBRLighting.frag

addresses this issue: https://github.com/jMonkeyEngine/jmonkeyengine/issues/2330

There were 2 apparent issues with our metallic calculation that were causing our PBR implementation to render different visual results compared to the khronos PBR standards:

1) fZero was being calculated incorrectly, as mentioned in the linked issue
2) the nonMetalSpec float constant was being set incorrectly. According to what I've read, it should always be 0.08

I also checked tested changes in my own app and it appears the rendering difference is more accurate now. But I'm not an expert in lighting math like this, so let me know if anything looks incorrect with the code.
Ryan McDonough 9 月之前
父節點
當前提交
68c94107bb
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag

+ 4 - 4
jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag

@@ -217,11 +217,11 @@ void main(){
         Roughness = 1.0 - glossiness;
         vec3 fZero = specularColor.xyz;
     #else
-        float specular = 0.5;
-        float nonMetalSpec = 0.08 * specular;
-        vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic;
+        float nonMetalSpec = 0.08; //nonMetalSpec is always constant value of 0.8 in metallic workflow
+        specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic;
         vec4 diffuseColor = albedo - albedo * Metallic;
-        vec3 fZero = vec3(specular);
+        vec3 fZero = vec3(0.04); 
+        fZero = mix(fZero, albedo.rgb, Metallic);          
     #endif
 
     gl_FragColor.rgb = vec3(0.0);