Search in sources :

Example 66 with ViewPort

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

the class BasicShadowRenderer method postQueue.

public void postQueue(RenderQueue rq) {
    for (Spatial scene : viewPort.getScenes()) {
        ShadowUtil.getGeometriesInCamFrustum(scene, viewPort.getCamera(), ShadowMode.Receive, lightReceivers);
    }
    // update frustum points based on current camera
    Camera viewCam = viewPort.getCamera();
    ShadowUtil.updateFrustumPoints(viewCam, viewCam.getFrustumNear(), viewCam.getFrustumFar(), 1.0f, points);
    Vector3f frustaCenter = new Vector3f();
    for (Vector3f point : points) {
        frustaCenter.addLocal(point);
    }
    frustaCenter.multLocal(1f / 8f);
    // update light direction
    shadowCam.setProjectionMatrix(null);
    shadowCam.setParallelProjection(true);
    //        shadowCam.setFrustumPerspective(45, 1, 1, 20);
    shadowCam.lookAtDirection(direction, Vector3f.UNIT_Y);
    shadowCam.update();
    shadowCam.setLocation(frustaCenter);
    shadowCam.update();
    shadowCam.updateViewProjection();
    // render shadow casters to shadow map
    ShadowUtil.updateShadowCamera(viewPort, lightReceivers, shadowCam, points, shadowOccluders, shadowMapSize);
    if (shadowOccluders.size() == 0) {
        noOccluders = true;
        return;
    } else {
        noOccluders = false;
    }
    Renderer r = renderManager.getRenderer();
    renderManager.setCamera(shadowCam, false);
    renderManager.setForcedMaterial(preshadowMat);
    r.setFrameBuffer(shadowFB);
    r.clearBuffers(true, true, true);
    viewPort.getQueue().renderShadowQueue(shadowOccluders, renderManager, shadowCam, true);
    r.setFrameBuffer(viewPort.getOutputFrameBuffer());
    renderManager.setForcedMaterial(null);
    renderManager.setCamera(viewCam, false);
}
Also used : Spatial(com.jme3.scene.Spatial) Vector3f(com.jme3.math.Vector3f) Renderer(com.jme3.renderer.Renderer) Camera(com.jme3.renderer.Camera)

Example 67 with ViewPort

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

the class TestAwtPanels method simpleInitApp.

@Override
public void simpleInitApp() {
    flyCam.setDragToRotate(true);
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
    /*
         * Wait until both AWT panels are ready.
         */
    try {
        panelsAreReady.await();
    } catch (InterruptedException exception) {
        throw new RuntimeException("Interrupted while waiting for panels", exception);
    }
    panel.attachTo(true, viewPort);
    guiViewPort.setClearFlags(true, true, true);
    panel2.attachTo(false, guiViewPort);
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 68 with ViewPort

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

the class VRViewManagerOSVR method syncScreenProcessing.

/**
     * Sets the two views to use the list of {@link SceneProcessor processors}.
     * @param sourceViewport the {@link ViewPort viewport} that contains the processors to use.
     */
public void syncScreenProcessing(ViewPort sourceViewport) {
    if (rightViewport == null) {
        return;
    }
    if (environment != null) {
        if (environment.getApplication() != null) {
            // setup post processing filters
            if (rightPostProcessor == null) {
                rightPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
                leftPostProcessor = new FilterPostProcessor(environment.getApplication().getAssetManager());
            }
            // clear out all filters & processors, to start from scratch
            rightPostProcessor.removeAllFilters();
            leftPostProcessor.removeAllFilters();
            leftViewport.clearProcessors();
            rightViewport.clearProcessors();
            // if we have no processors to sync, don't add the FilterPostProcessor
            if (sourceViewport.getProcessors().isEmpty())
                return;
            // add post processors we just made, which are empty
            leftViewport.addProcessor(leftPostProcessor);
            rightViewport.addProcessor(rightPostProcessor);
            // add them to the left viewport processor & clone them to the right
            for (SceneProcessor sceneProcessor : sourceViewport.getProcessors()) {
                if (sceneProcessor instanceof FilterPostProcessor) {
                    for (Filter f : ((FilterPostProcessor) sceneProcessor).getFilterList()) {
                        if (f instanceof TranslucentBucketFilter) {
                            // just remove this filter, we will add it at the end manually
                            ((FilterPostProcessor) sceneProcessor).removeFilter(f);
                        } else {
                            leftPostProcessor.addFilter(f);
                            // clone to the right
                            Filter f2;
                            if (f instanceof FogFilter) {
                                f2 = FilterUtil.cloneFogFilter((FogFilter) f);
                            } else if (f instanceof CartoonSSAO) {
                                f2 = new CartoonSSAO((CartoonSSAO) f);
                            } else if (f instanceof SSAOFilter) {
                                f2 = FilterUtil.cloneSSAOFilter((SSAOFilter) f);
                            } else if (f instanceof DirectionalLightShadowFilter) {
                                f2 = FilterUtil.cloneDirectionalLightShadowFilter(environment.getApplication().getAssetManager(), (DirectionalLightShadowFilter) f);
                            } else {
                                // dof, bloom, lightscattering etc.
                                f2 = f;
                            }
                            rightPostProcessor.addFilter(f2);
                        }
                    }
                } else if (sceneProcessor instanceof VRDirectionalLightShadowRenderer) {
                    // shadow processing
                    // TODO: make right shadow processor use same left shadow maps for performance
                    VRDirectionalLightShadowRenderer dlsr = (VRDirectionalLightShadowRenderer) sceneProcessor;
                    VRDirectionalLightShadowRenderer dlsrRight = dlsr.clone();
                    dlsrRight.setLight(dlsr.getLight());
                    rightViewport.getProcessors().add(0, dlsrRight);
                    leftViewport.getProcessors().add(0, sceneProcessor);
                }
            }
            // make sure each has a translucent filter renderer
            leftPostProcessor.addFilter(new TranslucentBucketFilter());
            rightPostProcessor.addFilter(new TranslucentBucketFilter());
        } 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 : SSAOFilter(com.jme3.post.ssao.SSAOFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) VRDirectionalLightShadowRenderer(com.jme3.shadow.VRDirectionalLightShadowRenderer) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) Filter(com.jme3.post.Filter) SSAOFilter(com.jme3.post.ssao.SSAOFilter) FogFilter(com.jme3.post.filters.FogFilter) TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter) FogFilter(com.jme3.post.filters.FogFilter) SceneProcessor(com.jme3.post.SceneProcessor) CartoonSSAO(com.jme3.post.CartoonSSAO)

Example 69 with ViewPort

use of com.jme3.renderer.ViewPort 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 70 with ViewPort

use of com.jme3.renderer.ViewPort 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)

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