mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-02 09:03:37 +00:00
Fix texture ShiftScale calculation.
Pokemon Stadium missing ground texture #412 reveals the problem: the game loads the same texture into tile0 and tile1. The only difference is ShiftScale values. Since the checksum is the same, the same CachedTexture is used for both tiles. Shift scale correction ovrwrites ShiftScale for tile0 when tile1 is loaded. Thus, texture coordinates for both tiles will be same. Combiner uses (tile0-tile1)*env_a+shade. Since t0==t1, texture component is missing. Solution: calculate ShiftScale for each tile right before use. Fixed #412
This commit is contained in:
parent
94a4f7c411
commit
4b1114a113
|
@ -1136,8 +1136,12 @@ void UniformBlock::updateTextureParameters()
|
|||
texCacheScale[1] = cache.current[0]->scaleT;
|
||||
texCacheOffset[0] = cache.current[0]->offsetS;
|
||||
texCacheOffset[1] = cache.current[0]->offsetT;
|
||||
texCacheShiftScale[0] = cache.current[0]->shiftScaleS;
|
||||
texCacheShiftScale[1] = cache.current[0]->shiftScaleT;
|
||||
|
||||
f32 shiftScaleS = 1.0f;
|
||||
f32 shiftScaleT = 1.0f;
|
||||
getTextureShiftScale(0, cache, shiftScaleS, shiftScaleT);
|
||||
texCacheShiftScale[0] = shiftScaleS;
|
||||
texCacheShiftScale[1] = shiftScaleT;
|
||||
texCacheFrameBuffer[0] = cache.current[0]->frameBufferTexture;
|
||||
}
|
||||
if (cache.current[1]) {
|
||||
|
@ -1145,8 +1149,12 @@ void UniformBlock::updateTextureParameters()
|
|||
texCacheScale[5] = cache.current[1]->scaleT;
|
||||
texCacheOffset[4] = cache.current[1]->offsetS;
|
||||
texCacheOffset[5] = cache.current[1]->offsetT;
|
||||
texCacheShiftScale[4] = cache.current[1]->shiftScaleS;
|
||||
texCacheShiftScale[5] = cache.current[1]->shiftScaleT;
|
||||
|
||||
f32 shiftScaleS = 1.0f;
|
||||
f32 shiftScaleT = 1.0f;
|
||||
getTextureShiftScale(1, cache, shiftScaleS, shiftScaleT);
|
||||
texCacheShiftScale[4] = shiftScaleS;
|
||||
texCacheShiftScale[5] = shiftScaleT;
|
||||
texCacheFrameBuffer[1] = cache.current[1]->frameBufferTexture;
|
||||
}
|
||||
memcpy(pData + m_textureBlock.m_offsets[tuCacheScale], texCacheScale, m_textureBlock.m_offsets[tuCacheOffset] - m_textureBlock.m_offsets[tuCacheScale]);
|
||||
|
|
|
@ -1031,10 +1031,13 @@ void OGLRender::drawTexturedRect(const TexturedRectParams & _params)
|
|||
} texST[2] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; //struct for texture coordinates
|
||||
|
||||
if (currentCombiner()->usesT0() && cache.current[0] && gSP.textureTile[0]) {
|
||||
texST[0].s0 = _params.uls * cache.current[0]->shiftScaleS - gSP.textureTile[0]->fuls;
|
||||
texST[0].t0 = _params.ult * cache.current[0]->shiftScaleT - gSP.textureTile[0]->fult;
|
||||
texST[0].s1 = (_params.lrs + 1.0f) * cache.current[0]->shiftScaleS - gSP.textureTile[0]->fuls;
|
||||
texST[0].t1 = (_params.lrt + 1.0f) * cache.current[0]->shiftScaleT - gSP.textureTile[0]->fult;
|
||||
f32 shiftScaleS = 1.0f;
|
||||
f32 shiftScaleT = 1.0f;
|
||||
getTextureShiftScale(0, cache, shiftScaleS, shiftScaleT);
|
||||
texST[0].s0 = _params.uls * shiftScaleS - gSP.textureTile[0]->fuls;
|
||||
texST[0].t0 = _params.ult * shiftScaleT - gSP.textureTile[0]->fult;
|
||||
texST[0].s1 = (_params.lrs + 1.0f) * shiftScaleS - gSP.textureTile[0]->fuls;
|
||||
texST[0].t1 = (_params.lrt + 1.0f) * shiftScaleT - gSP.textureTile[0]->fult;
|
||||
|
||||
if (cache.current[0]->frameBufferTexture) {
|
||||
texST[0].s0 = cache.current[0]->offsetS + texST[0].s0;
|
||||
|
@ -1058,10 +1061,13 @@ void OGLRender::drawTexturedRect(const TexturedRectParams & _params)
|
|||
}
|
||||
|
||||
if (currentCombiner()->usesT1() && cache.current[1] && gSP.textureTile[1]) {
|
||||
texST[1].s0 = _params.uls * cache.current[1]->shiftScaleS - gSP.textureTile[1]->fuls;
|
||||
texST[1].t0 = _params.ult * cache.current[1]->shiftScaleT - gSP.textureTile[1]->fult;
|
||||
texST[1].s1 = (_params.lrs + 1.0f) * cache.current[1]->shiftScaleS - gSP.textureTile[1]->fuls;
|
||||
texST[1].t1 = (_params.lrt + 1.0f) * cache.current[1]->shiftScaleT - gSP.textureTile[1]->fult;
|
||||
f32 shiftScaleS = 1.0f;
|
||||
f32 shiftScaleT = 1.0f;
|
||||
getTextureShiftScale(1, cache, shiftScaleS, shiftScaleT);
|
||||
texST[1].s0 = _params.uls * shiftScaleS - gSP.textureTile[1]->fuls;
|
||||
texST[1].t0 = _params.ult * shiftScaleT - gSP.textureTile[1]->fult;
|
||||
texST[1].s1 = (_params.lrs + 1.0f) * shiftScaleS - gSP.textureTile[1]->fuls;
|
||||
texST[1].t1 = (_params.lrt + 1.0f) * shiftScaleT - gSP.textureTile[1]->fult;
|
||||
|
||||
if (cache.current[1]->frameBufferTexture) {
|
||||
texST[1].s0 = cache.current[1]->offsetS + texST[1].s0;
|
||||
|
|
|
@ -1205,23 +1205,6 @@ void TextureCache::_clear()
|
|||
m_textures.clear();
|
||||
}
|
||||
|
||||
static
|
||||
void _updateShiftScale(u32 _t, CachedTexture *_pTexture)
|
||||
{
|
||||
_pTexture->shiftScaleS = 1.0f;
|
||||
_pTexture->shiftScaleT = 1.0f;
|
||||
|
||||
if (gSP.textureTile[_t]->shifts > 10)
|
||||
_pTexture->shiftScaleS = (f32)(1 << (16 - gSP.textureTile[_t]->shifts));
|
||||
else if (gSP.textureTile[_t]->shifts > 0)
|
||||
_pTexture->shiftScaleS /= (f32)(1 << gSP.textureTile[_t]->shifts);
|
||||
|
||||
if (gSP.textureTile[_t]->shiftt > 10)
|
||||
_pTexture->shiftScaleT = (f32)(1 << (16 - gSP.textureTile[_t]->shiftt));
|
||||
else if (gSP.textureTile[_t]->shiftt > 0)
|
||||
_pTexture->shiftScaleT /= (f32)(1 << gSP.textureTile[_t]->shiftt);
|
||||
}
|
||||
|
||||
void TextureCache::update(u32 _t)
|
||||
{
|
||||
if (config.textureFilter.txHiresEnable != 0 && config.textureFilter.txDump != 0) {
|
||||
|
@ -1291,7 +1274,6 @@ void TextureCache::update(u32 _t)
|
|||
}
|
||||
|
||||
if (current[_t] != NULL && current[_t]->crc == crc) {
|
||||
_updateShiftScale(_t, current[_t]);
|
||||
activateTexture(_t, current[_t]);
|
||||
return;
|
||||
}
|
||||
|
@ -1313,7 +1295,6 @@ void TextureCache::update(u32 _t)
|
|||
(current.size == gSP.textureTile[_t]->size)
|
||||
);
|
||||
|
||||
_updateShiftScale(_t, ¤t);
|
||||
activateTexture(_t, ¤t);
|
||||
m_hits++;
|
||||
return;
|
||||
|
@ -1365,11 +1346,28 @@ void TextureCache::update(u32 _t)
|
|||
pCurrent->offsetS = 0.5f;
|
||||
pCurrent->offsetT = 0.5f;
|
||||
|
||||
_updateShiftScale(_t, pCurrent);
|
||||
|
||||
_load(_t, pCurrent);
|
||||
activateTexture( _t, pCurrent );
|
||||
|
||||
m_cachedBytes += pCurrent->textureBytes;
|
||||
current[_t] = pCurrent;
|
||||
}
|
||||
|
||||
void getTextureShiftScale(u32 t, const TextureCache & cache, f32 & shiftScaleS, f32 & shiftScaleT)
|
||||
{
|
||||
if (gSP.textureTile[t]->textureMode != TEXTUREMODE_NORMAL) {
|
||||
shiftScaleS = cache.current[t]->shiftScaleS;
|
||||
shiftScaleT = cache.current[t]->shiftScaleT;
|
||||
return;
|
||||
}
|
||||
|
||||
if (gSP.textureTile[t]->shifts > 10)
|
||||
shiftScaleS = (f32)(1 << (16 - gSP.textureTile[t]->shifts));
|
||||
else if (gSP.textureTile[t]->shifts > 0)
|
||||
shiftScaleS /= (f32)(1 << gSP.textureTile[t]->shifts);
|
||||
|
||||
if (gSP.textureTile[t]->shiftt > 10)
|
||||
shiftScaleT = (f32)(1 << (16 - gSP.textureTile[t]->shiftt));
|
||||
else if (gSP.textureTile[t]->shiftt > 0)
|
||||
shiftScaleT /= (f32)(1 << gSP.textureTile[t]->shiftt);
|
||||
}
|
||||
|
|
|
@ -89,6 +89,8 @@ private:
|
|||
bool m_toggleDumpTex;
|
||||
};
|
||||
|
||||
void getTextureShiftScale(u32 tile, const TextureCache & cache, f32 & shiftScaleS, f32 & shiftScaleT);
|
||||
|
||||
inline TextureCache & textureCache()
|
||||
{
|
||||
return TextureCache::get();
|
||||
|
|
Loading…
Reference in New Issue
Block a user