@@ -376,6 +376,12 @@ static void gpuGP0Cmd_0xEx(gpu_unai_t &gpu_unai, u32 cmd_word)
376
376
377
377
#include " ../gpulib/gpu_timing.h"
378
378
379
+ // Strip lower 3 bits of each color and determine if lighting should be used:
380
+ static inline bool need_lighting (u32 rgb_raw)
381
+ {
382
+ return (rgb_raw & HTOLE32 (0xF8F8F8 )) != HTOLE32 (0x808080 );
383
+ }
384
+
379
385
static inline void textured_sprite (int &cpu_cycles_sum, int &cpu_cycles)
380
386
{
381
387
u32 PRIM = le32_to_u32 (gpu_unai.PacketBuffer .U4 [0 ]) >> 24 ;
@@ -395,9 +401,7 @@ static inline void textured_sprite(int &cpu_cycles_sum, int &cpu_cycles)
395
401
// NOTE: I've changed all textured sprite draw commands here and
396
402
// elsewhere to use proper behavior, but left poly commands
397
403
// alone, I don't want to slow rendering down too much. (TODO)
398
- // if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F))
399
- // Strip lower 3 bits of each color and determine if lighting should be used:
400
- if ((le32_raw (gpu_unai.PacketBuffer .U4 [0 ]) & HTOLE32 (0xF8F8F8 )) != HTOLE32 (0x808080 ))
404
+ if (need_lighting (le32_raw (gpu_unai.PacketBuffer .U4 [0 ])))
401
405
driver_idx |= Lighting;
402
406
PS driver = gpuSpriteDrivers[driver_idx];
403
407
PtrUnion packet = { .ptr = (void *)&gpu_unai.PacketBuffer };
@@ -539,13 +543,22 @@ int do_cmd_list(u32 *list_, int list_len,
539
543
// this is an untextured poly, so CF_LIGHT (texture blend)
540
544
// shouldn't apply. Until the original array of template
541
545
// instantiation ptrs is fixed, we're stuck with this. (TODO)
546
+ u8 gouraud = 129 ;
547
+ u32 xor_ = 0 , rgb0 = le32_raw (gpu_unai.PacketBuffer .U4 [0 ]);
548
+ for (i = 1 ; i < 3 ; i++)
549
+ xor_ |= rgb0 ^ le32_raw (gpu_unai.PacketBuffer .U4 [i * 2 ]);
550
+ if ((xor_ & HTOLE32 (0xf8f8f8 )) == 0 )
551
+ gouraud = 0 ;
542
552
PP driver = gpuPolySpanDrivers[
543
553
// (gpu_unai.blit_mask?1024:0) |
544
554
Dithering |
545
555
Blending_Mode |
546
- gpu_unai.Masking | Blending | 129 | gpu_unai.PixelMSB
556
+ gpu_unai.Masking | Blending | gouraud | gpu_unai.PixelMSB
547
557
];
548
- gpuDrawPolyG (packet, driver, false );
558
+ if (gouraud)
559
+ gpuDrawPolyG (packet, driver, false );
560
+ else
561
+ gpuDrawPolyF (packet, driver, false , POLYTYPE_G);
549
562
gput_sum (cpu_cycles_sum, cpu_cycles, gput_poly_base_g ());
550
563
} break ;
551
564
@@ -555,13 +568,28 @@ int do_cmd_list(u32 *list_, int list_len,
555
568
case 0x37 : { // Gouraud-shaded, textured 3-pt poly
556
569
gpuSetCLUT (le32_to_u32 (gpu_unai.PacketBuffer .U4 [2 ]) >> 16 );
557
570
gpuSetTexture (le32_to_u32 (gpu_unai.PacketBuffer .U4 [5 ]) >> 16 );
571
+ u8 lighting = Lighting;
572
+ u8 gouraud = lighting ? (1 <<7 ) : 0 ;
573
+ if (lighting) {
574
+ u32 xor_ = 0 , rgb0 = le32_raw (gpu_unai.PacketBuffer .U4 [0 ]);
575
+ for (i = 1 ; i < 3 ; i++)
576
+ xor_ |= rgb0 ^ le32_raw (gpu_unai.PacketBuffer .U4 [i * 3 ]);
577
+ if ((xor_ & HTOLE32 (0xf8f8f8 )) == 0 ) {
578
+ gouraud = 0 ;
579
+ if (!need_lighting (rgb0))
580
+ lighting = 0 ;
581
+ }
582
+ }
558
583
PP driver = gpuPolySpanDrivers[
559
584
// (gpu_unai.blit_mask?1024:0) |
560
585
Dithering |
561
586
Blending_Mode | gpu_unai.TEXT_MODE |
562
- gpu_unai.Masking | Blending | ((Lighting)? 129 : 0 ) | gpu_unai.PixelMSB
587
+ gpu_unai.Masking | Blending | gouraud | lighting | gpu_unai.PixelMSB
563
588
];
564
- gpuDrawPolyGT (packet, driver, false );
589
+ if (gouraud)
590
+ gpuDrawPolyGT (packet, driver, false ); // is_quad = true
591
+ else
592
+ gpuDrawPolyFT (packet, driver, false , POLYTYPE_GT);
565
593
gput_sum (cpu_cycles_sum, cpu_cycles, gput_poly_base_gt ());
566
594
} break ;
567
595
@@ -570,13 +598,22 @@ int do_cmd_list(u32 *list_, int list_len,
570
598
case 0x3A :
571
599
case 0x3B : { // Gouraud-shaded 4-pt poly
572
600
// See notes regarding '129' for 0x30..0x33 further above -senquack
601
+ u8 gouraud = 129 ;
602
+ u32 xor_ = 0 , rgb0 = le32_raw (gpu_unai.PacketBuffer .U4 [0 ]);
603
+ for (i = 1 ; i < 4 ; i++)
604
+ xor_ |= rgb0 ^ le32_raw (gpu_unai.PacketBuffer .U4 [i * 2 ]);
605
+ if ((xor_ & HTOLE32 (0xf8f8f8 )) == 0 )
606
+ gouraud = 0 ;
573
607
PP driver = gpuPolySpanDrivers[
574
608
// (gpu_unai.blit_mask?1024:0) |
575
609
Dithering |
576
610
Blending_Mode |
577
- gpu_unai.Masking | Blending | 129 | gpu_unai.PixelMSB
611
+ gpu_unai.Masking | Blending | gouraud | gpu_unai.PixelMSB
578
612
];
579
- gpuDrawPolyG (packet, driver, true ); // is_quad = true
613
+ if (gouraud)
614
+ gpuDrawPolyG (packet, driver, true ); // is_quad = true
615
+ else
616
+ gpuDrawPolyF (packet, driver, true , POLYTYPE_G);
580
617
gput_sum (cpu_cycles_sum, cpu_cycles, gput_quad_base_g ());
581
618
} break ;
582
619
@@ -598,13 +635,28 @@ int do_cmd_list(u32 *list_, int list_len,
598
635
break ;
599
636
}
600
637
gpuSetCLUT (le32_to_u32 (gpu_unai.PacketBuffer .U4 [2 ]) >> 16 );
638
+ u8 lighting = Lighting;
639
+ u8 gouraud = lighting ? (1 <<7 ) : 0 ;
640
+ if (lighting) {
641
+ u32 xor_ = 0 , rgb0 = le32_raw (gpu_unai.PacketBuffer .U4 [0 ]);
642
+ for (i = 1 ; i < 4 ; i++)
643
+ xor_ |= rgb0 ^ le32_raw (gpu_unai.PacketBuffer .U4 [i * 3 ]);
644
+ if ((xor_ & HTOLE32 (0xf8f8f8 )) == 0 ) {
645
+ gouraud = 0 ;
646
+ if (!need_lighting (rgb0))
647
+ lighting = 0 ;
648
+ }
649
+ }
601
650
PP driver = gpuPolySpanDrivers[
602
651
// (gpu_unai.blit_mask?1024:0) |
603
652
Dithering |
604
653
Blending_Mode | gpu_unai.TEXT_MODE |
605
- gpu_unai.Masking | Blending | ((Lighting)? 129 : 0 ) | gpu_unai.PixelMSB
654
+ gpu_unai.Masking | Blending | gouraud | lighting | gpu_unai.PixelMSB
606
655
];
607
- gpuDrawPolyGT (packet, driver, true ); // is_quad = true
656
+ if (gouraud)
657
+ gpuDrawPolyGT (packet, driver, true ); // is_quad = true
658
+ else
659
+ gpuDrawPolyFT (packet, driver, true , POLYTYPE_GT);
608
660
gput_sum (cpu_cycles_sum, cpu_cycles, gput_quad_base_gt ());
609
661
} break ;
610
662
0 commit comments