mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-11-15 20:36:11 +00:00
/* * Implement SVGF style denoising as bgfx example. Goal is to explore various * options and parameters, not produce an optimized, efficient denoiser. * * Starts with deferred rendering scene with very basic lighting. Lighting is * masked out with a noise pattern to provide something to denoise. There are * two options for the noise pattern. One is a fixed 2x2 dither pattern to * stand-in for lighting at quarter resolution. The other is the common * shadertoy random pattern as a stand-in for some fancier lighting without * enough samples per pixel, like ray tracing. * * First a temporal denoising filter is applied. The temporal filter is only * using normals to reject previous samples. The SVGF paper also describes using * depth comparison to reject samples but that is not implemented here. * * Followed by some number of spatial filters. These are implemented like in the * SVGF paper. As an alternative to the 5x5 Edge-Avoiding A-Trous filter, can * select a 3x3 filter instead. The 3x3 filter takes fewer samples and covers a * smaller area, but takes less time to compute. From a loosely eyeballed * comparison, N 5x5 passes looks similar to N+1 3x3 passes. The wider spatial * filters take a fair chunk of time to compute. I wonder if it would be a good * idea to interleave the input texture before computing, after the first pass * which skips zero pixels. * * I have not implemetened the variance guided part. * * There's also an optional TXAA pass to be applied after. I am not happy with * its implementation yet, so it defaults to off here. */ /* * References: * Spatiotemporal Variance-Guided Filtering: Real-Time Reconstruction for * Path-Traced Global Illumination. by Christoph Schied and more. * - SVGF denoising algorithm * * Streaming G-Buffer Compression for Multi-Sample Anti-Aliasing. * by E. Kerzner and M. Salvi. * - details about history comparison for temporal denoising filter * * Edge-Avoiding À-Trous Wavelet Transform for Fast Global Illumination * Filtering. by Holger Dammertz and more. * - details about a-trous algorithm for spatial denoising filter */
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
$input a_position, a_normal, a_texcoord0
|
|
$output v_normal, v_texcoord0, v_texcoord1, v_texcoord2, v_texcoord3
|
|
|
|
/*
|
|
* Copyright 2021 elven cache. All rights reserved.
|
|
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
|
*/
|
|
|
|
#include "../common/common.sh"
|
|
#include "parameters.sh"
|
|
|
|
void main()
|
|
{
|
|
// Calculate vertex position
|
|
vec3 pos = a_position.xyz;
|
|
gl_Position = mul(u_modelViewProj, vec4(pos, 1.0));
|
|
|
|
// Calculate previous frame's position
|
|
mat4 worldToViewPrev = mat4(
|
|
u_worldToViewPrev0,
|
|
u_worldToViewPrev1,
|
|
u_worldToViewPrev2,
|
|
u_worldToViewPrev3
|
|
);
|
|
mat4 viewToProjPrev = mat4(
|
|
u_viewToProjPrev0,
|
|
u_viewToProjPrev1,
|
|
u_viewToProjPrev2,
|
|
u_viewToProjPrev3
|
|
);
|
|
|
|
vec3 wsPos = mul(u_model[0], vec4(pos, 1.0)).xyz;
|
|
vec3 vspPos = instMul(worldToViewPrev, vec4(wsPos, 1.0)).xyz;
|
|
vec4 pspPos = instMul(viewToProjPrev, vec4(vspPos, 1.0));
|
|
|
|
// Calculate normal, unpack
|
|
vec3 osNormal = a_normal.xyz * 2.0 - 1.0;
|
|
|
|
// Transform normal into world space
|
|
vec3 wsNormal = mul(u_model[0], vec4(osNormal, 0.0)).xyz;
|
|
|
|
v_normal.xyz = normalize(wsNormal);
|
|
v_texcoord0 = a_texcoord0;
|
|
|
|
// Store previous frame projection space position in extra texCoord attribute
|
|
v_texcoord1 = pspPos;
|
|
|
|
// Store world space view vector in extra texCoord attribute
|
|
vec3 wsCamPos = mul(u_invView, vec4(0.0, 0.0, 0.0, 1.0)).xyz;
|
|
vec3 view = normalize(wsCamPos - wsPos);
|
|
|
|
v_texcoord2 = vec4(wsPos, 1.0);
|
|
v_texcoord3 = vec4(wsCamPos, 1.0);
|
|
}
|