use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class SceneLoader method endElement.
@Override
public void endElement(String uri, String name, String qName) throws SAXException {
if (qName.equals("node")) {
node = node.getParent();
} else if (qName.equals("nodes")) {
node = null;
} else if (qName.equals("entity")) {
node = entityNode.getParent();
entityNode = null;
} else if (qName.equals("camera")) {
node = cameraNode.getParent();
cameraNode = null;
} else if (qName.equals("light")) {
// apply the node's world transform on the light..
root.updateGeometricState();
if (light != null) {
if (light instanceof DirectionalLight) {
DirectionalLight dl = (DirectionalLight) light;
Quaternion q = node.getWorldRotation();
Vector3f dir = dl.getDirection();
q.multLocal(dir);
dl.setDirection(dir);
} else if (light instanceof PointLight) {
PointLight pl = (PointLight) light;
Vector3f pos = node.getWorldTranslation();
pl.setPosition(pos);
} else if (light instanceof SpotLight) {
SpotLight sl = (SpotLight) light;
Vector3f pos = node.getWorldTranslation();
sl.setPosition(pos);
Quaternion q = node.getWorldRotation();
Vector3f dir = sl.getDirection();
q.multLocal(dir);
sl.setDirection(dir);
}
}
light = null;
}
checkTopNode(qName);
elementStack.pop();
}
use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class TestJaime method setupLights.
public void setupLights() {
AmbientLight al = new AmbientLight();
al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1));
rootNode.addLight(al);
SpotLight sl = new SpotLight();
sl.setColor(ColorRGBA.White.mult(1.0f));
sl.setPosition(new Vector3f(1.2074411f, 10.6868908f, 4.1489987f));
sl.setDirection(sl.getPosition().mult(-1));
sl.setSpotOuterAngle(0.1f);
sl.setSpotInnerAngle(0.004f);
rootNode.addLight(sl);
//pointlight to fake indirect light coming from the ground
PointLight pl = new PointLight();
pl.setColor(ColorRGBA.White.mult(1.5f));
pl.setPosition(new Vector3f(0, 0, 1));
pl.setRadius(2);
rootNode.addLight(pl);
SpotLightShadowRenderer shadows = new SpotLightShadowRenderer(assetManager, 1024);
shadows.setLight(sl);
shadows.setShadowIntensity(0.3f);
shadows.setEdgeFilteringMode(EdgeFilteringMode.PCF8);
viewPort.addProcessor(shadows);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
SSAOFilter filter = new SSAOFilter(0.10997847f, 0.440001f, 0.39999998f, -0.008000026f);
;
fpp.addFilter(filter);
fpp.addFilter(new FXAAFilter());
fpp.addFilter(new FXAAFilter());
viewPort.addProcessor(fpp);
}
use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class LightHelper method toLight.
public Light toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
Light result = (Light) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedDataType.FEATURE);
if (result != null) {
return result;
}
Light light = null;
int type = ((Number) structure.getFieldValue("type")).intValue();
switch(type) {
case // Lamp
0:
light = new PointLight();
float distance = ((Number) structure.getFieldValue("dist")).floatValue();
((PointLight) light).setRadius(distance);
break;
case // Sun
1:
LOGGER.log(Level.WARNING, "'Sun' lamp is not supported in jMonkeyEngine. Using PointLight with radius = Float.MAX_VALUE.");
light = new PointLight();
((PointLight) light).setRadius(Float.MAX_VALUE);
break;
case // Spot
2:
light = new SpotLight();
// range
((SpotLight) light).setSpotRange(((Number) structure.getFieldValue("dist")).floatValue());
// outer angle
float outerAngle = ((Number) structure.getFieldValue("spotsize")).floatValue() * FastMath.DEG_TO_RAD * 0.5f;
((SpotLight) light).setSpotOuterAngle(outerAngle);
// inner angle
float spotblend = ((Number) structure.getFieldValue("spotblend")).floatValue();
spotblend = FastMath.clamp(spotblend, 0, 1);
float innerAngle = outerAngle * (1 - spotblend);
((SpotLight) light).setSpotInnerAngle(innerAngle);
break;
case // Hemi
3:
LOGGER.log(Level.WARNING, "'Hemi' lamp is not supported in jMonkeyEngine. Using DirectionalLight instead.");
case // Area
4:
light = new DirectionalLight();
break;
default:
throw new BlenderFileException("Unknown light source type: " + type);
}
float r = ((Number) structure.getFieldValue("r")).floatValue();
float g = ((Number) structure.getFieldValue("g")).floatValue();
float b = ((Number) structure.getFieldValue("b")).floatValue();
light.setColor(new ColorRGBA(r, g, b, 1.0f));
light.setName(structure.getName());
return light;
}
use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class LightSortTest method testSimpleSort.
@Test
public void testSimpleSort() {
Geometry g = new Geometry("test", new Mesh());
LightList list = new LightList(g);
list.add(new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X));
list.add(new PointLight(Vector3f.UNIT_X));
list.add(new DirectionalLight(Vector3f.UNIT_X));
list.add(new AmbientLight());
list.sort(true);
// Ambients always first
assert list.get(0) instanceof AmbientLight;
// .. then directionals
assert list.get(1) instanceof DirectionalLight;
// Spot is 0 units away from geom
assert list.get(2) instanceof SpotLight;
// .. and point is 1 unit away.
assert list.get(3) instanceof PointLight;
}
use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class SinglePassAndImageBasedLightingLogic method updateLightListUniforms.
/**
* Uploads the lights in the light list as two uniform arrays.<br/><br/> *
* <p>
* <code>uniform vec4 g_LightColor[numLights];</code><br/> //
* g_LightColor.rgb is the diffuse/specular color of the light.<br/> //
* g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br/> //
* 2 = Spot. <br/> <br/>
* <code>uniform vec4 g_LightPosition[numLights];</code><br/> //
* g_LightPosition.xyz is the position of the light (for point lights)<br/>
* // or the direction of the light (for directional lights).<br/> //
* g_LightPosition.w is the inverse radius (1/r) of the light (for
* attenuation) <br/> </p>
*/
protected int updateLightListUniforms(Shader shader, Geometry g, LightList lightList, int numLights, RenderManager rm, int startIndex, int lastTexUnit) {
if (numLights == 0) {
// this shader does not do lighting, ignore.
return 0;
}
Uniform lightData = shader.getUniform("g_LightData");
//8 lights * max 3
lightData.setVector4Length(numLights * 3);
Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
Uniform lightProbeData = shader.getUniform("g_LightProbeData");
lightProbeData.setVector4Length(1);
Uniform lightProbeIrrMap = shader.getUniform("g_IrradianceMap");
Uniform lightProbePemMap = shader.getUniform("g_PrefEnvMap");
lightProbe = null;
if (startIndex != 0) {
// apply additive blending for 2nd and future passes
rm.getRenderer().applyRenderState(ADDITIVE_LIGHT);
ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
} else {
lightProbe = extractIndirectLights(lightList, true);
ambientColor.setValue(VarType.Vector4, ambientLightColor);
}
//If there is a lightProbe in the list we force it's render on the first pass
if (lightProbe != null) {
BoundingSphere s = (BoundingSphere) lightProbe.getBounds();
lightProbeData.setVector4InArray(lightProbe.getPosition().x, lightProbe.getPosition().y, lightProbe.getPosition().z, 1f / s.getRadius(), 0);
//assigning new texture indexes
int irrUnit = lastTexUnit++;
int pemUnit = lastTexUnit++;
rm.getRenderer().setTexture(irrUnit, lightProbe.getIrradianceMap());
lightProbeIrrMap.setValue(VarType.Int, irrUnit);
rm.getRenderer().setTexture(pemUnit, lightProbe.getPrefilteredEnvMap());
lightProbePemMap.setValue(VarType.Int, pemUnit);
} else {
//Disable IBL for this pass
lightProbeData.setVector4InArray(0, 0, 0, -1, 0);
}
int lightDataIndex = 0;
TempVars vars = TempVars.get();
Vector4f tmpVec = vars.vect4f1;
int curIndex;
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();
if (l.getType() != Light.Type.Probe) {
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);
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);
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);
lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
lightDataIndex++;
tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f);
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
while (lightDataIndex < numLights * 3) {
lightData.setVector4InArray(0f, 0f, 0f, 0f, lightDataIndex);
lightDataIndex++;
}
return curIndex;
}
Aggregations