mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-05 18:16:23 +03:00
0024503: TKOpenGl - Porting ray-tracing component on BVH package
Updated test case v3d/raytrace/bug24130. The new version checks correctness of shadows.
This commit is contained in:
parent
05d7de534a
commit
265d4508bd
@ -92,13 +92,8 @@ void BVH_Geometry<T, N>::Update()
|
||||
return;
|
||||
}
|
||||
|
||||
BVH_Box<T, N> aBox;
|
||||
for (Standard_Integer anIndex = 0; anIndex < BVH_ObjectSet<T, N>::myObjects.Size(); ++anIndex)
|
||||
{
|
||||
aBox.Combine (BVH_ObjectSet<T, N>::myObjects.Value (anIndex)->Box());
|
||||
}
|
||||
myBuilder->Build (this, myBVH.operator->(), Box());
|
||||
|
||||
myBuilder->Build (this, myBVH.operator->(), aBox);
|
||||
myIsDirty = Standard_False;
|
||||
}
|
||||
|
||||
|
@ -133,11 +133,8 @@ Handle_OpenGl_ShaderObject.hxx
|
||||
Handle_OpenGl_ShaderProgram.hxx
|
||||
Handle_OpenGl_ShaderManager.hxx
|
||||
OpenGl_Cl.hxx
|
||||
OpenGl_AABB.hxx
|
||||
OpenGl_AABB.cxx
|
||||
OpenGl_SceneGeometry.hxx
|
||||
OpenGl_SceneGeometry.cxx
|
||||
OpenGl_RaytraceTypes.hxx
|
||||
OpenGl_RaytraceSource.cxx
|
||||
OpenGl_Workspace_Raytrace.cxx
|
||||
OpenGl_Flipper.hxx
|
||||
|
@ -1,132 +0,0 @@
|
||||
// Created on: 2013-08-27
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and / or modify it
|
||||
// under the terms of the GNU Lesser General Public version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
#include <Standard_ShortReal.hxx>
|
||||
|
||||
#include <OpenGl_AABB.hxx>
|
||||
|
||||
|
||||
OpenGl_AABB::OpenGl_AABB() : myMinPoint(),
|
||||
myMaxPoint(),
|
||||
myIsValid (false)
|
||||
{ }
|
||||
|
||||
OpenGl_AABB::OpenGl_AABB (const OpenGl_RTVec4f& thePoint) : myMinPoint (thePoint),
|
||||
myMaxPoint (thePoint),
|
||||
myIsValid (true)
|
||||
{ }
|
||||
|
||||
OpenGl_AABB::OpenGl_AABB (const OpenGl_RTVec4f& theMinPoint,
|
||||
const OpenGl_RTVec4f& theMaxPoint) : myMinPoint (theMinPoint),
|
||||
myMaxPoint (theMaxPoint),
|
||||
myIsValid (true)
|
||||
{ }
|
||||
|
||||
OpenGl_AABB::OpenGl_AABB (const OpenGl_AABB& theVolume) : myMinPoint (theVolume.myMinPoint),
|
||||
myMaxPoint (theVolume.myMaxPoint),
|
||||
myIsValid (theVolume.myIsValid)
|
||||
{ }
|
||||
|
||||
void OpenGl_AABB::Add (const OpenGl_RTVec4f& thePoint)
|
||||
{
|
||||
if (!myIsValid)
|
||||
{
|
||||
myMinPoint = thePoint;
|
||||
myMaxPoint = thePoint;
|
||||
myIsValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
myMinPoint = OpenGl_RTVec4f (Min (myMinPoint.x(), thePoint.x()),
|
||||
Min (myMinPoint.y(), thePoint.y()),
|
||||
Min (myMinPoint.z(), thePoint.z()),
|
||||
1.f);
|
||||
|
||||
myMaxPoint = OpenGl_RTVec4f (Max (myMaxPoint.x(), thePoint.x()),
|
||||
Max (myMaxPoint.y(), thePoint.y()),
|
||||
Max (myMaxPoint.z(), thePoint.z()),
|
||||
1.f);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGl_AABB::Combine (const OpenGl_AABB& theVolume)
|
||||
{
|
||||
if (!theVolume.myIsValid)
|
||||
return;
|
||||
|
||||
if (!myIsValid)
|
||||
{
|
||||
myMinPoint = theVolume.myMinPoint;
|
||||
myMaxPoint = theVolume.myMaxPoint;
|
||||
myIsValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
myMinPoint = OpenGl_RTVec4f (Min (myMinPoint.x(), theVolume.myMinPoint.x()),
|
||||
Min (myMinPoint.y(), theVolume.myMinPoint.y()),
|
||||
Min (myMinPoint.z(), theVolume.myMinPoint.z()),
|
||||
1.f);
|
||||
|
||||
myMaxPoint = OpenGl_RTVec4f (Max (myMaxPoint.x(), theVolume.myMaxPoint.x()),
|
||||
Max (myMaxPoint.y(), theVolume.myMaxPoint.y()),
|
||||
Max (myMaxPoint.z(), theVolume.myMaxPoint.z()),
|
||||
1.f);
|
||||
}
|
||||
}
|
||||
|
||||
OpenGl_AABB OpenGl_AABB::Added (const OpenGl_RTVec4f& thePoint) const
|
||||
{
|
||||
OpenGl_AABB result (*this);
|
||||
|
||||
result.Add (thePoint);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
OpenGl_AABB OpenGl_AABB::Combined (const OpenGl_AABB& theVolume) const
|
||||
{
|
||||
OpenGl_AABB result (*this);
|
||||
|
||||
result.Combine (theVolume);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void OpenGl_AABB::Clear()
|
||||
{
|
||||
myIsValid = false;
|
||||
}
|
||||
|
||||
OpenGl_RTVec4f OpenGl_AABB::Size() const
|
||||
{
|
||||
return myMaxPoint - myMinPoint;
|
||||
}
|
||||
|
||||
float OpenGl_AABB::Area() const
|
||||
{
|
||||
const float aXLen = myMaxPoint.x() - myMinPoint.x();
|
||||
const float aYLen = myMaxPoint.y() - myMinPoint.y();
|
||||
const float aZLen = myMaxPoint.z() - myMinPoint.z();
|
||||
|
||||
return ( aXLen * aYLen + aXLen * aZLen + aZLen * aYLen ) * 2.f;
|
||||
}
|
||||
|
||||
#endif
|
@ -1,83 +0,0 @@
|
||||
// Created on: 2013-08-27
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and / or modify it
|
||||
// under the terms of the GNU Lesser General Public version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _OpenGl_AABB_Header
|
||||
#define _OpenGl_AABB_Header
|
||||
|
||||
#include <OpenGl_RaytraceTypes.hxx>
|
||||
|
||||
|
||||
//! Axis aligned bounding box (AABB).
|
||||
class OpenGl_AABB
|
||||
{
|
||||
public:
|
||||
|
||||
//! Creates default (invalid) bounding volume.
|
||||
OpenGl_AABB();
|
||||
|
||||
//! Creates bounding volume of given point.
|
||||
OpenGl_AABB (const OpenGl_RTVec4f& thePoint);
|
||||
|
||||
//! Creates copy of another bounding volume.
|
||||
OpenGl_AABB (const OpenGl_AABB& theVolume);
|
||||
|
||||
//! Creates bounding volume from min and max points.
|
||||
OpenGl_AABB (const OpenGl_RTVec4f& theMinPoint,
|
||||
const OpenGl_RTVec4f& theMaxPoint);
|
||||
|
||||
//! Is object represents uninitialized volume?
|
||||
bool IsVoid() const { return !myIsValid; }
|
||||
|
||||
//! Appends new point to the volume.
|
||||
void Add (const OpenGl_RTVec4f& theVector);
|
||||
//! Combines the volume with another volume.
|
||||
void Combine (const OpenGl_AABB& theVolume);
|
||||
|
||||
//! Returns new volume created by appending a point to current volume.
|
||||
OpenGl_AABB Added (const OpenGl_RTVec4f& thePoint) const;
|
||||
//! Returns new volume created by combining with specified volume.
|
||||
OpenGl_AABB Combined (const OpenGl_AABB& theVolume) const;
|
||||
|
||||
//! Clears bounding volume (makes object invalid).
|
||||
void Clear();
|
||||
|
||||
//! Evaluates surface area of bounding volume.
|
||||
float Area() const;
|
||||
|
||||
//! Return diagonal of bounding volume.
|
||||
OpenGl_RTVec4f Size() const;
|
||||
|
||||
//! Returns minimum point of bounding volume.
|
||||
const OpenGl_RTVec4f& CornerMin() const { return myMinPoint; }
|
||||
//! Returns maximum point of bounding volume.
|
||||
const OpenGl_RTVec4f& CornerMax() const { return myMaxPoint; }
|
||||
|
||||
//! Returns minimum point of bounding volume.
|
||||
OpenGl_RTVec4f& CornerMin() { return myMinPoint; }
|
||||
//! Returns maximum point of bounding volume.
|
||||
OpenGl_RTVec4f& CornerMax() { return myMaxPoint; }
|
||||
|
||||
private:
|
||||
|
||||
//! Minimum point of bounding volume.
|
||||
OpenGl_RTVec4f myMinPoint;
|
||||
//! Maximum point of bounding volume.
|
||||
OpenGl_RTVec4f myMaxPoint;
|
||||
|
||||
//! Is bounding volume valid (up to date)?
|
||||
bool myIsValid;
|
||||
};
|
||||
|
||||
#endif
|
@ -1257,7 +1257,7 @@ void OpenGl_Context::ReleaseDelayed()
|
||||
myReleaseQueue->Pop();
|
||||
}
|
||||
|
||||
// release delayed shared resoruces
|
||||
// release delayed shared resources
|
||||
NCollection_Vector<TCollection_AsciiString> aDeadList;
|
||||
for (NCollection_DataMap<TCollection_AsciiString, Standard_Integer>::Iterator anIter (*myDelayed);
|
||||
anIter.More(); anIter.Next())
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,41 +0,0 @@
|
||||
// Created on: 2013-10-15
|
||||
// Created by: Denis BOGOLEPOV
|
||||
// Copyright (c) 2013 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of Open CASCADE Technology software library.
|
||||
//
|
||||
// This library is free software; you can redistribute it and / or modify it
|
||||
// under the terms of the GNU Lesser General Public version 2.1 as published
|
||||
// by the Free Software Foundation, with special exception defined in the file
|
||||
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
|
||||
// distribution for complete text of the license and disclaimer of any warranty.
|
||||
//
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
#ifndef _OpenGl_RaytraceTypes_Header
|
||||
#define _OpenGl_RaytraceTypes_Header
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <NCollection_Vec4.hxx>
|
||||
#include <NCollection_StdAllocator.hxx>
|
||||
|
||||
//! 4D vector of integers.
|
||||
typedef NCollection_Vec4<int> OpenGl_RTVec4i;
|
||||
|
||||
//! 4D vector of floats.
|
||||
typedef NCollection_Vec4<float> OpenGl_RTVec4f;
|
||||
|
||||
//! 4D vector of doubles.
|
||||
typedef NCollection_Vec4<double> OpenGl_RTVec4d;
|
||||
|
||||
//! Array of 4D integer vectors.
|
||||
typedef std::vector<OpenGl_RTVec4i,
|
||||
NCollection_StdAllocator<OpenGl_RTVec4i> > OpenGl_RTArray4i;
|
||||
|
||||
//! Array of 4D floating point vectors.
|
||||
typedef std::vector<OpenGl_RTVec4f,
|
||||
NCollection_StdAllocator<OpenGl_RTVec4f> > OpenGl_RTArray4f;
|
||||
|
||||
#endif
|
@ -19,25 +19,25 @@
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
#include <limits>
|
||||
#include <Standard_Assert.hxx>
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
#include <tbb/tbb.h>
|
||||
#endif
|
||||
|
||||
#include <OpenGl_SceneGeometry.hxx>
|
||||
|
||||
//! Use this macro to output BVH profiling info
|
||||
//#define BVH_PRINT_INFO
|
||||
|
||||
#ifdef BVH_PRINT_INFO
|
||||
#include <OSD_Timer.hxx>
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
//! Number of node bins per axis.
|
||||
static const int THE_NUMBER_OF_BINS = 32;
|
||||
|
||||
//! Max number of triangles per leaf node.
|
||||
static const int THE_MAX_LEAF_TRIANGLES = 4;
|
||||
|
||||
//! Useful constant for null integer 4D vector.
|
||||
static const OpenGl_RTVec4i THE_ZERO_VEC_4I;
|
||||
|
||||
//! Useful constant for null floating-point 4D vector.
|
||||
static const OpenGl_RTVec4f THE_ZERO_VEC_4F;
|
||||
|
||||
static const BVH_Vec4f ZERO_VEC_4F;
|
||||
};
|
||||
|
||||
// =======================================================================
|
||||
@ -45,29 +45,29 @@ namespace
|
||||
// purpose : Creates new default material
|
||||
// =======================================================================
|
||||
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial()
|
||||
: Ambient (THE_ZERO_VEC_4F),
|
||||
Diffuse (THE_ZERO_VEC_4F),
|
||||
Specular (THE_ZERO_VEC_4F),
|
||||
Emission (THE_ZERO_VEC_4F),
|
||||
Reflection (THE_ZERO_VEC_4F),
|
||||
Refraction (THE_ZERO_VEC_4F),
|
||||
Transparency (THE_ZERO_VEC_4F)
|
||||
: Ambient (ZERO_VEC_4F),
|
||||
Diffuse (ZERO_VEC_4F),
|
||||
Specular (ZERO_VEC_4F),
|
||||
Emission (ZERO_VEC_4F),
|
||||
Reflection (ZERO_VEC_4F),
|
||||
Refraction (ZERO_VEC_4F),
|
||||
Transparency (ZERO_VEC_4F)
|
||||
{ }
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_RaytraceMaterial
|
||||
// purpose : Creates new material with specified properties
|
||||
// =======================================================================
|
||||
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,
|
||||
const OpenGl_RTVec4f& theDiffuse,
|
||||
const OpenGl_RTVec4f& theSpecular)
|
||||
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
|
||||
const BVH_Vec4f& theDiffuse,
|
||||
const BVH_Vec4f& theSpecular)
|
||||
: Ambient (theAmbient),
|
||||
Diffuse (theDiffuse),
|
||||
Specular (theSpecular),
|
||||
Emission (THE_ZERO_VEC_4F),
|
||||
Reflection (THE_ZERO_VEC_4F),
|
||||
Refraction (THE_ZERO_VEC_4F),
|
||||
Transparency (THE_ZERO_VEC_4F)
|
||||
Emission (ZERO_VEC_4F),
|
||||
Reflection (ZERO_VEC_4F),
|
||||
Refraction (ZERO_VEC_4F),
|
||||
Transparency (ZERO_VEC_4F)
|
||||
{
|
||||
//
|
||||
}
|
||||
@ -76,17 +76,17 @@ OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbie
|
||||
// function : OpenGl_RaytraceMaterial
|
||||
// purpose : Creates new material with specified properties
|
||||
// =======================================================================
|
||||
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,
|
||||
const OpenGl_RTVec4f& theDiffuse,
|
||||
const OpenGl_RTVec4f& theSpecular,
|
||||
const OpenGl_RTVec4f& theEmission,
|
||||
const OpenGl_RTVec4f& theTranspar)
|
||||
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
|
||||
const BVH_Vec4f& theDiffuse,
|
||||
const BVH_Vec4f& theSpecular,
|
||||
const BVH_Vec4f& theEmission,
|
||||
const BVH_Vec4f& theTranspar)
|
||||
: Ambient (theAmbient),
|
||||
Diffuse (theDiffuse),
|
||||
Specular (theSpecular),
|
||||
Emission (theEmission),
|
||||
Reflection (THE_ZERO_VEC_4F),
|
||||
Refraction (THE_ZERO_VEC_4F),
|
||||
Reflection (ZERO_VEC_4F),
|
||||
Refraction (ZERO_VEC_4F),
|
||||
Transparency (theTranspar)
|
||||
{
|
||||
//
|
||||
@ -96,13 +96,13 @@ OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbie
|
||||
// function : OpenGl_RaytraceMaterial
|
||||
// purpose : Creates new material with specified properties
|
||||
// =======================================================================
|
||||
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,
|
||||
const OpenGl_RTVec4f& theDiffuse,
|
||||
const OpenGl_RTVec4f& theSpecular,
|
||||
const OpenGl_RTVec4f& theEmission,
|
||||
const OpenGl_RTVec4f& theTranspar,
|
||||
const OpenGl_RTVec4f& theReflection,
|
||||
const OpenGl_RTVec4f& theRefraction)
|
||||
OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
|
||||
const BVH_Vec4f& theDiffuse,
|
||||
const BVH_Vec4f& theSpecular,
|
||||
const BVH_Vec4f& theEmission,
|
||||
const BVH_Vec4f& theTranspar,
|
||||
const BVH_Vec4f& theReflection,
|
||||
const BVH_Vec4f& theRefraction)
|
||||
: Ambient (theAmbient),
|
||||
Diffuse (theDiffuse),
|
||||
Specular (theSpecular),
|
||||
@ -118,87 +118,26 @@ OpenGl_RaytraceMaterial::OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbie
|
||||
// function : OpenGl_LightSource
|
||||
// purpose : Creates new light source
|
||||
// =======================================================================
|
||||
OpenGl_RaytraceLight::OpenGl_RaytraceLight (const OpenGl_RTVec4f& theAmbient)
|
||||
: Ambient (theAmbient)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_LightSource
|
||||
// purpose : Creates new light source
|
||||
// =======================================================================
|
||||
OpenGl_RaytraceLight::OpenGl_RaytraceLight (const OpenGl_RTVec4f& theDiffuse,
|
||||
const OpenGl_RTVec4f& thePosition)
|
||||
OpenGl_RaytraceLight::OpenGl_RaytraceLight (const BVH_Vec4f& theDiffuse,
|
||||
const BVH_Vec4f& thePosition)
|
||||
: Diffuse (theDiffuse),
|
||||
Position (thePosition)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Center
|
||||
// purpose : Returns centroid of specified triangle
|
||||
// =======================================================================
|
||||
OpenGl_RTVec4f OpenGl_RaytraceScene::Center (const int theTriangle) const
|
||||
{
|
||||
const OpenGl_RTVec4i& anIndex = Triangles [theTriangle];
|
||||
|
||||
return ( Vertices[anIndex.x()] +
|
||||
Vertices[anIndex.y()] +
|
||||
Vertices[anIndex.z()] ) * ( 1.f / 3.f );
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : CenterAxis
|
||||
// purpose : Returns centroid of specified triangle
|
||||
// =======================================================================
|
||||
float OpenGl_RaytraceScene::CenterAxis (const int theTriangle,
|
||||
const int theAxis) const
|
||||
{
|
||||
const OpenGl_RTVec4i& anIndex = Triangles [theTriangle];
|
||||
|
||||
return ( Vertices[anIndex.x()][theAxis] +
|
||||
Vertices[anIndex.y()][theAxis] +
|
||||
Vertices[anIndex.z()][theAxis] ) * ( 1.f / 3.f );
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Box
|
||||
// purpose : Returns AABB of specified triangle
|
||||
// =======================================================================
|
||||
OpenGl_AABB OpenGl_RaytraceScene::Box (const int theTriangle) const
|
||||
{
|
||||
const OpenGl_RTVec4i& anIndex = Triangles[theTriangle];
|
||||
|
||||
const OpenGl_RTVec4f& pA = Vertices[anIndex.x()];
|
||||
const OpenGl_RTVec4f& pB = Vertices[anIndex.y()];
|
||||
const OpenGl_RTVec4f& pC = Vertices[anIndex.z()];
|
||||
|
||||
OpenGl_AABB aBox (pA);
|
||||
|
||||
aBox.Add (pB);
|
||||
aBox.Add (pC);
|
||||
|
||||
return aBox;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Clear
|
||||
// purpose : Clears all scene geometry data
|
||||
// purpose : Clears ray-tracing geometry
|
||||
// =======================================================================
|
||||
void OpenGl_RaytraceScene::Clear()
|
||||
void OpenGl_RaytraceGeometry::Clear()
|
||||
{
|
||||
AABB.Clear();
|
||||
BVH_Geometry<Standard_ShortReal, 4>::BVH_Geometry::Clear();
|
||||
|
||||
OpenGl_RTArray4f anEmptyNormals;
|
||||
Normals.swap (anEmptyNormals);
|
||||
std::vector<OpenGl_RaytraceLight,
|
||||
NCollection_StdAllocator<OpenGl_RaytraceLight> > anEmptySources;
|
||||
|
||||
OpenGl_RTArray4f anEmptyVertices;
|
||||
Vertices.swap (anEmptyVertices);
|
||||
|
||||
OpenGl_RTArray4i anEmptyTriangles;
|
||||
Triangles.swap (anEmptyTriangles);
|
||||
Sources.swap (anEmptySources);
|
||||
|
||||
std::vector<OpenGl_RaytraceMaterial,
|
||||
NCollection_StdAllocator<OpenGl_RaytraceMaterial> > anEmptyMaterials;
|
||||
@ -206,499 +145,187 @@ void OpenGl_RaytraceScene::Clear()
|
||||
Materials.swap (anEmptyMaterials);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_Node
|
||||
// purpose : Creates new empty BVH node
|
||||
// =======================================================================
|
||||
OpenGl_BVHNode::OpenGl_BVHNode()
|
||||
: myMinPoint (THE_ZERO_VEC_4F),
|
||||
myMaxPoint (THE_ZERO_VEC_4F),
|
||||
myDataRcrd (THE_ZERO_VEC_4I)
|
||||
#ifdef HAVE_TBB
|
||||
|
||||
struct OpenGL_BVHParallelBuilder
|
||||
{
|
||||
BVH_ObjectSet<Standard_ShortReal, 4>* Set;
|
||||
|
||||
OpenGL_BVHParallelBuilder (BVH_ObjectSet<Standard_ShortReal, 4>* theSet)
|
||||
: Set (theSet)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_Node
|
||||
// purpose : Creates new BVH node with specified data
|
||||
// =======================================================================
|
||||
OpenGl_BVHNode::OpenGl_BVHNode (const OpenGl_RTVec4f& theMinPoint,
|
||||
const OpenGl_RTVec4f& theMaxPoint,
|
||||
const OpenGl_RTVec4i& theDataRcrd)
|
||||
: myMinPoint (theMinPoint),
|
||||
myMaxPoint (theMaxPoint),
|
||||
myDataRcrd (theDataRcrd)
|
||||
void operator() (const tbb::blocked_range<size_t>& theRange) const
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_Node
|
||||
// purpose : Creates new leaf BVH node with specified data
|
||||
// =======================================================================
|
||||
OpenGl_BVHNode::OpenGl_BVHNode (const OpenGl_AABB& theAABB,
|
||||
const int theBegTriangle,
|
||||
const int theEndTriangle)
|
||||
: myMinPoint (theAABB.CornerMin()),
|
||||
myMaxPoint (theAABB.CornerMax()),
|
||||
myDataRcrd (1,
|
||||
theBegTriangle,
|
||||
theEndTriangle,
|
||||
0)
|
||||
for (size_t anObjectIdx = theRange.begin(); anObjectIdx != theRange.end(); ++anObjectIdx)
|
||||
{
|
||||
//
|
||||
}
|
||||
OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
|
||||
Set->Objects().ChangeValue (static_cast<Standard_Integer> (anObjectIdx)).operator->());
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_Node
|
||||
// purpose : Creates new leaf BVH node with specified data
|
||||
// =======================================================================
|
||||
OpenGl_BVHNode::OpenGl_BVHNode (const OpenGl_RTVec4f& theMinPoint,
|
||||
const OpenGl_RTVec4f& theMaxPoint,
|
||||
const int theBegTriangle,
|
||||
const int theEndTriangle)
|
||||
: myMinPoint (theMinPoint),
|
||||
myMaxPoint (theMaxPoint),
|
||||
myDataRcrd (1,
|
||||
theBegTriangle,
|
||||
theEndTriangle,
|
||||
0)
|
||||
if (aTriangleSet != NULL)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : CleanUp
|
||||
// purpose : Removes all tree nodes
|
||||
// =======================================================================
|
||||
void OpenGl_BVH::CleanUp()
|
||||
{
|
||||
OpenGl_RTArray4f anEmptyMinPointBuffer;
|
||||
myMinPointBuffer.swap (anEmptyMinPointBuffer);
|
||||
|
||||
OpenGl_RTArray4f anEmptyMaxPointBuffer;
|
||||
myMaxPointBuffer.swap (anEmptyMaxPointBuffer);
|
||||
|
||||
OpenGl_RTArray4i anEmptyDataRcrdBuffer;
|
||||
myDataRcrdBuffer.swap (anEmptyDataRcrdBuffer);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Node
|
||||
// purpose : Returns node with specified index
|
||||
// =======================================================================
|
||||
OpenGl_BVHNode OpenGl_BVH::Node (const int theIndex) const
|
||||
{
|
||||
return OpenGl_BVHNode (myMinPointBuffer[theIndex],
|
||||
myMaxPointBuffer[theIndex],
|
||||
myDataRcrdBuffer[theIndex]);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetNode
|
||||
// purpose : Replaces node with specified index
|
||||
// =======================================================================
|
||||
void OpenGl_BVH::SetNode (const int theIndex,
|
||||
const OpenGl_BVHNode& theNode)
|
||||
{
|
||||
if (theIndex < static_cast<int> (myMinPointBuffer.size()))
|
||||
{
|
||||
myMinPointBuffer[theIndex] = theNode.myMinPoint;
|
||||
myMaxPointBuffer[theIndex] = theNode.myMaxPoint;
|
||||
myDataRcrdBuffer[theIndex] = theNode.myDataRcrd;
|
||||
aTriangleSet->BVH();
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : PushNode
|
||||
// purpose : Adds new node to the tree
|
||||
// =======================================================================
|
||||
int OpenGl_BVH::PushNode (const OpenGl_BVHNode& theNode)
|
||||
{
|
||||
myMinPointBuffer.push_back (theNode.myMinPoint);
|
||||
myMaxPointBuffer.push_back (theNode.myMaxPoint);
|
||||
myDataRcrdBuffer.push_back (theNode.myDataRcrd);
|
||||
return static_cast<int> (myDataRcrdBuffer.size() - 1);
|
||||
}
|
||||
};
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_NodeBuildTask
|
||||
// purpose : Creates new node building task
|
||||
// =======================================================================
|
||||
OpenGl_BVHNodeTask::OpenGl_BVHNodeTask()
|
||||
: NodeToBuild (0),
|
||||
BegTriangle (0),
|
||||
EndTriangle (0)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_NodeBuildTask
|
||||
// purpose : Creates new node building task
|
||||
// =======================================================================
|
||||
OpenGl_BVHNodeTask::OpenGl_BVHNodeTask (const int theNodeToBuild,
|
||||
const int theBegTriangle,
|
||||
const int theEndTriangle)
|
||||
: NodeToBuild (theNodeToBuild),
|
||||
BegTriangle (theBegTriangle),
|
||||
EndTriangle (theEndTriangle)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : OpenGl_BinnedBVHBuilder
|
||||
// purpose : Creates new binned BVH builder
|
||||
// =======================================================================
|
||||
OpenGl_BinnedBVHBuilder::OpenGl_BinnedBVHBuilder()
|
||||
: myMaxDepth (30)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : ~OpenGl_BinnedBVHBuilder
|
||||
// purpose : Releases binned BVH builder
|
||||
// =======================================================================
|
||||
OpenGl_BinnedBVHBuilder::~OpenGl_BinnedBVHBuilder()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
#define BVH_DEBUG_OUTPUT_
|
||||
|
||||
#if defined( BVH_DEBUG_OUTPUT )
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
// =======================================================================
|
||||
// function : ReinterpretIntAsFloat
|
||||
// purpose : Reinterprets bits of integer value as floating-point value
|
||||
// function : ProcessAcceleration
|
||||
// purpose : Performs post-processing of high-level BVH
|
||||
// =======================================================================
|
||||
inline float ReinterpretIntAsFloat (int theValue)
|
||||
Standard_Boolean OpenGl_RaytraceGeometry::ProcessAcceleration()
|
||||
{
|
||||
return *reinterpret_cast< float* > (&theValue);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Build
|
||||
// purpose : Builds BVH tree using binned SAH algorithm
|
||||
// =======================================================================
|
||||
void OpenGl_BinnedBVHBuilder::Build (OpenGl_RaytraceScene& theGeometry,
|
||||
const float theEpsilon)
|
||||
{
|
||||
CleanUp();
|
||||
|
||||
#ifdef BVH_DEBUG_OUTPUT
|
||||
std::cout << "Start building BVH..." << std::endl;
|
||||
|
||||
std::cout << "Triangles: " << theGeometry.Triangles.size() << std::endl;
|
||||
#ifdef BVH_PRINT_INFO
|
||||
OSD_Timer aTimer;
|
||||
#endif
|
||||
|
||||
if (theGeometry.Triangles.size() == 0)
|
||||
return;
|
||||
MarkDirty(); // force BVH rebuilding
|
||||
|
||||
// Create root node with all scene triangles
|
||||
OpenGl_AABB anAABB = theGeometry.AABB;
|
||||
anAABB.CornerMin() = OpenGl_RTVec4f (anAABB.CornerMin().x() - theEpsilon,
|
||||
anAABB.CornerMin().y() - theEpsilon,
|
||||
anAABB.CornerMin().z() - theEpsilon,
|
||||
1.0f);
|
||||
anAABB.CornerMax() = OpenGl_RTVec4f (anAABB.CornerMax().x() + theEpsilon,
|
||||
anAABB.CornerMax().y() + theEpsilon,
|
||||
anAABB.CornerMax().z() + theEpsilon,
|
||||
1.0f);
|
||||
myTree.PushNode (OpenGl_BVHNode (anAABB, 0, static_cast<int> (theGeometry.Triangles.size() - 1)));
|
||||
|
||||
#ifdef BVH_DEBUG_OUTPUT
|
||||
std::cout << "Push root node: [" << 0 << ", " <<
|
||||
theGeometry.Triangles.size() - 1 << "]" << std::endl;
|
||||
#ifdef BVH_PRINT_INFO
|
||||
aTimer.Reset();
|
||||
aTimer.Start();
|
||||
#endif
|
||||
|
||||
// Setup splitting task for the root node
|
||||
myNodeTasksQueue.push_back (OpenGl_BVHNodeTask (0, 0, static_cast<int> (theGeometry.Triangles.size() - 1)));
|
||||
|
||||
// Building nodes while tasks queue is not empty
|
||||
for (int aTaskId = 0; aTaskId < static_cast<int> (myNodeTasksQueue.size()); ++aTaskId)
|
||||
{
|
||||
BuildNode (theGeometry, aTaskId);
|
||||
}
|
||||
|
||||
// Write support data to optimize traverse
|
||||
for (int aNode = 0; aNode < static_cast<int> (myTree.DataRcrdBuffer().size()); ++aNode)
|
||||
{
|
||||
OpenGl_RTVec4i aData = myTree.DataRcrdBuffer()[aNode];
|
||||
myTree.MinPointBuffer()[aNode].w() = ReinterpretIntAsFloat (aData[0] ? aData[1] : -aData[1]);
|
||||
myTree.MaxPointBuffer()[aNode].w() = ReinterpretIntAsFloat (aData[0] ? aData[2] : -aData[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : CleanUp
|
||||
// purpose : Clears previously built tree
|
||||
// =======================================================================
|
||||
void OpenGl_BinnedBVHBuilder::CleanUp()
|
||||
{
|
||||
myTree.CleanUp();
|
||||
myNodeTasksQueue.clear();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SetMaxDepth
|
||||
// purpose : Sets maximum tree depth
|
||||
// =======================================================================
|
||||
void OpenGl_BinnedBVHBuilder::SetMaxDepth (const int theMaxDepth)
|
||||
{
|
||||
if (theMaxDepth > 1 && theMaxDepth < 30)
|
||||
{
|
||||
myMaxDepth = theMaxDepth - 1;
|
||||
}
|
||||
}
|
||||
|
||||
//! Minimum node size to split.
|
||||
static const float THE_NODE_MIN_SIZE = 1e-4f;
|
||||
|
||||
// =======================================================================
|
||||
// function : BuildNode
|
||||
// purpose : Builds node using task info
|
||||
// =======================================================================
|
||||
void OpenGl_BinnedBVHBuilder::BuildNode (OpenGl_RaytraceScene& theGeometry,
|
||||
const int theTask)
|
||||
{
|
||||
OpenGl_BVHNodeTask aTask = myNodeTasksQueue[theTask];
|
||||
OpenGl_BVHNode aNode = myTree.Node (aTask.NodeToBuild);
|
||||
|
||||
#ifdef BVH_DEBUG_OUTPUT
|
||||
std::cout << "Build node " << aTask.NodeToBuild << ": [" <<
|
||||
aTask.BegTriangle << ", " << aTask.EndTriangle << "]" << std::endl;
|
||||
#ifdef HAVE_TBB
|
||||
// If Intel TBB is available, perform the preliminary
|
||||
// construction of bottom-level scene BVHs
|
||||
tbb::parallel_for (tbb::blocked_range<size_t> (0, Size()),
|
||||
OpenGL_BVHParallelBuilder (this));
|
||||
#endif
|
||||
|
||||
OpenGl_AABB anAABB (aNode.MinPoint(), aNode.MaxPoint());
|
||||
const OpenGl_RTVec4f aNodeSize = anAABB.Size();
|
||||
const float aNodeArea = anAABB.Area();
|
||||
|
||||
// Parameters for storing best split
|
||||
float aMinSplitCost = std::numeric_limits<float>::max();
|
||||
|
||||
int aMinSplitAxis = -1;
|
||||
int aMinSplitIndex = 0;
|
||||
int aMinSplitLftCount = 0;
|
||||
int aMinSplitRghCount = 0;
|
||||
|
||||
OpenGl_AABB aMinSplitLftAABB;
|
||||
OpenGl_AABB aMinSplitRghAABB;
|
||||
|
||||
// Find best split
|
||||
for (int anAxis = 0; anAxis < 3; ++anAxis)
|
||||
for (Standard_Integer anObjectIdx = 0; anObjectIdx < Size(); ++anObjectIdx)
|
||||
{
|
||||
if (aNodeSize[anAxis] <= THE_NODE_MIN_SIZE)
|
||||
OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
|
||||
myObjects.ChangeValue (anObjectIdx).operator->());
|
||||
|
||||
Standard_ASSERT_RETURN (aTriangleSet != NULL,
|
||||
"Error! Failed to get triangulation of OpenGL element", Standard_False);
|
||||
|
||||
Standard_ASSERT_RETURN (!aTriangleSet->BVH().IsNull(),
|
||||
"Error! Failed to update bottom-level BVH of OpenGL element", Standard_False);
|
||||
}
|
||||
|
||||
#ifdef BVH_PRINT_INFO
|
||||
aTimer.Stop();
|
||||
|
||||
std::cout << "Updating bottom-level BVHs (sec): " <<
|
||||
aTimer.ElapsedTime() << std::endl;
|
||||
#endif
|
||||
|
||||
#ifdef BVH_PRINT_INFO
|
||||
aTimer.Reset();
|
||||
aTimer.Start();
|
||||
#endif
|
||||
|
||||
NCollection_Handle<BVH_Tree<Standard_ShortReal, 4> > aBVH = BVH();
|
||||
|
||||
#ifdef BVH_PRINT_INFO
|
||||
aTimer.Stop();
|
||||
|
||||
std::cout << "Updating high-level BVH (sec): " <<
|
||||
aTimer.ElapsedTime() << std::endl;
|
||||
#endif
|
||||
|
||||
Standard_ASSERT_RETURN (!aBVH.IsNull(),
|
||||
"Error! Failed to update high-level BVH of ray-tracing scene", Standard_False);
|
||||
|
||||
Standard_Integer aVerticesOffset = 0;
|
||||
Standard_Integer aElementsOffset = 0;
|
||||
Standard_Integer aBVHNodesOffset = 0;
|
||||
|
||||
for (Standard_Integer aNodeIdx = 0; aNodeIdx < aBVH->Length(); ++aNodeIdx)
|
||||
{
|
||||
if (!aBVH->IsOuter (aNodeIdx))
|
||||
continue;
|
||||
|
||||
OpenGl_BinVector aBins (THE_NUMBER_OF_BINS);
|
||||
GetSubVolumes (theGeometry, aNode, aBins, anAxis);
|
||||
Standard_ASSERT_RETURN (aBVH->BegPrimitive (aNodeIdx) == aBVH->EndPrimitive (aNodeIdx),
|
||||
"Error! Invalid leaf node in high-level BVH (contains several objects)", Standard_False);
|
||||
|
||||
// Choose the best split (with minimum SAH cost)
|
||||
for (int aSplit = 1; aSplit < THE_NUMBER_OF_BINS; ++aSplit)
|
||||
{
|
||||
int aLftCount = 0;
|
||||
int aRghCount = 0;
|
||||
OpenGl_AABB aLftAABB;
|
||||
OpenGl_AABB aRghAABB;
|
||||
for (int anIndex = 0; anIndex < aSplit; ++anIndex)
|
||||
{
|
||||
aLftCount += aBins[anIndex].Count;
|
||||
aLftAABB.Combine (aBins[anIndex].Volume);
|
||||
Standard_Integer anObjectIdx = aBVH->BegPrimitive (aNodeIdx);
|
||||
|
||||
Standard_ASSERT_RETURN (anObjectIdx < myObjects.Size(),
|
||||
"Error! Invalid leaf node in high-level BVH (contains out-of-range object)", Standard_False);
|
||||
|
||||
OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
|
||||
myObjects.ChangeValue (anObjectIdx).operator->());
|
||||
|
||||
// Note: We overwrite node info record to store parameters
|
||||
// of bottom-level BVH and triangulation of OpenGL element
|
||||
|
||||
aBVH->NodeInfoBuffer().at (aNodeIdx) = BVH_Vec4i (
|
||||
anObjectIdx + 1 /* to keep leaf flag */, aBVHNodesOffset, aVerticesOffset, aElementsOffset);
|
||||
|
||||
aVerticesOffset += aTriangleSet->Vertices.size();
|
||||
aElementsOffset += aTriangleSet->Elements.size();
|
||||
aBVHNodesOffset += aTriangleSet->BVH()->Length();
|
||||
}
|
||||
|
||||
for (int anIndex = aSplit; anIndex < THE_NUMBER_OF_BINS; ++anIndex)
|
||||
{
|
||||
aRghCount += aBins[anIndex].Count;
|
||||
aRghAABB.Combine (aBins[anIndex].Volume);
|
||||
}
|
||||
|
||||
// Simple SAH evaluation
|
||||
float aCost = ( aLftAABB.Area() / aNodeArea ) * aLftCount +
|
||||
( aRghAABB.Area() / aNodeArea ) * aRghCount;
|
||||
|
||||
#ifdef BVH_DEBUG_OUTPUT
|
||||
std::cout << "\t\tBin " << aSplit << ", Cost = " << aCost << std::endl;
|
||||
#endif
|
||||
|
||||
if (aCost <= aMinSplitCost)
|
||||
{
|
||||
aMinSplitCost = aCost;
|
||||
aMinSplitAxis = anAxis;
|
||||
aMinSplitIndex = aSplit;
|
||||
aMinSplitLftAABB = aLftAABB;
|
||||
aMinSplitRghAABB = aRghAABB;
|
||||
aMinSplitLftCount = aLftCount;
|
||||
aMinSplitRghCount = aRghCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (aMinSplitAxis == -1)
|
||||
{
|
||||
// make outer (leaf) node
|
||||
myTree.DataRcrdBuffer()[aTask.NodeToBuild].x() = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BVH_DEBUG_OUTPUT
|
||||
switch (aMinSplitAxis)
|
||||
{
|
||||
case 0:
|
||||
std::cout << "\tSplit axis: X = " << aMinSplitIndex << std::endl;
|
||||
break;
|
||||
case 1:
|
||||
std::cout << "\tSplit axis: Y = " << aMinSplitIndex << std::endl;
|
||||
break;
|
||||
case 2:
|
||||
std::cout << "\tSplit axis: Z = " << aMinSplitIndex << std::endl;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
int aMiddle = SplitTriangles (theGeometry, aTask.BegTriangle, aTask.EndTriangle,
|
||||
aNode, aMinSplitIndex - 1, aMinSplitAxis);
|
||||
|
||||
#ifdef BVH_DEBUG_OUTPUT
|
||||
std::cout << "\tLeft child: [" << aTask.BegTriangle << ", "
|
||||
<< aMiddle - 1 << "]" << std::endl;
|
||||
|
||||
std::cout << "\tRight child: [" << aMiddle << ", "
|
||||
<< aTask.EndTriangle << "]" << std::endl;
|
||||
#endif
|
||||
|
||||
#define BVH_SIDE_LFT 1
|
||||
#define BVH_SIDE_RGH 2
|
||||
|
||||
// Setting up tasks for child nodes
|
||||
for (int aSide = BVH_SIDE_LFT; aSide <= BVH_SIDE_RGH; ++aSide)
|
||||
{
|
||||
OpenGl_RTVec4f aMinPoint = (aSide == BVH_SIDE_LFT)
|
||||
? aMinSplitLftAABB.CornerMin()
|
||||
: aMinSplitRghAABB.CornerMin();
|
||||
OpenGl_RTVec4f aMaxPoint = (aSide == BVH_SIDE_LFT)
|
||||
? aMinSplitLftAABB.CornerMax()
|
||||
: aMinSplitRghAABB.CornerMax();
|
||||
|
||||
int aBegTriangle = (aSide == BVH_SIDE_LFT)
|
||||
? aTask.BegTriangle
|
||||
: aMiddle;
|
||||
int aEndTriangle = (aSide == BVH_SIDE_LFT)
|
||||
? aMiddle - 1
|
||||
: aTask.EndTriangle;
|
||||
|
||||
OpenGl_BVHNode aChild (aMinPoint, aMaxPoint, aBegTriangle, aEndTriangle);
|
||||
aChild.SetLevel (aNode.Level() + 1);
|
||||
|
||||
// Check to see if child node must be split
|
||||
const int aNbTriangles = (aSide == BVH_SIDE_LFT)
|
||||
? aMinSplitLftCount
|
||||
: aMinSplitRghCount;
|
||||
|
||||
const int isChildALeaf = (aNbTriangles <= THE_MAX_LEAF_TRIANGLES) || (aNode.Level() >= myMaxDepth);
|
||||
if (isChildALeaf)
|
||||
aChild.SetOuter();
|
||||
else
|
||||
aChild.SetInner();
|
||||
|
||||
const int aChildIndex = myTree.PushNode (aChild);
|
||||
|
||||
// Modify parent node
|
||||
myTree.DataRcrdBuffer()[aTask.NodeToBuild].x() = 0; // inner node flag
|
||||
if (aSide == BVH_SIDE_LFT)
|
||||
myTree.DataRcrdBuffer()[aTask.NodeToBuild].y() = aChildIndex; // left child
|
||||
else
|
||||
myTree.DataRcrdBuffer()[aTask.NodeToBuild].z() = aChildIndex; // right child
|
||||
|
||||
// Make new building task
|
||||
if (!isChildALeaf)
|
||||
myNodeTasksQueue.push_back (OpenGl_BVHNodeTask (aChildIndex, aBegTriangle, aEndTriangle));
|
||||
}
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : SplitTriangles
|
||||
// purpose : Splits node triangles into two intervals for child nodes
|
||||
// function : AccelerationOffset
|
||||
// purpose : Returns offset of bottom-level BVH for given leaf node
|
||||
// =======================================================================
|
||||
int OpenGl_BinnedBVHBuilder::SplitTriangles (OpenGl_RaytraceScene& theGeometry,
|
||||
const int theBegTriangle,
|
||||
const int theEndTriangle,
|
||||
OpenGl_BVHNode& theNode,
|
||||
int theBin,
|
||||
const int theAxis)
|
||||
Standard_Integer OpenGl_RaytraceGeometry::AccelerationOffset (Standard_Integer theNodeIdx)
|
||||
{
|
||||
int aLftIndex (theBegTriangle);
|
||||
int aRghIndex (theEndTriangle);
|
||||
const NCollection_Handle<BVH_Tree<Standard_ShortReal, 4> >& aBVH = BVH();
|
||||
|
||||
const float aMin = theNode.MinPoint()[theAxis];
|
||||
const float aMax = theNode.MaxPoint()[theAxis];
|
||||
if (theNodeIdx >= aBVH->Length() || !aBVH->IsOuter (theNodeIdx))
|
||||
return INVALID_OFFSET;
|
||||
|
||||
const float aStep = (aMax - aMin) / THE_NUMBER_OF_BINS;
|
||||
|
||||
do
|
||||
{
|
||||
while ((int )floorf ((theGeometry.CenterAxis (aLftIndex, theAxis) - aMin) / aStep) <= theBin
|
||||
&& aLftIndex < theEndTriangle)
|
||||
{
|
||||
++aLftIndex;
|
||||
}
|
||||
while ((int )floorf ((theGeometry.CenterAxis (aRghIndex, theAxis) - aMin) / aStep) > theBin
|
||||
&& aRghIndex > theBegTriangle)
|
||||
{
|
||||
--aRghIndex;
|
||||
}
|
||||
|
||||
if (aLftIndex <= aRghIndex)
|
||||
{
|
||||
if (aLftIndex != aRghIndex)
|
||||
{
|
||||
OpenGl_RTVec4i aLftTrg = theGeometry.Triangles[aLftIndex];
|
||||
OpenGl_RTVec4i aRghTrg = theGeometry.Triangles[aRghIndex];
|
||||
theGeometry.Triangles[aLftIndex] = aRghTrg;
|
||||
theGeometry.Triangles[aRghIndex] = aLftTrg;
|
||||
}
|
||||
|
||||
aLftIndex++; aRghIndex--;
|
||||
}
|
||||
} while (aLftIndex <= aRghIndex);
|
||||
|
||||
return aLftIndex;
|
||||
return aBVH->NodeInfoBuffer().at (theNodeIdx).y();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : GetSubVolumes
|
||||
// purpose : Arranges node triangles into bins
|
||||
// function : VerticesOffset
|
||||
// purpose : Returns offset of triangulation vertices for given leaf node
|
||||
// =======================================================================
|
||||
void OpenGl_BinnedBVHBuilder::GetSubVolumes (OpenGl_RaytraceScene& theGeometry,
|
||||
const OpenGl_BVHNode& theNode,
|
||||
OpenGl_BinVector& theBins,
|
||||
const int theAxis)
|
||||
Standard_Integer OpenGl_RaytraceGeometry::VerticesOffset (Standard_Integer theNodeIdx)
|
||||
{
|
||||
const float aMin = theNode.MinPoint()[theAxis];
|
||||
const float aMax = theNode.MaxPoint()[theAxis];
|
||||
const NCollection_Handle<BVH_Tree<Standard_ShortReal, 4> >& aBVH = BVH();
|
||||
|
||||
const float aStep = (aMax - aMin) / THE_NUMBER_OF_BINS;
|
||||
if (theNodeIdx >= aBVH->Length() || !aBVH->IsOuter (theNodeIdx))
|
||||
return INVALID_OFFSET;
|
||||
|
||||
for (int aTri = theNode.BegTriangle(); aTri <= theNode.EndTriangle(); ++aTri)
|
||||
{
|
||||
float aCenter = theGeometry.CenterAxis (aTri, theAxis);
|
||||
int aBinIndex = (int )floorf ((aCenter - aMin) * ( 1.0f / aStep));
|
||||
if (aBinIndex < 0)
|
||||
{
|
||||
aBinIndex = 0;
|
||||
}
|
||||
else if (aBinIndex >= THE_NUMBER_OF_BINS)
|
||||
{
|
||||
aBinIndex = THE_NUMBER_OF_BINS - 1;
|
||||
return aBVH->NodeInfoBuffer().at (theNodeIdx).z();
|
||||
}
|
||||
|
||||
theBins[aBinIndex].Count++;
|
||||
theBins[aBinIndex].Volume.Combine (theGeometry.Box (aTri));
|
||||
// =======================================================================
|
||||
// function : ElementsOffset
|
||||
// purpose : Returns offset of triangulation elements for given leaf node
|
||||
// =======================================================================
|
||||
Standard_Integer OpenGl_RaytraceGeometry::ElementsOffset (Standard_Integer theNodeIdx)
|
||||
{
|
||||
const NCollection_Handle<BVH_Tree<Standard_ShortReal, 4> >& aBVH = BVH();
|
||||
|
||||
if (theNodeIdx >= aBVH->Length() || !aBVH->IsOuter (theNodeIdx))
|
||||
return INVALID_OFFSET;
|
||||
|
||||
return aBVH->NodeInfoBuffer().at (theNodeIdx).w();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : TriangleSet
|
||||
// purpose : Returns triangulation data for given leaf node
|
||||
// =======================================================================
|
||||
OpenGl_TriangleSet* OpenGl_RaytraceGeometry::TriangleSet (Standard_Integer theNodeIdx)
|
||||
{
|
||||
const NCollection_Handle<BVH_Tree<Standard_ShortReal, 4> >& aBVH = BVH();
|
||||
|
||||
if (theNodeIdx >= aBVH->Length() || !aBVH->IsOuter (theNodeIdx))
|
||||
return NULL;
|
||||
|
||||
if (aBVH->NodeInfoBuffer().at (theNodeIdx).x() > myObjects.Size())
|
||||
return NULL;
|
||||
|
||||
return dynamic_cast<OpenGl_TriangleSet*> (myObjects.ChangeValue (
|
||||
aBVH->NodeInfoBuffer().at (theNodeIdx).x() - 1).operator->());
|
||||
}
|
||||
|
||||
namespace OpenGl_Raytrace
|
||||
|
@ -18,9 +18,11 @@
|
||||
|
||||
#ifdef HAVE_OPENCL
|
||||
|
||||
#include <OpenGl_AABB.hxx>
|
||||
#include <OpenGl_Structure.hxx>
|
||||
#include <BVH_Geometry.hxx>
|
||||
#include <BVH_Triangulation.hxx>
|
||||
#include <NCollection_StdAllocator.hxx>
|
||||
#include <OpenGl_PrimitiveArray.hxx>
|
||||
#include <OpenGl_Structure.hxx>
|
||||
|
||||
namespace OpenGl_Raytrace
|
||||
{
|
||||
@ -40,25 +42,25 @@ class OpenGl_RaytraceMaterial
|
||||
public:
|
||||
|
||||
//! Ambient reflection coefficient.
|
||||
OpenGl_RTVec4f Ambient;
|
||||
BVH_Vec4f Ambient;
|
||||
|
||||
//! Diffuse reflection coefficient.
|
||||
OpenGl_RTVec4f Diffuse;
|
||||
BVH_Vec4f Diffuse;
|
||||
|
||||
//! Glossy reflection coefficient.
|
||||
OpenGl_RTVec4f Specular;
|
||||
BVH_Vec4f Specular;
|
||||
|
||||
//! Material emission.
|
||||
OpenGl_RTVec4f Emission;
|
||||
BVH_Vec4f Emission;
|
||||
|
||||
//! Specular reflection coefficient.
|
||||
OpenGl_RTVec4f Reflection;
|
||||
BVH_Vec4f Reflection;
|
||||
|
||||
//! Specular refraction coefficient.
|
||||
OpenGl_RTVec4f Refraction;
|
||||
BVH_Vec4f Refraction;
|
||||
|
||||
//! Material transparency.
|
||||
OpenGl_RTVec4f Transparency;
|
||||
BVH_Vec4f Transparency;
|
||||
|
||||
public:
|
||||
|
||||
@ -66,28 +68,31 @@ public:
|
||||
OpenGl_RaytraceMaterial();
|
||||
|
||||
//! Creates new material with specified properties.
|
||||
OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,
|
||||
const OpenGl_RTVec4f& theDiffuse,
|
||||
const OpenGl_RTVec4f& theSpecular);
|
||||
OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
|
||||
const BVH_Vec4f& theDiffuse,
|
||||
const BVH_Vec4f& theSpecular);
|
||||
|
||||
//! Creates new material with specified properties.
|
||||
OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,
|
||||
const OpenGl_RTVec4f& theDiffuse,
|
||||
const OpenGl_RTVec4f& theSpecular,
|
||||
const OpenGl_RTVec4f& theEmission,
|
||||
const OpenGl_RTVec4f& theTranspar);
|
||||
OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
|
||||
const BVH_Vec4f& theDiffuse,
|
||||
const BVH_Vec4f& theSpecular,
|
||||
const BVH_Vec4f& theEmission,
|
||||
const BVH_Vec4f& theTranspar);
|
||||
|
||||
//! Creates new material with specified properties.
|
||||
OpenGl_RaytraceMaterial (const OpenGl_RTVec4f& theAmbient,
|
||||
const OpenGl_RTVec4f& theDiffuse,
|
||||
const OpenGl_RTVec4f& theSpecular,
|
||||
const OpenGl_RTVec4f& theEmission,
|
||||
const OpenGl_RTVec4f& theTranspar,
|
||||
const OpenGl_RTVec4f& theReflection,
|
||||
const OpenGl_RTVec4f& theRefraction);
|
||||
OpenGl_RaytraceMaterial (const BVH_Vec4f& theAmbient,
|
||||
const BVH_Vec4f& theDiffuse,
|
||||
const BVH_Vec4f& theSpecular,
|
||||
const BVH_Vec4f& theEmission,
|
||||
const BVH_Vec4f& theTranspar,
|
||||
const BVH_Vec4f& theReflection,
|
||||
const BVH_Vec4f& theRefraction);
|
||||
|
||||
//! Returns packed (serialized) representation of material.
|
||||
const float* Packed() { return reinterpret_cast<float*> (this); }
|
||||
const Standard_ShortReal* Packed()
|
||||
{
|
||||
return reinterpret_cast<Standard_ShortReal*> (this);
|
||||
}
|
||||
};
|
||||
|
||||
//! Stores properties of OpenGL light source.
|
||||
@ -95,261 +100,110 @@ class OpenGl_RaytraceLight
|
||||
{
|
||||
public:
|
||||
|
||||
//! 'Ambient' intensity.
|
||||
OpenGl_RTVec4f Ambient;
|
||||
|
||||
//! 'Diffuse' intensity.
|
||||
OpenGl_RTVec4f Diffuse;
|
||||
//! Diffuse intensity (in terms of OpenGL).
|
||||
BVH_Vec4f Diffuse;
|
||||
|
||||
//! Position of light source (in terms of OpenGL).
|
||||
OpenGl_RTVec4f Position;
|
||||
|
||||
BVH_Vec4f Position;
|
||||
|
||||
public:
|
||||
|
||||
//! Creates new light source.
|
||||
OpenGl_RaytraceLight (const OpenGl_RTVec4f& theAmbient);
|
||||
|
||||
//! Creates new light source.
|
||||
OpenGl_RaytraceLight (const OpenGl_RTVec4f& theDiffuse,
|
||||
const OpenGl_RTVec4f& thePosition);
|
||||
OpenGl_RaytraceLight (const BVH_Vec4f& theDiffuse,
|
||||
const BVH_Vec4f& thePosition);
|
||||
|
||||
//! Returns packed (serialized) representation of light source.
|
||||
const float* Packed() { return reinterpret_cast<float*> (this); }
|
||||
const Standard_ShortReal* Packed()
|
||||
{
|
||||
return reinterpret_cast<Standard_ShortReal*> (this);
|
||||
}
|
||||
};
|
||||
|
||||
//! Stores scene geometry data.
|
||||
struct OpenGl_RaytraceScene
|
||||
//! Triangulation of single OpenGL primitive array.
|
||||
class OpenGl_TriangleSet : public BVH_Triangulation<Standard_ShortReal, 4>
|
||||
{
|
||||
//! AABB of 3D scene.
|
||||
OpenGl_AABB AABB;
|
||||
public:
|
||||
|
||||
//! Array of vertex normals.
|
||||
OpenGl_RTArray4f Normals;
|
||||
BVH_Array4f Normals;
|
||||
|
||||
//! Array of vertex coordinates.
|
||||
OpenGl_RTArray4f Vertices;
|
||||
public:
|
||||
|
||||
//! Array of scene triangles.
|
||||
OpenGl_RTArray4i Triangles;
|
||||
//! Creates new OpenGL element triangulation.
|
||||
OpenGl_TriangleSet()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//! Releases resources of OpenGL element triangulation.
|
||||
~OpenGl_TriangleSet()
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
||||
|
||||
//! Stores geometry of ray-tracing scene.
|
||||
class OpenGl_RaytraceGeometry : public BVH_Geometry<Standard_ShortReal, 4>
|
||||
{
|
||||
public:
|
||||
|
||||
//! Value of invalid offset to return in case of errors.
|
||||
static const Standard_Integer INVALID_OFFSET = -1;
|
||||
|
||||
public:
|
||||
|
||||
//! Array of properties of light sources.
|
||||
std::vector<OpenGl_RaytraceLight,
|
||||
NCollection_StdAllocator<OpenGl_RaytraceLight> > Sources;
|
||||
|
||||
//! Array of 'front' material properties.
|
||||
std::vector<OpenGl_RaytraceMaterial,
|
||||
NCollection_StdAllocator<OpenGl_RaytraceMaterial> > Materials;
|
||||
|
||||
//! Array of properties of light sources.
|
||||
std::vector<OpenGl_RaytraceLight,
|
||||
NCollection_StdAllocator<OpenGl_RaytraceLight> > LightSources;
|
||||
//! Global ambient from all light sources.
|
||||
BVH_Vec4f GlobalAmbient;
|
||||
|
||||
//! Clears all scene geometry and material data.
|
||||
public:
|
||||
|
||||
//! Creates uninitialized ray-tracing geometry.
|
||||
OpenGl_RaytraceGeometry()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//! Releases resources of ray-tracing geometry.
|
||||
~OpenGl_RaytraceGeometry()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//! Clears ray-tracing geometry.
|
||||
void Clear();
|
||||
|
||||
//! Returns AABB of specified triangle.
|
||||
OpenGl_AABB Box (const int theTriangle) const;
|
||||
|
||||
//! Returns centroid of specified triangle.
|
||||
OpenGl_RTVec4f Center (const int theTriangle) const;
|
||||
|
||||
//! Returns centroid coordinate for specified axis.
|
||||
float CenterAxis (const int theTriangle, const int theAxis) const;
|
||||
};
|
||||
|
||||
//! Stores parameters of BVH tree node.
|
||||
class OpenGl_BVHNode
|
||||
{
|
||||
friend class OpenGl_BVH;
|
||||
|
||||
public:
|
||||
|
||||
//! Creates new empty BVH node.
|
||||
OpenGl_BVHNode();
|
||||
//! Performs post-processing of high-level scene BVH.
|
||||
Standard_Boolean ProcessAcceleration();
|
||||
|
||||
//! Creates new BVH node with specified data.
|
||||
OpenGl_BVHNode (const OpenGl_RTVec4f& theMinPoint,
|
||||
const OpenGl_RTVec4f& theMaxPoint,
|
||||
const OpenGl_RTVec4i& theDataRcrd);
|
||||
//! Returns offset of bottom-level BVH for given leaf node.
|
||||
//! If the node index is not valid the function returns -1.
|
||||
//! @note Can be used after processing acceleration structure.
|
||||
Standard_Integer AccelerationOffset (Standard_Integer theNodeIdx);
|
||||
|
||||
//! Creates new leaf BVH node with specified data.
|
||||
OpenGl_BVHNode (const OpenGl_RTVec4f& theMinPoint,
|
||||
const OpenGl_RTVec4f& theMaxPoint,
|
||||
const int theBegTriangle,
|
||||
const int theEndTriangle);
|
||||
//! Returns offset of triangulation vertices for given leaf node.
|
||||
//! If the node index is not valid the function returns -1.
|
||||
//! @note Can be used after processing acceleration structure.
|
||||
Standard_Integer VerticesOffset (Standard_Integer theNodeIdx);
|
||||
|
||||
//! Creates new leaf BVH node with specified data.
|
||||
OpenGl_BVHNode (const OpenGl_AABB& theAABB,
|
||||
const int theBegTriangle,
|
||||
const int theEndTriangle);
|
||||
//! Returns offset of triangulation elements for given leaf node.
|
||||
//! If the node index is not valid the function returns -1.
|
||||
//! @note Can be used after processing acceleration structure.
|
||||
Standard_Integer ElementsOffset (Standard_Integer theNodeIdx);
|
||||
|
||||
//! Returns minimum point of node's AABB.
|
||||
OpenGl_RTVec4f& MinPoint() { return myMinPoint; }
|
||||
//! Returns maximum point of node's AABB.
|
||||
OpenGl_RTVec4f& MaxPoint() { return myMaxPoint; }
|
||||
|
||||
//! Returns minimum point of node's AABB.
|
||||
const OpenGl_RTVec4f& MinPoint() const { return myMinPoint; }
|
||||
//! Returns maximum point of node's AABB.
|
||||
const OpenGl_RTVec4f& MaxPoint() const { return myMaxPoint; }
|
||||
|
||||
//! Returns index of left child of inner node.
|
||||
int LeftChild() const { return myDataRcrd.y(); }
|
||||
//! Sets index of left child of inner node.
|
||||
void SetLeftChild (int theChild) { myDataRcrd.y() = theChild; }
|
||||
|
||||
//! Returns index of right child of inner node.
|
||||
int RightChild() const { return myDataRcrd.z(); }
|
||||
//! Sets index of right child of inner node.
|
||||
void SetRightChild (int theChild) { myDataRcrd.z() = theChild; }
|
||||
|
||||
//! Returns index of begin triangle of leaf node.
|
||||
int BegTriangle() const { return myDataRcrd.y(); }
|
||||
//! Sets index of begin triangle of leaf node.
|
||||
void SetBegTriangle (int theIndex) { myDataRcrd.y() = theIndex; }
|
||||
|
||||
//! Returns index of end triangle of leaf node.
|
||||
int EndTriangle() const { return myDataRcrd.z(); }
|
||||
//! Sets index of end triangle of leaf node.
|
||||
void SetEndTriangle (int theIndex) { myDataRcrd.z() = theIndex; }
|
||||
|
||||
//! Returns level of the node in BVH tree.
|
||||
int Level() const { return myDataRcrd.w(); }
|
||||
//! Sets level of the node in BVH tree.
|
||||
void SetLevel (int theLevel) { myDataRcrd.w() = theLevel; }
|
||||
|
||||
//! Is node a leaf (outer)?
|
||||
bool IsOuter() const { return myDataRcrd.x() == 1; }
|
||||
|
||||
//! Sets node type to 'outer'.
|
||||
void SetOuter() { myDataRcrd.x() = 1; }
|
||||
//! Sets node type to 'inner'.
|
||||
void SetInner() { myDataRcrd.x() = 0; }
|
||||
|
||||
private:
|
||||
|
||||
//! Minimum point of node's bounding box.
|
||||
OpenGl_RTVec4f myMinPoint;
|
||||
//! Maximum point of node's bounding box.
|
||||
OpenGl_RTVec4f myMaxPoint;
|
||||
|
||||
//! Data vector (stores data fields of the node).
|
||||
OpenGl_RTVec4i myDataRcrd;
|
||||
};
|
||||
|
||||
//! Stores parameters of BVH tree.
|
||||
class OpenGl_BVH
|
||||
{
|
||||
public:
|
||||
|
||||
//! Removes all tree nodes.
|
||||
void CleanUp();
|
||||
|
||||
//! Adds new node to the tree.
|
||||
int PushNode (const OpenGl_BVHNode& theNode);
|
||||
|
||||
//! Returns node with specified index.
|
||||
OpenGl_BVHNode Node (const int theIndex) const;
|
||||
|
||||
//! Replaces node with specified index by the new one.
|
||||
void SetNode (const int theIndex, const OpenGl_BVHNode& theNode);
|
||||
|
||||
//! Returns array of node min points.
|
||||
OpenGl_RTArray4f& MinPointBuffer() { return myMinPointBuffer; }
|
||||
//! Returns array of node max points.
|
||||
OpenGl_RTArray4f& MaxPointBuffer() { return myMaxPointBuffer; }
|
||||
//! Returns array of node data records.
|
||||
OpenGl_RTArray4i& DataRcrdBuffer() { return myDataRcrdBuffer; }
|
||||
|
||||
private:
|
||||
|
||||
//! Array of min points of BVH nodes.
|
||||
OpenGl_RTArray4f myMinPointBuffer;
|
||||
//! Array of max points of BVH nodes.
|
||||
OpenGl_RTArray4f myMaxPointBuffer;
|
||||
//! Array of data vectors of BVH nodes.
|
||||
OpenGl_RTArray4i myDataRcrdBuffer;
|
||||
};
|
||||
|
||||
//! Stores parameters of single node bin (slice of AABB).
|
||||
struct OpenGl_BVHBin
|
||||
{
|
||||
//! Creates new node bin.
|
||||
OpenGl_BVHBin(): Count (0) { }
|
||||
|
||||
//! Number of primitives in the bin.
|
||||
int Count;
|
||||
|
||||
//! AABB of the bin.
|
||||
OpenGl_AABB Volume;
|
||||
};
|
||||
|
||||
//! Node building task.
|
||||
struct OpenGl_BVHNodeTask
|
||||
{
|
||||
//! Creates new node building task.
|
||||
OpenGl_BVHNodeTask();
|
||||
|
||||
//! Creates new node building task.
|
||||
OpenGl_BVHNodeTask (const int theNodeToBuild,
|
||||
const int theBegTriangle,
|
||||
const int theEndTriangle);
|
||||
|
||||
//! Index of building tree node.
|
||||
int NodeToBuild;
|
||||
//! Index of start node triangle.
|
||||
int BegTriangle;
|
||||
//! Index of final node triangle.
|
||||
int EndTriangle;
|
||||
};
|
||||
|
||||
//! The array of bins of BVH tree node.
|
||||
typedef std::vector<OpenGl_BVHBin,
|
||||
NCollection_StdAllocator<OpenGl_BVHBin> > OpenGl_BinVector;
|
||||
|
||||
//! Binned SAH-based BVH builder.
|
||||
class OpenGl_BinnedBVHBuilder
|
||||
{
|
||||
public:
|
||||
|
||||
//! Creates new binned BVH builder.
|
||||
OpenGl_BinnedBVHBuilder();
|
||||
|
||||
//! Releases binned BVH builder.
|
||||
~OpenGl_BinnedBVHBuilder();
|
||||
|
||||
//! Builds BVH tree using binned SAH algorithm.
|
||||
void Build (OpenGl_RaytraceScene& theGeometry, const float theEpsilon = 1e-3f);
|
||||
|
||||
//! Sets maximum tree depth.
|
||||
void SetMaxDepth (const int theMaxDepth);
|
||||
|
||||
//! Clears previously constructed BVH tree.
|
||||
void CleanUp();
|
||||
|
||||
//! Return constructed BVH tree.
|
||||
OpenGl_BVH& Tree() { return myTree; }
|
||||
|
||||
private:
|
||||
|
||||
//! Builds node using task info.
|
||||
void BuildNode (OpenGl_RaytraceScene& theGeometry, const int theTask);
|
||||
|
||||
//! Arranges node triangles into bins.
|
||||
void GetSubVolumes (OpenGl_RaytraceScene& theGeometry, const OpenGl_BVHNode& theNode,
|
||||
OpenGl_BinVector& theBins, const int theAxis);
|
||||
|
||||
//! Splits node triangles into two intervals for child nodes.
|
||||
int SplitTriangles (OpenGl_RaytraceScene& theGeometry, const int theFirst, const int theLast,
|
||||
OpenGl_BVHNode& theNode, int theBin, const int theAxis);
|
||||
|
||||
private:
|
||||
|
||||
//! Queue of node building tasks.
|
||||
std::vector<OpenGl_BVHNodeTask> myNodeTasksQueue;
|
||||
|
||||
//! Builded BVH tree.
|
||||
OpenGl_BVH myTree;
|
||||
|
||||
//! Maximum depth of BVH tree.
|
||||
int myMaxDepth;
|
||||
//! Returns triangulation data for given leaf node.
|
||||
//! If the node index is not valid the function returns NULL.
|
||||
//! @note Can be used after processing acceleration structure.
|
||||
OpenGl_TriangleSet* TriangleSet (Standard_Integer theNodeIdx);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -277,40 +277,40 @@ protected: //! @name methods related to ray-tracing
|
||||
Standard_Boolean UpdateRaytraceEnvironmentMap();
|
||||
|
||||
//! Adds OpenGL structure to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytraceStructure (const OpenGl_Structure* theStruct,
|
||||
const float* theTrans, std::set<const OpenGl_Structure*>& theElements);
|
||||
Standard_Boolean AddRaytraceStructure (const OpenGl_Structure* theStructure,
|
||||
const Standard_ShortReal* theTransform, std::set<const OpenGl_Structure*>& theElements);
|
||||
|
||||
//! Adds OpenGL primitive array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytracePrimitiveArray (
|
||||
const CALL_DEF_PARRAY* theArray, int theMatID, const float* theTrans);
|
||||
OpenGl_TriangleSet* AddRaytracePrimitiveArray (
|
||||
const CALL_DEF_PARRAY* theArray, int theMatID, const Standard_ShortReal* theTrans);
|
||||
|
||||
//! Adds vertex indices from OpenGL primitive array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytraceVertexIndices (const CALL_DEF_PARRAY* theArray,
|
||||
int theFirstVert, int theVertOffset, int theVertNum, int theMatID);
|
||||
Standard_Boolean AddRaytraceVertexIndices (OpenGl_TriangleSet* theSet,
|
||||
const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
|
||||
|
||||
//! Adds OpenGL triangle array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytraceTriangleArray (const CALL_DEF_PARRAY* theArray,
|
||||
int theFirstVert, int theVertOffset, int theVertNum, int theMatID);
|
||||
Standard_Boolean AddRaytraceTriangleArray (OpenGl_TriangleSet* theSet,
|
||||
const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
|
||||
|
||||
//! Adds OpenGL triangle fan array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytraceTriangleFanArray (const CALL_DEF_PARRAY* theArray,
|
||||
int theFirstVert, int theVertOffset, int theVertNum, int theMatID);
|
||||
Standard_Boolean AddRaytraceTriangleFanArray (OpenGl_TriangleSet* theSet,
|
||||
const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
|
||||
|
||||
//! Adds OpenGL triangle fan array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytraceTriangleStripArray (const CALL_DEF_PARRAY* theArray,
|
||||
int theFirstVert, int theVertOffset, int theVertNum, int theMatID);
|
||||
//! Adds OpenGL triangle strip array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytraceTriangleStripArray (OpenGl_TriangleSet* theSet,
|
||||
const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
|
||||
|
||||
//! Adds OpenGL quadrangle array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytraceQuadrangleArray (const CALL_DEF_PARRAY* theArray,
|
||||
int theFirstVert, int theVertOffset, int theVertNum, int theMatID);
|
||||
Standard_Boolean AddRaytraceQuadrangleArray (OpenGl_TriangleSet* theSet,
|
||||
const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
|
||||
|
||||
//! Adds OpenGL quadrangle strip array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytraceQuadrangleStripArray (const CALL_DEF_PARRAY* theArray,
|
||||
int theFirstVert, int theVertOffset, int theVertNum, int theMatID);
|
||||
Standard_Boolean AddRaytraceQuadrangleStripArray (OpenGl_TriangleSet* theSet,
|
||||
const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
|
||||
|
||||
//! Adds OpenGL polygon array to ray-traced scene geometry.
|
||||
Standard_Boolean AddRaytracePolygonArray (const CALL_DEF_PARRAY* theArray,
|
||||
int theFirstVert, int theVertOffset, int theVertNum, int theMatID);
|
||||
Standard_Boolean AddRaytracePolygonArray (OpenGl_TriangleSet* theSet,
|
||||
const CALL_DEF_PARRAY* theArray, Standard_Integer theOffset, Standard_Integer theCount, Standard_Integer theMatID);
|
||||
|
||||
//! Initializes OpenCL resources.
|
||||
Standard_Boolean InitOpenCL();
|
||||
@ -325,12 +325,19 @@ protected: //! @name methods related to ray-tracing
|
||||
Standard_Boolean WriteRaytraceSceneToDevice();
|
||||
|
||||
//! Runs OpenCL ray-tracing kernels.
|
||||
Standard_Boolean RunRaytraceOpenCLKernels (const Graphic3d_CView& theCView,
|
||||
Standard_Boolean RunRaytraceOpenCLKernelsOld (const Graphic3d_CView& theCView,
|
||||
const GLfloat theOrigins[16],
|
||||
const GLfloat theDirects[16],
|
||||
const int theSizeX,
|
||||
const int theSizeY);
|
||||
|
||||
//! Launches OpenCL ray-tracing kernels.
|
||||
Standard_Boolean RunRaytraceOpenCLKernels (const Graphic3d_CView& theCView,
|
||||
const Standard_ShortReal theOrigins[16],
|
||||
const Standard_ShortReal theDirects[16],
|
||||
const Standard_Integer theSizeX,
|
||||
const Standard_Integer theSizeY);
|
||||
|
||||
//! Redraws the window using OpenCL ray tracing.
|
||||
Standard_Boolean Raytrace (const Graphic3d_CView& theCView,
|
||||
const int theSizeX, const int theSizeY, const Tint theToSwap);
|
||||
@ -346,21 +353,19 @@ protected: //! @name fields related to ray-tracing
|
||||
Standard_Boolean myIsRaytraceDataValid;
|
||||
//! Is geometry data musty be updated?
|
||||
Standard_Boolean myToUpdateRaytraceData;
|
||||
|
||||
//! 3D scene geometry data for ray-tracing.
|
||||
OpenGl_RaytraceScene myRaytraceSceneData;
|
||||
OpenGl_RaytraceGeometry myRaytraceGeometry;
|
||||
|
||||
//! Radius of bounding sphere of the scene.
|
||||
float myRaytraceSceneRadius;
|
||||
Standard_ShortReal myRaytraceSceneRadius;
|
||||
//! Scene epsilon to prevent self-intersections.
|
||||
float myRaytraceSceneEpsilon;
|
||||
|
||||
//! Binned SAH-based BVH builder.
|
||||
OpenGl_BinnedBVHBuilder myBVHBuilder;
|
||||
Standard_ShortReal myRaytraceSceneEpsilon;
|
||||
|
||||
//! OpenCL context.
|
||||
cl_context myComputeContext;
|
||||
//! OpenCL command queue.
|
||||
cl_command_queue myRaytraceQueue;
|
||||
cl_command_queue myComputeQueue;
|
||||
//! OpenCL computing program.
|
||||
cl_program myRaytraceProgram;
|
||||
//! OpenCL ray-tracing render kernel.
|
||||
@ -380,33 +385,38 @@ protected: //! @name fields related to ray-tracing
|
||||
//! OpenGL texture to store anti-aliasing result.
|
||||
Handle(OpenGl_Texture) myRaytraceOutputTextureAA;
|
||||
|
||||
//! OpenCL buffer of vertex normals.
|
||||
cl_mem myRaytraceNormalBuffer;
|
||||
//! OpenCL buffer of vertex coordinates.
|
||||
cl_mem myRaytraceVertexBuffer;
|
||||
//! OpenCL buffer of indices of triangle vertices.
|
||||
cl_mem myRaytraceTriangleBuffer;
|
||||
|
||||
//! OpenCL buffer of minimum points of BVH nodes.
|
||||
cl_mem myRaytraceNodeMinPointBuffer;
|
||||
//! OpenCL buffer of maximum points of BVH nodes.
|
||||
cl_mem myRaytraceNodeMaxPointBuffer;
|
||||
//! OpenCL buffer of data records of BVH nodes.
|
||||
cl_mem myRaytraceNodeDataRcrdBuffer;
|
||||
|
||||
//! OpenCL buffer of material properties.
|
||||
cl_mem myRaytraceMaterialBuffer;
|
||||
|
||||
//! OpenCL buffer of light source properties.
|
||||
cl_mem myRaytraceLightSourceBuffer;
|
||||
|
||||
//! OpenCL buffer of vertex coords.
|
||||
cl_mem myGeometryVertexBuffer;
|
||||
//! OpenCL buffer of vertex normals.
|
||||
cl_mem myGeometryNormalBuffer;
|
||||
//! OpenCL buffer of triangle indices.
|
||||
cl_mem myGeometryTriangBuffer;
|
||||
|
||||
//! OpenCL buffer of data records of high-level BVH nodes.
|
||||
cl_mem mySceneNodeInfoBuffer;
|
||||
//! OpenCL buffer of minimum points of high-level BVH nodes.
|
||||
cl_mem mySceneMinPointBuffer;
|
||||
//! OpenCL buffer of maximum points of high-level BVH nodes.
|
||||
cl_mem mySceneMaxPointBuffer;
|
||||
|
||||
//! OpenCL buffer of data records of bottom-level BVH nodes.
|
||||
cl_mem myObjectNodeInfoBuffer;
|
||||
//! OpenCL buffer of minimum points of bottom-level BVH nodes.
|
||||
cl_mem myObjectMinPointBuffer;
|
||||
//! OpenCL buffer of maximum points of bottom-level BVH nodes.
|
||||
cl_mem myObjectMaxPointBuffer;
|
||||
|
||||
//! State of OpenGL view.
|
||||
Standard_Size myViewModificationStatus;
|
||||
|
||||
//! State of OpenGL layer list.
|
||||
Standard_Size myLayersModificationStatus;
|
||||
|
||||
//! State of OpenGL elements reflected to ray-tracing.
|
||||
//! State of OpenGL structures reflected to ray-tracing.
|
||||
std::map<const OpenGl_Structure*, Standard_Size> myStructureStates;
|
||||
|
||||
#endif // HAVE_OPENCL
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,7 @@ restore $aShape2 s2
|
||||
vdisplay s1 s2
|
||||
vsetmaterial s1 Silver
|
||||
vsetmaterial s2 Pewter
|
||||
vlight change 0 pos -1 1 1
|
||||
vfit
|
||||
|
||||
# activate ray-tracing
|
||||
|
Loading…
x
Reference in New Issue
Block a user