forked from Ports/perfect_dark
updated variable names to match Ryan Dwyer's work clarifying the zbuffer behavior
This commit is contained in:
1 parent
75e34ace8c
commit
0d6c557982
6 files changed
+95
-75
No files matched your search
+4
-6
@@ -8477,7 +8477,7 @@ glabel var7f1aca90
|
|||||||
/* f0a71e4: 100002d5 */ b .L0f0a7d3c
|
/* f0a71e4: 100002d5 */ b .L0f0a7d3c
|
||||||
/* f0a71e8: 8fbf0034 */ lw $ra,0x34($sp)
|
/* f0a71e8: 8fbf0034 */ lw $ra,0x34($sp)
|
||||||
.L0f0a71ec:
|
.L0f0a71ec:
|
||||||
/* f0a71ec: 0fc5d9ad */ jal zbufDrawArtifactsOffscreen
|
/* f0a71ec: 0fc5d9ad */ jal zbufSaveArtifactDepths
|
||||||
/* f0a71f0: 8fa4014c */ lw $a0,0x14c($sp)
|
/* f0a71f0: 8fa4014c */ lw $a0,0x14c($sp)
|
||||||
/* f0a71f4: afa2014c */ sw $v0,0x14c($sp)
|
/* f0a71f4: afa2014c */ sw $v0,0x14c($sp)
|
||||||
/* f0a71f8: 0c002ca0 */ jal viPrepareZbuf
|
/* f0a71f8: 0c002ca0 */ jal viPrepareZbuf
|
||||||
@@ -9318,7 +9318,7 @@ glabel var7f1aca90
|
|||||||
/* f0a71e4: 100002d5 */ b .L0f0a7d3c
|
/* f0a71e4: 100002d5 */ b .L0f0a7d3c
|
||||||
/* f0a71e8: 8fbf0034 */ lw $ra,0x34($sp)
|
/* f0a71e8: 8fbf0034 */ lw $ra,0x34($sp)
|
||||||
.L0f0a71ec:
|
.L0f0a71ec:
|
||||||
/* f0a71ec: 0fc5d9ad */ jal zbufDrawArtifactsOffscreen
|
/* f0a71ec: 0fc5d9ad */ jal zbufSaveArtifactDepths
|
||||||
/* f0a71f0: 8fa4014c */ lw $a0,0x14c($sp)
|
/* f0a71f0: 8fa4014c */ lw $a0,0x14c($sp)
|
||||||
/* f0a71f4: afa2014c */ sw $v0,0x14c($sp)
|
/* f0a71f4: afa2014c */ sw $v0,0x14c($sp)
|
||||||
/* f0a71f8: 0c002ca0 */ jal viPrepareZbuf
|
/* f0a71f8: 0c002ca0 */ jal viPrepareZbuf
|
||||||
@@ -10159,7 +10159,7 @@ glabel var7f1aca90
|
|||||||
/* f0a4f30: 100002cd */ beqz $zero,.NB0f0a5a68
|
/* f0a4f30: 100002cd */ beqz $zero,.NB0f0a5a68
|
||||||
/* f0a4f34: 8fbf0034 */ lw $ra,0x34($sp)
|
/* f0a4f34: 8fbf0034 */ lw $ra,0x34($sp)
|
||||||
.NB0f0a4f38:
|
.NB0f0a4f38:
|
||||||
/* f0a4f38: 0fc5c4d5 */ jal zbufDrawArtifactsOffscreen
|
/* f0a4f38: 0fc5c4d5 */ jal zbufSaveArtifactDepths
|
||||||
/* f0a4f3c: 8fa40144 */ lw $a0,0x144($sp)
|
/* f0a4f3c: 8fa40144 */ lw $a0,0x144($sp)
|
||||||
/* f0a4f40: afa20144 */ sw $v0,0x144($sp)
|
/* f0a4f40: afa20144 */ sw $v0,0x144($sp)
|
||||||
/* f0a4f44: 0c002d00 */ jal viPrepareZbuf
|
/* f0a4f44: 0c002d00 */ jal viPrepareZbuf
|
||||||
@@ -10956,9 +10956,7 @@ void bgunRender(Gfx **gdlptr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef PLATFORM_N64 // TODO
|
gdl = zbufSaveArtifactDepths(gdl);
|
||||||
gdl = zbufDrawArtifactsOffscreen(gdl);
|
|
||||||
#endif
|
|
||||||
gdl = viPrepareZbuf(gdl);
|
gdl = viPrepareZbuf(gdl);
|
||||||
gdl = vi0000b1d0(gdl);
|
gdl = vi0000b1d0(gdl);
|
||||||
|
|
||||||
|
|||||||
+50
-30
@@ -439,14 +439,14 @@ void artifactsCalculateGlaresForRoom(s32 roomnum)
|
|||||||
|
|
||||||
if (index < MAX_ARTIFACTS) {
|
if (index < MAX_ARTIFACTS) {
|
||||||
#ifndef PLATFORM_N64
|
#ifndef PLATFORM_N64
|
||||||
artifact->unk02 = artifactTestLos(&spec, &g_BgRooms[roomnum].pos, xi, yi);
|
artifact->visiblelos = artifactTestLos(&spec, &g_BgRooms[roomnum].pos, xi, yi);
|
||||||
#endif
|
#endif
|
||||||
artifact->unk04 = floatToIntDepth(f0) >> 2;
|
artifact->expecteddepth = floatToIntDepth(f0) >> 2;
|
||||||
artifact->unk08 = &g_ZbufPtr1[viGetWidth() * yi + xi];
|
artifact->zbufptr = &g_ZbufPtr1[viGetWidth() * yi + xi];
|
||||||
artifact->light = &roomlights[i];
|
artifact->light = &roomlights[i];
|
||||||
artifact->type = ARTIFACTTYPE_GLARE;
|
artifact->type = ARTIFACTTYPE_GLARE;
|
||||||
artifact->unk0c.u16_2 = xi;
|
artifact->screenx = xi;
|
||||||
artifact->unk0c.u16_1 = yi;
|
artifact->screeny = yi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -457,7 +457,7 @@ void artifactsCalculateGlaresForRoom(s32 roomnum)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 func0f13d3c4(u8 arg0, u8 arg1)
|
u8 artifactsClamp(u8 arg0, u8 arg1)
|
||||||
{
|
{
|
||||||
if (arg1 >= arg0 + 7) {
|
if (arg1 >= arg0 + 7) {
|
||||||
return arg0 + 7;
|
return arg0 + 7;
|
||||||
@@ -505,18 +505,18 @@ Gfx *artifactsRenderGlaresForRoom(Gfx *gdl, s32 roomnum)
|
|||||||
u16 min;
|
u16 min;
|
||||||
u16 max;
|
u16 max;
|
||||||
f32 lightop_cur_frac;
|
f32 lightop_cur_frac;
|
||||||
s32 t2;
|
s32 numgood;
|
||||||
struct light *light;
|
struct light *light;
|
||||||
u8 *s3;
|
u8 *s3;
|
||||||
s32 k;
|
s32 k;
|
||||||
s32 count;
|
s32 count;
|
||||||
u16 t4;
|
u16 actualdepth;
|
||||||
f32 add;
|
f32 add;
|
||||||
s32 l;
|
s32 l;
|
||||||
f32 brightness;
|
f32 brightness;
|
||||||
s32 avg;
|
s32 tolerance;
|
||||||
f32 f0;
|
f32 f0;
|
||||||
s32 v1;
|
s32 difference;
|
||||||
s32 r;
|
s32 r;
|
||||||
s32 g;
|
s32 g;
|
||||||
s32 b;
|
s32 b;
|
||||||
@@ -542,6 +542,12 @@ Gfx *artifactsRenderGlaresForRoom(Gfx *gdl, s32 roomnum)
|
|||||||
struct light *light2 = artifacts[i].light;
|
struct light *light2 = artifacts[i].light;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* light arifacts are created from several, closely spaced
|
||||||
|
* textures that give the appearance of a dynamic light glare
|
||||||
|
* as the character moves. Loop to count all the sub-artifacts
|
||||||
|
* in this light.
|
||||||
|
*/
|
||||||
for (j = i; j < MAX_ARTIFACTS && artifacts[j].type == ARTIFACTTYPE_GLARE && artifacts[j].light == light2; j++) {
|
for (j = i; j < MAX_ARTIFACTS && artifacts[j].type == ARTIFACTTYPE_GLARE && artifacts[j].light == light2; j++) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
@@ -552,51 +558,65 @@ Gfx *artifactsRenderGlaresForRoom(Gfx *gdl, s32 roomnum)
|
|||||||
if (roomnum == light->roomnum) {
|
if (roomnum == light->roomnum) {
|
||||||
lightindex = ((uintptr_t)light - (uintptr_t)g_BgLightsFileData) / sizeof(struct light);
|
lightindex = ((uintptr_t)light - (uintptr_t)g_BgLightsFileData) / sizeof(struct light);
|
||||||
s3 = &var800a41a0[lightindex * 3];
|
s3 = &var800a41a0[lightindex * 3];
|
||||||
t2 = 0;
|
numgood = 0;
|
||||||
min = 0xffff;
|
min = 0xffff;
|
||||||
max = 0;
|
max = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loop to determine the min & max depth of
|
||||||
|
* the sub-artifacts composing this room light.
|
||||||
|
*/
|
||||||
for (k = i; k < i + count; k++) {
|
for (k = i; k < i + count; k++) {
|
||||||
if (artifacts[k].unk04 > max) {
|
if (artifacts[k].expecteddepth > max) {
|
||||||
max = artifacts[k].unk04;
|
max = artifacts[k].expecteddepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (artifacts[k].unk04 < min) {
|
if (artifacts[k].expecteddepth < min) {
|
||||||
min = artifacts[k].unk04;
|
min = artifacts[k].expecteddepth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
avg = (max - min) >> 1;
|
/**
|
||||||
|
* Define a depth tolerance from the min & max
|
||||||
|
* depths of sub-artifacts for a given light.
|
||||||
|
* This will be used to determine which light
|
||||||
|
* artifacts are visible when comparing depth
|
||||||
|
* values of lights to other items rendered
|
||||||
|
* on screen. Without this, the lights would
|
||||||
|
* constantly flicker due to z-fighting caused
|
||||||
|
* by the low precision of the N64 depth.
|
||||||
|
*/
|
||||||
|
tolerance = (max - min) >> 1;
|
||||||
|
|
||||||
if (avg < 25) {
|
if (tolerance < 25) {
|
||||||
avg = 25;
|
tolerance = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (k = i; k < i + count; k++) {
|
for (k = i; k < i + count; k++) {
|
||||||
#ifdef PLATFORM_N64
|
u16 expecteddepth;
|
||||||
u16 tmp;
|
actualdepth = (artifacts[k].actualdepth & 0xfffc) >> 2;
|
||||||
t4 = (artifacts[k].unk02 & 0xfffc) >> 2;
|
expecteddepth = artifacts[k].expecteddepth;
|
||||||
tmp = artifacts[k].unk04;
|
|
||||||
|
|
||||||
if (tmp < t4) {
|
if (expecteddepth < actualdepth) {
|
||||||
v1 = t4 - tmp;
|
difference = actualdepth - expecteddepth;
|
||||||
} else {
|
} else {
|
||||||
v1 = tmp - t4;
|
difference = expecteddepth - actualdepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (avg >= v1) {
|
#ifdef PLATFORM_N64
|
||||||
t2++;
|
if (difference <= tolerance) {
|
||||||
|
numgood++;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
t2 += artifacts[k].unk02;
|
numgood += artifacts[k].visiblelos;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
artifacts[k].type = ARTIFACTTYPE_FREE;
|
artifacts[k].type = ARTIFACTTYPE_FREE;
|
||||||
}
|
}
|
||||||
|
|
||||||
s3[0] = func0f13d3c4(s3[0], t2 * 2);
|
s3[0] = artifactsClamp(s3[0], numgood * 2);
|
||||||
|
|
||||||
if (t2 > 0) {
|
if (numgood > 0) {
|
||||||
brightness = viGetFovY() * 0.017453292f;
|
brightness = viGetFovY() * 0.017453292f;
|
||||||
add = cosf(brightness) / sinf(brightness) * 14.6f;
|
add = cosf(brightness) / sinf(brightness) * 14.6f;
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -2518,11 +2518,11 @@ void skyCreateSunArtifact(struct artifact *artifact, s32 x, s32 y)
|
|||||||
sunpos.x = env->suns[i].pos[0];
|
sunpos.x = env->suns[i].pos[0];
|
||||||
sunpos.y = env->suns[i].pos[1];
|
sunpos.y = env->suns[i].pos[1];
|
||||||
sunpos.z = env->suns[i].pos[2];
|
sunpos.z = env->suns[i].pos[2];
|
||||||
artifact->unk02 = artifactTestLos(&sunpos, &zero, x, y) * 0xfffc;
|
artifact->visiblelos = artifactTestLos(&sunpos, &zero, x, y) * 0xfffc;
|
||||||
#endif
|
#endif
|
||||||
artifact->unk08 = &g_ZbufPtr1[(s32)camGetScreenWidth() * y + x];
|
artifact->zbufptr = &g_ZbufPtr1[(s32)camGetScreenWidth() * y + x];
|
||||||
artifact->unk0c.u16_2 = x;
|
artifact->screenx = x;
|
||||||
artifact->unk0c.u16_1 = y;
|
artifact->screeny = y;
|
||||||
artifact->type = ARTIFACTTYPE_CIRCLE;
|
artifact->type = ARTIFACTTYPE_CIRCLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2533,7 +2533,7 @@ f32 skyGetArtifactGroupIntensityFrac(struct artifact *artifacts)
|
|||||||
s32 i;
|
s32 i;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
if (artifacts[i].type == ARTIFACTTYPE_CIRCLE && artifacts[i].unk02 == 0xfffc) {
|
if (artifacts[i].type == ARTIFACTTYPE_CIRCLE && artifacts[i].actualdepth == 0xfffc) {
|
||||||
sum += 0.125f;
|
sum += 0.125f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -177,23 +177,23 @@ u16 *zbufGetArtifactsCfb(s32 index)
|
|||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx *zbufDrawArtifactsOffscreen(Gfx *gdl)
|
Gfx *zbufSaveArtifactDepths(Gfx *gdl)
|
||||||
{
|
{
|
||||||
struct artifact *artifacts = schedGetWriteArtifacts();
|
struct artifact *artifacts = schedGetWriteArtifacts();
|
||||||
u32 stack;
|
u32 stack;
|
||||||
u16 *sp4c = g_ZbufPtr1;
|
u16 *zbuf = g_ZbufPtr1;
|
||||||
u32 s4 = 0;
|
u32 numsamples = 0;
|
||||||
u16 *sp44;
|
u16 *samples;
|
||||||
u16 *s2;
|
u16 *thissample;
|
||||||
u16 *image;
|
u16 *zbufrow;
|
||||||
s32 i;
|
s32 i;
|
||||||
|
|
||||||
viGetBackBuffer();
|
viGetBackBuffer();
|
||||||
sp44 = zbufGetArtifactsCfb(g_SchedWriteArtifactsIndex);
|
samples = zbufGetArtifactsCfb(g_SchedWriteArtifactsIndex);
|
||||||
g_SchedSpecialArtifactIndexes[g_SchedWriteArtifactsIndex] = 1;
|
g_SchedSpecialArtifactIndexes[g_SchedWriteArtifactsIndex] = 1;
|
||||||
|
|
||||||
gDPPipeSync(gdl++);
|
gDPPipeSync(gdl++);
|
||||||
gDPSetColorImage(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, viGetBufWidth(), OS_PHYSICAL_TO_K0(sp44));
|
gDPSetColorImage(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, viGetBufWidth(), OS_PHYSICAL_TO_K0(samples));
|
||||||
gDPSetScissor(gdl++, G_SC_NON_INTERLACE, 0, 0, SCREEN_320, SCREEN_240);
|
gDPSetScissor(gdl++, G_SC_NON_INTERLACE, 0, 0, SCREEN_320, SCREEN_240);
|
||||||
gDPSetCycleType(gdl++, G_CYC_COPY);
|
gDPSetCycleType(gdl++, G_CYC_COPY);
|
||||||
gDPSetTile(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0x0000, 5, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD);
|
gDPSetTile(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, 0, 0x0000, 5, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD);
|
||||||
@@ -220,24 +220,24 @@ Gfx *zbufDrawArtifactsOffscreen(Gfx *gdl)
|
|||||||
if (1);
|
if (1);
|
||||||
|
|
||||||
if (artifacts[i].type != ARTIFACTTYPE_FREE) {
|
if (artifacts[i].type != ARTIFACTTYPE_FREE) {
|
||||||
s2 = &sp44[s4];
|
thissample = &samples[numsamples];
|
||||||
image = &sp4c[artifacts[i].unk0c.u16_1 * viGetWidth()];
|
zbufrow = &zbuf[artifacts[i].screeny * viGetWidth()];
|
||||||
|
|
||||||
gDPPipeSync(gdl++);
|
gDPPipeSync(gdl++);
|
||||||
gDPSetTextureImage(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_320, image);
|
gDPSetTextureImage(gdl++, G_IM_FMT_RGBA, G_IM_SIZ_16b, SCREEN_320, zbufrow);
|
||||||
gDPLoadSync(gdl++);
|
gDPLoadSync(gdl++);
|
||||||
gDPLoadBlock(gdl++, 5, 0, 0, viGetWidth() - 1, 0);
|
gDPLoadBlock(gdl++, 5, 0, 0, viGetWidth() - 1, 0);
|
||||||
gDPPipeSync(gdl++);
|
gDPPipeSync(gdl++);
|
||||||
|
|
||||||
gSPTextureRectangle(gdl++,
|
gSPTextureRectangle(gdl++,
|
||||||
s4 << 2, 0,
|
numsamples << 2, 0,
|
||||||
(s4 + 3) << 2, 0,
|
(numsamples + 3) << 2, 0,
|
||||||
G_TX_RENDERTILE, (artifacts[i].unk0c.u16_2 * 32) + 16, 0x0010, 0x1000, 0);
|
G_TX_RENDERTILE, (artifacts[i].screenx * 32) + 16, 0x0010, 0x1000, 0);
|
||||||
|
|
||||||
artifacts[i].unk0c.u16p = s2;
|
artifacts[i].depthptr = thissample;
|
||||||
s4++;
|
numsamples++;
|
||||||
|
|
||||||
if (s2);
|
if (thissample);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,7 +251,7 @@ Gfx *zbufDrawArtifactsOffscreen(Gfx *gdl)
|
|||||||
gDPSetTexturePersp(gdl++, G_TP_PERSP);
|
gDPSetTexturePersp(gdl++, G_TP_PERSP);
|
||||||
gDPSetColorDither(gdl++, G_CD_BAYER);
|
gDPSetColorDither(gdl++, G_CD_BAYER);
|
||||||
|
|
||||||
if (sp44);
|
if (samples);
|
||||||
|
|
||||||
return gdl;
|
return gdl;
|
||||||
}
|
}
|
||||||
+10
-8
@@ -3494,17 +3494,19 @@ struct audioconfig {
|
|||||||
|
|
||||||
struct artifact {
|
struct artifact {
|
||||||
u16 type;
|
u16 type;
|
||||||
u16 unk02;
|
u16 actualdepth;
|
||||||
u16 unk04;
|
u16 expecteddepth;
|
||||||
u16 unk06;
|
u16 *zbufptr;
|
||||||
u16 *unk08;
|
#ifndef PLATFORM_N64
|
||||||
|
u16 visiblelos;
|
||||||
|
#endif
|
||||||
union {
|
union {
|
||||||
u16 *u16p;
|
u16 *depthptr;
|
||||||
struct {
|
struct {
|
||||||
u16 u16_1;
|
u16 screeny;
|
||||||
u16 u16_2;
|
u16 screenx;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
} unk0c;
|
|
||||||
struct light *light;
|
struct light *light;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -540,20 +540,20 @@ void schedUpdatePendingArtifacts(void)
|
|||||||
struct artifact *artifact = &artifacts[i];
|
struct artifact *artifact = &artifacts[i];
|
||||||
|
|
||||||
if (artifact->type != ARTIFACTTYPE_FREE) {
|
if (artifact->type != ARTIFACTTYPE_FREE) {
|
||||||
u16 *unk08 = artifact->unk08;
|
u16 *currdepthptr = artifact->zbufptr;
|
||||||
u16 value08 = unk08[0];
|
u16 currdepth = *currdepthptr;
|
||||||
|
|
||||||
if (g_SchedSpecialArtifactIndexes[g_SchedPendingArtifactsIndex] == 1) {
|
if (g_SchedSpecialArtifactIndexes[g_SchedPendingArtifactsIndex] == 1) {
|
||||||
u16 *unk0c = artifact->unk0c.u16p;
|
u16 *prevdepthptr = artifact->depthptr;
|
||||||
u16 value0c = unk0c[0];
|
u16 prevdepth = *prevdepthptr;
|
||||||
|
|
||||||
if (value0c > value08) {
|
if (currdepth < prevdepth) {
|
||||||
artifact->unk02 = value08;
|
artifact->actualdepth = currdepth;
|
||||||
} else {
|
} else {
|
||||||
artifact->unk02 = value0c;
|
artifact->actualdepth = prevdepth;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
artifact->unk02 = value08;
|
artifact->actualdepth = currdepth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user