Search in sources :

Example 61 with Texture2D

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

the class MaterialMatParamTest method testTextureOverride.

@Test
public void testTextureOverride() {
    material("Common/MatDefs/Light/Lighting.j3md");
    Texture2D tex1 = new Texture2D(128, 128, Format.RGBA8);
    Texture2D tex2 = new Texture2D(128, 128, Format.RGBA8);
    inputMp(mpoTexture2D("DiffuseMap", tex1));
    inputMpo(mpoTexture2D("DiffuseMap", tex2));
    outDefines(def("DIFFUSEMAP", VarType.Texture2D, tex2));
    outUniforms(uniform("DiffuseMap", VarType.Int, 0));
    outTextures(tex2);
}
Also used : Texture2D(com.jme3.texture.Texture2D) Test(org.junit.Test)

Example 62 with Texture2D

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

the class VRViewManagerOSVR method setupVRScene.

/**
     * Replaces rootNode as the main cameras scene with the distortion mesh
     */
private void setupVRScene() {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // no special scene to setup if we are doing instancing
            if (environment.isInstanceRendering()) {
                // distortion has to be done with compositor here... we want only one pass on our end!
                if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
                    setupMirrorBuffers(environment.getCamera(), dualEyeTex, true);
                }
                return;
            }
            leftEyeTexture = (Texture2D) leftViewport.getOutputFrameBuffer().getColorBuffer().getTexture();
            rightEyeTexture = (Texture2D) rightViewport.getOutputFrameBuffer().getColorBuffer().getTexture();
            leftEyeDepth = (Texture2D) leftViewport.getOutputFrameBuffer().getDepthBuffer().getTexture();
            rightEyeDepth = (Texture2D) rightViewport.getOutputFrameBuffer().getDepthBuffer().getTexture();
            // main viewport is either going to be a distortion scene or nothing
            // mirroring is handled by copying framebuffers
            Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                environment.getApplication().getViewPort().detachScene(spatialIter.next());
            }
            spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                environment.getApplication().getGuiViewPort().detachScene(spatialIter.next());
            }
            // only setup distortion scene if compositor isn't running (or using custom mesh distortion option)
            if (environment.getVRHardware().getCompositor() == null) {
                Node distortionScene = new Node();
                Material leftMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
                leftMat.setTexture("Texture", leftEyeTexture);
                Geometry leftEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Left, environment.getVRHardware()));
                leftEye.setMaterial(leftMat);
                distortionScene.attachChild(leftEye);
                Material rightMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
                rightMat.setTexture("Texture", rightEyeTexture);
                Geometry rightEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Right, environment.getVRHardware()));
                rightEye.setMaterial(rightMat);
                distortionScene.attachChild(rightEye);
                distortionScene.updateGeometricState();
                environment.getApplication().getViewPort().attachScene(distortionScene);
            //if( useCustomDistortion ) setupFinalFullTexture(app.getViewPort().getCamera());
            }
            if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
                setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
            }
        } 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 : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 63 with Texture2D

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

the class VRViewManagerOSVR method setupMirrorBuffers.

private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            Camera clonecam = cam.clone();
            ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
            clonecam.setParallelProjection(true);
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Black);
            Picture pic = new Picture("fullscene");
            pic.setLocalTranslation(-0.75f, -0.5f, 0f);
            if (expand) {
                pic.setLocalScale(3f, 1f, 1f);
            } else {
                pic.setLocalScale(1.5f, 1f, 1f);
            }
            pic.setQueueBucket(Bucket.Opaque);
            pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, false);
            viewPort.attachScene(pic);
            viewPort.setOutputFrameBuffer(null);
            pic.updateGeometricState();
            return viewPort;
        } 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 : Picture(com.jme3.ui.Picture) ViewPort(com.jme3.renderer.ViewPort) Camera(com.jme3.renderer.Camera)

Example 64 with Texture2D

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

the class VRViewManagerOpenVR method setupVRScene.

/**
     * Replaces rootNode as the main cameras scene with the distortion mesh
     */
private void setupVRScene() {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // no special scene to setup if we are doing instancing
            if (environment.isInstanceRendering()) {
                // distortion has to be done with compositor here... we want only one pass on our end!
                if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
                    setupMirrorBuffers(environment.getCamera(), dualEyeTex, true);
                }
                return;
            }
            leftEyeTexture = (Texture2D) getLeftViewport().getOutputFrameBuffer().getColorBuffer().getTexture();
            rightEyeTexture = (Texture2D) getRightViewport().getOutputFrameBuffer().getColorBuffer().getTexture();
            leftEyeDepth = (Texture2D) getLeftViewport().getOutputFrameBuffer().getDepthBuffer().getTexture();
            rightEyeDepth = (Texture2D) getRightViewport().getOutputFrameBuffer().getDepthBuffer().getTexture();
            // main viewport is either going to be a distortion scene or nothing
            // mirroring is handled by copying framebuffers
            Iterator<Spatial> spatialIter = environment.getApplication().getViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                environment.getApplication().getViewPort().detachScene(spatialIter.next());
            }
            spatialIter = environment.getApplication().getGuiViewPort().getScenes().iterator();
            while (spatialIter.hasNext()) {
                environment.getApplication().getGuiViewPort().detachScene(spatialIter.next());
            }
            // only setup distortion scene if compositor isn't running (or using custom mesh distortion option)
            if (environment.getVRHardware().getCompositor() == null) {
                Node distortionScene = new Node();
                Material leftMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
                leftMat.setTexture("Texture", leftEyeTexture);
                Geometry leftEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Left, environment.getVRHardware()));
                leftEye.setMaterial(leftMat);
                distortionScene.attachChild(leftEye);
                Material rightMat = new Material(environment.getApplication().getAssetManager(), "Common/MatDefs/VR/OpenVR.j3md");
                rightMat.setTexture("Texture", rightEyeTexture);
                Geometry rightEye = new Geometry("box", setupDistortionMesh(JOpenVRLibrary.EVREye.EVREye_Eye_Right, environment.getVRHardware()));
                rightEye.setMaterial(rightMat);
                distortionScene.attachChild(rightEye);
                distortionScene.updateGeometricState();
                environment.getApplication().getViewPort().attachScene(distortionScene);
            //if( useCustomDistortion ) setupFinalFullTexture(app.getViewPort().getCamera());
            }
            if (environment.getApplication().getContext().getSettings().isSwapBuffers()) {
                setupMirrorBuffers(environment.getCamera(), leftEyeTexture, false);
            }
        } 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 : Geometry(com.jme3.scene.Geometry) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node) Material(com.jme3.material.Material)

Example 65 with Texture2D

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

Aggregations

Texture2D (com.jme3.texture.Texture2D)54 Material (com.jme3.material.Material)19 FrameBuffer (com.jme3.texture.FrameBuffer)18 Picture (com.jme3.ui.Picture)12 Geometry (com.jme3.scene.Geometry)11 Image (com.jme3.texture.Image)11 ViewPort (com.jme3.renderer.ViewPort)9 Texture (com.jme3.texture.Texture)9 Camera (com.jme3.renderer.Camera)8 Node (com.jme3.scene.Node)7 Spatial (com.jme3.scene.Spatial)7 TextureKey (com.jme3.asset.TextureKey)6 Vector3f (com.jme3.math.Vector3f)6 ByteBuffer (java.nio.ByteBuffer)6 Quaternion (com.jme3.math.Quaternion)5 BufferedImage (java.awt.image.BufferedImage)4 Test (org.junit.Test)4 DirectionalLight (com.jme3.light.DirectionalLight)3 Vector2f (com.jme3.math.Vector2f)3 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3