wave-harmonic / crest

A class-leading water system implemented in Unity
MIT License
3.41k stars 475 forks source link

MSAA causes outline on objects in front of ocean #800

Closed metromeo closed 2 years ago

metromeo commented 3 years ago

Describe the bug msaa not works correctly in hdrp

Screenshots / video https://gfycat.com/damagedpinkladybug

Versions HDRP v. 10.3 10.4 Crest 4.8 4.9, Unity 2020.2.7 2020.3.3

To Reproduce Place any mesh with opaque material above water with another mesh with opaque material in background underwater

Platform

Hardware GForce GTX 1070, radeon 570

daleeidd commented 3 years ago

Thanks. I wasn't able to reproduce. Can I also grab a screenshot of the material for the object in the front? Also, which shader are you using for the Terrain? Are you able to reproduce in the main scene?

metromeo commented 3 years ago

Terrain material is simple hdrp/terrainlit I reproduced this in main scene, just added black plane (which also on the first gif, under water with terrain) for difference with white terrain also i uploaded part of the mesh, that have many edges - https://dropmefiles.com/5TMaZ

1 2 3 4

daleeidd commented 3 years ago

Thanks. I was able to reproduce. Not sure if I can solve this yet. If you look at the mesh up close you will see a fine outline when MSAA is enabled. And when you zoom out, like you have, it becomes more and more prominent. This is most likely caused by using something that has MSAA applied with something that doesn't have MSAA applied in our shader. It will need further investigation.

daleeidd commented 3 years ago

When we sample the depth buffer, choosing the maximum value around -and including- the sample point greatly reduces the issue. It still doesn't look great though and that is five samples (maybe more if using refraction).

I think having access to the MSAA depth might help with this. Although initial attempt was unsuccessful. Disappointing that this sort of thing is still an issue for developers to wrangle.

huwb commented 3 years ago

Thanks for the notes. Does it work in a standard SG? I'm assuming not but just checking. Seems like something unity should have a solution for.

Maybe others have complained about this online in the context of standard SGs.

huwb commented 3 years ago

A forum post. I think the reply is right that its always going to be a bit broken. He does propose something to address it although I didn't 100% follow, but maybe you could try it?

https://forum.unity.com/threads/anti-aliasing-and-shader-graph.1057298/

huwb commented 3 years ago

In another thread he seems to propose taking multiple samples as you did, from a quick glance at least

https://forum.unity.com/threads/fixing-screen-space-directional-shadows-and-anti-aliasing.379902/

And unity bouncing the issue, claiming it's fixed in URP/hdrp. I'm guessing it's fixed because it uses a different technique but linking here in case it's worth digging into:

https://issuetracker.unity3d.com/issues/when-using-anti-aliasing-in-the-unity-quality-settings-there-is-1px-white-border-between-object-and-its-shadow?_ga=2.212569106.744559521.1618035339-364151866.1568579459

daleeidd commented 3 years ago

Thanks for the notes. Does it work in a standard SG? I'm assuming not but just checking. Seems like something unity should have a solution for.

I did try a standard shader and sampling the colour texture and the issue is not as prominent. I didn't test using depth too (which appears to be the the problem) as I moved on to isolating on the ocean shader.

A forum post. I think the reply is right that its always going to be a bit broken. He does propose something to address it although I didn't 100% follow, but maybe you could try it?

Good find! Seems much simpler than the other one. Will give this a go.

In another thread he seems to propose taking multiple samples as you did, from a quick glance at least

I am using that currently (it's the simpler example provided by a commenter). It mostly works but is probably more costly than it needs to be.

And unity bouncing the issue, claiming it's fixed in URP/hdrp. I'm guessing it's fixed because it uses a different technique but linking here in case it's worth digging into

It might be. I'll have a look. They do have MSAA depth textures and sampling methods defined which might be what they are using. They just weren't bound for the transparent pass. Hopefully the simple fix works well enough.

Also, the HDRP MSAA documentation lists some interesting caveats with using MSAA.

huwb commented 3 years ago

Wow yeah according to that they force-disable a bunch of their techniques, and one that they leave enabled has the outline issue!

metromeo commented 3 years ago

Hellol, any news about fix?

daleeidd commented 3 years ago

@metromeo The issue is caused by two places in the SG. I had some success with one of the approaches at one place in the SG but struggled to replicate success elsewhere. I put this on hold for a little while. But I will evaluate it again sometime soon.

qamelior commented 2 years ago

Is there any potential workaround for this? We're getting really close to release with our game and having no MSAA creates lots of other visual problems for us. Maybe there is some terrain shader fix or something crest-related which would at least reduce the impact of these artifacts? We would be able to live with some level of picture degradation.

qamelior commented 2 years ago

Is there any potential workaround for this? We're getting really close to release with our game and having no MSAA creates lots of other visual problems for us. Maybe there is some terrain shader fix or something crest-related which would at least reduce the impact of these artifacts? We would be able to live with some level of picture degradation.

@daleeidd can I get a follow up, please. We need to make a decision next week.

daleeidd commented 2 years ago

Is there any potential workaround for this? We're getting really close to release with our game and having no MSAA creates lots of other visual problems for us. Maybe there is some terrain shader fix or something crest-related which would at least reduce the impact of these artifacts? We would be able to live with some level of picture degradation.

It's an issue with our shader. And there is no workaround I can think of from your end. I have a working solution but it is halfway complete as integrating it has some considerations. We will release a new version most likely this week or next at the latest and I will let you know if it makes it.

qamelior commented 2 years ago

@daleeidd just to be clear - we are currently using Unity 2019 version (some other assets we use require it). Will the fix be working on 2019 as well?

daleeidd commented 2 years ago

@daleeidd just to be clear - we are currently using Unity 2019 version (some other assets we use require it). Will the fix be working on 2019 as well?

It won't. We cannot afford to support 2019 unfortunately.

daleeidd commented 2 years ago

A workaround was added in 4.13 which darkens the outline which in most cases is not noticeable. A proper solution is to sample the MSAA depth texture that Unity provides, but that proved to be difficult as it is hard to access. Maybe for the future.