mirror of
https://github.com/pspdev/pspsdk.git
synced 2025-10-03 16:51:27 +00:00
Merge pull request #300 from fjtrujy/sceguLight
Improve `sceGuLight*` functions
This commit is contained in:
@@ -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
|
||||
}
|
||||
};
|
||||
|
@@ -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();
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
||||
int kind = 2;
|
||||
if (components != 8)
|
||||
kind = (components^6) < 1 ? 1 : 0;
|
||||
|
||||
sendCommandi(settings->type,((type & 0x03) << 8)|kind);
|
||||
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;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
sendCommandi(LIGHT0_AMBIENT + offset, color);
|
||||
sendCommandi(LIGHT0_DIFFUSE + offset, color);
|
||||
break;
|
||||
|
||||
case GU_SPECULAR: sendCommandi(settings->specular, color); break;
|
||||
case GU_DIFFUSE_AND_SPECULAR:
|
||||
{
|
||||
sendCommandi(settings->diffuse, color); break;
|
||||
sendCommandi(settings->specular, color); break;
|
||||
}
|
||||
sendCommandi(LIGHT0_DIFFUSE + offset, color);
|
||||
sendCommandi(LIGHT0_SPECULAR + offset, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -10,12 +10,11 @@
|
||||
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user