Search in sources :

Example 26 with Pass

use of com.jme3.post.Filter.Pass 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 27 with Pass

use of com.jme3.post.Filter.Pass 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)

Example 28 with Pass

use of com.jme3.post.Filter.Pass 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)

Aggregations

Material (com.jme3.material.Material)11 Vector3f (com.jme3.math.Vector3f)6 Camera (com.jme3.renderer.Camera)4 Geometry (com.jme3.scene.Geometry)4 Pass (com.jme3.post.Filter.Pass)3 Node (com.jme3.scene.Node)3 AmbientLight (com.jme3.light.AmbientLight)2 DirectionalLight (com.jme3.light.DirectionalLight)2 PointLight (com.jme3.light.PointLight)2 ColorRGBA (com.jme3.math.ColorRGBA)2 Quaternion (com.jme3.math.Quaternion)2 Vector2f (com.jme3.math.Vector2f)2 ChannelInfoMessage (com.jme3.network.message.ChannelInfoMessage)2 ClientRegistrationMessage (com.jme3.network.message.ClientRegistrationMessage)2 Renderer (com.jme3.renderer.Renderer)2 LightNode (com.jme3.scene.LightNode)2 Spatial (com.jme3.scene.Spatial)2 FrameBuffer (com.jme3.texture.FrameBuffer)2 Texture2D (com.jme3.texture.Texture2D)2 NativeObject (com.jme3.util.NativeObject)2