Added a define to toggle indirect lighting on or off, depending if there is a light probe in the light list or not.

However, this is not ideal, as this code will trigger a recompilation of the shader on each pass, in case there is more than 1 lighting pass.
Another way could be to multiply the indirect lighting contribution by the Ambient light color in the shader, and always perform the indirect lighting code (even without light probe).
As in the second pass ambient light is forced to 0, the indirect lighting contribution would be nullified. However we'd have to force ambient light to 0 if there are no light probe.
This would also have the nice side effect of having a way to dim or boost indirect lighting with the ambient light color.
define_list_fix
Nehon 9 years ago
parent 39fe8326ba
commit ab981b76fc
  1. 10
      jme3-core/src/main/java/com/jme3/material/Material.java
  2. 9
      jme3-core/src/main/java/com/jme3/material/Technique.java
  3. 4
      jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag
  4. 11
      jme3-examples/src/main/java/jme3test/light/pbr/TestPbrEnv.java

@ -777,6 +777,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
Vector4f tmpVec = vars.vect4f1; Vector4f tmpVec = vars.vect4f1;
int curIndex; int curIndex;
int endIndex = numLights + startIndex; int endIndex = numLights + startIndex;
boolean useIBL = false;
for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) { for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) {
@ -841,7 +842,8 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
lightDataIndex++; lightDataIndex++;
break; break;
case Probe: case Probe:
useIBL = true;
technique.setUseIndirectLighting(true);
endIndex++; endIndex++;
LightProbe probe = (LightProbe)l; LightProbe probe = (LightProbe)l;
BoundingSphere s = (BoundingSphere)probe.getBounds(); BoundingSphere s = (BoundingSphere)probe.getBounds();
@ -862,6 +864,10 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
} }
} }
vars.release(); vars.release();
if(!useIBL ){
technique.setUseIndirectLighting(false);
}
//Padding of unsued buffer space //Padding of unsued buffer space
while(lightDataIndex < numLights * 3) { while(lightDataIndex < numLights * 3) {
lightData.setVector4InArray(0f, 0f, 0f, 0f, lightDataIndex); 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); nbRenderedLights = updateLightListUniforms(shader, geom, lights, rm.getSinglePassLightBatchSize(), rm, nbRenderedLights);
r.setShader(shader); r.setShader(shader);
renderMeshFromGeometry(r, geom); renderMeshFromGeometry(r, geom);
} }
} }
return; return;
case FixedPipeline: case FixedPipeline:

@ -187,6 +187,15 @@ public class Technique /* implements Savable */ {
loadShader(assetManager,rendererCaps); 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<Caps> rendererCaps) { private void loadShader(AssetManager manager,EnumSet<Caps> rendererCaps) {

@ -202,7 +202,7 @@ void main(){
gl_FragColor.rgb += directLighting * fallOff; gl_FragColor.rgb += directLighting * fallOff;
} }
// #ifdef INDIRECT_LIGHTING #ifdef INDIRECT_LIGHTING
vec3 rv = reflect(-viewDir.xyz, normal.xyz); vec3 rv = reflect(-viewDir.xyz, normal.xyz);
//prallax fix for spherical bounds. //prallax fix for spherical bounds.
rv = g_ProbeData.w * (wPosition - g_ProbeData.xyz) +rv; rv = g_ProbeData.w * (wPosition - g_ProbeData.xyz) +rv;
@ -223,7 +223,7 @@ void main(){
vec3 indirectLighting = indirectDiffuse + indirectSpecular; vec3 indirectLighting = indirectDiffuse + indirectSpecular;
gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting ; gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting ;
// #endif #endif
#if defined(EMISSIVE) || defined (EMISSIVEMAP) #if defined(EMISSIVE) || defined (EMISSIVEMAP)
#ifdef EMISSIVEMAP #ifdef EMISSIVEMAP

@ -265,13 +265,15 @@ public class TestPbrEnv extends SimpleApplication implements ActionListener {
inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN)); inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT)); inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT));
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT)); 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 LightProbe lastProbe;
private Node debugGui ; private Node debugGui ;
@Override
public void onAction(String name, boolean keyPressed, float tpf) { public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("switchGroundMat") && keyPressed) { if (name.equals("switchGroundMat") && keyPressed) {
@ -290,6 +292,13 @@ public class TestPbrEnv extends SimpleApplication implements ActionListener {
rootNode.addLight(lastProbe); 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) { if (name.equals("fc") && keyPressed) {

Loading…
Cancel
Save