mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Move noise dithering into separate shader.
This commit is contained in:
parent
dd2e7e098b
commit
8b59da54d7
|
@ -22,6 +22,7 @@ static GLuint g_calc_noise_shader_object;
|
|||
static GLuint g_calc_depth_shader_object;
|
||||
static GLuint g_test_alpha_shader_object;
|
||||
static GLuint g_readtex_shader_object;
|
||||
static GLuint g_dither_shader_object;
|
||||
|
||||
GLuint g_monochrome_image_program = 0;
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
|
@ -285,6 +286,7 @@ void InitShaderCombiner()
|
|||
g_calc_noise_shader_object = _createFragmentShader(fragment_shader_noise);
|
||||
g_test_alpha_shader_object = _createFragmentShader(alpha_test_fragment_shader);
|
||||
g_readtex_shader_object = _createFragmentShader(fragment_shader_readtex);
|
||||
g_dither_shader_object = _createFragmentShader(fragment_shader_dither);
|
||||
|
||||
#ifdef GL_IMAGE_TEXTURES_SUPPORT
|
||||
if (video().getRender().isImageTexturesSupported() && config.frameBufferEmulation.N64DepthCompare != 0)
|
||||
|
@ -314,6 +316,8 @@ void DestroyShaderCombiner() {
|
|||
g_calc_noise_shader_object = 0;
|
||||
glDeleteShader(g_test_alpha_shader_object);
|
||||
g_test_alpha_shader_object = 0;
|
||||
glDeleteShader(g_dither_shader_object);
|
||||
g_dither_shader_object = 0;
|
||||
glDeleteShader(g_calc_depth_shader_object);
|
||||
g_calc_depth_shader_object = 0;
|
||||
|
||||
|
@ -540,8 +544,10 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
|
|||
strFragmentShader.append(" if (!alpha_test(alpha2)) discard;\n");
|
||||
|
||||
if (config.generalEmulation.enableNoise != 0) {
|
||||
strFragmentShader.append(fragment_shader_color_dither);
|
||||
strFragmentShader.append(fragment_shader_alpha_dither);
|
||||
strFragmentShader.append(
|
||||
" if (uColorDitherMode == 2) colorNoiseDither(clamp(snoise(), 0.0, 1.0), color2); \n"
|
||||
" if (uAlphaDitherMode == 2) alphaNoiseDither(clamp(snoise(), 0.0, 1.0), alpha2); \n"
|
||||
);
|
||||
}
|
||||
|
||||
strFragmentShader.append(
|
||||
|
@ -612,8 +618,10 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
|
|||
glAttachShader(m_program, g_test_alpha_shader_object);
|
||||
if (video().getRender().isImageTexturesSupported() && config.frameBufferEmulation.N64DepthCompare != 0)
|
||||
glAttachShader(m_program, g_calc_depth_shader_object);
|
||||
if (config.generalEmulation.enableNoise != 0)
|
||||
if (config.generalEmulation.enableNoise != 0) {
|
||||
glAttachShader(m_program, g_calc_noise_shader_object);
|
||||
glAttachShader(m_program, g_dither_shader_object);
|
||||
}
|
||||
#endif
|
||||
glLinkProgram(m_program);
|
||||
assert(checkProgramLinkStatus(m_program));
|
||||
|
|
35
Shaders.h
35
Shaders.h
|
@ -188,6 +188,8 @@ static const char* fragment_shader_header_common_functions =
|
|||
"lowp vec4 readTex(in sampler2D tex, in mediump vec2 texCoord, in bool fb8bit, in bool fbFixedAlpha); \n"
|
||||
"bool depth_compare(); \n"
|
||||
"bool alpha_test(in lowp float alphaValue); \n"
|
||||
"void colorNoiseDither(in float _noise, inout vec3 _color); \n"
|
||||
"void alphaNoiseDither(in float _noise, inout float _alpha);\n"
|
||||
#else
|
||||
" \n"
|
||||
"float snoise(); \n"
|
||||
|
@ -293,24 +295,23 @@ static const char* fragment_shader_header_main =
|
|||
;
|
||||
#endif
|
||||
|
||||
static const char* fragment_shader_color_dither =
|
||||
" if (uColorDitherMode == 2) { \n"
|
||||
" mediump vec3 tmpColor = color2*255.0; \n"
|
||||
" mediump ivec3 iColor = ivec3(tmpColor)&248; \n"
|
||||
" lowp float noise = clamp(snoise(), 0.0, 1.0); \n"
|
||||
" iColor += ivec3(tmpColor*noise)&7; \n"
|
||||
" color2 = vec3(iColor)/255.0; \n"
|
||||
" } \n"
|
||||
;
|
||||
|
||||
static const char* fragment_shader_alpha_dither =
|
||||
" if (uAlphaDitherMode == 2) { \n"
|
||||
" mediump float tmpAlpha = alpha2*255.0; \n"
|
||||
static const char* fragment_shader_dither =
|
||||
"#version 330 core \n"
|
||||
"void colorNoiseDither(in float _noise, inout 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"
|
||||
"} \n"
|
||||
"void alphaNoiseDither(in float _noise, inout float _alpha) \n"
|
||||
"{ \n"
|
||||
" mediump float tmpAlpha = _alpha*255.0; \n"
|
||||
" mediump int iAlpha = int(tmpAlpha)&248; \n"
|
||||
" lowp float noise = clamp(snoise(), 0.0, 1.0); \n"
|
||||
" iAlpha += int(tmpAlpha*noise)&7; \n"
|
||||
" alpha2 = float(iAlpha)/255.0; \n"
|
||||
" } \n"
|
||||
" iAlpha |= int(tmpAlpha*_noise)&7; \n"
|
||||
" _alpha = float(iAlpha)/255.0; \n"
|
||||
"} \n"
|
||||
;
|
||||
|
||||
#ifdef USE_TOONIFY
|
||||
|
|
Loading…
Reference in New Issue
Block a user