denoise.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  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.resolution.width = m_width;
  217. init.resolution.height = m_height;
  218. init.resolution.reset = m_reset;
  219. bgfx::init(init);
  220. // Enable debug text.
  221. bgfx::setDebug(m_debug);
  222. // Create uniforms
  223. m_uniforms.init();
  224. // Create texture sampler uniforms (used when we bind textures)
  225. s_albedo = bgfx::createUniform("s_albedo", bgfx::UniformType::Sampler); // Model's source albedo
  226. s_color = bgfx::createUniform("s_color", bgfx::UniformType::Sampler); // Color (albedo) gbuffer, default color input
  227. s_normal = bgfx::createUniform("s_normal", bgfx::UniformType::Sampler); // Normal gbuffer, Model's source normal
  228. s_velocity = bgfx::createUniform("s_velocity", bgfx::UniformType::Sampler); // Velocity gbuffer
  229. s_depth = bgfx::createUniform("s_depth", bgfx::UniformType::Sampler); // Depth gbuffer
  230. s_previousColor = bgfx::createUniform("s_previousColor", bgfx::UniformType::Sampler); // Previous frame's result
  231. s_previousNormal = bgfx::createUniform("s_previousNormal", bgfx::UniformType::Sampler); // Previous frame's gbuffer normal
  232. // Create program from shaders.
  233. m_gbufferProgram = loadProgram("vs_denoise_gbuffer", "fs_denoise_gbuffer"); // Fill gbuffer
  234. m_combineProgram = loadProgram("vs_denoise_screenquad", "fs_denoise_deferred_combine"); // Compute lighting from gbuffer
  235. m_copyProgram = loadProgram("vs_denoise_screenquad", "fs_denoise_copy");
  236. m_denoiseTemporalProgram = loadProgram("vs_denoise_screenquad", "fs_denoise_temporal");
  237. m_denoiseSpatialProgram3x3 = loadProgram("vs_denoise_screenquad", "fs_denoise_spatial_3x3");
  238. m_denoiseSpatialProgram5x5 = loadProgram("vs_denoise_screenquad", "fs_denoise_spatial_5x5");
  239. m_denoiseApplyLighting = loadProgram("vs_denoise_screenquad", "fs_denoise_apply_lighting");
  240. m_txaaProgram = loadProgram("vs_denoise_screenquad", "fs_denoise_txaa");
  241. // Load some meshes
  242. for (uint32_t ii = 0; ii < BX_COUNTOF(s_meshPaths); ++ii)
  243. {
  244. m_meshes[ii] = meshLoad(s_meshPaths[ii]);
  245. }
  246. // Randomly create some models
  247. bx::RngMwc mwc;
  248. for (uint32_t ii = 0; ii < BX_COUNTOF(m_models); ++ii)
  249. {
  250. Model& model = m_models[ii];
  251. model.mesh = mwc.gen() % BX_COUNTOF(s_meshPaths);
  252. model.position[0] = ( ( (mwc.gen() % 256) ) - 128.0f) / 20.0f;
  253. model.position[1] = 0;
  254. model.position[2] = ( ( (mwc.gen() % 256) ) - 128.0f) / 20.0f;
  255. }
  256. // Load ground, just use the cube
  257. m_ground = meshLoad("meshes/cube.bin");
  258. m_groundTexture = loadTexture("textures/fieldstone-rgba.dds");
  259. m_normalTexture = loadTexture("textures/fieldstone-n.dds");
  260. m_recreateFrameBuffers = false;
  261. createFramebuffers();
  262. // Vertex decl
  263. PosTexCoord0Vertex::init();
  264. // Init camera
  265. cameraCreate();
  266. cameraSetPosition({ 0.0f, 1.5f, 0.0f });
  267. cameraSetVerticalAngle(-0.3f);
  268. m_fovY = 60.0f;
  269. // Init "prev" matrices, will be same for first frame
  270. cameraGetViewMtx(m_view);
  271. bx::mtxProj(m_proj, m_fovY, float(m_size[0]) / float(m_size[1]), 0.01f, 100.0f, bgfx::getCaps()->homogeneousDepth);
  272. mat4Set(m_worldToViewPrev, m_view);
  273. mat4Set(m_viewToProjPrev, m_proj);
  274. // Track whether previous results are valid
  275. m_havePrevious = false;
  276. // Get renderer capabilities info.
  277. const bgfx::RendererType::Enum renderer = bgfx::getRendererType();
  278. m_texelHalf = bgfx::RendererType::Direct3D9 == renderer ? 0.5f : 0.0f;
  279. imguiCreate();
  280. }
  281. int32_t shutdown() override
  282. {
  283. for (uint32_t ii = 0; ii < BX_COUNTOF(s_meshPaths); ++ii)
  284. {
  285. meshUnload(m_meshes[ii]);
  286. }
  287. meshUnload(m_ground);
  288. bgfx::destroy(m_normalTexture);
  289. bgfx::destroy(m_groundTexture);
  290. bgfx::destroy(m_gbufferProgram);
  291. bgfx::destroy(m_combineProgram);
  292. bgfx::destroy(m_copyProgram);
  293. bgfx::destroy(m_denoiseTemporalProgram);
  294. bgfx::destroy(m_denoiseSpatialProgram3x3);
  295. bgfx::destroy(m_denoiseSpatialProgram5x5);
  296. bgfx::destroy(m_denoiseApplyLighting);
  297. bgfx::destroy(m_txaaProgram);
  298. m_uniforms.destroy();
  299. bgfx::destroy(s_albedo);
  300. bgfx::destroy(s_color);
  301. bgfx::destroy(s_normal);
  302. bgfx::destroy(s_velocity);
  303. bgfx::destroy(s_depth);
  304. bgfx::destroy(s_previousColor);
  305. bgfx::destroy(s_previousNormal);
  306. destroyFramebuffers();
  307. cameraDestroy();
  308. imguiDestroy();
  309. bgfx::shutdown();
  310. return 0;
  311. }
  312. bool update() override
  313. {
  314. if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
  315. {
  316. // skip processing when minimized, otherwise crashing
  317. if (0 == m_width
  318. || 0 == m_height)
  319. {
  320. return true;
  321. }
  322. // Update frame timer
  323. int64_t now = bx::getHPCounter();
  324. static int64_t last = now;
  325. const int64_t frameTime = now - last;
  326. last = now;
  327. const double freq = double(bx::getHPFrequency() );
  328. const float deltaTime = float(frameTime / freq);
  329. const bgfx::Caps* caps = bgfx::getCaps();
  330. if (m_size[0] != (int32_t)m_width
  331. || m_size[1] != (int32_t)m_height
  332. || m_recreateFrameBuffers)
  333. {
  334. destroyFramebuffers();
  335. createFramebuffers();
  336. m_recreateFrameBuffers = false;
  337. }
  338. // Update camera
  339. cameraUpdate(deltaTime*0.15f, m_mouseState, ImGui::MouseOverArea() );
  340. // Set up matrices for gbuffer
  341. cameraGetViewMtx(m_view);
  342. updateUniforms();
  343. bx::mtxProj(m_proj, m_fovY, float(m_size[0]) / float(m_size[1]), 0.01f, 100.0f, caps->homogeneousDepth);
  344. bx::mtxProj(m_proj2, m_fovY, float(m_size[0]) / float(m_size[1]), 0.01f, 100.0f, false);
  345. if (m_enableTxaa)
  346. {
  347. m_proj[2*4+0] += m_jitter[0] * (2.0f / m_size[0]);
  348. m_proj[2*4+1] -= m_jitter[1] * (2.0f / m_size[1]);
  349. }
  350. bgfx::ViewId view = 0;
  351. // Draw everything into gbuffer
  352. {
  353. bgfx::setViewName(view, "GBuffer");
  354. bgfx::setViewClear(view
  355. , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH
  356. , 0
  357. , 1.0f
  358. , 0
  359. );
  360. bgfx::setViewRect(view, 0, 0, uint16_t(m_size[0]), uint16_t(m_size[1]) );
  361. bgfx::setViewTransform(view, m_view, m_proj);
  362. // Make sure when we draw it goes into gbuffer and not backbuffer
  363. bgfx::setViewFrameBuffer(view, m_gbuffer);
  364. bgfx::setState(0
  365. | BGFX_STATE_WRITE_RGB
  366. | BGFX_STATE_WRITE_A
  367. | BGFX_STATE_WRITE_Z
  368. | BGFX_STATE_DEPTH_TEST_LESS
  369. );
  370. drawAllModels(view, m_gbufferProgram, m_uniforms);
  371. ++view;
  372. }
  373. float orthoProj[16];
  374. bx::mtxOrtho(orthoProj, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, caps->homogeneousDepth);
  375. // Shade gbuffer
  376. {
  377. bgfx::setViewName(view, "Combine");
  378. // for some reason, previous draws texture lingering in transform stack
  379. // need to clear out, otherwise this copy is garbled. this used to work
  380. // and broke after updating, but i last updated like 2 years ago.
  381. float identity[16];
  382. bx::mtxIdentity(identity);
  383. bgfx::setTransform(identity);
  384. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  385. bgfx::setViewTransform(view, NULL, orthoProj);
  386. bgfx::setViewFrameBuffer(view, m_currentColor.m_buffer);
  387. bgfx::setState(0
  388. | BGFX_STATE_WRITE_RGB
  389. | BGFX_STATE_WRITE_A
  390. | BGFX_STATE_DEPTH_TEST_ALWAYS
  391. );
  392. bgfx::setTexture(0, s_color, m_gbufferTex[GBUFFER_RT_COLOR]);
  393. bgfx::setTexture(1, s_normal, m_gbufferTex[GBUFFER_RT_NORMAL]);
  394. m_uniforms.submit();
  395. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  396. bgfx::submit(view, m_combineProgram);
  397. ++view;
  398. }
  399. // update last texture written, to chain passes together
  400. bgfx::TextureHandle lastTex = m_currentColor.m_texture;
  401. // denoise temporal pass
  402. if (m_useTemporalPass && m_havePrevious)
  403. {
  404. bgfx::setViewName(view, "Denoise Temporal");
  405. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  406. bgfx::setViewTransform(view, NULL, orthoProj);
  407. bgfx::setViewFrameBuffer(view, m_temporaryColor.m_buffer);
  408. bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
  409. // want color, prevColor
  410. // normal, prevNormal
  411. // depth, prevDepth to reject previous samples from accumulating - skipping depth for now
  412. bgfx::setTexture(0, s_color, lastTex);
  413. bgfx::setTexture(1, s_normal, m_gbufferTex[GBUFFER_RT_NORMAL]);
  414. bgfx::setTexture(2, s_velocity, m_gbufferTex[GBUFFER_RT_VELOCITY]);
  415. bgfx::setTexture(3, s_previousColor, m_previousDenoise.m_texture);
  416. bgfx::setTexture(4, s_previousNormal, m_previousNormal.m_texture);
  417. m_uniforms.submit();
  418. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  419. bgfx::submit(view, m_denoiseTemporalProgram);
  420. ++view;
  421. lastTex = m_temporaryColor.m_texture;
  422. }
  423. // denoise spatial passes
  424. if (0 < m_denoisePasses)
  425. {
  426. // variable number of passes for denoise, alternate between two textures/buffers
  427. bgfx::FrameBufferHandle destBuffer[] =
  428. {
  429. m_previousDenoise.m_buffer,
  430. m_currentColor.m_buffer,
  431. m_temporaryColor.m_buffer,
  432. m_currentColor.m_buffer,
  433. m_temporaryColor.m_buffer,
  434. m_currentColor.m_buffer,
  435. };
  436. BX_STATIC_ASSERT(BX_COUNTOF(destBuffer) == DENOISE_MAX_PASSES);
  437. const uint32_t denoisePasses = bx::min(DENOISE_MAX_PASSES, m_denoisePasses);
  438. for (uint32_t ii = 0; ii < denoisePasses; ++ii)
  439. {
  440. char name[64];
  441. bx::snprintf(name, BX_COUNTOF(name), "Denoise %d/%d", ii, denoisePasses-1);
  442. bgfx::setViewName(view, name);
  443. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  444. bgfx::setViewTransform(view, NULL, orthoProj);
  445. bgfx::setViewFrameBuffer(view, destBuffer[ii]);
  446. bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
  447. bgfx::setTexture(0, s_color, lastTex);
  448. bgfx::setTexture(1, s_normal, m_gbufferTex[GBUFFER_RT_NORMAL]);
  449. bgfx::setTexture(2, s_depth, m_gbufferTex[GBUFFER_RT_DEPTH]);
  450. // need to update some denoise uniforms per draw
  451. const float denoiseStepScale = bx::pow(2.0f, float(ii) );
  452. m_uniforms.m_denoiseStep = denoiseStepScale;
  453. m_uniforms.submit();
  454. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  455. const bgfx::ProgramHandle spatialProgram = (0 == m_spatialSampleType)
  456. ? m_denoiseSpatialProgram3x3
  457. : m_denoiseSpatialProgram5x5
  458. ;
  459. bgfx::submit(view, spatialProgram);
  460. ++view;
  461. if (m_previousDenoise.m_buffer.idx == destBuffer[ii].idx)
  462. {
  463. lastTex = m_previousDenoise.m_texture;
  464. }
  465. else if (m_temporaryColor.m_buffer.idx == destBuffer[ii].idx)
  466. {
  467. lastTex = m_temporaryColor.m_texture;
  468. }
  469. else
  470. {
  471. lastTex = m_currentColor.m_texture;
  472. }
  473. }
  474. }
  475. else
  476. {
  477. // need color result for temporal denoise if not supplied by spatial pass
  478. // (per SVGF paper, reuse previous frame's first spatial pass output as previous color
  479. bgfx::setViewName(view, "Copy Color for Temporal Denoise");
  480. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  481. bgfx::setViewTransform(view, NULL, orthoProj);
  482. bgfx::setViewFrameBuffer(view, m_previousDenoise.m_buffer);
  483. bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
  484. bgfx::setTexture(0, s_color, lastTex);
  485. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  486. bgfx::submit(view, m_copyProgram);
  487. ++view;
  488. }
  489. // apply lighting
  490. {
  491. bgfx::setViewName(view, "Apply Lighting");
  492. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  493. bgfx::setViewTransform(view, NULL, orthoProj);
  494. bgfx::FrameBufferHandle destBuffer = (lastTex.idx == m_currentColor.m_texture.idx)
  495. ? m_temporaryColor.m_buffer
  496. : m_currentColor.m_buffer
  497. ;
  498. bgfx::setViewFrameBuffer(view, destBuffer);
  499. bgfx::setState(0
  500. | BGFX_STATE_WRITE_RGB
  501. | BGFX_STATE_WRITE_A
  502. | BGFX_STATE_DEPTH_TEST_ALWAYS
  503. );
  504. bgfx::setTexture(0, s_color, lastTex);
  505. bgfx::setTexture(1, s_albedo, m_gbufferTex[GBUFFER_RT_COLOR]);
  506. m_uniforms.submit();
  507. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  508. bgfx::submit(view, m_denoiseApplyLighting);
  509. ++view;
  510. lastTex = (m_temporaryColor.m_buffer.idx == destBuffer.idx)
  511. ? m_temporaryColor.m_texture
  512. : m_currentColor.m_texture
  513. ;
  514. }
  515. if (m_enableTxaa)
  516. {
  517. // Draw txaa to txaa buffer
  518. {
  519. bgfx::setViewName(view, "Temporal AA");
  520. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  521. bgfx::setViewTransform(view, NULL, orthoProj);
  522. bgfx::setViewFrameBuffer(view, m_txaaColor.m_buffer);
  523. bgfx::setState(0
  524. | BGFX_STATE_WRITE_RGB
  525. | BGFX_STATE_WRITE_A
  526. | BGFX_STATE_DEPTH_TEST_ALWAYS
  527. );
  528. bgfx::setTexture(0, s_color, lastTex);
  529. bgfx::setTexture(1, s_previousColor, m_previousColor.m_texture);
  530. bgfx::setTexture(2, s_velocity, m_gbufferTex[GBUFFER_RT_VELOCITY]);
  531. bgfx::setTexture(3, s_depth, m_gbufferTex[GBUFFER_RT_DEPTH]);
  532. m_uniforms.submit();
  533. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  534. bgfx::submit(view, m_txaaProgram);
  535. ++view;
  536. }
  537. // Copy txaa result to previous
  538. {
  539. bgfx::setViewName(view, "Copy to Previous");
  540. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  541. bgfx::setViewTransform(view, NULL, orthoProj);
  542. bgfx::setViewFrameBuffer(view, m_previousColor.m_buffer);
  543. bgfx::setState(0
  544. | BGFX_STATE_WRITE_RGB
  545. | BGFX_STATE_WRITE_A
  546. | BGFX_STATE_DEPTH_TEST_ALWAYS
  547. );
  548. bgfx::setTexture(0, s_color, m_txaaColor.m_texture);
  549. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  550. bgfx::submit(view, m_copyProgram);
  551. ++view;
  552. }
  553. // Copy txaa result to swap chain
  554. {
  555. bgfx::setViewName(view, "Display");
  556. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  557. bgfx::setViewTransform(view, NULL, orthoProj);
  558. bgfx::setViewFrameBuffer(view, BGFX_INVALID_HANDLE);
  559. bgfx::setState(0
  560. | BGFX_STATE_WRITE_RGB
  561. | BGFX_STATE_WRITE_A
  562. | BGFX_STATE_DEPTH_TEST_ALWAYS
  563. );
  564. bgfx::setTexture(0, s_color, m_txaaColor.m_texture);
  565. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  566. bgfx::submit(view, m_copyProgram);
  567. ++view;
  568. }
  569. }
  570. else
  571. {
  572. // Copy color result to swap chain
  573. {
  574. bgfx::setViewName(view, "Display");
  575. bgfx::setViewClear(view
  576. , BGFX_CLEAR_NONE
  577. , 0
  578. , 1.0f
  579. , 0
  580. );
  581. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  582. bgfx::setViewTransform(view, NULL, orthoProj);
  583. bgfx::setViewFrameBuffer(view, BGFX_INVALID_HANDLE);
  584. bgfx::setState(0
  585. | BGFX_STATE_WRITE_RGB
  586. | BGFX_STATE_WRITE_A
  587. );
  588. bgfx::setTexture(0, s_color, lastTex);
  589. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  590. bgfx::submit(view, m_copyProgram);
  591. ++view;
  592. }
  593. }
  594. // copy the normal buffer for next time
  595. {
  596. bgfx::setViewName(view, "Copy Normals");
  597. bgfx::setViewRect(view, 0, 0, uint16_t(m_width), uint16_t(m_height) );
  598. bgfx::setViewTransform(view, NULL, orthoProj);
  599. bgfx::setViewFrameBuffer(view, m_previousNormal.m_buffer);
  600. bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS);
  601. bgfx::setTexture(0, s_color, m_gbufferTex[GBUFFER_RT_NORMAL]);
  602. screenSpaceQuad(float(m_width), float(m_height), m_texelHalf, caps->originBottomLeft);
  603. bgfx::submit(view, m_copyProgram);
  604. ++view;
  605. // update previous status
  606. m_havePrevious = true;
  607. }
  608. // Copy matrices for next time
  609. mat4Set(m_worldToViewPrev, m_view);
  610. mat4Set(m_viewToProjPrev, m_proj);
  611. // Draw UI
  612. imguiBeginFrame(m_mouseState.m_mx
  613. , m_mouseState.m_my
  614. , (m_mouseState.m_buttons[entry::MouseButton::Left] ? IMGUI_MBUT_LEFT : 0)
  615. | (m_mouseState.m_buttons[entry::MouseButton::Right] ? IMGUI_MBUT_RIGHT : 0)
  616. | (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
  617. , m_mouseState.m_mz
  618. , uint16_t(m_width)
  619. , uint16_t(m_height)
  620. );
  621. showExampleDialog(this);
  622. ImGui::SetNextWindowPos(
  623. ImVec2(m_width - m_width / 4.0f - 10.0f, 10.0f)
  624. , ImGuiCond_FirstUseEver
  625. );
  626. ImGui::SetNextWindowSize(
  627. ImVec2(m_width / 4.0f, m_height / 1.24f)
  628. , ImGuiCond_FirstUseEver
  629. );
  630. ImGui::Begin("Settings"
  631. , NULL
  632. , 0
  633. );
  634. ImGui::PushItemWidth(ImGui::GetWindowWidth() * 0.5f);
  635. {
  636. ImGui::TextWrapped(
  637. "In this demo, noise is added to results of deferred lighting. Then denoise is applied "
  638. "before multiplying the lit result with gbuffer albedo. Optionally, temporal antialiasing "
  639. "can be applied after that. (off by default, implementation blurry)");
  640. ImGui::Separator();
  641. ImGui::Text("noise controls:");
  642. ImGui::Combo("pattern", &m_noiseType, "none\0dither\0random\0\0");
  643. if (ImGui::IsItemHovered() )
  644. {
  645. ImGui::BeginTooltip();
  646. ImGui::Text("none");
  647. ImGui::BulletText("compare denoised results to this");
  648. ImGui::BulletText("brighter than noisy images, not losing any pixel's energy");
  649. ImGui::Text("dither");
  650. ImGui::BulletText("reject 3 out of 4 pixels in 2x2 pattern");
  651. ImGui::BulletText("could represent lower resolution signal");
  652. ImGui::Text("random");
  653. ImGui::BulletText("reject about half pixels, using common shader random");
  654. ImGui::BulletText("could represent monte carlo something or other");
  655. ImGui::EndTooltip();
  656. }
  657. ImGui::Checkbox("dynamic noise", &m_dynamicNoise);
  658. if (ImGui::IsItemHovered() )
  659. {
  660. ImGui::SetTooltip("update noise pattern each frame");
  661. }
  662. ImGui::Separator();
  663. }
  664. {
  665. ImGui::Text("temporal denoise pass controls:");
  666. ImGui::Checkbox("use temporal pass", &m_useTemporalPass);
  667. ImGui::Separator();
  668. }
  669. {
  670. ImGui::Text("spatial denoise pass controls:");
  671. ImGui::SliderInt("spatial passes", &m_denoisePasses, 0, DENOISE_MAX_PASSES);
  672. if (ImGui::IsItemHovered() )
  673. {
  674. ImGui::SetTooltip("set passes to 0 to turn off spatial denoise");
  675. }
  676. ImGui::Combo("spatial sample extent", &m_spatialSampleType, "three\0five\0\0");
  677. if (ImGui::IsItemHovered() )
  678. {
  679. ImGui::SetTooltip("select 3x3 or 5x5 filter kernel");
  680. }
  681. ImGui::SliderFloat("sigma z", &m_sigmaDepth, 0.0f, 0.1f, "%.5f");
  682. if (ImGui::IsItemHovered() )
  683. {
  684. ImGui::SetTooltip("lower sigma z, pickier blending across depth edges");
  685. }
  686. ImGui::SliderFloat("sigma n", &m_sigmaNormal, 1.0f, 256.0f);
  687. if (ImGui::IsItemHovered() )
  688. {
  689. ImGui::SetTooltip("higher sigma n, pickier blending across normal edges");
  690. }
  691. ImGui::Separator();
  692. }
  693. if (ImGui::CollapsingHeader("TXAA options") )
  694. {
  695. ImGui::Checkbox("use TXAA", &m_enableTxaa);
  696. ImGui::Checkbox("apply extra blur to current color", &m_applyMitchellFilter);
  697. if (ImGui::IsItemHovered() )
  698. {
  699. ImGui::SetTooltip("reduces flicker/crawl on thin features, maybe too much!");
  700. }
  701. ImGui::SliderFloat("feedback min", &m_feedbackMin, 0.0f, 1.0f);
  702. if (ImGui::IsItemHovered() )
  703. {
  704. ImGui::SetTooltip("minimum amount of previous frame to blend in");
  705. }
  706. ImGui::SliderFloat("feedback max", &m_feedbackMax, 0.0f, 1.0f);
  707. if (ImGui::IsItemHovered() )
  708. {
  709. ImGui::SetTooltip("maximum amount of previous frame to blend in");
  710. }
  711. ImGui::Checkbox("debug TXAA with slow frame rate", &m_useTxaaSlow);
  712. if (ImGui::IsItemHovered() )
  713. {
  714. ImGui::BeginTooltip();
  715. ImGui::Text("sleep 100ms per frame to highlight temporal artifacts");
  716. ImGui::Text("high framerate compensates for flickering, masking issues");
  717. ImGui::EndTooltip();
  718. }
  719. ImGui::Separator();
  720. }
  721. ImGui::End();
  722. imguiEndFrame();
  723. // Advance to next frame. Rendering thread will be kicked to
  724. // process submitted rendering primitives.
  725. m_currFrame = bgfx::frame();
  726. // add artificial wait to emphasize txaa behavior
  727. if (m_useTxaaSlow)
  728. {
  729. bx::sleep(100);
  730. }
  731. return true;
  732. }
  733. return false;
  734. }
  735. void drawAllModels(bgfx::ViewId _pass, bgfx::ProgramHandle _program, const Uniforms & _uniforms)
  736. {
  737. for (uint32_t ii = 0; ii < BX_COUNTOF(m_models); ++ii)
  738. {
  739. const Model& model = m_models[ii];
  740. // Set up transform matrix for each model
  741. const float scale = s_meshScale[model.mesh];
  742. float mtx[16];
  743. bx::mtxSRT(mtx
  744. , scale
  745. , scale
  746. , scale
  747. , 0.0f
  748. , 0.0f
  749. , 0.0f
  750. , model.position[0]
  751. , model.position[1]
  752. , model.position[2]
  753. );
  754. // Submit mesh to gbuffer
  755. bgfx::setTexture(0, s_albedo, m_groundTexture);
  756. bgfx::setTexture(1, s_normal, m_normalTexture);
  757. _uniforms.submit();
  758. meshSubmit(m_meshes[model.mesh], _pass, _program, mtx);
  759. }
  760. // Draw ground
  761. float mtxScale[16];
  762. const float scale = 10.0f;
  763. bx::mtxScale(mtxScale, scale, scale, scale);
  764. float mtxTranslate[16];
  765. bx::mtxTranslate(mtxTranslate
  766. , 0.0f
  767. , -10.0f
  768. , 0.0f
  769. );
  770. float mtx[16];
  771. bx::mtxMul(mtx, mtxScale, mtxTranslate);
  772. bgfx::setTexture(0, s_albedo, m_groundTexture);
  773. bgfx::setTexture(1, s_normal, m_normalTexture);
  774. _uniforms.submit();
  775. meshSubmit(m_ground, _pass, _program, mtx);
  776. }
  777. void createFramebuffers()
  778. {
  779. m_size[0] = m_width;
  780. m_size[1] = m_height;
  781. const uint64_t bilinearFlags = 0
  782. | BGFX_TEXTURE_RT
  783. | BGFX_SAMPLER_U_CLAMP
  784. | BGFX_SAMPLER_V_CLAMP
  785. ;
  786. const uint64_t pointSampleFlags = bilinearFlags
  787. | BGFX_SAMPLER_MIN_POINT
  788. | BGFX_SAMPLER_MAG_POINT
  789. | BGFX_SAMPLER_MIP_POINT
  790. ;
  791. m_gbufferTex[GBUFFER_RT_COLOR] = bgfx::createTexture2D(uint16_t(m_size[0]), uint16_t(m_size[1]), false, 1, bgfx::TextureFormat::BGRA8, pointSampleFlags);
  792. m_gbufferTex[GBUFFER_RT_NORMAL] = bgfx::createTexture2D(uint16_t(m_size[0]), uint16_t(m_size[1]), false, 1, bgfx::TextureFormat::BGRA8, pointSampleFlags);
  793. m_gbufferTex[GBUFFER_RT_VELOCITY] = bgfx::createTexture2D(uint16_t(m_size[0]), uint16_t(m_size[1]), false, 1, bgfx::TextureFormat::RG16F, pointSampleFlags);
  794. m_gbufferTex[GBUFFER_RT_DEPTH] = bgfx::createTexture2D(uint16_t(m_size[0]), uint16_t(m_size[1]), false, 1, bgfx::TextureFormat::D32F , pointSampleFlags);
  795. m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_gbufferTex), m_gbufferTex, true);
  796. bgfx::TextureFormat::Enum format = bgfx::TextureFormat::RG11B10F;
  797. if (!bgfx::isTextureValid(1, false, 1, format, bilinearFlags))
  798. {
  799. format = bgfx::TextureFormat::RGBA16F;
  800. }
  801. m_currentColor .init(m_size[0], m_size[1], format, bilinearFlags);
  802. m_previousColor .init(m_size[0], m_size[1], format, bilinearFlags);
  803. m_txaaColor .init(m_size[0], m_size[1], format, bilinearFlags);
  804. m_temporaryColor .init(m_size[0], m_size[1], format, bilinearFlags);
  805. m_previousNormal .init(m_size[0], m_size[1], format, pointSampleFlags);
  806. m_previousDenoise.init(m_size[0], m_size[1], format, bilinearFlags);
  807. }
  808. // all buffers set to destroy their textures
  809. void destroyFramebuffers()
  810. {
  811. bgfx::destroy(m_gbuffer);
  812. m_currentColor.destroy();
  813. m_previousColor.destroy();
  814. m_txaaColor.destroy();
  815. m_temporaryColor.destroy();
  816. m_previousNormal.destroy();
  817. m_previousDenoise.destroy();
  818. }
  819. void updateUniforms()
  820. {
  821. {
  822. uint32_t idx = m_currFrame % 8;
  823. const float offsets[] =
  824. {
  825. (1.0f/ 2.0f), (1.0f/3.0f),
  826. (1.0f/ 4.0f), (2.0f/3.0f),
  827. (3.0f/ 4.0f), (1.0f/9.0f),
  828. (1.0f/ 8.0f), (4.0f/9.0f),
  829. (5.0f/ 8.0f), (7.0f/9.0f),
  830. (3.0f/ 8.0f), (2.0f/9.0f),
  831. (7.0f/ 8.0f), (5.0f/9.0f),
  832. (1.0f/16.0f), (8.0f/9.0f),
  833. };
  834. // Strange constant for jitterX is because 8 values from halton2
  835. // sequence above do not average out to 0.5, 1/16 skews it to the
  836. // left. Subtracting a smaller value to center the range of jitter
  837. // around 0. Not necessary for jitterY. Not confident this makes sense...
  838. const float jitterX = 1.0f * (offsets[2*idx] - (7.125f/16.0f) );
  839. const float jitterY = 1.0f * (offsets[2*idx+1] - 0.5f);
  840. vec2Set(m_uniforms.m_cameraJitterCurr, jitterX, jitterY);
  841. vec2Set(m_uniforms.m_cameraJitterPrev, m_jitter[0], m_jitter[1]);
  842. m_jitter[0] = jitterX;
  843. m_jitter[1] = jitterY;
  844. }
  845. m_uniforms.m_feedbackMin = m_feedbackMin;
  846. m_uniforms.m_feedbackMax = m_feedbackMax;
  847. m_uniforms.m_applyMitchellFilter = m_applyMitchellFilter ? 1.0f : 0.0f;
  848. mat4Set(m_uniforms.m_worldToViewPrev, m_worldToViewPrev);
  849. mat4Set(m_uniforms.m_viewToProjPrev, m_viewToProjPrev);
  850. m_uniforms.m_frameOffsetForNoise = m_dynamicNoise
  851. ? float(m_currFrame % 8)
  852. : 0.0f
  853. ;
  854. m_uniforms.m_noiseType = float(m_noiseType);
  855. m_uniforms.m_sigmaDepth = m_sigmaDepth;
  856. m_uniforms.m_sigmaNormal = m_sigmaNormal;
  857. }
  858. uint32_t m_width;
  859. uint32_t m_height;
  860. uint32_t m_debug;
  861. uint32_t m_reset;
  862. entry::MouseState m_mouseState;
  863. // Resource handles
  864. bgfx::ProgramHandle m_gbufferProgram;
  865. bgfx::ProgramHandle m_combineProgram;
  866. bgfx::ProgramHandle m_copyProgram;
  867. bgfx::ProgramHandle m_denoiseTemporalProgram;
  868. bgfx::ProgramHandle m_denoiseSpatialProgram3x3;
  869. bgfx::ProgramHandle m_denoiseSpatialProgram5x5;
  870. bgfx::ProgramHandle m_denoiseApplyLighting;
  871. bgfx::ProgramHandle m_txaaProgram;
  872. // Shader uniforms
  873. Uniforms m_uniforms;
  874. // Uniforms to identify texture samplers
  875. bgfx::UniformHandle s_albedo;
  876. bgfx::UniformHandle s_color;
  877. bgfx::UniformHandle s_normal;
  878. bgfx::UniformHandle s_velocity;
  879. bgfx::UniformHandle s_depth;
  880. bgfx::UniformHandle s_previousColor;
  881. bgfx::UniformHandle s_previousNormal;
  882. bgfx::FrameBufferHandle m_gbuffer;
  883. bgfx::TextureHandle m_gbufferTex[GBUFFER_RENDER_TARGETS];
  884. RenderTarget m_currentColor;
  885. RenderTarget m_previousColor;
  886. RenderTarget m_txaaColor;
  887. RenderTarget m_temporaryColor; // need another buffer to ping-pong results
  888. RenderTarget m_previousNormal;
  889. RenderTarget m_previousDenoise; // color output by first spatial denoise pass, input to next frame as previous color
  890. struct Model
  891. {
  892. uint32_t mesh; // Index of mesh in m_meshes
  893. float position[3];
  894. };
  895. Model m_models[MODEL_COUNT];
  896. Mesh* m_meshes[BX_COUNTOF(s_meshPaths)];
  897. Mesh* m_ground;
  898. bgfx::TextureHandle m_groundTexture;
  899. bgfx::TextureHandle m_normalTexture;
  900. uint32_t m_currFrame;
  901. float m_texelHalf = 0.0f;
  902. float m_fovY = 60.0f;
  903. bool m_recreateFrameBuffers = false;
  904. bool m_havePrevious = false;
  905. float m_view[16];
  906. float m_proj[16];
  907. float m_proj2[16];
  908. float m_viewToProjPrev[16];
  909. float m_worldToViewPrev[16];
  910. float m_jitter[2];
  911. int32_t m_size[2];
  912. // UI parameters
  913. int32_t m_noiseType = 2;
  914. int32_t m_spatialSampleType = 1;
  915. int32_t m_denoisePasses = 5;
  916. float m_sigmaDepth = 0.05f;
  917. float m_sigmaNormal = 128.0f;
  918. float m_feedbackMin = 0.8f;
  919. float m_feedbackMax = 0.95f;
  920. bool m_dynamicNoise = true;
  921. bool m_useTemporalPass = true;
  922. bool m_enableTxaa = false;
  923. bool m_applyMitchellFilter = true;
  924. bool m_useTxaaSlow = false;
  925. };
  926. } // namespace
  927. ENTRY_IMPLEMENT_MAIN(ExampleDenoise, "43-denoise", "Denoise.");