AdaptiveScreenSampling (Standard_False),
ShowSamplingTiles (Standard_False),
TwoSidedBsdfModels (Standard_False),
+ RadianceClampingValue (30.0),
RebuildRayTracingShaders (Standard_False),
// stereoscopic parameters
StereoMode (Graphic3d_StereoMode_QuadBuffer),
Standard_Boolean AdaptiveScreenSampling; //!< enables/disables adaptive screen sampling mode for path tracing, FALSE by default
Standard_Boolean ShowSamplingTiles; //!< enables/disables debug mode for adaptive screen sampling, FALSE by default
Standard_Boolean TwoSidedBsdfModels; //!< forces path tracing to use two-sided versions of original one-sided scattering models
+ Standard_ShortReal RadianceClampingValue; //!< maximum radiance value used for clamping radiance estimation.
Standard_Boolean RebuildRayTracingShaders; //!< forces rebuilding ray tracing shaders at the next frame
Graphic3d_StereoMode StereoMode; //!< stereoscopic output mode, Graphic3d_StereoMode_QuadBuffer by default
OpenGl_RT_uOffsetY,
OpenGl_RT_uSamples,
- // adaptive path tracing images
+ // images used by ISS mode
OpenGl_RT_uRenderImage,
OpenGl_RT_uOffsetImage,
+ // maximum radiance value
+ OpenGl_RT_uMaxRadiance,
+
OpenGl_RT_NbVariables // special field
};
//! Enables/disables adaptive screen sampling for path tracing.
Standard_Boolean AdaptiveScreenSampling;
+ //! Enables/disables environment map for background.
+ Standard_Boolean UseEnvMapForBackground;
+
+ //! Maximum radiance value used for clamping radiance estimation.
+ Standard_ShortReal RadianceClampingValue;
+
//! Creates default compile-time ray-tracing parameters.
RaytracingParams()
- : StackSize (THE_DEFAULT_STACK_SIZE),
- NbBounces (THE_DEFAULT_NB_BOUNCES),
+ : StackSize (THE_DEFAULT_STACK_SIZE),
+ NbBounces (THE_DEFAULT_NB_BOUNCES),
TransparentShadows (Standard_False),
GlobalIllumination (Standard_False),
UseBindlessTextures (Standard_False),
TwoSidedBsdfModels (Standard_False),
- AdaptiveScreenSampling (Standard_False) { }
+ AdaptiveScreenSampling (Standard_False),
+ UseEnvMapForBackground (Standard_False),
+ RadianceClampingValue (30.0) { }
};
//! Describes state of OpenGL structure.
aShaderProgram->GetUniformLocation (theGlContext, "uBackColorTop");
myUniformLocations[anIndex][OpenGl_RT_uBackColorBot] =
aShaderProgram->GetUniformLocation (theGlContext, "uBackColorBot");
+
+ myUniformLocations[anIndex][OpenGl_RT_uMaxRadiance] =
+ aShaderProgram->GetUniformLocation (theGlContext, "uMaxRadiance");
}
theGlContext->BindProgram (myOutImageProgram);
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uUnviewMat], anUnviewMat);
- // Set ray-tracing intersection parameters
+ // Set screen dimensions
+ myRaytraceProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uWinSizeX], theWinSizeX);
+ myRaytraceProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uWinSizeY], theWinSizeY);
+
+ // Set 3D scene parameters
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uSceneRad], myRaytraceSceneRadius);
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uSceneEps], myRaytraceSceneEpsilon);
+ // Set light source parameters
const Standard_Integer aLightSourceBufferSize =
static_cast<Standard_Integer> (myRaytraceGeometry.Sources.size());
-
- // Set ray-tracing light source parameters
+
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uLightCount], aLightSourceBufferSize);
- theProgram->SetUniform (theGlContext,
- myUniformLocations[theProgramId][OpenGl_RT_uLightAmbnt], myRaytraceGeometry.Ambient);
-
- // Enable/disable run-time rendering effects
- theProgram->SetUniform (theGlContext,
- myUniformLocations[theProgramId][OpenGl_RT_uShadowsEnabled], myRenderParams.IsShadowEnabled ? 1 : 0);
- theProgram->SetUniform (theGlContext,
- myUniformLocations[theProgramId][OpenGl_RT_uReflectEnabled], myRenderParams.IsReflectionEnabled ? 1 : 0);
-
- // Set screen dimensions
- myRaytraceProgram->SetUniform (theGlContext,
- myUniformLocations[theProgramId][OpenGl_RT_uWinSizeX], theWinSizeX);
- myRaytraceProgram->SetUniform (theGlContext,
- myUniformLocations[theProgramId][OpenGl_RT_uWinSizeY], theWinSizeY);
-
- if (myRenderParams.IsGlobalIlluminationEnabled) // if Monte-Carlo sampling enabled
- {
- 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())
myUniformLocations[theProgramId][OpenGl_RT_uBackColorBot], aBackColor);
}
+ // Set environment map parameters
const Standard_Boolean toDisableEnvironmentMap = myTextureEnv.IsNull() || !myTextureEnv->IsValid();
theProgram->SetUniform (theGlContext,
theProgram->SetUniform (theGlContext,
myUniformLocations[theProgramId][OpenGl_RT_uSphereMapForBack], myRenderParams.UseEnvironmentMapBackground ? 1 : 0);
+ if (myRenderParams.IsGlobalIlluminationEnabled) // GI parameters
+ {
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uMaxRadiance], myRenderParams.RadianceClampingValue);
+
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uBlockedRngEnabled], myRenderParams.CoherentPathTracingMode ? 1 : 0);
+
+ // Check whether we should restart accumulation for run-time parameters
+ if (myRenderParams.RadianceClampingValue != myRaytraceParameters.RadianceClampingValue
+ || myRenderParams.UseEnvironmentMapBackground != myRaytraceParameters.UseEnvMapForBackground)
+ {
+ myAccumFrames = 0; // accumulation should be restarted
+
+ myRaytraceParameters.RadianceClampingValue = myRenderParams.RadianceClampingValue;
+ myRaytraceParameters.UseEnvMapForBackground = myRenderParams.UseEnvironmentMapBackground;
+ }
+ }
+ else // RT parameters
+ {
+ // Set ambient light source
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uLightAmbnt], myRaytraceGeometry.Ambient);
+
+ // Enable/disable run-time ray-tracing effects
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uShadowsEnabled], myRenderParams.IsShadowEnabled ? 1 : 0);
+ theProgram->SetUniform (theGlContext,
+ myUniformLocations[theProgramId][OpenGl_RT_uReflectEnabled], myRenderParams.IsReflectionEnabled ? 1 : 0);
+ }
+
return Standard_True;
}
vec4 aTexColor = textureLod (
sampler2D (uTextureSamplers[int (aMaterial.Kd.w)]), aTexCoord.st, 0.f);
- aMaterial.Kd.rgb *= (aTexColor.rgb, aTexColor.rgb) * aTexColor.w; // de-gamma correction (for gamma = 2)
+ aMaterial.Kd.rgb *= (aTexColor.rgb * aTexColor.rgb) * aTexColor.w; // de-gamma correction (for gamma = 2)
if (aTexColor.w != 1.0f)
{
uniform sampler2D uAccumTexture;
#endif
-//! Maximum radiance that can be added to the pixel. Decreases noise
-//! level, but introduces some bias.
-#define MAX_RADIANCE vec3 (50.f)
+//! Maximum radiance that can be added to the pixel.
+//! Decreases noise level, but introduces some bias.
+uniform float uMaxRadiance = 50.f;
// =======================================================================
// function : main
aColor.rgb = ZERO;
}
- aColor.rgb = min (aColor.rgb, MAX_RADIANCE);
+ aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance));
#ifdef ADAPTIVE_SAMPLING
" vec4 aTexColor = textureLod (\n"
" sampler2D (uTextureSamplers[int (aMaterial.Kd.w)]), aTexCoord.st, 0.f);\n"
"\n"
- " aMaterial.Kd.rgb *= (aTexColor.rgb, aTexColor.rgb) * aTexColor.w; // de-gamma correction (for gamma = 2)\n"
+ " aMaterial.Kd.rgb *= (aTexColor.rgb * aTexColor.rgb) * aTexColor.w; // de-gamma correction (for gamma = 2)\n"
"\n"
" if (aTexColor.w != 1.0f)\n"
" {\n"
" uniform sampler2D uAccumTexture;\n"
"#endif\n"
"\n"
- "//! Maximum radiance that can be added to the pixel. Decreases noise\n"
- "//! level, but introduces some bias.\n"
- "#define MAX_RADIANCE vec3 (50.f)\n"
+ "//! Maximum radiance that can be added to the pixel.\n"
+ "//! Decreases noise level, but introduces some bias.\n"
+ "uniform float uMaxRadiance = 50.f;\n"
"\n"
"// =======================================================================\n"
"// function : main\n"
" aColor.rgb = ZERO;\n"
" }\n"
"\n"
- " aColor.rgb = min (aColor.rgb, MAX_RADIANCE);\n"
+ " aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance));\n"
"\n"
"#ifdef ADAPTIVE_SAMPLING\n"
"\n"
theDI << "iss: " << (aParams.AdaptiveScreenSampling ? "on" : "off") << "\n";
theDI << "iss debug: " << (aParams.ShowSamplingTiles ? "on" : "off") << "\n";
theDI << "two-sided BSDF: " << (aParams.TwoSidedBsdfModels ? "on" : "off") << "\n";
+ theDI << "max radiance: " << aParams.RadianceClampingValue << "\n";
theDI << "shadingModel: ";
switch (aView->ShadingModel())
{
}
aParams.CoherentPathTracingMode = toEnable;
}
+ else if (aFlag == "-maxrad")
+ {
+ if (toPrint)
+ {
+ theDI << aParams.RadianceClampingValue << " ";
+ continue;
+ }
+ else if (++anArgIter >= theArgNb)
+ {
+ std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
+ return 1;
+ }
+
+ const TCollection_AsciiString aMaxRadStr = theArgVec[anArgIter];
+ if (!aMaxRadStr.IsRealValue())
+ {
+ std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
+ return 1;
+ }
+
+ const Standard_Real aMaxRadiance = aMaxRadStr.RealValue();
+ if (aMaxRadiance <= 0.0)
+ {
+ std::cerr << "Error: invalid radiance clamping value " << aMaxRadiance << ".\n";
+ return 1;
+ }
+ else
+ {
+ aParams.RadianceClampingValue = static_cast<Standard_ShortReal> (aMaxRadiance);
+ }
+ }
else if (aFlag == "-iss")
{
if (toPrint)
"\n '-twoside on|off' Enables/disables two-sided BSDF models (PT mode)"
"\n '-iss on|off' Enables/disables adaptive screen sampling (PT mode)"
"\n '-issd on|off' Shows screen sampling distribution in ISS mode"
+ "\n '-maxrad > 0.0' Value used for clamping radiance estimation (PT mode)"
"\n '-rebuildGlsl on|off' Rebuild Ray-Tracing GLSL programs (for debugging)"
"\n '-shadingModel model' Controls shading model from enumeration"
"\n color, flat, gouraud, phong"
--- /dev/null
+puts "============"
+puts "Visualization - Path Tracing, Cube sample with radiance clamping"
+puts "============"
+puts ""
+
+source $env(CSF_OCCTSamplesPath)/tcl/pathtrace_cube.tcl
+
+vrenderparams -maxrad 1.0
+vfps 100
+vdump $imagedir/${casename}_1.png
+
+vrenderparams -maxrad 2.0
+vfps 100
+vdump $imagedir/${casename}_2.png
+
+vrenderparams -maxrad 10.0
+vfps 100
+vdump $imagedir/${casename}_10.png
+
+vrenderparams -maxrad 100.0
+vfps 100
+vdump $imagedir/${casename}_100.png
\ No newline at end of file