SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLOptixRaytracer.h
Go to the documentation of this file.
1 /**
2  * \file SLOptixRaytracer.h
3  * \authors Nic Dorner
4  * \date October 2019
5  * \authors Nic Dorner
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #ifdef SL_HAS_OPTIX
12 # ifndef SLOPTIXRAYTRACER_H
13 # define SLOPTIXRAYTRACER_H
14 # include <optix_types.h>
15 # include <cuda.h>
16 # include <SLOptixDefinitions.h>
17 # include <SLRaytracer.h>
18 # include <SLOptixCudaBuffer.h>
19 # include <SLMesh.h>
20 
21 class SLScene;
22 class SLSceneView;
23 class SLRay;
24 class SLMaterial;
25 class SLCamera;
26 
27 //-----------------------------------------------------------------------------
28 //! SLOptixRaytracer hold all the methods for Whitted style Ray Tracing.
29 class SLOptixRaytracer : public SLRaytracer
30 {
31 public:
32  SLOptixRaytracer();
33  ~SLOptixRaytracer() override;
34 
35  void destroy();
36 
37  // setup raytracer
38  virtual void setupOptix();
39  virtual void setupScene(SLSceneView* sv, SLAssetManager* am);
40  virtual void updateScene(SLSceneView* sv);
41 
42  void prepareImage() override;
43 
44  // ray tracer functions
47  virtual void renderImage(bool updateTextureGL) override;
48  void saveImage() override;
49 
50 protected:
51  void initCompileOptions();
52 
53  OptixModule createModule(string);
54  OptixProgramGroup createProgram(OptixProgramGroupDesc);
55  OptixPipeline createPipeline(OptixProgramGroup*, unsigned int);
56  OptixShaderBindingTable createShaderBindingTable(const SLVMesh&, const bool);
57 
58  SLOptixCudaBuffer<float4> _imageBuffer = SLOptixCudaBuffer<float4>();
59  SLOptixCudaBuffer<ortParams> _paramsBuffer = SLOptixCudaBuffer<ortParams>();
60  SLOptixCudaBuffer<ortLight> _lightBuffer = SLOptixCudaBuffer<ortLight>();
61 
62  OptixModule _cameraModule{};
63  OptixModule _shadingModule{};
64  OptixModuleCompileOptions _module_compile_options{};
65  OptixPipelineCompileOptions _pipeline_compile_options{};
66 
67  OptixTraversableHandle _handle{};
68  ortParams _params{};
69 
70  SLOptixCudaBuffer<MissSbtRecord> _missBuffer = SLOptixCudaBuffer<MissSbtRecord>();
71  SLOptixCudaBuffer<HitSbtRecord> _hitBuffer = SLOptixCudaBuffer<HitSbtRecord>();
72  SLOptixCudaBuffer<RayGenClassicSbtRecord> _rayGenClassicBuffer = SLOptixCudaBuffer<RayGenClassicSbtRecord>();
73  SLOptixCudaBuffer<RayGenDistributedSbtRecord> _rayGenDistributedBuffer = SLOptixCudaBuffer<RayGenDistributedSbtRecord>();
74 
75  OptixPipeline _pipeline{};
76 
77  OptixProgramGroup _pinhole_raygen_prog_group{};
78  OptixProgramGroup _lens_raygen_prog_group{};
79  OptixProgramGroup _orthographic_raygen_prog_group{};
80  OptixProgramGroup _radiance_miss_group{};
81  OptixProgramGroup _occlusion_miss_group{};
82  OptixProgramGroup _radiance_hit_group{};
83  OptixProgramGroup _occlusion_hit_group{};
84 
85  OptixShaderBindingTable _sbtClassic{};
86  OptixShaderBindingTable _sbtDistributed{};
87 };
88 //-----------------------------------------------------------------------------
89 # endif // SLOPTIXRAYTRACER_H
90 #endif // SL_HAS_OPTIX
bool SLbool
Definition: SL.h:175
vector< SLMesh * > SLVMesh
Definition: SLMesh.h:263
Toplevel holder of the assets meshes, materials, textures and shaders.
Active or visible camera node class.
Definition: SLCamera.h:54
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
Ray class with ray and intersection properties.
Definition: SLRay.h:40
SLRaytracer hold all the methods for Whitted style Ray Tracing.
Definition: SLRaytracer.h:57
virtual void prepareImage()
SLbool renderClassic(SLSceneView *sv)
Definition: SLRaytracer.cpp:56
SLbool renderDistrib(SLSceneView *sv)
virtual void renderImage(bool updateTextureGL)
virtual void saveImage()
Saves the current RT image as PNG image.
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69