cnc-ddraw icon indicating copy to clipboard operation
cnc-ddraw copied to clipboard

Age of Empires 2 and for of war

Open Mitradis opened this issue 2 years ago • 2 comments

This problem is not related to the project, but maybe he can help. Old AOE2 have old for of war (FOW) texture. Its task is to hide the visible field by seeding it with black pixels: 1 it works well. But here's what happens if the resolution of the game matches the resolution of the monitor: AOK000 the fog becomes barely visible, but that's not the worst: AOK002 AOK001 the two screenshots above you should save to yourself and open the images in full screen mode (as if you were playing), only then will you notice the true difference between them: in the first screenshot, everything under the fog is green. The mesh (reticulate) texture of the fog negatively affects the display of the final image by the monitor. If we start to reduce the resolution of the game, but still keep it full screen, we will see (I can not convey this through the screenshot) that the fog becomes thick and dark, but at some resolutions it will take a strange shape (cubes).

what I would like: is it possible through the wrapper to replace the texture of the fog of war, make it dense but with an alpha channel (semi-transparent), or something else.

Mitradis avatar Feb 03 '22 21:02 Mitradis

and one bug report: AOK000 field for text (players managment or chat window) not displayed text in direct3d9 render.

Mitradis avatar Feb 03 '22 21:02 Mitradis

photos from phone. Interesting what phone capture green screen as purple. 20220206_151125 20220206_151129

Mitradis avatar Feb 06 '22 12:02 Mitradis

That is neither an issue with cnc-ddraw nor Age of Empires II in general. The screenshots look totally fine on all of my monitors.

What kind of Display are you using? Does it use some kind of scaling? A close up photo of the pink/green pixels would be interesting.

QuImUfu avatar Mar 07 '23 18:03 QuImUfu

