UnityGaussianSplatting icon indicating copy to clipboard operation
UnityGaussianSplatting copied to clipboard

Performance: investigate sorting removal (hashed alpha testing or MLAB)

Open aras-p opened this issue 2 years ago • 6 comments

Instead of sorting + alpha blending, investigate whether Hashed Alpha Testing would produce "acceptable" results. Or one of order independent transparency approaches like MLAB. If any of these is decent, perhaps add them as an option.

aras-p avatar Oct 18 '23 19:10 aras-p

I made some progress here, my code is a mess now, I can PR after cleaning it a bit. Here's how it looks with 1, 4, and 8 MSAA samples respectively:

There are some other tricks to reduce noise further as shown here: https://luebke.us/publications/StochasticTransparency_I3D2010.pdf 1x MSAA2 4X MSAA2 8x MSAA2

I write to SV_Coverage the coverage mask is created as follows:

uint createStochasticMask(float alpha, float3 pos, uint idx)
{
	uint mask = 0;
	for (uint i = 0; i < 8; i++)
	{
		float3 seed = pos + (idx + 1) * (10*i + 1);
		float cutoff = saturate(hash13(seed));
		
		if (alpha > cutoff)
		{
			mask |= 1 << i;
		}
	}
	return mask;
}

I use an intermediate Render Texture with MSAA enabled then resolve it to the main one. It doesn't seem to render well according to depth, when using no order it renders points randomly, and when using the Order buffer everything is inverted (further things render first). Any ideas why? I use:

ZWrite On
ZTest LEqual
Blend One Zero
Cull Off

pablodawson avatar Jan 01 '24 15:01 pablodawson

Would blue noise improve things here? It should be as simple as sampling from a pregenerated texture.

@pablodawson Is this right repo and branch? https://github.com/pablodawson/UnityGaussianSplatting

Nothing renders for me even when I try and bypass the NRE in the console.

andybak avatar Jan 04 '24 12:01 andybak

@andybak I updated the repo, it implements both Weighted blended OIT and Blue Noise/Hashed OIT, and you can switch between them in the inspector.

For the latter, Blue Noise seems to look worse in my opinion. Weighted blended OIT seems promising as it is less "grainy" but it might require some tweaking to get it right.

Also Noise/Hashed OIT seems to work only on sorted splats which kind of defeats the purpose, but it's a decent starting point I think.

Some comparisons:

Alpha blending: 1

Blue Noise (8x MSAA): blue

Hashed (8x MSAA): hashed

Weighted: weighted

I want to try Depth Peeling next, but it might be too much overhead.

Edit: Apparently weighted blending is not good for this case since it fails on surfaces with high alpha with transparency behind it https://therealmjp.github.io/posts/weighted-blended-oit/

pablodawson avatar Jan 04 '24 18:01 pablodawson

Also - it's worth noting that the Quill player varies the blue noise per frame. It increases "crawling" but at a high refresh rate it adds some temporal smoothing (I assume due to persistence of vision)

andybak avatar Jan 04 '24 22:01 andybak

Interesting, I'll see if I can implement that. Also forgot to add alpha correction, the latest commit should look better (and not require sorting)

pablodawson avatar Jan 05 '24 02:01 pablodawson

Update: Fixed some things. The bike scene looks decent now imo and depth is correct with no sorting.

Hashed alpha 8x: bike no alpha correction

Alpha blending: alphablending

On my 3070: Alpha blending (current): 80 FPS Hashed alpha 8X: 98 FPS Hashed alpha 4X: 103 FPS Hashed alpha 2X: 198 FPS

Also @andybak do you recall using anything else to reduce noise? Looking into TAA and Bilateral/Median Filters for example

pablodawson avatar Jan 06 '24 12:01 pablodawson