1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

-Remove enableDithering setting and use ditheringMode for everything

-Dithering Modes:
0 disabled
1 noise dithering
2 noise dithering with 5Bit quantitzation
3 noise and ordered grid dithering
4 noise and ordered grid dithering with 5Bit quantitzation
-Quantize dithered alpha (5Bit). Removes white remnants in SF Lylat
Wars.
This commit is contained in:
gizmo98 2020-03-11 07:45:49 +01:00 committed by Sergey Lipskiy
parent 1a6f83aa6c
commit 350d791596
9 changed files with 118 additions and 117 deletions

View File

@ -258,7 +258,9 @@ 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.enableDithering == 0) {
if(gDP.otherMode.colorDither <= 1 &&
((config.frameBufferEmulation.nativeResFactor != 1 && config.generalEmulation.ditheringMode >= 3)
|| config.generalEmulation.ditheringMode < 3)) {
s32 threshold = 0;
switch(gDP.otherMode.colorDither){

View File

@ -39,8 +39,7 @@ void Config::resetToDefaults()
generalEmulation.enableLOD = 1;
generalEmulation.enableNoise = 1;
generalEmulation.enableDithering = 0;
generalEmulation.ditheringMode = 0;
generalEmulation.ditheringMode = 1;
generalEmulation.enableHWLighting = 0;
generalEmulation.enableCustomSettings = 1;
generalEmulation.enableShadersStorage = 1;

View File

@ -48,7 +48,6 @@ struct Config
struct {
u32 enableNoise;
u32 enableDithering;
u32 ditheringMode;
u32 enableLOD;
u32 enableHWLighting;

View File

@ -41,7 +41,6 @@ void _loadSettings(QSettings & settings)
settings.beginGroup("generalEmulation");
config.generalEmulation.enableNoise = settings.value("enableNoise", config.generalEmulation.enableNoise).toInt();
config.generalEmulation.enableDithering = settings.value("enableDithering", config.generalEmulation.enableDithering).toInt();
config.generalEmulation.ditheringMode = settings.value("ditheringMode", config.generalEmulation.ditheringMode).toInt();
config.generalEmulation.enableLOD = settings.value("enableLOD", config.generalEmulation.enableLOD).toInt();
config.generalEmulation.enableHWLighting = settings.value("enableHWLighting", config.generalEmulation.enableHWLighting).toInt();

View File

@ -13,7 +13,6 @@ 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.enableDithering);
vecOptions.push_back(config.generalEmulation.ditheringMode);
vecOptions.push_back(config.generalEmulation.enableLOD);
vecOptions.push_back(config.frameBufferEmulation.N64DepthCompare == Config::dcFast ? 1 : 0);

View File

@ -718,41 +718,59 @@ class ShaderCallDither : public ShaderPart
public:
ShaderCallDither(const opengl::GLInfo & _glinfo)
{
if (!_glinfo.isGLES2 && config.generalEmulation.enableNoise != 0) {
m_part =
" if (uColorDitherMode == 2) { \n"
" colorNoiseDither(snoiseRGB(), clampedColor.rgb); \n"
" quantize(clampedColor.rgb); \n"
" } \n"
" if (uAlphaDitherMode == 2) alphaNoiseDither(snoiseA(), clampedColor.a);\n"
if (!_glinfo.isGLES2) {
if (config.generalEmulation.ditheringMode >= 1) {
m_part =
" if (uColorDitherMode == 2) { \n"
" colorNoiseDither(snoiseRGB(), clampedColor.rgb); \n"
" quantizeRGB(clampedColor.rgb); \n"
" } \n"
" if (uAlphaDitherMode == 2) { \n"
" alphaNoiseDither(snoiseA(), clampedColor.a); \n"
" quantizeA(clampedColor.a); \n"
" } \n"
;
}
if (!_glinfo.isGLES2 && config.generalEmulation.enableDithering != 0) {
m_part +=
" mediump mat4 threshold; \n"
" if (uColorDitherMode < 2) { \n"
// Try to eep dithering visible even at higher resolutions
" lowp float divider = 1.0 + step(3.0, uScreenScale.x); \n"
" mediump ivec2 position = ivec2(mod((gl_FragCoord.xy - 0.5) / divider,4.0));\n"
" \n"
" lowp mat4 bayer = mat4( 0.0, 0.75, 0.1875, 0.9375, \n"
" 0.5, 0.25, 0.6875, 0.4375, \n"
" 0.125, 0.875, 0.0625, 0.8125, \n"
" 0.625, 0.375, 0.5625, 0.3125); \n"
" lowp mat4 mSquare = mat4( 0.0, 0.6875, 0.75, 0.4375, \n"
" 0.875, 0.3125, 0.125, 0.5625, \n"
" 0.1875, 0.5, 0.9375, 0.25, \n"
" 0.8125, 0.375, 0.0625, 0.625); \n"
" \n"
" lowp float bayerThreshold = bayer[position.x][position.y]; \n"
" lowp float mSquareThreshold = mSquare[position.x][position.y]; \n"
" \n"
" lowp float threshold = mix(bayerThreshold,mSquareThreshold,float(uColorDitherMode));\n"
" colorDither(threshold, clampedColor.rgb); \n"
// 16 Bit quantization
" quantize(clampedColor.rgb); \n"
" } \n"
}
if (config.generalEmulation.ditheringMode >= 3) {
m_part +=
// Try to keep dithering visible even at higher resolutions
" lowp float divider = 1.0 + step(3.0, uScreenScale.x); \n"
" mediump ivec2 position = ivec2(mod((gl_FragCoord.xy - 0.5) / divider,4.0));\n"
" \n"
" lowp mat4 bayer = mat4( 0.0, 0.75, 0.1875, 0.9375, \n"
" 0.5, 0.25, 0.6875, 0.4375, \n"
" 0.125, 0.875, 0.0625, 0.8125, \n"
" 0.625, 0.375, 0.5625, 0.3125); \n"
" lowp mat4 mSquare = mat4( 0.0, 0.6875, 0.75, 0.4375, \n"
" 0.875, 0.3125, 0.125, 0.5625, \n"
" 0.1875, 0.5, 0.9375, 0.25, \n"
" 0.8125, 0.375, 0.0625, 0.625); \n"
" \n"
" lowp float bayerThreshold = bayer[position.x][position.y]; \n"
" lowp float mSquareThreshold = mSquare[position.x][position.y]; \n"
" \n"
" if (uColorDitherMode < 2) { \n"
" lowp float threshold = mix(mSquareThreshold,bayerThreshold,float(uColorDitherMode));\n"
" colorNoiseDither(vec3(threshold), clampedColor.rgb); \n"
// 16 Bit quantization
" quantizeRGB(clampedColor.rgb); \n"
" } \n"
" if (uAlphaDitherMode < 2) { \n"
" lowp float thresholdPattern = mix(mSquareThreshold,bayerThreshold,clamp(float(uColorDitherMode),0.0,1.0));\n"
" thresholdPattern = mix(thresholdPattern,mSquareThreshold,clamp(float(uColorDitherMode - 1),0.0,1.0));\n" // uColorDitherMode = 2
" thresholdPattern = mix(thresholdPattern,bayerThreshold,clamp(float(uColorDitherMode - 2),0.0,1.0));\n" // uColorDitherMode = 3
" \n"
" lowp float thresholdNotPattern = mix(bayerThreshold,mSquareThreshold,clamp(float(uColorDitherMode),0.0,1.0));\n"
" thresholdNotPattern = mix(thresholdNotPattern,bayerThreshold,clamp(float(uColorDitherMode - 1),0.0,1.0));\n" // uColorDitherMode = 2
" thresholdNotPattern = mix(thresholdNotPattern,mSquareThreshold,clamp(float(uColorDitherMode - 2),0.0,1.0));\n" // uColorDitherMode = 3
" \n"
" lowp float threshold = mix(thresholdNotPattern, thresholdPattern,float(uAlphaDitherMode));\n"
" alphaNoiseDither(threshold, clampedColor.a); \n"
// 16 Bit quantization
" quantizeA(clampedColor.a); \n"
" } \n"
;
}
}
}
};
@ -937,12 +955,6 @@ public:
m_part =
"lowp float snoise();\n"
;
if (!_glinfo.isGLES2 && config.generalEmulation.enableNoise != 0) {
m_part +=
"lowp vec3 snoiseRGB();\n"
"lowp float snoiseA();\n"
;
}
}
};
@ -1029,21 +1041,17 @@ class ShaderFragmentHeaderDither : public ShaderPart
public:
ShaderFragmentHeaderDither(const opengl::GLInfo & _glinfo)
{
if (!_glinfo.isGLES2 && config.generalEmulation.enableNoise != 0) {
m_part =
"void colorNoiseDither(in lowp vec3 _noise, inout lowp vec3 _color);\n"
"void alphaNoiseDither(in lowp float _noise, inout lowp float _alpha);\n"
;
}
if (!_glinfo.isGLES2 && config.generalEmulation.enableDithering != 0) {
m_part +=
"void colorDither(in lowp float _threshold, inout lowp vec3 _color);\n"
;
}
if (!_glinfo.isGLES2 && (config.generalEmulation.enableNoise != 0 || config.generalEmulation.enableDithering != 0)) {
m_part +=
"void quantize(inout lowp vec3 _color);\n"
;
if (!_glinfo.isGLES2) {
if(config.generalEmulation.ditheringMode >= 1) {
m_part =
"void colorNoiseDither(in lowp vec3 _noise, inout lowp vec3 _color);\n"
"void alphaNoiseDither(in lowp float _noise, inout lowp float _alpha);\n"
"void quantizeRGB(inout lowp vec3 _color);\n"
"void quantizeA(inout lowp float _alpha);\n"
"lowp vec3 snoiseRGB();\n"
"lowp float snoiseA();\n"
;
}
}
}
};
@ -1623,6 +1631,11 @@ public:
" return 0.5; \n"
"} \n"
;
if (config.generalEmulation.ditheringMode >= 1) {
m_part +=
"uniform sampler2D uTexNoise; \n"
;
}
} else {
if (_glinfo.isGLES2) {
m_part =
@ -1642,6 +1655,30 @@ public:
" ivec2 coord = ivec2(gl_FragCoord.xy/uScreenScale); \n"
" return texelFetch(uTexNoise, coord, 0).r; \n"
"} \n"
;
}
}
}
};
class ShaderDither : public ShaderPart
{
public:
ShaderDither(const opengl::GLInfo & _glinfo)
{
if (!_glinfo.isGLES2) {
if( config.generalEmulation.ditheringMode >= 1 ) {
m_part =
"void colorNoiseDither(in lowp vec3 _noise, inout lowp vec3 _color)\n"
"{ \n"
" mediump vec3 threshold = 7.0 / 255.0 * (_noise - 0.5);\n"
" _color = clamp(_color + threshold,0.0,1.0); \n"
"} \n"
"void alphaNoiseDither(in lowp float _noise, inout lowp float _alpha)\n"
"{ \n"
" mediump float threshold = 7.0 / 255.0 * (_noise - 0.5);\n"
" _alpha = clamp(_alpha + threshold,0.0,1.0); \n"
"} \n"
"lowp vec3 snoiseRGB() \n"
"{ \n"
" mediump vec2 texSize = vec2(640.0, 580.0); \n"
@ -1670,54 +1707,25 @@ public:
// Only red channel of noise texture contains noise.
" return texture(uTexNoise,coord).r; \n"
"} \n"
;
if ( config.generalEmulation.ditheringMode == 2 || config.generalEmulation.ditheringMode == 4 ) {
m_part +=
"void quantizeRGB(inout lowp vec3 _color)\n"
"{ \n"
" _color.rgb = round(_color.rgb * 32.0)/32.0; \n"
"} \n"
"void quantizeA(inout lowp float _alpha)\n"
"{ \n"
" _alpha = round(_alpha * 32.0)/32.0; \n"
"} \n"
;
}
}
}
};
class ShaderDither : public ShaderPart
{
public:
ShaderDither(const opengl::GLInfo & _glinfo)
{
if (!_glinfo.isGLES2 && config.generalEmulation.enableNoise != 0) {
m_part =
"void colorNoiseDither(in lowp vec3 _noise, inout lowp vec3 _color)\n"
"{ \n"
" mediump vec3 threshold = 7.0 / 255.0 * (_noise - 0.5);\n"
" _color = clamp(_color + threshold,0.0,1.0); \n"
"} \n"
"void alphaNoiseDither(in lowp float _noise, inout lowp float _alpha)\n"
"{ \n"
" mediump float threshold = 7.0 / 255.0 * (_noise - 0.5);\n"
" _alpha = clamp(_alpha + threshold,0.0,1.0); \n"
"} \n"
;
}
if (!_glinfo.isGLES2 && config.generalEmulation.enableDithering != 0) {
m_part +=
"void colorDither(in lowp float _threshold, inout lowp vec3 _color)\n"
"{ \n"
" lowp vec3 threshold = vec3(7.0 / 255.0 * (_threshold - 0.5));\n"
" _color = clamp(_color + threshold,0.0,1.0); \n"
"} \n"
;
}
if (!_glinfo.isGLES2 && (config.generalEmulation.enableNoise != 0 || config.generalEmulation.enableDithering != 0)) {
if (config.generalEmulation.ditheringMode == 1 ) {
m_part +=
"void quantize(inout lowp vec3 _color)\n"
"{ \n"
" _color.rgb = round(_color.rgb * 32.0)/32.0; \n"
"} \n"
;
}
else
{
m_part +=
"void quantize(inout lowp vec3 _color){}\n"
;
}
else {
m_part +=
"void quantizeRGB(inout lowp vec3 _color){}\n"
"void quantizeA(inout lowp float _alpha){}\n"
;
}
}
}
}

View File

@ -1042,7 +1042,7 @@ void CombinerProgramUniformFactory::buildUniforms(GLuint _program,
const CombinerKey & _key,
UniformGroups & _uniforms)
{
if (config.generalEmulation.enableNoise != 0)
if (config.generalEmulation.enableNoise != 0 || config.generalEmulation.ditheringMode > 0)
_uniforms.emplace_back(new UNoiseTex(_program));
if (!m_glInfo.isGLES2) {

View File

@ -106,7 +106,7 @@ void NoiseTexture::_fillTextureData()
void NoiseTexture::init()
{
if (config.generalEmulation.enableNoise == 0)
if (config.generalEmulation.enableNoise == 0 && config.generalEmulation.ditheringMode == 0)
return;
if (m_texData[0].empty())
@ -161,7 +161,7 @@ void NoiseTexture::destroy()
void NoiseTexture::update()
{
if (m_DList == dwnd().getBuffersSwapCount() || config.generalEmulation.enableNoise == 0)
if (m_DList == dwnd().getBuffersSwapCount() || (config.generalEmulation.enableNoise == 0 && config.generalEmulation.ditheringMode == 0))
return;
u32 rand_value(0U);

View File

@ -69,9 +69,7 @@ bool Config_SetDefault()
//#Emulation Settings
res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableNoise", config.generalEmulation.enableNoise, "Enable color noise emulation.");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableDithering", config.generalEmulation.enableDithering, "Enable dithering emulation.");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "DitheringMode", config.generalEmulation.ditheringMode, "Dithering mode. (false=32Bit colors, true=16Bit quantization like original hardware)");
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)");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableLOD", config.generalEmulation.enableLOD, "Enable LOD emulation.");
assert(res == M64ERR_SUCCESS);
@ -276,8 +274,6 @@ void Config_LoadCustomConfig()
result = ConfigExternalGetParameter(fileHandle, sectionName, "generalEmulation\\enableNoise", value, sizeof(value));
if (result == M64ERR_SUCCESS) config.generalEmulation.enableNoise = atoi(value);
result = ConfigExternalGetParameter(fileHandle, sectionName, "generalEmulation\\enableDithering", value, sizeof(value));
if (result == M64ERR_SUCCESS) config.generalEmulation.enableDithering = atoi(value);
result = ConfigExternalGetParameter(fileHandle, sectionName, "generalEmulation\\ditheringMode", value, sizeof(value));
if (result == M64ERR_SUCCESS) config.generalEmulation.ditheringMode = atoi(value);
result = ConfigExternalGetParameter(fileHandle, sectionName, "generalEmulation\\enableLOD", value, sizeof(value));
@ -403,8 +399,7 @@ void Config_LoadConfig()
config.texture.enableHalosRemoval = ConfigGetParamBool(g_configVideoGliden64, "enableHalosRemoval");
//#Emulation Settings
config.generalEmulation.enableNoise = ConfigGetParamBool(g_configVideoGliden64, "EnableNoise");
config.generalEmulation.enableDithering = ConfigGetParamBool(g_configVideoGliden64, "EnableDithering");
config.generalEmulation.ditheringMode = ConfigGetParamBool(g_configVideoGliden64, "DitheringMode");
config.generalEmulation.ditheringMode = ConfigGetParamInt(g_configVideoGliden64, "DitheringMode");
config.generalEmulation.enableLOD = ConfigGetParamBool(g_configVideoGliden64, "EnableLOD");
config.generalEmulation.enableHWLighting = ConfigGetParamBool(g_configVideoGliden64, "EnableHWLighting");
config.generalEmulation.enableShadersStorage = ConfigGetParamBool(g_configVideoGliden64, "EnableShadersStorage");