1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

0031196: Visualization, TKOpenGl - enable Ray-Tracing using OpenGL ES 3.2

OpenGl_Context now activates Ray-Tracing and arbTboRGB32 for GLES 3.2.
Removed initialization of some uniforms from GLSL code.
Fixed implicit casts within Ray-Tracing shaders.
This commit is contained in:
kgv 2021-02-20 15:01:16 +03:00 committed by bugmaster
parent 127330f9d7
commit 93cdaa76da
16 changed files with 133 additions and 161 deletions

View File

@ -391,7 +391,7 @@ Ray tracing requires OpenGL 4.0+ or OpenGL 3.3+ with *GL_ARB_texture_buffer_obje
Textures within ray tracing will be available only when *GL_ARB_bindless_texture extension* is provided by driver. Textures within ray tracing will be available only when *GL_ARB_bindless_texture extension* is provided by driver.
On mobile platforms, OpenGL ES 2.0+ is required for 3D viewer (OpenGL ES 3.1+ is recommended). On mobile platforms, OpenGL ES 2.0+ is required for 3D viewer (OpenGL ES 3.1+ is recommended).
The ray tracing is not yet available on mobile platforms. Ray tracing requires OpenGL ES 3.2.
Some old hardware might be unable to execute complex GLSL programs (e.g. with high number of light sources, clipping planes). Some old hardware might be unable to execute complex GLSL programs (e.g. with high number of light sources, clipping planes).
OCCT 3D Viewer, in general, supports wide range of graphics hardware - from very old to new. OCCT 3D Viewer, in general, supports wide range of graphics hardware - from very old to new.

View File

@ -1619,7 +1619,13 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
// get number of maximum clipping planes // get number of maximum clipping planes
glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes); glGetIntegerv (GL_MAX_CLIP_PLANES, &myMaxClipPlanes);
#endif
#if defined(GL_ES_VERSION_2_0)
// check whether ray tracing mode is supported
myHasRayTracing = IsGlGreaterEqual (3, 2);
myHasRayTracingTextures = myHasRayTracingAdaptiveSampling = myHasRayTracingAdaptiveSamplingAtomic = false;
#else
// check whether ray tracing mode is supported // check whether ray tracing mode is supported
myHasRayTracing = IsGlGreaterEqual (3, 1) myHasRayTracing = IsGlGreaterEqual (3, 1)
&& arbTboRGB32 && arbTboRGB32

View File

@ -1103,7 +1103,7 @@ public: //! @name extensions
OpenGl_ArbSamplerObject* arbSamplerObject; //!< GL_ARB_sampler_objects (on desktop OpenGL - since 3.3 or as extension GL_ARB_sampler_objects; on OpenGL ES - since 3.0) OpenGl_ArbSamplerObject* arbSamplerObject; //!< GL_ARB_sampler_objects (on desktop OpenGL - since 3.3 or as extension GL_ARB_sampler_objects; on OpenGL ES - since 3.0)
OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture OpenGl_ArbTexBindless* arbTexBindless; //!< GL_ARB_bindless_texture
OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object (on desktop OpenGL - since 3.1 or as extension GL_ARB_texture_buffer_object; on OpenGL ES - since 3.2) OpenGl_ArbTBO* arbTBO; //!< GL_ARB_texture_buffer_object (on desktop OpenGL - since 3.1 or as extension GL_ARB_texture_buffer_object; on OpenGL ES - since 3.2)
Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0 Standard_Boolean arbTboRGB32; //!< GL_ARB_texture_buffer_object_rgb32 (3-component TBO), in core since 4.0 (on OpenGL ES - since 3.2)
OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced (on desktop OpenGL - since 3.1 or as extension GL_ARB_draw_instanced; on OpenGL ES - since 3.0 or as extension GL_ANGLE_instanced_arrays to WebGL 1.0) OpenGl_ArbIns* arbIns; //!< GL_ARB_draw_instanced (on desktop OpenGL - since 3.1 or as extension GL_ARB_draw_instanced; on OpenGL ES - since 3.0 or as extension GL_ANGLE_instanced_arrays to WebGL 1.0)
OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output (on desktop OpenGL - since 4.3 or as extension GL_ARB_debug_output; on OpenGL ES - since 3.2 or as extension GL_KHR_debug) OpenGl_ArbDbg* arbDbg; //!< GL_ARB_debug_output (on desktop OpenGL - since 4.3 or as extension GL_ARB_debug_output; on OpenGL ES - since 3.2 or as extension GL_KHR_debug)
OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object OpenGl_ArbFBO* arbFBO; //!< GL_ARB_framebuffer_object

View File

@ -440,6 +440,7 @@ void OpenGl_GlFunctions::load (OpenGl_Context& theCtx,
theCtx.checkWrongVersion (3, 2, aLastFailedProc); theCtx.checkWrongVersion (3, 2, aLastFailedProc);
} }
theCtx.arbTboRGB32 = isGlGreaterEqualShort (3, 2); // OpenGL ES 3.2 introduces TBO already supporting RGB32 format
theCtx.extDrawBuffers = checkExtensionShort ("GL_EXT_draw_buffers") && theCtx.FindProc ("glDrawBuffersEXT", this->glDrawBuffers); theCtx.extDrawBuffers = checkExtensionShort ("GL_EXT_draw_buffers") && theCtx.FindProc ("glDrawBuffersEXT", this->glDrawBuffers);
theCtx.arbDrawBuffers = checkExtensionShort ("GL_ARB_draw_buffers") && theCtx.FindProc ("glDrawBuffersARB", this->glDrawBuffers); theCtx.arbDrawBuffers = checkExtensionShort ("GL_ARB_draw_buffers") && theCtx.FindProc ("glDrawBuffersARB", this->glDrawBuffers);

View File

@ -660,8 +660,7 @@ protected: //! @name data types related to ray-tracing
OpenGl_RT_uFrameRndSeed, OpenGl_RT_uFrameRndSeed,
// adaptive FSAA params // adaptive FSAA params
OpenGl_RT_uOffsetX, OpenGl_RT_uFsaaOffset,
OpenGl_RT_uOffsetY,
OpenGl_RT_uSamples, OpenGl_RT_uSamples,
// images used by ISS mode // images used by ISS mode
@ -721,7 +720,8 @@ protected: //! @name data types related to ray-tracing
} }
//! Returns shader source combined with prefix. //! Returns shader source combined with prefix.
TCollection_AsciiString Source() const; TCollection_AsciiString Source (const Handle(OpenGl_Context)& theCtx,
const GLenum theType) const;
//! Loads shader source from specified files. //! Loads shader source from specified files.
Standard_Boolean LoadFromFiles (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX); Standard_Boolean LoadFromFiles (const TCollection_AsciiString* theFileNames, const TCollection_AsciiString& thePrefix = EMPTY_PREFIX);

