#include <BVH_Geometry.hxx>
#include <BVH_Triangulation.hxx>
+#include <BVH_BinnedBuilder.hxx>
#include <NCollection_StdAllocator.hxx>
+#include <OpenGl_TextureBufferArb.hxx>
+#include <OpenGl_Texture.hxx>
+#include <OpenGl_Sampler.hxx>
+class OpenGl_Element;
struct OpenGl_ElementNode;
class OpenGl_Group;
class OpenGl_Structure;
//! Checks to see if the element contains ray-trace geometry.
Standard_Boolean IsRaytracedElement (const OpenGl_ElementNode* theNode);
- //! Checks to see if the structure contains ray-trace geometry.
- Standard_Boolean IsRaytracedStructure (const OpenGl_Structure* theStructure);
+ //! Checks to see if the element contains ray-trace geometry.
+ Standard_Boolean IsRaytracedElement (const OpenGl_Element* theElement);
}
//! Stores properties of surface material.
//! Material transparency.
BVH_Vec4f Transparency;
+ //! Texture transformation matrix.
+ BVH_Mat4f TextureTransform;
+
+ //! Physically-based material properties (used in path tracing engine).
+ struct Physical
+ {
+ //! Weight of coat specular/glossy BRDF.
+ BVH_Vec4f Kc;
+
+ //! Weight of base diffuse BRDF.
+ BVH_Vec4f Kd;
+
+ //! Weight of base specular/glossy BRDF.
+ BVH_Vec4f Ks;
+
+ //! Weight of base specular/glossy BTDF.
+ BVH_Vec4f Kt;
+
+ //! Radiance emitted by the surface.
+ BVH_Vec4f Le;
+
+ //! Fresnel coefficients of coat layer.
+ BVH_Vec4f FresnelCoat;
+
+ //! Fresnel coefficients of base layer.
+ BVH_Vec4f FresnelBase;
+
+ //! Absorption color/intensity.
+ BVH_Vec4f Absorption;
+
+ } BSDF;
+
public:
//! Creates new default material.
public:
//! Diffuse intensity (in terms of OpenGL).
- BVH_Vec4f Diffuse;
+ BVH_Vec4f Emission;
//! Position of light source (in terms of OpenGL).
BVH_Vec4f Position;
public:
//! Creates new light source.
- OpenGl_RaytraceLight (const BVH_Vec4f& theDiffuse,
+ OpenGl_RaytraceLight() { }
+
+ //! Creates new light source.
+ OpenGl_RaytraceLight (const BVH_Vec4f& theEmission,
const BVH_Vec4f& thePosition);
//! Returns packed (serialized) representation of light source.
}
};
+//! Shared pointer to quad BVH (QBVH) tree.
+typedef opencascade::handle<BVH_Tree<Standard_ShortReal, 3, BVH_QuadTree> > QuadBvhHandle;
+typedef BVH_Triangulation<Standard_ShortReal, 3> OpenGl_BVHTriangulation3f;
+
//! Triangulation of single OpenGL primitive array.
-class OpenGl_TriangleSet : public BVH_Triangulation<Standard_ShortReal, 4>
+class OpenGl_TriangleSet : public OpenGl_BVHTriangulation3f
{
+ DEFINE_STANDARD_RTTIEXT(OpenGl_TriangleSet, OpenGl_BVHTriangulation3f)
public:
//! Value of invalid material index to return in case of errors.
public:
//! Creates new OpenGL element triangulation.
- OpenGl_TriangleSet (const OpenGl_PrimitiveArray* theArray = NULL)
- : BVH_Triangulation<Standard_ShortReal, 4>(),
- myArray (theArray)
- {
- //
- }
-
- //! Releases resources of OpenGL element triangulation.
- ~OpenGl_TriangleSet()
- {
- //
- }
+ OpenGl_TriangleSet (const Standard_Size theArrayID,
+ const opencascade::handle<BVH_Builder<Standard_ShortReal, 3> >& theBuilder);
- //! Returns associated OpenGl structure.
- const OpenGl_PrimitiveArray* AssociatedPArray() const
+ //! Returns ID of associated primitive array.
+ Standard_Size AssociatedPArrayID() const
{
- return myArray;
+ return myArrayID;
}
//! Returns material index of triangle set.
Standard_Integer MaterialIndex() const
{
if (Elements.size() == 0)
+ {
return INVALID_MATERIAL;
+ }
return Elements.front().w();
}
//! Sets material index for entire triangle set.
- void SetMaterialIndex (Standard_Integer aMatID)
+ void SetMaterialIndex (Standard_Integer theMatID)
{
for (Standard_Size anIdx = 0; anIdx < Elements.size(); ++anIdx)
- Elements[anIdx].w() = aMatID;
- }
-
- //! Returns AABB of primitive set.
- BVH_BoxNt Box() const
- {
- const BVH_Transform<Standard_ShortReal, 4>* aTransform =
- dynamic_cast<const BVH_Transform<Standard_ShortReal, 4>* > (Properties().operator->());
-
- BVH_BoxNt aBox = BVH_PrimitiveSet<Standard_ShortReal, 4>::Box();
-
- if (aTransform)
{
- return aTransform->Apply (aBox);
+ Elements[anIdx].w() = theMatID;
}
-
- return aBox;
}
+ //! Returns AABB of primitive set.
+ virtual BVH_BoxNt Box() const Standard_OVERRIDE;
+
+ //! Returns AABB of the given object.
+ using BVH_Triangulation<Standard_ShortReal, 3>::Box;
+
+ //! Returns centroid position along the given axis.
+ virtual Standard_ShortReal Center (const Standard_Integer theIndex, const Standard_Integer theAxis) const Standard_OVERRIDE;
+
+ //! Returns quad BVH (QBVH) tree produced from binary BVH.
+ const QuadBvhHandle& QuadBVH();
+
public:
- BVH_Array4f Normals; //!< Array of vertex normals.
-
+ BVH_Array3f Normals; //!< Array of vertex normals.
+ BVH_Array2f TexCrds; //!< Array of texture coords.
+
private:
- const OpenGl_PrimitiveArray* myArray; //!< Reference to associated OpenGl structure.
+ Standard_Size myArrayID; //!< ID of associated primitive array.
+
+ QuadBvhHandle myQuadBVH; //!< QBVH produced from binary BVH tree.
};
//! Stores geometry of ray-tracing scene.
-class OpenGl_RaytraceGeometry : public BVH_Geometry<Standard_ShortReal, 4>
+class OpenGl_RaytraceGeometry : public BVH_Geometry<Standard_ShortReal, 3>
{
public:
//! Value of invalid offset to return in case of errors.
static const Standard_Integer INVALID_OFFSET = -1;
+ //! Maximum number of textures used in ray-tracing shaders.
+ //! This is not restriction of the solution implemented, but
+ //! rather the reasonable limit of the number of textures in
+ //! various applications (can be increased if needed).
+ static const Standard_Integer MAX_TEX_NUMBER = 32;
+
public:
//! Array of properties of light sources.
//! Creates uninitialized ray-tracing geometry.
OpenGl_RaytraceGeometry()
- : BVH_Geometry<Standard_ShortReal, 4>(),
- myHighLevelTreeDepth (0),
- myBottomLevelTreeDepth (0)
+ : BVH_Geometry<Standard_ShortReal, 3>(),
+ myTopLevelTreeDepth (0),
+ myBotLevelTreeDepth (0)
{
//
}
//
}
- //! Clears ray-tracing geometry.
- void Clear();
-
//! Clears only ray-tracing materials.
void ClearMaterials()
{
std::vector<OpenGl_RaytraceMaterial,
NCollection_StdAllocator<OpenGl_RaytraceMaterial> > anEmptyMaterials;
-
+
Materials.swap (anEmptyMaterials);
+
+ myTextures.Clear();
}
-public:
+ //! Clears ray-tracing geometry.
+ virtual void Clear() Standard_OVERRIDE;
+
+public: //! @name methods related to acceleration structure
//! Performs post-processing of high-level scene BVH.
Standard_Boolean ProcessAcceleration();
//! @note Can be used after processing acceleration structure.
OpenGl_TriangleSet* TriangleSet (Standard_Integer theNodeIdx);
- //! Returns depth of high-level scene BVH from last build.
- Standard_Integer HighLevelTreeDepth() const
+ //! Returns quad BVH (QBVH) tree produced from binary BVH.
+ const QuadBvhHandle& QuadBVH();
+
+public: //! @name methods related to texture management
+
+ //! Checks if scene contains textured objects.
+ Standard_Boolean HasTextures() const
{
- return myHighLevelTreeDepth;
+ return !myTextures.IsEmpty();
+ }
+
+ //! Adds new OpenGL texture to the scene and returns its index.
+ Standard_Integer AddTexture (const Handle(OpenGl_Texture)& theTexture);
+
+ //! Updates unique 64-bit texture handles to use in shaders.
+ Standard_Boolean UpdateTextureHandles (const Handle(OpenGl_Context)& theContext);
+
+ //! Makes the OpenGL texture handles resident (must be called before using).
+ Standard_Boolean AcquireTextures (const Handle(OpenGl_Context)& theContext);
+
+ //! Makes the OpenGL texture handles non-resident (must be called after using).
+ Standard_Boolean ReleaseTextures (const Handle(OpenGl_Context)& theContext) const;
+
+ //! Returns array of texture handles.
+ const std::vector<GLuint64>& TextureHandles() const
+ {
+ return myTextureHandles;
+ }
+
+ //! Releases OpenGL resources.
+ void ReleaseResources (const Handle(OpenGl_Context)& )
+ {
+ //
+ }
+
+public: //! @name auxiliary methods
+
+ //! Returns depth of top-level scene BVH from last build.
+ Standard_Integer TopLevelTreeDepth() const
+ {
+ return myTopLevelTreeDepth;
}
//! Returns maximum depth of bottom-level scene BVHs from last build.
- Standard_Integer BottomLevelTreeDepth() const
+ Standard_Integer BotLevelTreeDepth() const
{
- return myBottomLevelTreeDepth;
+ return myBotLevelTreeDepth;
}
protected:
- Standard_Integer myHighLevelTreeDepth; //!< Depth of high-level scene BVH from last build
- Standard_Integer myBottomLevelTreeDepth; //!< Maximum depth of bottom-level scene BVHs from last build
+ NCollection_Vector<Handle(OpenGl_Texture)> myTextures; //!< Array of texture maps shared between rendered objects
+ std::vector<GLuint64> myTextureHandles; //!< Array of unique 64-bit texture handles obtained from OpenGL
+ Standard_Integer myTopLevelTreeDepth; //!< Depth of high-level scene BVH from last build
+ Standard_Integer myBotLevelTreeDepth; //!< Maximum depth of bottom-level scene BVHs from last build
+
+ QuadBvhHandle myQuadBVH; //!< QBVH produced from binary BVH tree.
};