2685179e4a9ed4647b93b19b1916d26e6f3f96b1
[occt.git] / src / Shaders / Shaders_Display_fs.pxx
1 // This file has been automatically generated from resource file src/Shaders/Display.fs
2
3 static const char Shaders_Display_fs[] =
4   "#ifdef ADAPTIVE_SAMPLING\n"
5   "\n"
6   "  #extension GL_ARB_shader_image_load_store : require\n"
7   "\n"
8   "  //! OpenGL image used for accumulating rendering result.\n"
9   "  volatile restrict layout(size1x32) uniform image2D uRenderImage;\n"
10   "\n"
11   "  //! OpenGL image storing variance of sampled pixels blocks.\n"
12   "  volatile restrict layout(size1x32) uniform iimage2D uVarianceImage;\n"
13   "\n"
14   "#else // ADAPTIVE_SAMPLING\n"
15   "\n"
16   "  //! Input image.\n"
17   "  uniform sampler2D uInputTexture;\n"
18   "\n"
19   "  //! Ray tracing depth image.\n"
20   "  uniform sampler2D uDepthTexture;\n"
21   "\n"
22   "#endif // ADAPTIVE_SAMPLING\n"
23   "\n"
24   "//! Number of accumulated frames.\n"
25   "uniform int uAccumFrames;\n"
26   "\n"
27   "//! Is debug mode enabled for importance screen sampling.\n"
28   "uniform int uDebugAdaptive;\n"
29   "\n"
30   "//! Output pixel color.\n"
31   "out vec4 OutColor;\n"
32   "\n"
33   "//! RGB weight factors to calculate luminance.\n"
34   "#define LUMA vec3 (0.2126f, 0.7152f, 0.0722f)\n"
35   "\n"
36   "//! Scale factor used to quantize visual error.\n"
37   "#define SCALE_FACTOR 1.0e6f\n"
38   "\n"
39   "// =======================================================================\n"
40   "// function : main\n"
41   "// purpose  :\n"
42   "// =======================================================================\n"
43   "void main (void)\n"
44   "{\n"
45   "#ifndef ADAPTIVE_SAMPLING\n"
46   "\n"
47   "  vec4 aColor = texelFetch (uInputTexture, ivec2 (gl_FragCoord.xy), 0);\n"
48   "\n"
49   "#ifdef PATH_TRACING\n"
50   "  float aDepth = aColor.w; // path tracing uses averaged depth\n"
51   "#else\n"
52   "  float aDepth = texelFetch (uDepthTexture, ivec2 (gl_FragCoord.xy), 0).r;\n"
53   "#endif\n"
54   "\n"
55   "  gl_FragDepth = aDepth;\n"
56   "\n"
57   "#else // ADAPTIVE_SAMPLING\n"
58   "\n"
59   "  ivec2 aPixel = ivec2 (gl_FragCoord.xy);\n"
60   "\n"
61   "  vec4 aColor = vec4 (0.0);\n"
62   "\n"
63   "  // fetch accumulated color and total number of samples\n"
64   "  aColor.x = imageLoad (uRenderImage, ivec2 (3 * aPixel.x + 0,\n"
65   "                                             2 * aPixel.y + 0)).x;\n"
66   "  aColor.y = imageLoad (uRenderImage, ivec2 (3 * aPixel.x + 1,\n"
67   "                                             2 * aPixel.y + 0)).x;\n"
68   "  aColor.z = imageLoad (uRenderImage, ivec2 (3 * aPixel.x + 1,\n"
69   "                                             2 * aPixel.y + 1)).x;\n"
70   "  aColor.w = imageLoad (uRenderImage, ivec2 (3 * aPixel.x + 0,\n"
71   "                                             2 * aPixel.y + 1)).x;\n"
72   "\n"
73   "  // calculate normalization factor\n"
74   "  float aSampleWeight = 1.f / max (1.0, aColor.w);\n"
75   "\n"
76   "  // calculate averaged depth value\n"
77   "  gl_FragDepth = imageLoad (uRenderImage, ivec2 (3 * aPixel.x + 2,\n"
78   "                                                 2 * aPixel.y + 1)).x * aSampleWeight;\n"
79   "\n"
80   "  // calculate averaged radiance for all samples and even samples only\n"
81   "  float aHalfRad = imageLoad (uRenderImage, ivec2 (3 * aPixel.x + 2,\n"
82   "                                                   2 * aPixel.y + 0)).x * aSampleWeight * 2.f;\n"
83   "\n"
84   "  float aAverRad = dot (aColor.rgb, LUMA) * aSampleWeight;\n"
85   "\n"
86   "  // apply our 'tone mapping' operator (gamma correction and clamping)\n"
87   "  aHalfRad = min (1.f, sqrt (aHalfRad));\n"
88   "  aAverRad = min (1.f, sqrt (aAverRad));\n"
89   "\n"
90   "  // calculate visual error\n"
91   "  float anError = (aAverRad - aHalfRad) * (aAverRad - aHalfRad);\n"
92   "\n"
93   "  // accumulate visual error to current block\n"
94   "  imageAtomicAdd (uVarianceImage, ivec2 (aPixel / vec2 (BLOCK_SIZE)), int (anError * SCALE_FACTOR));\n"
95   "\n"
96   "  if (uDebugAdaptive == 0) // normal rendering\n"
97   "  {\n"
98   "    aColor = vec4 (aColor.rgb * aSampleWeight, 1.0);\n"
99   "  }\n"
100   "  else // showing number of samples\n"
101   "  {\n"
102   "    aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);\n"
103   "  }\n"
104   "\n"
105   "#endif // ADAPTIVE_SAMPLING\n"
106   "\n"
107   "#ifdef PATH_TRACING\n"
108   "\n"
109   "   // apply gamma correction (we use gamma = 2)\n"
110   "   OutColor = vec4 (sqrt (aColor.rgb), 0.f);\n"
111   "\n"
112   "#else // not PATH_TRACING\n"
113   "\n"
114   "   OutColor = aColor;\n"
115   "\n"
116   "#endif\n"
117   "}\n";