Search in sources :

Example 31 with FrameBuffer

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

the class VRGuiManager method getGuiQuad.

/**
	 * Create a GUI quad for the given camera.
	 * @param sourceCam the camera
	 * @return a GUI quad for the given camera.
	 */
private Spatial getGuiQuad(Camera sourceCam) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            if (guiQuadNode == null) {
                Vector2f guiCanvasSize = getCanvasSize();
                Camera offCamera = sourceCam.clone();
                offCamera.setParallelProjection(true);
                offCamera.setLocation(Vector3f.ZERO);
                offCamera.lookAt(Vector3f.UNIT_Z, Vector3f.UNIT_Y);
                offView = environment.getApplication().getRenderManager().createPreView("GUI View", offCamera);
                offView.setClearFlags(true, true, true);
                offView.setBackgroundColor(ColorRGBA.BlackNoAlpha);
                // create offscreen framebuffer
                FrameBuffer offBuffer = new FrameBuffer((int) guiCanvasSize.x, (int) guiCanvasSize.y, 1);
                //setup framebuffer's texture
                guiTexture = new Texture2D((int) guiCanvasSize.x, (int) guiCanvasSize.y, Format.RGBA8);
                guiTexture.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
                guiTexture.setMagFilter(Texture.MagFilter.Bilinear);
                //setup framebuffer to use texture
                offBuffer.setDepthBuffer(Format.Depth);
                offBuffer.setColorTexture(guiTexture);
                //set viewport to render to offscreen framebuffer
                offView.setOutputFrameBuffer(offBuffer);
                // setup framebuffer's scene
                Iterator<Spatial> spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
                while (spatialIter.hasNext()) {
                    offView.attachScene(spatialIter.next());
                }
                if (useCurvedSurface) {
                    guiQuad = (Geometry) environment.getApplication().getAssetManager().loadModel("Common/Util/gui_mesh.j3o");
                } else {
                    guiQuad = new Geometry("guiQuad", new CenterQuad(1f, 1f));
                }
                Material mat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/GuiOverlay.j3md");
                mat.getAdditionalRenderState().setDepthTest(!overdraw);
                mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
                mat.getAdditionalRenderState().setDepthWrite(false);
                mat.setTexture("ColorMap", guiTexture);
                guiQuad.setQueueBucket(Bucket.Translucent);
                guiQuad.setMaterial(mat);
                guiQuadNode = new Node("gui-quad-node");
                guiQuadNode.setQueueBucket(Bucket.Translucent);
                guiQuadNode.attachChild(guiQuad);
            }
            return guiQuadNode;
        } else {
            throw new IllegalStateException("VR GUI manager underlying environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("VR GUI manager is not attached to any environment.");
    }
}
Also used : Geometry(com.jme3.scene.Geometry) Texture2D(com.jme3.texture.Texture2D) Spatial(com.jme3.scene.Spatial) Vector2f(com.jme3.math.Vector2f) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) FrameBuffer(com.jme3.texture.FrameBuffer) CenterQuad(com.jme3.scene.CenterQuad)

Example 32 with FrameBuffer

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

the class PreNormalCaching method getPreNormals.

/**
     * Get pre-normals from the given rendering.
     * @param renderManager the render manager.
     * @param normalPass the normal pass.
     * @param viewPort the viewport.
     */
public static void getPreNormals(RenderManager renderManager, Pass normalPass, ViewPort viewPort) {
    curCount++;
    // do we already have a valid cache to set the framebuffer to?
    Renderer r = renderManager.getRenderer();
    if (cachedPreNormals != null) {
        r.copyFrameBuffer(cachedPreNormals, normalPass.getRenderFrameBuffer(), false);
    } else {
        // lets make the prenormals
        r.setFrameBuffer(normalPass.getRenderFrameBuffer());
        renderManager.getRenderer().clearBuffers(true, true, true);
        if (renderManager.getRenderer().getCaps().contains(Caps.GLSL150)) {
            renderManager.setForcedTechnique("PreNormalPass15");
        } else {
            renderManager.setForcedTechnique("PreNormalPass");
        }
        renderManager.renderViewPortQueues(viewPort, false);
        renderManager.setForcedTechnique(null);
        // if we should cache this, do it now
        if (lastNormalPassesCount > 1) {
            cachedPreNormals = normalPass.getRenderFrameBuffer();
        }
    }
    renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());
}
Also used : Renderer(com.jme3.renderer.Renderer)

