Search in sources :

Example 16 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class CartoonEdgeFilter method initFilter.

@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    this.renderManager = renderManager;
    this.viewPort = vp;
    normalPass = new Pass();
    normalPass.init(renderManager.getRenderer(), w, h, Format.RGBA8, Format.Depth);
    material = new Material(manager, "Common/MatDefs/Post/CartoonEdge.j3md");
    material.setFloat("EdgeWidth", edgeWidth);
    material.setFloat("EdgeIntensity", edgeIntensity);
    material.setFloat("NormalThreshold", normalThreshold);
    material.setFloat("DepthThreshold", depthThreshold);
    material.setFloat("NormalSensitivity", normalSensitivity);
    material.setFloat("DepthSensitivity", depthSensitivity);
    material.setColor("EdgeColor", edgeColor);
}
Also used : Pass(com.jme3.post.Filter.Pass) Material(com.jme3.material.Material)

Example 17 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class TestManyLightsSingle method simpleInitApp.

@Override
public void simpleInitApp() {
    renderManager.setPreferredLightMode(lm);
    renderManager.setSinglePassLightBatchSize(6);
    flyCam.setMoveSpeed(10);
    Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
    rootNode.attachChild(scene);
    Node n = (Node) rootNode.getChild(0);
    final LightList lightList = n.getWorldLightList();
    final Geometry g = (Geometry) n.getChild("Grid-geom-1");
    g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    /* A colored lit cube. Needs light source! */
    Box boxMesh = new Box(1f, 1f, 1f);
    final Geometry boxGeo = new Geometry("Colored Box", boxMesh);
    Material boxMat = g.getMaterial().clone();
    boxMat.clearParam("DiffuseMap");
    boxMat.setBoolean("UseMaterialColors", true);
    boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    boxMat.setColor("Diffuse", ColorRGBA.Blue);
    boxGeo.setMaterial(boxMat);
    final Node cubeNodes = new Node();
    n.attachChild(cubeNodes);
    int nb = 0;
    for (Light light : lightList) {
        nb++;
        PointLight p = (PointLight) light;
        if (nb > 60) {
            n.removeLight(light);
        } else {
            LightNode ln = new LightNode("l", light);
            n.attachChild(ln);
            ln.setLocalTranslation(p.getPosition());
            int rand = FastMath.nextRandomInt(0, 3);
            switch(rand) {
                case 0:
                    light.setColor(ColorRGBA.Red);
                    //   ln.addControl(new MoveControl(5f));
                    break;
                case 1:
                    light.setColor(ColorRGBA.Yellow);
                    //    ln.addControl(new MoveControl(5f));
                    break;
                case 2:
                    light.setColor(ColorRGBA.Green);
                    //ln.addControl(new MoveControl(-5f));
                    break;
                case 3:
                    light.setColor(ColorRGBA.Orange);
                    //ln.addControl(new MoveControl(-5f));
                    break;
            }
        }
        Geometry b = boxGeo.clone(false);
        cubeNodes.attachChild(b);
        b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
    }
    //        cam.setLocation(new Vector3f(3.1893547f, 17.977385f, 30.8378f));
    //        cam.setRotation(new Quaternion(0.14317635f, 0.82302624f, -0.23777823f, 0.49557027f));
    cam.setLocation(new Vector3f(-1.8901939f, 29.34097f, 73.07533f));
    cam.setRotation(new Quaternion(0.0021000702f, 0.971012f, -0.23886925f, 0.008527749f));
    BasicProfilerState profiler = new BasicProfilerState(true);
    profiler.setGraphScale(1000f);
    //  getStateManager().attach(profiler);
    //        guiNode.setCullHint(CullHint.Always);
    flyCam.setDragToRotate(true);
    flyCam.setMoveSpeed(50);
    final MaterialDebugAppState debug = new MaterialDebugAppState();
    stateManager.attach(debug);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggle") && isPressed) {
                if (lm == TechniqueDef.LightMode.SinglePass) {
                    lm = TechniqueDef.LightMode.MultiPass;
                    helloText.setText("(Multi pass)");
                } else {
                    lm = TechniqueDef.LightMode.SinglePass;
                    helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
                }
                renderManager.setPreferredLightMode(lm);
                reloadScene(g, boxGeo, cubeNodes);
            }
            if (name.equals("lightsUp") && isPressed) {
                renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1);
                helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
            }
            if (name.equals("lightsDown") && isPressed) {
                renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1);
                helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
            }
            if (name.equals("toggleOnOff") && isPressed) {
                for (final Light light : lightList) {
                    if (light instanceof AmbientLight) {
                        continue;
                    }
                    light.setEnabled(!light.isEnabled());
                }
            }
        }
    }, "toggle", "lightsUp", "lightsDown", "toggleOnOff");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L));
    SpotLight spot = new SpotLight();
    spot.setDirection(new Vector3f(-1f, -1f, -1f).normalizeLocal());
    spot.setColor(ColorRGBA.Blue.mult(5));
    spot.setSpotOuterAngle(FastMath.DEG_TO_RAD * 20);
    spot.setSpotInnerAngle(FastMath.DEG_TO_RAD * 5);
    spot.setPosition(new Vector3f(10, 10, 20));
    rootNode.addLight(spot);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, 1));
    rootNode.addLight(dl);
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    rootNode.addLight(al);
    /**
         * Write text on the screen (HUD)
         */
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);
}
Also used : Quaternion(com.jme3.math.Quaternion) MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) SpotLight(com.jme3.light.SpotLight) BasicProfilerState(com.jme3.app.BasicProfilerState) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) ActionListener(com.jme3.input.controls.ActionListener) BitmapText(com.jme3.font.BitmapText) LightNode(com.jme3.scene.LightNode) DirectionalLight(com.jme3.light.DirectionalLight) SpotLight(com.jme3.light.SpotLight) PointLight(com.jme3.light.PointLight) Light(com.jme3.light.Light) AmbientLight(com.jme3.light.AmbientLight) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) LightList(com.jme3.light.LightList) PointLight(com.jme3.light.PointLight) AmbientLight(com.jme3.light.AmbientLight)

