Ray tracing as alternative rendering method for OCCT visualization component

Forums: 

OCCT 6.7.0 introduces several major improvements of the visualization component. One of the most breaking changes in OCCT visualization concerns simplified implementation of ray tracing algorithm for regular OCCT visualization primitives. This algorithm is implemented using OpenCL. Being a part of TKOpenGl library, it is fully integrated with standard OCCT visualization logic. From now on, ray tracing can be used as alternative rendering method instead of OpenGL rasterization. Compared to third-party ray tracing libraries, the built-in implementation ensures real-time rendering performance, which is close to or even better than OpenGL rasterization performance on heavy models.

The simplified - but still powerful! - ray tracer implementation has the following features:

  • High-quality shading by interpolating normal across the triangle pixels and using advanced illumination model (Phong shading)
  • Depth-correct order-independent transparency for any number of overlapped objects
  • Sharp shadows from isotropic point and directional lights without any approximation – greatly improve visual appearance
  • Specular reflections and environment mapping – for high-quality rendering of metallic surfaces
  • Low-cost adaptive anti-aliasing allows to improve image quality by removing jagged edges from the image
  • Based on cross-platform OpenCL framework – runs on GPUs of major vendors (NVIDIA and AMD/ATI)
  • Makes the most of the mid-/top-range GPUs but also runs successfully on low-end GPUs that support OpenCL

Once OCCT has been built with OpenCL support, using ray tracing is really simple: it is enough to call V3d_View::SetRaytracingMode() to switch the 3D view to ray tracing rendering. Refer to V3d_View class documentation and check vraytrace and vsetraytracemode DRAW Test Harness commands for details how to adjust ray tracing options. Probably, the easiest way to evaluate ray tracing output is to run the following command from the DRAW command prompt:

source samples/tcl/raytrace.tcl

Below some snapshots are included that give a basic idea how OCCT ray tracing improves quality of 3D scene rendering. The snapshots were created using CAD models from http://www.grabcad.com/.

Sharp shadows, adaptive anti-aliasing, reflections
Sharp shadows, adaptive anti-aliasing, reflections
Adaptive anti-aliasing, realistic transparency
Sharp shadows, adaptive anti-aliasing, reflections and environment mapping
Sharp shadows, adaptive anti-aliasing, reflections and environment mapping

The first version of ray tracing algorithm has the following limitations, some or all of them will be addressed in the future OCCT releases:

  • Textures are not imported from OCCT visualization data (except for the environment texture which is taken into account)
  • Ray tracing component currently supports only polygonal geometry
    • Points, lines and text are not supported – as a consequence, wireframe presentation cannot be rendered using ray tracing
  • Coincident triangles results in visual artifacts (same problem as in case of OpenGL usage)
    • The workaround is to shift coincident geometries with respect to each other by a very small value
  • Support of CPUs and Intel GPUs is not tested
  • Operation under MacOS X is not tested. OCCT users are encouraged to provide their patches related to this platform.
  • Source geometry for ray tracing is taken from CPU memory, existing VBO data is not reused by ray tracing
    • To enable OpenGL rendering in parallel with ray tracer rendering, VBOs are created without releasing CPU memory occupied by geometrical data
  • Non-optimal memory footprint:
    • Combined rendering (OpenGL + ray-tracing): 3.3x memory amount used (2.3x on GPU)
    • 2 GB GPU memory: up to 30M triangles in ray-tracing mode
Patrik's picture

Hi Sergey,

just for interest: has anyone tried to compile it with the NVIDIA SDK? Or is the AMD SDK required for building?

Greets,

Patrik

Andrey BETENEV's picture

Hello Patrik,

As OCCT uses standard OpenCL interface, it should build well with either AMD or NVIDIA or any other OpenCL SDK compatible with the specification. We actually use OpenCL ICD Loader tool available from Khronos, see http://www.khronos.org/registry/cl/. You can download ready-to-use builds for Windows at http://www.opencascade.org/getocc/download/3rdparty/

Andrey

Patrik's picture

Cool,

thanks for the fast info. I'm very excited about the new visualization features ;-)

Patrik

Sergey Anikin's picture

Good news for those suffered recently from an extra OCCT dependency on OpenCL: the OCCT ray tracer is now written in GLSL.
A nice side-effect of this migration, switching between the OpenGL rasterizer and the ray tracing now takes almost zero time.

See issue 24739 - and don't forget to check out and try the code from the OCCT Git master!

Sergey Anikin's picture

One more new cool feature of the OCCT ray tracer that is worth having a look, bi-level BVH tree has been implemented that enables fast updates of the ray tracer acceleration structure and avoid heavy recalculations in the following cases:

  • Applying local transformations to particular presentations (essential for real-time animations in the ray tracer scene)
  • Changing visual attributes of particular presentations (color, material, etc.)
  • Adding/removing presentations to/from the scene

Refer to Mantis issue 24520 and corresponding Git commit that is already available in OCCT Git master.

Shockwave's picture

