SP / MP Lighting: render ambient color if no lights or only ambient lights

- Prevents "invisible model" bug if there are no lights
experimental
shadowislord 10 years ago
parent 32e56351df
commit 4c69cc00a6
  1. 17
      jme3-core/src/main/java/com/jme3/material/Material.java

@ -935,9 +935,9 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
renderMeshFromGeometry(r, g); renderMeshFromGeometry(r, g);
} }
if (isFirstLight && lightList.size() > 0) { if (isFirstLight) {
// There are only ambient lights in the scene. Render // Either there are no lights at all, or only ambient lights.
// a dummy "normal light" so we can see the ambient // Render a dummy "normal light" so we can see the ambient color.
ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList, false)); ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList, false));
lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha); lightColor.setValue(VarType.Vector4, ColorRGBA.BlackNoAlpha);
lightPos.setValue(VarType.Vector4, nullDirLight); lightPos.setValue(VarType.Vector4, nullDirLight);
@ -1152,11 +1152,6 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
TechniqueDef techDef = technique.getDef(); TechniqueDef techDef = technique.getDef();
if (techDef.getLightMode() == LightMode.MultiPass
&& lights.size() == 0) {
return;
}
if (rm.getForcedRenderState() != null) { if (rm.getForcedRenderState() != null) {
r.applyRenderState(rm.getForcedRenderState()); r.applyRenderState(rm.getForcedRenderState());
} else { } else {
@ -1191,11 +1186,17 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
case SinglePass: case SinglePass:
int nbRenderedLights = 0; int nbRenderedLights = 0;
resetUniformsNotSetByCurrent(shader); resetUniformsNotSetByCurrent(shader);
if (lights.size() == 0) {
nbRenderedLights = updateLightListUniforms(shader, geom, lights, rm.getSinglePassLightBatchSize(), rm, 0);
r.setShader(shader);
renderMeshFromGeometry(r, geom);
} else {
while (nbRenderedLights < lights.size()) { while (nbRenderedLights < lights.size()) {
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:
throw new IllegalArgumentException("OpenGL1 is not supported"); throw new IllegalArgumentException("OpenGL1 is not supported");

Loading…
Cancel
Save