diff --git a/src/BufferCopy/ColorBufferToRDRAM.cpp b/src/BufferCopy/ColorBufferToRDRAM.cpp index 1f20b9fb..82271e5b 100644 --- a/src/BufferCopy/ColorBufferToRDRAM.cpp +++ b/src/BufferCopy/ColorBufferToRDRAM.cpp @@ -258,9 +258,10 @@ u16 ColorBufferToRDRAM::_RGBAtoRGBA16(u32 _c, u32 x, u32 y) { union RGBA c; c.raw = _c; - if(gDP.otherMode.colorDither <= 1 && - ((config.frameBufferEmulation.nativeResFactor != 1 && config.generalEmulation.ditheringMode >= 3) - || config.generalEmulation.ditheringMode < 3)) { + if (gDP.otherMode.colorDither <= G_CD_BAYER // ordered grid dithering enabled in othermode + && (config.frameBufferEmulation.nativeResFactor != 1 // image is not already dithered + || config.generalEmulation.ditheringMode < Config::DitheringMode::dmFull)) + { s32 threshold = 0; switch(gDP.otherMode.colorDither){ diff --git a/src/Config.cpp b/src/Config.cpp index cea613ae..44048258 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -39,7 +39,7 @@ void Config::resetToDefaults() generalEmulation.enableLOD = 1; generalEmulation.enableNoise = 1; - generalEmulation.ditheringMode = 1; + generalEmulation.ditheringMode = DitheringMode::dmNoise; generalEmulation.enableHWLighting = 0; generalEmulation.enableCustomSettings = 1; generalEmulation.enableShadersStorage = 1; diff --git a/src/Config.h b/src/Config.h index 21908bb7..6ac1bacf 100644 --- a/src/Config.h +++ b/src/Config.h @@ -46,6 +46,14 @@ struct Config tcForce }; + enum DitheringMode { + dmDisable = 0, + dmNoise, + dmNoiseWithQuant, + dmFull, + dmFullWithQuant + }; + struct { u32 enableNoise; u32 ditheringMode; diff --git a/src/Graphics/CombinerProgram.cpp b/src/Graphics/CombinerProgram.cpp index 5580926d..e62e04db 100644 --- a/src/Graphics/CombinerProgram.cpp +++ b/src/Graphics/CombinerProgram.cpp @@ -13,7 +13,10 @@ namespace graphics { vecOptions.push_back(config.texture.enableHalosRemoval); vecOptions.push_back(config.generalEmulation.enableHWLighting); vecOptions.push_back(config.generalEmulation.enableNoise); - vecOptions.push_back(config.generalEmulation.ditheringMode); + vecOptions.push_back(config.generalEmulation.ditheringMode == Config::DitheringMode::dmNoise ? 1 : 0); + vecOptions.push_back(config.generalEmulation.ditheringMode == Config::DitheringMode::dmNoiseWithQuant ? 1 : 0); + vecOptions.push_back(config.generalEmulation.ditheringMode == Config::DitheringMode::dmFull ? 1 : 0); + vecOptions.push_back(config.generalEmulation.ditheringMode == Config::DitheringMode::dmFullWithQuant ? 1 : 0); vecOptions.push_back(config.generalEmulation.enableLOD); vecOptions.push_back(config.frameBufferEmulation.N64DepthCompare == Config::dcFast ? 1 : 0); vecOptions.push_back(config.frameBufferEmulation.N64DepthCompare == Config::dcCompatible ? 1 : 0); diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp index d1ab35a8..afa49bba 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramBuilder.cpp @@ -719,7 +719,7 @@ public: ShaderCallDither(const opengl::GLInfo & _glinfo) { if (!_glinfo.isGLES2) { - if (config.generalEmulation.ditheringMode >= 1) { + if (config.generalEmulation.ditheringMode != Config::DitheringMode::dmDisable) { m_part = " if (uColorDitherMode == 2) { \n" " colorNoiseDither(snoiseRGB(), clampedColor.rgb); \n" @@ -731,7 +731,7 @@ public: " } \n" ; } - if (config.generalEmulation.ditheringMode >= 3) { + if (config.generalEmulation.ditheringMode >= Config::DitheringMode::dmFull) { m_part += // Try to keep dithering visible even at higher resolutions " lowp float divider = 1.0 + step(3.0, uScreenScale.x); \n" @@ -1042,7 +1042,7 @@ public: ShaderFragmentHeaderDither(const opengl::GLInfo & _glinfo) { if (!_glinfo.isGLES2) { - if(config.generalEmulation.ditheringMode >= 1) { + if (config.generalEmulation.ditheringMode != Config::DitheringMode::dmDisable) { m_part = "void colorNoiseDither(in lowp vec3 _noise, inout lowp vec3 _color);\n" "void alphaNoiseDither(in lowp float _noise, inout lowp float _alpha);\n" @@ -1631,7 +1631,7 @@ public: " return 0.5; \n" "} \n" ; - if (config.generalEmulation.ditheringMode >= 1) { + if (config.generalEmulation.ditheringMode != Config::DitheringMode::dmDisable) { m_part += "uniform sampler2D uTexNoise; \n" ; @@ -1667,7 +1667,7 @@ public: ShaderDither(const opengl::GLInfo & _glinfo) { if (!_glinfo.isGLES2) { - if( config.generalEmulation.ditheringMode >= 1 ) { + if (config.generalEmulation.ditheringMode != Config::DitheringMode::dmDisable) { m_part = "void colorNoiseDither(in lowp vec3 _noise, inout lowp vec3 _color)\n" "{ \n" @@ -1708,7 +1708,8 @@ public: " return texture(uTexNoise,coord).r; \n" "} \n" ; - if ( config.generalEmulation.ditheringMode == 2 || config.generalEmulation.ditheringMode == 4 ) { + if (config.generalEmulation.ditheringMode == Config::DitheringMode::dmNoiseWithQuant || + config.generalEmulation.ditheringMode == Config::DitheringMode::dmFullWithQuant) { m_part += "void quantizeRGB(inout lowp vec3 _color)\n" "{ \n" diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp index d342f883..33b9c122 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp +++ b/src/Graphics/OpenGLContext/GLSL/glsl_CombinerProgramUniformFactory.cpp @@ -1042,8 +1042,10 @@ void CombinerProgramUniformFactory::buildUniforms(GLuint _program, const CombinerKey & _key, UniformGroups & _uniforms) { - if (config.generalEmulation.enableNoise != 0 || config.generalEmulation.ditheringMode > 0) + if (config.generalEmulation.enableNoise != 0 || + config.generalEmulation.ditheringMode != Config::DitheringMode::dmDisable) { _uniforms.emplace_back(new UNoiseTex(_program)); + } if (!m_glInfo.isGLES2) { _uniforms.emplace_back(new UDepthTex(_program)); diff --git a/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h b/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h index 660569e7..80ad42ab 100644 --- a/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h +++ b/src/Graphics/OpenGLContext/GLSL/glsl_ShaderStorage.h @@ -20,7 +20,7 @@ namespace glsl { bool _saveCombinerKeys(const graphics::Combiners & _combiners) const; bool _loadFromCombinerKeys(graphics::Combiners & _combiners); - const u32 m_formatVersion = 0x2AU; + const u32 m_formatVersion = 0x2BU; const u32 m_keysFormatVersion = 0x04; const opengl::GLInfo & m_glinfo; opengl::CachedUseProgram * m_useProgram; diff --git a/src/NoiseTexture.cpp b/src/NoiseTexture.cpp index ad6b1bd2..fbb6ad29 100644 --- a/src/NoiseTexture.cpp +++ b/src/NoiseTexture.cpp @@ -106,8 +106,10 @@ void NoiseTexture::_fillTextureData() void NoiseTexture::init() { - if (config.generalEmulation.enableNoise == 0 && config.generalEmulation.ditheringMode == 0) + if (config.generalEmulation.enableNoise == 0 && + config.generalEmulation.ditheringMode == Config::DitheringMode::dmDisable) { return; + } if (m_texData[0].empty()) _fillTextureData(); @@ -161,7 +163,7 @@ void NoiseTexture::destroy() void NoiseTexture::update() { - if (m_DList == dwnd().getBuffersSwapCount() || (config.generalEmulation.enableNoise == 0 && config.generalEmulation.ditheringMode == 0)) + if (m_texData[0].empty() || m_DList == dwnd().getBuffersSwapCount()) return; u32 rand_value(0U); diff --git a/src/mupenplus/Config_mupenplus.cpp b/src/mupenplus/Config_mupenplus.cpp index 1fa80da0..8b7910e3 100644 --- a/src/mupenplus/Config_mupenplus.cpp +++ b/src/mupenplus/Config_mupenplus.cpp @@ -69,7 +69,7 @@ bool Config_SetDefault() //#Emulation Settings res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableNoise", config.generalEmulation.enableNoise, "Enable color noise emulation."); assert(res == M64ERR_SUCCESS); - res = ConfigSetDefaultInt(g_configVideoGliden64, "DitheringMode", config.generalEmulation.ditheringMode, "Dithering mode. (0=disable, 1=only noise dithering (default), 2=noise dithering with 16bit quantization,3=noise and ordered grid dithering, 4=dithering with 16bit quantization)"); + res = ConfigSetDefaultInt(g_configVideoGliden64, "DitheringMode", config.generalEmulation.ditheringMode, "Dithering mode. (0=disable, 1=noise dithering (default), 2=noise dithering with 5bit quantization, 3=full dithering, 4=full dithering with 5bit quantization)"); assert(res == M64ERR_SUCCESS); res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableLOD", config.generalEmulation.enableLOD, "Enable LOD emulation."); assert(res == M64ERR_SUCCESS);