Skip to content

Commit

Permalink
Add sample shading for MSAA (better quality) (#1765)
Browse files Browse the repository at this point in the history
* Add minimum sample shading rate for MSAA (better quality)
* Change default value to 0.0f
  • Loading branch information
bcdrme authored Nov 12, 2024
1 parent a71f3fb commit 57a8c50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rts/Rendering/GlobalRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CONFIG(bool, DebugGLStacktraces).defaultValue(false).description("Create a stack
CONFIG(int, GLContextMajorVersion).defaultValue(3).minimumValue(3).maximumValue(4);
CONFIG(int, GLContextMinorVersion).defaultValue(0).minimumValue(0).maximumValue(5);
CONFIG(int, MSAALevel).defaultValue(0).minimumValue(0).maximumValue(32).description("Enables multisample anti-aliasing; 'level' is the number of samples used.");
CONFIG(float, MinSampleShadingRate).defaultValue(0.0f).minimumValue(0.0f).maximumValue(1.0f).description("A value of 1.0 indicates that each sample in the framebuffer should be independently shaded. A value of 0.0 effectively allows the GL to ignore sample rate shading. Any value between 0.0 and 1.0 allows the GL to shade only a subset of the total samples within each covered fragment.");

CONFIG(int, ForceDisablePersistentMapping).defaultValue(0).minimumValue(0).maximumValue(1);
CONFIG(int, ForceDisableExplicitAttribLocs).defaultValue(0).minimumValue(0).maximumValue(1);
Expand Down Expand Up @@ -162,6 +163,7 @@ CR_REG_METADATA(CGlobalRendering, (
CR_IGNORED(forceSwapBuffers),

CR_IGNORED(msaaLevel),
CR_IGNORED(minSampleShadingRate),
CR_IGNORED(maxTextureSize),
CR_IGNORED(maxFragShSlots),
CR_IGNORED(maxCombShSlots),
Expand Down Expand Up @@ -274,6 +276,7 @@ CGlobalRendering::CGlobalRendering()

// fallback
, msaaLevel(configHandler->GetInt("MSAALevel"))
, minSampleShadingRate(configHandler->GetFloat("MinSampleShadingRate"))
, maxTextureSize(2048)
, maxFragShSlots(8)
, maxCombShSlots(8)
Expand Down Expand Up @@ -1660,6 +1663,14 @@ void CGlobalRendering::InitGLState()
msaaLevel *= CheckGLMultiSampling();
ToggleMultisampling();

if(msaaLevel > 0 && minSampleShadingRate > 0.0f) {
// Enable sample shading
glEnable(GL_SAMPLE_SHADING_ARB);
if (GLEW_VERSION_4_0) {
glMinSampleShading(minSampleShadingRate);
}
}

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

Expand Down
1 change: 1 addition & 0 deletions rts/Rendering/GlobalRendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class CGlobalRendering {
* Level of multisample anti-aliasing
*/
int msaaLevel;
float minSampleShadingRate;

/**
* @brief maxTextureSize
Expand Down

0 comments on commit 57a8c50

Please sign in to comment.