mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Correct alpha compare for noise dither mode.
Fixed Rare logo in KI64, #11
This commit is contained in:
parent
6910278fbe
commit
79f5893000
|
@ -21,7 +21,6 @@ static GLuint g_calc_light_shader_object;
|
|||
static GLuint g_calc_mipmap_shader_object;
|
||||
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;
|
||||
|
||||
|
@ -282,7 +281,6 @@ void InitShaderCombiner()
|
|||
g_calc_light_shader_object = _createShader(GL_FRAGMENT_SHADER, fragment_shader_calc_light);
|
||||
g_calc_mipmap_shader_object = _createShader(GL_FRAGMENT_SHADER, fragment_shader_mipmap);
|
||||
g_calc_noise_shader_object = _createShader(GL_FRAGMENT_SHADER, fragment_shader_noise);
|
||||
g_test_alpha_shader_object = _createShader(GL_FRAGMENT_SHADER, alpha_test_fragment_shader);
|
||||
g_readtex_shader_object = _createShader(GL_FRAGMENT_SHADER, fragment_shader_readtex);
|
||||
g_dither_shader_object = _createShader(GL_FRAGMENT_SHADER, fragment_shader_dither);
|
||||
|
||||
|
@ -314,8 +312,6 @@ void DestroyShaderCombiner() {
|
|||
g_readtex_shader_object = 0;
|
||||
glDeleteShader(g_calc_noise_shader_object);
|
||||
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);
|
||||
|
@ -547,12 +543,17 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
|
|||
strFragmentShader.append(" vec_color = vec4(input_color, vShadeColor.a); \n");
|
||||
strFragmentShader.append(strCombiner);
|
||||
|
||||
strFragmentShader.append(" if (!alpha_test(alpha2)) discard;\n");
|
||||
strFragmentShader.append(
|
||||
" if (uEnableAlphaTest != 0) { \n"
|
||||
" lowp float alphaTestValue = (uAlphaCompareMode == 3 && alpha2 > 0.0) ? snoise() : uAlphaTestValue; \n"
|
||||
" if (alpha2 < alphaTestValue) discard; \n"
|
||||
" } \n"
|
||||
);
|
||||
|
||||
if (config.generalEmulation.enableNoise != 0) {
|
||||
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"
|
||||
" if (uColorDitherMode == 2) colorNoiseDither(snoise(), color2); \n"
|
||||
" if (uAlphaDitherMode == 2) alphaNoiseDither(snoise(), alpha2); \n"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -596,7 +597,6 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
|
|||
#endif
|
||||
|
||||
#ifdef GLES2
|
||||
strFragmentShader.append(alpha_test_fragment_shader);
|
||||
strFragmentShader.append(noise_fragment_shader);
|
||||
if (bUseLod)
|
||||
strFragmentShader.append(fragment_shader_mipmap);
|
||||
|
@ -625,7 +625,6 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
|
|||
glAttachShader(m_program, g_calc_mipmap_shader_object);
|
||||
else if (usesTex())
|
||||
glAttachShader(m_program, g_readtex_shader_object);
|
||||
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) {
|
||||
|
@ -905,16 +904,16 @@ void ShaderCombiner::updateAlphaTestInfo(bool _bForce) {
|
|||
_setIUniform(m_uniforms.uEnableAlphaTest, 0, _bForce);
|
||||
_setFUniform(m_uniforms.uAlphaTestValue, 0.0f, _bForce);
|
||||
} else if (gDP.otherMode.cycleType == G_CYC_COPY) {
|
||||
if (gDP.otherMode.alphaCompare & 1) {
|
||||
if (gDP.otherMode.alphaCompare & G_AC_THRESHOLD) {
|
||||
_setIUniform(m_uniforms.uEnableAlphaTest, 1, _bForce);
|
||||
_setFUniform(m_uniforms.uAlphaTestValue, 0.5f, _bForce);
|
||||
} else {
|
||||
_setIUniform(m_uniforms.uEnableAlphaTest, 0, _bForce);
|
||||
_setFUniform(m_uniforms.uAlphaTestValue, 0.0f, _bForce);
|
||||
}
|
||||
} else if ((gDP.otherMode.alphaCompare == G_AC_THRESHOLD) && (gDP.otherMode.alphaCvgSel == 0) && (gDP.otherMode.forceBlender == 0 || gDP.blendColor.a > 0)) {
|
||||
} else if (((gDP.otherMode.alphaCompare & G_AC_THRESHOLD) != 0) && (gDP.otherMode.alphaCvgSel == 0) && (gDP.otherMode.forceBlender == 0 || gDP.blendColor.a > 0)) {
|
||||
_setIUniform(m_uniforms.uEnableAlphaTest, 1, _bForce);
|
||||
_setFUniform(m_uniforms.uAlphaTestValue, gDP.blendColor.a, _bForce);
|
||||
_setFUniform(m_uniforms.uAlphaTestValue, max(gDP.blendColor.a, 1.0f/256.0f), _bForce);
|
||||
} else if (gDP.otherMode.cvgXAlpha != 0) {
|
||||
_setIUniform(m_uniforms.uEnableAlphaTest, 1, _bForce);
|
||||
_setFUniform(m_uniforms.uAlphaTestValue, 0.125f, _bForce);
|
||||
|
|
31
Shaders.h
31
Shaders.h
|
@ -204,6 +204,8 @@ static const char* fragment_shader_header_common_variables =
|
|||
"uniform lowp int uFb8Bit; \n"
|
||||
"uniform lowp int uFbFixedAlpha;\n"
|
||||
"uniform lowp int uSpecialBlendMode;\n"
|
||||
"uniform lowp int uEnableAlphaTest; \n"
|
||||
"uniform lowp float uAlphaTestValue;\n"
|
||||
"uniform mediump vec2 uDepthScale; \n"
|
||||
"in lowp vec4 vShadeColor; \n"
|
||||
"in mediump vec2 vTexCoord0;\n"
|
||||
|
@ -264,6 +266,8 @@ static const char* fragment_shader_header_common_variables_notex =
|
|||
"uniform lowp int uGammaCorrectionEnabled; \n"
|
||||
"uniform lowp int uFogUsage; \n"
|
||||
"uniform lowp int uSpecialBlendMode;\n"
|
||||
"uniform lowp int uEnableAlphaTest; \n"
|
||||
"uniform lowp float uAlphaTestValue;\n"
|
||||
"uniform mediump vec2 uDepthScale; \n"
|
||||
"in lowp vec4 vShadeColor; \n"
|
||||
"in lowp float vNumLights; \n"
|
||||
|
@ -280,7 +284,6 @@ static const char* fragment_shader_header_common_functions =
|
|||
"mediump float mipmap(out lowp vec4 readtex0, out lowp vec4 readtex1); \n"
|
||||
"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
|
||||
|
@ -289,7 +292,6 @@ static const char* fragment_shader_header_common_functions =
|
|||
"float calc_light(in float fLights, in vec3 input_color, out vec3 output_color);\n"
|
||||
"float mipmap(out vec4 readtex0, out vec4 readtex1); \n"
|
||||
"bool depth_compare(); \n"
|
||||
"bool alpha_test(in float alphaValue); \n"
|
||||
#endif
|
||||
#ifdef USE_TOONIFY
|
||||
"void toonify(in mediump float intensity); \n"
|
||||
|
@ -301,7 +303,6 @@ static const char* fragment_shader_header_common_functions_notex =
|
|||
"lowp float snoise(); \n"
|
||||
"void calc_light(in lowp float fLights, in lowp vec3 input_color, out lowp vec3 output_color);\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"
|
||||
;
|
||||
|
@ -328,34 +329,12 @@ static const char* fragment_shader_calc_light =
|
|||
"} \n"
|
||||
;
|
||||
|
||||
static const char* alpha_test_fragment_shader =
|
||||
#ifdef SHADER_PRECISION
|
||||
"#version 330 core \n"
|
||||
"uniform lowp int uEnableAlphaTest; \n"
|
||||
"uniform lowp float uAlphaTestValue; \n"
|
||||
"bool alpha_test(in lowp float alphaValue) \n"
|
||||
#else
|
||||
"#version 330 core \n"
|
||||
"uniform int uEnableAlphaTest; \n"
|
||||
"uniform float uAlphaTestValue; \n"
|
||||
"bool alpha_test(in float alphaValue) \n"
|
||||
#endif
|
||||
"{ \n"
|
||||
" if (uEnableAlphaTest == 0) return true; \n"
|
||||
" if (uAlphaTestValue > 0.0) return alphaValue >= uAlphaTestValue;\n"
|
||||
" return alphaValue > 0.0; \n"
|
||||
"} \n"
|
||||
;
|
||||
|
||||
static const char* fragment_shader_header_main =
|
||||
#ifdef SHADER_PRECISION
|
||||
" \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" gl_FragDepth = clamp((gl_FragCoord.z * 2.0 - 1.0) * uDepthScale.s + uDepthScale.t, 0.0, 1.0); \n"
|
||||
" if (uAlphaCompareMode == 3) {//dither \n"
|
||||
" if (snoise() < 0.0) discard; \n"
|
||||
" } \n"
|
||||
" lowp vec4 vec_color, combined_color; \n"
|
||||
" lowp float alpha1, alpha2; \n"
|
||||
" lowp vec3 color1, color2; \n"
|
||||
|
@ -639,7 +618,7 @@ static const char* fragment_shader_noise =
|
|||
"lowp float snoise() \n"
|
||||
"{ \n"
|
||||
" ivec2 coord = ivec2(gl_FragCoord.xy/uScreenScale); \n"
|
||||
" return (texelFetch(uTexNoise, coord, 0).r - 0.5)*2.0;\n"
|
||||
" return texelFetch(uTexNoise, coord, 0).r; \n"
|
||||
"} \n"
|
||||
;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user