// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
-#include <Graphic3d_TextureParams.hxx>
+#include <OpenGl_View.hxx>
-#include <OpenGl_FrameBuffer.hxx>
+#include <Graphic3d_TextureParams.hxx>
#include <OpenGl_PrimitiveArray.hxx>
#include <OpenGl_VertexBuffer.hxx>
-#include <OpenGl_View.hxx>
-
#include <OSD_Protection.hxx>
#include <OSD_File.hxx>
}
// Get structure material
- Standard_Integer aStructMatID = -1;
+ OpenGl_RaytraceMaterial aStructMaterial;
if (theStructure->AspectFace() != NULL)
{
- aStructMatID = static_cast<Standard_Integer> (myRaytraceGeometry.Materials.size());
-
- OpenGl_RaytraceMaterial aStructMaterial = convertMaterial (theStructure->AspectFace(), theGlContext);
-
- myRaytraceGeometry.Materials.push_back (aStructMaterial);
+ aStructMaterial = convertMaterial (theStructure->AspectFace(), theGlContext);
}
Standard_ShortReal aStructTransform[16];
}
}
- Standard_Boolean aResult = addRaytraceGroups (theStructure, aStructMatID,
+ Standard_Boolean aResult = addRaytraceGroups (theStructure, aStructMaterial,
theStructure->Transformation()->mat ? aStructTransform : NULL, theGlContext);
// Process all connected OpenGL structures
if (anInstanced != NULL && anInstanced->IsRaytracable())
{
- aResult &= addRaytraceGroups (anInstanced, aStructMatID,
+ aResult &= addRaytraceGroups (anInstanced, aStructMaterial,
theStructure->Transformation()->mat ? aStructTransform : NULL, theGlContext);
}
// function : addRaytraceGroups
// purpose : Adds OpenGL groups to ray-traced scene geometry
// =======================================================================
-Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* theStructure,
- const Standard_Integer theStructMat,
- const Standard_ShortReal* theTransform,
- const Handle(OpenGl_Context)& theGlContext)
+Standard_Boolean OpenGl_View::addRaytraceGroups (const OpenGl_Structure* theStructure,
+ const OpenGl_RaytraceMaterial& theStructMat,
+ const Standard_ShortReal* theTransform,
+ const Handle(OpenGl_Context)& theGlContext)
{
for (OpenGl_Structure::GroupIterator aGroupIter (theStructure->DrawGroups()); aGroupIter.More(); aGroupIter.Next())
{
// Get group material
- Standard_Integer aGroupMatID = -1;
+ OpenGl_RaytraceMaterial aGroupMaterial;
if (aGroupIter.Value()->AspectFace() != NULL)
{
- aGroupMatID = static_cast<Standard_Integer> (myRaytraceGeometry.Materials.size());
-
- OpenGl_RaytraceMaterial aGroupMaterial = convertMaterial (
+ aGroupMaterial = convertMaterial (
aGroupIter.Value()->AspectFace(), theGlContext);
-
- myRaytraceGeometry.Materials.push_back (aGroupMaterial);
}
- Standard_Integer aMatID = aGroupMatID < 0 ? theStructMat : aGroupMatID;
- if (aMatID < 0)
- {
- aMatID = static_cast<Standard_Integer> (myRaytraceGeometry.Materials.size());
+ Standard_Integer aMatID = static_cast<Standard_Integer> (myRaytraceGeometry.Materials.size());
- myRaytraceGeometry.Materials.push_back (OpenGl_RaytraceMaterial());
- }
+ // Use group material if available, otherwise use structure material
+ myRaytraceGeometry.Materials.push_back (
+ aGroupIter.Value()->AspectFace() != NULL ? aGroupMaterial : theStructMat);
// Add OpenGL elements from group (extract primitives arrays and aspects)
for (const OpenGl_ElementNode* aNode = aGroupIter.Value()->FirstNode(); aNode != NULL; aNode = aNode->next)
// =======================================================================
TCollection_AsciiString OpenGl_View::ShaderSource::Source() const
{
- static const TCollection_AsciiString aVersion = "#version 140";
+ const TCollection_AsciiString aVersion = "#version 140";
if (myPrefix.IsEmpty())
{
}
else if (theGlContext->caps->glslWarnings)
{
- myRaytraceProgram->FetchInfoLog (theGlContext, aLinkLog);
-
+ aProgram->FetchInfoLog (theGlContext, aLinkLog);
if (!aLinkLog.IsEmpty() && !aLinkLog.IsEqual ("No errors.\n"))
{
const TCollection_ExtendedString aMessage = TCollection_ExtendedString (
// function : initRaytraceResources
// purpose : Initializes OpenGL/GLSL shader programs
// =======================================================================
-Standard_Boolean OpenGl_View::initRaytraceResources (const Graphic3d_CView& theCView, const Handle(OpenGl_Context)& theGlContext)
+Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context)& theGlContext)
{
if (myRaytraceInitStatus == OpenGl_RT_FAIL)
{
}
}
- if (theCView.RenderParams.RaytracingDepth != myRaytraceParameters.NbBounces)
+ if (myRenderParams.RaytracingDepth != myRaytraceParameters.NbBounces)
{
- myRaytraceParameters.NbBounces = theCView.RenderParams.RaytracingDepth;
+ myRaytraceParameters.NbBounces = myRenderParams.RaytracingDepth;
aToRebuildShaders = Standard_True;
}
aToRebuildShaders = Standard_True;
}
- if (theCView.RenderParams.IsTransparentShadowEnabled != myRaytraceParameters.TransparentShadows)
+ if (myRenderParams.IsTransparentShadowEnabled != myRaytraceParameters.TransparentShadows)
{
- myRaytraceParameters.TransparentShadows = theCView.RenderParams.IsTransparentShadowEnabled;
+ myRaytraceParameters.TransparentShadows = myRenderParams.IsTransparentShadowEnabled;
aToRebuildShaders = Standard_True;
}
- if (theCView.RenderParams.IsGlobalIlluminationEnabled != myRaytraceParameters.GlobalIllumination)
+ if (myRenderParams.IsGlobalIlluminationEnabled != myRaytraceParameters.GlobalIllumination)
{
- myRaytraceParameters.GlobalIllumination = theCView.RenderParams.IsGlobalIlluminationEnabled;
+ myRaytraceParameters.GlobalIllumination = myRenderParams.IsGlobalIlluminationEnabled;
aToRebuildShaders = Standard_True;
}
return safeFailBack ("Ray-tracing requires EXT_framebuffer_blit extension", theGlContext);
}
- myRaytraceParameters.NbBounces = theCView.RenderParams.RaytracingDepth;
+ myRaytraceParameters.NbBounces = myRenderParams.RaytracingDepth;
TCollection_AsciiString aFolder = Graphic3d_ShaderProgram::ShadersFolder();
aShaderProgram->GetUniformLocation (theGlContext, "uSphereMapEnabled");
myUniformLocations[anIndex][OpenGl_RT_uSphereMapForBack] =
aShaderProgram->GetUniformLocation (theGlContext, "uSphereMapForBack");
+ myUniformLocations[anIndex][OpenGl_RT_uBlockedRngEnabled] =
+ aShaderProgram->GetUniformLocation (theGlContext, "uBlockedRngEnabled");
myUniformLocations[anIndex][OpenGl_RT_uSampleWeight] =
aShaderProgram->GetUniformLocation (theGlContext, "uSampleWeight");
nullifyResource (theGlContext, myRaytraceLightSrcTexture);
nullifyResource (theGlContext, myRaytraceMaterialTexture);
+ myRaytraceGeometry.ReleaseResources (theGlContext);
+
if (myRaytraceScreenQuad.IsValid())
myRaytraceScreenQuad.Release (theGlContext.operator->());
}
aDirect = aDirect - aOrigin;
- GLdouble aInvLen = 1.0 / sqrt (aDirect.x() * aDirect.x() +
- aDirect.y() * aDirect.y() +
- aDirect.z() * aDirect.z());
-
theOrigins[aOriginIndex++] = OpenGl_Vec3 (static_cast<GLfloat> (aOrigin.x()),
static_cast<GLfloat> (aOrigin.y()),
static_cast<GLfloat> (aOrigin.z()));
- theDirects[aDirectIndex++] = OpenGl_Vec3 (static_cast<GLfloat> (aDirect.x() * aInvLen),
- static_cast<GLfloat> (aDirect.y() * aInvLen),
- static_cast<GLfloat> (aDirect.z() * aInvLen));
+ theDirects[aDirectIndex++] = OpenGl_Vec3 (static_cast<GLfloat> (aDirect.x()),
+ static_cast<GLfloat> (aDirect.y()),
+ static_cast<GLfloat> (aDirect.z()));
}
}
}
myRaytraceGeometry.Ambient = BVH_Vec4f (0.0f, 0.0f, 0.0f, 0.0f);
- for (OpenGl_ListOfLight::Iterator aLightIter (myLights); aLightIter.More(); aLightIter.Next())
+ OpenGl_ListOfLight::Iterator aLightIter (myShadingModel == Graphic3d_TOSM_NONE ? OpenGl_NoShadingLight() : myLights);
+ for (; aLightIter.More(); aLightIter.Next())
{
const OpenGl_Light& aLight = aLightIter.Value();
- if (aLight.Type == Visual3d_TOLS_AMBIENT)
+ if (aLight.Type == Graphic3d_TOLS_AMBIENT)
{
myRaytraceGeometry.Ambient += BVH_Vec4f (aLight.Color.r() * aLight.Intensity,
aLight.Color.g() * aLight.Intensity,
-aLight.Direction.z(),
0.0f);
- if (aLight.Type != Visual3d_TOLS_DIRECTIONAL)
+ if (aLight.Type != Graphic3d_TOLS_DIRECTIONAL)
{
aPosition = BVH_Vec4f (aLight.Position.x(),
aLight.Position.y(),
{
aResult &= theGlContext->BindProgram (aProgram);
- if (!myTextureEnv.IsNull() && mySurfaceDetail != Visual3d_TOD_NONE)
+ if (!myTextureEnv.IsNull() && mySurfaceDetail != Graphic3d_TOD_NONE)
{
myTextureEnv->Bind (theGlContext,
GL_TEXTURE0 + OpenGl_RT_EnvironmentMapTexture);
// function : setUniformState
// purpose : Sets uniform state for the given ray-tracing shader program
// =======================================================================
-Standard_Boolean OpenGl_View::setUniformState (const Graphic3d_CView& theCView,
- const OpenGl_Vec3* theOrigins,
+Standard_Boolean OpenGl_View::setUniformState (const OpenGl_Vec3* theOrigins,
const OpenGl_Vec3* theDirects,
const OpenGl_Mat4& theUnviewMat,
const Standard_Integer theProgramId,
// Set run-time rendering options
theProgram->SetUniform (theGlContext,
- myUniformLocations[theProgramId][OpenGl_RT_uShadowsEnabled], theCView.RenderParams.IsShadowEnabled ? 1 : 0);
+ myUniformLocations[theProgramId][OpenGl_RT_uShadowsEnabled], myRenderParams.IsShadowEnabled ? 1 : 0);
theProgram->SetUniform (theGlContext,
- myUniformLocations[theProgramId][OpenGl_RT_uReflectEnabled], theCView.RenderParams.IsReflectionEnabled ? 1 : 0);
+ myUniformLocations[theProgramId][OpenGl_RT_uReflectEnabled], myRenderParams.IsReflectionEnabled ? 1 : 0);
+
+ if (myRenderParams.IsGlobalIlluminationEnabled)
+ {
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uBlockedRngEnabled], myRenderParams.CoherentPathTracingMode ? 1 : 0);
+ }
// Set array of 64-bit texture handles
if (theGlContext->arbTexBindless != NULL && myRaytraceGeometry.HasTextures())
{
+ const std::vector<GLuint64>& aTextures = myRaytraceGeometry.TextureHandles();
+
theProgram->SetUniform (theGlContext, myUniformLocations[theProgramId][OpenGl_RT_uTexSamplersArray],
- static_cast<GLsizei> (myRaytraceGeometry.TextureHandles().size()), &myRaytraceGeometry.TextureHandles()[0]);
+ static_cast<GLsizei> (aTextures.size()), (OpenGl_Vec2u* )&aTextures.front());
}
// Set background colors (only gradient background supported)
- if (myBgGradientArray != NULL)
+ if (myBgGradientArray != NULL
+ && myBgGradientArray->IsDefined())
{
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uBackColorTop], myBgGradientArray->GradientColor (0));
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uBackColorBot], myBgGradientArray->GradientColor (1));
}
+ else
+ {
+ const OpenGl_Vec4 aBackColor (myBgColor.rgb[0],
+ myBgColor.rgb[1],
+ myBgColor.rgb[2],
+ 1.0f);
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uBackColorTop], aBackColor);
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uBackColorBot], aBackColor);
+ }
theProgram->SetUniform (theGlContext,
- myUniformLocations[theProgramId][OpenGl_RT_uSphereMapForBack], theCView.RenderParams.UseEnvironmentMapBackground ? 1 : 0);
+ myUniformLocations[theProgramId][OpenGl_RT_uSphereMapForBack], myRenderParams.UseEnvironmentMapBackground ? 1 : 0);
return Standard_True;
}
// function : runRaytraceShaders
// purpose : Runs ray-tracing shader programs
// =======================================================================
-Standard_Boolean OpenGl_View::runRaytraceShaders (const Graphic3d_CView& theCView,
- const Standard_Integer theSizeX,
+Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
const OpenGl_Vec3* theOrigins,
const OpenGl_Vec3* theDirects,
aRenderFramebuffer->BindBuffer (theGlContext);
}
- else if (theCView.RenderParams.IsAntialiasingEnabled) // if 2-pass ray-tracing is used
+ else if (myRenderParams.IsAntialiasingEnabled) // if 2-pass ray-tracing is used
{
myRaytraceFBO1->BindBuffer (theGlContext);
Standard_Boolean aResult = theGlContext->BindProgram (myRaytraceProgram);
- aResult &= setUniformState (theCView,
- theOrigins,
+ aResult &= setUniformState (theOrigins,
theDirects,
theUnviewMat,
0, // ID of RT program
if (myRaytraceParameters.GlobalIllumination)
{
+ if (myAccumFrames == 0)
+ {
+ myRNG.SetSeed();
+ }
+
// Set frame accumulation weight
myRaytraceProgram->SetUniform (theGlContext,
myUniformLocations[0][OpenGl_RT_uSampleWeight], 1.f / (myAccumFrames + 1));
++myAccumFrames;
}
- else if (theCView.RenderParams.IsAntialiasingEnabled)
+ else if (myRenderParams.IsAntialiasingEnabled)
{
myRaytraceFBO1->ColorTexture()->Bind (theGlContext, GL_TEXTURE0 + OpenGl_RT_FsaaInputTexture);
aResult &= theGlContext->BindProgram (myPostFSAAProgram);
- aResult &= setUniformState (theCView,
- theOrigins,
+ aResult &= setUniformState (theOrigins,
theDirects,
theUnviewMat,
1, // ID of FSAA program
// function : raytrace
// purpose : Redraws the window using OpenGL/GLSL ray-tracing
// =======================================================================
-Standard_Boolean OpenGl_View::raytrace (const Graphic3d_CView& theCView,
- const Standard_Integer theSizeX,
+Standard_Boolean OpenGl_View::raytrace (const Standard_Integer theSizeX,
const Standard_Integer theSizeY,
OpenGl_FrameBuffer* theReadDrawFbo,
const Handle(OpenGl_Context)& theGlContext)
{
- if (!initRaytraceResources (theCView, theGlContext))
+ if (!initRaytraceResources (theGlContext))
{
return Standard_False;
}
0, GL_DEBUG_SEVERITY_MEDIUM_ARB, "Error: Failed to acquire OpenGL image textures");
}
- Standard_Boolean aResult = runRaytraceShaders (theCView,
- theSizeX,
+ Standard_Boolean aResult = runRaytraceShaders (theSizeX,
theSizeY,
aOrigins,
aDirects,
glEnable (GL_DEPTH_TEST);
return Standard_True;
-}
\ No newline at end of file
+}