MSAA in CesiumJS!

Hi all,

We’ve been working on adding an option for MSAA in CesiumJS with WebGL2 contexts - there’s a pull request open and we’d be happy to hear feedback from anyone interested in trying it out :slight_smile:

The instructions are in the main pull request post, but the gist is to request a WebGL2 context in the Viewer constructor:

var viewer = new Cesium.Viewer("cesiumContainer", {
  contextOptions: {
    requestWebgl2: true,
  msaaSamples: 4

Once a WebGL2 context is available the multisampling rate can be controlled with Scene.msaaSamples, which defaults to 1 (MSAA off).

This change is exciting to us because it’ll add another option for dealing with aliasing artifacts that are hard to fix with post-process anti-aliasing like FXAA. In particular, 3D geometry with small details or thin polylines and other edges should look a lot better with MSAA turned on. There are some limitations - MSAA does not affect effects that are applied in post-processing (i.e. outlines) - in these cases MSAA can be used with FXAA if needed. We are aware of a couple other issues that are listed in the pull request description. If you’re interested, please let us know if you notice any other bugs or have other comments about the changes, thanks!


Hi! This is great, we have waited this feature for many years! :slight_smile:

I tested the latest commit from this branch: manager-msaa (

:exclamation: I experience a bad performance bug still: on a machine with Nvidia RTX 3090 GPU even the empty sandcastle fullscreen runs about 25 fps. With scene.msaaSamples=1 fps is way above 60fps all the time. From my understanding this cannot be just normal performance penalty of MSAA, it has to be some error somewhere…

1 Like

@v12424124_34 Thanks for testing it out and posting those details. I was able to reproduce the low frames on another 30 series machine, but not on other computers. We’re still looking into this and I’ll post updates here if we resolve it.

1 Like

Oh, that is quite interesting… Thanks for the update! Heh, “ironic” that the most efficient GPU in the market fails on this :wink:

I did some more tests on 3090 (on Windows 10):

  • I updated to the newest Studio drivers fist to make sure its not outdated driver issue
  • I tried with Chrome and Firefox => Both behave the same, MSAA is about 30fps only
  • I tried this Threejs demo on Chrome:three.js WebGL 2 - Multisampled Renderbuffers => It runs smoothly, I did not notice any FPS drop on that demo.

@Eli Hi! This change fixes the framerate on 3090. So it seems that blitting the stencil is the cause?

MultisampleFramebuffer.prototype.blitFramebuffers = function (context) {
  const gl = context._gl;
  let mask = 0;
  if (this._colorFramebuffer._colorTextures.length > 0) {
    mask |= gl.COLOR_BUFFER_BIT;
  if (defined(this._colorFramebuffer.depthStencilTexture)) {
    mask |= gl.DEPTH_BUFFER_BIT;

@v12424124_34 Interesting. We believe it’s an issue on Windows rather than the NVIDIA cards because we’ve been able to reproduce the frame drops on machines that dual boot Linux and Windows only on the latter. I’ve posted in the WebGL mailing list to see if anyone’s run into this before. Unfortunately with the CesiumJS engine it’s not easy to decouple the framebuffers’ depth-stencil and color attachments so I don’t know if there’s a quick fix for this.

I tried the blit without the stencil mask bit and it worked very well for me… I am now wondering what are the implications of leaving the stencil out? Does it affect only the classification etc. advanced stuff but not really the globe rendering?

New test: NVIDIA GeForce GTX 1080: Same bug occurs there, with 4x msaa framerate drops to 20fps and disabling depth blit mask helps.

Yeah, this looks like an issue with the stencil blitting on Windows. I posted a small example to isolate the bug here -

The depth-stencil textures are important in a few places in CesiumJS, like classification and OIT to name a couple.

Thanks! Good to understand… I think in our use case we might event disable the stencil blit for now…

Performance problem is fixed on the main version now! :slight_smile: Many thanks for the MSAA improvement!

@v12424124_34 You were quick to test the changes :grin: Glad the performance is better now!

1 Like


Great update! :slight_smile:

1 Like

Is there any way of using MSAA in the postprocess shaders?

There isn’t, but MSAA can be combined with FXAA for anti-aliasing on post-process effects.

Hi @Eli!

On iOS 15.4 the MSAA got broken. It worked fine before the iOS update, but now it seems that depth buffer does not get cleared or something. Video in the zip: (949.1 KB)

@v12424124_34 Ah bummer… Would you be able to open an issue on the CesiumJS repo with steps to reproduce? Attaching the file would be helpful, as well as a screenshot of WebGL Report results on your device. Thanks!

iOS 15.5 fixes this. :+1:

1 Like