Search in sources :

Example 11 with FrameBuffer

use of com.jme3.texture.FrameBuffer 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 12 with FrameBuffer

use of com.jme3.texture.FrameBuffer 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 13 with FrameBuffer

use of com.jme3.texture.FrameBuffer in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method readFrameBufferWithGLFormat.

private void readFrameBufferWithGLFormat(FrameBuffer fb, ByteBuffer byteBuf, int glFormat, int dataType) {
    if (fb != null) {
        RenderBuffer rb = fb.getColorBuffer();
        if (rb == null) {
            throw new IllegalArgumentException("Specified framebuffer" + " does not have a colorbuffer");
        }
        setFrameBuffer(fb);
        if (gl2 != null) {
            if (context.boundReadBuf != rb.getSlot()) {
                gl2.glReadBuffer(GLFbo.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
                context.boundReadBuf = rb.getSlot();
            }
        }
    } else {
        setFrameBuffer(null);
    }
    gl.glReadPixels(vpX, vpY, vpW, vpH, glFormat, dataType, byteBuf);
}
Also used : RenderBuffer(com.jme3.texture.FrameBuffer.RenderBuffer)

Example 14 with FrameBuffer

use of com.jme3.texture.FrameBuffer 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)

Example 15 with FrameBuffer

use of com.jme3.texture.FrameBuffer 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)

Aggregations

FrameBuffer (com.jme3.texture.FrameBuffer)23 Texture2D (com.jme3.texture.Texture2D)18 Material (com.jme3.material.Material)12 Camera (com.jme3.renderer.Camera)10 ViewPort (com.jme3.renderer.ViewPort)7 Geometry (com.jme3.scene.Geometry)7 Picture (com.jme3.ui.Picture)5 Vector3f (com.jme3.math.Vector3f)4 Box (com.jme3.scene.shape.Box)4 RenderBuffer (com.jme3.texture.FrameBuffer.RenderBuffer)4 Spatial (com.jme3.scene.Spatial)3 Matrix4f (com.jme3.math.Matrix4f)2 SceneProcessor (com.jme3.post.SceneProcessor)2 Sphere (com.jme3.scene.shape.Sphere)2 Texture (com.jme3.texture.Texture)2 ActionListener (com.jme3.input.controls.ActionListener)1 KeyTrigger (com.jme3.input.controls.KeyTrigger)1 Quaternion (com.jme3.math.Quaternion)1 Vector2f (com.jme3.math.Vector2f)1 NiftyJmeDisplay (com.jme3.niftygui.NiftyJmeDisplay)1