Multisampling, sRGB and intermediate buffers


#1

In my application I’m using multisampling and sRGB conversion and until now everything worked great. But now I need to render the scene to an intermediate buffer in order to do some postprocessing, and I discovered the hard-way that multisampling does not like at all sRGB conversion.

If activate multisampling in the intermediate buffer (where the scene is rendered) and no more on the main framebuffer, the sRGB correction goes wrong and banding appears. This happens either if I activate sRGB on both the buffer and main framebuffer or if I manually do the correction in the postprocessing fragment shader.

I tried using floating point color to avoid any loss of precision, but no change.

So, can this actually work, and, if so, what is the right configuration ? or is it a bug in my driver or panda ? This is driving me nuts :slight_smile:

Without MSAA :

With MSAA:

Test code : test_srgb.zip (6.5 KB)

There are many configuration variables in the test_srgb.py but to simply change MSAA, just set multisamples_buffer to 0 or (for example) 2. The script use a modified version of the FilterManager class to modify the intermediate buffer fb properties.


#2

I found the cause of the issue and produced a fix. We were completely neglecting to handle the sRGB case for the multisample framebuffer.

Should I get the buildbot to produce a snapshot build? If so, which platform?


#3

Thanks for the quick reply :slight_smile: I already have started a local build so no need for a special snapshot build.


#4

OK, great. Just note that this change is not on the master branch yet, but still on the release/1.10.x branch.

Let me know whether the fix works for you and produces the expected results.


#5

Indeed I forgot to change the branch before starting the build :frowning:


#6

Sadly the issue is still there. What is strange is that the sRGB conversion is done, without it the sprite is only a small gray dot, the halo is only visible if you apply the gamma correction. The banding are coming from a precision loss, maybe because there is an additional linear -> sRGB -> linear conversion ?

What I also don’t understand is if I disable hardware sRGB conversion and do the gamma correction manually in the final shader the problem still appears, even when using floating point colors to avoid the precision loss.

(Note, I uploaded an older version of the test script, here is the one with correct floating point color : test_srgb2.zip (12.1 KB) )

After googling a bit more about the subject, it could be that downsampling a floating point buffer must be done manually in a shader.


#7

Ok, after some more exhaustive tests and more code modification I could get it working for both cases : srgb explicit buffer and manual conversion using floating point color.

There were two problems :

The first one is that I was not careful and so I was still installing panda3d1.10_1.10.0_amd64.deb instead of panda3d1.10_1.10.1_amd64.deb :stuck_out_tongue:

The second one is that in your fix you only test for srgb fb properties, not for floating point, I added

    if (_fb_properties.get_float_color()) {
      gl_format = GL_RGBA32F;
    } else

Before it.

So, when adding the above code there are no more banding in the floating point color case too.


#8

Thanks. I’ve checked this in and both fixes are in both the release/1.10.x and master branches.


#9

And it works fine on Linux. I just have transparent textures which are slightly too bright when using the floating point buffer but I guess that’s another problem

On Mac it works for RGBA8 buffers, but for floating point buffer I get an invalid operation at line 1890 in glGraphicsBuffer_src.cxx Maybe it’s a non supported combination, but then the buffer should not be created.


#10

Found why the textures were too bright… If I had taken the time to read the actual specification instead of what everyone repeat about sRGB and gamma correction, I would have knew that it’s slightly more complex than just pow(color, 1/2.2) :slight_smile:


#11

On Mac it’s because I’m still using a previous build : it seems that since a few days the buildbot is no longer building for the mac platform. (Also, on the official download page there are no more link towards the devel builds and installer btw)


#12

With a home made build, everything works fine on Mac too : hardware srgb conversion on main fb and intermediate fb, with and without multisampling.


#13

Great, thanks a lot! I’ve been doing a bit of maintenance on the macOS buildbot, which is why it has been behind—I’ll make sure that builds are available shortly.