use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class LightFilterTest method testSpotFiltering.
@Test
public void testSpotFiltering() {
SpotLight sl = new SpotLight(Vector3f.ZERO, Vector3f.UNIT_Z);
sl.setSpotRange(0);
geom.addLight(sl);
// Infinite spot lights are only filtered
checkFilteredLights(1);
// if the geometry is outside the infinite cone.
TempVars vars = TempVars.get();
try {
// The spot is not touching the near plane of the camera yet,
// should still be culled.
sl.setSpotRange(1f - FastMath.ZERO_TOLERANCE);
assert !sl.intersectsFrustum(cam, vars);
// should be culled from the geometry's PoV
checkFilteredLights(0);
// Now it touches the near plane.
sl.setSpotRange(1f);
// still culled from the geometry's PoV
checkFilteredLights(0);
assert sl.intersectsFrustum(cam, vars);
} finally {
vars.release();
}
// make it barely reach the geometry
sl.setSpotRange(9f);
checkFilteredLights(0);
// make it reach the geometry (touching its bound)
sl.setSpotRange(9f + FastMath.ZERO_TOLERANCE);
checkFilteredLights(1);
// rotate the cone a bit so it no longer faces the geom
sl.setDirection(new Vector3f(0.316f, 0, 0.948f).normalizeLocal());
checkFilteredLights(0);
// extent the range much farther
sl.setSpotRange(20);
checkFilteredLights(0);
// Create box of size X=10 (double the extent)
// now, the spot will touch the box.
geom.setMesh(new Box(5, 1, 1));
checkFilteredLights(1);
// ==================================
// Tests for bounding sphere, with a radius of 1f (in the box geom)
sl.setPosition(Vector3f.ZERO);
sl.setDirection(Vector3f.UNIT_Z);
geom.setLocalTranslation(Vector3f.ZERO);
geom.setModelBound(new BoundingSphere(1f, Vector3f.ZERO));
// Infinit spot lights are only filtered
// if the geometry is outside the infinite cone.
sl.setSpotRange(0);
checkFilteredLights(1);
//the geommetry is outside the infinit cone (cone direction going away from the geom)
sl.setPosition(Vector3f.UNIT_Z.mult(1 + FastMath.ZERO_TOLERANCE));
checkFilteredLights(0);
//place the spote ligth in the corner of the box geom, (in order to test bounding sphere)
sl.setDirection(new Vector3f(1, 1, 0).normalizeLocal());
geom.setLocalTranslation(0, 0, 10);
sl.setPosition(sl.getDirection().mult(-2f).add(geom.getLocalTranslation()));
// make it barely reach the sphere, incorect with a box
sl.setSpotRange(1f - FastMath.ZERO_TOLERANCE);
checkFilteredLights(0);
// make it reach the sphere
sl.setSpotRange(1f + FastMath.ZERO_TOLERANCE);
checkFilteredLights(1);
// extent the range
sl.setPosition(Vector3f.ZERO);
sl.setDirection(Vector3f.UNIT_Z);
sl.setSpotRange(20);
checkFilteredLights(1);
// rotate the cone a bit so it no longer faces the geom
sl.setDirection(new Vector3f(0, 0.3f, 0.7f).normalizeLocal());
checkFilteredLights(0);
// Create sphere of size X=10 (double the radius)
// now, the spot will touch the sphere.
geom.setModelBound(new BoundingSphere(5f, Vector3f.ZERO));
checkFilteredLights(1);
}
use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class LightSortTest method testSceneGraphSort.
@Test
public void testSceneGraphSort() {
Node n = new Node("node");
Geometry g = new Geometry("geom", new Mesh());
SpotLight spot = new SpotLight(Vector3f.ZERO, Vector3f.UNIT_X);
PointLight point = new PointLight(Vector3f.UNIT_X);
DirectionalLight directional = new DirectionalLight(Vector3f.UNIT_X);
AmbientLight ambient = new AmbientLight();
// Some lights are on the node
n.addLight(spot);
n.addLight(point);
// .. and some on the geometry.
g.addLight(directional);
g.addLight(ambient);
n.attachChild(g);
n.updateGeometricState();
LightList list = g.getWorldLightList();
// check the sorting (when geom is at 0,0,0)
assert list.get(0) instanceof AmbientLight;
assert list.get(1) instanceof DirectionalLight;
assert list.get(2) instanceof SpotLight;
assert list.get(3) instanceof PointLight;
// move the geometry closer to the point light
g.setLocalTranslation(Vector3f.UNIT_X);
n.updateGeometricState();
assert list.get(0) instanceof AmbientLight;
assert list.get(1) instanceof DirectionalLight;
assert list.get(2) instanceof PointLight;
assert list.get(3) instanceof SpotLight;
// now move the point light away from the geometry
// and the spot light closer
// XXX: doesn't work! jME can't detect that the light moved!
// point.setPosition(Vector3f.ZERO);
// spot.setPosition(Vector3f.UNIT_X);
// n.updateGeometricState();
//
// assert list.get(0) instanceof AmbientLight;
// assert list.get(1) instanceof DirectionalLight;
// assert list.get(2) instanceof SpotLight;
// assert list.get(3) instanceof PointLight;
}
use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class SpotLightShadowRenderer method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
zFarOverride = ic.readInt("zFarOverride", 0);
light = (SpotLight) ic.readSavable("light", null);
fadeInfo = (Vector2f) ic.readSavable("fadeInfo", null);
fadeLength = ic.readFloat("fadeLength", 0f);
init((int) shadowMapSize);
}
use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class TestConeVSFrustum method simpleInitApp.
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
frustumCam = cam.clone();
frustumCam.setFrustumFar(25);
Vector3f[] points = new Vector3f[8];
for (int i = 0; i < 8; i++) {
points[i] = new Vector3f();
}
ShadowUtil.updateFrustumPoints2(frustumCam, points);
WireFrustum frustumShape = new WireFrustum(points);
Geometry frustum = new Geometry("frustum", frustumShape);
frustum.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
rootNode.attachChild(frustum);
rootNode.addLight(new DirectionalLight());
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.2f));
rootNode.addLight(al);
Grid grid = new Grid(50, 50, 5);
Geometry gridGeom = new Geometry("grid", grid);
gridGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
gridGeom.getMaterial().setColor("Color", ColorRGBA.Gray);
rootNode.attachChild(gridGeom);
gridGeom.setLocalTranslation(-125, -25, -125);
// flyCam.setMoveSpeed(30);
// flyCam.setDragToRotate(true);
// cam.setLocation(new Vector3f(56.182674f, 19.037334f, 7.093905f));
// cam.setRotation(new Quaternion(0.0816657f, -0.82228005f, 0.12213967f, 0.5497892f));
spotLight = new SpotLight();
spotLight.setSpotRange(25);
spotLight.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
float radius = FastMath.tan(spotLight.getSpotOuterAngle()) * spotLight.getSpotRange();
Cylinder cylinder = new Cylinder(5, 16, 0, radius, spotLight.getSpotRange(), true, false);
geom = new Geometry("light", cylinder);
geom.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"));
geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
geom.getMaterial().setColor("Ambient", ColorRGBA.DarkGray);
geom.getMaterial().setBoolean("UseMaterialColors", true);
final LightNode ln = new LightNode("lb", spotLight);
ln.attachChild(geom);
geom.setLocalTranslation(0, -spotLight.getSpotRange() / 2f, 0);
geom.rotate(-FastMath.HALF_PI, 0, 0);
rootNode.attachChild(ln);
// ln.rotate(FastMath.QUARTER_PI, 0, 0);
// ln.setLocalTranslation(0, 0, -16);
inputManager.addMapping("click", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addMapping("shift", new KeyTrigger(KeyInput.KEY_LSHIFT), new KeyTrigger(KeyInput.KEY_RSHIFT));
inputManager.addMapping("middleClick", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
inputManager.addMapping("up", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
inputManager.addMapping("down", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
inputManager.addMapping("left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
inputManager.addMapping("right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
final Node camTarget = new Node("CamTarget");
rootNode.attachChild(camTarget);
ChaseCameraAppState chaser = new ChaseCameraAppState();
chaser.setTarget(camTarget);
chaser.setMaxDistance(150);
chaser.setDefaultDistance(70);
chaser.setDefaultHorizontalRotation(FastMath.HALF_PI);
chaser.setMinVerticalRotation(-FastMath.PI);
chaser.setMaxVerticalRotation(FastMath.PI * 2);
chaser.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
stateManager.attach(chaser);
flyCam.setEnabled(false);
inputManager.addListener(new AnalogListener() {
public void onAnalog(String name, float value, float tpf) {
Spatial s = null;
float mult = 1;
if (moving) {
s = ln;
}
if (panning) {
s = camTarget;
mult = -1;
}
if ((moving || panning) && s != null) {
if (shift) {
if (name.equals("left")) {
tmp.set(cam.getDirection());
s.rotate(tmpQuat.fromAngleAxis(value, tmp));
}
if (name.equals("right")) {
tmp.set(cam.getDirection());
s.rotate(tmpQuat.fromAngleAxis(-value, tmp));
}
} else {
value *= MOVE_SPEED * mult;
if (name.equals("up")) {
tmp.set(cam.getUp()).multLocal(value);
s.move(tmp);
}
if (name.equals("down")) {
tmp.set(cam.getUp()).multLocal(-value);
s.move(tmp);
}
if (name.equals("left")) {
tmp.set(cam.getLeft()).multLocal(value);
s.move(tmp);
}
if (name.equals("right")) {
tmp.set(cam.getLeft()).multLocal(-value);
s.move(tmp);
}
}
}
}
}, "up", "down", "left", "right");
inputManager.addListener(new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("click")) {
if (isPressed) {
moving = true;
} else {
moving = false;
}
}
if (name.equals("middleClick")) {
if (isPressed) {
panning = true;
} else {
panning = false;
}
}
if (name.equals("shift")) {
if (isPressed) {
shift = true;
} else {
shift = false;
}
}
}
}, "click", "middleClick", "shift");
/**
* An unshaded textured cube. // * Uses texture from jme3-test-data
* library!
*/
Box boxMesh = new Box(1f, 1f, 1f);
boxGeo = new Geometry("A Textured Box", boxMesh);
Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture monkeyTex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
boxMat.setTexture("ColorMap", monkeyTex);
boxGeo.setMaterial(boxMat);
// rootNode.attachChild(boxGeo);
//
//boxGeo2 = boxGeo.clone();
//rootNode.attachChild(boxGeo2);
System.err.println("light " + spotLight.getPosition());
}
use of com.jme3.light.SpotLight in project jmonkeyengine by jMonkeyEngine.
the class TestShadowBug method simpleInitApp.
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(100f);
rootNode.attachChild(makeFloor());
Node characters = new Node("Characters");
characters.setShadowMode(ShadowMode.Cast);
rootNode.attachChild(characters);
Spatial golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
golem.scale(0.5f);
golem.setLocalTranslation(200.0f, -6f, 200f);
golem.setShadowMode(ShadowMode.CastAndReceive);
characters.attachChild(golem);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(-1f, -1f, 1f));
sun.setColor(ColorRGBA.White.mult(1.3f));
rootNode.addLight(sun);
characters.addLight(sun);
SpotLight spot = new SpotLight();
// distance
spot.setSpotRange(13f);
// inner light cone (central beam)
spot.setSpotInnerAngle(15f * FastMath.DEG_TO_RAD);
// outer light cone (edge of the light)
spot.setSpotOuterAngle(20f * FastMath.DEG_TO_RAD);
// light color
spot.setColor(ColorRGBA.White.mult(1.3f));
spot.setPosition(new Vector3f(192.0f, -1f, 192f));
spot.setDirection(new Vector3f(1, -0.5f, 1));
rootNode.addLight(spot);
PointLight lamp_light = new PointLight();
lamp_light.setColor(ColorRGBA.Yellow);
lamp_light.setRadius(20f);
lamp_light.setPosition(new Vector3f(210.0f, 0f, 210f));
rootNode.addLight(lamp_light);
SpotLightShadowRenderer slsr = new SpotLightShadowRenderer(assetManager, 512);
slsr.setLight(spot);
slsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
slsr.setShadowIntensity(0.6f);
slsr.setFlushQueues(false);
viewPort.addProcessor(slsr);
PointLightShadowRenderer plsr = new PointLightShadowRenderer(assetManager, 512);
plsr.setLight(lamp_light);
plsr.setShadowIntensity(0.6f);
plsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
plsr.setFlushQueues(false);
viewPort.addProcessor(plsr);
viewPort.getCamera().setLocation(new Vector3f(192.0f, 10f, 192f));
float[] angles = new float[] { 3.14f / 2, 3.14f / 2, 0 };
viewPort.getCamera().setRotation(new Quaternion(angles));
}
Aggregations