Skip to content

Conversation

@VReaperV
Copy link
Contributor

@VReaperV VReaperV commented Dec 27, 2024

Implements #532.

Add r_msaa. When set to > 0, an MSAA FBO will be created with that many samples. This FBO will be used for rendering, other than when it requires sampling from current render/depth image. When such rendering is required the MSAA FBO will be blit into the main FBO and vice versa, to resolve the MSAA texture.

plat23:
No MSAA:
unvanquished_2024-12-27_181225_000
MSAA 4x:
unvanquished_2024-12-27_181202_000

thunder:
No MSAA:
unvanquished_2024-12-27_181409_000
MSAA 4x:
unvanquished_2024-12-27_181430_000
MSAA 16x:
unvanquished_2024-12-27_181539_000
MSAA 32x:
unvanquished_2024-12-27_181602_000

@VReaperV VReaperV added A-Renderer T-Feature-Request Proposed new feature labels Dec 27, 2024
@illwieckz
Copy link
Member

Nice! Finally some antialiasing!

It looks like when MSAA is enabled the heathaze from back surface is applied on front surfaces too:
https://imgsli.com/MzMyODgx

@illwieckz
Copy link
Member

My previous comment was about screenshots from the original post.

When I try the branch and enable MSAA I get a black screen (AMD Radeon with Mesa radeonsi driver).

@VReaperV
Copy link
Contributor Author

When I try the branch and enable MSAA I get a black screen (AMD Radeon with Mesa radeonsi driver).

That's interesting. Can you try with effects that use the main render target disabled, like heatHaze, bloom etc (or just use the lowest profile to make sure)? Also, does it work in the main menu?

@slipher
Copy link
Member

slipher commented Jan 5, 2025

I get a completely black screen (other than 2D drawing) with r_msaa 4 or 16 on Spacetracks. Plat23, on the other hand, renders. I tested with Nvidia on Windows; default cvars except with reliefmapping enabled.

@slipher
Copy link
Member

slipher commented Jan 11, 2025

Actually it's just black from whenever the 2nd map is loaded. Must be some cleanup bug

@illwieckz
Copy link
Member

Can this be rebased on current master? 🙂️

@VReaperV
Copy link
Contributor Author

Can this be rebased on current master? 🙂️

Done... but I haven't tested it after rebase, so I don't know if it still works lol.

@illwieckz
Copy link
Member

It looks like the rebase went wrong! 😅️

/home/vsts/work/1/s/src/engine/renderer/tr_backend.cpp:3105:1: error: expected expression
<<<<<<< HEAD
^

@VReaperV VReaperV force-pushed the msaa branch 2 times, most recently from 27484ca to a80b19e Compare August 31, 2025 10:50
@VReaperV
Copy link
Contributor Author

VReaperV commented Aug 31, 2025

I get a completely black screen (other than 2D drawing) with r_msaa 4 or 16 on Spacetracks. Plat23, on the other hand, renders. I tested with Nvidia on Windows; default cvars except with reliefmapping enabled.

Actually it's just black from whenever the 2nd map is loaded. Must be some cleanup bug

It looks like the rebase went wrong! 😅️

/home/vsts/work/1/s/src/engine/renderer/tr_backend.cpp:3105:1: error: expected expression
<<<<<<< HEAD
^

All fixed.

@VReaperV
Copy link
Contributor Author

VReaperV commented Aug 31, 2025

Nice! Finally some antialiasing!

It looks like when MSAA is enabled the heathaze from back surface is applied on front surfaces too: https://imgsli.com/MzMyODgx

The heatHaze is wrong because the heatHaze itself is drawn into the regular framebuffer, so this is an aliasing issue. It might be possible to make heatHaze render into an MSAA FBO, but I'm not sure it's worth the performance hit, since heatHaze with MSAA currently works as:
Resolve MSAA into main -> use main to render heatHaze surfaces into the other main FBO -> bind the other main FBO -> render distorted heatHaze surface from the first main FBO -> transition back into the MSAA FBO

