Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(ww3d2): draw a building's damage states without normal maps

Olcay Seygan4d31172d42aa
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4f80116d..94e11bd30 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -256,6 +256,7 @@ found and fixed — EA's own, not port damage.**
- 481 base-game textures at four times the resolution now beat Zero Hour's downscaled copies.
- The ground is drawn at twice the detail. Every map square used to get a 64-pixel patch of its ground texture, squeezed into sixteen-bit colour; it gets 128 pixels now in full colour, so sand, gravel and tracks stop turning to blocks and bands when you zoom in, and a ground texture that ships at twice the size is shown at that size.
- The ground has relief. Every grain of sand, pebble and crack catches the map's own sun on one side and falls into shade on the other, worked out from the ground's own picture when the map loads, and it follows the sun on a dusk map or a night one. The light the ground already had from its hills is kept; the relief goes on top. It is part of the new picture, so a machine on the old renderer keeps the flat ground.
+- A damaged building looks damaged, not carved out of marble. The damaged and burning versions of a building's skin are separate pictures a quarter the size of the healthy one, and the surface detail made from them spread one blotch of soot into a hill across a whole wall panel, so a command centre under fire turned black and white. They draw flat now, and the panels, rivets and deck stripes show through the soot again.
- A long thin texture loads at the size it was drawn at. Anything wider than eight to one used to be stretched onto a bigger, blurrier one, because that was the limit of a 2002 graphics card; the card is asked now, and modern ones have no such limit.
- Anything standing still keeps its shadow in the fog. A town you have already walked through used
to sit on flat ground the moment you looked away, buildings and derricks and walls with nothing
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp
index 044a95c63..3ff48b2cb 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.cpp
@@ -1024,10 +1024,44 @@ void TextureClass::Set_Normal_Map(TextureClass * normal_map)
NormalMapLooked = true;
}
+bool Texture_Name_Is_Damage_State(const char * name)
+{
+ static const char STATE_LETTERS[] = "desgnr";
+ static const size_t LONGEST_STATE_TAG = 4;
+
+ const char * tag = strrchr(name, '_');
+ if (tag == NULL)
+ {
+ return false;
+ }
+ ++tag;
+
+ size_t length = 0;
+ bool damaged = false;
+ for (; tag[length] != '\0' && tag[length] != '.'; ++length)
+ {
+ const char letter = (char)tolower((unsigned char)tag[length]);
+ if (strchr(STATE_LETTERS, letter) == NULL)
+ {
+ return false;
+ }
+ damaged = damaged || letter == 'd' || letter == 'e';
+ }
+ return damaged && length <= LONGEST_STATE_TAG;
+}
+
TextureClass * TextureClass::Find_Normal_Map()
{
static const char NORMAL_MAP_SUFFIX[] = "_nrm.dds";
+ // A damage state is a separate texture a quarter the size of the building's own, so its normal
+ // map spread a texel of relief over a whole panel: the damaged walls lit up as black and white
+ // marble. It draws flat, as it did in 2003.
+ if (!NormalMapLooked && Texture_Name_Is_Damage_State(Get_Texture_Name()))
+ {
+ NormalMapLooked = true;
+ }
+
if (!NormalMapLooked)
{
NormalMapLooked = true;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.h
index 26d17e4fd..fbdc2bb7d 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/texture.h
@@ -493,6 +493,10 @@ protected:
int Depth;
};
+// Is this texture file one of a building's damage states - "<name>_d", "_e", or the night, snow
+// and garrison copies of those, "_dn", "_es", "_dsg" and the rest? Those carry no normal map.
+bool Texture_Name_Is_Damage_State(const char * name);
+
// Utility functions for loading and saving texture descriptions from/to W3D files
TextureClass *Load_Texture(ChunkLoadClass & cload);
void Save_Texture(TextureClass * texture, ChunkSaveClass & csave);
diff --git a/GeneralsMD/Code/Tests/test_ww3d2.cpp b/GeneralsMD/Code/Tests/test_ww3d2.cpp
index 2fa67b22f..f0aa9d61f 100644
--- a/GeneralsMD/Code/Tests/test_ww3d2.cpp
+++ b/GeneralsMD/Code/Tests/test_ww3d2.cpp
@@ -1729,3 +1729,24 @@ TEST(sorting_depth_key_orders_the_way_the_depths_do)
/* the same depth twice is the same key, which is what keeps equal depths in pooled order */
CHECK_EQ( SortingRendererClass::_Depth_Sort_Key( 3.25f ), SortingRendererClass::_Depth_Sort_Key( 3.25f ) );
}
+
+// ---------------------------------------------------------------------------------------------
+// A building's damage states are separate low resolution textures, and their normal maps drew the
+// damaged walls as marble. Which names count as one decides which textures lose the relief.
+// ---------------------------------------------------------------------------------------------
+#include "texture.h"
+
+TEST(damage_state_textures_are_told_apart_by_their_suffix)
+{
+ CHECK( Texture_Name_Is_Damage_State( "ubarfrccmd_d.dds" ) );
+ CHECK( Texture_Name_Is_Damage_State( "ubarfrccmd_E.tga" ) );
+ CHECK( Texture_Name_Is_Damage_State( "abbarracks_dn.dds" ) );
+ CHECK( Texture_Name_Is_Damage_State( "abbarracks_dsg.dds" ) );
+ CHECK( Texture_Name_Is_Damage_State( "cbhouse_esn" ) );
+
+ CHECK( !Texture_Name_Is_Damage_State( "ubarfrccmd.dds" ) );
+ CHECK( !Texture_Name_Is_Damage_State( "ubarfrccmd_n.dds" ) );
+ CHECK( !Texture_Name_Is_Damage_State( "ubarfrccmd_sng.dds" ) );
+ CHECK( !Texture_Name_Is_Damage_State( "avcrusader_tread.dds" ) );
+ CHECK( !Texture_Name_Is_Damage_State( "cbtree_dead.dds" ) );
+}