0027258: Configuration - generate built-in replacement for mandatory resource files
[occt.git] / src / Shaders / Shaders_RaytraceRender_fs.pxx
CommitLineData
ee5befae 1// This file has been automatically generated from resource file src/Shaders/RaytraceRender.fs
2
3static const char Shaders_RaytraceRender_fs[] =
4 "out vec4 OutColor;\n"
5 "\n"
6 "// Seed for random number generator (generated on CPU).\n"
7 "uniform int uFrameRndSeed;\n"
8 "\n"
9 "//! Enables/disables using of single RNG seed for 16x16 image\n"
10 "//! blocks. Increases performance up to 4x, but the noise has\n"
11 "//! become structured. Can be used fo final rendering.\n"
12 "uniform int uBlockedRngEnabled;\n"
13 "\n"
14 "#ifndef ADAPTIVE_SAMPLING\n"
15 " //! Weight of current frame related to accumulated samples.\n"
16 " uniform float uSampleWeight;\n"
17 "\n"
18 " //! Input accumulated image.\n"
19 " uniform sampler2D uAccumTexture;\n"
20 "#endif\n"
21 "\n"
22 "//! Maximum radiance that can be added to the pixel. Decreases noise\n"
23 "//! level, but introduces some bias.\n"
24 "#define MAX_RADIANCE vec3 (25.f)\n"
25 "\n"
26 "// =======================================================================\n"
27 "// function : main\n"
28 "// purpose :\n"
29 "// =======================================================================\n"
30 "void main (void)\n"
31 "{\n"
32 " SeedRand (uFrameRndSeed, uWinSizeX, uBlockedRngEnabled == 0 ? 1 : 16);\n"
33 "\n"
34 "#ifndef PATH_TRACING\n"
35 "\n"
36 " SRay aRay = GenerateRay (vPixel);\n"
37 "\n"
38 "#else\n"
39 "\n"
40 " ivec2 aFragCoord = ivec2 (gl_FragCoord.xy);\n"
41 "\n"
42 "#ifdef ADAPTIVE_SAMPLING\n"
43 "\n"
44 " ivec2 aTileXY = imageLoad (uOffsetImage, ivec2 (aFragCoord.x / BLOCK_SIZE,\n"
45 " aFragCoord.y / BLOCK_SIZE)).xy;\n"
46 "\n"
47 " ivec2 aRealBlockSize = ivec2 (min (uWinSizeX - aTileXY.x, BLOCK_SIZE),\n"
48 " min (uWinSizeY - aTileXY.y, BLOCK_SIZE));\n"
49 "\n"
50 " aFragCoord.x = aTileXY.x + (aFragCoord.x % aRealBlockSize.x);\n"
51 " aFragCoord.y = aTileXY.y + (aFragCoord.y % aRealBlockSize.y);\n"
52 "\n"
53 "#endif // ADAPTIVE_SAMPLING\n"
54 "\n"
55 " vec2 aPnt = vec2 (aFragCoord.x + RandFloat(),\n"
56 " aFragCoord.y + RandFloat());\n"
57 "\n"
58 " SRay aRay = GenerateRay (aPnt / vec2 (uWinSizeX, uWinSizeY));\n"
59 "\n"
60 "#endif // PATH_TRACING\n"
61 "\n"
62 " vec3 aInvDirect = InverseDirection (aRay.Direct);\n"
63 "\n"
64 "#ifdef PATH_TRACING\n"
65 "\n"
66 " vec4 aColor = PathTrace (aRay, aInvDirect);\n"
67 "\n"
68 " if (any (isnan (aColor.rgb)))\n"
69 " {\n"
70 " aColor.rgb = ZERO;\n"
71 " }\n"
72 "\n"
73 " aColor.rgb = min (aColor.rgb, MAX_RADIANCE);\n"
74 "\n"
75 "#ifdef ADAPTIVE_SAMPLING\n"
76 "\n"
77 " // accumulate RGB color and depth\n"
78 " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 0,\n"
79 " 2 * aFragCoord.y + 0), aColor.r);\n"
80 " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 1,\n"
81 " 2 * aFragCoord.y + 0), aColor.g);\n"
82 " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 1,\n"
83 " 2 * aFragCoord.y + 1), aColor.b);\n"
84 " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 2,\n"
85 " 2 * aFragCoord.y + 1), aColor.w);\n"
86 "\n"
87 " // accumulate number of samples\n"
88 " float aNbSamples = imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 0,\n"
89 " 2 * aFragCoord.y + 1), 1.0);\n"
90 "\n"
91 " if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only\n"
92 " {\n"
93 " imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 2,\n"
94 " 2 * aFragCoord.y + 0), dot (LUMA, aColor.rgb));\n"
95 " }\n"
96 "\n"
97 " discard; // fragment should not be written to frame buffer\n"
98 "\n"
99 "#else\n"
100 "\n"
101 " if (uSampleWeight >= 1.f)\n"
102 " {\n"
103 " OutColor = aColor;\n"
104 " }\n"
105 " else\n"
106 " {\n"
107 " OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight);\n"
108 " }\n"
109 "\n"
110 "#endif // ADAPTIVE_SAMPLING\n"
111 "\n"
112 "#else\n"
113 "\n"
114 " OutColor = clamp (Radiance (aRay, aInvDirect), 0.f, 1.f);\n"
115 "\n"
116 "#endif // PATH_TRACING\n"
117 "}\n";