From 4f6d3850f0c2c2a35f8824f4d9713d63feb7771a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 6 Oct 2023 19:24:27 +1100 Subject: [PATCH] PS3: Make texture animations work --- misc/ps3/Makefile | 6 +++--- misc/ps3/ps_coloured_alpha.fcg | 9 +++++++++ misc/ps3/ps_textured_alpha.fcg | 12 +++++++++++ misc/ps3/vs_coloured.vcg | 31 +++++++++------------------- misc/ps3/vs_textured.vcg | 37 +++++++++++----------------------- misc/vita/colored_alpha_f.cg | 6 ++++-- misc/vita/colored_f.cg | 6 ++++-- misc/vita/textured_alpha_f.cg | 8 +++++--- misc/vita/textured_f.cg | 8 +++++--- src/Graphics_PS3.c | 27 +++++++++++++++++++------ 10 files changed, 84 insertions(+), 66 deletions(-) create mode 100644 misc/ps3/ps_coloured_alpha.fcg create mode 100644 misc/ps3/ps_textured_alpha.fcg diff --git a/misc/ps3/Makefile b/misc/ps3/Makefile index 7240c94ee..e859df91f 100644 --- a/misc/ps3/Makefile +++ b/misc/ps3/Makefile @@ -3,11 +3,11 @@ #--------------------------------------------------------------------------------- .SUFFIXES: #--------------------------------------------------------------------------------- -ifeq ($(strip $(PSL1GHT)),) -$(error "Please set PSL1GHT in your environment. export PSL1GHT=") +ifeq ($(strip $(PS3DEV)),) +$(error "Please set PS3DEV in your environment. export PS3DEV=") endif -include $(PSL1GHT)/ppu_rules +include $(PS3DEV)/ppu_rules #--------------------------------------------------------------------------------- # TARGET is the name of the output diff --git a/misc/ps3/ps_coloured_alpha.fcg b/misc/ps3/ps_coloured_alpha.fcg new file mode 100644 index 000000000..e16655d05 --- /dev/null +++ b/misc/ps3/ps_coloured_alpha.fcg @@ -0,0 +1,9 @@ +float4 main +( + float4 in_color: COLOR +) : COLOR +{ + if (in_color.a < 0.5) discard; + + return in_color; +} \ No newline at end of file diff --git a/misc/ps3/ps_textured_alpha.fcg b/misc/ps3/ps_textured_alpha.fcg new file mode 100644 index 000000000..b1c5811f0 --- /dev/null +++ b/misc/ps3/ps_textured_alpha.fcg @@ -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; +} \ No newline at end of file diff --git a/misc/ps3/vs_coloured.vcg b/misc/ps3/vs_coloured.vcg index d1b6366ad..6a02879fb 100644 --- a/misc/ps3/vs_coloured.vcg +++ b/misc/ps3/vs_coloured.vcg @@ -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; } \ No newline at end of file diff --git a/misc/ps3/vs_textured.vcg b/misc/ps3/vs_textured.vcg index 0cee007ca..64c02118e 100644 --- a/misc/ps3/vs_textured.vcg +++ b/misc/ps3/vs_textured.vcg @@ -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; } \ No newline at end of file diff --git a/misc/vita/colored_alpha_f.cg b/misc/vita/colored_alpha_f.cg index 928d7105c..5e6c57f92 100644 --- a/misc/vita/colored_alpha_f.cg +++ b/misc/vita/colored_alpha_f.cg @@ -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; diff --git a/misc/vita/colored_f.cg b/misc/vita/colored_f.cg index 7d23a719e..3ea062363 100644 --- a/misc/vita/colored_f.cg +++ b/misc/vita/colored_f.cg @@ -1,5 +1,7 @@ -float4 main( - float4 out_color: COLOR) : COLOR +float4 main +( + float4 out_color : COLOR +) : COLOR { return out_color; } \ No newline at end of file diff --git a/misc/vita/textured_alpha_f.cg b/misc/vita/textured_alpha_f.cg index 1945904bd..4bed4427f 100644 --- a/misc/vita/textured_alpha_f.cg +++ b/misc/vita/textured_alpha_f.cg @@ -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; diff --git a/misc/vita/textured_f.cg b/misc/vita/textured_f.cg index 0386696af..a78df885f 100644 --- a/misc/vita/textured_f.cg +++ b/misc/vita/textured_f.cg @@ -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; } \ No newline at end of file diff --git a/src/Graphics_PS3.c b/src/Graphics_PS3.c index 2d8b02198..46b10348d 100644 --- a/src/Graphics_PS3.c +++ b/src/Graphics_PS3.c @@ -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 */ }