diff --git a/jme3-core/src/main/java/com/jme3/material/Material.java b/jme3-core/src/main/java/com/jme3/material/Material.java index a727f104e..6e3e36bfc 100644 --- a/jme3-core/src/main/java/com/jme3/material/Material.java +++ b/jme3-core/src/main/java/com/jme3/material/Material.java @@ -777,6 +777,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { Vector4f tmpVec = vars.vect4f1; int curIndex; int endIndex = numLights + startIndex; + boolean useIBL = false; for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) { @@ -841,7 +842,8 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { lightDataIndex++; break; case Probe: - + useIBL = true; + technique.setUseIndirectLighting(true); endIndex++; LightProbe probe = (LightProbe)l; BoundingSphere s = (BoundingSphere)probe.getBounds(); @@ -862,6 +864,10 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { } } vars.release(); + + if(!useIBL ){ + technique.setUseIndirectLighting(false); + } //Padding of unsued buffer space while(lightDataIndex < numLights * 3) { lightData.setVector4InArray(0f, 0f, 0f, 0f, lightDataIndex); @@ -1238,7 +1244,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { nbRenderedLights = updateLightListUniforms(shader, geom, lights, rm.getSinglePassLightBatchSize(), rm, nbRenderedLights); r.setShader(shader); renderMeshFromGeometry(r, geom); - } + } } return; case FixedPipeline: diff --git a/jme3-core/src/main/java/com/jme3/material/Technique.java b/jme3-core/src/main/java/com/jme3/material/Technique.java index 8321991bf..66fe319e6 100644 --- a/jme3-core/src/main/java/com/jme3/material/Technique.java +++ b/jme3-core/src/main/java/com/jme3/material/Technique.java @@ -187,6 +187,15 @@ public class Technique /* implements Savable */ { loadShader(assetManager,rendererCaps); } } + + public void setUseIndirectLighting(boolean useIBL){ + if(useIBL){ + defines.set("INDIRECT_LIGHTING", VarType.Boolean, true); + }else{ + defines.remove("INDIRECT_LIGHTING"); + } + needReload = true; + } private void loadShader(AssetManager manager,EnumSet rendererCaps) { diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag index 240fed2ba..de9150b86 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag @@ -202,7 +202,7 @@ void main(){ gl_FragColor.rgb += directLighting * fallOff; } - // #ifdef INDIRECT_LIGHTING + #ifdef INDIRECT_LIGHTING vec3 rv = reflect(-viewDir.xyz, normal.xyz); //prallax fix for spherical bounds. rv = g_ProbeData.w * (wPosition - g_ProbeData.xyz) +rv; @@ -223,7 +223,7 @@ void main(){ vec3 indirectLighting = indirectDiffuse + indirectSpecular; gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting ; - // #endif + #endif #if defined(EMISSIVE) || defined (EMISSIVEMAP) #ifdef EMISSIVEMAP diff --git a/jme3-examples/src/main/java/jme3test/light/pbr/TestPbrEnv.java b/jme3-examples/src/main/java/jme3test/light/pbr/TestPbrEnv.java index fa6fa8df2..e1754f6fa 100644 --- a/jme3-examples/src/main/java/jme3test/light/pbr/TestPbrEnv.java +++ b/jme3-examples/src/main/java/jme3test/light/pbr/TestPbrEnv.java @@ -265,13 +265,15 @@ public class TestPbrEnv extends SimpleApplication implements ActionListener { inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN)); inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT)); inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT)); + inputManager.addMapping("delete", new KeyTrigger(KeyInput.KEY_DELETE)); - inputManager.addListener(this, "switchGroundMat", "snapshot", "debugTex", "debugProbe", "fc", "up", "down", "left", "right"); + inputManager.addListener(this, "delete","switchGroundMat", "snapshot", "debugTex", "debugProbe", "fc", "up", "down", "left", "right"); } private LightProbe lastProbe; private Node debugGui ; + @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("switchGroundMat") && keyPressed) { @@ -290,6 +292,13 @@ public class TestPbrEnv extends SimpleApplication implements ActionListener { rootNode.addLight(lastProbe); } + + if (name.equals("delete") && keyPressed) { + System.err.println(rootNode.getWorldLightList().size()); + rootNode.removeLight(lastProbe); + System.err.println("deleted"); + System.err.println(rootNode.getWorldLightList().size()); + } if (name.equals("fc") && keyPressed) {