denoise.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. /*
  2. * Copyright 2021 elven cache. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. /*
  6. * Implement SVGF style denoising as bgfx example. Goal is to explore various
  7. * options and parameters, not produce an optimized, efficient denoiser.
  8. *
  9. * Starts with deferred rendering scene with very basic lighting. Lighting is
  10. * masked out with a noise pattern to provide something to denoise. There are
  11. * two options for the noise pattern. One is a fixed 2x2 dither pattern to
  12. * stand-in for lighting at quarter resolution. The other is the common
  13. * shadertoy random pattern as a stand-in for some fancier lighting without
  14. * enough samples per pixel, like ray tracing.
  15. *
  16. * First a temporal denoising filter is applied. The temporal filter is only
  17. * using normals to reject previous samples. The SVGF paper also describes using
  18. * depth comparison to reject samples but that is not implemented here.
  19. *
  20. * Followed by some number of spatial filters. These are implemented like in the
  21. * SVGF paper. As an alternative to the 5x5 Edge-Avoiding A-Trous filter, can
  22. * select a 3x3 filter instead. The 3x3 filter takes fewer samples and covers a
  23. * smaller area, but takes less time to compute. From a loosely eyeballed
  24. * comparison, N 5x5 passes looks similar to N+1 3x3 passes. The wider spatial
  25. * filters take a fair chunk of time to compute. I wonder if it would be a good
  26. * idea to interleave the input texture before computing, after the first pass
  27. * which skips zero pixels.
  28. *
  29. * I have not implemetened the variance guided part.
  30. *
  31. * There's also an optional TXAA pass to be applied after. I am not happy with
  32. * its implementation yet, so it defaults to off here.
  33. */
  34. /*
  35. * Reference(s):
  36. *
  37. * - Spatiotemporal Variance-Guided Filtering: Real-Time Reconstruction for Path-Traced Global Illumination.
  38. * https://web.archive.org/web/20170720213354/https://research.nvidia.com/sites/default/files/pubs/2017-07_Spatiotemporal-Variance-Guided-Filtering%3A/svgf_preprint.pdf
  39. *
  40. * - Streaming G-Buffer Compression for Multi-Sample Anti-Aliasing.
  41. * https://web.archive.org/web/20200807211002/https://software.intel.com/content/www/us/en/develop/articles/streaming-g-buffer-compression-for-multi-sample-anti-aliasing.html
  42. *
  43. * - Edge-Avoiding A-Trous Wavelet Transform for fast Global Illumination Filtering
  44. * https://web.archive.org/web/20130412085423/https://www.uni-ulm.de/fileadmin/website_uni_ulm/iui.inst.100/institut/Papers/atrousGIfilter.pdf
  45. *
  46. */
  47. #include <common.h>
  48. #include <camera.h>
  49. #include <bgfx_utils.h>
  50. #include <imgui/imgui.h>
  51. #include <bx/rng.h>
  52. #include <bx/os.h>
  53. namespace {
  54. #define DENOISE_MAX_PASSES 6
  55. // Gbuffer has multiple render targets
  56. #define GBUFFER_RT_COLOR 0
  57. #define GBUFFER_RT_NORMAL 1
  58. #define GBUFFER_RT_VELOCITY 2
  59. #define GBUFFER_RT_DEPTH 3
  60. #define GBUFFER_RENDER_TARGETS 4
  61. #define MODEL_COUNT 100
  62. static const char * s_meshPaths[] =
  63. {
  64. "meshes/column.bin",
  65. "meshes/tree.bin",
  66. "meshes/hollowcube.bin",
  67. "meshes/bunny.bin"
  68. };
  69. static const float s_meshScale[] =
  70. {
  71. 0.05f,
  72. 0.15f,
  73. 0.25f,
  74. 0.25f
  75. };
  76. // Vertex decl for our screen space quad (used in deferred rendering)
  77. struct PosTexCoord0Vertex
  78. {
  79. float m_x;
  80. float m_y;
  81. float m_z;
  82. float m_u;
  83. float m_v;
  84. static void init()
  85. {
  86. ms_layout
  87. .begin()
  88. .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
  89. .add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
  90. .end();
  91. }
  92. static bgfx::VertexLayout ms_layout;
  93. };
  94. bgfx::VertexLayout PosTexCoord0Vertex::ms_layout;
  95. struct Uniforms
  96. {
  97. enum { NumVec4 = 13 };
  98. void init() {
  99. u_params = bgfx::createUniform("u_params", bgfx::UniformType::Vec4, NumVec4);
  100. };
  101. void submit() const {
  102. bgfx::setUniform(u_params, m_params, NumVec4);
  103. }
  104. void destroy() {
  105. bgfx::destroy(u_params);
  106. }
  107. union
  108. {
  109. struct
  110. {
  111. /* 0 */ struct { float m_cameraJitterCurr[2]; float m_cameraJitterPrev[2]; };
  112. /* 1 */ struct { float m_feedbackMin; float m_feedbackMax; float m_unused1[2]; };
  113. /* 2 */ struct { float m_unused2; float m_applyMitchellFilter; float m_options[2]; };
  114. /* 3-6 */ struct { float m_worldToViewPrev[16]; };
  115. /* 7-10 */ struct { float m_viewToProjPrev[16]; };
  116. /* 11 */ struct { float m_frameOffsetForNoise; float m_noiseType; float m_unused11[2]; };
  117. /* 12 */ struct { float m_denoiseStep; float m_sigmaDepth; float m_sigmaNormal; float m_unused12; };
  118. };
  119. float m_params[NumVec4 * 4];
  120. };
  121. bgfx::UniformHandle u_params;
  122. };
  123. struct RenderTarget
  124. {
  125. void init(uint32_t _width, uint32_t _height, bgfx::TextureFormat::Enum _format, uint64_t _flags)
  126. {
  127. m_texture = bgfx::createTexture2D(uint16_t(_width), uint16_t(_height), false, 1, _format, _flags);
  128. const bool destroyTextures = true;
  129. m_buffer = bgfx::createFrameBuffer(1, &m_texture, destroyTextures);
  130. }
  131. void destroy()
  132. {
  133. // also responsible for destroying texture
  134. bgfx::destroy(m_buffer);
  135. }
  136. bgfx::TextureHandle m_texture;
  137. bgfx::FrameBufferHandle m_buffer;
  138. };
  139. void screenSpaceQuad(float _textureWidth, float _textureHeight, float _texelHalf, bool _originBottomLeft, float _width = 1.0f, float _height = 1.0f)
  140. {
  141. if (3 == bgfx::getAvailTransientVertexBuffer(3, PosTexCoord0Vertex::ms_layout) )
  142. {
  143. bgfx::TransientVertexBuffer vb;
  144. bgfx::allocTransientVertexBuffer(&vb, 3, PosTexCoord0Vertex::ms_layout);
  145. PosTexCoord0Vertex* vertex = (PosTexCoord0Vertex*)vb.data;
  146. const float minx = -_width;
  147. const float maxx = _width;
  148. const float miny = 0.0f;
  149. const float maxy = _height * 2.0f;
  150. const float texelHalfW = _texelHalf / _textureWidth;
  151. const float texelHalfH = _texelHalf / _textureHeight;
  152. const float minu = -1.0f + texelHalfW;
  153. const float maxu = 1.0f + texelHalfW;
  154. const float zz = 0.0f;
  155. float minv = texelHalfH;
  156. float maxv = 2.0f + texelHalfH;
  157. if (_originBottomLeft)
  158. {
  159. float temp = minv;
  160. minv = maxv;
  161. maxv = temp;
  162. minv -= 1.0f;
  163. maxv -= 1.0f;
  164. }
  165. vertex[0].m_x = minx;
  166. vertex[0].m_y = miny;
  167. vertex[0].m_z = zz;
  168. vertex[0].m_u = minu;
  169. vertex[0].m_v = minv;
  170. vertex[1].m_x = maxx;
  171. vertex[1].m_y = miny;
  172. vertex[1].m_z = zz;
  173. vertex[1].m_u = maxu;
  174. vertex[1].m_v = minv;
  175. vertex[2].m_x = maxx;
  176. vertex[2].m_y = maxy;
  177. vertex[2].m_z = zz;
  178. vertex[2].m_u = maxu;
  179. vertex[2].m_v = maxv;
  180. bgfx::setVertexBuffer(0, &vb);
  181. }
  182. }
  183. void vec2Set(float* _v, float _x, float _y)
  184. {
  185. _v[0] = _x;
  186. _v[1] = _y;
  187. }
  188. void mat4Set(float * _m, const float * _src)
  189. {
  190. const uint32_t MAT4_FLOATS = 16;
  191. for (uint32_t ii = 0; ii < MAT4_FLOATS; ++ii) {
  192. _m[ii] = _src[ii];
  193. }
  194. }
  195. class ExampleDenoise : public entry::AppI
  196. {
  197. public:
  198. ExampleDenoise(const char* _name, const char* _description)
  199. : entry::AppI(_name, _description)
  200. , m_currFrame(UINT32_MAX)
  201. , m_texelHalf(0.0f)
  202. {
  203. }
  204. void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) override
  205. {
  206. Args args(_argc, _argv);
  207. m_width = _width;
  208. m_height = _height;
  209. m_debug = BGFX_DEBUG_NONE;
  210. m_reset = BGFX_RESET_VSYNC;
  211. bgfx::Init init;
  212. init.type = args.m_type;
  213. init.vendorId = args.m_pciId;
  214. init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
  215. init.platformData.ndt = entry::getNativeDisplayHandle();
  216. init.platformData.type = entry::getNativeWindowHandleType(entry::kDefaultWindowHandle);
  217. init.resolution.width = m_width;
  218. init.resolution.height = m_height;
  219. init.resolution.reset = m_reset;
  220. bgfx::init(init);
  221. // Enable debug text.
  222. bgfx::setDebug(m_debug);
  223. // Create uniforms
  224. m_uniforms.init();
  225. // Create texture sampler uniforms (used when we bind textures)
  226. s_albedo = bgfx::createUniform("s_albedo", bgfx::UniformType::Sampler); // Model's source albedo
  227. s_color = bgfx::createUniform("s_color", bgfx::UniformType::Sampler); // Color (albedo) gbuffer, default color input
  228. s_normal = bgfx::createUniform("s_normal", bgfx::UniformType::Sampler); // Normal gbuffer, Model's source normal
  229. s_velocity = bgfx::createUniform("s_velocity", bgfx::UniformType::Sampler); // Velocity gbuffer
  230. s_depth = bgfx::createUniform("s_depth", bgfx::UniformType::Sampler); // Depth gbuffer
  231. s_previousColor = bgfx::createUniform("s_previousColor", bgfx::UniformType::Sampler); // Previous frame's result
  232. s_previousNormal = bgfx::createUniform("s_previousNormal", bgfx::UniformType::Sampler); // Previous frame's gbuffer normal
  233. // Create program from shaders.
  234. m_gbufferProgram = loadProgram("vs_denoise_gbuffer", "fs_denoise_gbuffer"); // Fill gbuffer
  235. m_combineProgram = loadProgram("vs_denoise_screenquad", "fs_denoise_deferred_combine"); // Compute lighting from gbuffer
  236. m_copyProgram = loadProgram("vs_denoise_screenquad", "fs_denoise_copy");
  237. m_denoiseTemporalProgram = loadProgram("vs_denoise_screenquad", "fs_denoise_temporal");
  238. m_denoiseSpatialProgram3x3 = loadProgram("vs_denoise_screenquad", "fs_denoise_spatial_3x3");
  239. m_denoiseSpatialProgram5x5 = loadProgram("vs_denoise_screenquad", "fs_denoise_spatial_5x5");
  240. m_denoiseApplyLighting = loadProgram("vs_denoise_screenquad", "fs_denoise_apply_lighting");
  241. m_txaaProgram = loadProgram("vs_denoise_screenquad", "fs_denoise_txaa");
  242. // Load some meshes
  243. for (uint32_t ii = 0; ii < BX_COUNTOF(s_meshPaths); ++ii)
  244. {
  245. m_meshes[ii] = meshLoad(s_meshPaths[ii]);
  246. }
  247. // Randomly create some models
  248. bx::RngMwc mwc;
  249. for (uint32_t ii = 0; ii < BX_COUNTOF(m_models); ++ii)
  250. {
  251. Model& model = m_models[ii];
  252. model.mesh = mwc.gen() % BX_COUNTOF(s_meshPaths);
  253. model.position[0] = ( ( (mwc.gen() % 256) ) - 128.0f) / 20.0f;
  254. model.position[1] = 0;
  255. model.position[2] = ( ( (mwc.gen() % 256) ) - 128.0f) / 20.0f;
  256. }
  257. // Load ground, just use the cube
  258. m_ground = meshLoad("meshes/cube.bin");
  259. m_groundTexture = loadTexture("textures/fieldstone-rgba.dds");
  260. m_normalTexture = loadTexture("textures/fieldstone-n.dds");
  261. m_recreateFrameBuffers = false;
  262. createFramebuffers();
  263. // Vertex decl
  264. PosTexCoord0Vertex::init();
  265. // Init camera
  266. cameraCreate();
  267. cameraSetPosition({ 0.0f, 1.5f, 0.0f });
  268. cameraSetVerticalAngle(-0.3f);
  269. m_fovY = 60.0f;
  270. // Init "prev" matrices, will be same for first frame
  271. cameraGetViewMtx(m_view);
  272. bx::mtxProj(m_proj, m_fovY, float(m_size[0]) / float(m_size[1]), 0.01f, 100.0f, bgfx::getCaps()->homogeneousDepth);
  273. mat4Set(m_worldToViewPrev, m_view);
  274. mat4Set(m_viewToProjPrev, m_proj);
  275. // Track whether previous results are valid
  276. m_havePrevious = false;
  277. // Get renderer capabilities info.
  278. const bgfx::RendererType::Enum renderer = bgfx::getRendererType();
  279. m_texelHalf = bgfx::RendererType::Direct3D9 == renderer ? 0.5f : 0.0f;
  280. imguiCreate();
  281. }
  282. int32_t shutdown() override
  283. {
  284. for (uint32_t ii = 0; ii < BX_COUNTOF(s_meshPaths); ++ii)
  285. {
  286. meshUnload(m_meshes[ii]);
  287. }
  288. meshUnload(m_ground);
  289. bgfx::destroy(m_normalTexture);
  290. bgfx::destroy(m_groundTexture);
  291. bgfx::destroy(m_gbufferProgram);
  292. bgfx::destroy(m_combineProgram);
  293. bgfx::destroy(m_copyProgram);
  294. bgfx::destroy(m_denoiseTemporalProgram);
  295. bgfx::destroy(m_denoiseSpatialProgram3x3);
  296. bgfx::destroy(m_denoiseSpatialProgram5x5);
  297. bgfx::destroy(m_denoiseApplyLighting);
  298. bgfx::destroy(m_txaaProgram);
  299. m_uniforms.destroy();
  300. bgfx::destroy(s_albedo);
  301. bgfx::destroy(s_color);
  302. bgfx::destroy(s_normal);
  303. bgfx::destroy(s_velocity);
  304. bgfx::destroy(s_depth);
  305. bgfx::destroy(s_previousColor);
  306. bgfx::destroy(s_previousNormal);
  307. destroyFramebuffers();
  308. cameraDestroy();
  309. imguiDestroy();
  310. bgfx::shutdown();
  311. return 0;
  312. }
  313. bool update() override
  314. {
  315. if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
  316. {
  317. // skip processing when minimized, otherwise crashing
  318. if (0 == m_width
  319. || 0 == m_height)
  320. {
  321. return true;
  322. }
  323. // Update frame timer
  324. int64_t now = bx::getHPCounter();
  325. static int64_t last = now;
  326. const int64_t frameTime = now - last;
  327. last = now;
  328. const double freq = double(bx::getHPFrequency() );
  329. const float deltaTime = float(frameTime / freq);
  330. const bgfx::Caps* caps = bgfx::getCaps();
  331. if (m_size[0] != (int32_t)m_width
  332. || m_size[1] != (int32_t)m_height
  333. || m_recreateFrameBuffers)
  334. {
  335. destroyFramebuffers();
  336. createFramebuffers();
  337. m_recreateFrameBuffers = false;
  338. }
  339. // Update camera
  340. cameraUpdate(deltaTime*0.15f, m_mouseState, ImGui::MouseOverArea() );
  341. // Set up matrices for gbuffer
  342. cameraGetViewMtx(m_view);
  343. updateUniforms();
  344. bx::mtxProj(m_proj, m_fovY, float(m_size[0]) / float(m_size[1]), 0.01f, 100.0f, caps->homogeneousDepth);
  345. bx::mtxProj(m_proj2, m_fovY, float(m_size[0]) / float(m_size[1]), 0.01f, 100.0f, false);
  346. if (m_enableTxaa)
  347. {
  348. m_proj[2*4+0] += m_jitter[0] * (2.0f / m_size[0]);
  349. m_proj[2*4+1] -= m_jitter[1] * (2.0f / m_size[1]);
  350. }
  351. bgfx::ViewId view = 0;
  352. // Draw everything into gbuffer
  353. {
  354. bgfx::setViewName(view, "GBuffer");
  355. bgfx::setViewClear(view
  356. , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
  357. , 0
  358. , 1.0f
  359. , 0
  360. );
  361. bgfx::setViewRect(view, 0, 0, uint16_t(m_size[0]), uint16_t(m_size[1]) );
  362. bgfx::setViewTransform(view, m_view, m_proj);
  363. // Make sure when we draw it goes into gbuffer and not backbuffer
  364. bgfx::setViewFrameBuffer(view, m_gbuffer);
  365. bgfx::setState(0
  366. | BGFX_STATE_WRITE_RGB
  367. | BGFX_STATE_WRITE_A
  368. | BGFX_STATE_WRITE_Z
  369. | BGFX_STATE_DEPTH_TEST_LESS
  370. );
  371. drawAllModels(view, m_gbufferProgram, m_uniforms);
  372. ++view;
  373. }
  374. float orthoProj[16];
  375. bx::mtxOrtho(orthoProj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, caps->homogeneousDepth);
  376. // Shade gbuffer
  377. {
  378. bgfx::setViewName(view, "Combine");
  379. // for some reason, previous draws texture lingering in transform stack
  380. // need to clear out, otherwise this copy is garbled. this used to work
  381. // and broke after updating, but i last updated like 2 years ago.
  382. float identity[16];
  383. bx::mtxIdentity(identity);
  384. bgfx::setTransform(identity);
  385. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  386. bgfx::setViewTransform(view, NULL, orthoProj);
  387. bgfx::setViewFrameBuffer(view, m_currentColor.m_buffer);
  388. bgfx::setState(0
  389. | BGFX_STATE_WRITE_RGB
  390. | BGFX_STATE_WRITE_A
  391. | BGFX_STATE_DEPTH_TEST_ALWAYS
  392. );
  393. bgfx::setTexture(0, s_color, m_gbufferTex[GBUFFER_RT_COLOR]);
  394. bgfx::setTexture(1, s_normal, m_gbufferTex[GBUFFER_RT_NORMAL]);
  395. m_uniforms.submit();
  396. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  397. bgfx::submit(view, m_combineProgram);
  398. ++view;
  399. }
  400. // update last texture written, to chain passes together
  401. bgfx::TextureHandle lastTex = m_currentColor.m_texture;
  402. // denoise temporal pass
  403. if (m_useTemporalPass && m_havePrevious)
  404. {
  405. bgfx::setViewName(view, "Denoise Temporal");
  406. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  407. bgfx::setViewTransform(view, NULL, orthoProj);
  408. bgfx::setViewFrameBuffer(view, m_temporaryColor.m_buffer);
  409. bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
  410. // want color, prevColor
  411. // normal, prevNormal
  412. // depth, prevDepth to reject previous samples from accumulating - skipping depth for now
  413. bgfx::setTexture(0, s_color, lastTex);
  414. bgfx::setTexture(1, s_normal, m_gbufferTex[GBUFFER_RT_NORMAL]);
  415. bgfx::setTexture(2, s_velocity, m_gbufferTex[GBUFFER_RT_VELOCITY]);
  416. bgfx::setTexture(3, s_previousColor, m_previousDenoise.m_texture);
  417. bgfx::setTexture(4, s_previousNormal, m_previousNormal.m_texture);
  418. m_uniforms.submit();
  419. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  420. bgfx::submit(view, m_denoiseTemporalProgram);
  421. ++view;
  422. lastTex = m_temporaryColor.m_texture;
  423. }
  424. // denoise spatial passes
  425. if (0 < m_denoisePasses)
  426. {
  427. // variable number of passes for denoise, alternate between two textures/buffers
  428. bgfx::FrameBufferHandle destBuffer[] =
  429. {
  430. m_previousDenoise.m_buffer,
  431. m_currentColor.m_buffer,
  432. m_temporaryColor.m_buffer,
  433. m_currentColor.m_buffer,
  434. m_temporaryColor.m_buffer,
  435. m_currentColor.m_buffer,
  436. };
  437. BX_STATIC_ASSERT(BX_COUNTOF(destBuffer) == DENOISE_MAX_PASSES);
  438. const uint32_t denoisePasses = bx::min(DENOISE_MAX_PASSES, m_denoisePasses);
  439. for (uint32_t ii = 0; ii < denoisePasses; ++ii)
  440. {
  441. char name[64];
  442. bx::snprintf(name, BX_COUNTOF(name), "Denoise %d/%d", ii, denoisePasses-1);
  443. bgfx::setViewName(view, name);
  444. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  445. bgfx::setViewTransform(view, NULL, orthoProj);
  446. bgfx::setViewFrameBuffer(view, destBuffer[ii]);
  447. bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
  448. bgfx::setTexture(0, s_color, lastTex);
  449. bgfx::setTexture(1, s_normal, m_gbufferTex[GBUFFER_RT_NORMAL]);
  450. bgfx::setTexture(2, s_depth, m_gbufferTex[GBUFFER_RT_DEPTH]);
  451. // need to update some denoise uniforms per draw
  452. const float denoiseStepScale = bx::pow(2.0f, float(ii) );
  453. m_uniforms.m_denoiseStep = denoiseStepScale;
  454. m_uniforms.submit();
  455. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  456. const bgfx::ProgramHandle spatialProgram = (0 == m_spatialSampleType)
  457. ? m_denoiseSpatialProgram3x3
  458. : m_denoiseSpatialProgram5x5
  459. ;
  460. bgfx::submit(view, spatialProgram);
  461. ++view;
  462. if (m_previousDenoise.m_buffer.idx == destBuffer[ii].idx)
  463. {
  464. lastTex = m_previousDenoise.m_texture;
  465. }
  466. else if (m_temporaryColor.m_buffer.idx == destBuffer[ii].idx)
  467. {
  468. lastTex = m_temporaryColor.m_texture;
  469. }
  470. else
  471. {
  472. lastTex = m_currentColor.m_texture;
  473. }
  474. }
  475. }
  476. else
  477. {
  478. // need color result for temporal denoise if not supplied by spatial pass
  479. // (per SVGF paper, reuse previous frame's first spatial pass output as previous color
  480. bgfx::setViewName(view, "Copy Color for Temporal Denoise");
  481. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  482. bgfx::setViewTransform(view, NULL, orthoProj);
  483. bgfx::setViewFrameBuffer(view, m_previousDenoise.m_buffer);
  484. bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
  485. bgfx::setTexture(0, s_color, lastTex);
  486. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  487. bgfx::submit(view, m_copyProgram);
  488. ++view;
  489. }
  490. // apply lighting
  491. {
  492. bgfx::setViewName(view, "Apply Lighting");
  493. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  494. bgfx::setViewTransform(view, NULL, orthoProj);
  495. bgfx::FrameBufferHandle destBuffer = (lastTex.idx == m_currentColor.m_texture.idx)
  496. ? m_temporaryColor.m_buffer
  497. : m_currentColor.m_buffer
  498. ;
  499. bgfx::setViewFrameBuffer(view, destBuffer);
  500. bgfx::setState(0
  501. | BGFX_STATE_WRITE_RGB
  502. | BGFX_STATE_WRITE_A
  503. | BGFX_STATE_DEPTH_TEST_ALWAYS
  504. );
  505. bgfx::setTexture(0, s_color, lastTex);
  506. bgfx::setTexture(1, s_albedo, m_gbufferTex[GBUFFER_RT_COLOR]);
  507. m_uniforms.submit();
  508. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  509. bgfx::submit(view, m_denoiseApplyLighting);
  510. ++view;
  511. lastTex = (m_temporaryColor.m_buffer.idx == destBuffer.idx)
  512. ? m_temporaryColor.m_texture
  513. : m_currentColor.m_texture
  514. ;
  515. }
  516. if (m_enableTxaa)
  517. {
  518. // Draw txaa to txaa buffer
  519. {
  520. bgfx::setViewName(view, "Temporal AA");
  521. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  522. bgfx::setViewTransform(view, NULL, orthoProj);
  523. bgfx::setViewFrameBuffer(view, m_txaaColor.m_buffer);
  524. bgfx::setState(0
  525. | BGFX_STATE_WRITE_RGB
  526. | BGFX_STATE_WRITE_A
  527. | BGFX_STATE_DEPTH_TEST_ALWAYS
  528. );
  529. bgfx::setTexture(0, s_color, lastTex);
  530. bgfx::setTexture(1, s_previousColor, m_previousColor.m_texture);
  531. bgfx::setTexture(2, s_velocity, m_gbufferTex[GBUFFER_RT_VELOCITY]);
  532. bgfx::setTexture(3, s_depth, m_gbufferTex[GBUFFER_RT_DEPTH]);
  533. m_uniforms.submit();
  534. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  535. bgfx::submit(view, m_txaaProgram);
  536. ++view;
  537. }
  538. // Copy txaa result to previous
  539. {
  540. bgfx::setViewName(view, "Copy to Previous");
  541. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  542. bgfx::setViewTransform(view, NULL, orthoProj);
  543. bgfx::setViewFrameBuffer(view, m_previousColor.m_buffer);
  544. bgfx::setState(0
  545. | BGFX_STATE_WRITE_RGB
  546. | BGFX_STATE_WRITE_A
  547. | BGFX_STATE_DEPTH_TEST_ALWAYS
  548. );
  549. bgfx::setTexture(0, s_color, m_txaaColor.m_texture);
  550. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  551. bgfx::submit(view, m_copyProgram);
  552. ++view;
  553. }
  554. // Copy txaa result to swap chain
  555. {
  556. bgfx::setViewName(view, "Display");
  557. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  558. bgfx::setViewTransform(view, NULL, orthoProj);
  559. bgfx::setViewFrameBuffer(view, BGFX_INVALID_HANDLE);
  560. bgfx::setState(0
  561. | BGFX_STATE_WRITE_RGB
  562. | BGFX_STATE_WRITE_A
  563. | BGFX_STATE_DEPTH_TEST_ALWAYS
  564. );
  565. bgfx::setTexture(0, s_color, m_txaaColor.m_texture);
  566. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  567. bgfx::submit(view, m_copyProgram);
  568. ++view;
  569. }
  570. }
  571. else
  572. {
  573. // Copy color result to swap chain
  574. {
  575. bgfx::setViewName(view, "Display");
  576. bgfx::setViewClear(view
  577. , BGFX_CLEAR_NONE
  578. , 0
  579. , 1.0f
  580. , 0
  581. );
  582. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  583. bgfx::setViewTransform(view, NULL, orthoProj);
  584. bgfx::setViewFrameBuffer(view, BGFX_INVALID_HANDLE);
  585. bgfx::setState(0
  586. | BGFX_STATE_WRITE_RGB
  587. | BGFX_STATE_WRITE_A
  588. );
  589. bgfx::setTexture(0, s_color, lastTex);
  590. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  591. bgfx::submit(view, m_copyProgram);
  592. ++view;
  593. }
  594. }
  595. // copy the normal buffer for next time
  596. {
  597. bgfx::setViewName(view, "Copy Normals");
  598. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  599. bgfx::setViewTransform(view, NULL, orthoProj);
  600. bgfx::setViewFrameBuffer(view, m_previousNormal.m_buffer);
  601. bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
  602. bgfx::setTexture(0, s_color, m_gbufferTex[GBUFFER_RT_NORMAL]);
  603. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  604. bgfx::submit(view, m_copyProgram);
  605. ++view;
  606. // update previous status
  607. m_havePrevious = true;
  608. }
  609. // Copy matrices for next time
  610. mat4Set(m_worldToViewPrev, m_view);
  611. mat4Set(m_viewToProjPrev, m_proj);
  612. // Draw UI
  613. imguiBeginFrame(m_mouseState.m_mx
  614. , m_mouseState.m_my
  615. , (m_mouseState.m_buttons[entry::MouseButton::Left] ? IMGUI_MBUT_LEFT : 0)
  616. | (m_mouseState.m_buttons[entry::MouseButton::Right] ? IMGUI_MBUT_RIGHT : 0)
  617. | (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
  618. , m_mouseState.m_mz
  619. , uint16_t(m_width)
  620. , uint16_t(m_height)
  621. );
  622. showExampleDialog(this);
  623. ImGui::SetNextWindowPos(
  624. ImVec2(m_width - m_width / 4.0f - 10.0f, 10.0f)
  625. , ImGuiCond_FirstUseEver
  626. );
  627. ImGui::SetNextWindowSize(
  628. ImVec2(m_width / 4.0f, m_height / 1.24f)
  629. , ImGuiCond_FirstUseEver
  630. );
  631. ImGui::Begin("Settings"
  632. , NULL
  633. , 0
  634. );
  635. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
  636. {
  637. ImGui::TextWrapped(
  638. "In this demo, noise is added to results of deferred lighting. Then denoise is applied "
  639. "before multiplying the lit result with gbuffer albedo. Optionally, temporal antialiasing "
  640. "can be applied after that. (off by default, implementation blurry)");
  641. ImGui::Separator();
  642. ImGui::Text("noise controls:");
  643. ImGui::Combo("pattern", &m_noiseType, "none\0dither\0random\0\0");
  644. if (ImGui::IsItemHovered() )
  645. {
  646. ImGui::BeginTooltip();
  647. ImGui::Text("none");
  648. ImGui::BulletText("compare denoised results to this");
  649. ImGui::BulletText("brighter than noisy images, not losing any pixel's energy");
  650. ImGui::Text("dither");
  651. ImGui::BulletText("reject 3 out of 4 pixels in 2x2 pattern");
  652. ImGui::BulletText("could represent lower resolution signal");
  653. ImGui::Text("random");
  654. ImGui::BulletText("reject about half pixels, using common shader random");
  655. ImGui::BulletText("could represent monte carlo something or other");
  656. ImGui::EndTooltip();
  657. }
  658. ImGui::Checkbox("dynamic noise", &m_dynamicNoise);
  659. if (ImGui::IsItemHovered() )
  660. {
  661. ImGui::SetTooltip("update noise pattern each frame");
  662. }
  663. ImGui::Separator();
  664. }
  665. {
  666. ImGui::Text("temporal denoise pass controls:");
  667. ImGui::Checkbox("use temporal pass", &m_useTemporalPass);
  668. ImGui::Separator();
  669. }
  670. {
  671. ImGui::Text("spatial denoise pass controls:");
  672. ImGui::SliderInt("spatial passes", &m_denoisePasses, 0, DENOISE_MAX_PASSES);
  673. if (ImGui::IsItemHovered() )
  674. {
  675. ImGui::SetTooltip("set passes to 0 to turn off spatial denoise");
  676. }
  677. ImGui::Combo("spatial sample extent", &m_spatialSampleType, "three\0five\0\0");
  678. if (ImGui::IsItemHovered() )
  679. {
  680. ImGui::SetTooltip("select 3x3 or 5x5 filter kernel");
  681. }
  682. ImGui::SliderFloat("sigma z", &m_sigmaDepth, 0.0f, 0.1f, "%.5f");
  683. if (ImGui::IsItemHovered() )
  684. {
  685. ImGui::SetTooltip("lower sigma z, pickier blending across depth edges");
  686. }
  687. ImGui::SliderFloat("sigma n", &m_sigmaNormal, 1.0f, 256.0f);
  688. if (ImGui::IsItemHovered() )
  689. {
  690. ImGui::SetTooltip("higher sigma n, pickier blending across normal edges");
  691. }
  692. ImGui::Separator();
  693. }
  694. if (ImGui::CollapsingHeader("TXAA options") )
  695. {
  696. ImGui::Checkbox("use TXAA", &m_enableTxaa);
  697. ImGui::Checkbox("apply extra blur to current color", &m_applyMitchellFilter);
  698. if (ImGui::IsItemHovered() )
  699. {
  700. ImGui::SetTooltip("reduces flicker/crawl on thin features, maybe too much!");
  701. }
  702. ImGui::SliderFloat("feedback min", &m_feedbackMin, 0.0f, 1.0f);
  703. if (ImGui::IsItemHovered() )
  704. {
  705. ImGui::SetTooltip("minimum amount of previous frame to blend in");
  706. }
  707. ImGui::SliderFloat("feedback max", &m_feedbackMax, 0.0f, 1.0f);
  708. if (ImGui::IsItemHovered() )
  709. {
  710. ImGui::SetTooltip("maximum amount of previous frame to blend in");
  711. }
  712. ImGui::Checkbox("debug TXAA with slow frame rate", &m_useTxaaSlow);
  713. if (ImGui::IsItemHovered() )
  714. {
  715. ImGui::BeginTooltip();
  716. ImGui::Text("sleep 100ms per frame to highlight temporal artifacts");
  717. ImGui::Text("high framerate compensates for flickering, masking issues");
  718. ImGui::EndTooltip();
  719. }
  720. ImGui::Separator();
  721. }
  722. ImGui::End();
  723. imguiEndFrame();
  724. // Advance to next frame. Rendering thread will be kicked to
  725. // process submitted rendering primitives.
  726. m_currFrame = bgfx::frame();
  727. // add artificial wait to emphasize txaa behavior
  728. if (m_useTxaaSlow)
  729. {
  730. bx::sleep(100);
  731. }
  732. return true;
  733. }
  734. return false;
  735. }
  736. void drawAllModels(bgfx::ViewId _pass, bgfx::ProgramHandle _program, const Uniforms & _uniforms)
  737. {
  738. for (uint32_t ii = 0; ii < BX_COUNTOF(m_models); ++ii)
  739. {
  740. const Model& model = m_models[ii];
  741. // Set up transform matrix for each model
  742. const float scale = s_meshScale[model.mesh];
  743. float mtx[16];
  744. bx::mtxSRT(mtx
  745. , scale
  746. , scale
  747. , scale
  748. , 0.0f
  749. , 0.0f
  750. , 0.0f
  751. , model.position[0]
  752. , model.position[1]
  753. , model.position[2]
  754. );
  755. // Submit mesh to gbuffer
  756. bgfx::setTexture(0, s_albedo, m_groundTexture);
  757. bgfx::setTexture(1, s_normal, m_normalTexture);
  758. _uniforms.submit();
  759. meshSubmit(m_meshes[model.mesh], _pass, _program, mtx);
  760. }
  761. // Draw ground
  762. float mtxScale[16];
  763. const float scale = 10.0f;
  764. bx::mtxScale(mtxScale, scale, scale, scale);
  765. float mtxTranslate[16];
  766. bx::mtxTranslate(mtxTranslate
  767. , 0.0f
  768. , -10.0f
  769. , 0.0f
  770. );
  771. float mtx[16];
  772. bx::mtxMul(mtx, mtxScale, mtxTranslate);
  773. bgfx::setTexture(0, s_albedo, m_groundTexture);
  774. bgfx::setTexture(1, s_normal, m_normalTexture);
  775. _uniforms.submit();
  776. meshSubmit(m_ground, _pass, _program, mtx);
  777. }
  778. void createFramebuffers()
  779. {
  780. m_size[0] = m_width;
  781. m_size[1] = m_height;
  782. const uint64_t bilinearFlags = 0
  783. | BGFX_TEXTURE_RT
  784. | BGFX_SAMPLER_U_CLAMP
  785. | BGFX_SAMPLER_V_CLAMP
  786. ;
  787. const uint64_t pointSampleFlags = bilinearFlags
  788. | BGFX_SAMPLER_MIN_POINT
  789. | BGFX_SAMPLER_MAG_POINT
  790. | BGFX_SAMPLER_MIP_POINT
  791. ;
  792. m_gbufferTex[GBUFFER_RT_COLOR] = bgfx::createTexture2D(uint16_t(m_size[0]), uint16_t(m_size[1]), false, 1, bgfx::TextureFormat::BGRA8, pointSampleFlags);
  793. m_gbufferTex[GBUFFER_RT_NORMAL] = bgfx::createTexture2D(uint16_t(m_size[0]), uint16_t(m_size[1]), false, 1, bgfx::TextureFormat::BGRA8, pointSampleFlags);
  794. m_gbufferTex[GBUFFER_RT_VELOCITY] = bgfx::createTexture2D(uint16_t(m_size[0]), uint16_t(m_size[1]), false, 1, bgfx::TextureFormat::RG16F, pointSampleFlags);
  795. m_gbufferTex[GBUFFER_RT_DEPTH] = bgfx::createTexture2D(uint16_t(m_size[0]), uint16_t(m_size[1]), false, 1, bgfx::TextureFormat::D32F , pointSampleFlags);
  796. m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_gbufferTex), m_gbufferTex, true);
  797. bgfx::TextureFormat::Enum format = bgfx::TextureFormat::RG11B10F;
  798. if (!bgfx::isTextureValid(1, false, 1, format, bilinearFlags))
  799. {
  800. format = bgfx::TextureFormat::RGBA16F;
  801. }
  802. m_currentColor .init(m_size[0], m_size[1], format, bilinearFlags);
  803. m_previousColor .init(m_size[0], m_size[1], format, bilinearFlags);
  804. m_txaaColor .init(m_size[0], m_size[1], format, bilinearFlags);
  805. m_temporaryColor .init(m_size[0], m_size[1], format, bilinearFlags);
  806. m_previousNormal .init(m_size[0], m_size[1], format, pointSampleFlags);
  807. m_previousDenoise.init(m_size[0], m_size[1], format, bilinearFlags);
  808. }
  809. // all buffers set to destroy their textures
  810. void destroyFramebuffers()
  811. {
  812. bgfx::destroy(m_gbuffer);
  813. m_currentColor.destroy();
  814. m_previousColor.destroy();
  815. m_txaaColor.destroy();
  816. m_temporaryColor.destroy();
  817. m_previousNormal.destroy();
  818. m_previousDenoise.destroy();
  819. }
  820. void updateUniforms()
  821. {
  822. {
  823. uint32_t idx = m_currFrame % 8;
  824. const float offsets[] =
  825. {
  826. (1.0f/ 2.0f), (1.0f/3.0f),
  827. (1.0f/ 4.0f), (2.0f/3.0f),
  828. (3.0f/ 4.0f), (1.0f/9.0f),
  829. (1.0f/ 8.0f), (4.0f/9.0f),
  830. (5.0f/ 8.0f), (7.0f/9.0f),
  831. (3.0f/ 8.0f), (2.0f/9.0f),
  832. (7.0f/ 8.0f), (5.0f/9.0f),
  833. (1.0f/16.0f), (8.0f/9.0f),
  834. };
  835. // Strange constant for jitterX is because 8 values from halton2
  836. // sequence above do not average out to 0.5, 1/16 skews it to the
  837. // left. Subtracting a smaller value to center the range of jitter
  838. // around 0. Not necessary for jitterY. Not confident this makes sense...
  839. const float jitterX = 1.0f * (offsets[2*idx] - (7.125f/16.0f) );
  840. const float jitterY = 1.0f * (offsets[2*idx+1] - 0.5f);
  841. vec2Set(m_uniforms.m_cameraJitterCurr, jitterX, jitterY);
  842. vec2Set(m_uniforms.m_cameraJitterPrev, m_jitter[0], m_jitter[1]);
  843. m_jitter[0] = jitterX;
  844. m_jitter[1] = jitterY;
  845. }
  846. m_uniforms.m_feedbackMin = m_feedbackMin;
  847. m_uniforms.m_feedbackMax = m_feedbackMax;
  848. m_uniforms.m_applyMitchellFilter = m_applyMitchellFilter ? 1.0f : 0.0f;
  849. mat4Set(m_uniforms.m_worldToViewPrev, m_worldToViewPrev);
  850. mat4Set(m_uniforms.m_viewToProjPrev, m_viewToProjPrev);
  851. m_uniforms.m_frameOffsetForNoise = m_dynamicNoise
  852. ? float(m_currFrame % 8)
  853. : 0.0f
  854. ;
  855. m_uniforms.m_noiseType = float(m_noiseType);
  856. m_uniforms.m_sigmaDepth = m_sigmaDepth;
  857. m_uniforms.m_sigmaNormal = m_sigmaNormal;
  858. }
  859. uint32_t m_width;
  860. uint32_t m_height;
  861. uint32_t m_debug;
  862. uint32_t m_reset;
  863. entry::MouseState m_mouseState;
  864. // Resource handles
  865. bgfx::ProgramHandle m_gbufferProgram;
  866. bgfx::ProgramHandle m_combineProgram;
  867. bgfx::ProgramHandle m_copyProgram;
  868. bgfx::ProgramHandle m_denoiseTemporalProgram;
  869. bgfx::ProgramHandle m_denoiseSpatialProgram3x3;
  870. bgfx::ProgramHandle m_denoiseSpatialProgram5x5;
  871. bgfx::ProgramHandle m_denoiseApplyLighting;
  872. bgfx::ProgramHandle m_txaaProgram;
  873. // Shader uniforms
  874. Uniforms m_uniforms;
  875. // Uniforms to identify texture samplers
  876. bgfx::UniformHandle s_albedo;
  877. bgfx::UniformHandle s_color;
  878. bgfx::UniformHandle s_normal;
  879. bgfx::UniformHandle s_velocity;
  880. bgfx::UniformHandle s_depth;
  881. bgfx::UniformHandle s_previousColor;
  882. bgfx::UniformHandle s_previousNormal;
  883. bgfx::FrameBufferHandle m_gbuffer;
  884. bgfx::TextureHandle m_gbufferTex[GBUFFER_RENDER_TARGETS];
  885. RenderTarget m_currentColor;
  886. RenderTarget m_previousColor;
  887. RenderTarget m_txaaColor;
  888. RenderTarget m_temporaryColor; // need another buffer to ping-pong results
  889. RenderTarget m_previousNormal;
  890. RenderTarget m_previousDenoise; // color output by first spatial denoise pass, input to next frame as previous color
  891. struct Model
  892. {
  893. uint32_t mesh; // Index of mesh in m_meshes
  894. float position[3];
  895. };
  896. Model m_models[MODEL_COUNT];
  897. Mesh* m_meshes[BX_COUNTOF(s_meshPaths)];
  898. Mesh* m_ground;
  899. bgfx::TextureHandle m_groundTexture;
  900. bgfx::TextureHandle m_normalTexture;
  901. uint32_t m_currFrame;
  902. float m_texelHalf = 0.0f;
  903. float m_fovY = 60.0f;
  904. bool m_recreateFrameBuffers = false;
  905. bool m_havePrevious = false;
  906. float m_view[16];
  907. float m_proj[16];
  908. float m_proj2[16];
  909. float m_viewToProjPrev[16];
  910. float m_worldToViewPrev[16];
  911. float m_jitter[2];
  912. int32_t m_size[2];
  913. // UI parameters
  914. int32_t m_noiseType = 2;
  915. int32_t m_spatialSampleType = 1;
  916. int32_t m_denoisePasses = 5;
  917. float m_sigmaDepth = 0.05f;
  918. float m_sigmaNormal = 128.0f;
  919. float m_feedbackMin = 0.8f;
  920. float m_feedbackMax = 0.95f;
  921. bool m_dynamicNoise = true;
  922. bool m_useTemporalPass = true;
  923. bool m_enableTxaa = false;
  924. bool m_applyMitchellFilter = true;
  925. bool m_useTxaaSlow = false;
  926. };
  927. } // namespace
  928. ENTRY_IMPLEMENT_MAIN(ExampleDenoise, "43-denoise", "Denoise.");