1 // This file has been automatically generated from resource file src/Shaders/Display.fs
3 static const char Shaders_Display_fs[] =
4 "#ifdef ADAPTIVE_SAMPLING\n"
6 " #extension GL_ARB_shader_image_load_store : require\n"
8 " //! OpenGL image used for accumulating rendering result.\n"
9 " volatile restrict layout(size1x32) uniform image2D uRenderImage;\n"
11 " //! OpenGL image storing variance of sampled pixels blocks.\n"
12 " volatile restrict layout(size1x32) uniform iimage2D uVarianceImage;\n"
14 "#else // ADAPTIVE_SAMPLING\n"
17 " uniform sampler2D uInputTexture;\n"
19 " //! Ray tracing depth image.\n"
20 " uniform sampler2D uDepthTexture;\n"
22 "#endif // ADAPTIVE_SAMPLING\n"
24 "//! Number of accumulated frames.\n"
25 "uniform int uAccumFrames;\n"
27 "//! Is debug mode enabled for importance screen sampling.\n"
28 "uniform int uDebugAdaptive;\n"
30 "//! Output pixel color.\n"
31 "out vec4 OutColor;\n"
33 "//! RGB weight factors to calculate luminance.\n"
34 "#define LUMA vec3 (0.2126f, 0.7152f, 0.0722f)\n"
36 "//! Scale factor used to quantize visual error.\n"
37 "#define SCALE_FACTOR 1.0e6f\n"
39 "// =======================================================================\n"
40 "// function : main\n"
42 "// =======================================================================\n"
45 "#ifndef ADAPTIVE_SAMPLING\n"
47 " vec4 aColor = texelFetch (uInputTexture, ivec2 (gl_FragCoord.xy), 0);\n"
49 "#ifdef PATH_TRACING\n"
50 " float aDepth = aColor.w; // path tracing uses averaged depth\n"
52 " float aDepth = texelFetch (uDepthTexture, ivec2 (gl_FragCoord.xy), 0).r;\n"
55 " gl_FragDepth = aDepth;\n"
57 "#else // ADAPTIVE_SAMPLING\n"
59 " ivec2 aPixel = ivec2 (gl_FragCoord.xy);\n"
61 " vec4 aColor = vec4 (0.0);\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"
73 " // calculate normalization factor\n"
74 " float aSampleWeight = 1.f / max (1.0, aColor.w);\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"
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"
84 " float aAverRad = dot (aColor.rgb, LUMA) * aSampleWeight;\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"
90 " // calculate visual error\n"
91 " float anError = (aAverRad - aHalfRad) * (aAverRad - aHalfRad);\n"
93 " // accumulate visual error to current block\n"
94 " imageAtomicAdd (uVarianceImage, ivec2 (aPixel / vec2 (BLOCK_SIZE)), int (anError * SCALE_FACTOR));\n"
96 " if (uDebugAdaptive == 0) // normal rendering\n"
98 " aColor = vec4 (aColor.rgb * aSampleWeight, 1.0);\n"
100 " else // showing number of samples\n"
102 " aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);\n"
105 "#endif // ADAPTIVE_SAMPLING\n"
107 "#ifdef PATH_TRACING\n"
109 " // apply gamma correction (we use gamma = 2)\n"
110 " OutColor = vec4 (sqrt (aColor.rgb), 0.f);\n"
112 "#else // not PATH_TRACING\n"
114 " OutColor = aColor;\n"