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. 8
      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;
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);

@ -188,6 +188,15 @@ public class Technique /* implements Savable */ {
}
}
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) {
ShaderKey key = new ShaderKey(getAllDefines(),def.getShaderProgramLanguages(),def.getShaderProgramNames());

@ -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

@ -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) {
@ -291,6 +293,13 @@ public class TestPbrEnv extends SimpleApplication implements ActionListener {
}
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) {
flyCam.setEnabled(true);

Loading…
Cancel
Save