Yeah, this is a issue with modern monitors (It doesn't happen on CRT). All old 8bit color depth games have it (Warcraft 2, Total Annihilation etc..). The fog of war is flickering because it isn't real transparency (one pixel is black, next one is not). I also heard about the color issue as well on other games, I don't have that issue on my monitor though, I guess it only happens on some monitors.

You can workaround the issue by using a slightly lower resolution and then upscale it to native. One of the Total Annihilation players ended up using 1904x1071 instead of 1920x1080 and bilinear upscaled that to 1920x1080 and the problem was gone for him. That trick only works if the game supports such odd resolutions though.

It may be possible to create a shader to solve the problem, but I have yet to think about a good universal solution for it.

FunkyFr3sh avatar Mar 07 '23 18:03 FunkyFr3sh

thanks for the answer. Yes, changing the screen resolution can change how the effect works. At full resolution, it is not there, but the fog of war is very weak. On other resolutions, it happens, I don’t know what to call it, in general, it’s like a mosaic of repeating tiles. This is very ugly. Either a mosaic, or everything becomes diagonally striped. image

Mitradis avatar Mar 11 '23 20:03 Mitradis

Those might be scaling artifacts of your monitor. You could try scaling in software instead.
The very weak effect could be a side effect of some backlight technologies, causing these regions to be back-lit strongly, causing the brightness reduction to be much smaller than intended. Maybe there are some monitor settings that reduce the problem?
You could also mod the game, replacing the texture with one that is more than 50% black, or a two pixel checkerboard pattern.

One could probably write a shader that works around this, detecting colored pixels surrounded by black ones and blurring them smartly. As the non-native-resoulution workaround, that could degrade the look of the game.

QuImUfu avatar Mar 13 '23 06:03 QuImUfu

I tried to edit the texture. Nothing good came of it.

Mitradis avatar Mar 13 '23 07:03 Mitradis

I adapted one of the included shaders to make non-black pixels surrounded by black ones half as bright and fill black pixels surrounded by non-black pixels with a mix of the surrounding pixels, half as bright.

The brightness can be modified by changing the value of BRIGHTNESS in the shader file.

There are some minor artifacts:

  • Some singular black pixels within shadows are filled in and brightened
  • Shadows within the fog are noisy due to non-smoothed black-checkerboard pixels
  • The sides of the viewport are still alternating bright-dark, due to them having a completely non-black(top/bottom) or black (sides) border

Most of these problems should be fixable one way or another, but that would make the shader more complex. Maybe I'll look into it some more in a few days.

It works on my system, but I have no idea if/how well it will work on non AMD, non Linux systems, and I did not keep/use crazy compatibility defines.

If you want to try it, download smooth-chessboard-gray.glsl.txt, rename it to smooth-chessboard-gray.glsl, put it into the Shaders folder and configure the ddraw.ini to use it.

QuImUfu avatar Mar 21 '23 20:03 QuImUfu

@Mitradis Well, I had some time today and wrote an improved version.
I found no noticeable artifacts, except for a single bright pixel below a boar's snout if the boar is looking sideways.

It works similarly, but instead of requiring all neighboring pixels to be in the other state, it requires only 3, and that one pixel in the vicinity has all neighboring pixels in the other state.

Again, it works on my system, but I have no idea if/how well it will work on non AMD, non Linux systems, and I did not keep/use crazy compatibility defines.

If you want to try it, download smooth-chessboard-gray.glsl.txt, rename it to smooth-chessboard-gray.glsl, put it into the Shaders folder and configure the ddraw.ini to use it.

@FunkyFr3sh if you are interested in including the shader, I can make a PR.

QuImUfu avatar Mar 22 '23 13:03 QuImUfu

It's amazing! Thank you very much for your attention to this issue and finding a solution. It works great!

Mitradis avatar Mar 22 '23 13:03 Mitradis

Nice! I'll be doing some testing with it soon, I need to install a bunch of games first though

FunkyFr3sh avatar Mar 22 '23 23:03 FunkyFr3sh

@QuImUfu @FunkyFr3sh this has application to the mouse cursor, deforming contours, and to the inscriptions on the left (hints, chat, etc.) and on the left (statistic), making the text deformed. Can this be excluded from processing by the shader?

Mitradis avatar Apr 03 '23 11:04 Mitradis

I have (now had) this issue as well with the green. Dell S2716DG.

Vigilante-Thaldren avatar Apr 05 '23 12:04 Vigilante-Thaldren

Sorry, took some time, but now I finally tested it...

The first version works fine for me. Looks nice and performance is great too. Improved version is a mess, I don't even know how to explain it but it's like the entire screen is animated and things are shifting around. Also, the performance is really bad, about 1 FPS on a old intel APU.

Below some before and after screenshots

@QuImUfu @FunkyFr3sh this has application to the mouse cursor, deforming contours, and to the inscriptions on the left (hints, chat, etc.) and on the left (statistic), making the text deformed. Can this be excluded from processing by the shader?

Which version did you test?

Original original

First version v1

Improved version v2

FunkyFr3sh avatar Apr 05 '23 12:04 FunkyFr3sh

it is hard to explain : https://youtu.be/QLcbP0HqzBk on snow maps around the cursor, as if the contour is dancing. And as I wrote above, the text on the left and the statistics text is deformed, if compare it on the fog of war and without.

https://github.com/FunkyFr3sh/cnc-ddraw/issues/141#issuecomment-1479544334 where i can download last version?

Mitradis avatar Apr 05 '23 13:04 Mitradis

@FunkyFr3sh Thanks for testing. The second version is expected to perform slightly worse but 1fps and any funky behavior is ?probably? due to odd driver behavior with floating-point 0 comparisons.
Even the first version seems to be a bit… bugged on your system, but in a way that makes it artifact less noticeably. On the borders to black regions, contours should be (if the algorithm had been executed correctly) jagged, and not smoothed. But somehow, they got smoothed anyway. Also, a different, much less jarring artifact is visible on your screenshot, black areas are overly blended, but that's much less jarring than it would be in Age of Empires II in black object shadows. In that area, even the normal artifacts of the first version were really noticeable in Age of Empires II.

The second version works fine on my system, and seemingly Mitradis as well, I should have an old intel Laptop lying around… somewhere, I'll try it on there.
Just to make sure, I'll also give it a try it with Warcraft II on my main System.

@Mitradis Thanks for reporting these issues, I didn't notice them in my Tests. I can reproduce both and will take a look, but I am not sure whether I'll be able to find a fix that doesn't (re-)introduce other artifacts.

QuImUfu avatar Apr 05 '23 16:04 QuImUfu

@Mitradis I looked at your issues. Unfortunately, I can find no way to differentiate these artifacts from cases where smoothing is necessary (e.g. bright pixels in shadows). If I make the shader strict enough at selecting pixels to prevent these artifacts, all kinds of other artifacts appear.
The only ways (I know of) to fix these would be pattern matching (I could e.g., detect glyphs in the font and disable smoothing) or machine learning (pattern matching, but let the computer search for a good minimal pattern). Implementing either of them would be a lot of work, for a very small improvement to the result, so I probably won't fix those.

QuImUfu avatar Apr 11 '23 21:04 QuImUfu

I thought need some support from the wrapper for this, for exception effect for some elements. In any case, all is well. You fixed the main problem and it's definitely great! Thank you!

Mitradis avatar Apr 12 '23 08:04 Mitradis

Yea Thank You!

Vigilante-Thaldren avatar Apr 12 '23 16:04 Vigilante-Thaldren

@FunkyFr3sh I did not find time to test it on an Intel iGPU, but I made a version not dependent on floating point zero comparisons and not assuming zero-initialized variables. This version works with the mesa OpenGL software renderer (that was bugged with v2 and v1 as well) and manages to deliver well over 100fps with it.
If you find time you could try this version on your system. smooth-chessboard-gray-v3.glsl.txt

QuImUfu avatar Apr 26 '23 20:04 QuImUfu

still having issues, but it looks a bit different now: v3: https://github.com/FunkyFr3sh/cnc-ddraw/assets/8355237/9f1d4d75-275d-4bd5-ac2c-45fca2b38acc

v1:

https://github.com/FunkyFr3sh/cnc-ddraw/assets/8355237/b37b7708-35cf-4ef8-839c-67df4d519648

FunkyFr3sh avatar May 31 '23 22:05 FunkyFr3sh

i have an intel integrated GPU handy, plus the monitor i mentioned above both together as my active PC atm

@FunkyFr3sh I did not find time to test it on an Intel iGPU, but I made a version not dependent on floating point zero comparisons and not assuming zero-initialized variables. This version works with the mesa OpenGL software renderer (that was bugged with v2 and v1 as well) and manages to deliver well over 100fps with it. If you find time you could try this version on your system. smooth-chessboard-gray-v3.glsl.txt

Vigilante-Thaldren avatar May 31 '23 22:05 Vigilante-Thaldren

i have an intel integrated GPU handy, plus the monitor i mentioned above both together as my active PC atm

@FunkyFr3sh I did not find time to test it on an Intel iGPU, but I made a version not dependent on floating point zero comparisons and not assuming zero-initialized variables. This version works with the mesa OpenGL software renderer (that was bugged with v2 and v1 as well) and manages to deliver well over 100fps with it. If you find time you could try this version on your system. smooth-chessboard-gray-v3.glsl.txt

You could try out the new v3 version if you want!

FunkyFr3sh avatar Jun 01 '23 02:06 FunkyFr3sh

Sure I'll give a try sometime

i have an intel integrated GPU handy, plus the monitor i mentioned above both together as my active PC atm

@FunkyFr3sh I did not find time to test it on an Intel iGPU, but I made a version not dependent on floating point zero comparisons and not assuming zero-initialized variables. This version works with the mesa OpenGL software renderer (that was bugged with v2 and v1 as well) and manages to deliver well over 100fps with it. If you find time you could try this version on your system. smooth-chessboard-gray-v3.glsl.txt

You could try out the new v3 version if you want!

Vigilante-Thaldren avatar Jun 02 '23 02:06 Vigilante-Thaldren

Hmmmm... if shader Requires 'renderer=opengl', but if i must run game as windowed mode (if game crash in full scr) i need d3d9linear = true (or i have cubic image), but this work only for directx mode.

Mitradis avatar Jun 02 '23 15:06 Mitradis

Hmmmm... if shader Requires 'renderer=opengl', but if i must run game as windowed mode (if game crash in full scr) i need d3d9linear = true (or i have cubic image), but this work only for directx mode.

d3d9linear = true and cubic/opengl will both fix the issue, so you don't really need this shader here. This shader is only useful without having any upscaling enabled

FunkyFr3sh avatar Jun 02 '23 23:06 FunkyFr3sh

20230603_105433 not as good as this shader. i have 27` monitor with 1920-1080 res. Possible combine this shader with bilinear.glsl or cubic.glsl or any linear filter?

Mitradis avatar Jun 03 '23 07:06 Mitradis

@FunkyFr3sh That's a funky rendering bug… I blame Intel's drivers at this point. On my Intel GPU laptop cnc-ddraw fails to start in OpenGL mode (white box telling me it fell back to software rendering and to update my driver) on Linux, and it seems I have nuked my Windows partition some time ago.
So I currently have no way of reproducing that bug on any of the systems I own.

QuImUfu avatar Jun 03 '23 16:06 QuImUfu

I ought to give this a try soon!

Vigilante-Thaldren avatar Jun 03 '23 18:06 Vigilante-Thaldren

Intel's drivers it's garbage - this talking to me author ENB Series about why he do not make support for intel graphics. it's a bunch of bugs.

Mitradis avatar Jun 03 '23 18:06 Mitradis