0024739: TKOpenGl - port ray-tracing from OpenCL to GLSL for better integration and...
[occt.git] / src / OpenGl / OpenGl_SceneGeometry.hxx
... / ...
CommitLineData
1// Created on: 2013-08-27
2// Created by: Denis BOGOLEPOV
3// Copyright (c) 2013-2014 OPEN CASCADE SAS
4//
5// This file is part of Open CASCADE Technology software library.
6//
7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
12//
13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
15
16#ifndef _OpenGl_SceneGeometry_Header
17#define _OpenGl_SceneGeometry_Header
18
19#include <BVH_Geometry.hxx>
20#include <BVH_Triangulation.hxx>
21#include <NCollection_StdAllocator.hxx>
22#include <OpenGl_PrimitiveArray.hxx>
23#include <OpenGl_Structure.hxx>
24
25namespace OpenGl_Raytrace
26{
27 //! Checks to see if the group contains ray-trace geometry.
28 Standard_Boolean IsRaytracedGroup (const OpenGl_Group* theGroup);
29
30 //! Checks to see if the element contains ray-trace geometry.
31 Standard_Boolean IsRaytracedElement (const OpenGl_ElementNode* theNode);
32
33 //! Checks to see if the structure contains ray-trace geometry.
34 Standard_Boolean IsRaytracedStructure (const OpenGl_Structure* theStructure);
35}
36
37//! Stores properties of surface material.
38class OpenGl_RaytraceMaterial
39{
40public:
41
42 //! Ambient reflection coefficient.
43 BVH_Vec4f Ambient;
44
45 //! Diffuse reflection coefficient.
46 BVH_Vec4f Diffuse;
47
48 //! Glossy reflection coefficient.
49 BVH_Vec4f Specular;
50
51 //! Material emission.
52 BVH_Vec4f Emission;
53
54 //! Specular reflection coefficient.
55 BVH_Vec4f Reflection;
56
57 //! Specular refraction coefficient.
58 BVH_Vec4f Refraction;
59
60 //! Material transparency.
61 BVH_Vec4f Transparency;
62
63public:
64
65 //! Creates new default material.
66 OpenGl_RaytraceMaterial();
67
68 //! Creates new material with specified properties.
69 OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
70 const BVH_Vec4f& theDiffuse,
71 const BVH_Vec4f& theSpecular);
72
73 //! Creates new material with specified properties.
74 OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
75 const BVH_Vec4f& theDiffuse,
76 const BVH_Vec4f& theSpecular,
77 const BVH_Vec4f& theEmission,
78 const BVH_Vec4f& theTranspar);
79
80 //! Creates new material with specified properties.
81 OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
82 const BVH_Vec4f& theDiffuse,
83 const BVH_Vec4f& theSpecular,
84 const BVH_Vec4f& theEmission,
85 const BVH_Vec4f& theTranspar,
86 const BVH_Vec4f& theReflection,
87 const BVH_Vec4f& theRefraction);
88
89 //! Returns packed (serialized) representation of material.
90 const Standard_ShortReal* Packed()
91 {
92 return reinterpret_cast<Standard_ShortReal*> (this);
93 }
94};
95
96//! Stores properties of OpenGL light source.
97class OpenGl_RaytraceLight
98{
99public:
100
101 //! Diffuse intensity (in terms of OpenGL).
102 BVH_Vec4f Diffuse;
103
104 //! Position of light source (in terms of OpenGL).
105 BVH_Vec4f Position;
106
107public:
108
109 //! Creates new light source.
110 OpenGl_RaytraceLight (const BVH_Vec4f& theDiffuse,
111 const BVH_Vec4f& thePosition);
112
113 //! Returns packed (serialized) representation of light source.
114 const Standard_ShortReal* Packed()
115 {
116 return reinterpret_cast<Standard_ShortReal*> (this);
117 }
118};
119
120//! Triangulation of single OpenGL primitive array.
121class OpenGl_TriangleSet : public BVH_Triangulation<Standard_ShortReal, 4>
122{
123public:
124
125 BVH_Array4f Normals; //!< Array of vertex normals
126
127public:
128
129 //! Creates new OpenGL element triangulation.
130 OpenGl_TriangleSet()
131 : BVH_Triangulation<Standard_ShortReal, 4>()
132 {
133 //
134 }
135
136 //! Releases resources of OpenGL element triangulation.
137 ~OpenGl_TriangleSet()
138 {
139 //
140 }
141};
142
143//! Stores geometry of ray-tracing scene.
144class OpenGl_RaytraceGeometry : public BVH_Geometry<Standard_ShortReal, 4>
145{
146public:
147
148 //! Value of invalid offset to return in case of errors.
149 static const Standard_Integer INVALID_OFFSET = -1;
150
151public:
152
153 //! Array of properties of light sources.
154 std::vector<OpenGl_RaytraceLight,
155 NCollection_StdAllocator<OpenGl_RaytraceLight> > Sources;
156
157 //! Array of 'front' material properties.
158 std::vector<OpenGl_RaytraceMaterial,
159 NCollection_StdAllocator<OpenGl_RaytraceMaterial> > Materials;
160
161 //! Global ambient from all light sources.
162 BVH_Vec4f Ambient;
163
164public:
165
166 //! Creates uninitialized ray-tracing geometry.
167 OpenGl_RaytraceGeometry()
168 : BVH_Geometry<Standard_ShortReal, 4>(),
169 myHighLevelTreeDepth (0),
170 myBottomLevelTreeDepth (0)
171 {
172 //
173 }
174
175 //! Releases resources of ray-tracing geometry.
176 ~OpenGl_RaytraceGeometry()
177 {
178 //
179 }
180
181 //! Clears ray-tracing geometry.
182 void Clear();
183
184public:
185
186 //! Performs post-processing of high-level scene BVH.
187 Standard_Boolean ProcessAcceleration();
188
189 //! Returns offset of bottom-level BVH for given leaf node.
190 //! If the node index is not valid the function returns -1.
191 //! @note Can be used after processing acceleration structure.
192 Standard_Integer AccelerationOffset (Standard_Integer theNodeIdx);
193
194 //! Returns offset of triangulation vertices for given leaf node.
195 //! If the node index is not valid the function returns -1.
196 //! @note Can be used after processing acceleration structure.
197 Standard_Integer VerticesOffset (Standard_Integer theNodeIdx);
198
199 //! Returns offset of triangulation elements for given leaf node.
200 //! If the node index is not valid the function returns -1.
201 //! @note Can be used after processing acceleration structure.
202 Standard_Integer ElementsOffset (Standard_Integer theNodeIdx);
203
204 //! Returns triangulation data for given leaf node.
205 //! If the node index is not valid the function returns NULL.
206 //! @note Can be used after processing acceleration structure.
207 OpenGl_TriangleSet* TriangleSet (Standard_Integer theNodeIdx);
208
209 //! Returns depth of high-level scene BVH from last build.
210 Standard_Integer HighLevelTreeDepth() const
211 {
212 return myHighLevelTreeDepth;
213 }
214
215 //! Returns maximum depth of bottom-level scene BVHs from last build.
216 Standard_Integer BottomLevelTreeDepth() const
217 {
218 return myBottomLevelTreeDepth;
219 }
220
221protected:
222
223 Standard_Integer myHighLevelTreeDepth; //!< Depth of high-level scene BVH from last build
224 Standard_Integer myBottomLevelTreeDepth; //!< Maximum depth of bottom-level scene BVHs from last build
225
226};
227
228#endif