Search in sources :

Example 1 with DirectionalLightShadowFilter

use of com.jme3.shadow.DirectionalLightShadowFilter 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;
}
Also used : Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) ChaseCamera(com.jme3.input.ChaseCamera) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) DirectionalLightShadowRenderer(com.jme3.shadow.DirectionalLightShadowRenderer) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 2 with DirectionalLightShadowFilter

use of com.jme3.shadow.DirectionalLightShadowFilter in project jmonkeyengine by jMonkeyEngine.

the class TestDirectionalLightShadow method simpleInitApp.

@Override
public void simpleInitApp() {
    // put the camera in a bad position
    //        cam.setLocation(new Vector3f(65.25412f, 44.38738f, 9.087874f));
    //        cam.setRotation(new Quaternion(0.078139365f, 0.050241485f, -0.003942559f, 0.9956679f));
    cam.setLocation(new Vector3f(3.3720117f, 42.838284f, -83.43792f));
    cam.setRotation(new Quaternion(0.13833192f, -0.08969371f, 0.012581267f, 0.9862358f));
    flyCam.setMoveSpeed(100);
    loadScene();
    dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 3);
    dlsr.setLight(l);
    dlsr.setLambda(0.55f);
    dlsr.setShadowIntensity(0.8f);
    dlsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
    dlsr.displayDebug();
    viewPort.addProcessor(dlsr);
    dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 3);
    dlsf.setLight(l);
    dlsf.setLambda(0.55f);
    dlsf.setShadowIntensity(0.8f);
    dlsf.setEdgeFilteringMode(EdgeFilteringMode.Nearest);
    dlsf.setEnabled(false);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(dlsf);
    viewPort.addProcessor(fpp);
    initInputs();
}
Also used : Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) DirectionalLightShadowRenderer(com.jme3.shadow.DirectionalLightShadowRenderer) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter)

Example 3 with DirectionalLightShadowFilter

use of com.jme3.shadow.DirectionalLightShadowFilter in project jmonkeyengine by jMonkeyEngine.

