Permalink
Browse files

video-gliden64: Update to commit 3f7d868.

gonetz/GLideN64@3f7d868

* 3f7d868 Fix mipmaping when mip-map emulation disabled in settings. Most detailed tiles will always be used.
* a3ddc4c Correct mipmap shader again.
  • Loading branch information...
Gillou68310 committed Jun 18, 2015
1 parent a077a17 commit a9b9e1e8e744ae20c3423b49e1937e0489462d2f
@@ -214,7 +214,7 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
if (bUseHWLight)
strFragmentShader.append(fragment_shader_calc_light);
if (bUseLod)
- strFragmentShader.append(fragment_shader_mipmap);
+ strFragmentShader.append(fragment_shader_fake_mipmap);
else if (usesTexture()) {
if (config.texture.bilinearMode == BILINEAR_3POINT)
strFragmentShader.append(fragment_shader_readtex_3point);
@@ -277,7 +277,7 @@ void ShaderCombiner::_locateUniforms() {
LocateUniform(uSpecialBlendMode);
LocateUniform(uFogAlpha);
- LocateUniform(uPrimitiveLod);
+ LocateUniform(uMinLod);
LocateUniform(uDeltaZ);
LocateUniform(uAlphaTestValue);
@@ -426,12 +426,8 @@ void ShaderCombiner::updateDitherMode(bool _bForce)
void ShaderCombiner::updateLOD(bool _bForce)
{
if (usesLOD()) {
- int uCalcLOD = (gDP.otherMode.textureLOD == G_TL_LOD) ? 1 : 0;
- if (uCalcLOD) {
- m_uniforms.uScreenScale.set(video().getScaleX(), video().getScaleY(), _bForce);
- m_uniforms.uPrimitiveLod.set(gDP.primColor.l, _bForce);
- m_uniforms.uMaxTile.set(gSP.texture.level, _bForce);
- }
+ m_uniforms.uMinLod.set(gDP.primColor.m, _bForce);
+ m_uniforms.uMaxTile.set(gSP.texture.level, _bForce);
}
}
@@ -282,15 +282,15 @@ static const char* fragment_shader_end =
"} \n"
;
-static const char* fragment_shader_mipmap =
-"uniform lowp float uPrimitiveLod; \n"
+static const char* fragment_shader_fake_mipmap =
"uniform lowp int uMaxTile; \n"
+"uniform mediump float uMinLod; \n"
" \n"
"mediump float mipmap(out lowp vec4 readtex0, out lowp vec4 readtex1) { \n"
" readtex0 = texture2D(uTex0, vTexCoord0); \n"
" readtex1 = texture2D(uTex1, vTexCoord1); \n"
" if (uMaxTile == 0) return 1.0; \n"
-" return uPrimitiveLod; \n"
+" return uMinLod; \n"
"} \n"
;
@@ -92,7 +92,7 @@ class ShaderCombiner {
uMaxTile, uTextureDetail, uTexturePersp, uTextureFilterMode, uMSAASamples,
uAlphaCompareMode, uAlphaDitherMode, uColorDitherMode, uGammaCorrectionEnabled;
- fUniform uFogAlpha, uPrimitiveLod, uMinLod, uDeltaZ, uAlphaTestValue, uMSAAScale;
+ fUniform uFogAlpha, uMinLod, uDeltaZ, uAlphaTestValue, uMSAAScale;
fv2Uniform uScreenScale, uDepthScale, uFogScale;
@@ -355,12 +355,16 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
if (config.generalEmulation.enableNoise == 0)
strFragmentShader.append(fragment_shader_dummy_noise);
+ if (bUseLod && config.generalEmulation.enableLOD == 0)
+ strFragmentShader.append(fragment_shader_fake_mipmap);
+
#ifdef GLESX
if (bUseHWLight)
strFragmentShader.append(fragment_shader_calc_light);
- if (bUseLod)
- strFragmentShader.append(fragment_shader_mipmap);
- else if (usesTexture()) {
+ if (bUseLod) {
+ if (config.generalEmulation.enableLOD != 0)
+ strFragmentShader.append(fragment_shader_mipmap);
+ } else if (usesTexture()) {
strFragmentShader.append(config.texture.bilinearMode == BILINEAR_3POINT ? fragment_shader_readtex_3point : fragment_shader_readtex);
#ifdef GL_MULTISAMPLING_SUPPORT
if (config.video.multisampling > 0)
@@ -394,9 +398,10 @@ ShaderCombiner::ShaderCombiner(Combiner & _color, Combiner & _alpha, const gDPCo
#ifndef GLESX
if (bUseHWLight)
glAttachShader(m_program, g_calc_light_shader_object);
- if (bUseLod)
- glAttachShader(m_program, g_calc_mipmap_shader_object);
- else if (usesTexture()) {
+ if (bUseLod) {
+ if (config.generalEmulation.enableLOD != 0)
+ glAttachShader(m_program, g_calc_mipmap_shader_object);
+ } else if (usesTexture()) {
glAttachShader(m_program, g_readtex_shader_object);
if (config.video.multisampling > 0)
glAttachShader(m_program, g_readtex_ms_shader_object);
@@ -620,15 +625,17 @@ void ShaderCombiner::updateDitherMode(bool _bForce)
void ShaderCombiner::updateLOD(bool _bForce)
{
- if (usesLOD()) {
- int uCalcLOD = (config.generalEmulation.enableLOD && gDP.otherMode.textureLOD == G_TL_LOD) ? 1 : 0;
+ if (!usesLOD())
+ return;
+
+ m_uniforms.uMinLod.set(gDP.primColor.m, _bForce);
+ m_uniforms.uMaxTile.set(gSP.texture.level, _bForce);
+
+ if (config.generalEmulation.enableLOD != 0) {
+ const int uCalcLOD = (gDP.otherMode.textureLOD == G_TL_LOD) ? 1 : 0;
m_uniforms.uEnableLod.set(uCalcLOD, _bForce);
- if (uCalcLOD) {
- m_uniforms.uScreenScale.set(video().getScaleX(), video().getScaleY(), _bForce);
- m_uniforms.uMinLod.set(gDP.primColor.m, _bForce);
- m_uniforms.uMaxTile.set(gSP.texture.level - gSP.texture.tile, _bForce);
- m_uniforms.uTextureDetail.set(gDP.otherMode.textureDetail, _bForce);
- }
+ m_uniforms.uScreenScale.set(video().getScaleX(), video().getScaleY(), _bForce);
+ m_uniforms.uTextureDetail.set(gDP.otherMode.textureDetail, _bForce);
}
}
@@ -365,7 +365,9 @@ AUXILIARY_SHADER_VERSION
#else
" mediump vec2 dx = dFdx(vLodTexCoord); \n"
" dx *= uScreenScale; \n"
-" mediump float lod = length(dx); \n"
+" mediump vec2 dy = dFdy(vLodTexCoord); \n"
+" dy *= uScreenScale; \n"
+" mediump float lod = max(length(dx), length(dy)); \n"
#endif
" bool magnify = lod < 1.0; \n"
" mediump float lod_tile = magnify ? 0.0 : floor(log2(floor(lod))); \n"
@@ -385,26 +387,42 @@ AUXILIARY_SHADER_VERSION
" lowp vec4 lodT = textureLod(uTex1, vTexCoord1, lod_tile); \n"
" lowp vec4 lodT_m1 = textureLod(uTex1, vTexCoord1, lod_tile_m1); \n"
" lowp vec4 lodT_p1 = textureLod(uTex1, vTexCoord1, lod_tile + 1.0); \n"
-
-" if ((uTextureDetail & 2) != 0) { \n"
-" if (magnify) \n"
-" readtex1 = lodT; \n"
-" else { \n"
-" readtex0 = lodT; \n"
-" readtex1 = lodT_p1; \n"
+" if (lod_tile < 1.0) { \n"
+" if (magnify) { \n"
+// !sharpen && !detail
+" if (uTextureDetail == 0) readtex1 = readtex0; \n"
+" } else { \n"
+// detail
+" if ((uTextureDetail & 2) != 0 ) { \n"
+" readtex0 = lodT; \n"
+" readtex1 = lodT_p1; \n"
+" } \n"
" } \n"
" } else { \n"
-" if (!magnify) \n"
+" if ((uTextureDetail & 2) != 0 ) { \n"
+" readtex0 = lodT; \n"
+" readtex1 = lodT_p1; \n"
+" } else { \n"
" readtex0 = lodT_m1; \n"
-" if (distant || (((uTextureDetail & 1) != 0) && magnify)) \n"
-" readtex1 = readtex0; \n"
-" else \n"
" readtex1 = lodT; \n"
+" } \n"
" } \n"
" return lod_frac; \n"
"} \n"
;
+static const char* fragment_shader_fake_mipmap =
+"uniform lowp int uMaxTile; \n"
+"uniform mediump float uMinLod; \n"
+" \n"
+"mediump float mipmap(out lowp vec4 readtex0, out lowp vec4 readtex1) { \n"
+" readtex0 = texture(uTex0, vTexCoord0); \n"
+" readtex1 = texture(uTex1, vTexCoord1); \n"
+" if (uMaxTile == 0) return 1.0; \n"
+" return uMinLod; \n"
+"} \n"
+;
+
static const char* fragment_shader_readtex =
AUXILIARY_SHADER_VERSION
"lowp vec4 readTex(in sampler2D tex, in mediump vec2 texCoord, in bool fb8bit, in bool fbFixedAlpha) \n"
@@ -1 +1 @@
-#define PLUGIN_REVISION "db38b2f"
+#define PLUGIN_REVISION "3f7d868"

0 comments on commit a9b9e1e

Please sign in to comment.