diff --git a/libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/gbi.h b/libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/gbi.h index 843cb3cd6..2ca7981d2 100644 --- a/libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/gbi.h +++ b/libultraship/libultraship/Lib/Fast3D/U64/PR/ultra64/gbi.h @@ -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. diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_cc.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_cc.cpp index 25ae8b324..c92a05b8b 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_cc.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_cc.cpp @@ -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); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_cc.h b/libultraship/libultraship/Lib/Fast3D/gfx_cc.h index 7bf415f84..f0a9f2eca 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_cc.h +++ b/libultraship/libultraship/Lib/Fast3D/gfx_cc.h @@ -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; diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp index 52815bc1c..16f800a4f 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_opengl.cpp @@ -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(); } @@ -671,7 +676,7 @@ static void gfx_opengl_resize_framebuffer(int fb, uint32_t width, uint32_t heigh glBindRenderbuffer(GL_RENDERBUFFER, 0); } -void gfx_opengl_set_framebuffer(int fb) +void gfx_opengl_set_framebuffer(int fb) { glClipControl(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE); // Set origin to upper left corner, to match N64 and DX11 glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb); @@ -682,7 +687,7 @@ void gfx_opengl_set_framebuffer(int fb) glDepthMask(current_depth_mask ? GL_TRUE : GL_FALSE); } -void gfx_opengl_reset_framebuffer(void) +void gfx_opengl_reset_framebuffer(void) { glBindFramebuffer(GL_FRAMEBUFFER, 0); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp index 3f7bd7f9b..4810f3a86 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp @@ -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; @@ -799,7 +800,7 @@ static void import_texture(int i, int tile) { uint8_t siz = rdp.texture_tile[tile].siz; uint32_t tmem_index = rdp.texture_tile[tile].tmem_index; - // OTRTODO: Move it to a function to be faster + // OTRTODO: Move it to a function to be faster // ModInternal::bindHook(LOOKUP_TEXTURE); // ModInternal::initBindHook(8, // HOOK_PARAMETER("gfx_api", gfx_get_current_rendering_api()), @@ -1193,8 +1194,7 @@ 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; diff --git a/soh/include/variables.h b/soh/include/variables.h index 80e3b792d..774991f1d 100644 --- a/soh/include/variables.h +++ b/soh/include/variables.h @@ -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]; diff --git a/soh/src/code/z_fbdemo_circle.c b/soh/src/code/z_fbdemo_circle.c index 630f198d1..b19948737 100644 --- a/soh/src/code/z_fbdemo_circle.c +++ b/soh/src/code/z_fbdemo_circle.c @@ -56,8 +56,6 @@ void TransitionCircle_Start(void* thisx) { break; } - this->texture = ResourceMgr_LoadTexByName(this->texture); - if (this->speed == 0) { this->step = 0x14; } else { diff --git a/soh/src/overlays/actors/ovl_En_Part/z_en_part.c b/soh/src/overlays/actors/ovl_En_Part/z_en_part.c index ec4079887..bdf29aa52 100644 --- a/soh/src/overlays/actors/ovl_En_Part/z_en_part.c +++ b/soh/src/overlays/actors/ovl_En_Part/z_en_part.c @@ -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) { diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index ca5154567..84be5d58c 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -45,11 +45,8 @@ void FileChoose_SetView(FileChooseContext* this, f32 eyeX, f32 eyeY, f32 eyeZ) { func_800AAA50(&this->view, 0x7F); } -Gfx* FileChoose_QuadTextureIA8(Gfx* gfx, void* texture, s16 width, s16 height, s16 point) +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); @@ -1498,13 +1495,13 @@ void FileChoose_LoadGame(GameState* thisx) { gSaveContext.naviTimer = 0; // SWORDLESS LINK IS BACK BABY - if (CVar_GetS32("gSwordlessLink", 0) != 0) + if (CVar_GetS32("gSwordlessLink", 0) != 0) { if ((gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KOKIRI) && (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_MASTER) && (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_BGS) && (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KNIFE)) { - + gSaveContext.equips.buttonItems[0] = ITEM_NONE; swordEquipMask = _byteswap_ushort(gEquipMasks[EQUIP_SWORD]) & gSaveContext.equips.equipment; gSaveContext.equips.equipment &= gEquipNegMasks[EQUIP_SWORD]; diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index e45cdf27b..7c3032ba7 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -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) diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_equipment.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_equipment.c index 3c236637b..a7bf4f6e6 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_equipment.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_equipment.c @@ -64,7 +64,7 @@ void KaleidoScope_DrawEquipmentImage(GlobalContext* globalCtx, void* source, u32 gDPLoadSync(POLY_KAL_DISP++); gDPLoadTile(POLY_KAL_DISP++, G_TX_LOADTILE, 0, 0, (width - 1) << 2, (textureHeight - 1) << 2); - + gDPSetTextureImageFB(POLY_KAL_DISP++, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, fbTest); gSP1Quadrangle(POLY_KAL_DISP++, 0, 2, 3, 1, 0); @@ -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); } } } diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_item.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_item.c index bb42ff711..1a81dec9e 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_item.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_item.c @@ -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); } } diff --git a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c index a5c160700..9d45c6fbe 100644 --- a/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c +++ b/soh/src/overlays/misc/ovl_kaleido_scope/z_kaleido_scope_PAL.c @@ -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