Search in sources :

Example 56 with RenderManager

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

the class TestShaderNodes method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(20);
    Logger.getLogger("com.jme3").setLevel(Level.WARNING);
    Box boxshape1 = new Box(1f, 1f, 1f);
    Geometry cube_tex = new Geometry("A Textured Box", boxshape1);
    Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md");
    mat.selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    Technique t = mat.getActiveTechnique();
    //        for (Shader.ShaderSource shaderSource : t.getShader().getSources()) {
    //            System.out.println(shaderSource.getSource());
    //        }
    mat.setColor("Color", ColorRGBA.Yellow);
    mat.setTexture("ColorMap", tex);
    cube_tex.setMaterial(mat);
    rootNode.attachChild(cube_tex);
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Technique(com.jme3.material.Technique) Texture(com.jme3.texture.Texture)

Example 57 with RenderManager

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

the class TestDepthStencil method simpleRender.

@Override
public void simpleRender(RenderManager rm) {
    Renderer r = rm.getRenderer();
    //do FBO rendering
    r.setFrameBuffer(fb);
    // FBO uses current camera
    rm.setCamera(cam, false);
    r.clearBuffers(true, true, true);
    rm.renderScene(fbNode, viewPort);
    rm.flushQueue(viewPort);
    //go back to default rendering and let
    //SimpleApplication render the default scene
    r.setFrameBuffer(null);
}
Also used : Renderer(com.jme3.renderer.Renderer)

Example 58 with RenderManager

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

the class VRViewManagerOSVR method setupCamerasAndViews.

private void setupCamerasAndViews() {
    if (environment != null) {
        if (environment.getApplication() != null) {
            // get desired frustrum from original camera
            Camera origCam = environment.getCamera();
            float fFar = origCam.getFrustumFar();
            float fNear = origCam.getFrustumNear();
            // if we are using OSVR get the eye info here
            if (environment.getVRHardware() instanceof OSVR) {
                ((OSVR) environment.getVRHardware()).getEyeInfo();
            }
            // restore frustrum on distortion scene cam, if needed
            if (environment.isInstanceRendering()) {
                leftCamera = origCam;
            } else if (environment.compositorAllowed() == false) {
                origCam.setFrustumFar(100f);
                origCam.setFrustumNear(1f);
                leftCamera = origCam.clone();
                prepareCameraSize(origCam, 2f);
            } else {
                leftCamera = origCam.clone();
            }
            leftCamera.setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar);
            prepareCameraSize(leftCamera, 1f);
            if (environment.getVRHardware() != null)
                leftCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(leftCamera));
            if (!environment.isInstanceRendering()) {
                leftViewport = setupViewBuffers(leftCamera, LEFT_VIEW_NAME);
                rightCamera = leftCamera.clone();
                if (environment.getVRHardware() != null) {
                    rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera));
                }
                rightViewport = setupViewBuffers(rightCamera, RIGHT_VIEW_NAME);
            } else {
                System.err.println("[VRViewManager] THIS CODE NEED CHANGES !!!");
                leftViewport = environment.getApplication().getViewPort();
                //leftViewport.attachScene(app.getRootNode());
                rightCamera = leftCamera.clone();
                if (environment.getVRHardware() != null) {
                    rightCamera.setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(rightCamera));
                }
                org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0);
                //FIXME: [jme-vr] Fix with JMonkey next release
                //RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix();
                setupFinalFullTexture(environment.getApplication().getViewPort().getCamera());
            }
            // setup gui
            environment.getVRGUIManager().setupGui(leftCamera, rightCamera, leftViewport, rightViewport);
            if (environment.getVRHardware() != null) {
                // call these to cache the results internally
                environment.getVRHardware().getHMDMatrixPoseLeftEye();
                environment.getVRHardware().getHMDMatrixPoseRightEye();
            }
        } 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 : OSVR(com.jme3.input.vr.OSVR) Camera(com.jme3.renderer.Camera)

Example 59 with RenderManager

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

the class VRViewManagerOpenVR method setupCamerasAndViews.