Example 33 with FrameBuffer

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

the class AbstractShadowRendererVR method init.

private void init(AssetManager assetManager, int nbShadowMaps, int shadowMapSize) {
    this.postshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PostShadow.j3md");
    shadowFB = new FrameBuffer[nbShadowMaps];
    shadowMaps = new Texture2D[nbShadowMaps];
    dispPic = new Picture[nbShadowMaps];
    lightViewProjectionsMatrices = new Matrix4f[nbShadowMaps];
    shadowMapStringCache = new String[nbShadowMaps];
    lightViewStringCache = new String[nbShadowMaps];
    //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
    dummyTex = new Texture2D(shadowMapSize, shadowMapSize, Format.RGBA8);
    preshadowMat = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    postshadowMat.setFloat("ShadowMapSize", shadowMapSize);
    for (int i = 0; i < nbShadowMaps; i++) {
        lightViewProjectionsMatrices[i] = new Matrix4f();
        shadowFB[i] = new FrameBuffer(shadowMapSize, shadowMapSize, 1);
        shadowMaps[i] = new Texture2D(shadowMapSize, shadowMapSize, Format.Depth);
        shadowFB[i].setDepthTexture(shadowMaps[i]);
        //DO NOT COMMENT THIS (it prevent the OSX incomplete read buffer crash)
        shadowFB[i].setColorTexture(dummyTex);
        shadowMapStringCache[i] = "ShadowMap" + i;
        lightViewStringCache[i] = "LightViewProjectionMatrix" + i;
        postshadowMat.setTexture(shadowMapStringCache[i], shadowMaps[i]);
        //quads for debuging purpose
        dispPic[i] = new Picture("Picture" + i);
        dispPic[i].setTexture(assetManager, shadowMaps[i], false);
    }
    setShadowCompareMode(shadowCompareMode);
    setEdgeFilteringMode(edgeFilteringMode);
    setShadowIntensity(shadowIntensity);
    initForcedRenderState();
}
Also used : Texture2D(com.jme3.texture.Texture2D) Matrix4f(com.jme3.math.Matrix4f) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 34 with FrameBuffer

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

the class VRViewManagerOpenVR method setupFinalFullTexture.

private void setupFinalFullTexture(Camera cam) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // create offscreen framebuffer
            FrameBuffer out = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
            //offBuffer.setSrgb(true);
            //setup framebuffer's texture
            dualEyeTex = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
            dualEyeTex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
            dualEyeTex.setMagFilter(Texture.MagFilter.Bilinear);
            logger.config("Dual eye texture " + dualEyeTex.getName() + " (" + dualEyeTex.getImage().getId() + ")");
            logger.config("               Type: " + dualEyeTex.getType());
            logger.config("               Size: " + dualEyeTex.getImage().getWidth() + "x" + dualEyeTex.getImage().getHeight());
            logger.config("        Image depth: " + dualEyeTex.getImage().getDepth());
            logger.config("       Image format: " + dualEyeTex.getImage().getFormat());
            logger.config("  Image color space: " + dualEyeTex.getImage().getColorSpace());
            //setup framebuffer to use texture
            out.setDepthBuffer(Image.Format.Depth);
            out.setColorTexture(dualEyeTex);
            ViewPort viewPort = environment.getApplication().getViewPort();
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Black);
            viewPort.setOutputFrameBuffer(out);
        } else {
            throw new IllegalStateException("This 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 : Texture2D(com.jme3.texture.Texture2D) ViewPort(com.jme3.renderer.ViewPort) 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