// This file has been automatically generated from resource file src/Shaders/RaytraceRender.fs static const char Shaders_RaytraceRender_fs[] = "out vec4 OutColor;\n" "\n" "// Seed for random number generator (generated on CPU).\n" "uniform int uFrameRndSeed;\n" "\n" "//! Enables/disables using of single RNG seed for 16x16 image\n" "//! blocks. Increases performance up to 4x, but the noise has\n" "//! become structured. Can be used fo final rendering.\n" "uniform int uBlockedRngEnabled;\n" "\n" "//! Number of previously rendered frames (used in non-ISS mode).\n" "uniform int uAccumSamples;\n" "\n" "#ifndef ADAPTIVE_SAMPLING\n" " //! Input image with previously accumulated samples.\n" " uniform sampler2D uAccumTexture;\n" "#endif\n" "\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" "// purpose :\n" "// =======================================================================\n" "void main (void)\n" "{\n" " SeedRand (uFrameRndSeed, uWinSizeX, uBlockedRngEnabled == 0 ? 1 : 16);\n" "\n" "#ifndef PATH_TRACING\n" "\n" " SRay aRay = GenerateRay (vPixel);\n" "\n" "#else\n" "\n" " ivec2 aFragCoord = ivec2 (gl_FragCoord.xy);\n" "\n" "#ifdef ADAPTIVE_SAMPLING\n" "\n" " ivec2 aTileXY = imageLoad (uOffsetImage, ivec2 (aFragCoord.x / BLOCK_SIZE,\n" " aFragCoord.y / BLOCK_SIZE)).xy;\n" "\n" " ivec2 aRealBlockSize = ivec2 (min (uWinSizeX - aTileXY.x, BLOCK_SIZE),\n" " min (uWinSizeY - aTileXY.y, BLOCK_SIZE));\n" "\n" " aFragCoord.x = aTileXY.x + (aFragCoord.x % aRealBlockSize.x);\n" " aFragCoord.y = aTileXY.y + (aFragCoord.y % aRealBlockSize.y);\n" "\n" "#endif // ADAPTIVE_SAMPLING\n" "\n" " vec2 aPnt = vec2 (aFragCoord.x + RandFloat(),\n" " aFragCoord.y + RandFloat());\n" "\n" " SRay aRay = GenerateRay (aPnt / vec2 (uWinSizeX, uWinSizeY));\n" "\n" "#endif // PATH_TRACING\n" "\n" " vec3 aInvDirect = InverseDirection (aRay.Direct);\n" "\n" "#ifdef PATH_TRACING\n" "\n" "#ifndef ADAPTIVE_SAMPLING\n" "\n" " vec4 aColor = PathTrace (aRay, aInvDirect, uAccumSamples);\n" "\n" "#else\n" "\n" " float aNbSamples = imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 0,\n" " 2 * aFragCoord.y + 1), 1.0);\n" "\n" " vec4 aColor = PathTrace (aRay, aInvDirect, int (aNbSamples));\n" "\n" "#endif\n" "\n" " if (any (isnan (aColor.rgb)))\n" " {\n" " aColor.rgb = ZERO;\n" " }\n" "\n" " aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance));\n" "\n" "#ifdef ADAPTIVE_SAMPLING\n" "\n" " // accumulate RGB color and depth\n" " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 0,\n" " 2 * aFragCoord.y + 0), aColor.r);\n" " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 1,\n" " 2 * aFragCoord.y + 0), aColor.g);\n" " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 1,\n" " 2 * aFragCoord.y + 1), aColor.b);\n" " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 2,\n" " 2 * aFragCoord.y + 1), aColor.w);\n" "\n" " if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only\n" " {\n" " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 2,\n" " 2 * aFragCoord.y + 0), dot (LUMA, aColor.rgb));\n" " }\n" "\n" "#else\n" "\n" " if (uAccumSamples == 0)\n" " {\n" " OutColor = aColor;\n" " }\n" " else\n" " {\n" " OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, 1.f / (uAccumSamples + 1));\n" " }\n" "\n" "#endif // ADAPTIVE_SAMPLING\n" "\n" "#else\n" "\n" " OutColor = clamp (Radiance (aRay, aInvDirect), 0.f, 1.f);\n" "\n" "#endif // PATH_TRACING\n" "}\n";