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

Add dithering options and better color noise dithering

-Add enableDithering option: true - dithering enabled; false -
dithering disabled
-Add ditheringMode option: quantize noise or ordered grid dithered
content like original hardware would do it. true - quantize to 16Bit
colors, false 32Bit colors.
-Add snoiseRGB() and snoiseA() functions. Color dithering needs
different noiese values for r, g and b.
-snoiseRGB() and snoiseA() „double“ noise resolution if uScreenscale is
>= 2.0. So noise not so blocky but still grainy at higher resolutions.
-Increase config version to 28U
This commit is contained in:
gizmo98 2020-03-06 22:17:12 +01:00 committed by Sergey Lipskiy
parent 6bdcaa0bfa
commit 0597632f8a
6 changed files with 130 additions and 19 deletions

View File

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

View File

@ -5,7 +5,7 @@
#include "Types.h"
#define CONFIG_WITH_PROFILES 23U
#define CONFIG_VERSION_CURRENT 27U
#define CONFIG_VERSION_CURRENT 28U
#define BILINEAR_3POINT 0
#define BILINEAR_STANDARD 1
@ -48,6 +48,8 @@ struct Config
struct {
u32 enableNoise;
u32 enableDithering;
u32 ditheringMode;
u32 enableLOD;
u32 enableHWLighting;
u32 enableCustomSettings;

View File

@ -41,6 +41,8 @@ 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();
config.generalEmulation.enableShadersStorage = settings.value("enableShadersStorage", config.generalEmulation.enableShadersStorage).toInt();

View File

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

View File

@ -720,8 +720,38 @@ public:
{
if (!_glinfo.isGLES2 && config.generalEmulation.enableNoise != 0) {
m_part =
" if (uColorDitherMode == 2) colorNoiseDither(snoise(), clampedColor.rgb); \n"
" if (uAlphaDitherMode == 2) alphaNoiseDither(snoise(), clampedColor.a); \n"
" 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 && 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"
;
}
}
@ -905,8 +935,14 @@ public:
ShaderFragmentHeaderNoise(const opengl::GLInfo & _glinfo)
{
m_part =
"lowp float snoise();\n";
"lowp float snoise();\n"
;
if (!_glinfo.isGLES2 && config.generalEmulation.enableNoise != 0) {
m_part +=
"lowp vec3 snoiseRGB();\n"
"lowp float snoiseA();\n"
;
}
}
};
@ -995,8 +1031,18 @@ public:
{
if (!_glinfo.isGLES2 && config.generalEmulation.enableNoise != 0) {
m_part =
"void colorNoiseDither(in lowp float _noise, inout lowp vec3 _color);\n"
"void alphaNoiseDither(in lowp float _noise, inout lowp float _alpha);\n";
"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"
;
}
}
@ -1590,12 +1636,40 @@ public:
;
} else {
m_part =
"uniform sampler2D uTexNoise; \n"
"uniform sampler2D uTexNoise; \n"
"lowp float snoise() \n"
"{ \n"
" ivec2 coord = ivec2(gl_FragCoord.xy/uScreenScale); \n"
" return texelFetch(uTexNoise, coord, 0).r; \n"
"} \n"
"lowp vec3 snoiseRGB() \n"
"{ \n"
" mediump vec2 texSize = vec2(640.0, 580.0); \n"
// multiplier for higher res noise effect
" lowp float mult = 1.0 + step(2.0, uScreenScale.x); \n"
" \n"
" mediump vec2 coordR = mult * ((gl_FragCoord.xy)/uScreenScale/texSize);\n"
" mediump vec2 coordG = mult * ((gl_FragCoord.xy + vec2( 0.0, texSize.y / 2.0 ))/uScreenScale/texSize);\n"
" mediump vec2 coordB = mult * ((gl_FragCoord.xy + vec2( texSize.x / 2.0, 0.0))/uScreenScale/texSize);\n"
" \n"
// Only red channel of noise texture contains noise.
" lowp float r = texture(uTexNoise,coordR).r; \n"
" lowp float g = texture(uTexNoise,coordG).r; \n"
" lowp float b = texture(uTexNoise,coordB).r; \n"
" \n"
" return vec3(r,g,b); \n"
"} \n"
"lowp float snoiseA() \n"
"{ \n"
" mediump vec2 texSize = vec2(640.0, 580.0); \n"
// multiplier for higher res noise effect
" lowp float mult = 1.0 + step(2.0, uScreenScale.x); \n"
" \n"
" mediump vec2 coord = mult * ((gl_FragCoord.xy)/uScreenScale/texSize);\n"
" \n"
// Only red channel of noise texture contains noise.
" return texture(uTexNoise,coord).r; \n"
"} \n"
;
}
}
@ -1609,24 +1683,43 @@ public:
{
if (!_glinfo.isGLES2 && config.generalEmulation.enableNoise != 0) {
m_part =
"void colorNoiseDither(in lowp float _noise, inout lowp vec3 _color) \n"
"void colorNoiseDither(in lowp vec3 _noise, inout lowp vec3 _color)\n"
"{ \n"
" mediump vec3 tmpColor = _color*255.0; \n"
" mediump ivec3 iColor = ivec3(tmpColor); \n"
//" iColor &= 248; \n" // does not work with HW lighting enabled (why?!)
" iColor |= ivec3(tmpColor*_noise)&7; \n"
" _color = vec3(iColor)/255.0; \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"
"void alphaNoiseDither(in lowp float _noise, inout lowp float _alpha)\n"
"{ \n"
" mediump float tmpAlpha = _alpha*255.0; \n"
" mediump int iAlpha = int(tmpAlpha); \n"
//" iAlpha &= 248; \n" // causes issue #518. need further investigation
" iAlpha |= int(tmpAlpha*_noise)&7; \n"
" _alpha = float(iAlpha)/255.0; \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"
;
}
}
}
};

View File

@ -69,6 +69,10 @@ 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)");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableLOD", config.generalEmulation.enableLOD, "Enable LOD emulation.");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableHWLighting", config.generalEmulation.enableHWLighting, "Enable hardware per-pixel lighting.");
@ -272,6 +276,10 @@ 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));
if (result == M64ERR_SUCCESS) config.generalEmulation.enableLOD = atoi(value);
result = ConfigExternalGetParameter(fileHandle, sectionName, "generalEmulation\\enableHWLighting", value, sizeof(value));
@ -395,6 +403,8 @@ 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.enableLOD = ConfigGetParamBool(g_configVideoGliden64, "EnableLOD");
config.generalEmulation.enableHWLighting = ConfigGetParamBool(g_configVideoGliden64, "EnableHWLighting");
config.generalEmulation.enableShadersStorage = ConfigGetParamBool(g_configVideoGliden64, "EnableShadersStorage");