Skip to content

Commit

Permalink
Z-Buffered mode is improved. Now every polygon is sorted and Z-Buffer…
Browse files Browse the repository at this point in the history
…ed, but sprites ignore Z-Buffer
  • Loading branch information
Arsunt committed Jul 6, 2020
1 parent 52541f4 commit 464e654
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 10 deletions.
38 changes: 30 additions & 8 deletions 3dsystem/3d_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,18 +573,35 @@ void __cdecl S_InsertBackground(__int16 *ptrObj) {

ptrObj += 4; // skip x, y, z, radius
ptrObj = calc_object_vertices(ptrObj);
if( ptrObj != NULL ) {
if( SavedAppSettings.RenderMode == RM_Hardware )
HWR_EnableZBuffer(false, false);
if( ptrObj == NULL ) {
return;
}
ptrObj = calc_background_light(ptrObj);

ptrObj = calc_background_light(ptrObj);
if( SavedAppSettings.RenderMode == RM_Hardware ) {
HWR_EnableZBuffer(false, false);
}
#ifdef FEATURE_VIDEOFX_IMPROVED
if( SavedAppSettings.RenderMode == RM_Hardware
&& SavedAppSettings.ZBuffer
&& !SavedAppSettings.DontSortPrimitives )
{
// NOTE: just draw background unsorted right now with ZBuffer disabled
ptrObj = InsertObjectGT4_ZBuffered(ptrObj+1, *ptrObj, ST_FarZ);
ptrObj = InsertObjectGT3_ZBuffered(ptrObj+1, *ptrObj, ST_FarZ);
ptrObj = InsertObjectG4_ZBuffered(ptrObj+1, *ptrObj, ST_FarZ);
ptrObj = InsertObjectG3_ZBuffered(ptrObj+1, *ptrObj, ST_FarZ);
}
else
#endif // FEATURE_VIDEOFX_IMPROVED
{
ptrObj = ins_objectGT4(ptrObj+1, *ptrObj, ST_FarZ);
ptrObj = ins_objectGT3(ptrObj+1, *ptrObj, ST_FarZ);
ptrObj = ins_objectG4(ptrObj+1, *ptrObj, ST_FarZ);
ptrObj = ins_objectG3(ptrObj+1, *ptrObj, ST_FarZ);

if( SavedAppSettings.RenderMode == RM_Hardware )
HWR_EnableZBuffer(true, true);
}
if( SavedAppSettings.RenderMode == RM_Hardware ) {
HWR_EnableZBuffer(true, true);
}
}

Expand Down Expand Up @@ -976,7 +993,12 @@ void __cdecl phd_InitWindow(__int16 x, __int16 y, int width, int height, int nea
ins_trans_quad = InsertTransQuad;
}
else if( SavedAppSettings.RenderMode == RM_Hardware ) {
if( SavedAppSettings.ZBuffer ) {
#ifdef FEATURE_VIDEOFX_IMPROVED
if( SavedAppSettings.ZBuffer && SavedAppSettings.DontSortPrimitives )
#else // !FEATURE_VIDEOFX_IMPROVED
if( SavedAppSettings.ZBuffer )
#endif // !FEATURE_VIDEOFX_IMPROVED
{
ins_objectGT3 = InsertObjectGT3_ZBuffered;
ins_objectGT4 = InsertObjectGT4_ZBuffered;
ins_objectG3 = InsertObjectG3_ZBuffered;
Expand Down
4 changes: 2 additions & 2 deletions 3dsystem/3dinsert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2650,7 +2650,7 @@ void __cdecl InsertSprite_Sorted(int z, int x0, int y0, int x1, int y1, int spri

IsShadeEffect = 0;
#ifdef FEATURE_VIDEOFX_IMPROVED
short polyType = POLY_HWR_WGTmap;
short polyType = POLY_Z_IGNORE | POLY_HWR_WGTmap;
if( CHK_ANY(flags, SPR_TINT) ) {
GlobalTint = RGBA_SETALPHA(flags, 0xFF);
}
Expand All @@ -2661,7 +2661,7 @@ void __cdecl InsertSprite_Sorted(int z, int x0, int y0, int x1, int y1, int spri
POLY_HWR_WGTmapSub,
POLY_HWR_WGTmapQrt,
};
polyType = blend[(flags & SPR_BLEND) >> 29];
polyType = POLY_Z_IGNORE | blend[(flags & SPR_BLEND) >> 29];
}
InsertClippedPoly_Textured(nPoints, (float)z, polyType, PhdSpriteInfo[spriteIdx].texPage);
GlobalTint = 0;
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added Dozy cheat on *O* key (cheat flag in *"TOMBPC.DAT"* file required). It gives fly mode and full health, use *Shift* key to disable it.
- Lara has golden skin while in Dozy mode (hardware renderer and reflection feature required).
- SFX number limit increased from 256 to 370.
- Z-Buffered mode is improved. Now every polygon is sorted and Z-Buffered, but sprites ignore Z-Buffer, so they're rendered properly, as if Z-Buffer was disabled.
- The "Don't sort transparent polys"* setting from the *"Advanced"* tab has been redesigned to disable the new Z-Buffered mode, instead of just messing the transparent polys (it is recommended to keep this setting unchecked anyway).

### The original game bugfixes
- Fixed a bug that prevented the display of the save counter until the game relaunch, if the game was saved in an empty slot.
Expand Down
4 changes: 4 additions & 0 deletions global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ typedef struct {
#define IFL_REVERSE (0x4000)
#define IFL_CLEARBODY (0x8000)

// HWR poly sort flags
#define POLY_TYPEMASK (0x7FFF)
#define POLY_Z_IGNORE (0x8000)

// Glow tint colors
#define GLOW_FLARE_COLOR (0xFF8080) // Flare
#define GLOW_PISTOL_COLOR (0x3F380F) // Pistol/Magnums/Uzi gunfire
Expand Down
14 changes: 14 additions & 0 deletions specific/hwr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,20 @@ void __cdecl HWR_DrawPolyList() {
bufPtr = (UINT16 *)SortBuffer[i]._0;

polyType = *(bufPtr++);
#ifdef FEATURE_VIDEOFX_IMPROVED
if( SavedAppSettings.ZBuffer && !SavedAppSettings.DontSortPrimitives ) {
bool zCheck = !CHK_ANY(polyType, POLY_Z_IGNORE);
bool zWrite = false;
switch( polyType & POLY_TYPEMASK ) {
case POLY_HWR_GTmap:
case POLY_HWR_gouraud:
zWrite = true;
break;
}
HWR_EnableZBuffer(zWrite, zCheck);
}
polyType &= POLY_TYPEMASK;
#endif // FEATURE_VIDEOFX_IMPROVED
#ifdef FEATURE_HUD_IMPROVED
if( polyType == POLY_HWR_healthbar || polyType == POLY_HWR_airbar ) {
UINT16 x0 = *(bufPtr++);
Expand Down
5 changes: 5 additions & 0 deletions specific/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,14 @@ void __cdecl S_OutputPolyList() {
}
} else {
// Hardware renderer
#ifdef FEATURE_VIDEOFX_IMPROVED
// NOTE: DontSortPrimitives option is redesigned to affect opaque only polygons
phd_SortPolyList();
#else // !FEATURE_VIDEOFX_IMPROVED
if( !SavedAppSettings.ZBuffer || !SavedAppSettings.DontSortPrimitives ) {
phd_SortPolyList();
}
#endif // !FEATURE_VIDEOFX_IMPROVED
HWR_DrawPolyList();
D3DDev->EndScene();
}
Expand Down

0 comments on commit 464e654

Please sign in to comment.