Search
lxdream.org :: lxdream/src/pvr2/scene.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/pvr2/scene.c
changeset 847:2089244671d2
prev827:d333f4248727
next863:a5e5310061e2
author nkeynes
date Mon Sep 08 11:23:32 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change As long as we've broken save-state compatibility anyway, remove the two FIXME
padding words, and bump the version number
file annotate diff log raw
1.1 --- a/src/pvr2/scene.c Sun Aug 24 02:57:15 2008 +0000
1.2 +++ b/src/pvr2/scene.c Mon Sep 08 11:23:32 2008 +0000
1.3 @@ -55,8 +55,15 @@
1.4 return temp.f;
1.5 }
1.6
1.7 -
1.8 -
1.9 +static float parse_fog_density( uint32_t value )
1.10 +{
1.11 + union {
1.12 + uint32_t i;
1.13 + float f;
1.14 + } u;
1.15 + u.i = (((value+127)&0xFF)<<23)|((value & 0xFF00)<<7);
1.16 + return u.f;
1.17 +}
1.18
1.19
1.20 struct pvr2_scene_struct pvr2_scene;
1.21 @@ -245,7 +252,6 @@
1.22 unpack_bgra(*data.ival++, vert->rgba);
1.23 if( POLY1_SPECULAR(poly1) ) {
1.24 unpack_bgra(*data.ival++, vert->offset_rgba);
1.25 - vert->offset_rgba[3] = 1.0;
1.26 } else {
1.27 vert->offset_rgba[0] = 0.0;
1.28 vert->offset_rgba[1] = 0.0;
1.29 @@ -255,7 +261,6 @@
1.30
1.31 if( force_alpha ) {
1.32 vert->rgba[3] = 1.0;
1.33 - vert->offset_rgba[3] = 1.0;
1.34 }
1.35 }
1.36
1.37 @@ -329,6 +334,61 @@
1.38 }
1.39 }
1.40
1.41 +static float scene_compute_lut_fog_vertex( float z, float fog_density, float fog_table[][2] )
1.42 +{
1.43 + union {
1.44 + uint32_t i;
1.45 + float f;
1.46 + } v;
1.47 + v.f = z * fog_density;
1.48 + if( v.f < 1.0 ) v.f = 1.0;
1.49 + else if( v.f > 255.9999 ) v.f = 255.9999;
1.50 +
1.51 + uint32_t index = ((v.i >> 18) & 0x0F)|((v.i>>19)&0x70);
1.52 + return fog_table[index][0];
1.53 +}
1.54 +
1.55 +/**
1.56 + * Compute the fog coefficients for all polygons using lookup-table fog. It's
1.57 + * a little more convenient to do this as a separate pass, since we don't have
1.58 + * to worry about computed vertexes.
1.59 + */
1.60 +static void scene_compute_lut_fog( )
1.61 +{
1.62 + int i,j;
1.63 +
1.64 + float fog_density = parse_fog_density(MMIO_READ( PVR2, RENDER_FOGCOEFF ));
1.65 + float fog_table[128][2];
1.66 +
1.67 + /* Parse fog table out into floating-point format */
1.68 + for( i=0; i<128; i++ ) {
1.69 + uint32_t ent = MMIO_READ( PVR2, RENDER_FOGTABLE + (i<<2) );
1.70 + fog_table[i][0] = ((float)(((ent&0x0000FF00)>>8) + 1)) / 256.0;
1.71 + fog_table[i][1] = ((float)((ent&0x000000FF) + 1)) / 256.0;
1.72 + }
1.73 +
1.74 +
1.75 + for( i=0; i<pvr2_scene.poly_count; i++ ) {
1.76 + int mode = POLY2_FOG_MODE(pvr2_scene.poly_array[i].context[1]);
1.77 + if( mode == PVR2_POLY_FOG_LOOKUP ) {
1.78 + uint32_t index = pvr2_scene.poly_array[i].vertex_index;
1.79 + for( j=0; j<=pvr2_scene.poly_array[i].vertex_count; j++ ) {
1.80 + pvr2_scene.vertex_array[index+j].offset_rgba[3] =
1.81 + scene_compute_lut_fog_vertex( pvr2_scene.vertex_array[index+j].z, fog_density, fog_table );
1.82 + }
1.83 + } else if( mode == PVR2_POLY_FOG_LOOKUP2 ) {
1.84 + uint32_t index = pvr2_scene.poly_array[i].vertex_index;
1.85 + for( j=0; j<=pvr2_scene.poly_array[i].vertex_count; j++ ) {
1.86 + pvr2_scene.vertex_array[index+j].rgba[0] = pvr2_scene.fog_lut_colour[0];
1.87 + pvr2_scene.vertex_array[index+j].rgba[1] = pvr2_scene.fog_lut_colour[1];
1.88 + pvr2_scene.vertex_array[index+j].rgba[2] = pvr2_scene.fog_lut_colour[2];
1.89 + pvr2_scene.vertex_array[index+j].rgba[3] =
1.90 + scene_compute_lut_fog_vertex( pvr2_scene.vertex_array[index+j].z, fog_density, fog_table );
1.91 + }
1.92 + }
1.93 + }
1.94 +}
1.95 +
1.96 static void scene_add_vertexes( pvraddr_t poly_idx, int vertex_length,
1.97 gboolean is_modified )
1.98 {
1.99 @@ -628,6 +688,12 @@
1.100 */
1.101 pvr2_scene.bounds[1] *= 2;
1.102 }
1.103 +
1.104 + uint32_t fog_col = MMIO_READ( PVR2, RENDER_FOGTBLCOL );
1.105 + unpack_bgra( fog_col, pvr2_scene.fog_lut_colour );
1.106 + fog_col = MMIO_READ( PVR2, RENDER_FOGVRTCOL );
1.107 + unpack_bgra( fog_col, pvr2_scene.fog_vert_colour );
1.108 +
1.109 uint32_t *tilebuffer = (uint32_t *)(video_base + MMIO_READ( PVR2, RENDER_TILEBASE ));
1.110 uint32_t *segment = tilebuffer;
1.111 pvr2_scene.segment_list = (struct tile_segment *)tilebuffer;
1.112 @@ -688,6 +754,7 @@
1.113 } while( (control & SEGMENT_END) == 0 );
1.114
1.115 scene_extract_background();
1.116 + scene_compute_lut_fog();
1.117
1.118 vertex_buffer_unmap();
1.119 }
.