narzoul / DDrawCompat

DirectDraw and Direct3D 1-7 compatibility, performance and visual enhancements for Windows Vista, 7, 8, 10 and 11
BSD Zero Clause License
885 stars 67 forks source link

Panzer Commander transparency issue #200

Closed BEENNath58 closed 7 months ago

BEENNath58 commented 1 year ago

I was surprised to see every wrapper out there has problem with the game. There are different issues:

  1. Skybox overlapping game surface: The game screen gets overlapped by whatever the sky is. pcommandgrey

  2. Transparency: The game has transparency issues with many elements, such as the home roof. badtransparency

The game has issues with multi-core, consider using single core affinity to avoid major troubles.

narzoul commented 1 year ago

The first issue is fixable by limiting FPS to 30, which also seems to fix the game screen freezing after a short time in the 3D part.

The second issue took a few days of debugging. The creation of the z-buffer depends on an uninitialized stack value being zero. If it happens to be non-zero, then no z-buffer is created, hence the "transparency" issues.

The DWORD value in question comes from offset 44 of the lpContext parameter of a DirectDrawEnumerateA call. lpContext itself is a pointer to a 10888 bytes long uninitialized stack allocation, at least in the v1.3 patch.

According to IDA, the allocation is created via a function that it calls __alloca_probe, which is apparently used for stack allocations larger than a page size (4KB). I opted to replace this function with code that zero-initializes the allocated stack space, which resolves the z-buffer creation issue, and maybe some others.

Use a hex editor to replace this in panzer.exe: 513D001000008D4C2408721481E9001000002D0010000085013D0010000073EC2BC88BC485018BE18B088B400450C3 with this: 9C5156578D48EC89E74F31C0FDF3AA8D742413B914000000F3A44789FC8D7E11B905000000F3AB5F5E599DC3CCCCCC

I've only tested it with the v1.3 patch, but there's a good chance it works with other versions too.

There are also some issues when using palettized textures with DDrawCompat (poor performance and some textures are missing), but since the game works fine without them, I will check it with low prio. For now, I recommend the following settings for DDrawCompat:

AlternatePixelCenter = on
FpsLimiter = flipend(30)
PalettizedTextures = off

Even with AlternatePixelCenter, there is a 1-pixel border around the screen in the 3D part that I assume shouldn't be there, but that might just be another bug in the game, since it's there even on WinXP. Plus, the borders on the bottom and right sides are there even with the software renderer (which can be enabled with the Accel=FALSE setting in panzer.ini).

superblobster commented 1 year ago

@narzoul Fantastic work. Thanks so much, man!

This has been one of my holy grails. I've been trying to run this game on modern computers for ten years with mixed results. Several years ago it was possible on W7/10 with various compatibility modes and dgvoodoo. Then an unknown W10 or possibly Nvidia update broke something that affected the z-buffer and since then I've been unable to get it working without the transparent models bug. Until now, thanks to you.

Panzer Commander is very buggy and different versions have responded differently to all the compatibility fixes I've tried over the years. It has issues on period-correct hardware too.

The game is notable for its surprisingly advanced track physics and many challenging campaigns.

For players, I recommend adding this to ddrawcompat.ini for higher internal resolution: ResolutionScale=display

Screenshot 2023-03-26 022725

Additionally, I use these settings in the game's config.ini to improve draw distances and turn off fog for better visibility:

TextureThreshold = 7000   ; Distance at which texture mapping ends (meters)
PerspectiveThreshold = 1000  ; Distance at which perspective correction ends (meters)
HighPolyThreshold = 7500   ; Distance at which high-polygon models are used
PhysicsThreshold = 1000   ; Distance at which physics is enabled
SimWindowSize = 100   ; Size of main sim window
MaxViewDistance = 100   ; Distance beyond which no polygons are rendered
TextureSmoothing = TRUE   ; Allow smooth-shaded texture mapping
TextureFilter = TRUE   ; Bilinear or equivalent filtering on/off
Subpixel = TRUE    ; Subpixel correction on/off
AlphaBlend = TRUE  ; Alpha blending allowed for translucency effects
Dithering = TRUE   ; Dithered colors reduces color banding
PalettizedTextures = TRUE   ; Set 3D Hardware to use palettized textures
ColorKeyTextures = TRUE   ; Allow use of color keyed textures
FogEffect = FALSE   ; Allow atmospheric effects
SkyTexture = TRUE    ; Bitmap Sky
Particle = TRUE    ; Allow particle effects for explosions, etc
RealPhysics = TRUE   ; Allow real suspension physics rather than simplified physics
Smoke = TRUE   ; Smoke and Dust effects
TreadTracks = TRUE   ; Tread tracks left by tanks
ParallaxForests = TRUE   ; Double layered forests with front plane transparent
CoveredForests = FALSE   ; Roofs on forests
narzoul commented 7 months ago

I disabled PalettizedTextures by default in v0.5.0 because it caused more problems than it solved. For the very few cases where it's actually needed (Final Fantasy 7 and 8?) it can be enabled through the configuration instead. As far as I can see, there were no other fixes needed from DDrawCompat here, so closing this.