SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLOptixDefinitions.h
Go to the documentation of this file.
1 /**
2  * \file SLOptixDefinitions.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 SLOPTIXDEFINITIONS_H
13 # define SLOPTIXDEFINITIONS_H
14 # include <vector_types.h>
15 # include <optix_types.h>
16 # include <cuda.h>
17 # include <curand_kernel.h>
18 
19 //------------------------------------------------------------------------------
20 //! Optix ray tracing sample struct
21 struct ortSamples
22 {
23  unsigned int samplesX;
24  unsigned int samplesY;
25 };
26 //------------------------------------------------------------------------------
27 //! Optix ray tracing material information struct
28 struct ortMaterial
29 {
30  float4 diffuse_color;
31  float4 ambient_color;
32  float4 specular_color;
33  float4 transmissiv_color;
34  float4 emissive_color;
35  float shininess;
36  float kr;
37  float kt;
38  float kn;
39 };
40 //------------------------------------------------------------------------------
41 //! Optix ray tracing light information struct
42 struct ortLight
43 {
44  float4 diffuse_color;
45  float4 ambient_color;
46  float4 specular_color;
47  float3 position;
48  float spotCutOffDEG;
49  float spotExponent;
50  float spotCosCut;
51  float3 spotDirWS;
52  float kc;
53  float kl;
54  float kq;
55  ortSamples samples;
56  float radius;
57 };
58 //------------------------------------------------------------------------------
59 struct ortParams
60 {
61  float4* image;
62  unsigned int width;
63  unsigned int height;
64 
65  int max_depth;
66  float scene_epsilon;
67 
68  //! 1/gamma of the renderer, applied to the image by the raygen program.
69  /*! The path tracer kernel used to hard code 0.5, i.e. a gamma of 2.0, while
70  the CPU SLPathtracer corrects with the settable gamma() property whose
71  default is 2.2. The two therefore disagreed by 6 to 9 display levels and the
72  Gamma slider could not reach the OptiX image at all. It sits outside the
73  union below because that union overlays the ray tracer's fields with the
74  path tracer's, and this one belongs to both. */
75  float oneOverGamma;
76 
77  OptixTraversableHandle handle;
78 
79  union
80  {
81  struct
82  {
83  ortLight* lights;
84  unsigned int numLights;
85  float4 globalAmbientColor;
86  };
87 
88  struct
89  {
90  unsigned int samples;
91  unsigned int seed;
92  curandState* states;
93  };
94  };
95 };
96 //------------------------------------------------------------------------------
97 //! Optix ray tracing ray type enumeration
98 enum ortRayType
99 {
100  RAY_TYPE_RADIANCE = 0,
101  RAY_TYPE_OCCLUSION = 1,
102  RAY_TYPE_COUNT
103 };
104 //------------------------------------------------------------------------------
105 //! Optix ray tracing camera info for pinhole camera
106 struct ortCamera
107 {
108  float3 eye;
109  float3 U;
110  float3 V;
111  float3 W;
112 };
113 //------------------------------------------------------------------------------
114 //! Optix ray tracing camera info for lens camera
115 struct ortLensCamera
116 {
117  ortCamera camera;
118  ortSamples samples;
119  float lensDiameter;
120 };
121 //------------------------------------------------------------------------------
122 //! Optix ray tracing intersection miss data
123 struct ortMissData
124 {
125  float4 bg_color;
126 };
127 //------------------------------------------------------------------------------
128 //! Optix ray tracing intersection hit data
129 struct ortHitData
130 {
131  ortMaterial material;
132  CUtexObject textureObject;
133  int sbtIndex;
134  float3* normals;
135  short3* indices;
136  float2* texCords;
137 };
138 //------------------------------------------------------------------------------
139 template<typename T>
140 struct SbtRecord
141 {
142  __align__(OPTIX_SBT_RECORD_ALIGNMENT) char header[OPTIX_SBT_RECORD_HEADER_SIZE];
143  T data;
144 };
145 //------------------------------------------------------------------------------
146 typedef SbtRecord<ortCamera> RayGenClassicSbtRecord;
147 typedef SbtRecord<ortLensCamera> RayGenDistributedSbtRecord;
148 typedef SbtRecord<ortMissData> MissSbtRecord;
149 typedef SbtRecord<ortHitData> HitSbtRecord;
150 //------------------------------------------------------------------------------
151 # endif // SLOPTIXDEFINITIONS_H
152 #endif // SL_HAS_OPTIX