To fix it, it would have to be:
At the start, create another MSAA FBO
Resolve MSAA into main -> use main to render heatHaze surfaces into the extra MSAA FBO -> resolve the extra FBO into other main FBO -> bind main FBO -> render distorted heatHaze surface from the other main FBO -> transition back into the MSAA FBO
Which adds more rendering into MSAA targets and extra resolves (the extra resolves could also be more of an issue if material system is disabled, since the core renderer doesn't group drawcalls anywhere as efficiently).

@slipher
Copy link
Member

slipher commented Sep 1, 2025

Works great on my favorite jaggies test case from Spacetracks!

Default:
unvanquished-spacetracks-aliasing-jaggies

With r_msaa 1 - somehow a lot better already. Is that even supposed to be different from having it off?
unvanquished-spacetracks-aliasing-jaggies

r_msaa 64
unvanquished-spacetracks-aliasing-jaggies

@VReaperV
Copy link
Contributor Author

VReaperV commented Sep 1, 2025

With r_msaa 1 - somehow a lot better already. Is that even supposed to be different from having it off?

It's most likely that the driver is actually using a higher value. The spec says:

samples represents a request for a desired minimum number of samples.
Since different implementations may support different sample counts for multisampled textures, the actual number of samples allocated for the texture image is
implementation-dependent. However, the resulting value for TEXTURE_SAMPLES
is guaranteed to be greater than or equal to samples and no more than the next
larger sample count supported by the implementation.

@illwieckz
Copy link
Member

On my end it now works. I still get a black screen on AMD and Mesa when I use values higher than 8, but maybe we can cap that.

@VReaperV
Copy link
Contributor Author

VReaperV commented Sep 1, 2025

On my end it now works. I still get a black screen on AMD and Mesa when I use values higher than 8, but maybe we can cap that.

Does it say in the log that the samples requested were too high and it's falling back on some other value? According to https://opengl.gpuinfo.org/displaycapability.php?name=GL_MAX_COLOR_TEXTURE_SAMPLES, 8 is indeed the max for AMD, but the renderer should be automatically using that value if you specify a higher one.

@illwieckz
Copy link
Member

Using 4 dynamic light layers, 64 dynamic lights available per tile 
Warn: MSAA samples 9 > 8, setting to 8 
The change to r_msaa will take effect after restart. 
Warn: R_CheckFBO: (msaa) Framebuffer incomplete attachment 

After another vid_restart it works. So I guess we face some mess with the latching.

@illwieckz
Copy link
Member

illwieckz commented Sep 1, 2025

We probably need something similar to this, but for r_MSAA:

	// HACK: We want to set the current value, not the latched value
	Cvar::ClearFlags("r_customwidth", CVAR_LATCH);
	Cvar::ClearFlags("r_customheight", CVAR_LATCH);
	Cvar_Set( "r_customwidth", va("%d", windowConfig.vidWidth ) );
	Cvar_Set( "r_customheight", va("%d", windowConfig.vidHeight ) );
	Cvar::AddFlags("r_customwidth", CVAR_LATCH);
	Cvar::AddFlags("r_customheight", CVAR_LATCH);

@VReaperV
Copy link
Contributor Author

VReaperV commented Sep 1, 2025

Ah, yes. I'll add that a bit later.

@slipher
Copy link
Member

slipher commented Sep 1, 2025

We probably need something similar to this, but for r_MSAA:

Well that's only needed if you really want to use the cvar as a status display for the currently used value. Normally we try to avoid modifying cvars, and would store the current value in glConfig.msaa or something like that.

@VReaperV
Copy link
Contributor Author

VReaperV commented Sep 1, 2025

That's an option too.

@illwieckz
Copy link
Member

The glConfig.msaa way is fine.

@VReaperV
Copy link
Contributor Author

VReaperV commented Sep 2, 2025

The glConfig.msaa way is fine.

That part is done now.

@VReaperV
Copy link
Contributor Author

  • SSAO does not work.

Fixed.

@VReaperV
Copy link
Contributor Author

Turning on r_msaa causes tone mapping to be disabled in my tests. This is the same issue as I saw in #1684 (comment) (but this time I took screenshots with r_toneMapping 0 to confirm that this is what is happening). I can't reproduce it manually, only in scripted tests, so I need to do more investigation on how to reproduce it.
Also color grading is missing in my tests so it's like the whole cameraEffects shader is skipped?

I'm unable to reproduce this on NV and on Intel Arc (both with proprietary drivers).

@VReaperV
Copy link
Contributor Author

With conservative rasterisation I get seams with or without MSAA:
image

So perhaps there's an issue with the fog code as well.

@slipher
Copy link
Member

slipher commented Dec 28, 2025

Figured out what the tonemapping issue is. Nothing to do with my scripts; the problem is that screenshots are not the same as what you seen is on-screen. It seems to show the 3D drawing framebuffer before any color effects or 2D drawing.

@VReaperV
Copy link
Contributor Author

Figured out what the tonemapping issue is. Nothing to do with my scripts; the problem is that screenshots are not the same as what you seen is on-screen. It seems to show the 3D drawing framebuffer before any color effects or 2D drawing.

I suppose it's down to the order in which console commands are processed. The screenshots could be deferred such that the screenshot command is always inserted before the end of list command (the console commands just raising a flag instead).

@slipher
Copy link
Member

slipher commented Dec 29, 2025

Yeah looks like RB_ReadPixels doesn't bother to select which framebuffer to read from. So it depends on the correct one being active by accident and this could depend on the sequence of RenderCommands.

@slipher slipher mentioned this pull request Dec 29, 2025
Copy link
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

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

No regressions now and it looks great on my AMD card. Just a few nits.

GL_TexImage2D( target, 0, internalFormat, scaledWidth, scaledHeight, 0, format, GL_UNSIGNED_BYTE, scaledBuffer, isSRGB );
}
}
GL_CheckErrors();
Copy link
Member