View File

@ -1023,16 +1023,37 @@ const TCollection_AsciiString OpenGl_View::ShaderSource::EMPTY_PREFIX;
// function : Source // function : Source
// purpose : Returns shader source combined with prefix // purpose : Returns shader source combined with prefix
// ======================================================================= // =======================================================================
TCollection_AsciiString OpenGl_View::ShaderSource::Source() const TCollection_AsciiString OpenGl_View::ShaderSource::Source (const Handle(OpenGl_Context)& theCtx,
const GLenum theType) const
{ {
const TCollection_AsciiString aVersion = "#version 140"; TCollection_AsciiString aVersion =
#if defined(GL_ES_VERSION_2_0)
"#version 320 es\n";
#else
"#version 140\n";
#endif
TCollection_AsciiString aPrecisionHeader;
if (theType == GL_FRAGMENT_SHADER)
{
#if defined(GL_ES_VERSION_2_0)
aPrecisionHeader = theCtx->hasHighp
? "precision highp float;\n"
"precision highp int;\n"
"precision highp samplerBuffer;\n"
"precision highp isamplerBuffer;\n"
: "precision mediump float;\n"
"precision mediump int;\n"
"precision mediump samplerBuffer;\n"
"precision mediump isamplerBuffer;\n";
#else
(void )theCtx;
#endif
}
if (myPrefix.IsEmpty()) if (myPrefix.IsEmpty())
{ {
return aVersion + "\n" + mySource; return aVersion + aPrecisionHeader + mySource;
} }
return aVersion + aPrecisionHeader + myPrefix + "\n" + mySource;
return aVersion + "\n" + myPrefix + "\n" + mySource;
} }
// ======================================================================= // =======================================================================
@ -1220,7 +1241,7 @@ Handle(OpenGl_ShaderObject) OpenGl_View::initShader (const GLenum
return Handle(OpenGl_ShaderObject)(); return Handle(OpenGl_ShaderObject)();
} }
if (!aShader->LoadAndCompile (theGlContext, "", theSource.Source())) if (!aShader->LoadAndCompile (theGlContext, "", theSource.Source (theGlContext, theType)))
{ {
aShader->Release (theGlContext.get()); aShader->Release (theGlContext.get());
return Handle(OpenGl_ShaderObject)(); return Handle(OpenGl_ShaderObject)();
@ -1416,18 +1437,15 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Standard_Integer theS
myToUpdateEnvironmentMap = Standard_True; myToUpdateEnvironmentMap = Standard_True;
const TCollection_AsciiString aPrefixString = generateShaderPrefix (theGlContext); const TCollection_AsciiString aPrefixString = generateShaderPrefix (theGlContext);
#ifdef RAY_TRACE_PRINT_INFO #ifdef RAY_TRACE_PRINT_INFO
std::cout << "GLSL prefix string:" << std::endl << aPrefixString << std::endl; Message::SendTrace() << "GLSL prefix string:" << std::endl << aPrefixString;
#endif #endif
myRaytraceShaderSource.SetPrefix (aPrefixString); myRaytraceShaderSource.SetPrefix (aPrefixString);
myPostFSAAShaderSource.SetPrefix (aPrefixString); myPostFSAAShaderSource.SetPrefix (aPrefixString);
myOutImageShaderSource.SetPrefix (aPrefixString); myOutImageShaderSource.SetPrefix (aPrefixString);
if (!myRaytraceShader->LoadAndCompile (theGlContext, myRaytraceProgram->ResourceId(), myRaytraceShaderSource.Source (theGlContext, GL_FRAGMENT_SHADER))
if (!myRaytraceShader->LoadAndCompile (theGlContext, myRaytraceProgram->ResourceId(), myRaytraceShaderSource.Source()) || !myPostFSAAShader->LoadAndCompile (theGlContext, myPostFSAAProgram->ResourceId(), myPostFSAAShaderSource.Source (theGlContext, GL_FRAGMENT_SHADER))
|| !myPostFSAAShader->LoadAndCompile (theGlContext, myPostFSAAProgram->ResourceId(), myPostFSAAShaderSource.Source()) || !myOutImageShader->LoadAndCompile (theGlContext, myOutImageProgram->ResourceId(), myOutImageShaderSource.Source (theGlContext, GL_FRAGMENT_SHADER)))
|| !myOutImageShader->LoadAndCompile (theGlContext, myOutImageProgram->ResourceId(), myOutImageShaderSource.Source()))
{ {
return safeFailBack ("Failed to compile ray-tracing fragment shaders", theGlContext); return safeFailBack ("Failed to compile ray-tracing fragment shaders", theGlContext);
} }
@ -1435,7 +1453,6 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Standard_Integer theS
myRaytraceProgram->SetAttributeName (theGlContext, Graphic3d_TOA_POS, "occVertex"); myRaytraceProgram->SetAttributeName (theGlContext, Graphic3d_TOA_POS, "occVertex");
myPostFSAAProgram->SetAttributeName (theGlContext, Graphic3d_TOA_POS, "occVertex"); myPostFSAAProgram->SetAttributeName (theGlContext, Graphic3d_TOA_POS, "occVertex");
myOutImageProgram->SetAttributeName (theGlContext, Graphic3d_TOA_POS, "occVertex"); myOutImageProgram->SetAttributeName (theGlContext, Graphic3d_TOA_POS, "occVertex");
if (!myRaytraceProgram->Link (theGlContext) if (!myRaytraceProgram->Link (theGlContext)
|| !myPostFSAAProgram->Link (theGlContext) || !myPostFSAAProgram->Link (theGlContext)
|| !myOutImageProgram->Link (theGlContext)) || !myOutImageProgram->Link (theGlContext))
@ -1449,6 +1466,12 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Standard_Integer theS
{ {
myAccumFrames = 0; // accumulation should be restarted myAccumFrames = 0; // accumulation should be restarted
#if defined(GL_ES_VERSION_2_0)
if (!theGlContext->IsGlGreaterEqual (3, 2))
{
return safeFailBack ("Ray-tracing requires OpenGL ES 3.2 and higher", theGlContext);
}
#else
if (!theGlContext->IsGlGreaterEqual (3, 1)) if (!theGlContext->IsGlGreaterEqual (3, 1))
{ {
return safeFailBack ("Ray-tracing requires OpenGL 3.1 and higher", theGlContext); return safeFailBack ("Ray-tracing requires OpenGL 3.1 and higher", theGlContext);
@ -1461,6 +1484,7 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Standard_Integer theS
{ {
return safeFailBack ("Ray-tracing requires EXT_framebuffer_blit extension", theGlContext); return safeFailBack ("Ray-tracing requires EXT_framebuffer_blit extension", theGlContext);
} }
#endif
myRaytraceParameters.NbBounces = myRenderParams.RaytracingDepth; myRaytraceParameters.NbBounces = myRenderParams.RaytracingDepth;
@ -1474,7 +1498,7 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Standard_Integer theS
const TCollection_AsciiString aPrefixString = generateShaderPrefix (theGlContext); const TCollection_AsciiString aPrefixString = generateShaderPrefix (theGlContext);
#ifdef RAY_TRACE_PRINT_INFO #ifdef RAY_TRACE_PRINT_INFO
std::cout << "GLSL prefix string:" << std::endl << aPrefixString << std::endl; Message::SendTrace() << "GLSL prefix string:" << std::endl << aPrefixString;
#endif #endif
ShaderSource aBasicVertShaderSrc; ShaderSource aBasicVertShaderSrc;
@ -1684,10 +1708,8 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Standard_Integer theS
myUniformLocations[anIndex][OpenGl_RT_uLightAmbnt] = myUniformLocations[anIndex][OpenGl_RT_uLightAmbnt] =
aShaderProgram->GetUniformLocation (theGlContext, "uGlobalAmbient"); aShaderProgram->GetUniformLocation (theGlContext, "uGlobalAmbient");
myUniformLocations[anIndex][OpenGl_RT_uOffsetX] = myUniformLocations[anIndex][OpenGl_RT_uFsaaOffset] =
aShaderProgram->GetUniformLocation (theGlContext, "uOffsetX"); aShaderProgram->GetUniformLocation (theGlContext, "uFsaaOffset");
myUniformLocations[anIndex][OpenGl_RT_uOffsetY] =
aShaderProgram->GetUniformLocation (theGlContext, "uOffsetY");
myUniformLocations[anIndex][OpenGl_RT_uSamples] = myUniformLocations[anIndex][OpenGl_RT_uSamples] =
aShaderProgram->GetUniformLocation (theGlContext, "uSamples"); aShaderProgram->GetUniformLocation (theGlContext, "uSamples");
@ -2083,13 +2105,19 @@ void OpenGl_View::updatePerspCameraPT (const OpenGl_Mat4& theOrientati
// ======================================================================= // =======================================================================
Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext) Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)& theGlContext)
{ {
if (!theGlContext->IsGlGreaterEqual (3, 1)) #if defined(GL_ES_VERSION_2_0)
if (!theGlContext->IsGlGreaterEqual (3, 2))
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendFail() << "Error: OpenGL ES version is less than 3.2";
std::cout << "Error: OpenGL version is less than 3.1" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
#else
if (!theGlContext->IsGlGreaterEqual (3, 1))
{
Message::SendFail() << "Error: OpenGL version is less than 3.1";
return Standard_False;
}
#endif
myAccumFrames = 0; // accumulation should be restarted myAccumFrames = 0; // accumulation should be restarted
@ -2102,9 +2130,7 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
// to get unique 64- bit handles for using on the GPU // to get unique 64- bit handles for using on the GPU
if (!myRaytraceGeometry.UpdateTextureHandles (theGlContext)) if (!myRaytraceGeometry.UpdateTextureHandles (theGlContext))
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to get OpenGL texture handles";
std::cout << "Error: Failed to get OpenGL texture handles" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
} }
@ -2124,9 +2150,7 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
|| !mySceneMaxPointTexture->Create (theGlContext) || !mySceneMaxPointTexture->Create (theGlContext)
|| !mySceneTransformTexture->Create (theGlContext)) || !mySceneTransformTexture->Create (theGlContext))
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to create scene BVH buffers";
std::cout << "Error: Failed to create scene BVH buffers" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
} }
@ -2143,22 +2167,17 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
|| !myGeometryTexCrdTexture->Create (theGlContext) || !myGeometryTexCrdTexture->Create (theGlContext)
|| !myGeometryTriangTexture->Create (theGlContext)) || !myGeometryTriangTexture->Create (theGlContext))
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "\nError: Failed to create buffers for triangulation data";
std::cout << "Error: Failed to create buffers for triangulation data" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
} }
if (myRaytraceMaterialTexture.IsNull()) // create material buffer if (myRaytraceMaterialTexture.IsNull()) // create material buffer
{ {
myRaytraceMaterialTexture = new OpenGl_TextureBufferArb; myRaytraceMaterialTexture = new OpenGl_TextureBufferArb();
if (!myRaytraceMaterialTexture->Create (theGlContext)) if (!myRaytraceMaterialTexture->Create (theGlContext))
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to create buffers for material data";
std::cout << "Error: Failed to create buffers for material data" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
} }
@ -2225,9 +2244,7 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
if (!aResult) if (!aResult)
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to upload buffers for bottom-level scene BVH";
std::cout << "Error: Failed to upload buffers for bottom-level scene BVH" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
@ -2249,9 +2266,7 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
if (!aResult) if (!aResult)
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to upload buffers for scene geometry";
std::cout << "Error: Failed to upload buffers for scene geometry" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
@ -2295,9 +2310,7 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
if (!aResult) if (!aResult)
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to upload buffers for bottom-level scene BVHs";
std::cout << "Error: Failed to upload buffers for bottom-level scene BVHs" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
} }
@ -2330,9 +2343,7 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
if (!aResult) if (!aResult)
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to upload triangulation buffers for OpenGL element";
std::cout << "Error: Failed to upload triangulation buffers for OpenGL element" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
} }
@ -2347,9 +2358,7 @@ Standard_Boolean OpenGl_View::uploadRaytraceData (const Handle(OpenGl_Context)&
if (!aResult) if (!aResult)
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to upload material buffer";
std::cout << "Error: Failed to upload material buffer" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
} }
@ -2506,9 +2515,7 @@ Standard_Boolean OpenGl_View::updateRaytraceLightSources (const OpenGl_Mat4& the
const GLfloat* aDataPtr = myRaytraceGeometry.Sources.front().Packed(); const GLfloat* aDataPtr = myRaytraceGeometry.Sources.front().Packed();
if (!myRaytraceLightSrcTexture->Init (theGlContext, 4, GLsizei (myRaytraceGeometry.Sources.size() * 2), aDataPtr)) if (!myRaytraceLightSrcTexture->Init (theGlContext, 4, GLsizei (myRaytraceGeometry.Sources.size() * 2), aDataPtr))
{ {
#ifdef RAY_TRACE_PRINT_INFO Message::SendTrace() << "Error: Failed to upload light source buffer";
std::cout << "Error: Failed to upload light source buffer" << std::endl;
#endif
return Standard_False; return Standard_False;
} }
@ -2866,31 +2873,27 @@ Standard_Boolean OpenGl_View::runRaytrace (const Standard_Integer theSize
// available from initial ray-traced image). // available from initial ray-traced image).
for (Standard_Integer anIt = 1; anIt < 4; ++anIt) for (Standard_Integer anIt = 1; anIt < 4; ++anIt)
{ {
GLfloat aOffsetX = 1.f / theSizeX; OpenGl_Vec2 aFsaaOffset (1.f / theSizeX, 1.f / theSizeY);
GLfloat aOffsetY = 1.f / theSizeY;
if (anIt == 1) if (anIt == 1)
{ {
aOffsetX *= -0.55f; aFsaaOffset.x() *= -0.55f;
aOffsetY *= 0.55f; aFsaaOffset.y() *= 0.55f;
} }
else if (anIt == 2) else if (anIt == 2)
{ {
aOffsetX *= 0.00f; aFsaaOffset.x() *= 0.00f;
aOffsetY *= -0.55f; aFsaaOffset.y() *= -0.55f;
} }
else if (anIt == 3) else if (anIt == 3)
{ {
aOffsetX *= 0.55f; aFsaaOffset.x() *= 0.55f;
aOffsetY *= 0.00f; aFsaaOffset.y() *= 0.00f;
} }
aResult &= myPostFSAAProgram->SetUniform (theGlContext, aResult &= myPostFSAAProgram->SetUniform (theGlContext,
myUniformLocations[1][OpenGl_RT_uSamples], anIt + 1); myUniformLocations[1][OpenGl_RT_uSamples], anIt + 1);
aResult &= myPostFSAAProgram->SetUniform (theGlContext, aResult &= myPostFSAAProgram->SetUniform (theGlContext,
myUniformLocations[1][OpenGl_RT_uOffsetX], aOffsetX); myUniformLocations[1][OpenGl_RT_uFsaaOffset], aFsaaOffset);
aResult &= myPostFSAAProgram->SetUniform (theGlContext,
myUniformLocations[1][OpenGl_RT_uOffsetY], aOffsetY);
Handle(OpenGl_FrameBuffer)& aFramebuffer = anIt % 2 Handle(OpenGl_FrameBuffer)& aFramebuffer = anIt % 2
? myRaytraceFBO2[aFBOIdx] ? myRaytraceFBO2[aFBOIdx]

View File

@ -126,11 +126,9 @@ void main (void)
else // showing number of samples else // showing number of samples
{ {
vec2 aRatio = vec2 (1.f, 1.f); vec2 aRatio = vec2 (1.f, 1.f);
#ifdef GL_ARB_shader_image_size #ifdef GL_ARB_shader_image_size
aRatio = vec2 (imageSize (uRenderImage)) / vec2 (3.f * 512.f, 2.f * 512.f); aRatio = vec2 (imageSize (uRenderImage)) / vec2 (3.f * 512.f, 2.f * 512.f);
#endif #endif
aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, sqrt (aRatio.x * aRatio.y) * aColor.w / uAccumFrames * 0.35f, 0.f), 1.0); aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, sqrt (aRatio.x * aRatio.y) * aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);
} }
@ -138,7 +136,7 @@ void main (void)
#ifdef PATH_TRACING #ifdef PATH_TRACING
aColor *= pow (2, uExposure); aColor *= pow (2.0, uExposure);
#ifdef TONE_MAPPING_FILMIC #ifdef TONE_MAPPING_FILMIC
aColor = ToneMappingFilmic (aColor, uWhitePoint); aColor = ToneMappingFilmic (aColor, uWhitePoint);

View File

@ -643,25 +643,18 @@ float HandleDistantLight (in vec3 theInput, in vec3 theToLight, in float theCosM
vec3 IntersectLight (in SRay theRay, in int theDepth, in float theHitDistance, out float thePDF) vec3 IntersectLight (in SRay theRay, in int theDepth, in float theHitDistance, out float thePDF)
{ {
vec3 aTotalRadiance = ZERO; vec3 aTotalRadiance = ZERO;
thePDF = 0.f; // PDF of sampling light sources thePDF = 0.f; // PDF of sampling light sources
for (int aLightIdx = 0; aLightIdx < uLightCount; ++aLightIdx) for (int aLightIdx = 0; aLightIdx < uLightCount; ++aLightIdx)
{ {
vec4 aLight = texelFetch ( vec4 aLight = texelFetch (uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx));
uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx)); vec4 aParam = texelFetch (uRaytraceLightSrcTexture, LIGHT_PWR (aLightIdx));
vec4 aParam = texelFetch (
uRaytraceLightSrcTexture, LIGHT_PWR (aLightIdx));
// W component: 0 for infinite light and 1 for point light // W component: 0 for infinite light and 1 for point light
aLight.xyz -= mix (ZERO, theRay.Origin, aLight.w); aLight.xyz -= mix (ZERO, theRay.Origin, aLight.w);
float aPDF = 1.0 / float(uLightCount);
float aPDF = 1.f / uLightCount;
if (aLight.w != 0.f) // point light source if (aLight.w != 0.f) // point light source
{ {
float aCenterDst = length (aLight.xyz); float aCenterDst = length (aLight.xyz);
if (aCenterDst < theHitDistance) if (aCenterDst < theHitDistance)
{ {
float aVisibility = HandlePointLight ( float aVisibility = HandlePointLight (
@ -909,14 +902,12 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
if (uLightCount > 0 && IsNotZero (aBSDF, aThroughput)) if (uLightCount > 0 && IsNotZero (aBSDF, aThroughput))
{ {
aExpPDF = 1.f / uLightCount; aExpPDF = 1.0 / float(uLightCount);
int aLightIdx = min (int (floor (RandFloat() * uLightCount)), uLightCount - 1); int aLightIdx = min (int (floor (RandFloat() * float(uLightCount))), uLightCount - 1);
vec4 aLight = texelFetch ( vec4 aLight = texelFetch (uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx));
uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx)); vec4 aParam = texelFetch (uRaytraceLightSrcTexture, LIGHT_PWR (aLightIdx));
vec4 aParam = texelFetch (
uRaytraceLightSrcTexture, LIGHT_PWR (aLightIdx));
// 'w' component is 0 for infinite light and 1 for point light // 'w' component is 0 for infinite light and 1 for point light
aLight.xyz -= mix (ZERO, theRay.Origin, aLight.w); aLight.xyz -= mix (ZERO, theRay.Origin, aLight.w);
@ -971,7 +962,9 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
#endif #endif
// here, we additionally increase path length for non-diffuse bounces // here, we additionally increase path length for non-diffuse bounces
if (RandFloat() > aSurvive || all (lessThan (aThroughput, MIN_THROUGHPUT)) || aDepth >= theNbSamples / FRAME_STEP + step (1.f / M_PI, aImpPDF)) if (RandFloat() > aSurvive
|| all (lessThan (aThroughput, MIN_THROUGHPUT))
|| aDepth >= (theNbSamples / FRAME_STEP + int(step (1.0 / M_PI, aImpPDF))))
{ {
aDepth = INVALID_BOUNCES; // terminate path aDepth = INVALID_BOUNCES; // terminate path
} }

View File

@ -12,10 +12,10 @@
//! Normalized pixel coordinates. //! Normalized pixel coordinates.
in vec2 vPixel; in vec2 vPixel;
//! Sub-pixel offset in X direction for FSAA. //! Sub-pixel offset in for FSAA.
uniform float uOffsetX = 0.f; uniform vec2 uFsaaOffset;
//! Sub-pixel offset in Y direction for FSAA. //! Sub-pixel offset in Y direction for FSAA.
uniform float uOffsetY = 0.f; uniform float uOffsetY;
//! Origin of viewing ray in left-top corner. //! Origin of viewing ray in left-top corner.
uniform vec3 uOriginLT; uniform vec3 uOriginLT;
@ -124,15 +124,15 @@ uniform float uSceneEpsilon;
#endif #endif
//! Top color of gradient background. //! Top color of gradient background.
uniform vec4 uBackColorTop = vec4 (0.0); uniform vec4 uBackColorTop;
//! Bottom color of gradient background. //! Bottom color of gradient background.
uniform vec4 uBackColorBot = vec4 (0.0); uniform vec4 uBackColorBot;
//! Aperture radius of camera used for depth-of-field //! Aperture radius of camera used for depth-of-field
uniform float uApertureRadius = 0.f; uniform float uApertureRadius;
//! Focal distance of camera used for depth-of field //! Focal distance of camera used for depth-of field
uniform float uFocalPlaneDist = 10.f; uniform float uFocalPlaneDist;
//! Camera position used for projective mode //! Camera position used for projective mode
uniform vec3 uEyeOrig; uniform vec3 uEyeOrig;
@ -156,7 +156,6 @@ uniform vec2 uEyeSize;
struct SRay struct SRay
{ {
vec3 Origin; vec3 Origin;
vec3 Direct; vec3 Direct;
}; };
@ -164,9 +163,7 @@ struct SRay
struct SIntersect struct SIntersect
{ {
float Time; float Time;
vec2 UV; vec2 UV;
vec3 Normal; vec3 Normal;
}; };
@ -174,7 +171,6 @@ struct SIntersect
struct STriangle struct STriangle
{ {
ivec4 TriIndex; ivec4 TriIndex;
vec3 Points[3]; vec3 Points[3];
}; };

View File

@ -18,7 +18,7 @@ uniform int uAccumSamples;
//! Maximum radiance that can be added to the pixel. //! Maximum radiance that can be added to the pixel.
//! Decreases noise level, but introduces some bias. //! Decreases noise level, but introduces some bias.
uniform float uMaxRadiance = 50.f; uniform float uMaxRadiance;
#ifdef ADAPTIVE_SAMPLING #ifdef ADAPTIVE_SAMPLING
//! Wrapper over imageLoad()+imageStore() having similar syntax as imageAtomicAdd(). //! Wrapper over imageLoad()+imageStore() having similar syntax as imageAtomicAdd().
@ -77,8 +77,8 @@ void main (void)
#endif // ADAPTIVE_SAMPLING #endif // ADAPTIVE_SAMPLING
vec2 aPnt = vec2 (aFragCoord.x + RandFloat(), vec2 aPnt = vec2 (float(aFragCoord.x) + RandFloat(),
aFragCoord.y + RandFloat()); float(aFragCoord.y) + RandFloat());
SRay aRay = GenerateRay (aPnt / vec2 (uWinSizeX, uWinSizeY)); SRay aRay = GenerateRay (aPnt / vec2 (uWinSizeX, uWinSizeY));
@ -89,21 +89,16 @@ void main (void)
#ifdef PATH_TRACING #ifdef PATH_TRACING
#ifndef ADAPTIVE_SAMPLING #ifndef ADAPTIVE_SAMPLING
vec4 aColor = PathTrace (aRay, aInvDirect, uAccumSamples); vec4 aColor = PathTrace (aRay, aInvDirect, uAccumSamples);
#else #else
float aNbSamples = addRenderImageComp (aFragCoord, ivec2 (0, 1), 1.0); float aNbSamples = addRenderImageComp (aFragCoord, ivec2 (0, 1), 1.0);
vec4 aColor = PathTrace (aRay, aInvDirect, int (aNbSamples)); vec4 aColor = PathTrace (aRay, aInvDirect, int (aNbSamples));
#endif #endif
if (any (isnan (aColor.rgb))) if (any (isnan (aColor.rgb)))
{ {
aColor.rgb = ZERO; aColor.rgb = ZERO;
} }
aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance)); aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance));
#ifdef ADAPTIVE_SAMPLING #ifdef ADAPTIVE_SAMPLING
@ -113,7 +108,6 @@ void main (void)
addRenderImageComp (aFragCoord, ivec2 (1, 0), aColor.g); addRenderImageComp (aFragCoord, ivec2 (1, 0), aColor.g);
addRenderImageComp (aFragCoord, ivec2 (1, 1), aColor.b); addRenderImageComp (aFragCoord, ivec2 (1, 1), aColor.b);
addRenderImageComp (aFragCoord, ivec2 (2, 1), aColor.w); addRenderImageComp (aFragCoord, ivec2 (2, 1), aColor.w);
if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only
{ {
addRenderImageComp (aFragCoord, ivec2 (2, 0), dot (LUMA, aColor.rgb)); addRenderImageComp (aFragCoord, ivec2 (2, 0), dot (LUMA, aColor.rgb));
@ -127,7 +121,7 @@ void main (void)
} }
else else
{ {
OutColor = mix (texture (uAccumTexture, vPixel), aColor, 1.f / (uAccumSamples + 1)); OutColor = mix (texture (uAccumTexture, vPixel), aColor, 1.0 / float(uAccumSamples + 1));
} }
#endif // ADAPTIVE_SAMPLING #endif // ADAPTIVE_SAMPLING

View File

@ -21,8 +21,8 @@ void main (void)
int aPixelY = int (gl_FragCoord.y); int aPixelY = int (gl_FragCoord.y);
// Adjust FLIPTRI pattern used for adaptive FSAA // Adjust FLIPTRI pattern used for adaptive FSAA
float anOffsetX = mix (uOffsetX, -uOffsetX, float (aPixelX % 2)); float anOffsetX = mix (uFsaaOffset.x, -uFsaaOffset.x, float (aPixelX % 2));
float anOffsetY = mix (uOffsetY, -uOffsetY, float (aPixelY % 2)); float anOffsetY = mix (uFsaaOffset.y, -uFsaaOffset.y, float (aPixelY % 2));
vec4 aClr0 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY + 0), 0); vec4 aClr0 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY + 0), 0);
vec4 aClr1 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY - 1), 0); vec4 aClr1 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY - 1), 0);
@ -71,7 +71,7 @@ void main (void)
aRay.Direct.y < 0.f ? -aInvDirect.y : aInvDirect.y, aRay.Direct.y < 0.f ? -aInvDirect.y : aInvDirect.y,
aRay.Direct.z < 0.f ? -aInvDirect.z : aInvDirect.z); aRay.Direct.z < 0.f ? -aInvDirect.z : aInvDirect.z);
aColor = mix (aClr0, clamp (Radiance (aRay, aInvDirect), 0.f, 1.f), 1.f / uSamples); aColor = mix (aClr0, clamp (Radiance (aRay, aInvDirect), 0.0, 1.0), 1.0 / float(uSamples));
} }
OutColor = aColor; OutColor = aColor;

View File

@ -129,11 +129,9 @@ static const char Shaders_Display_fs[] =
" else // showing number of samples\n" " else // showing number of samples\n"
" {\n" " {\n"
" vec2 aRatio = vec2 (1.f, 1.f);\n" " vec2 aRatio = vec2 (1.f, 1.f);\n"
"\n"
"#ifdef GL_ARB_shader_image_size\n" "#ifdef GL_ARB_shader_image_size\n"
" aRatio = vec2 (imageSize (uRenderImage)) / vec2 (3.f * 512.f, 2.f * 512.f);\n" " aRatio = vec2 (imageSize (uRenderImage)) / vec2 (3.f * 512.f, 2.f * 512.f);\n"
"#endif\n" "#endif\n"
"\n"
" aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, sqrt (aRatio.x * aRatio.y) * aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);\n" " aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, sqrt (aRatio.x * aRatio.y) * aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);\n"
" }\n" " }\n"
"\n" "\n"
@ -141,7 +139,7 @@ static const char Shaders_Display_fs[] =
"\n" "\n"
"#ifdef PATH_TRACING\n" "#ifdef PATH_TRACING\n"
"\n" "\n"
" aColor *= pow (2, uExposure);\n" " aColor *= pow (2.0, uExposure);\n"
"\n" "\n"
"#ifdef TONE_MAPPING_FILMIC\n" "#ifdef TONE_MAPPING_FILMIC\n"
" aColor = ToneMappingFilmic (aColor, uWhitePoint);\n" " aColor = ToneMappingFilmic (aColor, uWhitePoint);\n"

View File

@ -646,25 +646,18 @@ static const char Shaders_PathtraceBase_fs[] =
"vec3 IntersectLight (in SRay theRay, in int theDepth, in float theHitDistance, out float thePDF)\n" "vec3 IntersectLight (in SRay theRay, in int theDepth, in float theHitDistance, out float thePDF)\n"
"{\n" "{\n"
" vec3 aTotalRadiance = ZERO;\n" " vec3 aTotalRadiance = ZERO;\n"
"\n"
" thePDF = 0.f; // PDF of sampling light sources\n" " thePDF = 0.f; // PDF of sampling light sources\n"
"\n"
" for (int aLightIdx = 0; aLightIdx < uLightCount; ++aLightIdx)\n" " for (int aLightIdx = 0; aLightIdx < uLightCount; ++aLightIdx)\n"
" {\n" " {\n"
" vec4 aLight = texelFetch (\n" " vec4 aLight = texelFetch (uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx));\n"
" uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx));\n" " vec4 aParam = texelFetch (uRaytraceLightSrcTexture, LIGHT_PWR (aLightIdx));\n"
" vec4 aParam = texelFetch (\n"
" uRaytraceLightSrcTexture, LIGHT_PWR (aLightIdx));\n"
"\n" "\n"
" // W component: 0 for infinite light and 1 for point light\n" " // W component: 0 for infinite light and 1 for point light\n"
" aLight.xyz -= mix (ZERO, theRay.Origin, aLight.w);\n" " aLight.xyz -= mix (ZERO, theRay.Origin, aLight.w);\n"
"\n" " float aPDF = 1.0 / float(uLightCount);\n"
" float aPDF = 1.f / uLightCount;\n"
"\n"
" if (aLight.w != 0.f) // point light source\n" " if (aLight.w != 0.f) // point light source\n"
" {\n" " {\n"
" float aCenterDst = length (aLight.xyz);\n" " float aCenterDst = length (aLight.xyz);\n"
"\n"
" if (aCenterDst < theHitDistance)\n" " if (aCenterDst < theHitDistance)\n"
" {\n" " {\n"
" float aVisibility = HandlePointLight (\n" " float aVisibility = HandlePointLight (\n"
@ -912,14 +905,12 @@ static const char Shaders_PathtraceBase_fs[] =
"\n" "\n"
" if (uLightCount > 0 && IsNotZero (aBSDF, aThroughput))\n" " if (uLightCount > 0 && IsNotZero (aBSDF, aThroughput))\n"
" {\n" " {\n"
" aExpPDF = 1.f / uLightCount;\n" " aExpPDF = 1.0 / float(uLightCount);\n"
"\n" "\n"
" int aLightIdx = min (int (floor (RandFloat() * uLightCount)), uLightCount - 1);\n" " int aLightIdx = min (int (floor (RandFloat() * float(uLightCount))), uLightCount - 1);\n"
"\n" "\n"
" vec4 aLight = texelFetch (\n" " vec4 aLight = texelFetch (uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx));\n"
" uRaytraceLightSrcTexture, LIGHT_POS (aLightIdx));\n" " vec4 aParam = texelFetch (uRaytraceLightSrcTexture, LIGHT_PWR (aLightIdx));\n"
" vec4 aParam = texelFetch (\n"
" uRaytraceLightSrcTexture, LIGHT_PWR (aLightIdx));\n"
"\n" "\n"
" // 'w' component is 0 for infinite light and 1 for point light\n" " // 'w' component is 0 for infinite light and 1 for point light\n"
" aLight.xyz -= mix (ZERO, theRay.Origin, aLight.w);\n" " aLight.xyz -= mix (ZERO, theRay.Origin, aLight.w);\n"
@ -974,7 +965,9 @@ static const char Shaders_PathtraceBase_fs[] =
"#endif\n" "#endif\n"
"\n" "\n"
" // here, we additionally increase path length for non-diffuse bounces\n" " // here, we additionally increase path length for non-diffuse bounces\n"
" if (RandFloat() > aSurvive || all (lessThan (aThroughput, MIN_THROUGHPUT)) || aDepth >= theNbSamples / FRAME_STEP + step (1.f / M_PI, aImpPDF))\n" " if (RandFloat() > aSurvive\n"
" || all (lessThan (aThroughput, MIN_THROUGHPUT))\n"
" || aDepth >= (theNbSamples / FRAME_STEP + int(step (1.0 / M_PI, aImpPDF))))\n"
" {\n" " {\n"
" aDepth = INVALID_BOUNCES; // terminate path\n" " aDepth = INVALID_BOUNCES; // terminate path\n"
" }\n" " }\n"

