11#include " iScrFX.h"
22
3+ #include " rwplcore.h"
34#include < types.h>
45
5- extern RwRaster* g_rast_gctapdance;
6- extern S32 g_alreadyTriedAlloc;
7- extern _iMotionBlurData sMBD ;
8- extern U32 sMotionBlurEnabled ;
9- extern F32 lbl_803CE168; // 0.0f
10- extern F32 lbl_803CE174; // 1.0f
11- extern F32 lbl_803CE178; // 0.5f
12- extern F32 lbl_803CE17C; // 254f
6+ static U32 sMotionBlurEnabled ;
7+ static RwRaster* g_rast_gctapdance;
8+ static S32 g_alreadyTriedAlloc;
9+ static _iMotionBlurData sMBD = {};
1310
1411void iScrFxInit ()
1512{
@@ -22,22 +19,49 @@ void iScrFxBegin()
2219 RwRenderStateSet (rwRENDERSTATEZTESTENABLE, NULL );
2320 RwRenderStateSet (rwRENDERSTATEZWRITEENABLE, NULL );
2421 RwRenderStateSet (rwRENDERSTATETEXTURERASTER, NULL );
25- RwRenderStateSet (rwRENDERSTATEVERTEXALPHAENABLE, (void *)true );
22+ RwRenderStateSet (rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE );
2623 RwRenderStateSet (rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
2724 RwRenderStateSet (rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
2825}
2926
3027void iScrFxEnd ()
3128{
3229 RwRenderStateSet (rwRENDERSTATEFOGENABLE, (void *)rwFOGTYPENAFOGTYPE);
33- RwRenderStateSet (rwRENDERSTATEZTESTENABLE, (void *)true );
34- RwRenderStateSet (rwRENDERSTATEZWRITEENABLE, (void *)true );
30+ RwRenderStateSet (rwRENDERSTATEZTESTENABLE, (void *)TRUE );
31+ RwRenderStateSet (rwRENDERSTATEZWRITEENABLE, (void *)TRUE );
3532 RwRenderStateSet (rwRENDERSTATETEXTURERASTER, NULL );
36- RwRenderStateSet (rwRENDERSTATEVERTEXALPHAENABLE, (void *)false );
33+ RwRenderStateSet (rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE );
3734 RwRenderStateSet (rwRENDERSTATESRCBLEND, (void *)rwBLENDONE);
3835 RwRenderStateSet (rwRENDERSTATEDESTBLEND, (void *)rwBLENDZERO);
3936}
4037
38+ void iScrFxDrawBox (F32 x1, F32 y1, F32 x2, F32 y2, U8 red, U8 green, U8 blue, U8 alpha)
39+ {
40+ U16 indices[4 ] = { 0 , 1 , 2 , 3 };
41+ rwGameCube2DVertex v[4 ];
42+ F32 nearZ = RwIm2DGetNearScreenZ ();
43+
44+ RwIm2DVertexSetScreenX (&v[0 ], x1);
45+ RwIm2DVertexSetScreenY (&v[0 ], y1);
46+ RwIm2DVertexSetScreenZ (&v[0 ], nearZ);
47+ RwIm2DVertexSetScreenX (&v[1 ], x2);
48+ RwIm2DVertexSetScreenY (&v[1 ], y1);
49+ RwIm2DVertexSetScreenZ (&v[1 ], nearZ);
50+ RwIm2DVertexSetScreenX (&v[2 ], x1);
51+ RwIm2DVertexSetScreenY (&v[2 ], y2);
52+ RwIm2DVertexSetScreenZ (&v[2 ], nearZ);
53+ RwIm2DVertexSetScreenX (&v[3 ], x2);
54+ RwIm2DVertexSetScreenY (&v[3 ], y2);
55+ RwIm2DVertexSetScreenZ (&v[3 ], nearZ);
56+
57+ for (S32 i = 0 ; i < 4 ; i++)
58+ {
59+ RwIm2DVertexSetRealRGBA (&v[i], red, green, blue, alpha);
60+ }
61+
62+ RwIm2DRenderIndexedPrimitive (rwPRIMTYPETRISTRIP, v, 4 , indices, 4 );
63+ }
64+
4165void iCameraMotionBlurActivate (U32 activate)
4266{
4367 sMotionBlurEnabled = activate;
@@ -46,18 +70,19 @@ void iCameraMotionBlurActivate(U32 activate)
4670// The instructions regarding the setting of sMotionBlurEnabled and sMBD.motionBlurAlpha are in the wrong order.
4771void iCameraSetBlurriness (F32 amount)
4872{
49- if (amount <= lbl_803CE168 )
73+ if (amount <= 0 . 0f )
5074 {
51- sMotionBlurEnabled = 0 ;
75+ sMotionBlurEnabled = FALSE ;
5276 }
5377 else
5478 {
55- if (amount > lbl_803CE174 )
79+ if (amount > 1 . 0f )
5680 {
57- amount = lbl_803CE174 ;
81+ amount = 1 . 0f ;
5882 }
59- sMotionBlurEnabled = 1 ;
60- sMBD .motionBlurAlpha = (S32)(lbl_803CE17C * amount + lbl_803CE178);
83+ sMotionBlurEnabled = TRUE ;
84+
85+ sMBD .motionBlurAlpha = 254 .0f * amount + 0 .5f ;
6186 }
6287}
6388
@@ -77,7 +102,7 @@ void iScrFxCameraCreated(RwCamera* pCamera)
77102
78103void iScrFxCameraEndScene (RwCamera* pCamera)
79104{
80- if (( sMotionBlurEnabled != 0 ) && ( sMBD .motionBlurAlpha != 0 ) )
105+ if (sMotionBlurEnabled && sMBD .motionBlurAlpha != 0 )
81106 {
82107 iScrFxMotionBlurRender (pCamera, sMBD .motionBlurAlpha & 0xff );
83108 }
@@ -88,7 +113,46 @@ void iScrFxPostCameraEnd(RwCamera* pCamera)
88113 GCMB_SiphonFrameBuffer (pCamera);
89114}
90115
91- RwRaster* FBMBlur_DebugIntervention (RwCamera* camera, RwRaster* ras)
116+ static void iCameraOverlayRender (RwCamera* pCamera, RwRaster* ras, RwRGBA col)
117+ {
118+ // RwRect rect; // from dwarf, not sure where it's used
119+ RwRaster* raster = FBMBlur_DebugIntervention (pCamera, ras);
120+
121+ for (S32 i = 0 ; i < 4 ; i++)
122+ {
123+ sMBD .vertex [i].emissiveColor .red = col.red ;
124+ sMBD .vertex [i].emissiveColor .green = col.green ;
125+ sMBD .vertex [i].emissiveColor .blue = col.blue ;
126+ sMBD .vertex [i].emissiveColor .alpha = col.alpha ;
127+ }
128+
129+ RwRenderStateSet (rwRENDERSTATETEXTUREFILTER, (void *)TRUE );
130+ RwRenderStateSet (rwRENDERSTATEFOGENABLE, (void *)FALSE );
131+ RwRenderStateSet (rwRENDERSTATEZTESTENABLE, (void *)FALSE );
132+ RwRenderStateSet (rwRENDERSTATEZWRITEENABLE, (void *)FALSE );
133+ RwRenderStateSet (rwRENDERSTATETEXTURERASTER, raster);
134+ RwRenderStateSet (rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE );
135+ RwRenderStateSet (rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
136+ RwRenderStateSet (rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
137+ if (raster != 0 )
138+ {
139+ RwRasterLock (raster, 0 , 2 );
140+ }
141+ RwIm2DRenderIndexedPrimitive (rwPRIMTYPETRILIST, sMBD .vertex , 4 , sMBD .index , 6 );
142+ if (raster != 0 )
143+ {
144+ RwRasterUnlock (raster);
145+ }
146+ RwRenderStateSet (rwRENDERSTATEFOGENABLE, (void *)FALSE );
147+ RwRenderStateSet (rwRENDERSTATEZTESTENABLE, (void *)TRUE );
148+ RwRenderStateSet (rwRENDERSTATEZWRITEENABLE, (void *)TRUE );
149+ RwRenderStateSet (rwRENDERSTATETEXTURERASTER, NULL );
150+ RwRenderStateSet (rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE );
151+ RwRenderStateSet (rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
152+ RwRenderStateSet (rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
153+ }
154+
155+ inline RwRaster* FBMBlur_DebugIntervention (RwCamera* camera, RwRaster* ras)
92156{
93157 return ras;
94158}
@@ -110,13 +174,11 @@ S32 iScrFxCameraDestroyed(RwCamera* pCamera)
110174 return 0 ;
111175}
112176
113- // WIP.
114- void iScrFxMotionBlurRender (RwCamera* camera, U32 col)
177+ void iScrFxMotionBlurRender (RwCamera* camera, U32 alpha)
115178{
116179 if (sMBD .motionBlurFrontBuffer != NULL )
117180 {
118- RwRGBA col;
119- col.alpha = 0xf8 ;
181+ RwRGBA col = { 0xff , 0xff , 0xff , (U8)alpha };
120182 iCameraOverlayRender (camera, (RwRaster*)sMBD .motionBlurFrontBuffer , col);
121183 }
122184}
0 commit comments