Choose a reason for hiding this comment

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

GL_CheckErrors not needed here since it is done after the switch statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where after the switch statement?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe I should say after the outermost if/else. Right before the new location of switch ( image->internalFormat )

@slipher
Copy link
Member

slipher commented Jan 3, 2026

Also there should be an extension or version check for the needed OpenGL features. https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2DMultisample.xhtml just says it is available from version 3.2.

@VReaperV
Copy link
Contributor Author

VReaperV commented Jan 4, 2026

Also there should be an extension or version check for the needed OpenGL features. https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2DMultisample.xhtml just says it is available from version 3.2.

Jesus h. w. Christ

@slipher
Copy link
Member

slipher commented Jan 4, 2026

For some other cases where the GL version needs to be checked, I have done it like this:

if ( std::make_pair( glConfig.glMajor, glConfig.glMinor ) >= std::make_pair( 3, 2 ) )

@VReaperV
Copy link
Contributor Author

VReaperV commented Jan 4, 2026

For some other cases where the GL version needs to be checked, I have done it like this:

if ( std::make_pair( glConfig.glMajor, glConfig.glMinor ) >= std::make_pair( 3, 2 ) )

i added that.

Copy link
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

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

Unfortunately I found another bug when trying a different graphics preset... when MSAA is on and SSAO is off, depth fade doesn't work (no alpha modification occurs). I reproduced it with Nvidia so you should hopefully be able to see it.

@VReaperV
Copy link
Contributor Author

VReaperV commented Jan 9, 2026

Unfortunately I found another bug when trying a different graphics preset... when MSAA is on and SSAO is off, depth fade doesn't work (no alpha modification occurs). I reproduced it with Nvidia so you should hopefully be able to see it.

Fixed I think. Also added the missing MSAA resolve to global fog.

Add `r_msaa`. When set to > 0, an MSAA FBO will be created with that many samples. This FBO will be used for rendering, other than when it requires sampling from current render/depth image. When such rendering is required the MSAA FBO will be blit into the main FBO and vice versa, to resolve the MSAA texture.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants