Skip to content

[3D] Add multisample anti aliasing (MSAA) #65829

Open
ViperMiniQ wants to merge 11 commits intoqgis:masterfrom
ViperMiniQ:add-msaa
Open

[3D] Add multisample anti aliasing (MSAA) #65829
ViperMiniQ wants to merge 11 commits intoqgis:masterfrom
ViperMiniQ:add-msaa

Conversation

@ViperMiniQ
Copy link
Copy Markdown
Contributor

@ViperMiniQ ViperMiniQ commented Apr 16, 2026

This PR adds multisample anti-aliasing to 3D map.

Inspired by: https://github.com/wonder-sk/qt3d-experiments/tree/master/msaa
More here: https://learnopengl.com/Advanced-OpenGL/Anti-Aliasing

MSAA is hardcoded to 4 samples and checkbox for toggling it on or off is located in Settings under Effects in global 3D settings:
Screenshot_20260423_171522

A simple rough example (with 2 px edge):

OFF
Screenshot_20260416_090705

ON
Screenshot_20260416_090641

@github-actions github-actions Bot added GUI/UX Related to QGIS application GUI or User Experience 3D Relates to QGIS' 3D engine or rendering labels Apr 16, 2026
@github-actions github-actions Bot added this to the 4.2.0 milestone Apr 16, 2026
Comment thread src/3d/qgs3dmapsettings.h
double mEyeDomeLightingStrength = 1000.0;
int mEyeDomeLightingDistance = 1;

bool mMsaaEnabled = false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we default to enabling this? I'd love it if it was "opt out" rather then in

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in a separate PR, there will probably be many tests to correct.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 4731c83)

🍎 MacOS Qt6 builds

Download MacOS Qt6 builds of this PR for testing.
This app is not notarized, run sudo xattr -d com.apple.quarantine /Applications/QGIS*.app to avoid the warning
(Built from commit ae861ff)

Copy link
Copy Markdown
Member

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a rendering test with MSAA enabled - but generally looking good!

(Now I see one can set number of samples for the multisample textures during their creation - but we could as well leave that hardcoded to 4x for the time being - and not overwhelm users with extra options)

Comment thread src/3d/framegraph/qgsforwardrenderview.cpp Outdated
Comment thread src/3d/framegraph/qgsforwardrenderview.cpp Outdated
Comment thread src/3d/framegraph/qgsframegraph.cpp
Comment thread src/3d/framegraph/qgsframegraph.h
Comment thread src/3d/qgs3dmapsettings.cpp Outdated
@ViperMiniQ
Copy link
Copy Markdown
Contributor Author

Now I see one can set number of samples for the multisample textures during their creation

@wonder-sk, the max value is apparently limited by GL_MAX_SAMPLES value.
An option could be to dynamically populate the MSAA combobox when the widget is being constructed, but I agree to keep the value hardcoded and have a checkbox only.

If you go over the limit the GPU is able to handle, you would get a warning Qt3D.Renderer.OpenGL.Backend: FBO incomplete, but the app wouldn't crash.

Copy link
Copy Markdown
Member

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please also check whether EDL, AO and shadows still work? (i.e. depth buffer is handled correctly at all times)

Comment thread src/3d/framegraph/qgsforwardrenderview.cpp
Comment thread src/3d/framegraph/qgsframegraph.cpp
@ViperMiniQ
Copy link
Copy Markdown
Contributor Author

Please add a rendering test with MSAA enabled

I am not able to get the offscreen engine to render with MSAA on.

QgsOffscreen3DEngine::QgsOffscreen3DEngine()

I tried explicitly adding the number of samples here, but that failed as well.

Comment thread src/app/3d/qgs3dmapconfigwidget.cpp Outdated
Copy link
Copy Markdown
Member

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something, but the MSAA on/off is not connected to the global options: 1. new 3D view does not use the MSAA even if it is enabled in global options, 2. when I change the global options, this is not reflected in existing 3D views

Comment thread src/app/3d/qgs3dmapconfigwidget.cpp Outdated
Comment thread src/3d/qgs3dmapsettings.cpp Outdated
@wonder-sk
Copy link
Copy Markdown
Member

@ViperMiniQ the code looks good, now we just need to rebase after the merge of gradient PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3D Relates to QGIS' 3D engine or rendering GUI/UX Related to QGIS application GUI or User Experience

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants