Search in sources :

Example 21 with ViewPort

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

the class FilterPostProcessor method reshape.

public void reshape(ViewPort vp, int w, int h) {
    Camera cam = vp.getCamera();
    //this has no effect at first init but is useful when resizing the canvas with multi views
    cam.setViewPort(left, right, bottom, top);
    //resizing the camera to fit the new viewport and saving original dimensions
    cam.resize(w, h, false);
    left = cam.getViewPortLeft();
    right = cam.getViewPortRight();
    top = cam.getViewPortTop();
    bottom = cam.getViewPortBottom();
    originalWidth = w;
    originalHeight = h;
    //computing real dimension of the viewport and resizing the camera 
    width = (int) (w * (Math.abs(right - left)));
    height = (int) (h * (Math.abs(bottom - top)));
    width = Math.max(1, width);
    height = Math.max(1, height);
    //camera must be handled differently
    if (originalWidth != width || originalHeight != height) {
        multiView = true;
    }
    cameraInit = true;
    computeDepth = false;
    if (renderFrameBuffer == null && renderFrameBufferMS == null) {
        outputBuffer = viewPort.getOutputFrameBuffer();
    }
    Collection<Caps> caps = renderer.getCaps();
    //antialiasing on filters only supported in opengl 3 due to depth read problem
    if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample)) {
        renderFrameBufferMS = new FrameBuffer(width, height, numSamples);
        if (caps.contains(Caps.OpenGL32)) {
            Texture2D msColor = new Texture2D(width, height, numSamples, fbFormat);
            Texture2D msDepth = new Texture2D(width, height, numSamples, Format.Depth);
            renderFrameBufferMS.setDepthTexture(msDepth);
            renderFrameBufferMS.setColorTexture(msColor);
            filterTexture = msColor;
            depthTexture = msDepth;
        } else {
            renderFrameBufferMS.setDepthBuffer(Format.Depth);
            renderFrameBufferMS.setColorBuffer(fbFormat);
        }
    }
    if (numSamples <= 1 || !caps.contains(Caps.OpenGL32)) {
        renderFrameBuffer = new FrameBuffer(width, height, 1);
        renderFrameBuffer.setDepthBuffer(Format.Depth);
        filterTexture = new Texture2D(width, height, fbFormat);
        renderFrameBuffer.setColorTexture(filterTexture);
    }
    for (Filter filter : filters.getArray()) {
        initFilter(filter, vp);
    }
    setupViewPortFrameBuffer();
}
Also used : Texture2D(com.jme3.texture.Texture2D) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 22 with ViewPort

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

the class HDRRenderer method initialize.

public void initialize(RenderManager rm, ViewPort vp) {
    if (!enabled)
        return;
    renderer = rm.getRenderer();
    renderManager = rm;
    viewPort = vp;
    // loadInitial()
    fsQuad = new Picture("HDR Fullscreen Quad");
    Format lumFmt = Format.RGB8;
    scene64FB = new FrameBuffer(64, 64, 1);
    scene64 = new Texture2D(64, 64, lumFmt);
    scene64FB.setColorTexture(scene64);
    scene64.setMagFilter(fbMagFilter);
    scene64.setMinFilter(fbMinFilter);
    scene8FB = new FrameBuffer(8, 8, 1);
    scene8 = new Texture2D(8, 8, lumFmt);
    scene8FB.setColorTexture(scene8);
    scene8.setMagFilter(fbMagFilter);
    scene8.setMinFilter(fbMinFilter);
    scene1FB[0] = new FrameBuffer(1, 1, 1);
    scene1[0] = new Texture2D(1, 1, lumFmt);
    scene1FB[0].setColorTexture(scene1[0]);
    scene1FB[1] = new FrameBuffer(1, 1, 1);
    scene1[1] = new Texture2D(1, 1, lumFmt);
    scene1FB[1].setColorTexture(scene1[1]);
    // prepare tonemap shader
    tone = new Material(manager, "Common/MatDefs/Hdr/ToneMap.j3md");
    tone.setFloat("A", 0.18f);
    tone.setFloat("White", 100);
    // load();
    int w = vp.getCamera().getWidth();
    int h = vp.getCamera().getHeight();
    reshape(vp, w, h);
}
Also used : Texture2D(com.jme3.texture.Texture2D) Format(com.jme3.texture.Image.Format) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 23 with ViewPort

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

