Search in sources :

Example 1 with Scene

use of org.rajawali3d.scene.Scene in project Rajawali by Rajawali.

the class SideBySideRenderer method initScene.

@Override
public void initScene() {
    mCameraLeft = new Camera();
    mCameraLeft.setNearPlane(.01f);
    mCameraLeft.setFieldOfView(getCurrentCamera().getFieldOfView());
    mCameraLeft.setNearPlane(getCurrentCamera().getNearPlane());
    mCameraLeft.setFarPlane(getCurrentCamera().getFarPlane());
    mCameraRight = new Camera();
    mCameraRight.setNearPlane(.01f);
    mCameraRight.setFieldOfView(getCurrentCamera().getFieldOfView());
    mCameraRight.setNearPlane(getCurrentCamera().getNearPlane());
    mCameraRight.setFarPlane(getCurrentCamera().getFarPlane());
    setPupilDistance(mPupilDistance);
    mLeftQuadMaterial = new Material();
    mLeftQuadMaterial.setColorInfluence(0);
    mRightQuadMaterial = new Material();
    mRightQuadMaterial.setColorInfluence(0);
    mSideBySideScene = new Scene(this);
    mLeftQuad = new ScreenQuad();
    mLeftQuad.setScaleX(.5);
    mLeftQuad.setX(-.25);
    mLeftQuad.setMaterial(mLeftQuadMaterial);
    mSideBySideScene.addChild(mLeftQuad);
    mRightQuad = new ScreenQuad();
    mRightQuad.setScaleX(.5);
    mRightQuad.setX(.25);
    mRightQuad.setMaterial(mRightQuadMaterial);
    mSideBySideScene.addChild(mRightQuad);
    addScene(mSideBySideScene);
    mViewportWidthHalf = (int) (mDefaultViewportWidth * .5f);
    mLeftRenderTarget = new RenderTarget("sbsLeftRT", mViewportWidthHalf, mDefaultViewportHeight);
    mLeftRenderTarget.setFullscreen(false);
    mRightRenderTarget = new RenderTarget("sbsRightRT", mViewportWidthHalf, mDefaultViewportHeight);
    mRightRenderTarget.setFullscreen(false);
    mCameraLeft.setProjectionMatrix(mViewportWidthHalf, mDefaultViewportHeight);
    mCameraRight.setProjectionMatrix(mViewportWidthHalf, mDefaultViewportHeight);
    addRenderTarget(mLeftRenderTarget);
    addRenderTarget(mRightRenderTarget);
    try {
        mLeftQuadMaterial.addTexture(mLeftRenderTarget.getTexture());
        mRightQuadMaterial.addTexture(mRightRenderTarget.getTexture());
    } catch (TextureException e) {
        e.printStackTrace();
    }
}
Also used : TextureException(org.rajawali3d.materials.textures.ATexture.TextureException) ScreenQuad(org.rajawali3d.primitives.ScreenQuad) Material(org.rajawali3d.materials.Material) Camera(org.rajawali3d.cameras.Camera) Scene(org.rajawali3d.scene.Scene)

Example 2 with Scene

use of org.rajawali3d.scene.Scene in project Rajawali by Rajawali.

the class PostProcessingManager method render.

public void render(@IntRange(from = 0) long ellapsedTime, @FloatRange(from = 0d) double deltaTime) {
    if (mComponentsDirty) {
        updatePassesList();
        mComponentsDirty = false;
    }
    mWriteBuffer = mRenderTarget1;
    mReadBuffer = mRenderTarget2;
    boolean maskActive = false;
    IPass pass;
    for (int i = 0; i < mNumPasses; i++) {
        pass = mPasses.get(i);
        if (!pass.isEnabled()) {
            continue;
        }
        PassType type = pass.getPassType();
        if (pass.getRenderToScreen()) {
            mRenderer.clearOverrideViewportDimensions();
        } else {
            mRenderer.setOverrideViewportDimensions(pass.getWidth(), pass.getHeight());
        }
        final boolean depthOrRenderPass = type == PassType.RENDER || type == PassType.DEPTH;
        final Scene renderScene = depthOrRenderPass ? mRenderer.getCurrentScene() : mScene;
        pass.render(renderScene, mRenderer, mScreenQuad, mWriteBuffer, mReadBuffer, ellapsedTime, deltaTime);
        if (pass.needsSwap() && i < mNumPasses - 1) {
            if (maskActive) {
                GLES20.glStencilFunc(GLES20.GL_NOTEQUAL, 1, 0xffffffff);
                mCopyPass.render(mScene, mRenderer, mScreenQuad, mWriteBuffer, mReadBuffer, ellapsedTime, deltaTime);
                GLES20.glStencilFunc(GLES20.GL_EQUAL, 1, 0xffffffff);
            }
            swapBuffers();
        }
        // If the current pass is a mask pass, notify the next pass that mask is active.
        if (type == PassType.MASK) {
            maskActive = true;
        } else if (type == PassType.CLEAR) {
            maskActive = false;
        }
    }
    // Restore the viewport dimensions
    mRenderer.clearOverrideViewportDimensions();
}
Also used : Scene(org.rajawali3d.scene.Scene) PassType(org.rajawali3d.postprocessing.IPass.PassType)

Aggregations

Scene (org.rajawali3d.scene.Scene)2 Camera (org.rajawali3d.cameras.Camera)1 Material (org.rajawali3d.materials.Material)1 TextureException (org.rajawali3d.materials.textures.ATexture.TextureException)1 PassType (org.rajawali3d.postprocessing.IPass.PassType)1 ScreenQuad (org.rajawali3d.primitives.ScreenQuad)1