Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aras-p opened this issue Oct 18, 2023 · 6 comments
Open
Labels
enhancement New feature or request

Comments

@aras-p
Copy link
Owner

aras-p commented Oct 18, 2023

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 aras-p changed the title Performance: investigate hashed alpha testing (might remove need for sorting) Performance: investigate sorting removal (hashed alpha testing or MLAB) Oct 18, 2023
@aras-p aras-p added the enhancement New feature or request label Oct 18, 2023
aras-p added a commit that referenced this issue Oct 21, 2023
@pablodawson
Copy link

pablodawson commented Jan 1, 2024

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

@andybak
Copy link

andybak commented Jan 4, 2024

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.

@pablodawson
Copy link

pablodawson commented Jan 4, 2024

@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/

@andybak
Copy link

andybak commented Jan 4, 2024

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)

@pablodawson
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants