Search in sources :

Example 46 with Camera

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

the class RenderManager method renderViewPortQueues.

/**
     * Render the given viewport queues.
     * <p>
     * Changes the {@link Renderer#setDepthRange(float, float) depth range}
     * appropriately as expected by each queue and then calls 
     * {@link RenderQueue#renderQueue(com.jme3.renderer.queue.RenderQueue.Bucket, com.jme3.renderer.RenderManager, com.jme3.renderer.Camera, boolean) }
     * on the queue. Makes sure to restore the depth range to [0, 1] 
     * at the end of the call.
     * Note that the {@link Bucket#Translucent translucent bucket} is NOT
     * rendered by this method. Instead the user should call 
     * {@link #renderTranslucentQueue(com.jme3.renderer.ViewPort) }
     * after this call.
     * 
     * @param vp the viewport of which queue should be rendered
     * @param flush If true, the queues will be cleared after
     * rendering.
     * 
     * @see RenderQueue
     * @see #renderTranslucentQueue(com.jme3.renderer.ViewPort) 
     */
public void renderViewPortQueues(ViewPort vp, boolean flush) {
    RenderQueue rq = vp.getQueue();
    Camera cam = vp.getCamera();
    boolean depthRangeChanged = false;
    // opaque objects are sorted front-to-back, reducing overdraw
    if (prof != null)
        prof.vpStep(VpStep.RenderBucket, vp, Bucket.Opaque);
    rq.renderQueue(Bucket.Opaque, this, cam, flush);
    // render the sky, with depth range set to the farthest
    if (!rq.isQueueEmpty(Bucket.Sky)) {
        if (prof != null)
            prof.vpStep(VpStep.RenderBucket, vp, Bucket.Sky);
        renderer.setDepthRange(1, 1);
        rq.renderQueue(Bucket.Sky, this, cam, flush);
        depthRangeChanged = true;
    }
    // back-to-front.
    if (!rq.isQueueEmpty(Bucket.Transparent)) {
        if (prof != null)
            prof.vpStep(VpStep.RenderBucket, vp, Bucket.Transparent);
        if (depthRangeChanged) {
            renderer.setDepthRange(0, 1);
            depthRangeChanged = false;
        }
        rq.renderQueue(Bucket.Transparent, this, cam, flush);
    }
    if (!rq.isQueueEmpty(Bucket.Gui)) {
        if (prof != null)
            prof.vpStep(VpStep.RenderBucket, vp, Bucket.Gui);
        renderer.setDepthRange(0, 0);
        setCamera(cam, true);
        rq.renderQueue(Bucket.Gui, this, cam, flush);
        setCamera(cam, false);
        depthRangeChanged = true;
    }
    // restore range to default
    if (depthRangeChanged) {
        renderer.setDepthRange(0, 1);
    }
}
Also used : RenderQueue(com.jme3.renderer.queue.RenderQueue)

Example 47 with Camera

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

the class RenderManager method renderViewPort.

/**
     * Renders the {@link ViewPort}.
     * <p>
     * If the ViewPort is {@link ViewPort#isEnabled() disabled}, this method
     * returns immediately. Otherwise, the ViewPort is rendered by 
     * the following process:<br>
     * <ul>
     * <li>All {@link SceneProcessor scene processors} that are attached
     * to the ViewPort are {@link SceneProcessor#initialize(com.jme3.renderer.RenderManager, com.jme3.renderer.ViewPort) initialized}.
     * </li>
     * <li>The SceneProcessors' {@link SceneProcessor#preFrame(float) } method 
     * is called.</li>
     * <li>The ViewPort's {@link ViewPort#getOutputFrameBuffer() output framebuffer}
     * is set on the Renderer</li>
     * <li>The camera is set on the renderer, including its view port parameters.
     * (see {@link #setCamera(com.jme3.renderer.Camera, boolean) })</li>
     * <li>Any buffers that the ViewPort requests to be cleared are cleared
     * and the {@link ViewPort#getBackgroundColor() background color} is set</li>
     * <li>Every scene that is attached to the ViewPort is flattened into 
     * the ViewPort's render queue 
     * (see {@link #renderViewPortQueues(com.jme3.renderer.ViewPort, boolean) })
     * </li>
     * <li>The SceneProcessors' {@link SceneProcessor#postQueue(com.jme3.renderer.queue.RenderQueue) }
     * method is called.</li>
     * <li>The render queue is sorted and then flushed, sending
     * rendering commands to the underlying Renderer implementation. 
     * (see {@link #flushQueue(com.jme3.renderer.ViewPort) })</li>
     * <li>The SceneProcessors' {@link SceneProcessor#postFrame(com.jme3.texture.FrameBuffer) }
     * method is called.</li>
     * <li>The translucent queue of the ViewPort is sorted and then flushed
     * (see {@link #renderTranslucentQueue(com.jme3.renderer.ViewPort) })</li>
     * <li>If any objects remained in the render queue, they are removed
     * from the queue. This is generally objects added to the 
     * {@link RenderQueue#renderShadowQueue(com.jme3.renderer.queue.RenderQueue.ShadowMode, com.jme3.renderer.RenderManager, com.jme3.renderer.Camera, boolean) 
     * shadow queue}
     * which were not rendered because of a missing shadow renderer.</li>
     * </ul>
     * 
     * @param vp View port to render
     * @param tpf Time per frame value
     */
