rasterize: simplify handling of non-textured polys: it seems that everything is logical if the sampler returns opaque white and everything else proceeds as normal.

This commit is contained in:
zeromus 2010-06-28 07:24:20 +00:00
parent ef767f03c3
commit f810403c92
3 changed files with 31 additions and 32 deletions

View File

@ -73,6 +73,9 @@
//produce a 32bpp color from a DS RGB16
#define RGB16TO32(col,alpha) (((alpha)<<24) | ((((col) & 0x7C00)>>7)<<16) | ((((col) & 0x3E0)>>2)<<8) | (((col) & 0x1F)<<3))
//produce a 32bpp color from a ds RGB15, using a table
#define RGB15TO32_NOALPHA(col) ( color_15bit_to_24bit[col&0x7FFF] )
//produce a 32bpp color from a ds RGB15 plus an 8bit alpha, using a table
#define RGB15TO32(col,alpha8) ( ((alpha8)<<24) | color_15bit_to_24bit[col&0x7FFF] )

View File

@ -365,6 +365,7 @@ public:
{
Sampler() {}
bool enabled;
int width, height;
int wmask, hmask;
int wrap;
@ -379,6 +380,7 @@ public:
wmask = width-1;
hmask = height-1;
wrap = (texParam>>16)&0xF;
enabled = gfx3d.renderState.enableTexturing && (texFormat!=0);
}
FORCEINLINE void clamp(int &val, const int size, const int sizemask){
@ -430,6 +432,9 @@ public:
FORCEINLINE FragmentColor sample(float u, float v)
{
static FragmentColor white = MakeFragmentColor(63,63,63,31);
if(!sampler.enabled) return white;
//finally, we can use floor here. but, it is slower than we want.
//the best solution is probably to wait until the pipeline is full of fixed point
s32 iu = s32floor(u);
@ -491,33 +496,24 @@ public:
v = shader.invv*shader.w;
texColor = sample(u,v);
FragmentColor toonColor = engine->toonTable[shader.materialColor.r>>1];
if(sampler.texFormat == 0)
if(gfx3d.renderState.shading == GFX3D_State::HIGHLIGHT)
{
//if no texture is set then we dont need to modulate texture with toon
//but rather just use toon directly
dst = toonColor;
dst.a = shader.materialColor.a;
dst.r = modulate_table[texColor.r][shader.materialColor.r];
dst.g = modulate_table[texColor.g][shader.materialColor.r];
dst.b = modulate_table[texColor.b][shader.materialColor.r];
dst.a = modulate_table[GFX3D_5TO6(texColor.a)][GFX3D_5TO6(shader.materialColor.a)]>>1;
dst.r = min<u8>(63, (dst.r + toonColor.r));
dst.g = min<u8>(63, (dst.g + toonColor.g));
dst.b = min<u8>(63, (dst.b + toonColor.b));
}
else
{
if(gfx3d.renderState.shading == GFX3D_State::HIGHLIGHT)
{
dst.r = modulate_table[texColor.r][shader.materialColor.r];
dst.g = modulate_table[texColor.g][shader.materialColor.r];
dst.b = modulate_table[texColor.b][shader.materialColor.r];
dst.a = modulate_table[GFX3D_5TO6(texColor.a)][GFX3D_5TO6(shader.materialColor.a)]>>1;
dst.r = min<u8>(63, (dst.r + toonColor.r));
dst.g = min<u8>(63, (dst.g + toonColor.g));
dst.b = min<u8>(63, (dst.b + toonColor.b));
}
else
{
dst.r = modulate_table[texColor.r][toonColor.r];
dst.g = modulate_table[texColor.g][toonColor.g];
dst.b = modulate_table[texColor.b][toonColor.b];
dst.a = modulate_table[GFX3D_5TO6(texColor.a)][GFX3D_5TO6(shader.materialColor.a)]>>1;
}
dst.r = modulate_table[texColor.r][toonColor.r];
dst.g = modulate_table[texColor.g][toonColor.g];
dst.b = modulate_table[texColor.b][toonColor.b];
dst.a = modulate_table[GFX3D_5TO6(texColor.a)][GFX3D_5TO6(shader.materialColor.a)]>>1;
}
}
@ -526,20 +522,12 @@ public:
//is this right? only with the material color?
dst = shader.materialColor;
break;
case 4: //our own special mode which only uses the material color (for when texturing is disabled)
dst = shader.materialColor;
break;
}
}
void setupShader(u32 polyattr)
{
shader.mode = (polyattr>>4)&0x3;
//if there is no texture set, then set to the mode which doesnt even use a texture
//(no texture makes sense for toon/highlight mode)
if(sampler.texFormat == 0 && (shader.mode == 0 || shader.mode == 1))
shader.mode = 4;
}
FORCEINLINE void pixel(int adr,float r, float g, float b, float invu, float invv, float w, float z)
@ -1157,13 +1145,14 @@ void SoftRasterizerEngine::updateToonTable()
//convert the toon colors
for(int i=0;i<32;i++) {
#ifdef WORDS_BIGENDIAN
u32 u32temp = RGB15TO32(gfx3d.renderState.u16ToonTable[i]);
u32 u32temp = RGB15TO32_NOALPHA(gfx3d.renderState.u16ToonTable[i]);
toonTable[i].r = (u32temp >> 2) & 0x3F;
toonTable[i].g = (u32temp >> 10) & 0x3F;
toonTable[i].b = (u32temp >> 18) & 0x3F;
#else
toonTable[i].color = (RGB15TO32_NOALPHA(gfx3d.renderState.u16ToonTable[i])>>2)&0x3F3F3F3F;
#endif
//printf("%d %d %d %d\n",toonTable[i].r,toonTable[i].g,toonTable[i].b,toonTable[i].a);
}
}

View File

@ -36,6 +36,13 @@ union FragmentColor {
};
};
inline FragmentColor MakeFragmentColor(u8 r, u8 g,u8 b,u8 a)
{
FragmentColor ret;
ret.r = r; ret.g = g; ret.b = b; ret.a = a;
return ret;
}
struct Fragment
{
u32 depth;