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

Commit

Permalink
port Output_InsertPoly_Gouraud
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Nov 15, 2023
1 parent 8ea224a commit 0eb9d0d
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 10 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.
2 changes: 1 addition & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ typedef enum LARA_MESH {
0040AC80 0000008C + const int16_t *__cdecl Output_InsertObjectGT4_Sorted(const int16_t *obj_ptr, int32_t num, enum SORT_TYPE sort_type);
0040AD10 0000009F + const int16_t *__cdecl Output_InsertObjectGT3_Sorted(const int16_t *obj_ptr, int32_t num, enum SORT_TYPE sort_type);
0040ADB0 0000043B + const int16_t *__cdecl Output_InsertObjectG4_Sorted(const int16_t *obj_ptr, int32_t num, enum SORT_TYPE sort_type);
0040B1F0 00000175 - void __cdecl Output_InsertPoly_Gouraud(int32_t vtx_count, float z, int32_t red, int32_t green, int32_t blue, int16_t poly_type);
0040B1F0 00000175 + void __cdecl Output_InsertPoly_Gouraud(int32_t vtx_count, float z, int32_t red, int32_t green, int32_t blue, int16_t poly_type);
0040B370 00000343 + const int16_t *__cdecl Output_InsertObjectG3_Sorted(const int16_t *obj_ptr, int32_t num, enum SORT_TYPE sort_type);
0040B6C0 00000347 + void __cdecl Output_InsertSprite_Sorted(int32_t z, int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t sprite_idx, int16_t shade);
0040BA10 0000017F + void __cdecl Output_InsertFlatRect_Sorted(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t z, uint8_t color_idx);
Expand Down
58 changes: 58 additions & 0 deletions src/game/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
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_ShadeLightColor(
uint32_t shade, uint32_t red, uint32_t green, uint32_t blue, uint8_t alpha);
static double Output_CalculatePolyZ(
enum SORT_TYPE sort_type, double z0, double z1, double z2, double z3);

static void __fastcall Output_FlatA(int32_t y1, int32_t y2, uint8_t color_idx);
static void __fastcall Output_TransA(int32_t y1, int32_t y2, uint8_t depth_q);
static void __fastcall Output_GourA(int32_t y1, int32_t y2, uint8_t color_idx);
static void __fastcall Output_GTMapA(
int32_t y1, int32_t y2, const uint8_t *tex_page);
static void __fastcall Output_WGTMapA(
int32_t y1, int32_t y2, const uint8_t *tex_page);
static inline void Output_ClipG(
struct VERTEX_INFO *const buf, const struct VERTEX_INFO *const vtx1,
const struct VERTEX_INFO *const vtx2, const float clip);
static inline void Output_ClipGUV(
struct VERTEX_INFO *const buf, const struct VERTEX_INFO *const vtx1,
const struct VERTEX_INFO *const vtx2, const float clip);

static D3DCOLOR Output_ShadeColor(
uint32_t red, uint32_t green, uint32_t blue, uint8_t alpha)
Expand All @@ -34,6 +52,16 @@ static D3DCOLOR Output_ShadeLight(uint32_t shade)
return Output_ShadeColor(value, value, value, 0xFF);
}

static D3DCOLOR Output_ShadeLightColor(
uint32_t shade, uint32_t red, uint32_t green, uint32_t blue, uint8_t alpha)
{
shade = 0x1FFF - shade;
red = (red * shade) >> 12;
green = (green * shade) >> 12;
blue = (blue * shade) >> 12;
return Output_ShadeColor(red, green, blue, alpha);
}

static double Output_CalculatePolyZ(
enum SORT_TYPE sort_type, double z0, double z1, double z2, double z3)
{
Expand Down Expand Up @@ -4106,3 +4134,33 @@ void __cdecl Output_InsertClippedPoly_Textured(
g_HWR_VertexPtr += vtx_count;
g_SurfaceCount++;
}

void __cdecl Output_InsertPoly_Gouraud(
const int32_t vtx_count, const float z, const int32_t red,
const int32_t green, const int32_t blue, const int16_t poly_type)
{
g_Sort3DPtr->_0 = (int32_t)g_Info3DPtr;
g_Sort3DPtr->_1 = MAKE_ZSORT(z);
g_Sort3DPtr++;

*g_Info3DPtr++ = poly_type;
*g_Info3DPtr++ = vtx_count;
*(D3DTLVERTEX **)g_Info3DPtr = g_HWR_VertexPtr;
g_Info3DPtr += sizeof(D3DTLVERTEX *) / sizeof(int16_t);

for (int i = 0; i < vtx_count; i++) {
g_HWR_VertexPtr[i].sx = g_VBuffer[i].x;
g_HWR_VertexPtr[i].sy = g_VBuffer[i].y;
if (g_SavedAppSettings.zbuffer) {
g_HWR_VertexPtr[i].sz =
g_FltResZBuf - g_FltResZORhw * g_VBuffer[0].rhw;
}
g_HWR_VertexPtr[i].rhw = g_VBuffer[0].rhw;
g_HWR_VertexPtr[i].color = Output_ShadeLightColor(
g_VBuffer[i].g, red, green, blue,
poly_type == POLY_HWR_TRANS ? 0x80 : 0xFF);
}

g_HWR_VertexPtr += vtx_count;
g_SurfaceCount++;
}
4 changes: 4 additions & 0 deletions src/game/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ const int16_t *__cdecl Output_InsertRoomSprite(

void __cdecl Output_InsertClippedPoly_Textured(
int32_t vtx_count, float z, int16_t poly_type, int16_t tex_page);

void __cdecl Output_InsertPoly_Gouraud(
int32_t vtx_count, float z, int32_t red, int32_t green, int32_t blue,
int16_t poly_type);
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_InsertPoly_Gouraud ((void __cdecl (*)(int32_t vtx_count, float z, int32_t red, int32_t green, int32_t blue, int16_t poly_type))0x0040B1F0)
#define Output_DrawSprite ((void __cdecl (*)(uint32_t flags, int32_t x, int32_t y, int32_t z, int16_t sprite_idx, int16_t shade, int16_t scale))0x0040C050)
#define Output_DrawPickup ((void __cdecl (*)(int32_t sx, int32_t sy, int32_t scale, int16_t sprite_idx, int16_t shade))0x0040C320)
#define Output_DrawScreenSprite2D ((void __cdecl (*)(int32_t sx, int32_t sy, int32_t sz, int32_t scale_h, int32_t scale_v, int16_t sprite_idx, int16_t shade, uint16_t flags))0x0040C510)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static void Inject_Output(void)
INJECT(1, 0x0040AC80, Output_InsertObjectGT4_Sorted);
INJECT(1, 0x0040AD10, Output_InsertObjectGT3_Sorted);
INJECT(1, 0x0040ADB0, Output_InsertObjectG4_Sorted);
INJECT(1, 0x0040B1F0, Output_InsertPoly_Gouraud);
INJECT(1, 0x0040B370, Output_InsertObjectG3_Sorted);
INJECT(1, 0x0040B6C0, Output_InsertSprite_Sorted);
INJECT(1, 0x0040BA10, Output_InsertFlatRect_Sorted);
Expand Down

0 comments on commit 0eb9d0d

Please sign in to comment.