Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
port Output_InsertFlatRect_ZBuffered
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Nov 14, 2023
1 parent ed0bf8b commit 5c2290a
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 28 deletions.
16 changes: 8 additions & 8 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ typedef enum LARA_MESH {
00409450 0000039C + const int16_t *__cdecl Output_InsertObjectG4_ZBuffered(const int16_t *obj_ptr, int32_t num, enum SORT_TYPE sort_type);
004097F0 000000F7 - void __cdecl Output_DrawPoly_Gouraud(int32_t vtx_count, int32_t red, int32_t green, int32_t blue);
004098F0 000002D3 + const int16_t *__cdecl Output_InsertObjectG3_ZBuffered(const int16_t *obj_ptr, int32_t num, enum SORT_TYPE sort_type);
00409BD0 000001C9 - void __cdecl Output_InsertFlatRect_ZBuffered(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z, uint8_t color_idx);
00409BD0 000001C9 + void __cdecl Output_InsertFlatRect_ZBuffered(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z, uint8_t color_idx);
00409DA0 00000133 - void __cdecl Output_InsertLine_ZBuffered(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z, uint8_t color_idx);
00409EE0 00000706 - void __cdecl Output_InsertGT3_Sorted(const struct PHD_VBUF *vtx0, const struct PHD_VBUF *vtx1, const struct PHD_VBUF *vtx2, const struct PHD_TEXTURE *texture, const struct PHD_UV *uv0, const struct PHD_UV *uv1, const struct PHD_UV *uv2, enum SORT_TYPE sort_type);
0040A5F0 000001AC - void __cdecl Output_InsertClippedPoly_Textured(int32_t vtx_count, float z, int16_t poly_type, int16_t tex_page);
Expand Down Expand Up @@ -2704,6 +2704,7 @@ typedef enum LARA_MESH {
00519F60 - D3DTLVERTEX *g_HWR_VertexPtr;
0051A208 - int32_t g_Input;
0051B918 - RECT g_PhdWinRect;
0051B930 - RGB888 g_GamePalette8[256];
0051BCC0 - struct APP_SETTINGS g_SavedAppSettings;
0051BD20 - char g_ErrorMessage[128];
0051BDA8 - int32_t g_MasterVolume;
Expand Down
81 changes: 64 additions & 17 deletions src/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@
>= ((c).ys - (b).ys) * ((a).xs - (b).xs))
#define MAKE_ZSORT(z) ((uint32_t)(z))

static D3DCOLOR Output_ShadeColor(uint32_t shade)
{
const uint8_t alpha = 0xFF;

uint32_t value = (0x1FFF - shade) >> 4;
CLAMPG(value, 0xFF);
static D3DCOLOR Output_ShadeLight(uint32_t shade);
static D3DCOLOR Output_ShadeColor(
uint32_t red, uint32_t green, uint32_t blue, uint8_t alpha);

static D3DCOLOR Output_ShadeColor(
uint32_t red, uint32_t green, uint32_t blue, uint8_t alpha)
{
if (g_IsShadeEffect) {
const uint32_t v45 = (value << 15) & 0xFFFF00FF;
const uint32_t v46 = ((224 * value) | v45) & 0xFFFFFF00;
return value | v46 | (alpha << 24);
red /= 2;
green = green * 7 / 8;
}
return RGBA_MAKE(red, green, blue, alpha);
}

return RGBA_MAKE(value, value, value, 0xFF);
static D3DCOLOR Output_ShadeLight(uint32_t shade)
{
uint32_t value = (0x1FFF - shade) >> 4;
CLAMPG(value, 0xFF);
return Output_ShadeColor(value, value, value, 0xFF);
}

static double Output_CalculatePolyZ(
Expand Down Expand Up @@ -3002,23 +3007,23 @@ void __cdecl Output_InsertGT3_ZBuffered(
g_VBufferD3D[0].sy = vtx0->ys;
g_VBufferD3D[0].sz = g_FltResZBuf - g_FltResZORhw * vtx0->rhw;
g_VBufferD3D[0].rhw = vtx0->rhw;
g_VBufferD3D[0].color = Output_ShadeColor(vtx0->g);
g_VBufferD3D[0].color = Output_ShadeLight(vtx0->g);
g_VBufferD3D[0].tu = (double)uv0->u / (double)PHD_ONE;
g_VBufferD3D[0].tv = (double)uv0->v / (double)PHD_ONE;

g_VBufferD3D[1].sx = vtx1->xs;
g_VBufferD3D[1].sy = vtx1->ys;
g_VBufferD3D[1].sz = g_FltResZBuf - g_FltResZORhw * vtx1->rhw;
g_VBufferD3D[1].rhw = vtx1->rhw;
g_VBufferD3D[1].color = Output_ShadeColor(vtx1->g);
g_VBufferD3D[1].color = Output_ShadeLight(vtx1->g);
g_VBufferD3D[1].tu = (double)uv1->u / (double)PHD_ONE;
g_VBufferD3D[1].tv = (double)uv1->v / (double)PHD_ONE;

g_VBufferD3D[2].sx = vtx2->xs;
g_VBufferD3D[2].sy = vtx2->ys;
g_VBufferD3D[2].sz = g_FltResZBuf - g_FltResZORhw * vtx2->rhw;
g_VBufferD3D[2].rhw = vtx2->rhw;
g_VBufferD3D[2].color = Output_ShadeColor(vtx2->g);
g_VBufferD3D[2].color = Output_ShadeLight(vtx2->g);
g_VBufferD3D[2].tu = (double)uv2->u / (double)PHD_ONE;
g_VBufferD3D[2].tv = (double)uv2->v / (double)PHD_ONE;

Expand Down Expand Up @@ -3146,31 +3151,31 @@ void __cdecl Output_InsertGT4_ZBuffered(
g_VBufferD3D[0].sy = vtx0->ys;
g_VBufferD3D[0].sz = g_FltResZBuf - g_FltResZORhw * vtx0->rhw;
g_VBufferD3D[0].rhw = vtx0->rhw;
g_VBufferD3D[0].color = Output_ShadeColor(vtx0->g);
g_VBufferD3D[0].color = Output_ShadeLight(vtx0->g);
g_VBufferD3D[0].tu = (double)texture->uv[0].u / (double)PHD_ONE;
g_VBufferD3D[0].tv = (double)texture->uv[0].v / (double)PHD_ONE;

g_VBufferD3D[1].sx = vtx1->xs;
g_VBufferD3D[1].sy = vtx1->ys;
g_VBufferD3D[1].sz = g_FltResZBuf - g_FltResZORhw * vtx1->rhw;
g_VBufferD3D[1].rhw = vtx1->rhw;
g_VBufferD3D[1].color = Output_ShadeColor(vtx1->g);
g_VBufferD3D[1].color = Output_ShadeLight(vtx1->g);
g_VBufferD3D[1].tu = (double)texture->uv[1].u / (double)PHD_ONE;
g_VBufferD3D[1].tv = (double)texture->uv[1].v / (double)PHD_ONE;

g_VBufferD3D[2].sx = vtx2->xs;
g_VBufferD3D[2].sy = vtx2->ys;
g_VBufferD3D[2].sz = g_FltResZBuf - g_FltResZORhw * vtx2->rhw;
g_VBufferD3D[2].rhw = vtx2->rhw;
g_VBufferD3D[2].color = Output_ShadeColor(vtx2->g);
g_VBufferD3D[2].color = Output_ShadeLight(vtx2->g);
g_VBufferD3D[2].tu = (double)texture->uv[2].u / (double)PHD_ONE;
g_VBufferD3D[2].tv = (double)texture->uv[2].v / (double)PHD_ONE;

g_VBufferD3D[3].sx = vtx3->xs;
g_VBufferD3D[3].sy = vtx3->ys;
g_VBufferD3D[3].sz = g_FltResZBuf - g_FltResZORhw * vtx3->rhw;
g_VBufferD3D[3].rhw = vtx3->rhw;
g_VBufferD3D[3].color = Output_ShadeColor(vtx3->g);
g_VBufferD3D[3].color = Output_ShadeLight(vtx3->g);
g_VBufferD3D[3].tu = (double)texture->uv[3].u / (double)PHD_ONE;
g_VBufferD3D[3].tv = (double)texture->uv[3].v / (double)PHD_ONE;

Expand All @@ -3180,3 +3185,45 @@ void __cdecl Output_InsertGT4_ZBuffered(
g_D3DDev, D3DPT_TRIANGLEFAN, D3DVT_TLVERTEX, g_VBufferD3D, 4,
D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS);
}

void __cdecl Output_InsertFlatRect_ZBuffered(
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z,
const uint8_t color_idx)
{
if (x2 <= x1 || y2 <= y1) {
return;
}

CLAMPL(x1, g_PhdWinMinX);
CLAMPL(y1, g_PhdWinMinY);
CLAMPG(x2, g_PhdWinWidth + g_PhdWinMinX);
CLAMPG(y2, g_PhdWinMinY + g_PhdWinHeight);
CLAMP(z, g_PhdNearZ, g_PhdFarZ);

const double rhw = g_RhwFactor / (double)z;
const double sz = g_FltResZBuf - rhw * g_FltResZORhw;

const RGB888 *const color = &g_GamePalette8[color_idx];
const D3DCOLOR d3d_color =
Output_ShadeColor(color->red, color->green, color->blue, 0xFF);

g_VBufferD3D[0].sx = (float)x1;
g_VBufferD3D[0].sy = (float)y1;
g_VBufferD3D[1].sx = (float)x2;
g_VBufferD3D[1].sy = (float)y1;
g_VBufferD3D[2].sx = (float)x1;
g_VBufferD3D[2].sy = (float)y2;
g_VBufferD3D[3].sx = (float)x2;
g_VBufferD3D[3].sy = (float)y2;
for (int i = 0; i < 4; i++) {
g_VBufferD3D[i].sz = sz;
g_VBufferD3D[i].rhw = rhw;
g_VBufferD3D[i].color = d3d_color;
}

HWR_TexSource(0);
HWR_EnableColorKey(0);
g_D3DDev->lpVtbl->DrawPrimitive(
g_D3DDev, D3DPT_TRIANGLESTRIP, D3DVT_TLVERTEX, g_VBufferD3D, 4,
D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS);
}
4 changes: 4 additions & 0 deletions src/game/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,7 @@ void __cdecl Output_InsertGT4_ZBuffered(
const struct PHD_VBUF *vtx0, const struct PHD_VBUF *vtx1,
const struct PHD_VBUF *vtx2, const struct PHD_VBUF *vtx3,
const struct PHD_TEXTURE *texture);

void __cdecl Output_InsertFlatRect_ZBuffered(
int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z,
uint8_t color_idx);
1 change: 0 additions & 1 deletion src/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define Output_InsertInventoryBackground ((void __cdecl (*)(const int16_t *obj_ptr))0x00401D50)
#define Output_DrawClippedPoly_Textured ((void __cdecl (*)(int32_t vtx_count))0x00408D70)
#define Output_DrawPoly_Gouraud ((void __cdecl (*)(int32_t vtx_count, int32_t red, int32_t green, int32_t blue))0x004097F0)
#define Output_InsertFlatRect_ZBuffered ((void __cdecl (*)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z, uint8_t color_idx))0x00409BD0)
#define Output_InsertLine_ZBuffered ((void __cdecl (*)(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t z, uint8_t color_idx))0x00409DA0)
#define Output_InsertGT3_Sorted ((void __cdecl (*)(const struct PHD_VBUF *vtx0, const struct PHD_VBUF *vtx1, const struct PHD_VBUF *vtx2, const struct PHD_TEXTURE *texture, const struct PHD_UV *uv0, const struct PHD_UV *uv1, const struct PHD_UV *uv2, enum SORT_TYPE sort_type))0x00409EE0)
#define Output_InsertClippedPoly_Textured ((void __cdecl (*)(int32_t vtx_count, float z, int16_t poly_type, int16_t tex_page))0x0040A5F0)
Expand Down
3 changes: 2 additions & 1 deletion src/global/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
#define g_IsWaterEffect (*(int32_t*)0x004D6C14)
#define g_VBuffer (*(struct VERTEX_INFO(*)[20])0x004D6CD8)
#define g_IsShadeEffect (*(int8_t*)0x004D6F78)
#define g_VBufferD3D (*(D3DTLVERTEX(*)[64])0x004D6F80)
#define g_VBufferD3D (*(D3DTLVERTEX(*)[132])0x004D6F80)
#define g_GamePalette16 (*(PALETTEENTRY(*)[256])0x004D7380)
#define g_CineFrameCurrent (*(int32_t*)0x004D7780)
#define g_IsChunkyCamera (*(int32_t*)0x004D778C)
Expand Down Expand Up @@ -125,6 +125,7 @@
#define g_HWR_VertexPtr (*(D3DTLVERTEX **)0x00519F60)
#define g_Input (*(int32_t*)0x0051A208)
#define g_PhdWinRect (*(RECT*)0x0051B918)
#define g_GamePalette8 (*(RGB888(*)[256])0x0051B930)
#define g_SavedAppSettings (*(struct APP_SETTINGS*)0x0051BCC0)
#define g_ErrorMessage (*(char(*)[128])0x0051BD20)
#define g_MasterVolume (*(int32_t*)0x0051BDA8)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ static void Inject_Output(void)
INJECT(1, 0x004093A0, Output_InsertObjectGT3_ZBuffered);
INJECT(1, 0x00409450, Output_InsertObjectG4_ZBuffered);
INJECT(1, 0x004098F0, Output_InsertObjectG3_ZBuffered);
INJECT(1, 0x00409BD0, Output_InsertFlatRect_ZBuffered);
INJECT(1, 0x0041BA50, Output_InsertPolygons_I);
}

Expand Down

0 comments on commit 5c2290a

Please sign in to comment.