use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class TestCinematic method createScene.
private void createScene() {
model = (Spatial) assetManager.loadModel("Models/Oto/Oto.mesh.xml");
model.center();
model.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(model);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Cyan);
teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
teapot.setLocalTranslation(10, 0, 10);
teapot.setMaterial(mat);
teapot.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(teapot);
Material matSoil = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
matSoil.setBoolean("UseMaterialColors", true);
matSoil.setColor("Ambient", ColorRGBA.Gray);
matSoil.setColor("Diffuse", ColorRGBA.Green);
matSoil.setColor("Specular", ColorRGBA.Black);
Geometry soil = new Geometry("soil", new Box(50, 1, 50));
soil.setLocalTranslation(0, -6, 0);
soil.setMaterial(matSoil);
soil.setShadowMode(ShadowMode.Receive);
rootNode.attachChild(soil);
DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
light.setColor(ColorRGBA.White.mult(1.5f));
rootNode.addLight(light);
fpp = new FilterPostProcessor(assetManager);
fade = new FadeFilter();
fpp.addFilter(fade);
if (renderer.getCaps().contains(Caps.GLSL100)) {
PssmShadowRenderer pssm = new PssmShadowRenderer(assetManager, 512, 1);
pssm.setDirection(new Vector3f(0, -1, -1).normalizeLocal());
pssm.setShadowIntensity(0.4f);
viewPort.addProcessor(pssm);
viewPort.addProcessor(fpp);
}
}
use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class DirectionalLightShadowRenderer method read.
@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
lambda = ic.readFloat("lambda", 0.65f);
zFarOverride = ic.readInt("zFarOverride", 0);
light = (DirectionalLight) ic.readSavable("light", null);
fadeInfo = (Vector2f) ic.readSavable("fadeInfo", null);
fadeLength = ic.readFloat("fadeLength", 0f);
init(nbShadowMaps, (int) shadowMapSize);
}
use of com.jme3.light.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class TestColorApp method simpleInitApp.
@Override
public void simpleInitApp() {
// Lights
DirectionalLight sun = new DirectionalLight();
Vector3f sunPosition = new Vector3f(1, -1, 1);
sun.setDirection(sunPosition);
sun.setColor(new ColorRGBA(1f, 1f, 1f, 1f));
rootNode.addLight(sun);
//DirectionalLightShadowFilter sun_renderer = new DirectionalLightShadowFilter(assetManager, 2048, 4);
DirectionalLightShadowRenderer sun_renderer = new DirectionalLightShadowRenderer(assetManager, 2048, 1);
sun_renderer.setLight(sun);
viewPort.addProcessor(sun_renderer);
// FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
// fpp.addFilter(sun_renderer);
// viewPort.addProcessor(fpp);
rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
// Camera
viewPort.setBackgroundColor(new ColorRGBA(.6f, .6f, .6f, 1f));
ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
// Objects
// Ground Object
final Geometry groundBoxWhite = new Geometry("Box", new Box(7.5f, 7.5f, .25f));
float[] f = { -FastMath.PI / 2, 3 * FastMath.PI / 2, 0f };
groundBoxWhite.setLocalRotation(new Quaternion(f));
groundBoxWhite.move(7.5f, -.75f, 7.5f);
final Material groundMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
groundMaterial.setColor("Diffuse", new ColorRGBA(.9f, .9f, .9f, .9f));
groundBoxWhite.setMaterial(groundMaterial);
groundBoxWhite.addControl(chaseCam);
rootNode.attachChild(groundBoxWhite);
// Planter
Geometry planterBox = new Geometry("Box", new Box(.5f, .5f, .5f));
final Material planterMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
planterMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
planterBox.setMaterial(groundMaterial);
planterBox.setLocalTranslation(10, 0, 9);
rootNode.attachChild(planterBox);
// Action!
inputManager.addMapping("on", new KeyTrigger(KeyInput.KEY_Z));
inputManager.addMapping("off", new KeyTrigger(KeyInput.KEY_X));
inputManager.addListener(new AnalogListener() {
@Override
public void onAnalog(String s, float v, float v1) {
if (s.equals("on")) {
groundBoxWhite.setMaterial(planterMaterial);
}
if (s.equals("off")) {
groundBoxWhite.setMaterial(groundMaterial);
}
}
}, "on", "off");
inputEnabled = true;
}
use of com.jme3.light.DirectionalLight 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.DirectionalLight in project jmonkeyengine by jMonkeyEngine.
the class TestDirectionalLightShadow method loadScene.
public void loadScene() {
obj = new Spatial[2];
// Setup first view
mat = new Material[2];
mat[0] = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
mat[1] = assetManager.loadMaterial("Textures/Terrain/Pond/Pond.j3m");
mat[1].setBoolean("UseMaterialColors", true);
mat[1].setColor("Ambient", ColorRGBA.White);
mat[1].setColor("Diffuse", ColorRGBA.White.clone());
obj[0] = new Geometry("sphere", new Sphere(30, 30, 2));
obj[0].setShadowMode(ShadowMode.CastAndReceive);
obj[1] = new Geometry("cube", new Box(1.0f, 1.0f, 1.0f));
obj[1].setShadowMode(ShadowMode.CastAndReceive);
TangentBinormalGenerator.generate(obj[1]);
TangentBinormalGenerator.generate(obj[0]);
Spatial t = obj[0].clone(false);
t.setLocalScale(10f);
t.setMaterial(mat[1]);
rootNode.attachChild(t);
t.setLocalTranslation(0, 25, 0);
for (int i = 0; i < 60; i++) {
t = obj[FastMath.nextRandomInt(0, obj.length - 1)].clone(false);
t.setLocalScale(FastMath.nextRandomFloat() * 10f);
t.setMaterial(mat[FastMath.nextRandomInt(0, mat.length - 1)]);
rootNode.attachChild(t);
t.setLocalTranslation(FastMath.nextRandomFloat() * 200f, FastMath.nextRandomFloat() * 30f + 20, 30f * (i + 2f));
}
Box b = new Box(1000, 2, 1000);
b.scaleTextureCoordinates(new Vector2f(10, 10));
ground = new Geometry("soil", b);
ground.setLocalTranslation(0, 10, 550);
matGroundU = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
matGroundU.setColor("Color", ColorRGBA.Green);
matGroundL = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
grass.setWrap(WrapMode.Repeat);
matGroundL.setTexture("DiffuseMap", grass);
ground.setMaterial(matGroundL);
ground.setShadowMode(ShadowMode.CastAndReceive);
rootNode.attachChild(ground);
l = new DirectionalLight();
//l.setDirection(new Vector3f(0.5973172f, -0.16583486f, 0.7846725f).normalizeLocal());
l.setDirection(new Vector3f(-1, -1, -1));
rootNode.addLight(l);
al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(0.02f));
rootNode.addLight(al);
Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
sky.setLocalScale(350);
rootNode.attachChild(sky);
}
Aggregations