Skip to content

Commit

Permalink
port calc_vertice_light
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 14, 2021
1 parent 5b9c160 commit 4248c60
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
12 changes: 6 additions & 6 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 @@ -23,7 +23,7 @@ HWR_VisibleZClip 0x00401A20 0x000000A9 +
phd_PutPolygons 0x00401AD0 0x000000F3 *
S_InsertRoom 0x00401BD0 0x0000006E *
calc_object_vertices 0x00401C40 0x000001B6 +
calc_vertice_light 0x00401E00 0x00000165 -
calc_vertice_light 0x00401E00 0x00000165 +
calc_roomvert 0x00401F70 0x00000428 -
phd_RotateLight 0x004023A0 0x000000CF +
phd_PointLight ---------- ---------- x
Expand Down
45 changes: 45 additions & 0 deletions src/3dsystem/3d_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,50 @@ int16_t *calc_object_vertices(int16_t *obj_ptr)
return total_clip == 0 ? obj_ptr : NULL;
}

int16_t *calc_vertice_light(int16_t *obj_ptr)
{
int32_t vertex_count = *obj_ptr++;
if (vertex_count > 0) {
if (LsDivider) {
int32_t xv = (PhdMatrixPtr->_00 * LsVectorView.x
+ PhdMatrixPtr->_10 * LsVectorView.y
+ PhdMatrixPtr->_20 * LsVectorView.z)
/ LsDivider;
int32_t yv = (PhdMatrixPtr->_01 * LsVectorView.x
+ PhdMatrixPtr->_11 * LsVectorView.y
+ PhdMatrixPtr->_21 * LsVectorView.z)
/ LsDivider;
int32_t zv = (PhdMatrixPtr->_02 * LsVectorView.x
+ PhdMatrixPtr->_12 * LsVectorView.y
+ PhdMatrixPtr->_22 * LsVectorView.z)
/ LsDivider;
for (int i = 0; i < vertex_count; i++) {
int16_t shade = LsAdder
+ ((obj_ptr[0] * xv + obj_ptr[1] * yv + obj_ptr[2] * zv)
>> 16);
CLAMP(shade, 0, 0x1FFF);
PhdVBuf[i].g = shade;
obj_ptr += 3;
}
return obj_ptr;
} else {
int16_t shade = LsAdder;
CLAMP(shade, 0, 0x1FFF);
for (int i = 0; i < vertex_count; i++) {
PhdVBuf[i].g = shade;
}
obj_ptr += 3 * vertex_count;
}
} else {
for (int i = 0; i < -vertex_count; i++) {
int16_t shade = LsAdder + *obj_ptr++;
CLAMP(shade, 0, 0x1FFF);
PhdVBuf[i].g = shade;
}
}
return obj_ptr;
}

void T1MInject3DSystem3DGen()
{
INJECT(0x00401000, phd_GenerateW2V);
Expand All @@ -503,6 +547,7 @@ void T1MInject3DSystem3DGen()
INJECT(0x004019A0, phd_TranslateAbs);
INJECT(0x00401A20, visible_zclip);
INJECT(0x00401C40, calc_object_vertices);
INJECT(0x00401E00, calc_vertice_light);
INJECT(0x004023A0, phd_RotateLight);
INJECT(0x004025D0, phd_InitWindow);
INJECT(0x004026D0, AlterFOV);
Expand Down
1 change: 1 addition & 0 deletions src/3dsystem/3d_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void phd_PushUnitMatrix();
void phd_PopMatrix();

int16_t *calc_object_vertices(int16_t *obj_ptr);
int16_t *calc_vertice_light(int16_t *obj_ptr);

void T1MInject3DSystem3DGen();

Expand Down

0 comments on commit 4248c60

Please sign in to comment.