Possible fix for S3TC Texture Decoding (Grass in ZWW is now properly alpha tested), and some code formatting cleanup.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3224 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
omegadox 2009-05-13 23:37:26 +00:00
parent 158fcaf889
commit 136dc16f94
5 changed files with 124 additions and 98 deletions

View File

@ -1,4 +1,4 @@
// Copyright (C) 2003-2008 Dolphin Project. // Copyright (C) 2003-2009 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by

View File

@ -15,13 +15,11 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "Common.h"
#include "Profiler.h"
#include <cmath> #include <cmath>
#include "Common.h"
#include "Profiler.h"
#include "Statistics.h" #include "Statistics.h"
#include "PixelShaderManager.h" #include "PixelShaderManager.h"
#include "VideoCommon.h" #include "VideoCommon.h"
@ -67,36 +65,42 @@ void PixelShaderManager::Shutdown()
void PixelShaderManager::SetConstants() void PixelShaderManager::SetConstants()
{ {
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i)
if (s_nColorsChanged[i]) { {
if (s_nColorsChanged[i])
{
int baseind = i ? C_KCOLORS : C_COLORS; int baseind = i ? C_KCOLORS : C_COLORS;
for (int j = 0; j < 4; ++j) { for (int j = 0; j < 4; ++j)
if (s_nColorsChanged[i] & (1 << j)) { {
if (s_nColorsChanged[i] & (1 << j))
SetPSConstant4fv(baseind+j, &lastRGBAfull[i][j][0]); SetPSConstant4fv(baseind+j, &lastRGBAfull[i][j][0]);
} }
}
s_nColorsChanged[i] = 0; s_nColorsChanged[i] = 0;
} }
} }
if (s_nTexDimsChanged) { if (s_nTexDimsChanged)
for (int i = 0; i < 8; ++i) { {
if (s_nTexDimsChanged & (1<<i)) { for (int i = 0; i < 8; ++i)
{
if (s_nTexDimsChanged & (1<<i))
SetPSTextureDims(i); SetPSTextureDims(i);
} }
}
s_nTexDimsChanged = 0; s_nTexDimsChanged = 0;
} }
if (s_bAlphaChanged) { if (s_bAlphaChanged)
{
SetPSConstant4f(C_ALPHA, (lastAlpha&0xff)/255.0f, ((lastAlpha>>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f); SetPSConstant4f(C_ALPHA, (lastAlpha&0xff)/255.0f, ((lastAlpha>>8)&0xff)/255.0f, 0, ((lastAlpha>>16)&0xff)/255.0f);
s_bAlphaChanged = false; s_bAlphaChanged = false;
} }
if (s_bZTextureTypeChanged) { if (s_bZTextureTypeChanged)
{
static float ffrac = 255.0f/256.0f; static float ffrac = 255.0f/256.0f;
float ftemp[4]; float ftemp[4];
switch (bpmem.ztex2.type) { switch (bpmem.ztex2.type)
{
case 0: case 0:
// 8 bits // 8 bits
// this breaks the menu in SSBM when it is set correctly to // this breaks the menu in SSBM when it is set correctly to
@ -116,19 +120,23 @@ void PixelShaderManager::SetConstants()
s_bZTextureTypeChanged = false; s_bZTextureTypeChanged = false;
} }
if (s_bZBiasChanged || s_bDepthRangeChanged) { if (s_bZBiasChanged || s_bDepthRangeChanged)
{
//ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias); //ERROR_LOG("pixel=%x,%x, bias=%x\n", bpmem.zcontrol.pixel_format, bpmem.ztex2.type, lastZBias);
SetPSConstant4f(C_ZBIAS+1, lastDepthRange[0] / 16777216.0f, lastDepthRange[1] / 16777216.0f, 0, (float)( (((int)lastZBias<<8)>>8))/16777216.0f); SetPSConstant4f(C_ZBIAS+1, lastDepthRange[0] / 16777216.0f, lastDepthRange[1] / 16777216.0f, 0, (float)( (((int)lastZBias<<8)>>8))/16777216.0f);
s_bZBiasChanged = s_bDepthRangeChanged = false; s_bZBiasChanged = s_bDepthRangeChanged = false;
} }
// indirect incoming texture scales // indirect incoming texture scales
if (s_nIndTexScaleChanged) { if (s_nIndTexScaleChanged)
{
// set as two sets of vec4s, each containing S and T of two ind stages. // set as two sets of vec4s, each containing S and T of two ind stages.
float f[8]; float f[8];
if (s_nIndTexScaleChanged & 0x03) { if (s_nIndTexScaleChanged & 0x03)
for (u32 i = 0; i < 2; ++i) { {
for (u32 i = 0; i < 2; ++i)
{
f[2 * i] = bpmem.texscale[0].getScaleS(i & 1); f[2 * i] = bpmem.texscale[0].getScaleS(i & 1);
f[2 * i + 1] = bpmem.texscale[0].getScaleT(i & 1); f[2 * i + 1] = bpmem.texscale[0].getScaleT(i & 1);
PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]); PRIM_LOG("tex indscale%d: %f %f\n", i, f[2 * i], f[2 * i + 1]);
@ -148,9 +156,12 @@ void PixelShaderManager::SetConstants()
s_nIndTexScaleChanged = 0; s_nIndTexScaleChanged = 0;
} }
if (s_nIndTexMtxChanged) { if (s_nIndTexMtxChanged)
for (int i = 0; i < 3; ++i) { {
if (s_nIndTexMtxChanged & (1 << i)) { for (int i = 0; i < 3; ++i)
{
if (s_nIndTexMtxChanged & (1 << i))
{
int scale = ((u32)bpmem.indmtx[i].col0.s0 << 0) | int scale = ((u32)bpmem.indmtx[i].col0.s0 << 0) |
((u32)bpmem.indmtx[i].col1.s1 << 2) | ((u32)bpmem.indmtx[i].col1.s1 << 2) |
((u32)bpmem.indmtx[i].col2.s2 << 4); ((u32)bpmem.indmtx[i].col2.s2 << 4);
@ -178,12 +189,14 @@ void PixelShaderManager::SetConstants()
s_nIndTexMtxChanged = 0; s_nIndTexMtxChanged = 0;
} }
if (s_bFogColorChanged) { if (s_bFogColorChanged)
{
SetPSConstant4f(C_FOG, bpmem.fog.color.r / 255.0f, bpmem.fog.color.g / 255.0f, bpmem.fog.color.b / 255.0f, 0); SetPSConstant4f(C_FOG, bpmem.fog.color.r / 255.0f, bpmem.fog.color.g / 255.0f, bpmem.fog.color.b / 255.0f, 0);
s_bFogColorChanged = false; s_bFogColorChanged = false;
} }
if (s_bFogParamChanged) { if (s_bFogParamChanged)
{
float a = bpmem.fog.a.GetA() * ((float)(1 << bpmem.fog.b_shift)); float a = bpmem.fog.a.GetA() * ((float)(1 << bpmem.fog.b_shift));
float b = ((float)bpmem.fog.b_magnitude / 8388638) * ((float)(1 << (bpmem.fog.b_shift - 1))); float b = ((float)bpmem.fog.b_magnitude / 8388638) * ((float)(1 << (bpmem.fog.b_shift - 1)));
SetPSConstant4f(C_FOG + 1, a, b, bpmem.fog.c_proj_fsel.GetC(), 0); SetPSConstant4f(C_FOG + 1, a, b, bpmem.fog.c_proj_fsel.GetC(), 0);
@ -199,14 +212,16 @@ void PixelShaderManager::SetPSTextureDims(int texid)
// pow 2 textures - texdims.xy are reciprocals of the real texture dimensions // pow 2 textures - texdims.xy are reciprocals of the real texture dimensions
// both - texdims.zw are the scaled dimensions // both - texdims.zw are the scaled dimensions
float fdims[4]; float fdims[4];
if (s_texturemask & (1<<texid)) { if (s_texturemask & (1 << texid))
{
TCoordInfo& tc = bpmem.texcoords[texid]; TCoordInfo& tc = bpmem.texcoords[texid];
fdims[0] = (float)(lastTexDims[texid] & 0xffff); fdims[0] = (float)(lastTexDims[texid] & 0xffff);
fdims[1] = (float)((lastTexDims[texid] >> 16) & 0xfff); fdims[1] = (float)((lastTexDims[texid] >> 16) & 0xfff);
fdims[2] = (float)(tc.s.scale_minus_1 + 1)*lastCustomTexScale[texid][0]; fdims[2] = (float)(tc.s.scale_minus_1 + 1)*lastCustomTexScale[texid][0];
fdims[3] = (float)(tc.t.scale_minus_1 + 1)*lastCustomTexScale[texid][1]; fdims[3] = (float)(tc.t.scale_minus_1 + 1)*lastCustomTexScale[texid][1];
} }
else { else
{
TCoordInfo& tc = bpmem.texcoords[texid]; TCoordInfo& tc = bpmem.texcoords[texid];
fdims[0] = 1.0f / (float)(lastTexDims[texid] & 0xffff); fdims[0] = 1.0f / (float)(lastTexDims[texid] & 0xffff);
fdims[1] = 1.0f / (float)((lastTexDims[texid] >> 16) & 0xfff); fdims[1] = 1.0f / (float)((lastTexDims[texid] >> 16) & 0xfff);
@ -235,7 +250,8 @@ void PixelShaderManager::SetColorChanged(int type, int num)
void PixelShaderManager::SetAlpha(const AlphaFunc& alpha) void PixelShaderManager::SetAlpha(const AlphaFunc& alpha)
{ {
if ((alpha.hex & 0xffff) != lastAlpha) { if ((alpha.hex & 0xffff) != lastAlpha)
{
lastAlpha = (lastAlpha & ~0xffff) | (alpha.hex & 0xffff); lastAlpha = (lastAlpha & ~0xffff) | (alpha.hex & 0xffff);
s_bAlphaChanged = true; s_bAlphaChanged = true;
} }
@ -243,7 +259,8 @@ void PixelShaderManager::SetAlpha(const AlphaFunc& alpha)
void PixelShaderManager::SetDestAlpha(const ConstantAlpha& alpha) void PixelShaderManager::SetDestAlpha(const ConstantAlpha& alpha)
{ {
if (alpha.alpha != (lastAlpha >> 16)) { if (alpha.alpha != (lastAlpha >> 16))
{
lastAlpha = (lastAlpha & ~0xff0000) | ((alpha.hex & 0xff) << 16); lastAlpha = (lastAlpha & ~0xff0000) | ((alpha.hex & 0xff) << 16);
s_bAlphaChanged = true; s_bAlphaChanged = true;
} }
@ -252,7 +269,8 @@ void PixelShaderManager::SetDestAlpha(const ConstantAlpha& alpha)
void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt) void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wraps, u32 wrapt)
{ {
u32 wh = width | (height << 16) | (wraps << 28) | (wrapt << 30); u32 wh = width | (height << 16) | (wraps << 28) | (wrapt << 30);
if (lastTexDims[texmapid] != wh) { if (lastTexDims[texmapid] != wh)
{
lastTexDims[texmapid] = wh; lastTexDims[texmapid] = wh;
s_nTexDimsChanged |= 1 << texmapid; s_nTexDimsChanged |= 1 << texmapid;
} }
@ -260,7 +278,8 @@ void PixelShaderManager::SetTexDims(int texmapid, u32 width, u32 height, u32 wra
void PixelShaderManager::SetCustomTexScale(int texmapid, float x, float y) void PixelShaderManager::SetCustomTexScale(int texmapid, float x, float y)
{ {
if (lastCustomTexScale[texmapid][0] != x || lastCustomTexScale[texmapid][1] != y) { if (lastCustomTexScale[texmapid][0] != x || lastCustomTexScale[texmapid][1] != y)
{
s_nTexDimsChanged |= 1 << texmapid; s_nTexDimsChanged |= 1 << texmapid;
lastCustomTexScale[texmapid][0] = x; lastCustomTexScale[texmapid][0] = x;
lastCustomTexScale[texmapid][1] = y; lastCustomTexScale[texmapid][1] = y;
@ -269,7 +288,8 @@ void PixelShaderManager::SetCustomTexScale(int texmapid, float x, float y)
void PixelShaderManager::SetZTextureBias(u32 bias) void PixelShaderManager::SetZTextureBias(u32 bias)
{ {
if (lastZBias != bias) { if (lastZBias != bias)
{
s_bZBiasChanged = true; s_bZBiasChanged = true;
lastZBias = bias; lastZBias = bias;
} }
@ -285,7 +305,8 @@ void PixelShaderManager::SetViewport(float* viewport)
// [4] = yorig + height/2 + 342 // [4] = yorig + height/2 + 342
// [5] = 16777215 * farz // [5] = 16777215 * farz
if(lastDepthRange[0] != viewport[5] || lastDepthRange[1] != viewport[2]) { if(lastDepthRange[0] != viewport[5] || lastDepthRange[1] != viewport[2])
{
lastDepthRange[0] = viewport[5]; lastDepthRange[0] = viewport[5];
lastDepthRange[1] = viewport[2]; lastDepthRange[1] = viewport[2];
@ -309,9 +330,12 @@ void PixelShaderManager::SetZTextureTypeChanged()
void PixelShaderManager::SetTexturesUsed(u32 nonpow2tex) void PixelShaderManager::SetTexturesUsed(u32 nonpow2tex)
{ {
if (s_texturemask != nonpow2tex) { if (s_texturemask != nonpow2tex)
for (int i = 0; i < 8; ++i) { {
if (nonpow2tex & (0x10101 << i)) { for (int i = 0; i < 8; ++i)
{
if (nonpow2tex & (0x10101 << i))
{
// this check was previously implicit, but should it be here? // this check was previously implicit, but should it be here?
if (s_nTexDimsChanged ) if (s_nTexDimsChanged )
s_nTexDimsChanged |= 1 << i; s_nTexDimsChanged |= 1 << i;

View File

@ -15,6 +15,8 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <cmath>
#include "Common.h" #include "Common.h"
//#include "VideoCommon.h" // to get debug logs //#include "VideoCommon.h" // to get debug logs
@ -292,6 +294,7 @@ inline u32 makecol(int r, int g, int b, int a)
void decodeDXTBlock(u32 *dst, const DXTBlock *src, int pitch) void decodeDXTBlock(u32 *dst, const DXTBlock *src, int pitch)
{ {
// S3TC Decoder (Note: GCN decodes differently from PC)
u16 c1 = Common::swap16(src->color1); u16 c1 = Common::swap16(src->color1);
u16 c2 = Common::swap16(src->color2); u16 c2 = Common::swap16(src->color2);
int blue1 = lut5to8[c1 & 0x1F]; int blue1 = lut5to8[c1 & 0x1F];
@ -312,11 +315,10 @@ void decodeDXTBlock(u32 *dst, const DXTBlock *src, int pitch)
} }
else else
{ {
colors[0] = makecol(red1, green1, blue1, 255); colors[0] = makecol(red1, green1, blue1, 255); // Color 1
colors[1] = makecol(red2, green2, blue2, 255); colors[1] = makecol(red2, green2, blue2, 255); // Color 2
colors[2] = makecol((red1+red2)/2, (green1+green2)/2, (blue1+blue2)/2, 255); colors[2] = makecol((int)ceil((float)(red1+red2)/2), (int)ceil((float)(green1+green2)/2), (int)ceil((float)(blue1+blue2)/2), 255); // Average
// Not sure whether to use color 1 or 2 here. Let's try the average :P colors[3] = makecol(red2, green2, blue2, 0); // Color2 but transparent
colors[3] = makecol((red1+red2)/2, (green1+green2)/2, (blue1+blue2)/2, 0); // 0 alpha, transparent
} }
for (int y = 0; y < 4; y++) for (int y = 0; y < 4; y++)

View File

@ -262,7 +262,7 @@ void VertexShaderManager::SetConstants(bool Hack_hack1 ,float Hack_value1 ,bool
g_fProjectionMatrix[8] = 0.0f; g_fProjectionMatrix[8] = 0.0f;
g_fProjectionMatrix[9] = 0.0f; g_fProjectionMatrix[9] = 0.0f;
g_fProjectionMatrix[10] = (Hack_hack1 ? -(Hack_value1 + xfregs.rawProjection[4]) : xfregs.rawProjection[4]); g_fProjectionMatrix[10] = (Hack_hack1 ? -(Hack_value1 + xfregs.rawProjection[4]) : xfregs.rawProjection[4]);
g_fProjectionMatrix[11] = (Hack_hack2 ? -(Hack_value2 + xfregs.rawProjection[5]) : xfregs.rawProjection[5]) + (0.0f); g_fProjectionMatrix[11] = (Hack_hack2 ? -(Hack_value2 + xfregs.rawProjection[5]) : xfregs.rawProjection[5]);
g_fProjectionMatrix[12] = 0.0f; g_fProjectionMatrix[12] = 0.0f;
g_fProjectionMatrix[13] = 0.0f; g_fProjectionMatrix[13] = 0.0f;

View File

@ -646,37 +646,37 @@ void Config::UpdateHack()
switch(g_Config.iPhackvalue) switch(g_Config.iPhackvalue)
{ {
case OGL_HACK_NONE: case OGL_HACK_NONE:
g_Config.bPhackvalue1 = 0; g_Config.bPhackvalue1 = false;
g_Config.bPhackvalue2 = 0; g_Config.bPhackvalue2 = false;
break; break;
case OGL_HACK_ZELDA_TP_BLOOM_HACK: case OGL_HACK_ZELDA_TP_BLOOM_HACK:
g_Config.bPhackvalue1 = 1; g_Config.bPhackvalue1 = true;
break; break;
case OGL_HACK_SUPER_MARIO_GALAXY: case OGL_HACK_SUPER_MARIO_GALAXY:
g_Config.bPhackvalue1 = 1; g_Config.bPhackvalue1 = true;
g_Config.fhackvalue1 = 0.00006f; g_Config.fhackvalue1 = 0.00006f;
g_Config.bPhackvalue2 = 0; g_Config.bPhackvalue2 = false;
break; break;
case OGL_HACK_MARIO_KART_WII: case OGL_HACK_MARIO_KART_WII:
g_Config.bPhackvalue1 = 1; g_Config.bPhackvalue1 = true;
g_Config.fhackvalue1 = 0.00006f; g_Config.fhackvalue1 = 0.00006f;
g_Config.bPhackvalue2 = 0; g_Config.bPhackvalue2 = false;
break; break;
case OGL_HACK_SONIC_AND_THE_BLACK_KNIGHT: case OGL_HACK_SONIC_AND_THE_BLACK_KNIGHT:
g_Config.bPhackvalue1 = 1; g_Config.bPhackvalue1 = true;
g_Config.fhackvalue1 = 0.00002f; g_Config.fhackvalue1 = 0.00002f;
g_Config.bPhackvalue2 = 1; g_Config.bPhackvalue2 = true;
g_Config.fhackvalue2 = 1.999980f; g_Config.fhackvalue2 = 1.999980f;
break; break;
case OGL_HACK_BLEACH_VERSUS_CRUSADE: case OGL_HACK_BLEACH_VERSUS_CRUSADE:
g_Config.bPhackvalue2 = 1; g_Config.bPhackvalue2 = true;
g_Config.fhackvalue2 = 0.5f; g_Config.fhackvalue2 = 0.5f;
g_Config.bPhackvalue1 = 0; g_Config.bPhackvalue1 = false;
break; break;
case OGL_HACK_FINAL_FANTASY_CC_ECHO_OF_TIME: case OGL_HACK_FINAL_FANTASY_CC_ECHO_OF_TIME:
g_Config.bPhackvalue1 = 1; g_Config.bPhackvalue1 = true;
g_Config.fhackvalue1 = 0.8f; g_Config.fhackvalue1 = 0.8f;
g_Config.bPhackvalue2 = 1; g_Config.bPhackvalue2 = true;
g_Config.fhackvalue2 = 1.2f; g_Config.fhackvalue2 = 1.2f;
break; break;
} }