--- a/src/pvr2/scene.c Sun Aug 24 02:57:15 2008 +0000 +++ b/src/pvr2/scene.c Mon Sep 08 11:23:32 2008 +0000 @@ -55,8 +55,15 @@ return temp.f; } - - +static float parse_fog_density( uint32_t value ) +{ + union { + uint32_t i; + float f; + } u; + u.i = (((value+127)&0xFF)<<23)|((value & 0xFF00)<<7); + return u.f; +} struct pvr2_scene_struct pvr2_scene; @@ -245,7 +252,6 @@ unpack_bgra(*data.ival++, vert->rgba); if( POLY1_SPECULAR(poly1) ) { unpack_bgra(*data.ival++, vert->offset_rgba); - vert->offset_rgba[3] = 1.0; } else { vert->offset_rgba[0] = 0.0; vert->offset_rgba[1] = 0.0; @@ -255,7 +261,6 @@ if( force_alpha ) { vert->rgba[3] = 1.0; - vert->offset_rgba[3] = 1.0; } } @@ -329,6 +334,61 @@ } } +static float scene_compute_lut_fog_vertex( float z, float fog_density, float fog_table[][2] ) +{ + union { + uint32_t i; + float f; + } v; + v.f = z * fog_density; + if( v.f < 1.0 ) v.f = 1.0; + else if( v.f > 255.9999 ) v.f = 255.9999; + + uint32_t index = ((v.i >> 18) & 0x0F)|((v.i>>19)&0x70); + return fog_table[index][0]; +} + +/** + * Compute the fog coefficients for all polygons using lookup-table fog. It's + * a little more convenient to do this as a separate pass, since we don't have + * to worry about computed vertexes. + */ +static void scene_compute_lut_fog( ) +{ + int i,j; + + float fog_density = parse_fog_density(MMIO_READ( PVR2, RENDER_FOGCOEFF )); + float fog_table[128][2]; + + /* Parse fog table out into floating-point format */ + for( i=0; i<128; i++ ) { + uint32_t ent = MMIO_READ( PVR2, RENDER_FOGTABLE + (i<<2) ); + fog_table[i][0] = ((float)(((ent&0x0000FF00)>>8) + 1)) / 256.0; + fog_table[i][1] = ((float)((ent&0x000000FF) + 1)) / 256.0; + } + + + for( i=0; i