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