aShaderProgram->GetUniformLocation (theGlContext, "uDirectLT");
myUniformLocations[anIndex][OpenGl_RT_uDirectRT] =
aShaderProgram->GetUniformLocation (theGlContext, "uDirectRT");
+ myUniformLocations[anIndex][OpenGl_RT_uViewMat] =
+ aShaderProgram->GetUniformLocation (theGlContext, "uViewMat");
myUniformLocations[anIndex][OpenGl_RT_uUnviewMat] =
aShaderProgram->GetUniformLocation (theGlContext, "uUnviewMat");
myOutImageProgram->SetSampler (theGlContext,
"uInputTexture", OpenGl_RT_PrevAccumTexture);
+ myOutImageProgram->SetSampler (theGlContext,
+ "uDepthTexture", OpenGl_RT_DepthTexture);
+
theGlContext->BindProgram (NULL);
}
const OpenGl_Mat4& theViewMapping,
OpenGl_Vec3* theOrigins,
OpenGl_Vec3* theDirects,
+ OpenGl_Mat4& theView,
OpenGl_Mat4& theUnview)
{
- // compute inverse model-view-projection matrix
- (theViewMapping * theOrientation).Inverted (theUnview);
+ // compute view-projection matrix
+ theView = theViewMapping * theOrientation;
+
+ // compute inverse view-projection matrix
+ theView.Inverted (theUnview);
Standard_Integer aOriginIndex = 0;
Standard_Integer aDirectIndex = 0;
// =======================================================================
Standard_Boolean OpenGl_View::setUniformState (const OpenGl_Vec3* theOrigins,
const OpenGl_Vec3* theDirects,
+ const OpenGl_Mat4& theViewMat,
const OpenGl_Mat4& theUnviewMat,
const Standard_Integer theProgramId,
const Handle(OpenGl_Context)& theGlContext)
myUniformLocations[theProgramId][OpenGl_RT_uDirectLT], theDirects[2]);
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uDirectRT], theDirects[3]);
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uViewMat], theViewMat);
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uUnviewMat], theUnviewMat);
const Standard_Integer theSizeY,
const OpenGl_Vec3* theOrigins,
const OpenGl_Vec3* theDirects,
+ const OpenGl_Mat4& theViewMat,
const OpenGl_Mat4& theUnviewMat,
Graphic3d_Camera::Projection theProjection,
OpenGl_FrameBuffer* theReadDrawFbo,
else if (myRenderParams.IsAntialiasingEnabled) // if 2-pass ray-tracing is used
{
myRaytraceFBO1[aFBOIdx]->BindBuffer (theGlContext);
-
- glDisable (GL_BLEND);
}
Standard_Boolean aResult = theGlContext->BindProgram (myRaytraceProgram);
aResult &= setUniformState (theOrigins,
theDirects,
+ theViewMat,
theUnviewMat,
0, // ID of RT program
theGlContext);
if (myRaytraceParameters.GlobalIllumination)
{
// Output accumulated image
- glDisable (GL_BLEND);
-
theGlContext->BindProgram (myOutImageProgram);
if (theReadDrawFbo != NULL)
aRenderFramebuffer->ColorTexture()->Bind (
theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
+ aRenderFramebuffer->DepthStencilTexture()->Bind (
+ theGlContext, GL_TEXTURE0 + OpenGl_RT_DepthTexture);
+
theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
+
+ aRenderFramebuffer->DepthStencilTexture()->Unbind (
+ theGlContext, GL_TEXTURE0 + OpenGl_RT_DepthTexture);
+
+ aRenderFramebuffer->ColorTexture()->Unbind (
+ theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
}
else if (myRenderParams.IsAntialiasingEnabled)
{
aResult &= setUniformState (theOrigins,
theDirects,
+ theViewMat,
theUnviewMat,
1, // ID of FSAA program
theGlContext);
OpenGl_Vec3 aOrigins[4];
OpenGl_Vec3 aDirects[4];
+ OpenGl_Mat4 aViewMat;
OpenGl_Mat4 anUnviewMat;
updateCamera (aOrientationMatrix,
aViewMappingMatrix,
aOrigins,
aDirects,
+ aViewMat,
anUnviewMat);
- glDisable (GL_BLEND);
- glDisable (GL_DEPTH_TEST);
-
if (theReadDrawFbo != NULL)
{
theReadDrawFbo->BindBuffer (theGlContext);
0, GL_DEBUG_SEVERITY_MEDIUM, "Error: Failed to acquire OpenGL image textures");
}
+ // Remember the old depth function
+ GLint aDepthFunc;
+ theGlContext->core11fwd->glGetIntegerv (GL_DEPTH_FUNC, &aDepthFunc);
+
+ glDisable (GL_BLEND);
+ glDepthFunc (GL_ALWAYS);
+
Standard_Boolean aResult = runRaytraceShaders (theSizeX,
theSizeY,
aOrigins,
aDirects,
+ aViewMat,
anUnviewMat,
theProjection,
theReadDrawFbo,
theGlContext);
+ // Restore depth function
+ glDepthFunc (aDepthFunc);
+
if (!aResult)
{
theGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_ERROR,
myRaytraceScreenQuad.UnbindVertexAttrib (theGlContext, Graphic3d_TOA_POS);
}
- glDisable (GL_BLEND);
- glEnable (GL_DEPTH_TEST);
-
return Standard_True;
}