Example 18 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class TestTwoSideLighting method simpleInitApp.

@Override
public void simpleInitApp() {
    // Two-sided lighting requires single pass.
    renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
    renderManager.setSinglePassLightBatchSize(4);
    cam.setLocation(new Vector3f(5.936224f, 3.3759952f, -3.3202777f));
    cam.setRotation(new Quaternion(0.16265652f, -0.4811838f, 0.09137692f, 0.8565368f));
    Geometry quadGeom = new Geometry("quad", new Quad(1, 1));
    quadGeom.move(1, 0, 0);
    Material mat1 = assetManager.loadMaterial("Textures/BumpMapTest/SimpleBump.j3m");
    // Display both front and back faces.
    mat1.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
    quadGeom.setMaterial(mat1);
    // SimpleBump material requires tangents.
    TangentBinormalGenerator.generate(quadGeom);
    rootNode.attachChild(quadGeom);
    Geometry teapot = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.move(-1, 0, 0);
    teapot.setLocalScale(2f);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    mat2.setFloat("Shininess", 25);
    mat2.setBoolean("UseMaterialColors", true);
    mat2.setColor("Ambient", ColorRGBA.Black);
    mat2.setColor("Diffuse", ColorRGBA.Gray);
    mat2.setColor("Specular", ColorRGBA.Gray);
    // Only display backfaces.
    mat2.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Front);
    teapot.setMaterial(mat2);
    rootNode.attachChild(teapot);
    lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    lightMdl.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    lightMdl.getMesh().setStatic();
    rootNode.attachChild(lightMdl);
    pl = new PointLight();
    pl.setColor(ColorRGBA.White);
    pl.setRadius(4f);
    rootNode.addLight(pl);
}
Also used : Geometry(com.jme3.scene.Geometry) Sphere(com.jme3.scene.shape.Sphere) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) PointLight(com.jme3.light.PointLight)

Example 19 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class TestMultiRenderTarget method reshape.

