* Prevent UnsupportedOperationException when using LightMode SinglePass

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7491 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 14 years ago
parent bfe76ba56a
commit 3430cd93d1
  1. 25
      engine/src/core/com/jme3/material/Material.java

@ -560,10 +560,15 @@ public class Material implements Cloneable, Savable, Comparable<Material> {
lightColor.setVector4Length(numLights);
lightPos.setVector4Length(numLights);
Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));
int lightIndex = 0;
for (int i = 0; i < numLights; i++) {
if (lightList.size() <= i) {
lightColor.setVector4InArray(0f, 0f, 0f, 0f, i);
lightPos.setVector4InArray(0f, 0f, 0f, 0f, i);
lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
} else {
Light l = lightList.get(i);
ColorRGBA color = l.getColor();
@ -577,7 +582,7 @@ public class Material implements Cloneable, Savable, Comparable<Material> {
case Directional:
DirectionalLight dl = (DirectionalLight) l;
Vector3f dir = dl.getDirection();
lightPos.setVector4InArray(dir.getX(), dir.getY(), dir.getZ(), -1, i);
lightPos.setVector4InArray(dir.getX(), dir.getY(), dir.getZ(), -1, lightIndex);
break;
case Point:
PointLight pl = (PointLight) l;
@ -586,12 +591,24 @@ public class Material implements Cloneable, Savable, Comparable<Material> {
if (invRadius != 0) {
invRadius = 1f / invRadius;
}
lightPos.setVector4InArray(pos.getX(), pos.getY(), pos.getZ(), invRadius, i);
lightPos.setVector4InArray(pos.getX(), pos.getY(), pos.getZ(), invRadius, lightIndex);
break;
case Ambient:
// skip this light. Does not increase lightIndex
continue;
default:
throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
}
}
lightIndex++;
}
while (lightIndex < numLights){
lightColor.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
lightPos.setVector4InArray(0f, 0f, 0f, 0f, lightIndex);
lightIndex++;
}
}

Loading…
Cancel
Save