Moved gfx effects to the gpu and removed loadtexbyname on some textures

This commit is contained in:
KiritoDev 2022-03-29 10:27:41 -06:00
commit b01156fb2d
13 changed files with 71 additions and 41 deletions

View file

@ -170,6 +170,17 @@
#define G_TEXRECT_WIDE 0x37
#define G_FILLWIDERECT 0x38
/* GFX Effects */
// RDP Cmd
#define G_SET_GFX_EFFECT 0x39
// Effects
enum GFXEffects {
NONE, GRAYOUT, SEPIA
};
/*
* The following commands are the "generated" RDP commands; the user
* never sees them, the RSP microcode generates them.
@ -2821,6 +2832,14 @@ _DW({ \
_g->words.w1 = 0; \
}
#define gsSPSetGfxEffect(pkt, fb) \
{ \
Gfx *_g = (Gfx *)(pkt); \
\
_g->words.w0 = _SHIFTL(G_SET_GFX_EFFECT, 24, 8); \
_g->words.w1 = fb; \
}
#ifdef F3DEX_GBI_2
/*
* One gSPGeometryMode(pkt,c,s) GBI is equal to these two GBIs.

View file

@ -16,6 +16,7 @@ void gfx_cc_get_features(uint64_t shader_id0, uint32_t shader_id1, struct CCFeat
cc_features->opt_2cyc = (shader_id1 & SHADER_OPT_2CYC) != 0;
cc_features->opt_alpha_threshold = (shader_id1 & SHADER_OPT_ALPHA_THRESHOLD) != 0;
cc_features->opt_invisible = (shader_id1 & SHADER_OPT_INVISIBLE) != 0;
cc_features->opt_grayscale = (shader_id1 & SHADER_OPT_GRAYSCALE) != 0;
cc_features->clamp[0][0] = (shader_id1 & SHADER_OPT_TEXEL0_CLAMP_S);
cc_features->clamp[0][1] = (shader_id1 & SHADER_OPT_TEXEL0_CLAMP_T);

View file

@ -39,10 +39,11 @@ enum {
#define SHADER_OPT_2CYC (1 << 4)
#define SHADER_OPT_ALPHA_THRESHOLD (1 << 5)
#define SHADER_OPT_INVISIBLE (1 << 6)
#define SHADER_OPT_TEXEL0_CLAMP_S (1 << 7)
#define SHADER_OPT_TEXEL0_CLAMP_T (1 << 8)
#define SHADER_OPT_TEXEL1_CLAMP_S (1 << 9)
#define SHADER_OPT_TEXEL1_CLAMP_T (1 << 10)
#define SHADER_OPT_GRAYSCALE (1 << 7)
#define SHADER_OPT_TEXEL0_CLAMP_S (1 << 8)
#define SHADER_OPT_TEXEL0_CLAMP_T (1 << 9)
#define SHADER_OPT_TEXEL1_CLAMP_S (1 << 10)
#define SHADER_OPT_TEXEL1_CLAMP_T (1 << 11)
#define CC_SHADER_OPT_POS 56
struct CCFeatures {
@ -54,6 +55,7 @@ struct CCFeatures {
bool opt_2cyc;
bool opt_alpha_threshold;
bool opt_invisible;
bool opt_grayscale;
bool used_textures[2];
bool clamp[2][2];
int num_inputs;

View file

@ -341,6 +341,11 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
append_line(fs_buf, &fs_len, "texel.a *= floor(clamp(random(vec3(floor(gl_FragCoord.xy * (240.0 / float(window_height))), float(frame_count))) + texel.a, 0.0, 1.0));");
}
if(cc_features.opt_grayscale) {
append_line(fs_buf, &fs_len, "float light = (texel.r + texel.g + texel.b) / 7.0;");
append_line(fs_buf, &fs_len, "texel.rgb = vec3(light, light, light);");
}
if (cc_features.opt_alpha) {
if (cc_features.opt_alpha_threshold) {
append_line(fs_buf, &fs_len, "if (texel.a < 8.0 / 256.0) discard;");
@ -389,9 +394,9 @@ static struct ShaderProgram* gfx_opengl_create_and_load_new_shader(uint64_t shad
GLint max_length = 0;
glGetShaderiv(fragment_shader, GL_INFO_LOG_LENGTH, &max_length);
char error_log[1024];
//fprintf(stderr, "Fragment shader compilation failed\n");
fprintf(stderr, "Fragment shader compilation failed\n");
glGetShaderInfoLog(fragment_shader, max_length, &max_length, &error_log[0]);
//fprintf(stderr, "%s\n", &error_log[0]);
fprintf(stderr, "%s\n", &error_log[0]);
abort();
}

View file

@ -155,6 +155,7 @@ static struct RDP {
uint32_t other_mode_l, other_mode_h;
uint64_t combine_mode;
uint32_t gfx_effect;
uint8_t prim_lod_fraction;
struct RGBA env_color, prim_color, fog_color, fill_color;
@ -1194,7 +1195,6 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
uint64_t cc_id = rdp.combine_mode;
//bool use_alpha = (rdp.other_mode_l & (3 << 18)) == G_BL_1MA || (rdp.other_mode_l & (3 << 16)) == G_BL_1MA;
bool use_alpha = (rdp.other_mode_l & (3 << 20)) == (G_BL_CLR_MEM << 20) && (rdp.other_mode_l & (3 << 16)) == (G_BL_1MA << 16);
bool use_fog = (rdp.other_mode_l >> 30) == G_BL_CLR_FOG;
bool texture_edge = (rdp.other_mode_l & CVG_X_ALPHA) == CVG_X_ALPHA;
@ -1202,6 +1202,7 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
bool use_2cyc = (rdp.other_mode_h & (3U << G_MDSFT_CYCLETYPE)) == G_CYC_2CYCLE;
bool alpha_threshold = (rdp.other_mode_l & (3U << G_MDSFT_ALPHACOMPARE)) == G_AC_THRESHOLD;
bool invisible = (rdp.other_mode_l & (3 << 24)) == (G_BL_0 << 24) && (rdp.other_mode_l & (3 << 20)) == (G_BL_CLR_MEM << 20);
bool use_grayscale = rdp.gfx_effect == GRAYOUT;
if (texture_edge) {
use_alpha = true;
@ -1214,6 +1215,7 @@ static void gfx_sp_tri1(uint8_t vtx1_idx, uint8_t vtx2_idx, uint8_t vtx3_idx, bo
if (use_2cyc) cc_id |= (uint64_t)SHADER_OPT_2CYC << CC_SHADER_OPT_POS;
if (alpha_threshold) cc_id |= (uint64_t)SHADER_OPT_ALPHA_THRESHOLD << CC_SHADER_OPT_POS;
if (invisible) cc_id |= (uint64_t)SHADER_OPT_INVISIBLE << CC_SHADER_OPT_POS;
if (use_grayscale) cc_id |= (uint64_t)SHADER_OPT_GRAYSCALE << CC_SHADER_OPT_POS;
if (!use_alpha) {
cc_id &= ~((0xfff << 16) | ((uint64_t)0xfff << 44));
@ -2429,8 +2431,8 @@ static void gfx_run_dl(Gfx* cmd) {
fbActive = 1;
active_fb = framebuffers.find(cmd->words.w1);
gfx_rapi->set_framebuffer(active_fb->first);
}
break;
}
case G_RESETFB:
{
gfx_flush();
@ -2438,7 +2440,6 @@ static void gfx_run_dl(Gfx* cmd) {
gfx_rapi->reset_framebuffer();
break;
}
break;
case G_SETTIMG_FB:
{
gfx_flush();
@ -2448,8 +2449,13 @@ static void gfx_run_dl(Gfx* cmd) {
//if (texPtr != NULL)
//gfx_dp_set_texture_image(C0(21, 3), C0(19, 2), C0(0, 10), texPtr);
break;
}
case G_SET_GFX_EFFECT:
{
rdp.gfx_effect = cmd->words.w1;
break;
}
break;
case G_LOADBLOCK:
gfx_dp_load_block(C1(24, 3), C0(12, 12), C0(0, 12), C1(12, 12), C1(0, 12));
break;

View file

@ -99,6 +99,7 @@ extern "C"
extern u32 gGsFlagsMasks[4];
extern u32 gGsFlagsShifts[4];
extern void* gItemIcons[0x82];
extern u8 gItemAgeReqs[];
extern u8 gItemSlots[56];
extern void (*gSceneCmdHandlers[26])(GlobalContext*, SceneCmd*);
extern s16 gLinkObjectIds[2];

View file

@ -56,8 +56,6 @@ void TransitionCircle_Start(void* thisx) {
break;
}
this->texture = ResourceMgr_LoadTexByName(this->texture);
if (this->speed == 0) {
this->step = 0x14;
} else {

View file

@ -298,13 +298,13 @@ void EnPart_Draw(Actor* thisx, GlobalContext* globalCtx) {
gSPSegment(POLY_OPA_DISP++, 0x09, func_80ACEAC0(globalCtx->state.gfxCtx, 225, 205, 115, 25, 20, 0));
gSPSegment(POLY_OPA_DISP++, 0x0A, func_80ACEAC0(globalCtx->state.gfxCtx, 225, 205, 115, 25, 20, 0));
} else if ((thisx->params == 9) && (this->displayList == ResourceMgr_LoadGfxByName(object_tite_DL_002FF0))) {
gSPSegment(POLY_OPA_DISP++, 0x08, ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(object_tite_Tex_001300)));
gSPSegment(POLY_OPA_DISP++, 0x09, ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(object_tite_Tex_001700)));
gSPSegment(POLY_OPA_DISP++, 0x0A, ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(object_tite_Tex_001900)));
gSPSegment(POLY_OPA_DISP++, 0x08, object_tite_Tex_001300);
gSPSegment(POLY_OPA_DISP++, 0x09, object_tite_Tex_001700);
gSPSegment(POLY_OPA_DISP++, 0x0A, object_tite_Tex_001900);
} else if ((thisx->params == 10) && (this->displayList == ResourceMgr_LoadGfxByName(object_tite_DL_002FF0))) {
gSPSegment(POLY_OPA_DISP++, 0x08, ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(object_tite_Tex_001B00)));
gSPSegment(POLY_OPA_DISP++, 0x09, ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(object_tite_Tex_001F00)));
gSPSegment(POLY_OPA_DISP++, 0x0A, ResourceMgr_LoadTexByName(SEGMENTED_TO_VIRTUAL(object_tite_Tex_002100)));
gSPSegment(POLY_OPA_DISP++, 0x08, object_tite_Tex_001B00);
gSPSegment(POLY_OPA_DISP++, 0x09, object_tite_Tex_001F00);
gSPSegment(POLY_OPA_DISP++, 0x0A, object_tite_Tex_002100);
}
if (this->displayList != NULL) {

View file

@ -47,9 +47,6 @@ void FileChoose_SetView(FileChooseContext* this, f32 eyeX, f32 eyeY, f32 eyeZ) {
Gfx* FileChoose_QuadTextureIA8(Gfx* gfx, void* texture, s16 width, s16 height, s16 point)
{
if (ResourceMgr_OTRSigCheck(texture))
texture = ResourceMgr_LoadTexByName(texture);
gDPLoadTextureBlock(gfx++, texture, G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, G_TX_NOMIRROR | G_TX_WRAP,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD);

View file

@ -161,7 +161,7 @@ void Title_Draw(TitleContext* this) {
gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 170, 255, 255, 255);
gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 255, 128);
gDPLoadMultiBlock(POLY_OPA_DISP++, ResourceMgr_LoadTexByName(nintendo_rogo_static_Tex_001800), 0x100, 1, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0,
gDPLoadMultiBlock(POLY_OPA_DISP++, nintendo_rogo_static_Tex_001800, 0x100, 1, G_IM_FMT_I, G_IM_SIZ_8b, 32, 32, 0,
G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, 5, 5, 2, 11);
for (idx = 0, y = 94; idx < 16; idx++, y += 2)

View file

@ -550,7 +550,6 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
if (LINK_AGE_IN_YEARS == YEARS_CHILD) {
point = CUR_UPG_VALUE(sChildUpgrades[i]);
if (1) {}
if ((point != 0) && (CUR_UPG_VALUE(sChildUpgrades[i]) != 0)) {
KaleidoScope_DrawQuadTextureRGBA32(globalCtx->state.gfxCtx,
gItemIcons[sChildUpgradeItemBases[i] + point - 1], 32, 32, 0);
@ -574,7 +573,12 @@ void KaleidoScope_DrawEquipment(GlobalContext* globalCtx) {
} else if ((i == 0) && (k == 2) && (gBitFlags[bit + 1] & gSaveContext.inventory.equipment)) {
KaleidoScope_DrawQuadTextureRGBA32(globalCtx->state.gfxCtx, gBrokenGiantsKnifeIconTex, 32, 32, point);
} else if (gBitFlags[bit] & gSaveContext.inventory.equipment) {
KaleidoScope_DrawQuadTextureRGBA32(globalCtx->state.gfxCtx, gItemIcons[ITEM_SWORD_KOKIRI + temp], 32, 32, point);
int itemId = ITEM_SWORD_KOKIRI + temp;
bool not_acquired = (gItemAgeReqs[itemId] != 9) && (gItemAgeReqs[itemId] != gSaveContext.linkAge);
if (not_acquired)
gsSPSetGfxEffect(POLY_KAL_DISP++, GRAYOUT);
KaleidoScope_DrawQuadTextureRGBA32(globalCtx->state.gfxCtx, gItemIcons[itemId], 32, 32, point);
gsSPSetGfxEffect(POLY_KAL_DISP++, NONE);
}
}
}

View file

@ -466,8 +466,13 @@ void KaleidoScope_DrawItemSelect(GlobalContext* globalCtx) {
}
gSPVertex(POLY_KAL_DISP++, &pauseCtx->itemVtx[j + 0], 4, 0);
KaleidoScope_DrawQuadTextureRGBA32(globalCtx->state.gfxCtx, gItemIcons[gSaveContext.inventory.items[i]], 32,
int itemId = gSaveContext.inventory.items[i];
bool not_acquired = (gItemAgeReqs[itemId] != 9) && (gItemAgeReqs[itemId] != gSaveContext.linkAge);
if (not_acquired)
gsSPSetGfxEffect(POLY_KAL_DISP++, GRAYOUT);
KaleidoScope_DrawQuadTextureRGBA32(globalCtx->state.gfxCtx, gItemIcons[itemId], 32,
32, 0);
gsSPSetGfxEffect(POLY_KAL_DISP++, NONE);
}
}

View file

@ -3110,14 +3110,6 @@ void KaleidoScope_Update(GlobalContext* globalCtx)
gSegments[8] = VIRTUAL_TO_PHYSICAL(pauseCtx->iconItemSegment);
for (i = 0; i < ARRAY_COUNTU(gItemAgeReqs); i++) {
if ((gItemAgeReqs[i] != 9) && (gItemAgeReqs[i] != ((void)0, gSaveContext.linkAge)))
{
gSPInvalidateTexCache(globalCtx->state.gfxCtx->polyKal.p++, ResourceMgr_LoadTexByName(gItemIcons[i]));
KaleidoScope_GrayOutTextureRGBA32(SEGMENTED_TO_VIRTUAL(gItemIcons[i]), 0x400);
}
}
pauseCtx->iconItem24Segment = (void*)(((uintptr_t)pauseCtx->iconItemSegment + size0 + 0xF) & ~0xF);
#if 1