소스 검색

Add copyright and javadoc, fix some merging issues

Riccardo Balbo 2 년 전
부모
커밋
67a37021eb

+ 42 - 35
jme3-core/src/main/java/com/jme3/environment/EnvironmentProbeControl.java

@@ -16,36 +16,45 @@ import com.jme3.scene.control.Control;
 import com.jme3.texture.Image.Format;
 
 /**
- * SmartLightProbe
+ * A control that automatically handles environment bake and rebake including
+ * only tagged spatials.
+ * 
+ * @author Riccardo Balbo
  */
 public class EnvironmentProbeControl extends LightProbe implements Control {
 
+    private RenderManager renderManager;
+    private AssetManager assetManager;
+    private int envMapSize;
+    private Spatial spatial;
+    private boolean BAKE_NEEDED = true;
 
-
-    RenderManager renderManager;
-    AssetManager assetManager;
-    int envMapSize;
-    Spatial spatial;
-    boolean BAKE_NEEDED=true;
-    Function<Geometry,Boolean> filter=(s)->{
-        return s.getUserData("tags.env")!=null;
+    private Function<Geometry, Boolean> filter = (s) -> {
+        return s.getUserData("tags.env") != null;
     };
 
-    public static void tag(Spatial s){
-        if(s instanceof Node){
-            Node n=(Node)s;
-            for(Spatial sx:n.getChildren()){
+    /**
+     * Tag spatial as part of the environment. Only tagged spatials will be
+     * rendered in the environment map.
+     * 
+     * @param s
+     *            the spatial
+     */
+    public static void tag(Spatial s) {
+        if (s instanceof Node) {
+            Node n = (Node) s;
+            for (Spatial sx : n.getChildren()) {
                 tag(sx);
             }
-        }else if(s instanceof Geometry){
+        } else if (s instanceof Geometry) {
             s.setUserData("tags.env", true);
         }
     }
 
-    public EnvironmentProbeControl(RenderManager rm,AssetManager am, int size){
-        renderManager=rm;
-        assetManager=am;
-        envMapSize=size;
+    public EnvironmentProbeControl(RenderManager rm, AssetManager am, int size) {
+        renderManager = rm;
+        assetManager = am;
+        envMapSize = size;
     }
 
     @Override
@@ -55,9 +64,9 @@ public class EnvironmentProbeControl extends LightProbe implements Control {
 
     @Override
     public void setSpatial(Spatial spatial) {
-        
+
         spatial.addLight(this);
-        this.spatial=spatial;
+        this.spatial = spatial;
 
     }
 
@@ -67,30 +76,28 @@ public class EnvironmentProbeControl extends LightProbe implements Control {
     }
 
     @Override
-	public void render(RenderManager rm, ViewPort vp) {
-        if(BAKE_NEEDED){
-            BAKE_NEEDED=false;
+    public void render(RenderManager rm, ViewPort vp) {
+        if (BAKE_NEEDED) {
+            BAKE_NEEDED = false;
             rebakeNow();
         }
     }
 
-    public void rebake(){
-        BAKE_NEEDED=true;
+    /**
+     * Schedule a rebake of the environment map.
+     */
+    public void rebake() {
+        BAKE_NEEDED = true;
     }
-    
+
     void rebakeNow() {
-        System.out.println("BAKE");
 
-        IBLGLEnvBakerLight baker = new IBLGLEnvBakerLight(renderManager, assetManager, Format.RGB16F, Format.Depth,
-                envMapSize, envMapSize);
-        
-       
-        baker.bakeEnvironment(spatial, Vector3f.ZERO, 0.001f, 1000f,filter);
+        IBLGLEnvBakerLight baker = new IBLGLEnvBakerLight(renderManager, assetManager, Format.RGB16F, Format.Depth, envMapSize, envMapSize);
+
+        baker.bakeEnvironment(spatial, Vector3f.ZERO, 0.001f, 1000f, filter);
         baker.bakeSpecularIBL();
         baker.bakeSphericalHarmonicsCoefficients();
 
-
-        // probe.setPosition(Vector3f.ZERO);
         setPrefilteredMap(baker.getSpecularIBL());
         setNbMipMaps(getPrefilteredEnvMap().getImage().getMipMapSizes().length);
         setShCoeffs(baker.getSphericalHarmonicsCoefficients());
@@ -100,5 +107,5 @@ public class EnvironmentProbeControl extends LightProbe implements Control {
         baker.clean();
 
     }
-    
+
 }

+ 18 - 13
jme3-core/src/main/java/com/jme3/environment/LightProbeFactory.java

@@ -45,31 +45,36 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
 /**
  * Creates LightProbes within a scene, given an EnvironmentCamera.
  * 
- * Since this process can take a long time, you can provide a JobProgressListener that
- * will be notified of the ongoing generation process when calling the makeProbe method.
+ * Since this process can take a long time, you can provide a
+ * JobProgressListener that will be notified of the ongoing generation process
+ * when calling the makeProbe method.
  * 
- * The process is as follows: 
- * 1. Create an EnvironmentCamera
- * 2. give it a position in the scene
- * 3. call {@link LightProbeFactory#makeProbe(com.jme3.environment.EnvironmentCamera, com.jme3.scene.Spatial)}
- * 4. add the created LightProbe to a node with the {@link Node#addLight(com.jme3.light.Light) } method.
+ * The process is as follows: 1. Create an EnvironmentCamera 2. give it a
+ * position in the scene 3. call
+ * {@link LightProbeFactory#makeProbe(com.jme3.environment.EnvironmentCamera, com.jme3.scene.Spatial)}
+ * 4. add the created LightProbe to a node with the
+ * {@link Node#addLight(com.jme3.light.Light) } method.
  * 
  * Optionally for step 3 call
  * {@link #makeProbe(com.jme3.environment.EnvironmentCamera, com.jme3.scene.Spatial, com.jme3.environment.generation.JobProgressListener)}
- * with a {@link JobProgressListener} to be notified of the progress of the generation process.
+ * with a {@link JobProgressListener} to be notified of the progress of the
+ * generation process.
  * 
- * The generation will be split in several threads for faster generation. 
+ * The generation will be split in several threads for faster generation.
  * 
- * This class is entirely thread safe and can be called from any thread. 
+ * This class is entirely thread safe and can be called from any thread.
  * 
  * Note that in case you are using a {@link JobProgressListener}, all its
- * methods will be called inside an app.enqueue callable.
- * This means that it's completely safe to modify the scenegraph within the 
- * Listener method, but also means that the event will be delayed until next update loop.
+ * methods will be called inside an app.enqueue callable. This means that it's
+ * completely safe to modify the scenegraph within the Listener method, but also
+ * means that the event will be delayed until next update loop.
  * 
+ * @deprecated Use LightProbeFactory2 or EnvironmentProbeControl whenever possible.
  * @see EnvironmentCamera
  * @author bouquet
  */
+
+@Deprecated
 public class LightProbeFactory {
 
     /**

+ 15 - 1
jme3-core/src/main/java/com/jme3/environment/LightProbeFactory2.java

@@ -41,10 +41,24 @@ import com.jme3.scene.Node;
 import com.jme3.scene.Spatial;
 import com.jme3.texture.Image.Format;
 
-
+/**
+ * A faster version of LightProbeFactory that uses accelerated Baking.
+ * @author Riccardo Balbo
+ */
 public class LightProbeFactory2 {
 
  
+    /**
+     * Creates a LightProbe with the giver EnvironmentCamera in the given scene.
+     * @param rm The RenderManager
+     * @param am The AssetManager
+     * @param size The size of the probe
+     * @param pos The position of the probe
+     * @param frustumNear The near frustum of the probe
+     * @param frustumFar The far frustum of the probe
+     * @param scene The scene to bake
+     * @return The baked LightProbe
+     */
     public static LightProbe makeProbe(RenderManager rm,
     AssetManager am, int size,Vector3f pos, float frustumNear,float frustumFar,Spatial scene) {
         IBLGLEnvBakerLight baker=new IBLGLEnvBakerLight(rm,

+ 21 - 2
jme3-core/src/main/java/com/jme3/environment/baker/EnvBaker.java

@@ -8,12 +8,31 @@ import com.jme3.scene.Spatial;
 import com.jme3.texture.TextureCubeMap;
 
 /**
- * And environment baker. It bakes the environment. ( ͡° ͜ʖ ͡°)
+ * And environment baker. It bakes the environment.
  *
  * @author Riccardo Balbo
  */
 public interface EnvBaker {
-    public void bakeEnvironment(Spatial scene, Vector3f position, float frustumNear, float frustumFar,Function<Geometry,Boolean> filter);
+    /**
+     * Bake the environment
+     * @param scene The scene to bake
+     * @param position The position of the camera
+     * @param frustumNear The near frustum
+     * @param frustumFar The far frustum
+     * @param filter A filter to select which geometries to bake
+     */
+    public void bakeEnvironment(Spatial scene, Vector3f position, float frustumNear, float frustumFar, Function<Geometry, Boolean> filter);
+    
+    /**
+     * Get the environment map
+     * @return The environment map
+     */
     public TextureCubeMap getEnvMap();
+
+    /**
+     * Clean the environment baker
+     * This method should be called when the baker is no longer needed
+     * It will clean up all the resources
+     */
     public void clean();    
 }

+ 97 - 87
jme3-core/src/main/java/com/jme3/environment/baker/GenericEnvBaker.java

@@ -1,16 +1,43 @@
+/*
+ * Copyright (c) 2009-2023 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 package com.jme3.environment.baker;
 
-import java.io.FileOutputStream;
 import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.HashMap;
 import java.util.function.Function;
 
 import com.jme3.asset.AssetManager;
-import com.jme3.environment.baker.EnvBaker;
 import com.jme3.math.ColorRGBA;
 import com.jme3.math.Quaternion;
-import com.jme3.math.Vector2f;
 import com.jme3.math.Vector3f;
 import com.jme3.renderer.Camera;
 import com.jme3.renderer.RenderManager;
@@ -18,6 +45,7 @@ import com.jme3.renderer.ViewPort;
 import com.jme3.scene.Geometry;
 import com.jme3.scene.Spatial;
 import com.jme3.texture.FrameBuffer;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture.MagFilter;
 import com.jme3.texture.Texture.MinFilter;
@@ -26,113 +54,102 @@ import com.jme3.texture.TextureCubeMap;
 import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 
-
 /**
  * Render the environment into a cubemap
  *
  * @author Riccardo Balbo
  */
-public abstract class GenericEnvBaker implements EnvBaker{
-
-    protected static Vector3f[] axisX=new Vector3f[6];
-    protected static Vector3f[] axisY=new Vector3f[6];
-    protected static Vector3f[] axisZ=new Vector3f[6];
-    static{
-        //PositiveX axis(left, up, direction)
-        axisX[0]=Vector3f.UNIT_Z.mult(1.0F);
-        axisY[0]=Vector3f.UNIT_Y.mult(-1.0F);
-        axisZ[0]=Vector3f.UNIT_X.mult(1.0F);
-        //NegativeX
-        axisX[1]=Vector3f.UNIT_Z.mult(-1.0F);
-        axisY[1]=Vector3f.UNIT_Y.mult(-1.0F);
-        axisZ[1]=Vector3f.UNIT_X.mult(-1.0F);
-        //PositiveY
-        axisX[2]=Vector3f.UNIT_X.mult(-1.0F);
-        axisY[2]=Vector3f.UNIT_Z.mult(1.0F);
-        axisZ[2]=Vector3f.UNIT_Y.mult(1.0F);
-        //NegativeY
-        axisX[3]=Vector3f.UNIT_X.mult(-1.0F);
-        axisY[3]=Vector3f.UNIT_Z.mult(-1.0F);
-        axisZ[3]=Vector3f.UNIT_Y.mult(-1.0F);
-        //PositiveZ
-        axisX[4]=Vector3f.UNIT_X.mult(-1.0F);
-        axisY[4]=Vector3f.UNIT_Y.mult(-1.0F);
-        axisZ[4]=Vector3f.UNIT_Z;
-        //NegativeZ
-        axisX[5]=Vector3f.UNIT_X.mult(1.0F);
-        axisY[5]=Vector3f.UNIT_Y.mult(-1.0F);
-        axisZ[5]=Vector3f.UNIT_Z.mult(-1.0F);
+public abstract class GenericEnvBaker implements EnvBaker {
+
+    protected static Vector3f[] axisX = new Vector3f[6];
+    protected static Vector3f[] axisY = new Vector3f[6];
+    protected static Vector3f[] axisZ = new Vector3f[6];
+    static {
+        // PositiveX axis(left, up, direction)
+        axisX[0] = Vector3f.UNIT_Z.mult(1.0F);
+        axisY[0] = Vector3f.UNIT_Y.mult(-1.0F);
+        axisZ[0] = Vector3f.UNIT_X.mult(1.0F);
+        // NegativeX
+        axisX[1] = Vector3f.UNIT_Z.mult(-1.0F);
+        axisY[1] = Vector3f.UNIT_Y.mult(-1.0F);
+        axisZ[1] = Vector3f.UNIT_X.mult(-1.0F);
+        // PositiveY
+        axisX[2] = Vector3f.UNIT_X.mult(-1.0F);
+        axisY[2] = Vector3f.UNIT_Z.mult(1.0F);
+        axisZ[2] = Vector3f.UNIT_Y.mult(1.0F);
+        // NegativeY
+        axisX[3] = Vector3f.UNIT_X.mult(-1.0F);
+        axisY[3] = Vector3f.UNIT_Z.mult(-1.0F);
+        axisZ[3] = Vector3f.UNIT_Y.mult(-1.0F);
+        // PositiveZ
+        axisX[4] = Vector3f.UNIT_X.mult(-1.0F);
+        axisY[4] = Vector3f.UNIT_Y.mult(-1.0F);
+        axisZ[4] = Vector3f.UNIT_Z;
+        // NegativeZ
+        axisX[5] = Vector3f.UNIT_X.mult(1.0F);
+        axisY[5] = Vector3f.UNIT_Y.mult(-1.0F);
+        axisZ[5] = Vector3f.UNIT_Z.mult(-1.0F);
     }
 
     protected TextureCubeMap env;
     protected Format depthFormat;
 
-
     protected final RenderManager renderManager;
     protected final AssetManager assetManager;
     protected final Camera cam;
     protected final boolean copyToRam;
 
+    public GenericEnvBaker(RenderManager rm, AssetManager am, Format colorFormat, Format depthFormat, int env_size, boolean copyToRam) {
+        this.copyToRam = copyToRam;
+        this.depthFormat = depthFormat;
 
-    public GenericEnvBaker(
-        RenderManager rm,
-        AssetManager am,
-        Format colorFormat,
-        Format depthFormat,
-        int env_size,
-        boolean copyToRam
-    ){
-        this.copyToRam=copyToRam;
-        this.depthFormat=depthFormat;
-
-        renderManager=rm;
-        assetManager=am;
+        renderManager = rm;
+        assetManager = am;
 
+        cam = new Camera(128, 128);
 
-        cam=new Camera(128,128);
-        
-        env=new TextureCubeMap(env_size,env_size,colorFormat);
+        env = new TextureCubeMap(env_size, env_size, colorFormat);
         env.setMagFilter(MagFilter.Bilinear);
         env.setMinFilter(MinFilter.BilinearNoMipMaps);
         env.setWrap(WrapMode.EdgeClamp);
         env.getImage().setColorSpace(ColorSpace.Linear);
     }
 
-    public TextureCubeMap getEnvMap(){
+    public TextureCubeMap getEnvMap() {
         return env;
-    }   
+    }
 
-    Camera getCam(int id,int w,int h,Vector3f position,float frustumNear,float frustumFar){
-        cam.resize(w,h,false);
+    Camera getCam(int id, int w, int h, Vector3f position, float frustumNear, float frustumFar) {
+        cam.resize(w, h, false);
         cam.setLocation(position);
-        cam.setFrustumPerspective(90.0F,1F,frustumNear,frustumFar);
-        cam.setRotation(new Quaternion().fromAxes(axisX[id],axisY[id],axisZ[id]));
+        cam.setFrustumPerspective(90.0F, 1F, frustumNear, frustumFar);
+        cam.setRotation(new Quaternion().fromAxes(axisX[id], axisY[id], axisZ[id]));
         return cam;
-    }    
+    }
 
     @Override
-    public void clean(){
+    public void clean() {
         env.getImage().dispose();
         System.gc();
-        System.gc();        
+        System.gc();
     }
 
-
     @Override
-    public void bakeEnvironment(Spatial scene,   Vector3f position, float frustumNear, float frustumFar,Function<Geometry,Boolean> filter) {       
-        FrameBuffer envbaker=new FrameBuffer(env.getImage().getWidth(),env.getImage().getHeight(),1);
-        envbaker.setDepthTarget(FrameBuffer.newTarget(depthFormat));
+    public void bakeEnvironment(Spatial scene, Vector3f position, float frustumNear, float frustumFar, Function<Geometry, Boolean> filter) {
+        FrameBuffer envbaker = new FrameBuffer(env.getImage().getWidth(), env.getImage().getHeight(), 1);
+
+        envbaker.setDepthTarget(FrameBufferTarget.newTarget(depthFormat));
         envbaker.setSrgb(false);
 
-        for(int i=0;i<6;i++) envbaker.addColorTarget(FrameBuffer.newTarget(env).face(TextureCubeMap.Face.values()[i]));
-            
-          for(int i=0;i<6;i++){
+        for (int i = 0; i < 6; i++) envbaker.addColorTarget(FrameBufferTarget.newTarget(env).face(TextureCubeMap.Face.values()[i]));
+
+        for (int i = 0; i < 6; i++) {
             envbaker.setTargetIndex(i);
 
-            ViewPort viewPort=new ViewPort("EnvBaker",getCam(i,envbaker.getWidth(),envbaker.getHeight(),position,frustumNear,frustumFar));
-            viewPort.setClearFlags(true,true,true);
+            ViewPort viewPort = new ViewPort("EnvBaker", getCam(i, envbaker.getWidth(), envbaker.getHeight(), position, frustumNear, frustumFar));
+            viewPort.setClearFlags(true, true, true);
             viewPort.setBackgroundColor(ColorRGBA.Pink);
-        
+
             viewPort.setOutputFrameBuffer(envbaker);
             viewPort.clearScenes();
             viewPort.attachScene(scene);
@@ -140,32 +157,25 @@ public abstract class GenericEnvBaker implements EnvBaker{
             scene.updateLogicalState(0);
             scene.updateModelBound();
             scene.updateGeometricState();
-           
-            Function<Geometry,Boolean> ofilter= renderManager.getRenderFilter();
+
+            Function<Geometry, Boolean> ofilter = renderManager.getRenderFilter();
 
             renderManager.setRenderFilter(filter);
-            renderManager.renderViewPort(viewPort,0.16f);
+            renderManager.renderViewPort(viewPort, 0.16f);
             renderManager.setRenderFilter(ofilter);
 
-            if(copyToRam){
-                ByteBuffer face=BufferUtils.createByteBuffer(
-                    (
-                        env.getImage().getWidth()*env.getImage().getHeight()*(
-                            env.getImage().getFormat().getBitsPerPixel()/8
-                        )
-                    )
-                ); 
-                renderManager.getRenderer().readFrameBufferWithFormat(envbaker, face,env.getImage().getFormat());
+            if (copyToRam) {
+                ByteBuffer face = BufferUtils.createByteBuffer((env.getImage().getWidth() * env.getImage().getHeight() * (env.getImage().getFormat().getBitsPerPixel() / 8)));
+                renderManager.getRenderer().readFrameBufferWithFormat(envbaker, face, env.getImage().getFormat());
                 face.rewind();
-                env.getImage().setData(i,face);
+                env.getImage().setData(i, face);
 
             }
         }
 
         env.getImage().clearUpdateNeeded();
-  
+
         envbaker.dispose();
     }
 
-    
 }

+ 54 - 1
jme3-core/src/main/java/com/jme3/environment/baker/IBLEnvBaker.java

@@ -1,3 +1,36 @@
+/*
+ * Copyright (c) 2009-2023 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
 package com.jme3.environment.baker;
 
 import com.jme3.texture.Texture2D;
@@ -8,12 +41,32 @@ import com.jme3.texture.TextureCubeMap;
  *
  * @author Riccardo Balbo
  */
-public interface IBLEnvBaker extends EnvBaker{
+public interface IBLEnvBaker extends EnvBaker {
+    /**
+     * Generate the BRDF texture
+     * @return The BRDF texture
+     */
     public Texture2D genBRTF() ;
     
+    /**
+     * Bake the irradiance map
+     */
     public void bakeIrradiance();
+
+    /**
+     * Bake the specular IBL map
+     */
     public void bakeSpecularIBL() ;
 
+    /**
+     * Get the specular IBL map
+     * @return The specular IBL map
+     */
     public TextureCubeMap getSpecularIBL();
+
+    /**
+     * Get the irradiance map
+     * @return The irradiance map
+     */
     public TextureCubeMap getIrradiance();
 }

+ 35 - 2
jme3-core/src/main/java/com/jme3/environment/baker/IBLEnvBakerLight.java

@@ -1,3 +1,36 @@
+/*
+ * Copyright (c) 2009-2023 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+ 
 package com.jme3.environment.baker;
 
 import com.jme3.math.Vector3f;
@@ -5,10 +38,10 @@ import com.jme3.texture.TextureCubeMap;
 
 /**
  * An environment baker for IBL, that uses spherical harmonics for irradiance.
- *
  * @author Riccardo Balbo
  */
-public interface IBLEnvBakerLight extends EnvBaker{   
+public interface IBLEnvBakerLight extends EnvBaker {
+    
     public void bakeSpecularIBL();
     public void bakeSphericalHarmonicsCoefficients();
 

+ 38 - 5
jme3-core/src/main/java/com/jme3/environment/baker/IBLGLEnvBaker.java

@@ -1,7 +1,39 @@
+/*
+ * Copyright (c) 2009-2023 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
 package com.jme3.environment.baker;
 
 import com.jme3.asset.AssetManager;
-import com.jme3.environment.baker.IBLEnvBaker;
 import com.jme3.material.Material;
 import com.jme3.math.FastMath;
 import com.jme3.math.Vector3f;
@@ -16,12 +48,13 @@ import com.jme3.texture.Texture.MinFilter;
 import com.jme3.texture.Texture.WrapMode;
 import com.jme3.texture.Texture2D;
 import com.jme3.texture.TextureCubeMap;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.texture.image.ColorSpace;
 import com.jme3.ui.Picture;
 
 
 /**
- *  An env baker for IBL that runs on the GPU 
+ *  An env baker for IBL that runs entirely on the GPU 
  * 
  * @author Riccardo Balbo
  */
@@ -92,7 +125,7 @@ public class IBLGLEnvBaker extends GenericEnvBaker implements IBLEnvBaker{
             FrameBuffer specularbaker=new FrameBuffer(mipWidth,mipHeight,1);
             specularbaker.setSrgb(false);
 
-            for(int i=0;i<6;i++)specularbaker.addColorTarget( FrameBuffer.newTarget(specular).level(mip).face(i) );
+            for(int i=0;i<6;i++)specularbaker.addColorTarget( FrameBufferTarget.newTarget(specular).level(mip).face(i) );
             
             float roughness=(float)mip/(float)(specular.getImage().getMipMapSizes().length-1);
             mat.setFloat("Roughness",roughness);
@@ -122,7 +155,7 @@ public class IBLGLEnvBaker extends GenericEnvBaker implements IBLEnvBaker{
 
         FrameBuffer brtfbaker=new FrameBuffer(brtf.getImage().getWidth(),brtf.getImage().getHeight(),1);
         brtfbaker.setSrgb(false);
-        brtfbaker.addColorTarget(FrameBuffer.newTarget(brtf));
+        brtfbaker.addColorTarget(FrameBufferTarget.newTarget(brtf));
 
         Camera envcam=getCam(0,brtf.getImage().getWidth(),brtf.getImage().getHeight(),Vector3f.ZERO,1,1000);
 
@@ -152,7 +185,7 @@ public class IBLGLEnvBaker extends GenericEnvBaker implements IBLEnvBaker{
         FrameBuffer irradiancebaker=new FrameBuffer(irradiance.getImage().getWidth(),irradiance.getImage().getHeight(),1);
         irradiancebaker.setSrgb(false);
         
-        for(int i=0;i<6;i++) irradiancebaker.addColorTarget(FrameBuffer.newTarget(irradiance).face(TextureCubeMap.Face.values()[i]));
+        for(int i=0;i<6;i++) irradiancebaker.addColorTarget(FrameBufferTarget.newTarget(irradiance).face(TextureCubeMap.Face.values()[i]));
 
         Material mat=new Material(assetManager,"Common/IBL/IBLKernels.j3md");
         mat.setBoolean("UseIrradiance",true);

+ 76 - 45
jme3-core/src/main/java/com/jme3/environment/baker/IBLGLEnvBakerLight.java

@@ -1,7 +1,38 @@
+/*
+ * Copyright (c) 2009-2023 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 package com.jme3.environment.baker;
 
 import com.jme3.asset.AssetManager;
-import com.jme3.environment.baker.IBLEnvBakerLight;
 import com.jme3.environment.util.EnvMapUtils;
 import com.jme3.material.Material;
 import com.jme3.math.FastMath;
@@ -11,6 +42,7 @@ import com.jme3.scene.Geometry;
 import com.jme3.scene.shape.Box;
 import com.jme3.texture.FrameBuffer;
 import com.jme3.texture.TextureCubeMap;
+import com.jme3.texture.FrameBuffer.FrameBufferTarget;
 import com.jme3.texture.Image.Format;
 import com.jme3.texture.Texture.MagFilter;
 import com.jme3.texture.Texture.MinFilter;
@@ -18,87 +50,86 @@ import com.jme3.texture.Texture.WrapMode;
 import com.jme3.texture.image.ColorSpace;
 
 /**
- *  An env baker for IBL that runs on the GPU 
+ * An env baker for IBL that bakes the specular map on the GPU and uses
+ * spherical harmonics for the irradiance map.
+ * 
+ * This is lighter on VRAM but uses the CPU to compute the irradiance map.
  * 
  * @author Riccardo Balbo
  */
-public class IBLGLEnvBakerLight extends GenericEnvBaker implements IBLEnvBakerLight{
+public class IBLGLEnvBakerLight extends GenericEnvBaker implements IBLEnvBakerLight {
     protected TextureCubeMap specular;
     protected Vector3f[] shCoef;
-    public IBLGLEnvBakerLight(RenderManager rm,AssetManager am,
-                        Format format,
-                        Format depthFormat,
-                        int env_size,
-                        int specular_size
-                     
-    ){
-        super(rm,am,format,depthFormat,env_size,true);
-
-        specular=new TextureCubeMap(specular_size,specular_size,format);
+
+    public IBLGLEnvBakerLight(RenderManager rm, AssetManager am, Format format, Format depthFormat, int env_size, int specular_size
+
+    ) {
+        super(rm, am, format, depthFormat, env_size, true);
+
+        specular = new TextureCubeMap(specular_size, specular_size, format);
         specular.setMagFilter(MagFilter.Bilinear);
         specular.setMinFilter(MinFilter.BilinearNoMipMaps);
         specular.setWrap(WrapMode.EdgeClamp);
         specular.getImage().setColorSpace(ColorSpace.Linear);
-        int nbMipMaps=(int)(Math.log(specular_size)/Math.log(2)+1);
-        if(nbMipMaps>6)nbMipMaps=6;
-        int[] sizes=new int[nbMipMaps];
-        for(int i=0;i<nbMipMaps;i++){
-            int size=(int)FastMath.pow(2,nbMipMaps-1-i);
-            sizes[i]=size*size*(specular.getImage().getFormat().getBitsPerPixel()/8);
+        int nbMipMaps = (int) (Math.log(specular_size) / Math.log(2) + 1);
+        if (nbMipMaps > 6) nbMipMaps = 6;
+        int[] sizes = new int[nbMipMaps];
+        for (int i = 0; i < nbMipMaps; i++) {
+            int size = (int) FastMath.pow(2, nbMipMaps - 1 - i);
+            sizes[i] = size * size * (specular.getImage().getFormat().getBitsPerPixel() / 8);
         }
         specular.getImage().setMipMapSizes(sizes);
-	}
-
+    }
 
     @Override
     public void bakeSpecularIBL() {
-        Box boxm=new Box(1,1,1);
-        Geometry screen=new Geometry("BakeBox",boxm);
-    
-        Material mat=new Material(assetManager,"Common/IBL/IBLKernels.j3md");
-        mat.setBoolean("UseSpecularIBL",true);
-        mat.setTexture("EnvMap",env);
+        Box boxm = new Box(1, 1, 1);
+        Geometry screen = new Geometry("BakeBox", boxm);
+
+        Material mat = new Material(assetManager, "Common/IBL/IBLKernels.j3md");
+        mat.setBoolean("UseSpecularIBL", true);
+        mat.setTexture("EnvMap", env);
         screen.setMaterial(mat);
-    
-        for(int mip=0;mip<specular.getImage().getMipMapSizes().length;mip++){
-            int mipWidth=(int)(specular.getImage().getWidth()*FastMath.pow(0.5f,mip));
-            int mipHeight=(int)(specular.getImage().getHeight()*FastMath.pow(0.5f,mip));
 
-            FrameBuffer specularbaker=new FrameBuffer(mipWidth,mipHeight,1);
+        for (int mip = 0; mip < specular.getImage().getMipMapSizes().length; mip++) {
+            int mipWidth = (int) (specular.getImage().getWidth() * FastMath.pow(0.5f, mip));
+            int mipHeight = (int) (specular.getImage().getHeight() * FastMath.pow(0.5f, mip));
+
+            FrameBuffer specularbaker = new FrameBuffer(mipWidth, mipHeight, 1);
             specularbaker.setSrgb(false);
-            for(int i=0;i<6;i++)specularbaker.addColorTarget( FrameBuffer.newTarget(specular).level(mip).face(i) );
-            
-            float roughness=(float)mip/(float)(specular.getImage().getMipMapSizes().length-1);
-            mat.setFloat("Roughness",roughness);
+            for (int i = 0; i < 6; i++) specularbaker.addColorTarget(FrameBufferTarget.newTarget(specular).level(mip).face(i));
+
+            float roughness = (float) mip / (float) (specular.getImage().getMipMapSizes().length - 1);
+            mat.setFloat("Roughness", roughness);
 
-            for(int i=0;i<6;i++){
+            for (int i = 0; i < 6; i++) {
                 specularbaker.setTargetIndex(i);
-                mat.setInt("FaceId",i);
+                mat.setInt("FaceId", i);
 
                 screen.updateLogicalState(0);
                 screen.updateGeometricState();
 
-                renderManager.setCamera(getCam(i,specularbaker.getWidth(),specularbaker.getHeight(),Vector3f.ZERO,1,1000),false);
+                renderManager.setCamera(getCam(i, specularbaker.getWidth(), specularbaker.getHeight(), Vector3f.ZERO, 1, 1000), false);
                 renderManager.getRenderer().setFrameBuffer(specularbaker);
                 renderManager.renderGeometry(screen);
             }
             specularbaker.dispose();
-        }        
-        specular.setMinFilter(MinFilter.Trilinear);        
+        }
+        specular.setMinFilter(MinFilter.Trilinear);
     }
 
     @Override
     public TextureCubeMap getSpecularIBL() {
         return specular;
     }
-    
+
     @Override
     public void bakeSphericalHarmonicsCoefficients() {
-		shCoef=EnvMapUtils.getSphericalHarmonicsCoefficents(getEnvMap());
-	}
+        shCoef = EnvMapUtils.getSphericalHarmonicsCoefficents(getEnvMap());
+    }
 
     @Override
-    public Vector3f[] getSphericalHarmonicsCoefficients(){
+    public Vector3f[] getSphericalHarmonicsCoefficients() {
         return shCoef;
     }
 }