0030640: Visualization, Graphic3d_Camera - add option creating Projection matrix...
[occt.git] / src / Shaders / Shaders_RaytraceRender_fs.pxx
1 // This file has been automatically generated from resource file src/Shaders/RaytraceRender.fs
2
3 static 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   "//! Number of previously rendered frames (used in non-ISS mode).\n"
15   "uniform int uAccumSamples;\n"
16   "\n"
17   "#ifndef ADAPTIVE_SAMPLING\n"
18   "  //! Input image with previously accumulated samples.\n"
19   "  uniform sampler2D uAccumTexture;\n"
20   "#endif\n"
21   "\n"
22   "//! Maximum radiance that can be added to the pixel.\n"
23   "//! Decreases noise level, but introduces some bias.\n"
24   "uniform float uMaxRadiance;\n"
25   "\n"
26   "#ifdef ADAPTIVE_SAMPLING\n"
27   "//! Wrapper over imageLoad()+imageStore() having similar syntax as imageAtomicAdd().\n"
28   "//! Modifies one component of 3Wx2H uRenderImage:\n"
29   "//! |RGL| Red, Green, Luminance\n"
30   "//! |SBH| Samples, Blue, Hit time transformed into OpenGL NDC space\n"
31   "//! Returns previous value of the component.\n"
32   "float addRenderImageComp (in ivec2 theFrag, in ivec2 theComp, in float theVal)\n"
33   "{\n"
34   "  ivec2 aCoord = ivec2 (3 * theFrag.x + theComp.x,\n"
35   "                        2 * theFrag.y + theComp.y);\n"
36   "#ifdef ADAPTIVE_SAMPLING_ATOMIC\n"
37   "  return imageAtomicAdd (uRenderImage, aCoord, theVal);\n"
38   "#else\n"
39   "  float aVal = imageLoad (uRenderImage, aCoord).x;\n"
40   "  imageStore (uRenderImage, aCoord, vec4 (aVal + theVal));\n"
41   "  return aVal;\n"
42   "#endif\n"
43   "}\n"
44   "#endif\n"
45   "\n"
46   "// =======================================================================\n"
47   "// function : main\n"
48   "// purpose  :\n"
49   "// =======================================================================\n"
50   "void main (void)\n"
51   "{\n"
52   "  SeedRand (uFrameRndSeed, uWinSizeX, uBlockedRngEnabled == 0 ? 1 : 16);\n"
53   "\n"
54   "#ifndef PATH_TRACING\n"
55   "\n"
56   "  SRay aRay = GenerateRay (vPixel);\n"
57   "\n"
58   "#else\n"
59   "\n"
60   "  ivec2 aFragCoord = ivec2 (gl_FragCoord.xy);\n"
61   "\n"
62   "#ifdef ADAPTIVE_SAMPLING\n"
63   "\n"
64   "#ifdef ADAPTIVE_SAMPLING_ATOMIC\n"
65   "  ivec2 aTileXY = imageLoad (uOffsetImage, aFragCoord / uTileSize).xy * uTileSize;\n"
66   "  if (aTileXY.x < 0) { discard; }\n"
67   "\n"
68   "  ivec2 aRealBlockSize = ivec2 (min (uWinSizeX - aTileXY.x, uTileSize.x),\n"
69   "                                min (uWinSizeY - aTileXY.y, uTileSize.y));\n"
70   "\n"
71   "  aFragCoord.x = aTileXY.x + (aFragCoord.x % aRealBlockSize.x);\n"
72   "  aFragCoord.y = aTileXY.y + (aFragCoord.y % aRealBlockSize.y);\n"
73   "#else\n"
74   "  int aNbTileSamples = imageAtomicAdd (uTilesImage, aFragCoord / uTileSize, int(-1));\n"
75   "  if (aNbTileSamples <= 0)\n"
76   "  {\n"
77   "    discard;\n"
78   "  }\n"
79   "#endif\n"
80   "\n"
81   "#endif // ADAPTIVE_SAMPLING\n"
82   "\n"
83   "  vec2 aPnt = vec2 (float(aFragCoord.x) + RandFloat(),\n"
84   "                    float(aFragCoord.y) + RandFloat());\n"
85   "\n"
86   "  SRay aRay = GenerateRay (aPnt / vec2 (uWinSizeX, uWinSizeY));\n"
87   "\n"
88   "#endif // PATH_TRACING\n"
89   "\n"
90   "  vec3 aInvDirect = InverseDirection (aRay.Direct);\n"
91   "\n"
92   "#ifdef PATH_TRACING\n"
93   "\n"
94   "#ifndef ADAPTIVE_SAMPLING\n"
95   "  vec4 aColor = PathTrace (aRay, aInvDirect, uAccumSamples);\n"
96   "#else\n"
97   "  float aNbSamples = addRenderImageComp (aFragCoord, ivec2 (0, 1), 1.0);\n"
98   "  vec4 aColor = PathTrace (aRay, aInvDirect, int (aNbSamples));\n"
99   "#endif\n"
100   "\n"
101   "  if (any (isnan (aColor.rgb)))\n"
102   "  {\n"
103   "    aColor.rgb = ZERO;\n"
104   "  }\n"
105   "  aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance));\n"
106   "\n"
107   "#ifdef ADAPTIVE_SAMPLING\n"
108   "\n"
109   "  // accumulate RGB color and depth\n"
110   "  addRenderImageComp (aFragCoord, ivec2 (0, 0), aColor.r);\n"
111   "  addRenderImageComp (aFragCoord, ivec2 (1, 0), aColor.g);\n"
112   "  addRenderImageComp (aFragCoord, ivec2 (1, 1), aColor.b);\n"
113   "  addRenderImageComp (aFragCoord, ivec2 (2, 1), aColor.w);\n"
114   "  if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only\n"
115   "  {\n"
116   "    addRenderImageComp (aFragCoord, ivec2 (2, 0), dot (LUMA, aColor.rgb));\n"
117   "  }\n"
118   "\n"
119   "#else\n"
120   "\n"
121   "  if (uAccumSamples == 0)\n"
122   "  {\n"
123   "    OutColor = aColor;\n"
124   "  }\n"
125   "  else\n"
126   "  {\n"
127   "    OutColor = mix (texture (uAccumTexture, vPixel), aColor, 1.0 / float(uAccumSamples + 1));\n"
128   "  }\n"
129   "\n"
130   "#endif // ADAPTIVE_SAMPLING\n"
131   "\n"
132   "#else\n"
133   "\n"
134   "  OutColor = clamp (Radiance (aRay, aInvDirect), 0.f, 1.f);\n"
135   "\n"
136   "#endif // PATH_TRACING\n"
137   "}\n";