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;
|
GuDrawBuffer gu_draw_buffer;
|
||||||
unsigned int* gu_object_stack[32];
|
unsigned int* gu_object_stack[32];
|
||||||
int gu_object_stack_depth;
|
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;
|
int height;
|
||||||
} GuDrawBuffer;
|
} 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 GuContext gu_contexts[3];
|
||||||
extern int ge_list_executed[2];
|
extern int ge_list_executed[2];
|
||||||
extern void *ge_edram_address;
|
extern void *ge_edram_address;
|
||||||
@@ -111,8 +80,6 @@ extern GuDrawBuffer gu_draw_buffer;
|
|||||||
extern unsigned int *gu_object_stack[];
|
extern unsigned int *gu_object_stack[];
|
||||||
extern int gu_object_stack_depth;
|
extern int gu_object_stack_depth;
|
||||||
|
|
||||||
extern GuLightSettings light_settings[4];
|
|
||||||
|
|
||||||
void callbackSig(int id, void *arg);
|
void callbackSig(int id, void *arg);
|
||||||
void callbackFin(int id, void *arg);
|
void callbackFin(int id, void *arg);
|
||||||
void _sceGuResetGlobalVariables();
|
void _sceGuResetGlobalVariables();
|
||||||
|
@@ -273,7 +273,7 @@ extern "C" {
|
|||||||
#define GU_SPECULAR (4)
|
#define GU_SPECULAR (4)
|
||||||
#define GU_AMBIENT_AND_DIFFUSE (GU_AMBIENT|GU_DIFFUSE)
|
#define GU_AMBIENT_AND_DIFFUSE (GU_AMBIENT|GU_DIFFUSE)
|
||||||
#define GU_DIFFUSE_AND_SPECULAR (GU_DIFFUSE|GU_SPECULAR)
|
#define GU_DIFFUSE_AND_SPECULAR (GU_DIFFUSE|GU_SPECULAR)
|
||||||
#define GU_UNKNOWN_LIGHT_COMPONENT (8)
|
#define GU_POWERED_DIFFUSE (8)
|
||||||
|
|
||||||
/* Light modes */
|
/* Light modes */
|
||||||
#define GU_SINGLE_COLOR (0)
|
#define GU_SINGLE_COLOR (0)
|
||||||
@@ -863,7 +863,7 @@ void sceGuDisable(int state);
|
|||||||
* Available light components are:
|
* Available light components are:
|
||||||
* - GU_AMBIENT_AND_DIFFUSE
|
* - GU_AMBIENT_AND_DIFFUSE
|
||||||
* - GU_DIFFUSE_AND_SPECULAR
|
* - GU_DIFFUSE_AND_SPECULAR
|
||||||
* - GU_UNKNOWN_LIGHT_COMPONENT
|
* - GU_POWERED_DIFFUSE
|
||||||
*
|
*
|
||||||
* @param light - Light index
|
* @param light - Light index
|
||||||
* @param type - Light type
|
* @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 mask - Masks the color index with this bitmask after the shift (0-0xFF)
|
||||||
* @param csa - Read-out start location (16-palette units)
|
* @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
|
* Set virtual coordinate offset
|
||||||
|
@@ -8,17 +8,27 @@
|
|||||||
|
|
||||||
#include "guInternal.h"
|
#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)
|
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);
|
if (components == GU_POWERED_DIFFUSE) {
|
||||||
sendCommandf(settings->ypos,position->y);
|
ltype = LTYPE_POWERED_DIFFUSE;
|
||||||
sendCommandf(settings->zpos,position->z);
|
} else if (components == GU_DIFFUSE_AND_SPECULAR) {
|
||||||
|
ltype = LTYPE_DIFFUSE_AND_SPECULAR;
|
||||||
|
} else {
|
||||||
|
ltype = LTYPE_DIFFUSE;
|
||||||
|
}
|
||||||
|
|
||||||
int kind = 2;
|
// Light position
|
||||||
if (components != 8)
|
sendCommandf(LIGHT0_X + offset, position->x);
|
||||||
kind = (components^6) < 1 ? 1 : 0;
|
sendCommandf(LIGHT0_Y + offset, position->y);
|
||||||
|
sendCommandf(LIGHT0_Z + offset, position->z);
|
||||||
sendCommandi(settings->type,((type & 0x03) << 8)|kind);
|
// 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)
|
void sceGuLightAtt(int light, float atten0, float atten1, float atten2)
|
||||||
{
|
{
|
||||||
GuLightSettings* settings = &light_settings[light];
|
int offset = light * 3;
|
||||||
|
|
||||||
sendCommandf(settings->constant,atten0);
|
sendCommandf(LIGHT0_CONSTANT_ATTEN + offset, atten0);
|
||||||
sendCommandf(settings->linear,atten1);
|
sendCommandf(LIGHT0_LINEAR_ATTEN + offset, atten1);
|
||||||
sendCommandf(settings->quadratic,atten2);
|
sendCommandf(LIGHT0_QUADRATIC_ATTEN + offset, atten2);
|
||||||
}
|
}
|
||||||
|
@@ -10,25 +10,27 @@
|
|||||||
|
|
||||||
void sceGuLightColor(int light, int component, unsigned int color)
|
void sceGuLightColor(int light, int component, unsigned int color)
|
||||||
{
|
{
|
||||||
GuLightSettings* settings = &light_settings[light];
|
|
||||||
|
int offset = light * 3;
|
||||||
|
|
||||||
switch (component)
|
switch (component)
|
||||||
{
|
{
|
||||||
case GU_AMBIENT: sendCommandi(settings->ambient, color); break;
|
case GU_AMBIENT:
|
||||||
case GU_DIFFUSE: sendCommandi(settings->diffuse, color); break;
|
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:
|
case GU_AMBIENT_AND_DIFFUSE:
|
||||||
{
|
sendCommandi(LIGHT0_AMBIENT + offset, color);
|
||||||
sendCommandi(settings->ambient, color); break;
|
sendCommandi(LIGHT0_DIFFUSE + offset, color);
|
||||||
sendCommandi(settings->diffuse, color); break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GU_SPECULAR: sendCommandi(settings->specular, color); break;
|
|
||||||
case GU_DIFFUSE_AND_SPECULAR:
|
case GU_DIFFUSE_AND_SPECULAR:
|
||||||
{
|
sendCommandi(LIGHT0_DIFFUSE + offset, color);
|
||||||
sendCommandi(settings->diffuse, color); break;
|
sendCommandi(LIGHT0_SPECULAR + offset, color);
|
||||||
sendCommandi(settings->specular, color); break;
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,13 +9,12 @@
|
|||||||
#include "guInternal.h"
|
#include "guInternal.h"
|
||||||
|
|
||||||
void sceGuLightSpot(int light, const ScePspFVector3 *direction, float exponent, float cutoff)
|
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(LIGHT0_DIRECTION_X + offset, direction->x);
|
||||||
sendCommandf(settings->cutoff,cutoff);
|
sendCommandf(LIGHT0_DIRECTION_Y + offset, direction->y);
|
||||||
|
sendCommandf(LIGHT0_DIRECTION_Z + offset, direction->z);
|
||||||
sendCommandf(settings->xdir,direction->x);
|
|
||||||
sendCommandf(settings->ydir,direction->y);
|
|
||||||
sendCommandf(settings->zdir,direction->z);
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user