View File

@ -15,10 +15,10 @@ static const char Shaders_RaytraceBase_fs[] =
"//! Normalized pixel coordinates.\n" "//! Normalized pixel coordinates.\n"
"in vec2 vPixel;\n" "in vec2 vPixel;\n"
"\n" "\n"
"//! Sub-pixel offset in X direction for FSAA.\n" "//! Sub-pixel offset in for FSAA.\n"
"uniform float uOffsetX = 0.f;\n" "uniform vec2 uFsaaOffset;\n"
"//! Sub-pixel offset in Y direction for FSAA.\n" "//! Sub-pixel offset in Y direction for FSAA.\n"
"uniform float uOffsetY = 0.f;\n" "uniform float uOffsetY;\n"
"\n" "\n"
"//! Origin of viewing ray in left-top corner.\n" "//! Origin of viewing ray in left-top corner.\n"
"uniform vec3 uOriginLT;\n" "uniform vec3 uOriginLT;\n"
@ -127,15 +127,15 @@ static const char Shaders_RaytraceBase_fs[] =
"#endif\n" "#endif\n"
"\n" "\n"
"//! Top color of gradient background.\n" "//! Top color of gradient background.\n"
"uniform vec4 uBackColorTop = vec4 (0.0);\n" "uniform vec4 uBackColorTop;\n"
"//! Bottom color of gradient background.\n" "//! Bottom color of gradient background.\n"
"uniform vec4 uBackColorBot = vec4 (0.0);\n" "uniform vec4 uBackColorBot;\n"
"\n" "\n"
"//! Aperture radius of camera used for depth-of-field\n" "//! Aperture radius of camera used for depth-of-field\n"
"uniform float uApertureRadius = 0.f;\n" "uniform float uApertureRadius;\n"
"\n" "\n"
"//! Focal distance of camera used for depth-of field\n" "//! Focal distance of camera used for depth-of field\n"
"uniform float uFocalPlaneDist = 10.f;\n" "uniform float uFocalPlaneDist;\n"
"\n" "\n"
"//! Camera position used for projective mode\n" "//! Camera position used for projective mode\n"
"uniform vec3 uEyeOrig;\n" "uniform vec3 uEyeOrig;\n"
@ -159,7 +159,6 @@ static const char Shaders_RaytraceBase_fs[] =
"struct SRay\n" "struct SRay\n"
"{\n" "{\n"
" vec3 Origin;\n" " vec3 Origin;\n"
"\n"
" vec3 Direct;\n" " vec3 Direct;\n"
"};\n" "};\n"
"\n" "\n"
@ -167,9 +166,7 @@ static const char Shaders_RaytraceBase_fs[] =
"struct SIntersect\n" "struct SIntersect\n"
"{\n" "{\n"
" float Time;\n" " float Time;\n"
"\n"
" vec2 UV;\n" " vec2 UV;\n"
"\n"
" vec3 Normal;\n" " vec3 Normal;\n"
"};\n" "};\n"
"\n" "\n"
@ -177,7 +174,6 @@ static const char Shaders_RaytraceBase_fs[] =
"struct STriangle\n" "struct STriangle\n"
"{\n" "{\n"
" ivec4 TriIndex;\n" " ivec4 TriIndex;\n"
"\n"
" vec3 Points[3];\n" " vec3 Points[3];\n"
"};\n" "};\n"
"\n" "\n"