public void renderViewPort(ViewPort vp, float tpf) {
    if (!vp.isEnabled()) {
        return;
    }
    if (prof != null)
        prof.vpStep(VpStep.BeginRender, vp, null);
    SafeArrayList<SceneProcessor> processors = vp.getProcessors();
    if (processors.isEmpty()) {
        processors = null;
    }
    if (processors != null) {
        if (prof != null)
            prof.vpStep(VpStep.PreFrame, vp, null);
        for (SceneProcessor proc : processors.getArray()) {
            if (!proc.isInitialized()) {
                proc.initialize(this, vp);
            }
            proc.setProfiler(this.prof);
            if (prof != null)
                prof.spStep(SpStep.ProcPreFrame, proc.getClass().getSimpleName());
            proc.preFrame(tpf);
        }
    }
    renderer.setFrameBuffer(vp.getOutputFrameBuffer());
    setCamera(vp.getCamera(), false);
    if (vp.isClearDepth() || vp.isClearColor() || vp.isClearStencil()) {
        if (vp.isClearColor()) {
            renderer.setBackgroundColor(vp.getBackgroundColor());
        }
        renderer.clearBuffers(vp.isClearColor(), vp.isClearDepth(), vp.isClearStencil());
    }
    if (prof != null)
        prof.vpStep(VpStep.RenderScene, vp, null);
    List<Spatial> scenes = vp.getScenes();
    for (int i = scenes.size() - 1; i >= 0; i--) {
        renderScene(scenes.get(i), vp);
    }
    if (processors != null) {
        if (prof != null)
            prof.vpStep(VpStep.PostQueue, vp, null);
        for (SceneProcessor proc : processors.getArray()) {
            if (prof != null)
                prof.spStep(SpStep.ProcPostQueue, proc.getClass().getSimpleName());
            proc.postQueue(vp.getQueue());
        }
    }
    if (prof != null)
        prof.vpStep(VpStep.FlushQueue, vp, null);
    flushQueue(vp);
    if (processors != null) {
        if (prof != null)
            prof.vpStep(VpStep.PostFrame, vp, null);
        for (SceneProcessor proc : processors.getArray()) {
            if (prof != null)
                prof.spStep(SpStep.ProcPostFrame, proc.getClass().getSimpleName());
            proc.postFrame(vp.getOutputFrameBuffer());
        }
        if (prof != null)
            prof.vpStep(VpStep.ProcEndRender, vp, null);
    }
    //renders the translucent objects queue after processors have been rendered
    renderTranslucentQueue(vp);
    // clear any remaining spatials that were not rendered.
    clearQueue(vp);
    if (prof != null)
        prof.vpStep(VpStep.EndRender, vp, null);
}
Also used : SceneProcessor(com.jme3.post.SceneProcessor)

Example 48 with Camera

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

the class FilterPostProcessor method reshape.