Please can you post some models and code for reproducing the same result of the samples that you have posted in this thread?
I have tried to enable raytracing, with shadows, reflection and antialiasing, but I haven't reached the same result as you have posted on the visualization project page
http://dev.opencascade.org/index.php?q=home/projects/visualization
Could you add the models and sample code for having this results?

Then I have tried to use it, but for me is far from being realtime, I have tested the master trunk snapshot 6.7.2, have you any further develope in progress to make this ray tracer really in real time?

Kirill Gavrilov's picture

Dear mach22,

have you any further develope in progress to make this ray tracer really in real time?

the Ray-tracing core in OCCT is in functionality prototyping stage and is not designed for old GPU architectures - you need modern GPU (GCN+ from AMD or Kepler+ from NVIDIA) to achieve performance comparable to traditional rasterization pipeline.

Please see earlier discussion here:
http://dev.opencascade.org/index.php?q=node/954#comment-321

Could you please post you graphic card model name?

The optimization for obsolete GPUs is currently out of scope but might be considered if requested by customers.

Shockwave's picture

I have tested it on Nvidia Geeforce 720M, as I need to make this working not only on the top graphic card, which ones do you certified as minimal requirement? better AMD or Nvidia, I have read that it seem that AMD has better support for OpenCL so it could be better, right?
An AMD R7 260x could be good for example? Or I need to have a GCN or Kepler?
I'm quite disappointed because I can't request a top graphic card to have this kind of rendering while other cad software can make this working with middle level GPU. I hope you'll improve it.

Kirill Gavrilov's picture

An AMD R7 260x could be good for example? Or I need to have a GCN or Kepler?

AMD R7 260x is based on GCN 1.1 architecture. It should be sufficient for testing this functionality, although we have not such card yet to perform own tests.

GeForce 720M is quite old low-end graphics based on Fermi kernel (released in 2010). As most low-end chips it has worst performance characteristics, and sufficient only for basic rendering.

I have read that it seem that AMD has better support for OpenCL so it could be better, right?

Yes, GeForce drivers have problems with OpenCL. However Ray-tracing core in OCCT master branch is no more based on OpenCL - it uses GLSL (apart from releases 670 and 671 with OpenCL-based code).

other cad software can make this working with middle level GPU.

There is no other CAD software which provides complete built-in real-time Ray-Tracing as far as I know - only limited features or spec-effects.

Shockwave's picture

which card can you recommend to test this functionality?
An AMD R9 270x could be good? or it could have some problems and better going on a R9 280x? Or better an NVIDIA card?
On which card do you have tested it with good performances? can you post a list with the brand and model certified to works good with the rendering based on ray tracing?
I'd like to have some model and example with right materials and light to reproduce the models presented in the project of visualization

http://dev.opencascade.org/index.php?q=home/projects/visualization

like the Samovar sample or the 3 example of BRep model testing the
Ambient occlusion sample
Soft shadows sample
Rendering with light refraction support (simulating glass)

There will be any improvement in the next public release? 6.8.0 or 7.0.0?
Thanks

Sergey Anikin's picture

Dear mach22,

As a general remark related to graphic hardware compatibility check, we are thinking currently how to implement it, see this post for example. Obviously, we will not be able to test OCCT visualization component with all popular graphic cards on the market, so we are in favor of some automated procedure that can give the answer quickly for a particular hardware.

Just as an example of suitable hardware, we use AMD RADEON HD 7850 on one of our development stations, and ray tracing (after migration to GLSL) seems to show acceptable performance. Another example is NVIDIA GeForce GTX 770. Naturally, these are just samples, not the complete compatibility list.

I'd like to have some model and example with right materials and light to reproduce the models presented in the project of visualization

We are working on this topic right now, hope to prepare an OCCT Git branch soon that will contain the mentioned Tcl samples and new BRep models.
However, please note that experiments with soft shadows are not yet completed and corresponding development results are not yet in OCCT Git.

There will be any improvement in the next public release? 6.8.0 or 7.0.0?

We have plans to include some ray tracing improvements into OCCT 6.8.0 - like migration to GLSL, implementation of refractions and support of lines and text labels. Some of these features are already available as corresponding OCCT Git branches. Follow the visualization forum, we post information about new important improvements in real time as soon as development branch is ready for testing.

Shockwave's picture

You could make an executable like glCapsViewer to check the performance of the graphic card in the local machine and make the result loaded to an online community database

http://delphigl.de/glcapsviewer/listreports.php

In this way you could list several cards making involved the community of OpenCascade developers and users, and so presenting the minimal requirement compared with many different graphic cards.

Sergey Anikin's picture

Hello mach22!

Your idea sounds good, and this is definitely one of the options we will consider.

Best regards,
Sergey

Sergey Anikin's picture

Hello mach22!

Before any more sophisticated tests are available, can you please try the following very simple one in DRAW command prompt:

source samples/tcl/raytrace.tcl
vfps

and post here the results for the graphic cards you use?

And please state clearly which OCCT version you use - OCCT 6.7.1 or the current development snapshot from Git.

