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

Correct alpha compare and alpha/color dither with noise.

This commit is contained in:
Sergey Lipskiy 2014-04-26 21:22:26 +07:00
parent dd522d123c
commit 994e961db2
4 changed files with 33 additions and 16 deletions

View File

@ -422,6 +422,9 @@ GLSLCombiner::GLSLCombiner(Combiner *_color, Combiner *_alpha) {
strcat(fragment_shader, " input_color = vShadeColor.rgb;\n");
strcat(fragment_shader, " vec_color = vec4(input_color, vShadeColor.a); \n");
strcat(fragment_shader, strCombiner);
strcat(fragment_shader, " if (uColorDitherMode == 2) color2 *= clamp(snoise(vNoiseCoord2D), 0, 1);");
// strcat(fragment_shader, " if (uAlphaDitherMode == 2) alpha2 *= clamp(snoise(vNoiseCoord2D), 0, 1);");
strcat(fragment_shader, " gl_FragColor = vec4(color2, alpha2); \n");
strcat(fragment_shader, " if (!alpha_test(gl_FragColor.a)) discard; \n");
@ -515,7 +518,9 @@ void GLSLCombiner::_locateUniforms() {
LocateUniform(uZlutImage);
LocateUniform(uDepthImage);
LocateUniform(uEnableFog);
LocateUniform(uEnableDither);
LocateUniform(uAlphaCompareMode);
LocateUniform(uAlphaDitherMode);
LocateUniform(uColorDitherMode);
LocateUniform(uEnableLod);
LocateUniform(uEnableAlphaTest);
LocateUniform(uEnableDepth);
@ -534,6 +539,8 @@ void GLSLCombiner::_locateUniforms() {
LocateUniform(uK5);
LocateUniform(uPrimLod);
LocateUniform(uNoiseTime);
LocateUniform(uScreenWidth);
LocateUniform(uScreenHeight);
LocateUniform(uLodXScale);
LocateUniform(uLodYScale);
LocateUniform(uMinLod);
@ -595,6 +602,8 @@ void GLSLCombiner::Set() {
_setIUniform(m_uniforms.uTex0, 0, true);
_setIUniform(m_uniforms.uTex1, 1, true);
_setFUniform(m_uniforms.uScreenWidth, OGL.width, true);
_setFUniform(m_uniforms.uScreenHeight, OGL.height, true);
UpdateRenderState(true);
UpdateColors(true);
@ -643,10 +652,12 @@ void GLSLCombiner::UpdateColors(bool _bForce) {
}
}
int nDither = (gDP.otherMode.alphaCompare == 3 && (gDP.otherMode.colorDither == 2 || gDP.otherMode.alphaDither == 2)) ? 1 : 0;
_setIUniform(m_uniforms.uEnableDither, nDither, _bForce);
_setIUniform(m_uniforms.uAlphaCompareMode, gDP.otherMode.alphaCompare, _bForce);
_setIUniform(m_uniforms.uAlphaDitherMode, gDP.otherMode.alphaDither, _bForce);
_setIUniform(m_uniforms.uColorDitherMode, gDP.otherMode.colorDither, _bForce);
if ((m_nInputs & (1<<NOISE)) + nDither > 0)
const int nDither = (gDP.otherMode.colorDither == 2 || gDP.otherMode.alphaDither == 2 || gDP.otherMode.alphaCompare == 3) ? 1 : 0;
if ((m_nInputs & (1<<NOISE)) + nDither != 0)
_setFUniform(m_uniforms.uNoiseTime, (float)(rand()&255), _bForce);
if (!_bForce)

View File

@ -25,12 +25,13 @@ private:
struct UniformLocation
{
iUniform uTex0, uTex1, uTlutImage, uZlutImage, uDepthImage,
uEnableFog, uEnableDither, uEnableLod, uEnableAlphaTest,
uEnableFog, uEnableLod, uEnableAlphaTest,
uEnableDepth, uEnableDepthCompare, uEnableDepthUpdate,
uDepthMode, uFb8Bit, uFbFixedAlpha, uRenderState,
uMaxTile, uTextureDetail, uTexturePersp;
uMaxTile, uTextureDetail, uTexturePersp,
uAlphaCompareMode, uAlphaDitherMode, uColorDitherMode;
fUniform uFogMultiplier, uFogOffset, uK4, uK5, uPrimLod, uNoiseTime,
fUniform uFogMultiplier, uFogOffset, uK4, uK5, uPrimLod, uNoiseTime, uScreenWidth, uScreenHeight,
uLodXScale, uLodYScale, uMinLod, uDepthTrans, uDepthScale, uAlphaTestValue;
fv4Uniform uEnvColor, uPrimColor, uFogColor, uCenterColor, uScaleColor;

View File

@ -118,7 +118,7 @@ const char *noise_fragment_shader =
" vec3 g; \n"
" g.x = a0.x * x0.x + h.x * x0.y; \n"
" g.yz = a0.yz * x12.xz + h.yz * x12.yw; \n"
" return 130.0 * dot(m, g); \n"
" return clamp(130.0 * dot(m, g), -1.0, 1.0); \n"
"} \n"
" \n"
#endif

View File

@ -9,8 +9,9 @@ static const char* vertex_shader =
" \n"
"uniform int uRenderState; \n"
"uniform int uTexturePersp; \n"
"uniform float uNoiseTime; \n"
"uniform float uFogMultiplier, uFogOffset; \n"
"uniform lowp float uNoiseTime; \n"
"uniform mediump uFogMultiplier, uFogOffset; \n"
"uniform mediump float uScreenWidth, uScreenHeight; \n"
" \n"
"uniform mediump vec2 uTexScale; \n"
"uniform mediump vec2 uTexOffset[2]; \n"
@ -38,6 +39,7 @@ static const char* vertex_shader =
"uniform int uTexturePersp; \n"
"uniform float uNoiseTime; \n"
"uniform float uFogMultiplier, uFogOffset; \n"
"uniform float uScreenWidth, uScreenHeight; \n"
" \n"
"uniform vec2 uTexScale; \n"
"uniform vec2 uTexOffset[2]; \n"
@ -77,8 +79,7 @@ static const char* vertex_shader =
" vTexCoord0 = aTexCoord0; \n"
" vTexCoord1 = aTexCoord1; \n"
" } \n"
//" vNoiseCoord2D = gl_Vertex.xy + vec2(0.0, uNoiseTime); \n"
" vNoiseCoord2D = vec2(0.0, uNoiseTime); \n"
" vNoiseCoord2D = vec2(gl_Position.x*uScreenWidth, gl_Position.y*uScreenHeight + uNoiseTime);\n"
" if (aPosition.z < -aPosition.w) \n"
" vFogFragCoord = -uFogMultiplier + uFogOffset; \n"
" else \n"
@ -101,7 +102,9 @@ static const char* fragment_shader_header_common_variables =
"uniform lowp float uK4; \n"
"uniform lowp float uK5; \n"
"uniform lowp float uPrimLod; \n"
"uniform lowp int uEnableDither;\n"
"uniform lowp int uAlphaCompareMode; \n"
"uniform lowp int uAlphaDitherMode; \n"
"uniform lowp int uColorDitherMode; \n"
"uniform lowp int uEnableFog; \n"
"uniform lowp int uFb8Bit; \n"
"uniform lowp int uFbFixedAlpha;\n"
@ -124,7 +127,9 @@ static const char* fragment_shader_header_common_variables =
"uniform float uK4; \n"
"uniform float uK5; \n"
"uniform float uPrimLod; \n"
"uniform int uEnableDither; \n"
"uniform int uAlphaCompareMode; \n"
"uniform int uAlphaDitherMode; \n"
"uniform int uColorDitherMode; \n"
"uniform int uEnableFog; \n"
"uniform int uFb8Bit; \n"
"uniform int uFbFixedAlpha; \n"
@ -292,7 +297,7 @@ static const char* fragment_shader_header_main =
" \n"
"void main() \n"
"{ \n"
" if (uEnableDither != 0) { \n"
" if (uAlphaCompareMode == 3) {//dither \n"
" if (snoise(vNoiseCoord2D) < 0.0) discard; \n"
" } \n"
" lowp vec4 vec_color, combined_color; \n"
@ -303,7 +308,7 @@ static const char* fragment_shader_header_main =
" \n"
"void main() \n"
"{ \n"
" if (uEnableDither != 0) { \n"
" if (uAlphaCompareMode == 3) {//dither \n"
" if (snoise(vNoiseCoord2D) < 0.0) discard; \n"
" } \n"
" vec4 vec_color, combined_color; \n"