PS3: Make texture animations work

This commit is contained in:
UnknownShadow200 2023-10-06 19:24:27 +11:00
parent 9ee529c8c3
commit 4f6d3850f0
10 changed files with 84 additions and 66 deletions

View File

@ -3,11 +3,11 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(PSL1GHT)),)
$(error "Please set PSL1GHT in your environment. export PSL1GHT=<path>")
ifeq ($(strip $(PS3DEV)),)
$(error "Please set PS3DEV in your environment. export PS3DEV=<path>")
endif
include $(PSL1GHT)/ppu_rules
include $(PS3DEV)/ppu_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output

View File

@ -0,0 +1,9 @@
float4 main
(
float4 in_color: COLOR
) : COLOR
{
if (in_color.a < 0.5) discard;
return in_color;
}

View File

@ -0,0 +1,12 @@
float4 main
(
float4 in_color : COLOR,
float2 in_tex0 : TEXCOORD0,
uniform sampler2D tex
) : COLOR
{
float4 color = tex2D(tex, in_texcoord) * in_color;
if (color.a < 0.5) discard;
return color;
}

View File

@ -1,24 +1,11 @@
struct vIn {
float4 color : DIFFUSE;
float4 position : POSITION;
};
struct vOut {
float4 col : COLOR;
float4 pos : POSITION;
};
vOut main(
vIn input,
uniform float4x4 mvp
)
void main(
float4 in_position : POSITION,
float4 in_color : DIFFUSE,
uniform float4x4 mvp,
out float4 out_pos : POSITION,
out float4 out_color : COLOR)
{
vOut result;
float4 position;
position = float4(input.position.xyz, 1.0f);
result.pos = mul(position, mvp);
result.col = input.color;
return result;
float4 pos = float4(in_position.xyz, 1.0f);
out_pos = mul(pos, mvp);
out_color = in_color;
}

View File

@ -1,27 +1,14 @@
struct vIn {
float4 tex : TEXCOORD;
float4 color : DIFFUSE;
float4 position : POSITION;
};
struct vOut {
float4 pos : POSITION;
float4 col : COLOR;
float4 tex : TEXCOORD0;
};
vOut main(
vIn input,
uniform float4x4 mvp
)
void main(
float4 in_position : POSITION,
float4 in_color : DIFFUSE,
float4 in_tex : TEXCOORD,
uniform float4x4 mvp,
out float4 out_pos : POSITION,
out float4 out_color : COLOR,
out float2 out_tex : TEXCOORD0)
{
vOut result;
float4 position;
position = float4(input.position.xyz, 1.0f);
result.pos = mul(position, mvp);
result.col = input.color;
result.tex = input.tex;
return result;
float4 pos = float4(in_position.xyz, 1.0f);
out_pos = mul(pos, mvp);
out_color = in_color;
out_tex = in_tex;
}

View File

@ -1,5 +1,7 @@
float4 main(
float4 out_color: COLOR) : COLOR
float4 main
(
float4 out_color: COLOR
) : COLOR
{
if (out_color.a < 0.5) discard;

View File

@ -1,5 +1,7 @@
float4 main(
float4 out_color: COLOR) : COLOR
float4 main
(
float4 out_color : COLOR
) : COLOR
{
return out_color;
}

View File

@ -1,7 +1,9 @@
float4 main(
float4 main
(
uniform sampler2D tex,
float4 out_color: COLOR,
float2 out_texcoord : TEXCOORD0) : COLOR
float4 out_color : COLOR,
float2 out_texcoord : TEXCOORD0
) : COLOR
{
float4 color = tex2D(tex, out_texcoord) * out_color;

View File

@ -1,7 +1,9 @@
float4 main(
float4 main
(
uniform sampler2D tex,
float4 out_color: COLOR,
float2 out_texcoord : TEXCOORD0) : COLOR
float4 out_color : COLOR,
float2 out_texcoord : TEXCOORD0
) : COLOR
{
return tex2D(tex, out_texcoord) * out_color;
}

View File

@ -11,8 +11,10 @@
/* Current format and size of vertices */
static int gfx_stride, gfx_format = -1;
static cc_bool renderingDisabled;
static cc_bool alphaTesting;
static gcmContextData* context;
static u32 cur_fb = 0;
static u32 cur_fb;
#define CB_SIZE 0x100000 // TODO: smaller command buffer?
#define HOST_SIZE (32 * 1024 * 1024)
@ -70,8 +72,10 @@ typedef struct CCFragmentProgram {
extern const u8 ps_textured_fpo[];
extern const u8 ps_coloured_fpo[];
extern const u8 ps_textured_alpha_fpo[];
extern const u8 ps_coloured_alpha_fpo[];
static FragmentProgram FP_list[2];
static FragmentProgram FP_list[4];
static FragmentProgram* FP_active;
@ -88,10 +92,13 @@ static void FP_Load(FragmentProgram* fp, const u8* source) {
static void LoadFragmentPrograms(void) {
FP_Load(&FP_list[0], ps_coloured_fpo);
FP_Load(&FP_list[1], ps_textured_fpo);
FP_Load(&FP_list[2], ps_coloured_alpha_fpo);
FP_Load(&FP_list[3], ps_textured_alpha_fpo);
}
static void FP_SwitchActive(void) {
int index = gfx_format == VERTEX_FORMAT_TEXTURED ? 1 : 0;
if (alphaTesting) index += 2; // TODO: Doesn't work
FragmentProgram* FP = &FP_list[index];
if (FP == FP_active) return;
@ -264,7 +271,6 @@ void Gfx_TransferImage(u32 offset, s32 w, s32 h) {
/*########################################################################################################################*
*-----------------------------------------------------State management----------------------------------------------------*
*#########################################################################################################################*/
static PackedCol gfx_clearColor;
void Gfx_SetFaceCulling(cc_bool enabled) {
rsxSetCullFaceEnable(context, enabled);
}
@ -298,7 +304,10 @@ void Gfx_SetDepthTest(cc_bool enabled) {
void Gfx_SetTexturing(cc_bool enabled) { }
void Gfx_SetAlphaTest(cc_bool enabled) { /* TODO */ }
void Gfx_SetAlphaTest(cc_bool enabled) {
alphaTesting = enabled;
FP_SwitchActive();
}
void Gfx_DepthOnlyRendering(cc_bool depthOnly) {/* TODO */
}
@ -393,7 +402,7 @@ void Gfx_OnWindowResize(void) {
f32 zmin = 0.0f;
f32 zmax = 1.0f;
scale[0] = w * 0.5f;
scale[0] = w * 0.5f;
scale[1] = h * -0.5f;
scale[2] = (zmax - zmin) * 0.5f;
scale[3] = 0.0f;
@ -403,7 +412,7 @@ void Gfx_OnWindowResize(void) {
offset[3] = 0.0f;
rsxSetViewport(context, 0, 0, w, h, zmin, zmax, scale, offset);
rsxSetScissor(context, 0, 0, w, h);
rsxSetScissor(context, 0, 0, w, h);
// TODO: even needed?
for (int i = 0; i < 8; i++)
@ -558,6 +567,12 @@ void Gfx_DeleteTexture(GfxResourceID* texId) {
}
void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) {
CCTexture* tex = (CCTexture*)texId;
// NOTE: Only valid for LINEAR textures
cc_uint32* dst = (tex->pixels + x) + y * tex->width;
CopyTextureData(dst, tex->width * 4, part, rowWidth << 2);
rsxInvalidateTextureCache(context, GCM_INVALIDATE_TEXTURE);
/* TODO */
}