private void setupCamerasAndViews() {
    if (environment != null) {
        // get desired frustrum from original camera
        Camera origCam = environment.getCamera();
        float fFar = origCam.getFrustumFar();
        float fNear = origCam.getFrustumNear();
        // restore frustrum on distortion scene cam, if needed
        if (environment.isInstanceRendering()) {
            leftCamera = origCam;
        } else if (environment.compositorAllowed() == false) {
            origCam.setFrustumFar(100f);
            origCam.setFrustumNear(1f);
            leftCamera = origCam.clone();
            prepareCameraSize(origCam, 2f);
        } else {
            leftCamera = origCam.clone();
        }
        getLeftCamera().setFrustumPerspective(environment.getDefaultFOV(), environment.getDefaultAspect(), fNear, fFar);
        prepareCameraSize(getLeftCamera(), 1f);
        if (environment.getVRHardware() != null) {
            getLeftCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionLeftEye(getLeftCamera()));
        }
        if (!environment.isInstanceRendering()) {
            leftViewport = setupViewBuffers(getLeftCamera(), LEFT_VIEW_NAME);
            rightCamera = getLeftCamera().clone();
            if (environment.getVRHardware() != null) {
                getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera()));
            }
            rightViewport = setupViewBuffers(getRightCamera(), RIGHT_VIEW_NAME);
        } else {
            if (environment.getApplication() != null) {
                logger.severe("THIS CODE NEED CHANGES !!!");
                leftViewport = environment.getApplication().getViewPort();
                //leftViewport.attachScene(app.getRootNode());
                rightCamera = getLeftCamera().clone();
                if (environment.getVRHardware() != null) {
                    getRightCamera().setProjectionMatrix(environment.getVRHardware().getHMDMatrixProjectionRightEye(getRightCamera()));
                }
                org.lwjgl.opengl.GL11.glEnable(org.lwjgl.opengl.GL30.GL_CLIP_DISTANCE0);
                //FIXME: [jme-vr] Fix with JMonkey next release
                //RenderManager._VRInstancing_RightCamProjection = camRight.getViewProjectionMatrix();
                setupFinalFullTexture(environment.getApplication().getViewPort().getCamera());
            } else {
                throw new IllegalStateException("This VR environment is not attached to any application.");
            }
        }
        // setup gui
        environment.getVRGUIManager().setupGui(getLeftCamera(), getRightCamera(), getLeftViewport(), getRightViewport());
        if (environment.getVRHardware() != null) {
            // call these to cache the results internally
            environment.getVRHardware().getHMDMatrixPoseLeftEye();
            environment.getVRHardware().getHMDMatrixPoseRightEye();
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Camera(com.jme3.renderer.Camera)

Example 60 with RenderManager

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

the class CartoonSSAO method initFilter.

@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    this.renderManager = renderManager;
    this.viewPort = vp;
    int screenWidth = Math.round(w / downsample);
    int screenHeight = Math.round(h / downsample);
    normalPass = new Pass();
    normalPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth);
    frustumNearFar = new Vector2f();
    float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar();
    float farX = farY * ((float) screenWidth / (float) screenHeight);
    frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar());
    frustumNearFar.x = vp.getCamera().getFrustumNear();
    frustumNearFar.y = vp.getCamera().getFrustumFar();
    //ssao Pass
    material = new Material(manager, "Common/MatDefs/VR/CartoonSSAO.j3md");
    material.setTexture("Normals", normalPass.getRenderedTexture());
    material.setVector3("FrustumCorner", frustumCorner);
    material.setVector2("FrustumNearFar", frustumNearFar);
    material.setFloat("Distance", applyDistance);
    if (useOutline == false)
        material.setBoolean("disableOutline", true);
    if (instancedRendering)
        material.setBoolean("useInstancing", true);
}
Also used : Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material)

Aggregations

Material (com.jme3.material.Material)25 Camera (com.jme3.renderer.Camera)15 Renderer (com.jme3.renderer.Renderer)11 Vector3f (com.jme3.math.Vector3f)8 Texture2D (com.jme3.texture.Texture2D)5 DirectionalLight (com.jme3.light.DirectionalLight)4 Geometry (com.jme3.scene.Geometry)4 Picture (com.jme3.ui.Picture)4 TempVars (com.jme3.util.TempVars)4 Light (com.jme3.light.Light)3 PointLight (com.jme3.light.PointLight)3 SpotLight (com.jme3.light.SpotLight)3 Pass (com.jme3.post.Filter.Pass)3 RenderManager (com.jme3.renderer.RenderManager)3 Spatial (com.jme3.scene.Spatial)3 Shader (com.jme3.shader.Shader)3 FrameBuffer (com.jme3.texture.FrameBuffer)3 Texture (com.jme3.texture.Texture)3 Test (org.junit.Test)3 Technique (com.jme3.material.Technique)2