Explorar el Código

PBR calibration with recent changes

Nehon hace 9 años
padre
commit
e2f180811c

+ 3 - 3
jme3-core/src/main/java/com/jme3/environment/util/EnvMapUtils.java

@@ -433,13 +433,13 @@ public class EnvMapUtils {
 
     public static float getRoughnessFromMip(int miplevel, int miptot) {
         float mipScale = 1.0f;
-        float mipOffset = -0.3f;        
+        float mipOffset = -0.5f;
 
-        return pow(2, (float) (miplevel - (miptot - 1) + mipOffset) / mipScale);
+        return pow(2, (miplevel - (miptot - 1) + mipOffset) / mipScale);
     }
 
     public static float getMipFromRoughness(float roughness, int miptot) {
-        float mipScale = 1.2f;
+        float mipScale = 1.0f;
         float Lod = (float) (Math.log(roughness) / Math.log(2)) * mipScale + miptot - 1.0f;       
 
         return (float) Math.max(0.0, Lod);

+ 2 - 2
jme3-core/src/main/resources/Common/ShaderLib/PBR.glsllib

@@ -135,7 +135,7 @@ vec3 EnvDFGPolynomial( vec3 specularColor, float roughness, float ndotv ){
 
 vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec){
     //TODO magic values should be replaced by defines.
-    float Lod = log2(Roughness) * 1.5 + 6.0 - 1.0;
+    float Lod = log2(Roughness) * 1.1 + 6.0 - 2.0;
     vec3 PrefilteredColor =  textureCubeLod(envMap, refVec.xyz,Lod).rgb;
     vec2 EnvBRDF = texture2D(integrateBRDF,vec2(Roughness, ndotv)).rg;
     return PrefilteredColor * ( SpecularColor * EnvBRDF.x+ EnvBRDF.y );    
@@ -143,7 +143,7 @@ vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 Spe
 
 vec3 ApproximateSpecularIBLPolynomial(samplerCube envMap, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec){
     //TODO magic values should be replaced by defines.
-    float Lod = log2(Roughness) * 1.1 + 6.0 - 1.0;
+    float Lod = log2(Roughness) * 1.1 + 6.0 - 2.0;
     vec3 PrefilteredColor =  textureCubeLod(envMap, refVec.xyz, Lod).rgb;    
     return PrefilteredColor * EnvDFGPolynomial(SpecularColor, Roughness, ndotv);
 }

+ 31 - 9
jme3-examples/src/main/java/jme3test/light/pbr/RefEnv.java

@@ -17,6 +17,7 @@ import com.jme3.math.Vector3f;
 import com.jme3.scene.Geometry;
 import com.jme3.scene.Node;
 import com.jme3.scene.Spatial;
+import com.jme3.ui.Picture;
 import com.jme3.util.MaterialDebugAppState;
 
 /**
@@ -27,14 +28,11 @@ import com.jme3.util.MaterialDebugAppState;
 public class RefEnv extends SimpleApplication {
 
     private Node tex;
+    private Node ref;
+    private Picture refDE;
+    private Picture refM;
 
     public static void main(String[] args) {
-        System.err.println(Math.min(1, 8192));
-        System.err.println(Math.min(1 << (6), 8192));
-        System.err.println(Math.min(1 << (8), 8192));
-        System.err.println(Math.min(1 << (10), 8192));
-        System.err.println(Math.min(1 << (12), 8192));
-        System.err.println(Math.min(1 << (14), 8192));
         RefEnv app = new RefEnv();
         app.start();
     }
@@ -42,16 +40,29 @@ public class RefEnv extends SimpleApplication {
     @Override
     public void simpleInitApp() {
 
-        cam.setLocation(new Vector3f(-3.0286736f, 2.8702848f, 5.153083f));
-        cam.setRotation(new Quaternion(0.06595449f, 0.9340066f, -0.24384351f, 0.2526304f));
+        cam.setLocation(new Vector3f(-2.3324413f, 2.9567573f, 4.6054406f));
+        cam.setRotation(new Quaternion(0.06310794f, 0.9321281f, -0.29613864f, 0.1986369f));
         Spatial sc = assetManager.loadModel("Scenes/PBR/spheres.j3o");
         rootNode.attachChild(sc);
         rootNode.getChild("Scene").setCullHint(Spatial.CullHint.Always);
 
+        ref = new Node("reference pictures");
+        refDE = new Picture("refDE");
+        refDE.setHeight(cam.getHeight());
+        refDE.setWidth(cam.getWidth());
+        refDE.setImage(assetManager,"jme3test/light/pbr/spheresRefDE.png", false);
+        refM = new Picture("refM");
+        refM.setImage(assetManager,"jme3test/light/pbr/spheresRefM.png", false);
+        refM.setHeight(cam.getHeight());
+        refM.setWidth(cam.getWidth());
+
+        ref.attachChild(refDE);
+
         stateManager.attach(new EnvironmentCamera());
 
         inputManager.addMapping("tex", new KeyTrigger(KeyInput.KEY_SPACE));
         inputManager.addMapping("switch", new KeyTrigger(KeyInput.KEY_RETURN));
+        inputManager.addMapping("ref", new KeyTrigger(KeyInput.KEY_R));
         inputManager.addListener(new ActionListener() {
 
             @Override
@@ -70,8 +81,15 @@ public class RefEnv extends SimpleApplication {
                 if (name.equals("switch") && isPressed) {
                     switchMat(rootNode.getChild("Scene"));
                 }
+                if (name.equals("ref") && isPressed) {
+                    if (ref.getParent() == null) {
+                        guiNode.attachChild(ref);
+                    } else {
+                        ref.removeFromParent();
+                    }
+                }
             }
-        }, "tex", "switch");
+        }, "tex", "switch", "ref");
 
     }
 
@@ -87,9 +105,13 @@ public class RefEnv extends SimpleApplication {
             if (((Float) mat.getParam("Metallic").getValue()) == 1f) {
                 mat.setFloat("Metallic", 0);
                 mat.setColor("BaseColor", ColorRGBA.Black);
+                ref.attachChild(refDE);
+                refM.removeFromParent();
             } else {
                 mat.setFloat("Metallic", 1);
                 mat.setColor("BaseColor", ColorRGBA.White);
+                ref.attachChild(refM);
+                refDE.removeFromParent();
             }
         }
     }

BIN
jme3-examples/src/main/resources/jme3test/light/pbr/spheresRefDE.png


BIN
jme3-examples/src/main/resources/jme3test/light/pbr/spheresRefM.png