[ES1 renderer update] multi sampling support (full screen anti-aliasing)

Forums Programming cocos2d support (graphics engine) [ES1 renderer update] multi sampling support (full screen anti-aliasing)

This topic contains 21 replies, has 9 voices, and was last updated by  Mark Sawicki 3 years, 3 months ago.

Viewing 22 posts - 1 through 22 (of 22 total)
Author Posts
Author Posts
June 30, 2010 at 11:16 pm #222868

araker
Moderator
@araker

I’ve just uploaded my changes to the renderer to enable multi sampling (link). I’ve did some very limited testing on a 3GS, so consider this alpha stage at best. Code is based on 0.9.9.4 RC2.

It would help me out if some of you could test this code and see if you get any artifacts and how the performance is holding up on your device.

This only works on OS4

To use it,

  • If you initialized the EAGLView manually change the following line:
    EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
    pixelFormat:kEAGLColorFormatRGBA8 // RGBA8 color buffer
    depthFormat:GL_DEPTH_COMPONENT16_OES // 16-bit depth buffer
    preserveBackbuffer:NO
    multiSampling:YES
    numberOfSamples:4];

    depth buffer is optional

  • If you use the CC_DIRECTOR_INIT macro, look it up in ccmacro.h,add the multiSampling and numberOfSamples argument also

    change the pixelFormat to kEAGLColorFormatRGBA8.

  • If you use Interface builder to create your view, you’re out of luck.

EDIT: In the director uncomment line 210 to set a projection.

For current limitations click on the link above.

June 30, 2010 at 11:18 pm #288904

robodude666
@robodude666

How badly does this kill performance on your 3GS?

Looks great though!

EDIT: Ouch! Drop of 10-20 FPS? That sounds painful.

June 30, 2010 at 11:21 pm #288905

araker
Moderator
@araker

The only test I’ve done so far with my 3GS let the frame rate drop from a solid 60 to a very fluctuating one between 40 and 50 (with 4 samples). With 2x it’s around 45- 50.

EDIT Yeah, it’s quite a drop, so the usefulness of this will be limited. For games that require only 30 FPS it could still be an option though (if 3G performance isn’t a lot worse).

June 30, 2010 at 11:30 pm #288906

robodude666
@robodude666

Not too bad. I’m testing it out in the simulator, and all I get is a black screen.

June 30, 2010 at 11:33 pm #288907

araker
Moderator
@araker

Do you see any openGL error in your console (only shows in debug)?

June 30, 2010 at 11:41 pm #288908

robodude666
@robodude666

Just the good ol’

OpenGL error 0x0506 in -[EAGLView swapBuffers]

If I disable MSAA in the EAGLView then I don’t get this error, but the screen is still black.

June 30, 2010 at 11:56 pm #288909

araker
Moderator
@araker

I’ve tried it out with a empty project, a few things that can be wrong ..

if you use the macro, then the pixelformat has to change to kEAGLColorFormatRGBA8

In the director, uncomment line 210 to set the default projection.

July 1, 2010 at 12:39 am #288910

Kenny Ackerson
Participant
@pearapps

So it doesn’t work on 3.2? That sucks…

July 1, 2010 at 1:53 am #288911

araker
Moderator
@araker

No this won’t work on the iPad until iOS4 is out.

July 1, 2010 at 1:58 am #288912

Kenny Ackerson
Participant
@pearapps

Gah – You know how much I NEED this right now??!!

July 1, 2010 at 2:47 am #288913

robodude666
@robodude666

Question:

Because this MSAA filter is applied to the entire screen, does it care about screen activity? It would apply just as fast for a simple “Hello World” string on screen as it would for a single bouncing ball or a few hundred sprites and dozens of particle effects?

July 1, 2010 at 5:38 pm #288914

araker
Moderator
@araker

It shouldn’t matter performance wise, since it operates on pixels not on geometry (link). Note though that the simulator and 3G and lower actually perform supersampling instead of multisampling, which is less efficient.