View File

@ -21,7 +21,7 @@ static const char Shaders_RaytraceRender_fs[] =
"\n" "\n"
"//! Maximum radiance that can be added to the pixel.\n" "//! Maximum radiance that can be added to the pixel.\n"
"//! Decreases noise level, but introduces some bias.\n" "//! Decreases noise level, but introduces some bias.\n"
"uniform float uMaxRadiance = 50.f;\n" "uniform float uMaxRadiance;\n"
"\n" "\n"
"#ifdef ADAPTIVE_SAMPLING\n" "#ifdef ADAPTIVE_SAMPLING\n"
"//! Wrapper over imageLoad()+imageStore() having similar syntax as imageAtomicAdd().\n" "//! Wrapper over imageLoad()+imageStore() having similar syntax as imageAtomicAdd().\n"
@ -80,8 +80,8 @@ static const char Shaders_RaytraceRender_fs[] =
"\n" "\n"
"#endif // ADAPTIVE_SAMPLING\n" "#endif // ADAPTIVE_SAMPLING\n"
"\n" "\n"
" vec2 aPnt = vec2 (aFragCoord.x + RandFloat(),\n" " vec2 aPnt = vec2 (float(aFragCoord.x) + RandFloat(),\n"
" aFragCoord.y + RandFloat());\n" " float(aFragCoord.y) + RandFloat());\n"
"\n" "\n"
" SRay aRay = GenerateRay (aPnt / vec2 (uWinSizeX, uWinSizeY));\n" " SRay aRay = GenerateRay (aPnt / vec2 (uWinSizeX, uWinSizeY));\n"
"\n" "\n"
@ -92,21 +92,16 @@ static const char Shaders_RaytraceRender_fs[] =
"#ifdef PATH_TRACING\n" "#ifdef PATH_TRACING\n"
"\n" "\n"
"#ifndef ADAPTIVE_SAMPLING\n" "#ifndef ADAPTIVE_SAMPLING\n"
"\n"
" vec4 aColor = PathTrace (aRay, aInvDirect, uAccumSamples);\n" " vec4 aColor = PathTrace (aRay, aInvDirect, uAccumSamples);\n"
"\n"
"#else\n" "#else\n"
"\n"
" float aNbSamples = addRenderImageComp (aFragCoord, ivec2 (0, 1), 1.0);\n" " float aNbSamples = addRenderImageComp (aFragCoord, ivec2 (0, 1), 1.0);\n"
" vec4 aColor = PathTrace (aRay, aInvDirect, int (aNbSamples));\n" " vec4 aColor = PathTrace (aRay, aInvDirect, int (aNbSamples));\n"
"\n"
"#endif\n" "#endif\n"
"\n" "\n"
" if (any (isnan (aColor.rgb)))\n" " if (any (isnan (aColor.rgb)))\n"
" {\n" " {\n"
" aColor.rgb = ZERO;\n" " aColor.rgb = ZERO;\n"
" }\n" " }\n"
"\n"
" aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance));\n" " aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance));\n"
"\n" "\n"
"#ifdef ADAPTIVE_SAMPLING\n" "#ifdef ADAPTIVE_SAMPLING\n"
@ -116,7 +111,6 @@ static const char Shaders_RaytraceRender_fs[] =
" addRenderImageComp (aFragCoord, ivec2 (1, 0), aColor.g);\n" " addRenderImageComp (aFragCoord, ivec2 (1, 0), aColor.g);\n"
" addRenderImageComp (aFragCoord, ivec2 (1, 1), aColor.b);\n" " addRenderImageComp (aFragCoord, ivec2 (1, 1), aColor.b);\n"
" addRenderImageComp (aFragCoord, ivec2 (2, 1), aColor.w);\n" " addRenderImageComp (aFragCoord, ivec2 (2, 1), aColor.w);\n"
"\n"
" if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only\n" " if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only\n"
" {\n" " {\n"
" addRenderImageComp (aFragCoord, ivec2 (2, 0), dot (LUMA, aColor.rgb));\n" " addRenderImageComp (aFragCoord, ivec2 (2, 0), dot (LUMA, aColor.rgb));\n"
@ -130,7 +124,7 @@ static const char Shaders_RaytraceRender_fs[] =
" }\n" " }\n"
" else\n" " else\n"
" {\n" " {\n"
" OutColor = mix (texture (uAccumTexture, vPixel), aColor, 1.f / (uAccumSamples + 1));\n" " OutColor = mix (texture (uAccumTexture, vPixel), aColor, 1.0 / float(uAccumSamples + 1));\n"
" }\n" " }\n"
"\n" "\n"
"#endif // ADAPTIVE_SAMPLING\n" "#endif // ADAPTIVE_SAMPLING\n"

