GPU Path-Tracing


how to switch to GPU Path-Tracing mode in my application? Or is this only available in CAD-Rays?


Daniel Duesentrieb's picture

I found it:

ChangeRenderingParams().IsGlobalIlluminationEnabled = true;

problem is that it doesn't work or extremely slow. There is no load on the CPU, nor GPU.

I am running Window. But now I am worried that I have to switch to MSVC instead MinGW since CUDA is not avaliable for MinGW?

Kirill Gavrilov's picture

Apart from mentioned Boolean flag, Path Tracing requires a plenty of setup:

  • Enabling Ray Tracing (Graphic3d_RenderingParams::Method = Graphic3d_RM_RAYTRACING) + Path Tracing (Graphic3d_RenderingParams::IsGlobalIlluminationEnabled).
  • Configuring PBR materials for your models (simplified Graphic3d_MaterialAspect::PBRMaterial() and advanced Graphic3d_MaterialAspect::BSDF()).
    You may start from importing some glTF 2.0 models, which are expected to have realistic materials.
  • Configuring light sources (Graphic3d_CLight) with proper power Graphic3d_CLight::Intensity (scalable to physical dimensions of your scene) and extra parameters specific to Path Tracing.
  • Configuring IBL (Image-Based-Lighting) for environment lighting (V3d_View::SetBackgroundCubeMap()).
  • Enabling continuous rendering for Path-Tracing to advance (AIS_ViewController::IsContinuousRedraw() or whatever you use in your application).
  • Configuring other Ray-Tracing parameters in Graphic3d_RenderingParams.

Ray Tracing doesn't use CUDA - it is implemented using OpenGL shader programs, so it is irrelevant which C++ compiler to use for building OCCT.

Draw Harness comes with a couple of samples of Path Tracing setups, which might be a good point to start with:

Daniel Duesentrieb's picture

Thanks Kirill,
the missing part was - and is - AIS_ViewController::IsContinuousRedraw()

a workaround is a for to loop and Redraw().

I run 7.5.0 and it is not available there. Currently try to compile 7.6.0

Daniel Duesentrieb's picture

I can't get the AIS_ViewController do anything. Ho do I get continuesRedraw going?


class OccView : public QWidget, protected AIS_ViewController

void OccView::EnableRaytracing()
    if (!myIsRaytracing)
        m_view->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
        m_view->ChangeRenderingParams().AdaptiveScreenSampling = true;
        m_view->ChangeRenderingParams().AdaptiveScreenSamplingAtomic = true;
        m_view->ChangeRenderingParams().IsGlobalIlluminationEnabled = true;
        m_view->ChangeRenderingParams().IsTransparentShadowEnabled = true;
        m_view->ChangeRenderingParams().RaytracingDepth = 10;
        m_view->ChangeRenderingParams().ToShowStats = true;


    //for (int i=0; i< 50; i++)
    //    m_view->Redraw();

    myIsRaytracing = true;
//    m_context->UpdateCurrentViewer();
Kirill Gavrilov's picture

Default implementation of AIS_ViewController::SetContinuousRedraw() ends up in calling Aspect_Window::InvalidateContent(). In case of interconnection with GUI frameworks (like Qt in your case), this might not work as expected or do not work at all. If Aspect_NeutralWindow implementation is used or a custom subclass of Aspect_Window wrapping Qt widget - this method may do nothing.

In such cases, it is better checking documentation of your GUI framework for a best way to ask it continuously redrawing 3D widget content. Usually these mechanisms are used for drawing animation. In case of QtQuick, for instance, calling QQuickWindow::update() at the end of a frame (e.g. right after repainting OCCT 3D Viewer content) would be enough to ask Qt to draw one more frame. In case of QOpenGlWidget, this could be done by calling QOpenGlWidget::update() (see how AIS_ViewController::handleViewRedraw() is overridden to handle myToAskNextFrame):

void OcctQtViewer::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
                                     const Handle(V3d_View)& theView)
  AIS_ViewController::handleViewRedraw (theCtx, theView);
  if (myToAskNextFrame)
    // ask more frames for animation

void OcctQtViewer::updateView()
  //if (window() != NULL) { window()->update(); }

AIS_ViewController::myToAskNextFrame is set to TRUE in case of some animation started or when AIS_ViewController::IsContinuousRedraw() is set. I guess that in case of a usual QWidget there should be some other way to do similar thing.

zhu gaolei's picture

HI,Kirill Gavrilov。 In OCCT7.5 has no method AIS_ViewController::SetContinuousRedraw()。Can use GPU Path-Tracing on 7.5?

Kirill Gavrilov's picture

AIS_ViewController::SetContinuousRedraw() is just a helper to redraw view automatically again and again using native window invalidation routines like calling

InvalidateRect ((HWND )myHWindow, NULL, TRUE);

from WinAPI at the end of currently drawn frame (AIS_ViewController::HandleViewEvents()).

You may implement this redrawing logic on your own with help of GUI framework, like configuring multimedia timer redrawing the viewer at desired framerate (by calling  V3d_View::Invalidate() and AIS_ViewController::FlushViewEvents()).