From d14b21dc11783422522a00c60d80cb866728489d Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 2 Apr 2025 19:36:03 +1100 Subject: [PATCH] Wii U: WIP on refactoring shaders --- misc/wiiu/assembler.sh | 12 +++-- misc/wiiu/offset_exp.gsh | Bin 0 -> 1840 bytes misc/wiiu/offset_lin.gsh | Bin 0 -> 1840 bytes .../{textured_ofst.gsh => offset_none.gsh} | Bin ...vs_textured_offset.glsl => vs_offset.glsl} | 0 .../{vs_textured_offset.vsh => vs_offset.vsh} | 0 src/Graphics_WiiU.c | 44 +++++++++++------- 7 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 misc/wiiu/offset_exp.gsh create mode 100644 misc/wiiu/offset_lin.gsh rename misc/wiiu/{textured_ofst.gsh => offset_none.gsh} (100%) rename misc/wiiu/{vs_textured_offset.glsl => vs_offset.glsl} (100%) rename misc/wiiu/{vs_textured_offset.vsh => vs_offset.vsh} (100%) diff --git a/misc/wiiu/assembler.sh b/misc/wiiu/assembler.sh index abf20d5b9..47f2aae1a 100755 --- a/misc/wiiu/assembler.sh +++ b/misc/wiiu/assembler.sh @@ -6,10 +6,12 @@ assemble() $ASSEMBLER assemble $1 --vsh $2 --psh $3 } -assemble coloured_none.gsh vs_coloured.vsh ps_coloured_none.psh +assemble coloured_none.gsh vs_coloured.vsh ps_coloured_none.psh -assemble textured_none.gsh vs_textured.vsh ps_textured_none.psh -assemble textured_lin.gsh vs_textured.vsh ps_textured_lin.psh -assemble textured_exp.gsh vs_textured.vsh ps_textured_exp.psh +assemble textured_none.gsh vs_textured.vsh ps_textured_none.psh +assemble textured_lin.gsh vs_textured.vsh ps_textured_lin.psh +assemble textured_exp.gsh vs_textured.vsh ps_textured_exp.psh -assemble textured_ofst.gsh vs_textured_offset.vsh ps_textured_none.psh +assemble offset_none.gsh vs_offset.vsh ps_textured_none.psh +assemble offset_lin.gsh vs_offset.vsh ps_textured_lin.psh +assemble offset_exp.gsh vs_offset.vsh ps_textured_exp.psh diff --git a/misc/wiiu/offset_exp.gsh b/misc/wiiu/offset_exp.gsh new file mode 100644 index 0000000000000000000000000000000000000000..49b5ab4fb7c6d9f9ef93245b8d9e4962cd4e06b2 GIT binary patch literal 1840 zcmd^AziSjx5dLO&?{cS!SumxN$8kjp!Jt=Ov7Cx02J#OCT+zEATylqr;Xs9VV3ESY zBBkIKmX;|kQm0DcA0UUt6&98jvgbE1yO(erVx^!1^Jc!8c|T`n_inp?1ArmVk%jD$ zC)8NG|D3>()u-fB{eG(IC_$#{JQp9Bz9uxg()&pE3hrB{h!4!EX zvDBt)=b=yk#(Bf9^y8kqrvED0y{SGIZEuLnnJvt0Z;3CE9WmxTm5Uh^;t$kyj*_>v z*TZhBzus=|w03EDvi+df-Es0!x8vlqJ=#xVjCkG>=hw(h@&>s>e({nCXUGbfB!`Su zT4B7NS!s^?;f%T{WN(+(2}5n!=nT}7dIIbhaezoD?PWQl49t>q|AT`x4SX3cN;839 z7+xn9zdT$g9{3Bxu2cR$snDlAL_3_p#F*>roR#q(_e{wYgnu? z{8x#kG&Ay1WIp!MQ*J7v+tB#51guJBYO{{GdR(Nb(qbY z*uWaTLZm(7?v?eC)^pxlL1tUcW7^%#Tis6gDKV(u*?tV|qkCHqH(P4s{vXMoj(Zr9 ze{hd*s!!@!pBSD=_g5-Vug}N}zq9V1?z^Xl0FJD2vXzBhE=E zwHe$dDobCNC z_FBD-c6+zAN5_+$2i<7b>PJz>>Sz1(pM)53za@^Z5lv!~=nyYn^1<0L$5 zzwTLOf%egyyeMRMm*)w)#$}@;P)q6wa8Se{0-=sC%7EH4D>nQOHqtb3WwE)6588l+&nnjrNUuNp~9j8~I>y2v;*UV%X46+_N=B_L5mrLP>v>3})!W%Gz3PvbuU)4c9L literal 0 HcmV?d00001 diff --git a/misc/wiiu/textured_ofst.gsh b/misc/wiiu/offset_none.gsh similarity index 100% rename from misc/wiiu/textured_ofst.gsh rename to misc/wiiu/offset_none.gsh diff --git a/misc/wiiu/vs_textured_offset.glsl b/misc/wiiu/vs_offset.glsl similarity index 100% rename from misc/wiiu/vs_textured_offset.glsl rename to misc/wiiu/vs_offset.glsl diff --git a/misc/wiiu/vs_textured_offset.vsh b/misc/wiiu/vs_offset.vsh similarity index 100% rename from misc/wiiu/vs_textured_offset.vsh rename to misc/wiiu/vs_offset.vsh diff --git a/src/Graphics_WiiU.c b/src/Graphics_WiiU.c index b8daad6c6..f9cc8b350 100644 --- a/src/Graphics_WiiU.c +++ b/src/Graphics_WiiU.c @@ -73,7 +73,9 @@ extern const uint8_t coloured_none_gsh[]; extern const uint8_t textured_none_gsh[]; extern const uint8_t textured_lin_gsh[]; extern const uint8_t textured_exp_gsh[]; -extern const uint8_t textured_ofst_gsh[]; +extern const uint8_t offset_none_gsh[]; +extern const uint8_t offset_lin_gsh[]; +extern const uint8_t offset_exp_gsh[]; #define VS_UNI_OFFSET_MVP 0 #define VS_UNI_COUNT_MVP 16 @@ -85,8 +87,17 @@ extern const uint8_t textured_ofst_gsh[]; #define PS_UNI_OFFSET_FOG 4 #define PS_UNI_COUNT_FOG 4 -static GX2VertexShader *texture_VS, *colour_VS, *offset_VS; -static GX2PixelShader *texture_PS[3], *colour_PS[3]; +struct ShaderProgram { + GX2VertexShader* vs; + GX2PixelShader* ps; +}; + +static struct ShaderProgram colour_PG, texture_PG[3], offset_PG[3]; + +static void LoadProgram(struct ShaderProgram* prog, const cc_uint8* gsh) { + prog->vs = WHBGfxLoadGFDVertexShader(0, gsh); + prog->ps = WHBGfxLoadGFDPixelShader(0, gsh); +} static GX2Sampler sampler; static GfxResourceID white_square; @@ -98,40 +109,39 @@ static void InitGfx(void) { CompileFetchShaders(); GX2InitSampler(&sampler, GX2_TEX_CLAMP_MODE_WRAP, GX2_TEX_XY_FILTER_MODE_POINT); - colour_VS = WHBGfxLoadGFDVertexShader(0, coloured_none_gsh); - colour_PS[0] = WHBGfxLoadGFDPixelShader(0, coloured_none_gsh); + LoadProgram(&colour_PG, coloured_none_gsh); - texture_VS = WHBGfxLoadGFDVertexShader(0, textured_none_gsh); + LoadProgram(&texture_PG[0], textured_none_gsh); + LoadProgram(&texture_PG[1], textured_lin_gsh); + LoadProgram(&texture_PG[2], textured_exp_gsh); - offset_VS = WHBGfxLoadGFDVertexShader(0, textured_ofst_gsh); - - texture_PS[0] = WHBGfxLoadGFDPixelShader(0, textured_none_gsh); - texture_PS[1] = WHBGfxLoadGFDPixelShader(0, textured_lin_gsh); - texture_PS[2] = WHBGfxLoadGFDPixelShader(0, textured_exp_gsh); + LoadProgram(&offset_PG[0], offset_none_gsh); + LoadProgram(&offset_PG[1], offset_lin_gsh); + LoadProgram(&offset_PG[2], offset_exp_gsh); } static struct Vec4 texOffset; static void UpdateVS(void) { if (gfx_format != VERTEX_FORMAT_TEXTURED) { - cur_VS = colour_VS; + cur_VS = colour_PG.vs; } else if (texOffset.x || texOffset.y) { - cur_VS = offset_VS; + cur_VS = offset_PG[0].vs; } else { - cur_VS = texture_VS; + cur_VS = texture_PG[0].vs; } GX2SetVertexShader(cur_VS); } static void UpdatePS(void) { if (gfx_format != VERTEX_FORMAT_TEXTURED) { - cur_PS = colour_PS[0]; + cur_PS = colour_PG.ps; /*} else if (gfx_fogEnabled && fog_func == FOG_EXP) { cur_PS = texture_PS[2]; } else if (gfx_fogEnabled && fog_func == FOG_LINEAR) { cur_PS = texture_PS[1]; */} else { - cur_PS = texture_PS[0]; + cur_PS = texture_PG[0].ps; } GX2SetPixelShader(cur_PS); } @@ -223,7 +233,7 @@ void Gfx_BindTexture(GfxResourceID texId) { } static void BindPendingTexture(void) { - if (!pendingTex || cur_VS == colour_VS) return; + if (!pendingTex || cur_VS == colour_PG.vs) return; GX2SetPixelTexture(pendingTex, cur_PS->samplerVars[0].location); GX2SetPixelSampler(&sampler, cur_PS->samplerVars[0].location);