View File

@ -24,8 +24,8 @@ static const char Shaders_RaytraceSmooth_fs[] =
" int aPixelY = int (gl_FragCoord.y);\n" " int aPixelY = int (gl_FragCoord.y);\n"
"\n" "\n"
" // Adjust FLIPTRI pattern used for adaptive FSAA\n" " // Adjust FLIPTRI pattern used for adaptive FSAA\n"
" float anOffsetX = mix (uOffsetX, -uOffsetX, float (aPixelX % 2));\n" " float anOffsetX = mix (uFsaaOffset.x, -uFsaaOffset.x, float (aPixelX % 2));\n"
" float anOffsetY = mix (uOffsetY, -uOffsetY, float (aPixelY % 2));\n" " float anOffsetY = mix (uFsaaOffset.y, -uFsaaOffset.y, float (aPixelY % 2));\n"
"\n" "\n"
" vec4 aClr0 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY + 0), 0);\n" " vec4 aClr0 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY + 0), 0);\n"
" vec4 aClr1 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY - 1), 0);\n" " vec4 aClr1 = texelFetch (uFSAAInputTexture, ivec2 (aPixelX + 0, aPixelY - 1), 0);\n"
@ -74,7 +74,7 @@ static const char Shaders_RaytraceSmooth_fs[] =
" aRay.Direct.y < 0.f ? -aInvDirect.y : aInvDirect.y,\n" " aRay.Direct.y < 0.f ? -aInvDirect.y : aInvDirect.y,\n"
" aRay.Direct.z < 0.f ? -aInvDirect.z : aInvDirect.z);\n" " aRay.Direct.z < 0.f ? -aInvDirect.z : aInvDirect.z);\n"
"\n" "\n"
" aColor = mix (aClr0, clamp (Radiance (aRay, aInvDirect), 0.f, 1.f), 1.f / uSamples);\n" " aColor = mix (aClr0, clamp (Radiance (aRay, aInvDirect), 0.0, 1.0), 1.0 / float(uSamples));\n"
" }\n" " }\n"
"\n" "\n"
" OutColor = aColor;\n" " OutColor = aColor;\n"