Standard_Integer aVerticesOffset = 0;
Standard_Integer aElementsOffset = 0;
- Standard_Integer aBVHNodesOffset = 0;
+ Standard_Integer aBVHNodesOffset = BVH()->Length();
for (Standard_Integer aNodeIdx = 0; aNodeIdx < aBVH->Length(); ++aNodeIdx)
{
//! Defines texture samplers.
enum ShaderSamplerNames
{
- OpenGl_RT_SceneNodeInfoTexture = 0,
- OpenGl_RT_SceneMinPointTexture = 1,
- OpenGl_RT_SceneMaxPointTexture = 2,
+ OpenGl_RT_SceneNodeInfoTexture = 0,
+ OpenGl_RT_SceneMinPointTexture = 1,
+ OpenGl_RT_SceneMaxPointTexture = 2,
+ OpenGl_RT_SceneTransformTexture = 3,
- OpenGl_RT_ObjectNodeInfoTexture = 3,
- OpenGl_RT_ObjectMinPointTexture = 4,
- OpenGl_RT_ObjectMaxPointTexture = 5,
+ OpenGl_RT_GeometryVertexTexture = 4,
+ OpenGl_RT_GeometryNormalTexture = 5,
+ OpenGl_RT_GeometryTexCrdTexture = 6,
+ OpenGl_RT_GeometryTriangTexture = 7,
- OpenGl_RT_GeometryVertexTexture = 6,
- OpenGl_RT_GeometryNormalTexture = 7,
- OpenGl_RT_GeometryTexCrdTexture = 8,
- OpenGl_RT_GeometryTriangTexture = 9,
+ OpenGl_RT_EnvironmentMapTexture = 8,
- OpenGl_RT_EnvironmentMapTexture = 10,
+ OpenGl_RT_RaytraceMaterialTexture = 9,
+ OpenGl_RT_RaytraceLightSrcTexture = 10,
- OpenGl_RT_RaytraceMaterialTexture = 11,
- OpenGl_RT_RaytraceLightSrcTexture = 12,
+ OpenGl_RT_FSAAInputTexture = 11,
- OpenGl_RT_FSAAInputTexture = 13,
-
- OpenGl_RT_SceneTransformTexture = 14,
-
- OpenGl_RT_OpenGlColorTexture = 15,
- OpenGl_RT_OpenGlDepthTexture = 16
+ OpenGl_RT_OpenGlColorTexture = 12,
+ OpenGl_RT_OpenGlDepthTexture = 13
};
//! Tool class for management of shader sources.
//! OpenGL/GLSL adaptive-AA shader program.
Handle(OpenGl_ShaderProgram) myPostFSAAProgram;
- //! Texture buffer of data records of high-level BVH nodes.
+ //! Texture buffer of data records of bottom-level BVH nodes.
Handle(OpenGl_TextureBufferArb) mySceneNodeInfoTexture;
- //! Texture buffer of minimum points of high-level BVH nodes.
+ //! Texture buffer of minimum points of bottom-level BVH nodes.
Handle(OpenGl_TextureBufferArb) mySceneMinPointTexture;
- //! Texture buffer of maximum points of high-level BVH nodes.
+ //! Texture buffer of maximum points of bottom-level BVH nodes.
Handle(OpenGl_TextureBufferArb) mySceneMaxPointTexture;
//! Texture buffer of transformations of high-level BVH nodes.
Handle(OpenGl_TextureBufferArb) mySceneTransformTexture;
- //! Texture buffer of data records of bottom-level BVH nodes.
- Handle(OpenGl_TextureBufferArb) myObjectNodeInfoTexture;
- //! Texture buffer of minimum points of bottom-level BVH nodes.
- Handle(OpenGl_TextureBufferArb) myObjectMinPointTexture;
- //! Texture buffer of maximum points of bottom-level BVH nodes.
- Handle(OpenGl_TextureBufferArb) myObjectMaxPointTexture;
-
//! Texture buffer of vertex coords.
Handle(OpenGl_TextureBufferArb) myGeometryVertexTexture;
//! Texture buffer of vertex normals.
{
return UpdateRaytraceGeometry (OpenGl_GUM_PREPARE);
}
- }
+ }
else if (theMode == OpenGl_GUM_PREPARE)
{
if (!aStructure->IsRaytracable()
}
}
}
- }
+ }
else if (theMode == OpenGl_GUM_UPDATE)
{
if (!aStructure->IsRaytracable())
// =======================================================================
// function : CheckRaytraceStructure
-// purpose : Checks to see if the structure is modified
+// purpose : Checks to see if the structure is modified
// =======================================================================
Standard_Boolean OpenGl_Workspace::CheckRaytraceStructure (const OpenGl_Structure* theStructure)
{
if (!aBounds.IsNull())
{
- #ifdef RAY_TRACE_PRINT_INFO
+#ifdef RAY_TRACE_PRINT_INFO
std::cout << "\tNumber of bounds = " << aBounds->NbBounds << std::endl;
- #endif
+#endif
Standard_Integer aBoundStart = 0;
for (Standard_Integer aBound = 0; aBound < aBounds->NbBounds; ++aBound)
{
const Standard_Integer aVertNum = aBounds->Bounds[aBound];
- #ifdef RAY_TRACE_PRINT_INFO
+#ifdef RAY_TRACE_PRINT_INFO
std::cout << "\tAdding indices from bound " << aBound << ": " <<
aBoundStart << " .. " << aVertNum << std::endl;
- #endif
+#endif
if (!AddRaytraceVertexIndices (*aSet, *theArray, aBoundStart, aVertNum, theMatID))
{
"uSceneMaxPointTexture", OpenGl_RT_SceneMaxPointTexture);
aShaderProgram->SetSampler (myGlContext,
"uSceneNodeInfoTexture", OpenGl_RT_SceneNodeInfoTexture);
- aShaderProgram->SetSampler (myGlContext,
- "uObjectMinPointTexture", OpenGl_RT_ObjectMinPointTexture);
- aShaderProgram->SetSampler (myGlContext,
- "uObjectMaxPointTexture", OpenGl_RT_ObjectMaxPointTexture);
- aShaderProgram->SetSampler (myGlContext,
- "uObjectNodeInfoTexture", OpenGl_RT_ObjectNodeInfoTexture);
aShaderProgram->SetSampler (myGlContext,
"uGeometryVertexTexture", OpenGl_RT_GeometryVertexTexture);
aShaderProgram->SetSampler (myGlContext,
NullifyResource (myGlContext, mySceneMinPointTexture);
NullifyResource (myGlContext, mySceneMaxPointTexture);
- NullifyResource (myGlContext, myObjectNodeInfoTexture);
- NullifyResource (myGlContext, myObjectMinPointTexture);
- NullifyResource (myGlContext, myObjectMaxPointTexture);
-
NullifyResource (myGlContext, myGeometryVertexTexture);
NullifyResource (myGlContext, myGeometryNormalTexture);
NullifyResource (myGlContext, myGeometryTexCrdTexture);
}
/////////////////////////////////////////////////////////////////////////////
- // Create OpenGL texture buffers
+ // Create OpenGL BVH buffers
- if (mySceneNodeInfoTexture.IsNull()) // create hight-level BVH buffers
+ if (mySceneNodeInfoTexture.IsNull()) // create scene BVH buffers
{
- mySceneNodeInfoTexture = new OpenGl_TextureBufferArb;
- mySceneMinPointTexture = new OpenGl_TextureBufferArb;
- mySceneMaxPointTexture = new OpenGl_TextureBufferArb;
+ mySceneNodeInfoTexture = new OpenGl_TextureBufferArb;
+ mySceneMinPointTexture = new OpenGl_TextureBufferArb;
+ mySceneMaxPointTexture = new OpenGl_TextureBufferArb;
mySceneTransformTexture = new OpenGl_TextureBufferArb;
- if (!mySceneNodeInfoTexture->Create (myGlContext)
- || !mySceneMinPointTexture->Create (myGlContext)
- || !mySceneMaxPointTexture->Create (myGlContext)
+ if (!mySceneNodeInfoTexture->Create (myGlContext)
+ || !mySceneMinPointTexture->Create (myGlContext)
+ || !mySceneMaxPointTexture->Create (myGlContext)
|| !mySceneTransformTexture->Create (myGlContext))
{
#ifdef RAY_TRACE_PRINT_INFO
- std::cout << "Error: Failed to create buffers for high-level scene BVH" << std::endl;
-#endif
- return Standard_False;
- }
- }
-
- if (myObjectNodeInfoTexture.IsNull()) // create bottom-level BVH buffers
- {
- myObjectNodeInfoTexture = new OpenGl_TextureBufferArb;
- myObjectMinPointTexture = new OpenGl_TextureBufferArb;
- myObjectMaxPointTexture = new OpenGl_TextureBufferArb;
-
- if (!myObjectNodeInfoTexture->Create (myGlContext)
- || !myObjectMinPointTexture->Create (myGlContext)
- || !myObjectMaxPointTexture->Create (myGlContext))
- {
-#ifdef RAY_TRACE_PRINT_INFO
- std::cout << "Error: Failed to create buffers for bottom-level scene BVH" << std::endl;
+ std::cout << "Error: Failed to create scene BVH buffers" << std::endl;
#endif
return Standard_False;
}
}
- if (myGeometryVertexTexture.IsNull()) // create geometry buffers
+ if (myGeometryVertexTexture.IsNull()) // create geometry buffers
{
myGeometryVertexTexture = new OpenGl_TextureBufferArb;
myGeometryNormalTexture = new OpenGl_TextureBufferArb;
}
}
- if (myRaytraceMaterialTexture.IsNull()) // create material buffer
+ if (myRaytraceMaterialTexture.IsNull()) // create material buffer
{
myRaytraceMaterialTexture = new OpenGl_TextureBufferArb;
return Standard_False;
}
}
-
- /////////////////////////////////////////////////////////////////////////////
- // Write top-level BVH buffers
-
- const NCollection_Handle<BVH_Tree<Standard_ShortReal, 3> >& aBVH = myRaytraceGeometry.BVH();
-
- bool aResult = true;
- if (!aBVH->NodeInfoBuffer().empty())
- {
- aResult &= mySceneNodeInfoTexture->Init (myGlContext, 4, GLsizei (aBVH->NodeInfoBuffer().size()),
- reinterpret_cast<const GLuint*> (&aBVH->NodeInfoBuffer().front()));
- aResult &= mySceneMinPointTexture->Init (myGlContext, 3, GLsizei (aBVH->MinPointBuffer().size()),
- reinterpret_cast<const GLfloat*> (&aBVH->MinPointBuffer().front()));
- aResult &= mySceneMaxPointTexture->Init (myGlContext, 3, GLsizei (aBVH->MaxPointBuffer().size()),
- reinterpret_cast<const GLfloat*> (&aBVH->MaxPointBuffer().front()));
- }
- if (!aResult)
- {
-#ifdef RAY_TRACE_PRINT_INFO
- std::cout << "Error: Failed to upload buffers for high-level scene BVH" << std::endl;
-#endif
- return Standard_False;
- }
-
+
/////////////////////////////////////////////////////////////////////////////
// Write transform buffer
BVH_Mat4f* aNodeTransforms = new BVH_Mat4f[myRaytraceGeometry.Size()];
+ bool aResult = true;
+
for (Standard_Integer anElemIndex = 0; anElemIndex < myRaytraceGeometry.Size(); ++anElemIndex)
{
OpenGl_TriangleSet* aTriangleSet = dynamic_cast<OpenGl_TriangleSet*> (
aTotalBVHNodesNb += aTriangleSet->BVH()->NodeInfoBuffer().size();
}
+ aTotalBVHNodesNb += myRaytraceGeometry.BVH()->NodeInfoBuffer().size();
+
if (aTotalBVHNodesNb != 0)
{
- aResult &= myObjectNodeInfoTexture->Init (
+ aResult &= mySceneNodeInfoTexture->Init (
myGlContext, 4, GLsizei (aTotalBVHNodesNb), static_cast<const GLuint*> (NULL));
- aResult &= myObjectMinPointTexture->Init (
+ aResult &= mySceneMinPointTexture->Init (
myGlContext, 3, GLsizei (aTotalBVHNodesNb), static_cast<const GLfloat*> (NULL));
- aResult &= myObjectMaxPointTexture->Init (
+ aResult &= mySceneMaxPointTexture->Init (
myGlContext, 3, GLsizei (aTotalBVHNodesNb), static_cast<const GLfloat*> (NULL));
}
return Standard_False;
}
+ const NCollection_Handle<BVH_Tree<Standard_ShortReal, 3> >& aBVH = myRaytraceGeometry.BVH();
+
+ aResult &= mySceneNodeInfoTexture->SubData (myGlContext, 0, aBVH->Length(),
+ reinterpret_cast<const GLuint*> (&aBVH->NodeInfoBuffer().front()));
+ aResult &= mySceneMinPointTexture->SubData (myGlContext, 0, aBVH->Length(),
+ reinterpret_cast<const GLfloat*> (&aBVH->MinPointBuffer().front()));
+ aResult &= mySceneMaxPointTexture->SubData (myGlContext, 0, aBVH->Length(),
+ reinterpret_cast<const GLfloat*> (&aBVH->MaxPointBuffer().front()));
+
for (Standard_Integer aNodeIdx = 0; aNodeIdx < aBVH->Length(); ++aNodeIdx)
{
if (!aBVH->IsOuter (aNodeIdx))
Standard_ASSERT_RETURN (aTriangleSet != NULL,
"Error: Failed to get triangulation of OpenGL element", Standard_False);
- const Standard_Integer aBVHOffset = myRaytraceGeometry.AccelerationOffset (aNodeIdx);
+ Standard_Integer aBVHOffset = myRaytraceGeometry.AccelerationOffset (aNodeIdx);
Standard_ASSERT_RETURN (aBVHOffset != OpenGl_RaytraceGeometry::INVALID_OFFSET,
"Error: Failed to get offset for bottom-level BVH", Standard_False);
- const size_t aBVHBuffserSize = aTriangleSet->BVH()->NodeInfoBuffer().size();
+ const Standard_Integer aBvhBuffersSize = aTriangleSet->BVH()->Length();
- if (aBVHBuffserSize != 0)
+ if (aBvhBuffersSize != 0)
{
- aResult &= myObjectNodeInfoTexture->SubData (myGlContext, aBVHOffset, GLsizei (aBVHBuffserSize),
+ aResult &= mySceneNodeInfoTexture->SubData (myGlContext, aBVHOffset, aBvhBuffersSize,
reinterpret_cast<const GLuint*> (&aTriangleSet->BVH()->NodeInfoBuffer().front()));
- aResult &= myObjectMinPointTexture->SubData (myGlContext, aBVHOffset, GLsizei (aBVHBuffserSize),
+ aResult &= mySceneMinPointTexture->SubData (myGlContext, aBVHOffset, aBvhBuffersSize,
reinterpret_cast<const GLfloat*> (&aTriangleSet->BVH()->MinPointBuffer().front()));
- aResult &= myObjectMaxPointTexture->SubData (myGlContext, aBVHOffset, GLsizei (aBVHBuffserSize),
+ aResult &= mySceneMaxPointTexture->SubData (myGlContext, aBVHOffset, aBvhBuffersSize,
reinterpret_cast<const GLfloat*> (&aTriangleSet->BVH()->MaxPointBuffer().front()));
if (!aResult)
{
mySceneMinPointTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMinPointTexture);
mySceneMaxPointTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMaxPointTexture);
mySceneNodeInfoTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneNodeInfoTexture);
- myObjectMinPointTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMinPointTexture);
- myObjectMaxPointTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMaxPointTexture);
- myObjectNodeInfoTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectNodeInfoTexture);
myGeometryVertexTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryVertexTexture);
myGeometryNormalTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryNormalTexture);
myGeometryTexCrdTexture->BindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryTexCrdTexture);
myOpenGlFBO->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlColorTexture);
myOpenGlFBO->DepthStencilTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlDepthTexture);
- mySceneMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMinPointTexture);
- mySceneMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMaxPointTexture);
- mySceneNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneNodeInfoTexture);
- myObjectMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMinPointTexture);
- myObjectMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMaxPointTexture);
- myObjectNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectNodeInfoTexture);
+ mySceneMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMinPointTexture);
+ mySceneMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMaxPointTexture);
+ mySceneNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneNodeInfoTexture);
myGeometryVertexTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryVertexTexture);
myGeometryNormalTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryNormalTexture);
myGeometryTexCrdTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryTexCrdTexture);
myRaytraceFBO1->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_FSAAInputTexture);
myOpenGlFBO->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlColorTexture);
myOpenGlFBO->DepthStencilTexture()->Unbind (myGlContext, GL_TEXTURE0 + OpenGl_RT_OpenGlDepthTexture);
- mySceneMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMinPointTexture);
- mySceneMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMaxPointTexture);
- mySceneNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneNodeInfoTexture);
- myObjectMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMinPointTexture);
- myObjectMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectMaxPointTexture);
- myObjectNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_ObjectNodeInfoTexture);
+ mySceneMinPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMinPointTexture);
+ mySceneMaxPointTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneMaxPointTexture);
+ mySceneNodeInfoTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_SceneNodeInfoTexture);
myGeometryVertexTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryVertexTexture);
myGeometryNormalTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryNormalTexture);
myGeometryTexCrdTexture->UnbindTexture (myGlContext, GL_TEXTURE0 + OpenGl_RT_GeometryTexCrdTexture);
//! Inverse model-view-projection matrix.
uniform mat4 uUnviewMat;
-//! Texture buffer of data records of high-level BVH nodes.
+//! Texture buffer of data records of bottom-level BVH nodes.
uniform isamplerBuffer uSceneNodeInfoTexture;
-//! Texture buffer of minimum points of high-level BVH nodes.
+//! Texture buffer of minimum points of bottom-level BVH nodes.
uniform samplerBuffer uSceneMinPointTexture;
-//! Texture buffer of maximum points of high-level BVH nodes.
+//! Texture buffer of maximum points of bottom-level BVH nodes.
uniform samplerBuffer uSceneMaxPointTexture;
//! Texture buffer of transformations of high-level BVH nodes.
uniform samplerBuffer uSceneTransformTexture;
-//! Texture buffer of data records of bottom-level BVH nodes.
-uniform isamplerBuffer uObjectNodeInfoTexture;
-//! Texture buffer of minimum points of bottom-level BVH nodes.
-uniform samplerBuffer uObjectMinPointTexture;
-//! Texture buffer of maximum points of bottom-level BVH nodes.
-uniform samplerBuffer uObjectMaxPointTexture;
-
//! Texture buffer of vertex coords.
uniform samplerBuffer uGeometryVertexTexture;
//! Texture buffer of vertex normals.
float aDdotD = dot (theRay.Direct, theRay.Direct);
float aDdotO = dot (theRay.Direct, theRay.Origin);
float aOdotO = dot (theRay.Origin, theRay.Origin);
-
+
float aD = aDdotO * aDdotO - aDdotD * (aOdotO - theRadius * theRadius);
-
+
if (aD > 0.0f)
{
float aTime = (sqrt (aD) - aDdotO) * (1.0f / aDdotD);
return aTime > 0.0f ? aTime : MAXFLOAT;
}
-
+
return MAXFLOAT;
}
{
vec3 aEdge0 = thePnt1 - thePnt0;
vec3 aEdge1 = thePnt0 - thePnt2;
-
+
theNorm = cross (aEdge1, aEdge0);
vec3 aEdge2 = (1.0f / dot (theNorm, theRay.Direct)) * (thePnt0 - theRay.Origin);
-
+
float aTime = dot (theNorm, aEdge2);
vec3 theVec = cross (theRay.Direct, aEdge2);
-
+
theUV.x = dot (theVec, aEdge1);
theUV.y = dot (theVec, aEdge0);
-
+
return bool (int(aTime >= 0.0f) &
int(theUV.x >= 0.0f) &
int(theUV.y >= 0.0f) &
ivec4 aTriIndex = INALID_HIT;
- while (true)
+ bool toContinue = true;
+
+ while (toContinue)
{
- ivec3 aData = texelFetch (uObjectNodeInfoTexture, aNode).xyz;
+ ivec3 aData = texelFetch (uSceneNodeInfoTexture, aNode).xyz;
if (aData.x == 0) // if inner node
{
float aTimeOut;
float aTimeLft;
float aTimeRgh;
-
+
aData.y += theBVHOffset;
aData.z += theBVHOffset;
-
- vec3 aNodeMinLft = texelFetch (uObjectMinPointTexture, aData.y).xyz;
- vec3 aNodeMaxLft = texelFetch (uObjectMaxPointTexture, aData.y).xyz;
- vec3 aNodeMinRgh = texelFetch (uObjectMinPointTexture, aData.z).xyz;
- vec3 aNodeMaxRgh = texelFetch (uObjectMaxPointTexture, aData.z).xyz;
+
+ vec3 aNodeMinLft = texelFetch (uSceneMinPointTexture, aData.y).xyz;
+ vec3 aNodeMinRgh = texelFetch (uSceneMinPointTexture, aData.z).xyz;
+ vec3 aNodeMaxLft = texelFetch (uSceneMaxPointTexture, aData.y).xyz;
+ vec3 aNodeMaxRgh = texelFetch (uSceneMaxPointTexture, aData.z).xyz;
vec3 aTime0 = (aNodeMinLft - theRay.Origin) * theInverse;
vec3 aTime1 = (aNodeMaxLft - theRay.Origin) * theInverse;
-
+
vec3 aTimeMax = max (aTime0, aTime1);
vec3 aTimeMin = min (aTime0, aTime1);
aTime0 = (aNodeMinRgh - theRay.Origin) * theInverse;
aTime1 = (aNodeMaxRgh - theRay.Origin) * theInverse;
-
+
aTimeOut = min (aTimeMax.x, min (aTimeMax.y, aTimeMax.z));
aTimeLft = max (aTimeMin.x, max (aTimeMin.y, aTimeMin.z));
if (bool(aHitLft & aHitRgh))
{
aNode = (aTimeLft < aTimeRgh) ? aData.y : aData.z;
-
+
Stack[++aHead] = (aTimeLft < aTimeRgh) ? aData.z : aData.y;
}
else
}
else
{
- if (aHead == theSentinel)
- return aTriIndex;
+ toContinue = (aHead != theSentinel);
- aNode = Stack[aHead--];
+ if (toContinue)
+ aNode = Stack[aHead--];
}
}
}
aPoint2,
aParams,
aNormal);
-
+
if (aTime < theHit.Time)
{
aTriIndex = aTriangle;
theHit = SIntersect (aTime, aParams, aNormal);
}
}
-
- if (aHead == theSentinel)
- return aTriIndex;
- aNode = Stack[aHead--];
+ toContinue = (aHead != theSentinel);
+
+ if (toContinue)
+ aNode = Stack[aHead--];
}
}
while (true)
{
- ivec4 aData = texelFetch (uObjectNodeInfoTexture, aNode);
+ ivec4 aData = texelFetch (uSceneNodeInfoTexture, aNode);
if (aData.x == 0) // if inner node
{
aData.y += theBVHOffset;
aData.z += theBVHOffset;
-
- vec3 aNodeMinLft = texelFetch (uObjectMinPointTexture, aData.y).xyz;
- vec3 aNodeMaxLft = texelFetch (uObjectMaxPointTexture, aData.y).xyz;
- vec3 aNodeMinRgh = texelFetch (uObjectMinPointTexture, aData.z).xyz;
- vec3 aNodeMaxRgh = texelFetch (uObjectMaxPointTexture, aData.z).xyz;
+
+ vec3 aNodeMinLft = texelFetch (uSceneMinPointTexture, aData.y).xyz;
+ vec3 aNodeMaxLft = texelFetch (uSceneMaxPointTexture, aData.y).xyz;
+ vec3 aNodeMinRgh = texelFetch (uSceneMinPointTexture, aData.z).xyz;
+ vec3 aNodeMaxRgh = texelFetch (uSceneMaxPointTexture, aData.z).xyz;
vec3 aTime0 = (aNodeMinLft - theRay.Origin) * theInverse;
vec3 aTime1 = (aNodeMaxLft - theRay.Origin) * theInverse;
aTime0 = (aNodeMinRgh - theRay.Origin) * theInverse;
aTime1 = (aNodeMaxRgh - theRay.Origin) * theInverse;
-
+
aTimeOut = min (aTimeMax.x, min (aTimeMax.y, aTimeMax.z));
aTimeLft = max (aTimeMin.x, max (aTimeMin.y, aTimeMin.z));
vec3 aTrsfInverse = 1.0f / max (abs (aTrsfRay.Direct), SMALL);
- aTrsfInverse.x = aTrsfRay.Direct.x < 0.f ? -aTrsfInverse.x : aTrsfInverse.x;
- aTrsfInverse.y = aTrsfRay.Direct.y < 0.f ? -aTrsfInverse.y : aTrsfInverse.y;
- aTrsfInverse.z = aTrsfRay.Direct.z < 0.f ? -aTrsfInverse.z : aTrsfInverse.z;
+ aTrsfInverse = mix (-aTrsfInverse, aTrsfInverse, step (ZERO, aTrsfRay.Direct));
ivec4 aTriIndex = ObjectNearestHit (
aData.y, aData.z, aData.w, aTrsfRay, aTrsfInverse, theHit, aHead);
theObjectId = anObjectId;
}
}
-
+
if (aHead < 0)
return aHitObject;
aTimeLft = max (aTimeMin.x, max (aTimeMin.y, aTimeMin.z));
int aHitLft = int(aTimeLft <= aTimeOut) & int(aTimeOut >= 0.0f) & int(aTimeLft <= theHit.Time);
-
+
aTime0 = (aNodeMinRgh - theRay.Origin) * theInverse;
aTime1 = (aNodeMaxRgh - theRay.Origin) * theInverse;
aTimeOut = min (aTimeMax.x, min (aTimeMax.y, aTimeMax.z));
aTimeRgh = max (aTimeMin.x, max (aTimeMin.y, aTimeMin.z));
-
+
int aHitRgh = int(aTimeRgh <= aTimeOut) & int(aTimeOut >= 0.0f) & int(aTimeRgh <= theHit.Time);
if (bool(aHitLft & aHitRgh))
}
}
}
-
+
return aHitObject;
}
vec3 aTrsfInverse = 1.0f / max (abs (aTrsfRay.Direct), SMALL);
- aTrsfInverse.x = aTrsfRay.Direct.x < 0.0f ? -aTrsfInverse.x : aTrsfInverse.x;
- aTrsfInverse.y = aTrsfRay.Direct.y < 0.0f ? -aTrsfInverse.y : aTrsfInverse.y;
- aTrsfInverse.z = aTrsfRay.Direct.z < 0.0f ? -aTrsfInverse.z : aTrsfInverse.z;
+ aTrsfInverse = mix (-aTrsfInverse, aTrsfInverse, step (ZERO, aTrsfRay.Direct));
#ifdef TRANSPARENT_SHADOWS
aFactor *= ObjectAnyHit (
{
vec4 aLight = texelFetch (
uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx));
-
+
float aDistance = MAXFLOAT;
-
+
if (aLight.w != 0.0f) // point light source
{
aDistance = length (aLight.xyz -= aPoint);
-
+
aLight.xyz *= 1.0f / aDistance;
}
SRay aShadow = SRay (aPoint + aLight.xyz * uSceneEpsilon, aLight.xyz);
-
+
aShadow.Origin += aHit.Normal * uSceneEpsilon *
(dot (aHit.Normal, aLight.xyz) >= 0.0f ? 1.0f : -1.0f);
-
+
float aVisibility = 1.0f;
-
+
if (bool(uShadowsEnable))
{
vec3 aInverse = 1.0f / max (abs (aLight.xyz), SMALL);
- aInverse.x = aLight.x < 0.0f ? -aInverse.x : aInverse.x;
- aInverse.y = aLight.y < 0.0f ? -aInverse.y : aInverse.y;
- aInverse.z = aLight.z < 0.0f ? -aInverse.z : aInverse.z;
-
- aVisibility = SceneAnyHit (aShadow, aInverse, aDistance);
+ aVisibility = SceneAnyHit (
+ aShadow, mix (-aInverse, aInverse, step (ZERO, aLight.xyz)), aDistance);
}
-
+
if (aVisibility > 0.0f)
{
vec3 aIntensity = vec3 (texelFetch (
theInverse = 1.0f / max (abs (theRay.Direct), SMALL);
- theInverse.x = theRay.Direct.x < 0.0f ? -theInverse.x : theInverse.x;
- theInverse.y = theRay.Direct.y < 0.0f ? -theInverse.y : theInverse.y;
- theInverse.z = theRay.Direct.z < 0.0f ? -theInverse.z : theInverse.z;
+ theInverse = mix (-theInverse, theInverse, step (ZERO, theRay.Direct));
aPoint += aHit.Normal * (dot (aHit.Normal, theRay.Direct) >= 0.0f ? uSceneEpsilon : -uSceneEpsilon);
theInverse = 1.0f / max (abs (theRay.Direct), SMALL);
- theInverse.x = theRay.Direct.x < 0.0f ? -theInverse.x : theInverse.x;
- theInverse.y = theRay.Direct.y < 0.0f ? -theInverse.y : theInverse.y;
- theInverse.z = theRay.Direct.z < 0.0f ? -theInverse.z : theInverse.z;
+ theInverse = mix (-theInverse, theInverse, step (ZERO, theRay.Direct));
aPoint += aHit.Normal * (dot (aHit.Normal, theRay.Direct) >= 0.0f ? uSceneEpsilon : -uSceneEpsilon);