public void reshape(ViewPort vp, int w, int h) {
    Camera cam = vp.getCamera();
    //this has no effect at first init but is useful when resizing the canvas with multi views
    cam.setViewPort(left, right, bottom, top);
    //resizing the camera to fit the new viewport and saving original dimensions
    cam.resize(w, h, false);
    left = cam.getViewPortLeft();
    right = cam.getViewPortRight();
    top = cam.getViewPortTop();
    bottom = cam.getViewPortBottom();
    originalWidth = w;
    originalHeight = h;
    //computing real dimension of the viewport and resizing the camera 
    width = (int) (w * (Math.abs(right - left)));
    height = (int) (h * (Math.abs(bottom - top)));
    width = Math.max(1, width);
    height = Math.max(1, height);
    //camera must be handled differently
    if (originalWidth != width || originalHeight != height) {
        multiView = true;
    }
    cameraInit = true;
    computeDepth = false;
    if (renderFrameBuffer == null && renderFrameBufferMS == null) {
        outputBuffer = viewPort.getOutputFrameBuffer();
    }
    Collection<Caps> caps = renderer.getCaps();
    //antialiasing on filters only supported in opengl 3 due to depth read problem
    if (numSamples > 1 && caps.contains(Caps.FrameBufferMultisample)) {
        renderFrameBufferMS = new FrameBuffer(width, height, numSamples);
        if (caps.contains(Caps.OpenGL32)) {
            Texture2D msColor = new Texture2D(width, height, numSamples, fbFormat);
            Texture2D msDepth = new Texture2D(width, height, numSamples, Format.Depth);
            renderFrameBufferMS.setDepthTexture(msDepth);
            renderFrameBufferMS.setColorTexture(msColor);
            filterTexture = msColor;
            depthTexture = msDepth;
        } else {
            renderFrameBufferMS.setDepthBuffer(Format.Depth);
            renderFrameBufferMS.setColorBuffer(fbFormat);
        }
    }
    if (numSamples <= 1 || !caps.contains(Caps.OpenGL32)) {
        renderFrameBuffer = new FrameBuffer(width, height, 1);
        renderFrameBuffer.setDepthBuffer(Format.Depth);
        filterTexture = new Texture2D(width, height, fbFormat);
        renderFrameBuffer.setColorTexture(filterTexture);
    }
    for (Filter filter : filters.getArray()) {
        initFilter(filter, vp);
    }
    setupViewPortFrameBuffer();
}
Also used : Texture2D(com.jme3.texture.Texture2D) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 49 with Camera

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

the class RenderQueue method renderGeometryList.

private void renderGeometryList(GeometryList list, RenderManager rm, Camera cam, boolean clear) {
    // select camera for sorting
    list.setCamera(cam);
    list.sort();
    for (int i = 0; i < list.size(); i++) {
        Geometry obj = list.get(i);
        assert obj != null;
        rm.renderGeometry(obj);
        obj.queueDistance = Float.NEGATIVE_INFINITY;
    }
    if (clear) {
        list.clear();
    }
}
Also used : Geometry(com.jme3.scene.Geometry)

Example 50 with Camera

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

the class BillboardControl method rotateScreenAligned.

/**
     * Rotate the billboard so it points directly opposite the direction the
     * camera's facing
     *
     * @param camera
     *            Camera
     */
private void rotateScreenAligned(Camera camera) {
    // coopt diff for our in direction:
    look.set(camera.getDirection()).negateLocal();
    // coopt loc for our left direction:
    left.set(camera.getLeft()).negateLocal();
    orient.fromAxes(left, camera.getUp(), look);
    Node parent = spatial.getParent();
    Quaternion rot = new Quaternion().fromRotationMatrix(orient);
    if (parent != null) {
        rot = parent.getWorldRotation().inverse().multLocal(rot);
        rot.normalizeLocal();
    }
    spatial.setLocalRotation(rot);
    fixRefreshFlags();
}
Also used : Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node)

Aggregations

Camera (com.jme3.renderer.Camera)63 Vector3f (com.jme3.math.Vector3f)51 Material (com.jme3.material.Material)26 Geometry (com.jme3.scene.Geometry)26 Quaternion (com.jme3.math.Quaternion)23 Spatial (com.jme3.scene.Spatial)19 TempVars (com.jme3.util.TempVars)16 Box (com.jme3.scene.shape.Box)13 ViewPort (com.jme3.renderer.ViewPort)11 Node (com.jme3.scene.Node)11 DirectionalLight (com.jme3.light.DirectionalLight)10 FrameBuffer (com.jme3.texture.FrameBuffer)10 Texture (com.jme3.texture.Texture)10 FilterPostProcessor (com.jme3.post.FilterPostProcessor)9 Texture2D (com.jme3.texture.Texture2D)9 ArrayList (java.util.ArrayList)9 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)8 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)8 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)8 CameraNode (com.jme3.scene.CameraNode)7