@riq, do you think this is a useful feature for cocos2d? For me this was a small experiment to see what the performance impact would be, which is hefty. If there is no interest to include this into cocos I’ll leave it this way, else I could test it some more to make sure it doesn’t break anything.

July 1, 2010 at 5:49 pm #288915

riq
Keymaster
@admin

@araker: It might be useful but I haven’t played with multisampling yet (and I don’t have an iPhone4 yet). If you think it is useful, please, continue improving it, and keep posting your findings here. Thanks!

October 6, 2010 at 8:15 pm #288916

araker
Moderator
@araker

Due to a request I’ve updated this code, it now works with 0.99.5 beta 3 (code can be found using link in first post).

I still haven’t tested it thoroughly so the current limitations still stand.

@riq, MSAA is for all devices that can run 4.0.

EDIT I made a error by not discarding the right attachments, now there is almost no performance penalty anymore on the 3GS. So disregard my older posts regarding performance.

October 7, 2010 at 12:29 am #288917

araker
Moderator
@araker

Now that the performance is acceptable on my 3GS, I’ve did some testing and the code works fine. The tests I run were

- EAGLViewTest, no problems with a non standard size EAGLView

- AttachDemo, no problems with removing/allocating EAGLView

- RenderTextureTest with different sizes

- Particle performance test on 3GS (release, GCC 4.2), 3000 particles

with fsaa 4x

A1 60 B1 40 C1 6 D1 2

without fsaa

A1 60 B1 60 C1 16 D1 5

What needs to be done?

- a few more tests to make it foolproof.

- testing on 3G/ipod touch 2G, I don’t have such a device yet.

- changing every EAGLView initializer in the tests, I’m working on forking cocos on github for this.

October 12, 2010 at 5:06 pm #288918

djdrzzy
Participant
@djdrzzy

Checked it out and it works beautifully! Thanks araker!

October 14, 2010 at 6:33 pm #288919

riq
Keymaster
@admin

@araker: Thanks. I’ve just merged it into the develop branch. I merged it from the @djdrzzy branch.

October 15, 2010 at 7:18 pm #288920

asinesio
Participant
@asinesio

Wow, this is a really neat feature. I’ll have to give it a try on my project!

October 15, 2010 at 7:37 pm #288921

cjl
Participant
@cjl

Sorry for my remarkable lack of OpenGl knowledge, but what does this do?

I thought multi sampling was used for ’3D’, and would be of limited use for ’2D’?

October 15, 2010 at 9:08 pm #288922

riq
Keymaster
@admin

How to use it.

. Download “develop” branch

. Edit SpriteTest.m and use this code:

// Create an EAGLView with a RGB8 color buffer, and a depth buffer of 24-bits
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:GL_DEPTH_COMPONENT24_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:YES
numberOfSamples:4];

Suggestion:

- Don’t use on 1st and 2nd generation devices. Only enable on 3rd gen or newer devices, since they support multisampling on hardware.

It works also on 2D games, but it is not as useful as it is on 3D games.

Sorry for my remarkable lack of OpenGl knowledge, but what does this do?

It does Anti-Aliasing in all your scene. I think it is also called FSAA: Full Screen Anti Aliasing. The other name is MSAA: Multi-Sampling Anti Aliasing.

Tests:

- I’ll try to code a test that shows the benefits of MSAA. If you already have a tests, feel free to share it! thanks.

January 6, 2011 at 5:31 am #288923

MisterX
Participant
@misterx

What is the “develop” branch? What does that mean?

January 6, 2011 at 5:47 am #288924

Mark Sawicki
Participant
@effervescent

@MisterX,

the develop branch of cocos2d from GitHub: https://github.com/cocos2d/cocos2d-iphone/tree/develop

Basically follow the first part of the instructions for submitting a patch on the FAQ page.

Submit a patch by using git

HTH,

- Mark

Viewing 22 posts - 1 through 22 (of 22 total)

You must be logged in to reply to this topic.