0028794: Visualization, Ray tracing - Implement tone mapping
[occt.git] / src / OpenGl / OpenGl_View_Raytrace.cxx
index 02d69d1..88c7682 100644 (file)
@@ -1148,6 +1148,15 @@ TCollection_AsciiString OpenGl_View::generateShaderPrefix (const Handle(OpenGl_C
     {
       aPrefixString += TCollection_AsciiString ("\n#define TWO_SIDED_BXDF");
     }
+
+    switch (myRaytraceParameters.ToneMappingMethod)
+    {
+      case Graphic3d_ToneMappingMethod_Disabled:
+        break;
+      case Graphic3d_ToneMappingMethod_Filmic:
+        aPrefixString += TCollection_AsciiString ("\n#define TONE_MAPPING_FILMIC");
+        break;
+    }
   }
 
   return aPrefixString;
@@ -1412,6 +1421,12 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
       aToRebuildShaders = Standard_True;
     }
 
+    if (myRenderParams.ToneMappingMethod != myRaytraceParameters.ToneMappingMethod)
+    {
+      myRaytraceParameters.ToneMappingMethod = myRenderParams.ToneMappingMethod;
+      aToRebuildShaders = true;
+    }
+
     if (aToRebuildShaders)
     {
       // Reject accumulated frames
@@ -2931,6 +2946,19 @@ Standard_Boolean OpenGl_View::runPathtrace (const Standard_Integer
     myOutImageProgram->SetUniform (theGlContext, "uDebugAdaptive", myRenderParams.ShowSamplingTiles ?  1 : 0);
   }
 
+  if (myRaytraceParameters.GlobalIllumination)
+  {
+    myOutImageProgram->SetUniform(theGlContext, "uExposure", myRenderParams.Exposure);
+    switch (myRaytraceParameters.ToneMappingMethod)
+    {
+      case Graphic3d_ToneMappingMethod_Disabled:
+        break;
+      case Graphic3d_ToneMappingMethod_Filmic:
+        myOutImageProgram->SetUniform (theGlContext, "uWhitePoint", myRenderParams.WhitePoint);
+        break;
+    }
+  }
+
   if (theReadDrawFbo != NULL)
   {
     theReadDrawFbo->BindBuffer (theGlContext);