public void reshape(ViewPort vp, int w, int h) {
    diffuseData = new Texture2D(w, h, Format.RGBA8);
    normalData = new Texture2D(w, h, Format.RGBA8);
    specularData = new Texture2D(w, h, Format.RGBA8);
    depthData = new Texture2D(w, h, Format.Depth);
    mat = new Material(assetManager, "Common/MatDefs/Light/Deferred.j3md");
    mat.setTexture("DiffuseData", diffuseData);
    mat.setTexture("SpecularData", specularData);
    mat.setTexture("NormalData", normalData);
    mat.setTexture("DepthData", depthData);
    display.setMaterial(mat);
    display.setPosition(0, 0);
    display.setWidth(w);
    display.setHeight(h);
    display1.setTexture(assetManager, diffuseData, false);
    display2.setTexture(assetManager, normalData, false);
    display3.setTexture(assetManager, specularData, false);
    display4.setTexture(assetManager, depthData, false);
    display1.setPosition(0, 0);
    display2.setPosition(w / 2, 0);
    display3.setPosition(0, h / 2);
    display4.setPosition(w / 2, h / 2);
    display1.setWidth(w / 2);
    display1.setHeight(h / 2);
    display2.setWidth(w / 2);
    display2.setHeight(h / 2);
    display3.setWidth(w / 2);
    display3.setHeight(h / 2);
    display4.setWidth(w / 2);
    display4.setHeight(h / 2);
    guiNode.updateGeometricState();
    fb = new FrameBuffer(w, h, 1);
    fb.setDepthTexture(depthData);
    fb.addColorTexture(diffuseData);
    fb.addColorTexture(normalData);
    fb.addColorTexture(specularData);
    fb.setMultiTarget(true);
/*
         * Marks pixels in front of the far light boundary
            Render back-faces of light volume
            Depth test GREATER-EQUAL
            Write to stencil on depth pass
            Skipped for very small distant lights
         */
/*
         * Find amount of lit pixels inside the volume
             Start pixel query
             Render front faces of light volume
             Depth test LESS-EQUAL
             Don’t write anything – only EQUAL stencil test
         */
/*
         * Enable conditional rendering
            Based on query results from previous stage
            GPU skips rendering for invisible lights
         */
/*
         * Render front-faces of light volume
            Depth test - LESS-EQUAL
            Stencil test - EQUAL
            Runs only on marked pixels inside light
         */
}
Also used : Texture2D(com.jme3.texture.Texture2D) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 20 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method load.

public Object load(AssetInfo info) throws IOException {
    try {
        key = info.getKey();
        assetManager = info.getManager();
        sceneName = key.getName();
        String ext = key.getExtension();
        folderName = key.getFolder();
        sceneName = sceneName.substring(0, sceneName.length() - ext.length() - 1);
        reset();
        // == Run 1st pass over XML file to determine material list ==
        materialList = materialLoader.load(assetManager, folderName, info.openStream());
        if (materialList == null || materialList.isEmpty()) {
            // NOTE: No materials were found by searching the externals section.
            // Try finding a similarly named material file in the same folder.
            // (Backward compatibility only!)
            OgreMaterialKey materialKey = new OgreMaterialKey(sceneName + ".material");
            try {
                materialList = (MaterialList) assetManager.loadAsset(materialKey);
            } catch (AssetNotFoundException ex) {
                logger.log(Level.WARNING, "Cannot locate {0} for scene {1}", new Object[] { materialKey, key });
                materialList = null;
            }
        }
        // == Run 2nd pass to load entities and other objects ==
        // Added by larynx 25.06.2011
        // Android needs the namespace aware flag set to true 
        // Kirill 30.06.2011
        // Now, hack is applied for both desktop and android to avoid
        // checking with JmeSystem.
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XMLReader xr = factory.newSAXParser().getXMLReader();
        xr.setContentHandler(this);
        xr.setErrorHandler(this);
        InputStreamReader r = null;
        try {
            r = new InputStreamReader(info.openStream());
            xr.parse(new InputSource(r));
        } finally {
            if (r != null) {
                r.close();
            }
        }
        return root;
    } catch (SAXException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        throw ioEx;
    } catch (ParserConfigurationException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        throw ioEx;
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) OgreMaterialKey(com.jme3.scene.plugins.ogre.matext.OgreMaterialKey) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Aggregations

Material (com.jme3.material.Material)11 Vector3f (com.jme3.math.Vector3f)6 Camera (com.jme3.renderer.Camera)4 Geometry (com.jme3.scene.Geometry)4 Pass (com.jme3.post.Filter.Pass)3 Node (com.jme3.scene.Node)3 AmbientLight (com.jme3.light.AmbientLight)2 DirectionalLight (com.jme3.light.DirectionalLight)2 PointLight (com.jme3.light.PointLight)2 ColorRGBA (com.jme3.math.ColorRGBA)2 Quaternion (com.jme3.math.Quaternion)2 Vector2f (com.jme3.math.Vector2f)2 ChannelInfoMessage (com.jme3.network.message.ChannelInfoMessage)2 ClientRegistrationMessage (com.jme3.network.message.ClientRegistrationMessage)2 Renderer (com.jme3.renderer.Renderer)2 LightNode (com.jme3.scene.LightNode)2 Spatial (com.jme3.scene.Spatial)2 FrameBuffer (com.jme3.texture.FrameBuffer)2 Texture2D (com.jme3.texture.Texture2D)2 NativeObject (com.jme3.util.NativeObject)2