Search in sources :

Example 26 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class TestPostWater method createBox.

private void createBox() {
    //creating a transluscent box
    box = new Geometry("box", new Box(50, 50, 50));
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(1.0f, 0, 0, 0.3f));
    mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
    //mat.getAdditionalRenderState().setDepthWrite(false);
    //mat.getAdditionalRenderState().setDepthTest(false);
    box.setMaterial(mat);
    box.setQueueBucket(Bucket.Translucent);
    //creating a post view port
    //        ViewPort post=renderManager.createPostView("transpPost", cam);
    //        post.setClearFlags(false, true, true);
    box.setLocalTranslation(-600, 0, 300);
    //attaching the box to the post viewport
    //Don't forget to updateGeometricState() the box in the simpleUpdate
    //  post.attachScene(box);
    rootNode.attachChild(box);
}
Also used : Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 27 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class EnvironmentCamera method createOffScreenFrameBuffer.

/**
     * create an offscreen frame buffer.
     *
     * @param mapSize
     * @param offView
     * @return
     */
protected FrameBuffer createOffScreenFrameBuffer(int mapSize, ViewPort offView) {
    // create offscreen framebuffer
    final FrameBuffer offBuffer = new FrameBuffer(mapSize, mapSize, 1);
    offBuffer.setDepthBuffer(Image.Format.Depth);
    offView.setOutputFrameBuffer(offBuffer);
    return offBuffer;
}
Also used : FrameBuffer(com.jme3.texture.FrameBuffer)

Example 28 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class WaterFilter method initFilter.

@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    if (reflectionScene == null) {
        reflectionScene = vp.getScenes().get(0);
        DirectionalLight l = findLight((Node) reflectionScene);
        if (l != null) {
            lightDirection = l.getDirection();
        }
    }
    this.renderManager = renderManager;
    this.viewPort = vp;
    reflectionPass = new Pass();
    reflectionPass.init(renderManager.getRenderer(), reflectionMapSize, reflectionMapSize, Format.RGBA8, Format.Depth);
    reflectionCam = new Camera(reflectionMapSize, reflectionMapSize);
    reflectionView = new ViewPort("reflectionView", reflectionCam);
    reflectionView.setClearFlags(true, true, true);
    reflectionView.attachScene(reflectionScene);
    reflectionView.setOutputFrameBuffer(reflectionPass.getRenderFrameBuffer());
    plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y));
    reflectionProcessor = new ReflectionProcessor(reflectionCam, reflectionPass.getRenderFrameBuffer(), plane);
    reflectionProcessor.setReflectionClipPlane(plane);
    reflectionView.addProcessor(reflectionProcessor);
    normalTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/water_normalmap.dds");
    if (foamTexture == null) {
        foamTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg");
    }
    if (causticsTexture == null) {
        causticsTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/caustics.jpg");
    }
    heightTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/heightmap.jpg");
    normalTexture.setWrap(WrapMode.Repeat);
    foamTexture.setWrap(WrapMode.Repeat);
    causticsTexture.setWrap(WrapMode.Repeat);
    heightTexture.setWrap(WrapMode.Repeat);
    material = new Material(manager, "Common/MatDefs/Water/Water.j3md");
    material.setTexture("HeightMap", heightTexture);
    material.setTexture("CausticsMap", causticsTexture);
    material.setTexture("FoamMap", foamTexture);
    material.setTexture("NormalMap", normalTexture);
    material.setTexture("ReflectionMap", reflectionPass.getRenderedTexture());
    material.setFloat("WaterTransparency", waterTransparency);
    material.setFloat("NormalScale", normalScale);
    material.setFloat("R0", refractionConstant);
    material.setFloat("MaxAmplitude", maxAmplitude);
    material.setVector3("LightDir", lightDirection);
    material.setColor("LightColor", lightColor);
    material.setFloat("ShoreHardness", shoreHardness);
    material.setFloat("RefractionStrength", refractionStrength);
    material.setFloat("WaveScale", waveScale);
    material.setVector3("FoamExistence", foamExistence);
    material.setFloat("SunScale", sunScale);
    material.setVector3("ColorExtinction", colorExtinction);
    material.setFloat("Shininess", shininess);
    material.setColor("WaterColor", waterColor);
    material.setColor("DeepWaterColor", deepWaterColor);
    material.setVector2("WindDirection", windDirection);
    material.setFloat("FoamHardness", foamHardness);
    material.setBoolean("UseRipples", useRipples);
    material.setBoolean("UseHQShoreline", useHQShoreline);
    material.setBoolean("UseSpecular", useSpecular);
    material.setBoolean("UseFoam", useFoam);
    material.setBoolean("UseCaustics", useCaustics);
    material.setBoolean("UseRefraction", useRefraction);
    material.setFloat("ReflectionDisplace", reflectionDisplace);
    material.setFloat("FoamIntensity", foamIntensity);
    material.setFloat("UnderWaterFogDistance", underWaterFogDistance);
    material.setFloat("CausticsIntensity", causticsIntensity);
    if (center != null) {
        material.setVector3("Center", center);
        material.setFloat("Radius", radius * radius);
        material.setBoolean("SquareArea", shapeType == AreaShape.Square);
    }
    material.setFloat("WaterHeight", waterHeight);
}
Also used : Pass(com.jme3.post.Filter.Pass) DirectionalLight(com.jme3.light.DirectionalLight) ViewPort(com.jme3.renderer.ViewPort) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera)

Example 29 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class TestBareBonesApp method initialize.

@Override
public void initialize() {
    super.initialize();
    System.out.println("Initialize");
    // create a box
    boxGeom = new Geometry("Box", new Box(2, 2, 2));
    // load some default material
    boxGeom.setMaterial(assetManager.loadMaterial("Interface/Logo/Logo.j3m"));
    // attach box to display in primary viewport
    viewPort.attachScene(boxGeom);
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box)

Example 30 with ViewPort

use of com.jme3.renderer.ViewPort in project jmonkeyengine by jMonkeyEngine.

the class PosterizationFilter method initFilter.

@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    material = new Material(manager, "Common/MatDefs/Post/Posterization.j3md");
    material.setInt("NumColors", numColors);
    material.setFloat("Gamma", gamma);
    material.setFloat("Strength", strength);
}
Also used : Material(com.jme3.material.Material)

Aggregations

Material (com.jme3.material.Material)29 Camera (com.jme3.renderer.Camera)19 FrameBuffer (com.jme3.texture.FrameBuffer)19 Geometry (com.jme3.scene.Geometry)18 Texture2D (com.jme3.texture.Texture2D)17 ViewPort (com.jme3.renderer.ViewPort)16 Vector3f (com.jme3.math.Vector3f)14 Spatial (com.jme3.scene.Spatial)12 Box (com.jme3.scene.shape.Box)9 Node (com.jme3.scene.Node)8 FilterPostProcessor (com.jme3.post.FilterPostProcessor)7 Renderer (com.jme3.renderer.Renderer)7 Picture (com.jme3.ui.Picture)6 KeyTrigger (com.jme3.input.controls.KeyTrigger)5 Quaternion (com.jme3.math.Quaternion)5 DirectionalLight (com.jme3.light.DirectionalLight)4 SceneProcessor (com.jme3.post.SceneProcessor)4 Sphere (com.jme3.scene.shape.Sphere)4 ActionListener (com.jme3.input.controls.ActionListener)3 Vector2f (com.jme3.math.Vector2f)3