Multisampling antialiasing (MSAA) in cocos2dx-v4

Hello, we’ve successfully ported our mixed 2d-3d game’s prototype with disabled MSAA to cocos-V4 with only 5% performance drop.

Now I’m trying to enable antialiasing back.

As far as I understood MSAA is currently unimplemented in v4.

// from
- (id) initWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained sharegroup:(EAGLSharegroup*)sharegroup multiSampling:(BOOL)sampling numberOfSamples:(unsigned int)nSamples
{ ..
// numberOfSamples and nSamples are unused here

If I’m not right could you please advise me on how to enable MSAA in cocos2dx-v4.

Or if it’s unimplemented, do you planning to implement it and when?

@zhangxm @coulsonwang can you help with this?

1 Like

Sorry about for MSAA missing in v4, I will take a look when I am finished works at hand.

Thanks for Your reply. I’ll continue to investigate possible ways of implementing MSAA my self.

If you fix the MSAA issue, it will be appreciated to post a PR to v4 branch, and we will review it.

After a month and a half passed I finally made a pull request with my MSAA solutions.

My first goal was to implement OpenGL-like multisampling over metal. And now it works fine for most cases.

But not in my game. Where I found that Renderer has to create the new MTL-encoder on each 2d/3d sprite change during scene draw.

It takes a lot of time to create encoder with multisample attachments. To achieve acceptable rendering speed I made a unified MTL-encoder for drawing to texture with MSAA and depth enabled.

You may check the performance advantage of this encoder by running the new test “RenderTextureWithMsaaSprite3D”.

I understand that this solution is pretty dirty and situational to be merged to cocos-2d master. But its a good start point for future development. Here is the capture of this test running on a 6 scale.

The speedup was 12 to 60 fps on my iPhone 10.

Hello @zhangxm @coulsonwang. Sorry for auto-tests failed by my previous commit. I’m not a very experienced GitHub user and didn’t notice the test’s status.