fig02

lens

Jan 19th, 2022 (edited)
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void Actor_DrawLensActors(GlobalContext* globalCtx, s32 numInvisibleActors, Actor** invisibleActors) {
  2.     Actor** invisibleActor;
  3.     GraphicsContext* gfxCtx;
  4.     s32 i;
  5.  
  6.     gfxCtx = globalCtx->state.gfxCtx;
  7.  
  8.     OPEN_DISPS(gfxCtx, "../z_actor.c", 6197);
  9.  
  10.     gDPNoOpString(POLY_OPA_DISP++, "魔法のメガネ START", 0); // "Magic lens START"
  11.  
  12.     gDPPipeSync(POLY_XLU_DISP++);
  13.  
  14.     if (globalCtx->roomCtx.curRoom.showInvisActors == 0) {
  15.         // Update both the color frame buffer and the z-buffer
  16.         gDPSetOtherMode(POLY_XLU_DISP++,
  17.                         G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE |
  18.                             G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
  19.                         G_AC_THRESHOLD | G_ZS_PRIM | Z_UPD | G_RM_CLD_SURF | G_RM_CLD_SURF2);
  20.         gDPSetCombineMode(POLY_XLU_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
  21.         gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, 0, 0, 255);
  22.  
  23.         // the z-buffer will later only allow drawing inside the lens circle
  24.     } else {
  25.         // Update the z-buffer but leave the frame buffer untouched
  26.         gDPSetOtherMode(POLY_XLU_DISP++,
  27.                         G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE |
  28.                             G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
  29.                         G_AC_THRESHOLD | G_ZS_PRIM | Z_UPD | IM_RD | CVG_DST_SAVE | ZMODE_OPA | FORCE_BL |
  30.                             GBL_c1(G_BL_CLR_BL, G_BL_0, G_BL_CLR_MEM, G_BL_1MA) |
  31.                             GBL_c2(G_BL_CLR_BL, G_BL_0, G_BL_CLR_MEM, G_BL_1MA));
  32.  
  33.         // inverts the mask image, which initially is 0 inner and 74 outer,
  34.         // by setting the combiner to draw 74 - image instead of the image
  35.         gDPSetCombineLERP(POLY_XLU_DISP++, PRIMITIVE, TEXEL0, PRIM_LOD_FRAC, 0, PRIMITIVE, TEXEL0, PRIM_LOD_FRAC, 0,
  36.                           PRIMITIVE, TEXEL0, PRIM_LOD_FRAC, 0, PRIMITIVE, TEXEL0, PRIM_LOD_FRAC, 0);
  37.         gDPSetPrimColor(POLY_XLU_DISP++, 0, 0xFF, 74, 74, 74, 74);
  38.  
  39.         // the z-buffer will later only allow drawing outside the lens circle
  40.     }
  41.  
  42.     // Since `G_ZS_PRIM` is used in the other mode set above (in both branches), the depth value will be 0 as set here
  43.     // for further drawing. 0 is the closest depth value, meaning that for a pixel corresponding to such a depth value
  44.     // the z-buffer will consider any geometry drawn to that pixel to be behind something and the pixel will stay
  45.     // unchanged.
  46.     gDPSetPrimDepth(POLY_XLU_DISP++, 0, 0);
  47.  
  48.     // 0 is effectively put into the z-buffer by `Actor_DrawLensOverlay` where the mask is not fully transparent
  49.     // (alpha not 0), which can be inner or outer the lens circle depending on the branch just above.
  50.     Actor_DrawLensOverlay(gfxCtx);
  51.  
  52.     // "Magic lens invisible Actor display START"
  53.     gDPNoOpString(POLY_OPA_DISP++, "魔法のメガネ 見えないActor表示 START", numInvisibleActors);
  54.  
  55.     invisibleActor = &invisibleActors[0];
  56.     for (i = 0; i < numInvisibleActors; i++) {
  57.         // "Magic lens invisible Actor display"
  58.         gDPNoOpString(POLY_OPA_DISP++, "魔法のメガネ 見えないActor表示", i);
  59.         Actor_Draw(globalCtx, *(invisibleActor++));
  60.     }
  61.  
  62.     // "Magic lens invisible Actor display END"
  63.     gDPNoOpString(POLY_OPA_DISP++, "魔法のメガネ 見えないActor表示 END", numInvisibleActors);
  64.  
  65.     if (globalCtx->roomCtx.curRoom.showInvisActors != 0) {
  66.         // visually draw the lens mask to the framebuffer and not just the z-buffer,
  67.         // the same way the `showInvisActors == 0` branch above does
  68.  
  69.         gDPNoOpString(POLY_OPA_DISP++, "青い眼鏡(外側)", 0); // "Blue spectacles (exterior)"
  70.        
  71.         gDPPipeSync(POLY_XLU_DISP++);
  72.         gDPSetOtherMode(POLY_XLU_DISP++,
  73.                         G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE |
  74.                             G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_NPRIMITIVE,
  75.                         G_AC_THRESHOLD | G_ZS_PRIM | G_RM_CLD_SURF | G_RM_CLD_SURF2);
  76.         gDPSetCombineMode(POLY_XLU_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM);
  77.         gDPSetPrimColor(POLY_XLU_DISP++, 0, 0, 255, 0, 0, 255);
  78.  
  79.         Actor_DrawLensOverlay(gfxCtx);
  80.  
  81.         gDPNoOpString(POLY_OPA_DISP++, "青い眼鏡(外側)", 1); // "Blue spectacles (exterior)"
  82.     }
  83.  
  84.     gDPNoOpString(POLY_OPA_DISP++, "魔法のメガネ END", 0); // "Magic lens END"
  85.  
  86.     CLOSE_DISPS(gfxCtx, "../z_actor.c", 6284);
  87. }
RAW Paste Data Copied