Beispiel #1
0
void Camera::FillXMLInfo(XMLNode *xmlInfo) const
{
    Component::FillXMLInfo(xmlInfo);
    xmlInfo->SetTagName("Camera");

    xmlInfo->SetColor("ClearColor", GetClearColor());
    xmlInfo->SetFloat("ZNear", GetZNear());
    xmlInfo->SetFloat("ZFar", GetZFar());
    xmlInfo->SetEnum("ProjectionMode",
                     ProjectionMode_GetNamesVector(),
                     ProjectionMode_GetIndexFromValue(m_projMode),
                     {XMLProperty::Readonly});
    xmlInfo->SetFloat("AspectRatio", GetAspectRatio());

    if (GetProjectionMode() == ProjectionMode::Orthographic)
    {
        xmlInfo->SetFloat("OrthoHeight", GetOrthoHeight());
        xmlInfo->SetFloat("FOVDegrees", GetFovDegrees(), {XMLProperty::Hidden});
    }
    else
    {
        xmlInfo->SetFloat("OrthoHeight", GetOrthoHeight(), {XMLProperty::Hidden});
        xmlInfo->SetFloat("FOVDegrees", GetFovDegrees());
    }
}
void RenderStrategy::Render( content::Ref< Scene > scene, content::Ref< Camera > camera )
{
    rtgi::ClearColorBuffer( GetClearColor() );
    rtgi::ClearDepthBuffer();
    rtgi::ClearStencilBuffer();

    scene->Render();

    CallRenderCallback( scene );
}
Beispiel #3
0
void Camera::CloneInto(ICloneable *clone) const
{
    Component::CloneInto(clone);
    Camera *cam = static_cast<Camera*>(clone);
    cam->SetZFar(GetZFar());
    cam->SetZNear(GetZNear());
    cam->SetClearColor(GetClearColor());
    cam->SetFovDegrees(GetFovDegrees());
    cam->SetOrthoHeight(GetOrthoHeight());
    cam->SetAspectRatio(GetAspectRatio());
    cam->SetProjectionMode(GetProjectionMode());
    cam->SetAutoUpdateAspectRatio(GetAutoUpdateAspectRatio());
}
void RenderTask::PrepareRenderInstruction( RenderInstruction& instruction, BufferIndex updateBufferIndex )
{
  DALI_ASSERT_DEBUG( NULL != mCameraAttachment );

  TASK_LOG(Debug::General);

  Viewport viewport;
  bool viewportSet = QueryViewport( updateBufferIndex, viewport );

  instruction.Reset( mCameraAttachment,
                     GetFrameBufferId(),
                     viewportSet ? &viewport : NULL,
                     mClearEnabled ? &GetClearColor( updateBufferIndex ) : NULL );
}
Beispiel #5
0
void Camera::OnDrawGizmos()
{
    if (gameObject->IsEditorGameObject()) return;

    Component::OnDrawGizmos();

    Camera *sceneCam = Scene::GetCamera();
    float distScale = Vector3::Distance(sceneCam->transform->GetPosition(),
                                        transform->GetPosition());

    Gizmos::SetDrawWireframe(false);
    Gizmos::SetReceivesLighting(true);
    Gizmos::SetPosition(transform->GetPosition());
    Gizmos::SetRotation(transform->GetRotation());
    Gizmos::SetScale(Vector3::One * 0.02f * distScale);
    Gizmos::SetColor(GetClearColor());
    Gizmos::RenderCustomMesh(Camera::s_camMesh);

    if (gameObject->IsSelected())
    {
        Gizmos::SetColor(Color::Red);
        Gizmos::SetReceivesLighting(false);

        if (GetProjectionMode() == ProjectionMode::Perspective)
        {
            Gizmos::RenderFrustum(transform->GetForward(), transform->GetUp(),
                                  transform->GetPosition(),
                                  GetZNear(), GetZFar(),
                                  GetFovDegrees(), GetAspectRatio());
        }
        else
        {
            Box orthoBox;
            orthoBox.SetMin(transform->GetPosition() + Vector3(-GetOrthoWidth(), -GetOrthoHeight(), -GetZNear()));
            orthoBox.SetMax(transform->GetPosition() + Vector3( GetOrthoWidth(),  GetOrthoHeight(), -GetZFar()));
            Gizmos::SetRotation(transform->GetRotation());
            Gizmos::RenderSimpleBox(orthoBox);
        }
    }
}
Beispiel #6
0
 void DX11LightAccumulationbuffer::Clear()
 {
     mContext->ClearRenderTargetView(mRTV, GetClearColor());
 }