the class BillboardControl method controlRender.

@Override
protected void controlRender(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();
    rotateBillboard(cam);
}
Also used : Camera(com.jme3.renderer.Camera)

Example 24 with ViewPort

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

the class LodControl method controlRender.

protected void controlRender(RenderManager rm, ViewPort vp) {
    BoundingVolume bv = spatial.getWorldBound();
    Camera cam = vp.getCamera();
    float atanNH = FastMath.atan(cam.getFrustumNear() * cam.getFrustumTop());
    float ratio = (FastMath.PI / (8f * atanNH));
    float newDistance = bv.distanceTo(vp.getCamera().getLocation()) / ratio;
    int level;
    if (Math.abs(newDistance - lastDistance) <= distTolerance) {
        // we haven't moved relative to the model, send the old measurement back.
        level = lastLevel;
    } else if (lastDistance > newDistance && lastLevel == 0) {
        // we're already at the lowest setting and we just got closer to the model, no need to keep trying.
        level = lastLevel;
    } else if (lastDistance < newDistance && lastLevel == numLevels - 1) {
        // we're already at the highest setting and we just got further from the model, no need to keep trying.
        level = lastLevel;
    } else {
        lastDistance = newDistance;
        // estimate area of polygon via bounding volume
        float area = AreaUtils.calcScreenArea(bv, lastDistance, cam.getWidth());
        float trisToDraw = area * trisPerPixel;
        level = numLevels - 1;
        for (int i = numLevels; --i >= 0; ) {
            if (trisToDraw - numTris[i] < 0) {
                break;
            }
            level = i;
        }
        lastLevel = level;
    }
    spatial.setLodLevel(level);
}
Also used : BoundingVolume(com.jme3.bounding.BoundingVolume) Camera(com.jme3.renderer.Camera)

Example 25 with ViewPort

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

the class TestDepthStencil method simpleInitApp.

@Override
public void simpleInitApp() {
    int w = settings.getWidth();
    int h = settings.getHeight();
    //setup framebuffer
    fb = new FrameBuffer(w, h, 1);
    Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
    fb.setDepthBuffer(Format.Depth24Stencil8);
    fb.setColorTexture(fbTex);
    // setup framebuffer's scene
    Sphere sphMesh = new Sphere(20, 20, 1);
    Material solidColor = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    final Geometry sphere = new Geometry("sphere", sphMesh);
    sphere.setMaterial(solidColor);
    fbNode.attachChild(sphere);
    sphere.addControl(new AbstractControl() {

        @Override
        protected void controlUpdate(float tpf) {
            Material mat = sphere.getMaterial();
            mat.getAdditionalRenderState().setStencil(enableStencil, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.TestFunction.Never, RenderState.TestFunction.Never);
        }

        @Override
        protected void controlRender(RenderManager rm, ViewPort vp) {
        }
    });
    //setup main scene
    Picture p = new Picture("Picture");
    p.setPosition(0, 0);
    p.setWidth(w);
    p.setHeight(h);
    p.setTexture(assetManager, fbTex, false);
    rootNode.attachChild(p);
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if (enableStencil) {
                    enableStencil = false;
                    System.out.println("Stencil Enabled (model should be hidden)");
                } else {
                    enableStencil = true;
                    System.out.println("Stencil Disabled (model should be visible)");
                }
            }
        }
    };
    inputManager.addListener(acl, "toggle");
    System.out.println("Press space to toggle stencil");
}
Also used : Texture2D(com.jme3.texture.Texture2D) KeyTrigger(com.jme3.input.controls.KeyTrigger) AbstractControl(com.jme3.scene.control.AbstractControl) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Picture(com.jme3.ui.Picture) ViewPort(com.jme3.renderer.ViewPort) RenderManager(com.jme3.renderer.RenderManager)

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