summaryrefslogtreecommitdiff
path: root/mm/2s2h/Enhancements/Graphics/FlatShading.cpp
blob: 523c8fd1200ac3d1165927fbea6a742820b9182b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <libultraship/bridge/consolevariablebridge.h>
#include "2s2h/GameInteractor/GameInteractor.h"
#include "2s2h/BenGui/CosmeticEditor.h"
#include "2s2h/Enhancements/FrameInterpolation/FrameInterpolation.h"
#include "2s2h/ShipInit.hpp"

extern "C" {
#include "align_asset_macro.h"
extern PlayState* gPlayState;
}

#define CVAR_NAME CVAR_SILLY_FLAT_SHADING
#define CVAR CVarGetInteger(CVAR_NAME, 0)

static const ALIGN_ASSET(2) char sFlatShader[] = "__OTR__shaders/flatavg";

void RegisterFlatShading() {
    COND_HOOK(OnPlayDrawWorldStart, CVAR, []() {
        OPEN_DISPS(gPlayState->state.gfxCtx);
        gSPPushShader(POLY_OPA_DISP++, sFlatShader);
        gSPPushShader(POLY_XLU_DISP++, sFlatShader);
        CLOSE_DISPS(gPlayState->state.gfxCtx);
    });

    COND_HOOK(OnPlayDrawWorldEnd, CVAR, []() {
        OPEN_DISPS(gPlayState->state.gfxCtx);
        gSPPopShader(POLY_OPA_DISP++);
        gSPPopShader(POLY_XLU_DISP++);
        CLOSE_DISPS(gPlayState->state.gfxCtx);
    });
}

static RegisterShipInitFunc initFunc(RegisterFlatShading, { CVAR_NAME });