-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Improved SSAO2 when samples <16. Added more control over SSAO2 denoising filter. #13621
Conversation
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
I would very much like to run this commit with the demo bellow to evaluate the results, is that possible? |
Related issue: #12630 SSAO2 however needs a big overhaul and modernization. It really should look better than it does and there are improvements to be made in the SSAO step as well as using more advanced denoising filters, perhaps a "guided filter" or something even more recent. The current bilateral filter also needs fixing. It doesn't take normals into account and thus can be fooled quite easily by some geometry in the depth buffer. That however is out of scope for this PR since it would break the "not slower" performance criteria. The SSAO2 shader as a whole probably also needs overhauling. It looks much more "hacky" and primitive than for example the blur postprocessing shaders. There are also synergies that can come from extracting common things there, like the gaussian filter code and optimizations. |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://babylonsnapshots.z22.web.core.windows.net/refs/pull/13621/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/13621/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/13621/merge#BCU1XR#0 |
Thanks for the PR, I will have a look tomorrow!
You can browse this PG locally: http://localhost:1338/#T3K2SA#1 |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
First, a noob question, is the left or the right side the stored reference? Secondly, could someone help me to figure out why "Light Projection Texture" test completely changed to/from a black screen? I don't see how it is connected to SSAO2. |
There is also a failing unit test that I don't understand how it is affected by my changes:
|
Don't worry with the first visualization test that fails, it's not related to your PR but a long standing problem we have with this test... Regarding the 2nd one, have you merged your PR with the latest changes from master? It could explain why it is failing it you didn't do it. |
OK, got it. 👍
I think I did, but both those tests looks like they are using SSAO, so some change would be expected. Where can I find the source of those tests so I can see how they are setup? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
I also noticed that we are generating mipmaps for the SSAO effect and blur textures, which doesn't make sense! You should change the two occurrences of TRILINEAR_SAMPLINGMODE
in _createBlurPostProcess
to BILINEAR_SAMPLINGMODE
to fix this.
It is on the right.
I didn't see there were other visualization tests failing, I thought you were speaking of the unit test! You can find the PG ids corresponding to the visualization tests in When you look at this PG and hit the "3" key, we can see there's clearly a problem (comparison with existing SSAO2: https://playground.babylonjs.com/#N96NXC#119), the blur is not applied everywhere it should. I don't know if using gaussian instead of box explains everything(?) Let's try to see what's going on before looking at the visualization test. |
How about the one in _randomTexture, should that stay? |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
1 similar comment
Visualization tests for webgl2 have failed. If some tests failed because the snapshots do not match, the report can be found at If tests were successful afterwards, this report might not be available anymore. |
You can also change it for this one, but this is not as much of a problem as the others, because no mipmap is created for this texture, so TRILINEAR will be treated as BILINEAR internally. But in the other cases, defining a TRILINEAR filter will force the system to generate mipmaps for the post-processes! |
I'm a bit uneasy with your latest changes, where you test 0.1 / 0.05 to make it look better in your example test, but it could be worse in other tests... I think this value should be a parameter, that way people would be able to change it as they see fit. Also, we probably need a parameter to enable the new code because I fear the changes could adversely impact people who are using the existing SSAO2 and may have tweaked the parameters for their use case. |
That is true. I tweaked it to look as crisp as possible in the different test cases I tried, without reducing the actual denoising in any of them. But still, those four tests is only a sample of every possible way. The result is a bit less "crisp" edges since the sample rejection test was very strict before, that is what the tweak was about. The biggest upside is the reduction of the pretty glaring ghosting you get from the old box-filter. You can see it in the cat's mouth and nose for example, or the sharp edges in the terrain boxes which got duplicated with the previous filter. The real fix would be to implement normal-based sample rejection as well, but given the hard requirement of "never slower" that wasn't really feasible here.
I'm a bit unsure how to add that without getting even more settings on the SSAO2 postprocess. Because after you add it you can't really remove it again? Ideally, I wanted to have some sort of enum-based setting to switch between different filter types, that way one could easily add more filters in the future in a safe way, even though I guess it would default to the old not-very-good filter. @Popov72 , I would really appreciate your help to get a "denoising algorithm" (enum) setting into place in a way that follows best practices and is backward compatible. The old "expensiveBlur" would map to "Bilateral Box" (true, default) and "Gaussian" (false) with such an enum. |
Actually, I have another suggestion @Popov72 . What if I back out all the potential breaking changes regarding the "expensiveBlur" and remove the new stuff, basically keeping this as a bug-fix / cleanup task to prepare for a larger rewrite later? Then I take the code changes I started with here and continue on them to create new filter(s), including any new options to tweak, and work on them until we are certain that they are well tested. |
I agree, this PR is becoming a bit heavy for something we plan to replace in the short/mid term.
Actually, we planned to do as for SSR: write a new separate implementation and deprecate the old one. There is probably a newer SSAO algorithm we could use, and we won't bother to make the old and the new one work side by side in the same implementation. Having a separate implementation for the new algorithm is easier to manage. |
All done @Popov72 , please take a new look when you have a chance. Since you said you were going to start over with "SSAO3" and not reuse this class I went in this direction:
Tweaking the new settings works fairly well and can get an almost perfect cat for example. And at the same time, with the default settings there should be no changes in the output at all. Fingers crossed. |
Looking at the code again this morning with fresh eyes, I noticed that there were several uniforms being declared and bound to the blur filter that has never been used in the blur shader, so I removed those. Along with one for the SSAO shader. Also, how come |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
packages/dev/core/src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts
Outdated
Show resolved
Hide resolved
packages/dev/core/src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts
Outdated
Show resolved
Hide resolved
I agree with all your comments! Regarding:
Yes, please add serialization to this property, as well as to Thanks! |
Some code review fixes has been commited, but there is still some work left. I got sidetracked trying to figure out why the SSAO2 algorithm performes so badly for samples <16, and think I figured it out. The fix is in PR #13652 |
Regarding this one:
@serialize()
private _textureType: number;
...
constructor(...) {
...
this._textureType = textureType;
}
public static Parse(source: any, scene: Scene, rootUrl: string): SSAO2RenderingPipeline {
return SerializationHelper.Parse(() => new SSAO2RenderingPipeline(source._name, scene, source._ratio, undefined, source._forceGeometryBuffer, source._textureType) , source, scene, rootUrl);
} I think it should do it! |
@sebavan Because Popov72 told me to. =)
It was my understanding that we did disabled the MIP-map generation as well by changing from TRILINEAR to BILINEAR in the PR. |
Makes much more sense completely missed this in the comment !!! thanks. All good to me. |
This is a great first contribution, grats! |
Related to this thread in the forums:
https://forum.babylonjs.com/t/ssao2-blur-shader-issues/38924/25
SSAO calculation fix
Fixes an error in SSAO2 calculations that caused massive amounts of incorrect occlusions on flat surfaces when samples were <16. This change is automatically applied with the new
epsilon
parameter defaulting to 0.02, demonstrated below with samples = 8 (fixed on the right). Setting the new parameter to 0.0 will revert back to the old behavior.See #13652 for discussions and more screenshots.
Terrain (#N96NXC#127)
Cat (#T3K2SA#1)
Room (#LCUPCU#14)
Denoising / Blur filter is more configurable
The "expensiveBlur" filter has been improved with new features and their associated parameters.
This change was done with care so that the new code keeps all the quirks and bugs in the current code, while adding options to mitigate them on a per scene/project basis. This was none of the existing deployments are affected since they might have already tried to compensate for them in other ways.
Summary of changes
This is the first time I contribute to Babylon.js, so please let me know if I need to do or change something.