void GPUSegRenderStrategy::Render( content::Ref< rendering::Scene > scene, content::Ref< rendering::Camera > camera )
{
    if ( sVolumeLoaded )
    {
        //
        // calculate bounding box
        //
        VolumeDesc volumeDesc = sOriginalVolumeDesc;

        math::Vector3 textureSpaceVoxelDimensions( 1.0f / volumeDesc.numVoxelsX, 1.0f / volumeDesc.numVoxelsY, 1.0f / volumeDesc.numVoxelsZ );
        math::Vector3 boundingBoxDimensions( volumeDesc.numVoxelsX, volumeDesc.numVoxelsY, volumeDesc.numVoxelsZ * volumeDesc.zAnisotropy );
        math::Vector3 boundingBoxHalfDimensions = boundingBoxDimensions * 0.5f;

        math::Vector3 boxP1, boxP2, currentBoundingBoxExtent, cuttingPlaneP1, cuttingPlaneP2, cuttingPlaneP3, cuttingPlaneP4;
        bool renderCuttingPlane;

        if ( sOriginalVolumeDesc.upDirection == math::Vector3(  0,  0, -1 ) )
        {
            currentBoundingBoxExtent = boundingBoxHalfDimensions;

            currentBoundingBoxExtent[ math::Z ] =
                - boundingBoxHalfDimensions[ math::Z ] + ( boundingBoxHalfDimensions[ math::Z ] * math::Clamp( 0, 1, sCuttingPlaneZValue.GetValue() ) * 2 );

            boxP1            = currentBoundingBoxExtent;
            boxP2            = - boundingBoxHalfDimensions;
            boxP2[ math::Z ] = - boxP2[ math::Z ];

            cuttingPlaneP1 = math::Vector3( - currentBoundingBoxExtent[ math::X ], - currentBoundingBoxExtent[ math::Y ], currentBoundingBoxExtent[ math::Z ] );
            cuttingPlaneP2 = math::Vector3( - currentBoundingBoxExtent[ math::X ],   currentBoundingBoxExtent[ math::Y ], currentBoundingBoxExtent[ math::Z ] );
            cuttingPlaneP3 = math::Vector3(   currentBoundingBoxExtent[ math::X ],   currentBoundingBoxExtent[ math::Y ], currentBoundingBoxExtent[ math::Z ] );
            cuttingPlaneP4 = math::Vector3(   currentBoundingBoxExtent[ math::X ], - currentBoundingBoxExtent[ math::Y ], currentBoundingBoxExtent[ math::Z ] );

            if ( sCuttingPlaneZValue.GetValue() <= 0 )
            {
                renderCuttingPlane = false;
            }
            else
            {
                renderCuttingPlane = true;
            }
        }
        else
        {
            currentBoundingBoxExtent = boundingBoxHalfDimensions;

            currentBoundingBoxExtent[ math::Z ] =
                - boundingBoxHalfDimensions[ math::Z ] + ( boundingBoxHalfDimensions[ math::Z ] * math::Clamp( 0, 1, sCuttingPlaneZValue.GetValue() ) * 2 );

            boxP1 = - boundingBoxHalfDimensions;
            boxP2 = currentBoundingBoxExtent;

            cuttingPlaneP1 = math::Vector3( - currentBoundingBoxExtent[ math::X ], - currentBoundingBoxExtent[ math::Y ], currentBoundingBoxExtent[ math::Z ] );
            cuttingPlaneP2 = math::Vector3(   currentBoundingBoxExtent[ math::X ], - currentBoundingBoxExtent[ math::Y ], currentBoundingBoxExtent[ math::Z ] );
            cuttingPlaneP3 = math::Vector3(   currentBoundingBoxExtent[ math::X ],   currentBoundingBoxExtent[ math::Y ], currentBoundingBoxExtent[ math::Z ] );
            cuttingPlaneP4 = math::Vector3( - currentBoundingBoxExtent[ math::X ],   currentBoundingBoxExtent[ math::Y ], currentBoundingBoxExtent[ math::Z ] );

            if ( sCuttingPlaneZValue.GetValue() >= 1.0 )
            {
                renderCuttingPlane = false;
            }
            else
            {
                renderCuttingPlane = true;
            }
        }

        float fovYRadians = 0.0f;
        float aspectRatio = 0.0f;
        float nearPlane   = 0.0f;
        float farPlane    = 0.0f;

        camera->GetProjectionParameters( fovYRadians, aspectRatio, nearPlane, farPlane );

        Assert( fovYRadians != 0.0f );
        Assert( aspectRatio != 0.0f );
        Assert( nearPlane   != 0.0f );
        Assert( farPlane    != 0.0f );

        float imagePlaneXYScaleFactor = 5;
        float imagePlaneZScaleFactor  = 2;
        float imagePlaneHalfHeight    = atan( nearPlane * fovYRadians * 0.5 ) * imagePlaneXYScaleFactor;
        float imagePlaneHalfWidth     = imagePlaneHalfHeight * aspectRatio;

        math::Vector3 imagePlaneTopLeftCameraSpace     = math::Vector3( - imagePlaneHalfWidth,   imagePlaneHalfHeight, - nearPlane * imagePlaneZScaleFactor );
        math::Vector3 imagePlaneTopRightCameraSpace    = math::Vector3(   imagePlaneHalfWidth,   imagePlaneHalfHeight, - nearPlane * imagePlaneZScaleFactor );
        math::Vector3 imagePlaneBottomRightCameraSpace = math::Vector3(   imagePlaneHalfWidth, - imagePlaneHalfHeight, - nearPlane * imagePlaneZScaleFactor );
        math::Vector3 imagePlaneBottomLeftCameraSpace  = math::Vector3( - imagePlaneHalfWidth, - imagePlaneHalfHeight, - nearPlane * imagePlaneZScaleFactor );

        math::Matrix44 cameraToWorldMatrix;
        camera->GetLookAtMatrix( cameraToWorldMatrix );
        cameraToWorldMatrix.InvertTranspose();

        math::Vector3 imagePlaneTopLeftWorldSpace     = cameraToWorldMatrix.Transform( imagePlaneTopLeftCameraSpace );
        math::Vector3 imagePlaneTopRightWorldSpace    = cameraToWorldMatrix.Transform( imagePlaneTopRightCameraSpace );
        math::Vector3 imagePlaneBottomRightWorldSpace = cameraToWorldMatrix.Transform( imagePlaneBottomRightCameraSpace );
        math::Vector3 imagePlaneBottomLeftWorldSpace  = cameraToWorldMatrix.Transform( imagePlaneBottomLeftCameraSpace );

        int initialWidth, initialHeight;
        rendering::Context::GetInitialViewport( initialWidth, initialHeight );

        //
        // render back faces to a texture
        //
        sFrameBufferObject->Bind( sBackFacesTexture );
        
        rendering::rtgi::SetFaceCullingEnabled( true );
        rendering::rtgi::SetFaceCullingFace( rendering::rtgi::FaceCullingFace_Front );
        rendering::rtgi::ClearColorBuffer( rendering::rtgi::ColorRGBA( 0, 0, 0, 0 ) );
        rendering::rtgi::ClearDepthBuffer();
        rendering::rtgi::ClearStencilBuffer();

        sObjectSpacePositionAsColorShader->BeginSetShaderParameters();
        sObjectSpacePositionAsColorShader->SetShaderParameter( "boundingBoxDimensions", boundingBoxDimensions );
        sObjectSpacePositionAsColorShader->EndSetShaderParameters();
        sObjectSpacePositionAsColorShader->Bind();

        rendering::DebugDraw::DrawCube( boxP1, boxP2, rendering::rtgi::ColorRGB( 1, 1, 1 ) );

        sObjectSpacePositionAsColorShader->Unbind();

        sFrameBufferObject->Unbind();

        //
        // render front faces to a texture
        //
        sFrameBufferObject->Bind( sFrontFacesTexture );

        rendering::rtgi::ClearColorBuffer( rendering::rtgi::ColorRGBA( 0, 1, 1, 0 ) );
        rendering::rtgi::ClearDepthBuffer();
        rendering::rtgi::ClearStencilBuffer();

        sObjectSpacePositionAsColorShader->BeginSetShaderParameters();
        sObjectSpacePositionAsColorShader->SetShaderParameter( "boundingBoxDimensions", boundingBoxDimensions );
        sObjectSpacePositionAsColorShader->EndSetShaderParameters();
        sObjectSpacePositionAsColorShader->Bind();

        rendering::rtgi::SetFaceCullingEnabled( false );
        rendering::rtgi::SetDepthTestingEnabled( false );
        rendering::rtgi::SetDepthWritingEnabled( true );

        rendering::DebugDraw::DrawQuad(
            imagePlaneTopLeftWorldSpace,
            imagePlaneTopRightWorldSpace,
            imagePlaneBottomRightWorldSpace,
            imagePlaneBottomLeftWorldSpace,
            rendering::rtgi::ColorRGB( 1, 1, 1 ) );

        rendering::rtgi::SetFaceCullingEnabled( true );
        rendering::rtgi::SetFaceCullingFace( rendering::rtgi::FaceCullingFace_Back );
        rendering::rtgi::SetDepthTestingEnabled( true );
        rendering::rtgi::SetDepthWritingEnabled( true );

        rendering::DebugDraw::DrawCube( boxP1, boxP2, rendering::rtgi::ColorRGB( 1, 1, 1 ) );

        sObjectSpacePositionAsColorShader->Unbind();

        sFrameBufferObject->Unbind();

        //
        // render the volume
        //
        sFrameBufferObject->Bind( sRaycastTexture );

        rendering::rtgi::TextureSamplerStateDesc textureSamplerStateDesc;

        textureSamplerStateDesc.textureSamplerInterpolationMode = rendering::rtgi::TextureSamplerInterpolationMode_Smooth;
        textureSamplerStateDesc.textureSamplerWrapMode          = rendering::rtgi::TextureSamplerWrapMode_ClampToEdge;

        rendering::rtgi::ClearColorBuffer( GetClearColor() );
        rendering::rtgi::ClearDepthBuffer();
        rendering::rtgi::ClearStencilBuffer();
        rendering::rtgi::SetFaceCullingEnabled( false );

        sVolumeShader->BeginSetShaderParameters();
        sVolumeShader->SetShaderParameter( "sourceVolumeSampler",                   sSourceVolumeTexture,                   textureSamplerStateDesc );
        sVolumeShader->SetShaderParameter( "levelSetVolumeSampler",                 sCurrentLevelSetVolumeTexture,          textureSamplerStateDesc );
        sVolumeShader->SetShaderParameter( "frozenLevelSetVolumeSampler",           sFrozenLevelSetVolumeTexture,           textureSamplerStateDesc );
        sVolumeShader->SetShaderParameter( "activeElementsSampler",                 sActiveElementsVolumeTexture,           textureSamplerStateDesc );
        sVolumeShader->SetShaderParameter( "frontFacesSampler",                     sFrontFacesTexture,                     textureSamplerStateDesc );
        sVolumeShader->SetShaderParameter( "backFacesSampler",                      sBackFacesTexture,                      textureSamplerStateDesc );
        sVolumeShader->SetShaderParameter( "textureSpaceVoxelDimensions",           textureSpaceVoxelDimensions );
        sVolumeShader->SetShaderParameter( "cuttingPlaneZValue",                    sCuttingPlaneZValue.GetValue() );
        sVolumeShader->SetShaderParameter( "isosurface",                            sRenderingIsosurface.GetValue() );
        sVolumeShader->SetShaderParameter( "debugRender",                           sUpdateOpenGLTexture.GetValue() );
        sVolumeShader->SetShaderParameter( "renderLevelSet",                        sRenderLevelSet.GetValue() );
        sVolumeShader->SetShaderParameter( "renderHalo",                            sRenderHalo.GetValue() );
        sVolumeShader->SetShaderParameter( "showSourceData",                        sShowSourceData.GetValue() );
        sVolumeShader->SetShaderParameter( "zeroOutsideWindow",                     sZeroOutsideWindow.GetValue() );
        sVolumeShader->SetShaderParameter( "sourceWindow",                          sSourceWindow.GetValue() );
        sVolumeShader->SetShaderParameter( "sourceLevel",                           sSourceLevel.GetValue() );
        sVolumeShader->EndSetShaderParameters();

        sVolumeShader->Bind();

        rendering::DebugDraw::DrawCube( boxP1, boxP2, rendering::rtgi::ColorRGB( 1, 1, 1 ) );
        
        sVolumeShader->Unbind();

        //
        // render sketch interaction
        //
        if ( sSketchPoints.Size() > 0 )
        {
            rendering::rtgi::SetLineWidth( 1 );

             rendering::DebugDraw::DrawLine2D(
                sSketchPoints.At( 0 )[ math::X ],
                sSketchPoints.At( 0 )[ math::Y ],
                sSketchPoints.At( sSketchPoints.Size() - 1 )[ math::X ],
                sSketchPoints.At( sSketchPoints.Size() - 1 )[ math::Y ],
                rendering::rtgi::ColorRGB( 0, 1, 0 ) );

             rendering::DebugDraw::DrawPoint2D(
                sSketchPoints.At( 0 )[ math::X ],
                sSketchPoints.At( 0 )[ math::Y ],
                rendering::rtgi::ColorRGB( 0, 1, 0 ),
                4 );

             rendering::DebugDraw::DrawPoint2D(
                sSketchPoints.At( sSketchPoints.Size() - 1 )[ math::X ],
                sSketchPoints.At( sSketchPoints.Size() - 1 )[ math::Y ],
                rendering::rtgi::ColorRGB( 0, 1, 0 ),
                4 );
        }

        //
        // render debug stuff
        //
        rendering::rtgi::SetLineWidth( 2 );

        rendering::rtgi::SetColorWritingEnabled( true );
        rendering::rtgi::SetDepthTestingEnabled( true );
        rendering::rtgi::SetWireframeRenderingEnabled( true );
        rendering::rtgi::SetFaceCullingEnabled( true );
        rendering::rtgi::SetFaceCullingFace( rendering::rtgi::FaceCullingFace_Back );

        //if ( sDebugRender.GetValue() == 1.0f )
        //{
        //    rendering::DebugDraw::DrawCube( boxP1, boxP2, rendering::rtgi::ColorRGB( 1, 1, 1 ) );
        //}

        if ( renderCuttingPlane )
        {
#ifdef WHITE_BACKGROUND
            rendering::DebugDraw::DrawQuad( cuttingPlaneP1, cuttingPlaneP2, cuttingPlaneP3, cuttingPlaneP4, rendering::rtgi::ColorRGB( 0, 0, 0 ) );
#else
            rendering::DebugDraw::DrawQuad( cuttingPlaneP1, cuttingPlaneP2, cuttingPlaneP3, cuttingPlaneP4, rendering::rtgi::ColorRGB( 1, 1, 1 ) );
#endif
        }

        rendering::rtgi::SetWireframeRenderingEnabled( false );
        rendering::rtgi::SetFaceCullingEnabled( false );

        if ( sDebugRender.GetValue() > 0.0f )
        {
            //rendering::DebugDraw::DrawLine( math::Vector3( 0, 0, 0 ), math::Vector3( boundingBoxDimensions[ math::X ], 0, 0 ), rendering::rtgi::ColorRGB( 1, 0, 0 ) );
            //rendering::DebugDraw::DrawLine( math::Vector3( 0, 0, 0 ), math::Vector3( 0, boundingBoxDimensions[ math::Y ], 0 ), rendering::rtgi::ColorRGB( 0, 1, 0 ) );
            //rendering::DebugDraw::DrawLine( math::Vector3( 0, 0, 0 ), math::Vector3( 0, 0, boundingBoxDimensions[ math::Z ] ), rendering::rtgi::ColorRGB( 0, 0, 1 ) );

#ifdef WHITE_BACKGROUND
            rendering::rtgi::SetColor( rendering::rtgi::ColorRGB( 0, 0, 0 ) );
#else
            rendering::rtgi::SetColor( rendering::rtgi::ColorRGB( 1, 1, 1 ) );
#endif


            rendering::TextConsole::RenderCallback();
        }

        sFrameBufferObject->Unbind();

        sRaycastTexture->Bind( textureSamplerStateDesc );
        rendering::DebugDraw::DrawFullScreenQuad2D( rendering::rtgi::ColorRGB( 1, 1, 1 ) );
        sRaycastTexture->Unbind();
    }
}
Beispiel #8
0
HRESULT RenderTargetGroup::BeginUsing( bool push_state )
{
	if( !mRenderedTexturePtr || mRenderedTexturePtr->IsEmpty( ) )
		return XFXERR_INVALIDCALL;

	HRESULT hr;

	if( push_state )
	{
#if (__XFX_DIRECTX_VER__ < 9)
		LPDIRECT3DSURFACE8 saved_color;
		LPDIRECT3DSURFACE8 saved_depth;
#else
		LPDIRECT3DSURFACE9 saved_color;
		LPDIRECT3DSURFACE9 saved_depth;
#endif

#if (__XFX_DIRECTX_VER__ < 9)
		if( FAILED( hr = xfx::Renderer::Instance( ).pD3DDevice( )->GetRenderTarget( &saved_color ) ) )
#else
		if( FAILED( hr = xfx::Renderer::Instance( ).pD3DDevice( )->GetRenderTarget( 0, &saved_color ) ) )
#endif
			return hr;

		mpSavedColor.reset( saved_color, IUnknownDeleter( ) );

		if( FAILED( hr = xfx::Renderer::Instance( ).pD3DDevice( )->GetDepthStencilSurface( &saved_depth ) ) )
			return hr;

		mpSavedDepth.reset( saved_depth, IUnknownDeleter( ) );
	}

	xfx::Renderer::Instance( ).GetDrawTools( ).FlushAll( );

#if (__XFX_DIRECTX_VER__ < 9)
	if( FAILED( hr = xfx::Renderer::Instance( ).pD3DDevice( )->SetRenderTarget( mRenderedTexturePtr->GetD3DSurface( ), mDepthStencilPtr ? mDepthStencilPtr->GetD3DSurface( ) : NULL ) ) )
		return hr;
#else
	if( FAILED( hr = xfx::Renderer::Instance( ).pD3DDevice( )->SetRenderTarget( 0, mRenderedTexturePtr->GetD3DSurface( ) ) ) )
		return hr;

	if( FAILED( hr = xfx::Renderer::Instance( ).pD3DDevice( )->SetDepthStencilSurface( mDepthStencilPtr ? mDepthStencilPtr->GetD3DSurface( ) : NULL ) ) )
		return hr;
#endif

	if( GetClearFlags( ) )
		xfx::Renderer::Instance( ).pD3DDevice( )->Clear( 0, NULL, mDepthStencilPtr && !mDepthStencilPtr->IsEmpty( ) ? GetClearFlags( ) : GetClearFlags( ) & ~D3DCLEAR_ZBUFFER, GetClearColor( ).dword, GetClearDepth( ), GetClearStencil( ) );

	return S_OK;
}
void
My_TestGLDrawing::DrawTest(bool offscreen)
{
    std::cout << "My_TestGLDrawing::DrawTest()\n";

    HdPerfLog& perfLog = HdPerfLog::GetInstance();
    perfLog.Enable();
    
    // Reset all counters we care about.
    perfLog.ResetCache(HdTokens->extent);
    perfLog.ResetCache(HdTokens->points);
    perfLog.ResetCache(HdTokens->topology);
    perfLog.ResetCache(HdTokens->transform);
    perfLog.SetCounter(UsdImagingTokens->usdVaryingExtent, 0);
    perfLog.SetCounter(UsdImagingTokens->usdVaryingPrimvar, 0);
    perfLog.SetCounter(UsdImagingTokens->usdVaryingTopology, 0);
    perfLog.SetCounter(UsdImagingTokens->usdVaryingVisibility, 0);
    perfLog.SetCounter(UsdImagingTokens->usdVaryingXform, 0);

    int width = GetWidth(), height = GetHeight();

    double aspectRatio = double(width)/height;
    GfFrustum frustum;
    frustum.SetPerspective(60.0, aspectRatio, 1, 100000.0);

    GfMatrix4d viewMatrix;
    viewMatrix.SetIdentity();
    viewMatrix *= GfMatrix4d().SetRotate(GfRotation(GfVec3d(0, 1, 0), _rotate[0]));
    viewMatrix *= GfMatrix4d().SetRotate(GfRotation(GfVec3d(1, 0, 0), _rotate[1]));
    viewMatrix *= GfMatrix4d().SetTranslate(GfVec3d(_translate[0], _translate[1], _translate[2]));

    GfMatrix4d projMatrix = frustum.ComputeProjectionMatrix();

    GfMatrix4d modelViewMatrix = viewMatrix; 
    if (UsdGeomGetStageUpAxis(_stage) == UsdGeomTokens->z) {
        // rotate from z-up to y-up
        modelViewMatrix = 
            GfMatrix4d().SetRotate(GfRotation(GfVec3d(1.0,0.0,0.0), -90.0)) *
            modelViewMatrix;
    }

    GfVec4d viewport(0, 0, width, height);
    _engine->SetCameraState(modelViewMatrix, projMatrix, viewport);

    size_t i = 0;
    TF_FOR_ALL(timeIt, GetTimes()) {
        UsdTimeCode time = *timeIt;
        if (*timeIt == -999) {
            time = UsdTimeCode::Default();
        }
        UsdImagingGLRenderParams params;
        params.drawMode = GetDrawMode();
        params.enableLighting = IsEnabledTestLighting();
        params.enableIdRender = IsEnabledIdRender();
        params.frame = time;
        params.complexity = _GetComplexity();
        params.cullStyle = IsEnabledCullBackfaces() ?
                            UsdImagingGLCullStyle::CULL_STYLE_BACK :
                            UsdImagingGLCullStyle::CULL_STYLE_NOTHING;

        glViewport(0, 0, width, height);

        glEnable(GL_DEPTH_TEST);

        if(IsEnabledTestLighting()) {
            if(UsdImagingGLEngine::IsHydraEnabled()) {
                _engine->SetLightingState(_lightingContext);
            } else {
                _engine->SetLightingStateFromOpenGL();
            }
        }

        if (!GetClipPlanes().empty()) {
            params.clipPlanes = GetClipPlanes();
            for (size_t i=0; i<GetClipPlanes().size(); ++i) {
                glEnable(GL_CLIP_PLANE0 + i);
            }
        }

        GfVec4f const &clearColor = GetClearColor();
        GLfloat clearDepth[1] = { 1.0f };

        // Make sure we render to convergence.
        TfErrorMark mark;
        do {
            glClearBufferfv(GL_COLOR, 0, clearColor.data());
            glClearBufferfv(GL_DEPTH, 0, clearDepth);
            _engine->Render(_stage->GetPseudoRoot(), params);
        } while (!_engine->IsConverged());
        TF_VERIFY(mark.IsClean(), "Errors occurred while rendering!");

        std::cout << "itemsDrawn " << perfLog.GetCounter(HdTokens->itemsDrawn) << std::endl;
        std::cout << "totalItemCount " << perfLog.GetCounter(HdTokens->totalItemCount) << std::endl;

        std::string imageFilePath = GetOutputFilePath();
        if (!imageFilePath.empty()) {
            if (time != UsdTimeCode::Default()) {
                std::stringstream suffix;
                suffix << "_" << std::setw(3) << std::setfill('0') << params.frame << ".png";
                imageFilePath = TfStringReplace(imageFilePath, ".png", suffix.str());
            }
            std::cout << imageFilePath << "\n";
            WriteToFile("color", imageFilePath);
        }
        i++;
    }