the class RollingTheMonkey method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);
    cam.setLocation(new Vector3f(0.0f, 12.0f, 21.0f));
    viewPort.setBackgroundColor(new ColorRGBA(0.2118f, 0.0824f, 0.6549f, 1.0f));
    // init physics
    BulletAppState bulletState = new BulletAppState();
    stateManager.attach(bulletState);
    space = bulletState.getPhysicsSpace();
    space.addCollisionListener(this);
    // create light
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection((new Vector3f(-0.7f, -0.3f, -0.5f)).normalizeLocal());
    System.out.println("Here We Go: " + sun.getDirection());
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun);
    // create materials
    Material materialRed = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    materialRed.setBoolean("UseMaterialColors", true);
    materialRed.setBoolean("HardwareShadows", true);
    materialRed.setColor("Diffuse", new ColorRGBA(0.9451f, 0.0078f, 0.0314f, 1.0f));
    materialRed.setColor("Specular", ColorRGBA.White);
    materialRed.setFloat("Shininess", 64.0f);
    Material materialGreen = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    materialGreen.setBoolean("UseMaterialColors", true);
    materialGreen.setBoolean("HardwareShadows", true);
    materialGreen.setColor("Diffuse", new ColorRGBA(0.0431f, 0.7725f, 0.0078f, 1.0f));
    materialGreen.setColor("Specular", ColorRGBA.White);
    materialGreen.setFloat("Shininess", 64.0f);
    Material logoMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    logoMaterial.setBoolean("UseMaterialColors", true);
    logoMaterial.setBoolean("HardwareShadows", true);
    logoMaterial.setTexture("DiffuseMap", assetManager.loadTexture("com/jme3/app/Monkey.png"));
    logoMaterial.setColor("Diffuse", ColorRGBA.White);
    logoMaterial.setColor("Specular", ColorRGBA.White);
    logoMaterial.setFloat("Shininess", 32.0f);
    Material materialYellow = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    materialYellow.setBoolean("UseMaterialColors", true);
    materialYellow.setBoolean("HardwareShadows", true);
    materialYellow.setColor("Diffuse", new ColorRGBA(0.9529f, 0.7843f, 0.0078f, 1.0f));
    materialYellow.setColor("Specular", ColorRGBA.White);
    materialYellow.setFloat("Shininess", 64.0f);
    // create level spatial
    // TODO: create your own level mesh
    Node level = new Node("level");
    level.setShadowMode(ShadowMode.CastAndReceive);
    Geometry floor = new Geometry("floor", new Box(22.0f, 0.5f, 22.0f));
    floor.setShadowMode(ShadowMode.Receive);
    floor.setLocalTranslation(0.0f, -0.5f, 0.0f);
    floor.setMaterial(materialGreen);
    Geometry wallNorth = new Geometry("wallNorth", new Box(22.0f, 2.0f, 0.5f));
    wallNorth.setLocalTranslation(0.0f, 2.0f, 21.5f);
    wallNorth.setMaterial(materialRed);
    Geometry wallSouth = new Geometry("wallSouth", new Box(22.0f, 2.0f, 0.5f));
    wallSouth.setLocalTranslation(0.0f, 2.0f, -21.5f);
    wallSouth.setMaterial(materialRed);
    Geometry wallEast = new Geometry("wallEast", new Box(0.5f, 2.0f, 21.0f));
    wallEast.setLocalTranslation(-21.5f, 2.0f, 0.0f);
    wallEast.setMaterial(materialRed);
    Geometry wallWest = new Geometry("wallWest", new Box(0.5f, 2.0f, 21.0f));
    wallWest.setLocalTranslation(21.5f, 2.0f, 0.0f);
    wallWest.setMaterial(materialRed);
    level.attachChild(floor);
    level.attachChild(wallNorth);
    level.attachChild(wallSouth);
    level.attachChild(wallEast);
    level.attachChild(wallWest);
    // The easy way: level.addControl(new RigidBodyControl(0));
    // create level Shape
    CompoundCollisionShape levelShape = new CompoundCollisionShape();
    BoxCollisionShape floorShape = new BoxCollisionShape(new Vector3f(22.0f, 0.5f, 22.0f));
    BoxCollisionShape wallNorthShape = new BoxCollisionShape(new Vector3f(22.0f, 2.0f, 0.5f));
    BoxCollisionShape wallSouthShape = new BoxCollisionShape(new Vector3f(22.0f, 2.0f, 0.5f));
    BoxCollisionShape wallEastShape = new BoxCollisionShape(new Vector3f(0.5f, 2.0f, 21.0f));
    BoxCollisionShape wallWestShape = new BoxCollisionShape(new Vector3f(0.5f, 2.0f, 21.0f));
    levelShape.addChildShape(floorShape, new Vector3f(0.0f, -0.5f, 0.0f));
    levelShape.addChildShape(wallNorthShape, new Vector3f(0.0f, 2.0f, -21.5f));
    levelShape.addChildShape(wallSouthShape, new Vector3f(0.0f, 2.0f, 21.5f));
    levelShape.addChildShape(wallEastShape, new Vector3f(-21.5f, 2.0f, 0.0f));
    levelShape.addChildShape(wallEastShape, new Vector3f(21.5f, 2.0f, 0.0f));
    level.addControl(new RigidBodyControl(levelShape, 0));
    rootNode.attachChild(level);
    space.addAll(level);
    // create Pickups
    // TODO: create your own pickUp mesh
    //       create single mesh for all pickups
    // HINT: think particles.
    pickUps = new Node("pickups");
    Quaternion rotation = new Quaternion();
    Vector3f translation = new Vector3f(0.0f, PICKUP_SIZE * 1.5f, -PICKUP_RADIUS);
    int index = 0;
    float ammount = FastMath.TWO_PI / PICKUP_COUNT;
    for (float angle = 0; angle < FastMath.TWO_PI; angle += ammount) {
        Geometry pickUp = new Geometry("pickUp" + (index++), new Box(PICKUP_SIZE, PICKUP_SIZE, PICKUP_SIZE));
        pickUp.setShadowMode(ShadowMode.CastAndReceive);
        pickUp.setMaterial(materialYellow);
        pickUp.setLocalRotation(rotation.fromAngles(FastMath.rand.nextFloat() * FastMath.TWO_PI, FastMath.rand.nextFloat() * FastMath.TWO_PI, FastMath.rand.nextFloat() * FastMath.TWO_PI));
        rotation.fromAngles(0.0f, angle, 0.0f);
        rotation.mult(translation, pickUp.getLocalTranslation());
        pickUps.attachChild(pickUp);
        pickUp.addControl(new GhostControl(new SphereCollisionShape(PICKUP_SIZE)));
        space.addAll(pickUp);
    //space.addCollisionListener(pickUpControl);
    }
    rootNode.attachChild(pickUps);
    // Create player
    // TODO: create your own player mesh
    Geometry playerGeometry = new Geometry("player", new Sphere(16, 32, PLAYER_RADIUS));
    playerGeometry.setShadowMode(ShadowMode.CastAndReceive);
    playerGeometry.setLocalTranslation(PLAYER_START.clone());
    playerGeometry.setMaterial(logoMaterial);
    // Store control for applying forces
    // TODO: create your own player control
    player = new RigidBodyControl(new SphereCollisionShape(PLAYER_RADIUS), PLAYER_MASS);
    player.setRestitution(PLAYER_REST);
    playerGeometry.addControl(player);
    rootNode.attachChild(playerGeometry);
    space.addAll(playerGeometry);
    inputManager.addMapping(INPUT_MAPPING_FORWARD, new KeyTrigger(KeyInput.KEY_UP), new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping(INPUT_MAPPING_BACKWARD, new KeyTrigger(KeyInput.KEY_DOWN), new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping(INPUT_MAPPING_LEFT, new KeyTrigger(KeyInput.KEY_LEFT), new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping(INPUT_MAPPING_RIGHT, new KeyTrigger(KeyInput.KEY_RIGHT), new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping(INPUT_MAPPING_RESET, new KeyTrigger(KeyInput.KEY_R));
    inputManager.addListener(this, INPUT_MAPPING_FORWARD, INPUT_MAPPING_BACKWARD, INPUT_MAPPING_LEFT, INPUT_MAPPING_RIGHT, INPUT_MAPPING_RESET);
    // init UI
    infoText = new BitmapText(guiFont, false);
    infoText.setText(INFO_MESSAGE);
    guiNode.attachChild(infoText);
    scoreText = new BitmapText(guiFont, false);
    scoreText.setText("Score: 0");
    guiNode.attachChild(scoreText);
    messageText = new BitmapText(guiFont, false);
    messageText.setText(MESSAGE);
    messageText.setLocalScale(0.0f);
    guiNode.attachChild(messageText);
    infoText.setLocalTranslation(0.0f, cam.getHeight(), 0.0f);
    scoreText.setLocalTranslation((cam.getWidth() - scoreText.getLineWidth()) / 2.0f, scoreText.getLineHeight(), 0.0f);
    messageText.setLocalTranslation((cam.getWidth() - messageText.getLineWidth()) / 2.0f, (cam.getHeight() - messageText.getLineHeight()) / 2, 0.0f);
    // init shadows
    FilterPostProcessor processor = new FilterPostProcessor(assetManager);
    DirectionalLightShadowFilter filter = new DirectionalLightShadowFilter(assetManager, 2048, 1);
    filter.setLight(sun);
    processor.addFilter(filter);
    viewPort.addProcessor(processor);
}
Also used : CompoundCollisionShape(com.jme3.bullet.collision.shapes.CompoundCollisionShape) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) BoxCollisionShape(com.jme3.bullet.collision.shapes.BoxCollisionShape) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) ColorRGBA(com.jme3.math.ColorRGBA) BitmapText(com.jme3.font.BitmapText) GhostControl(com.jme3.bullet.control.GhostControl) Vector3f(com.jme3.math.Vector3f) BulletAppState(com.jme3.bullet.BulletAppState) DirectionalLight(com.jme3.light.DirectionalLight)

Example 4 with DirectionalLightShadowFilter

use of com.jme3.shadow.DirectionalLightShadowFilter in project jmonkeyengine by jMonkeyEngine.

the class AbstractVRViewManager method syncScreenProcessing.

/**
     * Sets the two views to use the list of {@link SceneProcessor processors}.
     * @param sourceViewport the {@link ViewPort viewport} that contains the processors to use.
     */
public void syncScreenProcessing(ViewPort sourceViewport) {
    if (environment != null) {
        if (getRightViewport() == null) {
            return;
        }
        if (environment.getApplication() != null) {
            // setup post processing filters
            if (getRightPostProcessor() == null) {
                rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
                leftPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
            }
            // clear out all filters & processors, to start from scratch
            getRightPostProcessor().removeAllFilters();
            getLeftPostProcessor().removeAllFilters();
            getLeftViewport().clearProcessors();
            getRightViewport().clearProcessors();
            // if we have no processors to sync, don't add the FilterPostProcessor
            if (sourceViewport.getProcessors().isEmpty())
                return;
            // add post processors we just made, which are empty
            getLeftViewport().addProcessor(getLeftPostProcessor());
            getRightViewport().addProcessor(getRightPostProcessor());
            // add them to the left viewport processor & clone them to the right
            for (SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
                if (sceneProcessor instanceof FilterPostProcessor) {
                    for (Filter f : ((FilterPostProcessor) sceneProcessor).getFilterList()) {
                        if (f instanceof TranslucentBucketFilter) {
                            // just remove this filter, we will add it at the end manually
                            ((FilterPostProcessor) sceneProcessor).removeFilter(f);
                        } else {
                            getLeftPostProcessor().addFilter(f);
                            // clone to the right
                            Filter f2;
                            if (f instanceof FogFilter) {
                                f2 = FilterUtil.cloneFogFilter((FogFilter) f);
                            } else if (f instanceof CartoonSSAO) {
                                f2 = new CartoonSSAO((CartoonSSAO) f);
                            } else if (f instanceof SSAOFilter) {
                                f2 = FilterUtil.cloneSSAOFilter((SSAOFilter) f);
                            } else if (f instanceof DirectionalLightShadowFilter) {
                                f2 = FilterUtil.cloneDirectionalLightShadowFilter(environment.getApplication().getAssetManager(), (DirectionalLightShadowFilter) f);
                            } else {
                                // dof, bloom, lightscattering etc.
                                f2 = f;
                            }
                            getRightPostProcessor().addFilter(f2);
                        }
                    }
                } else if (sceneProcessor instanceof VRDirectionalLightShadowRenderer) {
                    // shadow processing
                    // TODO: make right shadow processor use same left shadow maps for performance
                    VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
                    VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
                    dlsrRight.setLight(dlsr.getLight());
                    getRightViewport().getProcessors().add(0, dlsrRight);
                    getLeftViewport().getProcessors().add(0, sceneProcessor);
                }
            }
            // make sure each has a translucent filter renderer
            getLeftPostProcessor().addFilter(new TranslucentBucketFilter());
            getRightPostProcessor().addFilter(new TranslucentBucketFilter());
        } else {
            throw new IllegalStateException("The VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) VRDirectionalLightShadowRenderer(com.jme3.shadow.VRDirectionalLightShadowRenderer) FogFilter(com.jme3.post.filters.FogFilter) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) Filter(com.jme3.post.Filter) SSAOFilter(com.jme3.post.ssao.SSAOFilter) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) FogFilter(com.jme3.post.filters.FogFilter) SceneProcessor(com.jme3.post.SceneProcessor) CartoonSSAO(com.jme3.post.CartoonSSAO)

Example 5 with DirectionalLightShadowFilter

use of com.jme3.shadow.DirectionalLightShadowFilter in project jmonkeyengine by jMonkeyEngine.

the class FilterUtil method cloneDirectionalLightShadowFilter.

public static DirectionalLightShadowFilter cloneDirectionalLightShadowFilter(AssetManager assetManager, DirectionalLightShadowFilter filter) {
    DirectionalLightShadowFilter clone = new DirectionalLightShadowFilter(assetManager, 512, 3);
    clone.setLight(filter.getLight());
    clone.setLambda(filter.getLambda());
    clone.setShadowIntensity(filter.getShadowIntensity());
    clone.setEdgeFilteringMode(filter.getEdgeFilteringMode());
    //        clone.setEnabled(filter.isEnabled());
    return clone;
}
Also used : DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter)

Aggregations

DirectionalLightShadowFilter (com.jme3.shadow.DirectionalLightShadowFilter)8 FilterPostProcessor (com.jme3.post.FilterPostProcessor)7 Vector3f (com.jme3.math.Vector3f)6 DirectionalLight (com.jme3.light.DirectionalLight)5 Quaternion (com.jme3.math.Quaternion)5 Box (com.jme3.scene.shape.Box)4 KeyTrigger (com.jme3.input.controls.KeyTrigger)3 Material (com.jme3.material.Material)3 ColorRGBA (com.jme3.math.ColorRGBA)3 SSAOFilter (com.jme3.post.ssao.SSAOFilter)3 Geometry (com.jme3.scene.Geometry)3 Sphere (com.jme3.scene.shape.Sphere)3 DirectionalLightShadowRenderer (com.jme3.shadow.DirectionalLightShadowRenderer)3 BulletAppState (com.jme3.bullet.BulletAppState)2 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)2 CartoonSSAO (com.jme3.post.CartoonSSAO)2 Filter (com.jme3.post.Filter)2 SceneProcessor (com.jme3.post.SceneProcessor)2 FogFilter (com.jme3.post.filters.FogFilter)2 TranslucentBucketFilter (com.jme3.post.filters.TranslucentBucketFilter)2