Best regards,
Sergey

UPDATED: Just for fun, we have tried this simple test with integrated Intel graphics (Intel Core i5-3450) and the current OCCT development snapshot (debug build!).
Here are the results:

Draw[2]> source c:/occt/samples/tcl/raytrace.tcl
Plugin file name has not been specified. Defaults to DrawPlugin
Parse Value ==> TOPTEST
Parse aCurKey = TOPTEST
Parse aCurKey =
Parse Value ==> TKTopTest
Parse aCurKey = TKTopTest
Parse aCurKey =
Parse Value ==> AISV
Parse aCurKey = AISV
Parse aCurKey =
Parse Value ==> TKTopTest
Parse aCurKey = TKTopTest
Parse aCurKey =
Parse Value ==> TKViewerTest
Parse aCurKey = TKViewerTest
Parse aCurKey =
aResource = TOPTEST
Value ==> TKTopTest
Draw Plugin : All topological operations kernel commands are loaded
Load c:\disr\src\DrawResources/TKTopTest.tcl TclScript
aResource = AISV
Value ==> TKViewerTest
Constructing bottle body...

COMPUTE: temps total 0.1248008s  dont :
- Init + ExtentAnalyse 0s
- PerformSetOfSurf 0.0780005s
- PerformFilletOnVertex 0.0156001s
- FilDS 0s
- Reconstruction 0.0312002s
- SetRegul 0s

Constructing threading...
Putting together and writing "Open CASCADE"...
Showing result...
Command vinit should be called before!
nb of modes to recalculate : 2
nb of modes to recalculate : 2
Trying raytrace mode...
TKOpenGl.OpenGL | Type: Performance | ID: 2 | Severity: Medium | Message:
  Fragment shader recompiled due to state change.

Draw[3]> vglinfo
OpenGL info:
  GLvendor    = 'Intel'
  GLdevice    = 'Intel(R) HD Graphics 2500'
  GLversion   = '4.0.0 - Build 10.18.10.3496'
  GLSLversion = '4.00 - Build 10.18.10.3496'
  GLdebug     =  ON

Draw[4]> vfps
FPS: 13.251066348761087
CPU: 0.46800300000001016 msec

Now you have some reference to compare your figures with.

Shockwave's picture

with the integrated intel HD 4000

Draw[6]> vglinfo
OpenGL info:
GLvendor = 'Intel'
GLdevice = 'Intel(R) HD Graphics 4000'
GLversion = '4.0.0 - Build 10.18.10.3308'
GLSversion = '4.00 - Build 10.18.10.3308'
GLdebug = ON

Draw[7]> vfps
FPS: 25.355400361316079
CPU: 0.46875 msec

With the NVIDIA 720m

Draw[6]> vglinfo
OpenGL info:
GLvendor = 'NVIDIA Corporation'
GLdevice = 'GeForce GT 720M/PCIe/SSE2'
GLversion = '4.4.0'
GLSversion = '4.40 NVIDIA via CG compiler'
GLdebug = ON

Draw[7]> vfps
FPS: 9.3194306227965331
CPU: 83.28125 msec

It seem that the integrated intel HD 4000 is better than the NVIDIA 720m is it right?

Kirill Gavrilov's picture

It seem that the integrated intel HD 4000 is better than the NVIDIA 720m is it right?

Yes, low-end graphics from AMD (but not in their APUs) and NVIDIA has worst characteristics and does not inherit GPU architecture improvements of their bigger brothers for years (being renamed to new "family numbers" from really older chips each year).

Although this does not mean that Intel HD 4000 would lead in all use cases!

High CPU time on NVIDIA card also indicates that GLSL program is most likely not executed entirely on GPU due to driver bugs or hardware limitations (such limitation might be determined by close analysis, but it does not mean that code can be (easily) improved to workaround such limitations).

Shockwave's picture

running the same sample with an intel HD 3000 I can't finish the raytracing test because of a crash of the Draw.exe

Do you have some other benchmark with some graphic card where the raytracing works well to understand which are the minimal requirements for AMD or NVIDIA cards?

Kirill Gavrilov's picture

running the same sample with an intel HD 3000 I can't finish the raytracing test because of a crash of the Draw.exe

Please make sure you have recent drivers - Intel drivers are known to be extremely buggy. Although new problems regularly occurs after upgrade...

Shockwave's picture

I have installed the last driver for this processor.

Kirill Gavrilov's picture

If you've observed FPE exceptions in Draw - this is known issue (unfortunately appears often on Intel OpenGL drivers and software Mesa LLVM renderer with GLSL):
http://tracker.dev.opencascade.org/view.php?id=24589

Otherwise - could you please provide stack trace / error message?

Sergey Slyadnev's picture

I think that "source samples/tcl/bottle.tcl" should be changed with "source samples/tcl/raytrace.tcl" in the description of OCCT ray tracing above. The "bottle.tcl" seems to use simple shading.

Andrey BETENEV's picture

Ok, done