When performing supersampling, there is no point in going above a rendering scale factor of 2.0 because the viewport won't be displayed with mipmaps. A scale factor of 2.0 provides 4× SSAA already (2 times resolution on each axis), and it's expensive enough already :)

My game pretty much depends on solving this issue, that will make or break it as without AA it is just incredible terrible to look at.

Have you tried drawing several identical lines/polygons with lower opacity, but with slight pixel offsets? This works fairly well in my experience. I recently implemented this in another engine: https://github.com/coelckers/gzdoom/pull/1516

@Calinou said: When performing supersampling, there is no point in going above a rendering scale factor of 2.0 because the viewport won't be displayed with mipmaps. A scale factor of 2.0 provides 4× SSAA already (2 times resolution on each axis), and it's expensive enough already :)

My game pretty much depends on solving this issue, that will make or break it as without AA it is just incredible terrible to look at.

Have you tried drawing several identical lines/polygons with lower opacity, but with slight pixel offsets? This works fairly well in my experience. I recently implemented this in another engine: https://github.com/coelckers/gzdoom/pull/1516

Simply out of curiosity, does LOD work on 2D? That could also be an option that would also possibly save on performances, even if the impact is small, by only applying the supersampling effect to the specific sprites. You could use the LOD to have for example the default sprite be at lets say 64x64, then a better LOD at 128x128 (for a x2 effect.), 256x256 (for a x4 effect) and so on. This could also allow for older computers to run the game by using a crappier LOD such as 32x32 and so on.

It might take a little more work as you would need to have a high quality sprite that you'd need to scale down whilst keeping the pixels correct, but that could be a nice way to save performances to the cost of a little more disk space when exporting.

It would also allow the code and setup to remain the same with a few adjustments to include the switching of those sprites.

Otherwise, if LOD isn't in the 2D part of the engine, it could still be implemented rather easily.

Okay, I started looking into it and realized it might be helpful in my demo, so I'm going to try to get it working. I have some code that looks like it works, but I need to alter the viewport setup in Godot, as it requires two viewports. I should be able to get it working later today.

@Calinou said: Have you tried drawing several identical lines/polygons with lower opacity, but with slight pixel offsets? This works fairly well in my experience. I recently implemented this in another engine: https://github.com/coelckers/gzdoom/pull/1516

I have tried something similar, but I could never get it to work in a satisfactory way with the sharp contrasts between the colors in my game, and the fact that my polygons can move around, and if two of them touch each other no seam should be visible.

@cybereality said: Okay, I started looking into it and realized it might be helpful in my demo, so I'm going to try to get it working. I have some code that looks like it works, but I need to alter the viewport setup in Godot, as it requires two viewports. I should be able to get it working later today.

This sounds great, thank you a lot! :)

Okay, so I did get it working, however it is way too slow. Here is how it looks:

That is a 1440p render supersampled down to 720p. The quality is amazing, unfortunately it is running at 25 fps on a 720p window with a simple scene. If you go fullscreen (1440p on my monitor) it renders to 5K and that is 5 fps (but it does look great). I think the problem is reading the viewport texture on the CPU, which is costly. I'm going to keep looking into it and see if there is a way to do it fully on the GPU.

I did get it working. It was really easy, not sure if anyone figured this out yet cause all the tutorials I found were wrong. But it does work, I'm getting 3000 fps at 5K!!! (yes 3,000 at 5120x2880 resolution). I need to clean a few things up, give me an hour or two and I'll post the code.

Here is the project file. It works perfectly. It should be clear how it works, but let me know if you have questions. Also, you have to use GLES3 as the shader function requires it. If you need GLES2 I'd need to rewrite the function myself, but I think that would hurt performance.

@cybereality

Thank you a lot!!

This works fantastic, exactly how I tried to get it.

I recently switched to GLES2, as per your recommendation here: https://godotforums.org/discussion/comment/57167/#Comment_57167 since I want to support as many devices as possible, including old ones (my game is easy on the hardware anyway). So if you could make a GLES2 version, that would be great. Also I'd like to thank you in the credits of my game when I release it, without your help I'd have a major issue here. =)

Also, I think this project would be a great addition for https://github.com/godotengine/godot-demo-projects/ While I tried to find a solution for this, there were many posts of people over the years trying to do the same but no real solution. This one is simple, works great and should help a lot of people!

Okay nice! Yeah, I can make a GLES2 version tomorrow probably. The method was a little complex, but it's actually not a lot of code. I'm surprised no one figured this out already. I think the github is for official projects, but I will contact them about adding it. I also plan to submit to the AssetLib but I still need to clean up a few things before it is ready. I'm really happy it worked.

Here's the GLES2 version. I had to implement some shader functions myself but the result is pretty close (if not the same). I think that might be slightly slower than using the hardware functions, however, since GLES2 now works, the performance overall is much better (about 50% better). I also changed it so you don't have to make the world a child of the Resolution node. You can work on your game as normal and it handles everything.

Thank you again a lot! :)

I'll try it out as soon I'm home again.

@cybereality This looks pretty cool! Do you think the same approach (sampling several times in a shader) can be used in 3D?

Either way, I think this would be worth including as a separate 2D-focused demo project in the official demo repository.

@Calinou Yeah, it should work in 3D fine as it's just sampling a color image, so it doesn't really matter if it's 2D or 3D. I'm going to test it today in 3D, because I need to determine how it stacks up against MSAA and FXAA. I'm fairly certain it should be better than FXAA, but MSAA is already optimized in hardware so I'm not sure how it would compare (especially for performance). And the code is all working, but I want to test it a little more with some other projects to make sure it works in a more general case. It may take me a few more days, but I would definitely like to add this on the demo repository.

Here is the latest version with a 5K image sampled down to 1440p getting over 5,000 fps on an RX 6800 XT.

This is the latest version. I fixed a major bug, so it doesn't look quite as smooth, but is more accurate with realistic content. I think I've optimized as much as I can, but it is still pretty slow on low-end devices. I would advise against pushing it up to 200% as many older PCs and phones may not be able to handle it. I'm working on an FXAA shader and Lanczos upscaling, which also look quite good and are much faster (don't require such a high render scale). They are not finished yet, may take me a few more days. Here is an image of the latest version SSAA at 4K highest settings.

I'm finishing up on my shader. 3D works perfect now, just need to verify that 2D is still working after all the changes I've made. I should be ready to publish in the next few days. This new version should be more optimized and provide better quality, so please hang tight for a moment.

Thats great!

I need to finish another thing I'm working on right now and then I'll integrate it in my game and give it a proper test.

Thank you again! I'm sure this will help others too :)

Yeah, no problem. Thanks for giving me the idea, because this turned out way better than I expected. And it should be useful for my project and other people too.