From da602c8e7abf9c3b23374d0a6c0b208cf246ec5d Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sun, 8 Jun 2025 11:04:16 +0200 Subject: [PATCH] Improve sceGuLight* functions --- src/gu/guInternal.c | 31 ------------------------------- src/gu/guInternal.h | 33 --------------------------------- src/gu/pspgu.h | 6 +++--- src/gu/sceGuLight.c | 28 +++++++++++++++++++--------- src/gu/sceGuLightAtt.c | 8 ++++---- src/gu/sceGuLightColor.c | 32 +++++++++++++++++--------------- src/gu/sceGuLightSpot.c | 15 +++++++-------- 7 files changed, 50 insertions(+), 103 deletions(-) diff --git a/src/gu/guInternal.c b/src/gu/guInternal.c index 5619041e..1c70f45e 100644 --- a/src/gu/guInternal.c +++ b/src/gu/guInternal.c @@ -21,34 +21,3 @@ int gu_states; GuDrawBuffer gu_draw_buffer; unsigned int* gu_object_stack[32]; int gu_object_stack_depth; - -GuLightSettings light_settings[4] = -{ - { - 0x18, 0x5f, 0x63, 0x64, - 0x65, 0x6f, 0x70, 0x71, - 0x8f, 0x90, 0x91, 0x7b, - 0x7c, 0x7d, 0x87, 0x8b - }, - - { - 0x19, 0x60, 0x66, 0x67, - 0x68, 0x72, 0x73, 0x74, - 0x92, 0x93, 0x94, 0x7e, - 0x7f, 0x80, 0x88, 0x8c - }, - - { - 0x1a, 0x61, 0x69, 0x6a, - 0x6b, 0x75, 0x76, 0x77, - 0x95, 0x96, 0x97, 0x81, - 0x82, 0x83, 0x89, 0x8d - }, - - { - 0x1b, 0x62, 0x6c, 0x6d, - 0x6e, 0x78, 0x79, 0x7a, - 0x98, 0x99, 0x9a, 0x84, - 0x85, 0x86, 0x8a, 0x8e - } -}; diff --git a/src/gu/guInternal.h b/src/gu/guInternal.h index c76f3a6b..4abf81c2 100644 --- a/src/gu/guInternal.h +++ b/src/gu/guInternal.h @@ -65,37 +65,6 @@ typedef struct int height; } GuDrawBuffer; -typedef struct -{ - /* row 0 */ - - unsigned char enable; // Light enable - unsigned char type; // Light type - unsigned char xpos; // X position - unsigned char ypos; // Y position - - /* row 1 */ - - unsigned char zpos; // Z position - unsigned char xdir; // X direction - unsigned char ydir; // Y direction - unsigned char zdir; // Z direction - - /* row 2 */ - - unsigned char ambient; // Ambient color - unsigned char diffuse; // Diffuse color - unsigned char specular; // Specular color - unsigned char constant; // Constant attenuation - - /* row 3 */ - - unsigned char linear; // Linear attenuation - unsigned char quadratic; // Quadratic attenuation - unsigned char exponent; // Light exponent - unsigned char cutoff; // Light cutoff -} GuLightSettings; - extern GuContext gu_contexts[3]; extern int ge_list_executed[2]; extern void *ge_edram_address; @@ -111,8 +80,6 @@ extern GuDrawBuffer gu_draw_buffer; extern unsigned int *gu_object_stack[]; extern int gu_object_stack_depth; -extern GuLightSettings light_settings[4]; - void callbackSig(int id, void *arg); void callbackFin(int id, void *arg); void _sceGuResetGlobalVariables(); diff --git a/src/gu/pspgu.h b/src/gu/pspgu.h index 56e2670d..eeac81d5 100644 --- a/src/gu/pspgu.h +++ b/src/gu/pspgu.h @@ -273,7 +273,7 @@ extern "C" { #define GU_SPECULAR (4) #define GU_AMBIENT_AND_DIFFUSE (GU_AMBIENT|GU_DIFFUSE) #define GU_DIFFUSE_AND_SPECULAR (GU_DIFFUSE|GU_SPECULAR) -#define GU_UNKNOWN_LIGHT_COMPONENT (8) +#define GU_POWERED_DIFFUSE (8) /* Light modes */ #define GU_SINGLE_COLOR (0) @@ -863,7 +863,7 @@ void sceGuDisable(int state); * Available light components are: * - GU_AMBIENT_AND_DIFFUSE * - GU_DIFFUSE_AND_SPECULAR - * - GU_UNKNOWN_LIGHT_COMPONENT + * - GU_POWERED_DIFFUSE * * @param light - Light index * @param type - Light type @@ -1420,7 +1420,7 @@ void sceGuClutLoad(int num_blocks, const void* cbp); * @param mask - Masks the color index with this bitmask after the shift (0-0xFF) * @param csa - Read-out start location (16-palette units) **/ -void sceGuClutMode(unsigned int cpsm, unsigned int shift, unsigned int mask, unsigned int a3); +void sceGuClutMode(unsigned int cpsm, unsigned int shift, unsigned int mask, unsigned int csa); /** * Set virtual coordinate offset diff --git a/src/gu/sceGuLight.c b/src/gu/sceGuLight.c index 93c475c4..dbe5d3d2 100644 --- a/src/gu/sceGuLight.c +++ b/src/gu/sceGuLight.c @@ -8,17 +8,27 @@ #include "guInternal.h" +#define LTYPE_POWERED_DIFFUSE (2) +#define LTYPE_DIFFUSE_AND_SPECULAR (1) +#define LTYPE_DIFFUSE (0) + void sceGuLight(int light, int type, int components, const ScePspFVector3 *position) { - GuLightSettings* settings = &light_settings[light]; + int offset = light * 3; + int ltype; - sendCommandf(settings->xpos,position->x); - sendCommandf(settings->ypos,position->y); - sendCommandf(settings->zpos,position->z); + if (components == GU_POWERED_DIFFUSE) { + ltype = LTYPE_POWERED_DIFFUSE; + } else if (components == GU_DIFFUSE_AND_SPECULAR) { + ltype = LTYPE_DIFFUSE_AND_SPECULAR; + } else { + ltype = LTYPE_DIFFUSE; + } - int kind = 2; - if (components != 8) - kind = (components^6) < 1 ? 1 : 0; - - sendCommandi(settings->type,((type & 0x03) << 8)|kind); + // Light position + sendCommandf(LIGHT0_X + offset, position->x); + sendCommandf(LIGHT0_Y + offset, position->y); + sendCommandf(LIGHT0_Z + offset, position->z); + // Light type and components + sendCommandi(LIGHT_TYPE0 + light, ((type & GU_AMBIENT_AND_DIFFUSE) << 8) | ltype); } diff --git a/src/gu/sceGuLightAtt.c b/src/gu/sceGuLightAtt.c index cc17e25c..6a8abe9a 100644 --- a/src/gu/sceGuLightAtt.c +++ b/src/gu/sceGuLightAtt.c @@ -10,9 +10,9 @@ void sceGuLightAtt(int light, float atten0, float atten1, float atten2) { - GuLightSettings* settings = &light_settings[light]; + int offset = light * 3; - sendCommandf(settings->constant,atten0); - sendCommandf(settings->linear,atten1); - sendCommandf(settings->quadratic,atten2); + sendCommandf(LIGHT0_CONSTANT_ATTEN + offset, atten0); + sendCommandf(LIGHT0_LINEAR_ATTEN + offset, atten1); + sendCommandf(LIGHT0_QUADRATIC_ATTEN + offset, atten2); } diff --git a/src/gu/sceGuLightColor.c b/src/gu/sceGuLightColor.c index 02ad385c..0734f2bf 100644 --- a/src/gu/sceGuLightColor.c +++ b/src/gu/sceGuLightColor.c @@ -10,25 +10,27 @@ void sceGuLightColor(int light, int component, unsigned int color) { - GuLightSettings* settings = &light_settings[light]; + + int offset = light * 3; switch (component) { - case GU_AMBIENT: sendCommandi(settings->ambient, color); break; - case GU_DIFFUSE: sendCommandi(settings->diffuse, color); break; + case GU_AMBIENT: + sendCommandi(LIGHT0_AMBIENT + offset, color); + break; + case GU_DIFFUSE: + sendCommandi(LIGHT0_DIFFUSE + offset, color); + break; + case GU_SPECULAR: + sendCommandi(LIGHT0_SPECULAR + offset, color); + break; case GU_AMBIENT_AND_DIFFUSE: - { - sendCommandi(settings->ambient, color); break; - sendCommandi(settings->diffuse, color); break; - } - break; - - case GU_SPECULAR: sendCommandi(settings->specular, color); break; + sendCommandi(LIGHT0_AMBIENT + offset, color); + sendCommandi(LIGHT0_DIFFUSE + offset, color); + break; case GU_DIFFUSE_AND_SPECULAR: - { - sendCommandi(settings->diffuse, color); break; - sendCommandi(settings->specular, color); break; - } - break; + sendCommandi(LIGHT0_DIFFUSE + offset, color); + sendCommandi(LIGHT0_SPECULAR + offset, color); + break; } } diff --git a/src/gu/sceGuLightSpot.c b/src/gu/sceGuLightSpot.c index 2193dc3f..7283455e 100644 --- a/src/gu/sceGuLightSpot.c +++ b/src/gu/sceGuLightSpot.c @@ -9,13 +9,12 @@ #include "guInternal.h" void sceGuLightSpot(int light, const ScePspFVector3 *direction, float exponent, float cutoff) -{ - GuLightSettings* settings = &light_settings[light]; +{ + int offset = light * 3; + sendCommandf(LIGHT0_EXPONENT_ATTEN + light, exponent); + sendCommandf(LIGHT0_CUTOFF_ATTEN + light, cutoff); - sendCommandf(settings->exponent,exponent); - sendCommandf(settings->cutoff,cutoff); - - sendCommandf(settings->xdir,direction->x); - sendCommandf(settings->ydir,direction->y); - sendCommandf(settings->zdir,direction->z); + sendCommandf(LIGHT0_DIRECTION_X + offset, direction->x); + sendCommandf(LIGHT0_DIRECTION_Y + offset, direction->y); + sendCommandf(LIGHT0_DIRECTION_Z + offset, direction->z); }