|
|
|
@ -120,73 +120,72 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic { |
|
|
|
|
int endIndex = numLights + startIndex; |
|
|
|
|
for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) { |
|
|
|
|
|
|
|
|
|
Light l = lightList.get(curIndex); |
|
|
|
|
if (l.getType() == Light.Type.Ambient) { |
|
|
|
|
endIndex++; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
ColorRGBA color = l.getColor(); |
|
|
|
|
//Color
|
|
|
|
|
lightData.setVector4InArray(color.getRed(), |
|
|
|
|
color.getGreen(), |
|
|
|
|
color.getBlue(), |
|
|
|
|
l.getType().getId(), |
|
|
|
|
lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
|
|
|
|
|
Light l = lightList.get(curIndex); |
|
|
|
|
if(l.getType() == Light.Type.Ambient){ |
|
|
|
|
endIndex++; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
ColorRGBA color = l.getColor(); |
|
|
|
|
//Color
|
|
|
|
|
lightData.setVector4InArray(color.getRed(), |
|
|
|
|
color.getGreen(), |
|
|
|
|
color.getBlue(), |
|
|
|
|
l.getType().getId(), |
|
|
|
|
lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
|
|
|
|
|
switch (l.getType()) { |
|
|
|
|
case Directional: |
|
|
|
|
DirectionalLight dl = (DirectionalLight) l; |
|
|
|
|
Vector3f dir = dl.getDirection(); |
|
|
|
|
//Data directly sent in view space to avoid a matrix mult for each pixel
|
|
|
|
|
tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f); |
|
|
|
|
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); |
|
|
|
|
switch (l.getType()) { |
|
|
|
|
case Directional: |
|
|
|
|
DirectionalLight dl = (DirectionalLight) l; |
|
|
|
|
Vector3f dir = dl.getDirection(); |
|
|
|
|
//Data directly sent in view space to avoid a matrix mult for each pixel
|
|
|
|
|
tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f); |
|
|
|
|
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); |
|
|
|
|
// tmpVec.divideLocal(tmpVec.w);
|
|
|
|
|
// tmpVec.normalizeLocal();
|
|
|
|
|
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
//PADDING
|
|
|
|
|
lightData.setVector4InArray(0,0,0,0, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
break; |
|
|
|
|
case Point: |
|
|
|
|
PointLight pl = (PointLight) l; |
|
|
|
|
Vector3f pos = pl.getPosition(); |
|
|
|
|
float invRadius = pl.getInvRadius(); |
|
|
|
|
tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f); |
|
|
|
|
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); |
|
|
|
|
//tmpVec.divideLocal(tmpVec.w);
|
|
|
|
|
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
//PADDING
|
|
|
|
|
lightData.setVector4InArray(0,0,0,0, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
break; |
|
|
|
|
case Spot: |
|
|
|
|
SpotLight sl = (SpotLight) l; |
|
|
|
|
Vector3f pos2 = sl.getPosition(); |
|
|
|
|
Vector3f dir2 = sl.getDirection(); |
|
|
|
|
float invRange = sl.getInvSpotRange(); |
|
|
|
|
float spotAngleCos = sl.getPackedAngleCos(); |
|
|
|
|
tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f); |
|
|
|
|
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); |
|
|
|
|
// tmpVec.divideLocal(tmpVec.w);
|
|
|
|
|
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
|
|
|
|
|
//We transform the spot direction in view space here to save 5 varying later in the lighting shader
|
|
|
|
|
//one vec4 less and a vec4 that becomes a vec3
|
|
|
|
|
//the downside is that spotAngleCos decoding happens now in the frag shader.
|
|
|
|
|
tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f); |
|
|
|
|
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); |
|
|
|
|
tmpVec.normalizeLocal(); |
|
|
|
|
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw new UnsupportedOperationException("Unknown type of light: " + l.getType()); |
|
|
|
|
} |
|
|
|
|
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
//PADDING
|
|
|
|
|
lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
break; |
|
|
|
|
case Point: |
|
|
|
|
PointLight pl = (PointLight) l; |
|
|
|
|
Vector3f pos = pl.getPosition(); |
|
|
|
|
float invRadius = pl.getInvRadius(); |
|
|
|
|
tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f); |
|
|
|
|
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); |
|
|
|
|
//tmpVec.divideLocal(tmpVec.w);
|
|
|
|
|
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
//PADDING
|
|
|
|
|
lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
break; |
|
|
|
|
case Spot: |
|
|
|
|
SpotLight sl = (SpotLight) l; |
|
|
|
|
Vector3f pos2 = sl.getPosition(); |
|
|
|
|
Vector3f dir2 = sl.getDirection(); |
|
|
|
|
float invRange = sl.getInvSpotRange(); |
|
|
|
|
float spotAngleCos = sl.getPackedAngleCos(); |
|
|
|
|
tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f); |
|
|
|
|
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); |
|
|
|
|
// tmpVec.divideLocal(tmpVec.w);
|
|
|
|
|
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
|
|
|
|
|
//We transform the spot direction in view space here to save 5 varying later in the lighting shader
|
|
|
|
|
//one vec4 less and a vec4 that becomes a vec3
|
|
|
|
|
//the downside is that spotAngleCos decoding happens now in the frag shader.
|
|
|
|
|
tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f); |
|
|
|
|
rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec); |
|
|
|
|
tmpVec.normalizeLocal(); |
|
|
|
|
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex); |
|
|
|
|
lightDataIndex++; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw new UnsupportedOperationException("Unknown type of light: " + l.getType()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
vars.release(); |
|
|
|
|
//Padding of unsued buffer space
|
|
|
|
@ -197,7 +196,6 @@ public final class SinglePassLightingLogic extends DefaultTechniqueDefLogic { |
|
|
|
|
return curIndex; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights) { |
|
|
|
|
int nbRenderedLights = 0; |
|
|
|
|