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.

feat(ww3d2): bent glass cloak, faint cloak shadow, readable heat

Olcay Seygan1d82bfd88eeb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6233fac62..a9eb97edc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1459,7 +1459,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- Blasts throw fragments that smoke. A tank shell, rocket, artillery round or bomb landing flings a few orange-hot sparks out past its fireball, each drawing a thin grey line of smoke as it arcs down. A vehicle that blows up throws pieces of its hull, which bounce where they land and drag a longer ribbon of grey smoke with embers burning at its head. In a fight of seventeen tanks the screen held about 1250 particles where it held 770, well inside the 2500 limit. The fragments are the first effect the particle limit and a lower detail setting drop, so a big fight keeps its explosions. What a weapon does is unchanged.
- A China mine field tells you what kind it is. EA's field had no model at all, only a soft white glint swelling and fading on each of its eight spots, so your own minefield looked like a patch of fireflies. Each mine is now marked by a small arming light that snaps on for a quarter of a second every second and a half, red on standard and cluster mines and blue on EMP mines, with a white-hot point and a dark rim that keep it readable on grass, sand or snow. No mine body is drawn on the ground, only the light. The enemy still sees nothing until he detects the field. A mine going off under a tank now throws a column of dark earth twice the tank's height, scatters clods round it and leaves a low black smoke and a scorch, with a short jolt of the screen; it used to puff a pale spray of specks that looked like dust kicked up. An EMP mine throws no earth, so you can tell which kind went off: it lights a blue ring across the ground, a crackle of blue sparks and a short blue flash at the spot; EA's flash grew until it washed the whole screen white for a fifth of a second. What a mine does is unchanged.
- A base out of power looks out of power. A building that switches off when your power runs short, or one a hacker shut down, drains to a cold grey and sags darker, and its windows and lamps go out. Every few seconds it blinks dark for an instant or its lights catch again for a moment, and blue sparks jump on its walls where something shorts. A tank or building hit by an EMP crawls with thin blue arcs for as long as it stays dead, where it used to just turn dark grey.
-- Your own stealthed units look like glass, not like ice. In 3.0 a camouflaged Rebel, a Pathfinder or Colonel Burton came out under a blue skin with bands running up it, which players rightly called ugly. The blue is gone: the ground behind him shows through his body in its own colours, bent by a slow, gentle shimmer that ripples along him and a little more at his outline, with his own paint muted inside it and a soft pale edge round him, so you do not lose him at the zoom you play at. He never turns solid, and the 2003 breathing of the fade is still there. The shimmer moves the same few pixels at any zoom, so a stealthed squad seen from far out does not fizz. When an enemy detector has found him, his body warms and an amber edge beats on him, plain enough to notice in a fight. On every renderer, a stealthed unit of yours no longer comes out solid whenever no building is on the screen: the game drew it a second time without its see-through. An enemy stealth unit your detector finds used to turn into a flat orange shape with no paint; now it shows as heat, its own shading run from dark red through orange to a pale yellow so you can still tell a tank from a soldier, with a burning outline and a slow glow climbing it that flares on every sweep of the detector. The fine scan lines of 3.0 are gone, since zoomed out they broke into stripes. This is the default renderer; Classic and the old renderer keep the 2003 look for all of these.
+- Your own stealthed units look like glass, not like ice. In 3.0 a camouflaged Rebel, a Pathfinder or Colonel Burton came out under a blue skin with bands running up it, which players rightly called ugly. The blue is gone: the ground behind him shows through his body in its own colours and bends, a slow lens that ripples along him and pulls harder at his outline, with only a hint of his own paint left in it. The bend is what you find him by: each face of him tips the ground behind it its own way, so his shape shows even on plain sand, and the bend never drops below a few pixels, and a faint cool haze that thickens at his outline keeps a cloaked soldier or building findable at the zoom you play at, without turning him white. Up close a building's flat wall bends across its face. It moves slowly and never fizzes. He never turns solid, and the 2003 breathing of the fade is still there. His shadow fades with him, to between a quarter and a half of its strength as he breathes, where it used to lie on the ground at full strength and give him away before his body did; on Classic and the old renderer the shadow stays whole. When an enemy detector has found him, his whole body beats amber along with his edge, so a spotted building reads as spotted and does not just turn tan. On every renderer, a stealthed unit of yours no longer comes out solid whenever no building is on the screen: the game drew it a second time without its see-through. An enemy stealth unit your detector finds used to turn into a flat orange shape with no paint; now it shows as heat, its own shading run from dark red through orange to a warm yellow that stops short of white, so you can still tell a tank from a soldier and bright GLA paint keeps its detail, with a burning outline and a slow glow climbing it that flares on every sweep of the detector. The fine scan lines of 3.0 are gone, since zoomed out they broke into stripes. This is the default renderer; Classic and the old renderer keep the 2003 look for all of these.
- Effects fade out instead of blinking off. The rings a nuke sends across the ground, and any spark, flash or puff whose own colours never reached nothing, used to vanish at full strength on their last frame. Each one now dims away over its last quarter of a second, or over a quarter of its life when it lives shorter than that. One that was already fading looks the way it always did.
- Toxin, anthrax and radiation pools lie on the ground. A pool is a carpet of puddle pictures spread up to 140 paces from where the shell or the spray came down, and every one of them was drawn dead flat at the height of that one spot: on a hillside the uphill half of the pool disappeared into the slope and the downhill half hung in the air above it. Each puddle now bends over the ground underneath it, on both renderers, and a pool on a bridge stays on the deck. The pool also holds still. It used to throb twice a second, because every half second the pool's poison fired a fresh batch of puddles that swelled out of black to full green and back to black in two seconds, each batch somewhere new. Now it comes up in half a second, stays one pool at full colour for as long as it does damage, and fades over its last three seconds, or over three seconds from the moment the fog of war closes over it. It is not frozen, though: each puddle fades down and back up on its own beat, so the surface shimmers like something liquid while the pool as a whole never pulses. Four Scud warheads landing on one spot used to stack into a white-hot blotch in the middle; overlapping pools now share their light and the middle stays toxin green. The ground under it takes on its colour, green for toxin and the anthrax colours for anthrax, so it looks spilled rather than shone onto the grass. China's radiation keeps its orange but glows instead of browning the grass, which made it look like a scorch mark, and small bubbles swell out of it and pop. A nuke's radiation lies on the hillside as a pool from three seconds after the blast, where its first ten seconds used to be flat squares cutting into the slope.
- A Scud Storm or a carpet bomb shakes the screen as hard as it should. The game cut a pile of heavy shakes back to a mild one, so a run of missiles or bombs landing together shook less than one of them alone. Each now shakes a step lighter and the run builds up. Demo traps and Aurora bombs shake now, and a falling building shakes harder the bigger it was.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
index 0abbe9703..3f7d74785 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
@@ -70,6 +70,7 @@
#include "WW3D2/camera.h"
#include "WW3D2/dx8renderer.h"
#include "WW3D2/dx11runtime.h"
+#include "WW3D2/ffshader.h"
#include "WW3D2/sortingrenderer.h"
#include "GameClient/View.h"
#include "Platform/RenderTypes.h"
@@ -4403,6 +4404,20 @@ void W3DVolumetricShadowManager::renderShadowMap( CameraClass &sceneCamera )
}
}
+ /* An own stealthed unit casts only a share of its shadow, breathing with its fade, the way
+ the cloak lets the ground show through its body (effect_cloak_shadow in ffshader.h). A
+ render object with no drawable behind it, a ghost or a prop, casts in full. */
+ sunInfo.drawEffect = DRAW_EFFECT_NONE;
+ const DrawableInfo *casterInfo = (const DrawableInfo *)robj->Get_User_Data();
+ const Drawable *caster = casterInfo ? casterInfo->m_drawable : NULL;
+ if (caster && Direct3D11_Draw_Effects()
+ && (caster->getStealthLook() == STEALTHLOOK_VISIBLE_FRIENDLY
+ || caster->getStealthLook() == STEALTHLOOK_VISIBLE_FRIENDLY_DETECTED))
+ {
+ sunInfo.drawEffect = DRAW_EFFECT_CLOAK_SHADOW;
+ sunInfo.drawEffectParameters[3] = caster->getEffectiveOpacity();
+ }
+
robj->Render( sunInfo );
++castersCounted;
}
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
index 7ad4f0198..3279da297 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp
@@ -1009,15 +1009,19 @@ void DX11BackendClass::Set_Draw_Effect(unsigned effect, const float parameters[4
}
}
-/** Which look the current draw takes. Only the scene's own world draws: not the sun's map, not a
- mirror or a filter target, not a screen space quad and not a transcribed program. A draw
+/** Which look the current draw takes. Only the scene's own world draws, and in the sun's map only
+ the cloak's thinned shadow: not a mirror or a filter target, not a screen space quad and not a transcribed program. A draw
adding light (ONE as either factor) takes the outage alone, which puts a building's glow cards
out with it; dressed in arcs or a rim, the card's whole quad would show. A multiplying pass
takes none. The cloak needs the scene's copy, and without one the object keeps its plain
translucency. */
unsigned DX11BackendClass::Draw_Effect() const
{
- if (DrawEffect == DRAW_EFFECT_NONE || ShadowMapBound || CurrentTarget != NULL
+ // The cloak's shadow is the one look the sun's map takes, and the only place it is drawn.
+ if (ShadowMapBound != (DrawEffect == DRAW_EFFECT_CLOAK_SHADOW)) {
+ return DRAW_EFFECT_NONE;
+ }
+ if (DrawEffect == DRAW_EFFECT_NONE || CurrentTarget != NULL
|| (VertexFormat & D3DFVF_XYZRHW) != 0
|| VertexProgram != ENGINE_SHADER_NONE || PixelProgram != ENGINE_SHADER_NONE) {
return DRAW_EFFECT_NONE;
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp
index 2c80eb74d..06a2b552e 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp
@@ -477,7 +477,8 @@ static bool generate_combiners(const CombinerDescription & description,
" current = effect_outage(current, input.Position);\n",
" current = effect_emp(current, input.Position);\n",
" current = effect_cloak(current, input.Position);\n",
- " current = effect_revealed(current, input.Position);\n"
+ " current = effect_revealed(current, input.Position);\n",
+ " current = effect_cloak_shadow(current, input.Position);\n"
};
hlsl += effect_calls[effect];
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h
index b2fb594a6..da6b47b8a 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h
@@ -134,7 +134,8 @@ enum
DRAW_EFFECT_EMP = 2, ///< anything an EMP disabled: arcs crawling over it
DRAW_EFFECT_CLOAK = 3, ///< own stealthed unit: what is behind it, gently bent, through its muted paint
DRAW_EFFECT_REVEALED = 4, ///< enemy stealthed unit a detector found: seen as heat
- DRAW_EFFECT_COUNT = 5
+ DRAW_EFFECT_CLOAK_SHADOW = 5, ///< own stealthed unit in the sun's map: casts a share of its shadow
+ DRAW_EFFECT_COUNT = 6
};
// The constant block still carries this many normal mapped light slots, unread, so the shadow and
@@ -560,16 +561,21 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;
" return current;\n" \
"}\n" \
"\n" \
- "/* Own stealthed unit, seen through like glass. What is behind it shows through its body,\n" \
- " bent a few pixels by a slow, broad ripple that swims along it and bends a little more\n" \
- " towards the outline. No tint: the scene keeps its colour, and the unit's own paint, drained\n" \
- " a little, sits in it at about half by the game's own stealth opacity, so the 2003 breathing\n" \
- " still shows; darker than that and a unit at play zoom was lost but for its shadow. A soft\n" \
- " near-white fresnel edge holds the silhouette. The ripple is measured in the world and moves\n" \
- " a fixed share of the screen, so a unit far out shimmers as gently as one up close and never\n" \
- " breaks into noise. Detected (the strength is never below 0.6 then), the body warms and an\n" \
- " amber edge beats. The alpha goes back up to the texel's own, because the shade already\n" \
- " holds the mix. */\n" \
+ "/* Own stealthed unit, seen through like thick bent glass, and the bend is what you find it by.\n" \
+ " Each face leans the scene behind it the way its normal leans on the screen, so faces turned\n" \
+ " different ways show the ground shifted by different amounts and the body's shape reads even\n" \
+ " over plain sand; a slow, broad ripple swims over that and bends a flat wall across its face.\n" \
+ " The reach is two and a half world units in pixels at the pixel's depth, never under 4 pixels\n" \
+ " at 1080 so a unit at play zoom still visibly distorts, never over 4% of the screen. The\n" \
+ " ripple is low frequency in the world and slow, so nothing fizzes in motion. The bend alone\n" \
+ " was lost at play zoom, so the glass also leans a little toward a cool mid grey, 7% face on\n" \
+ " and about half at the outline, where a soldier's round body has most of its faces and a\n" \
+ " building's flat walls have few: a haze rather than a white edge, darkening bright ground as much\n" \
+ " as it lifts dark ground. A hint of the unit's own paint stays in it, breathing with the\n" \
+ " game's own stealth opacity as it did in 2003. Detected (the strength is never below 0.6\n" \
+ " then), the whole body beats amber as well as its edge: a big flat building has almost no\n" \
+ " edge facing away from the eye, and with the beat on the rim alone it only turned tan. The\n" \
+ " alpha goes back up to the texel's own, because the shade already holds the mix. */\n" \
"float4 effect_cloak(float4 current, float4 position)\n" \
"{\n" \
" float3 world; float3 surface; float facing;\n" \
@@ -578,27 +584,38 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;
" float detected = DrawEffectParameters.y;\n" \
" float opacity = max(DrawEffectParameters.w, 0.05);\n" \
" float rim = pow(1.0 - facing, 2.0);\n" \
- " float swim_x = effect_noise(world * 0.12 + float3(t * 0.35, t * 0.2, t * 0.45)) - 0.5;\n" \
- " float swim_y = effect_noise(world * 0.12 + float3(7.3 - t * 0.3, 2.1, t * 0.4)) - 0.5;\n" \
+ " float swim_x = effect_noise(world * 0.09 + float3(t * 0.35, t * 0.2, t * 0.45)) - 0.5;\n" \
+ " float swim_y = effect_noise(world * 0.09 + float3(7.3 - t * 0.3, 2.1, t * 0.4)) - 0.5;\n" \
" float2 screen = 1.0 / ShadowViewport.xy;\n" \
- " float2 bend = float2(swim_x, swim_y) * (0.008 + 0.006 * rim) * screen.y;\n" \
+ " float2 ndc = float2(position.x * ShadowViewport.x * 2.0 - 1.0, 1.0 - position.y * ShadowViewport.y * 2.0);\n" \
+ " float4 across = mul(float4(ndc + float2(2.0 * ShadowViewport.x, 0.0), position.z, 1.0), WorldFromClip);\n" \
+ " float4 above = mul(float4(ndc + float2(0.0, 2.0 * ShadowViewport.y), position.z, 1.0), WorldFromClip);\n" \
+ " float3 right = across.xyz / across.w - world;\n" \
+ " float3 up = above.xyz / above.w - world;\n" \
+ " float world_per_pixel = max(length(up), 1e-4);\n" \
+ " float2 lean = float2(dot(surface, right), -dot(surface, up)) / world_per_pixel;\n" \
+ " float reach = clamp(2.5 / world_per_pixel, 0.0037 * screen.y, 0.04 * screen.y);\n" \
+ " float2 bend = (lean * 0.8 + float2(swim_x, swim_y) * 1.2) * reach;\n" \
" int2 at = int2(clamp(position.xy + bend, float2(0.0, 0.0), screen - 1.0));\n" \
" float3 behind = SceneColour.Load(int3(at, 0)).rgb;\n" \
" float grey = dot(current.rgb, float3(0.299, 0.587, 0.114));\n" \
" float3 own = lerp(grey.xxx, current.rgb, 0.7);\n" \
- " float3 glass = lerp(behind, own, 0.3 + 0.35 * opacity) + rim * 0.4 * float3(0.92, 0.96, 1.0) + 0.04;\n" \
+ " float3 glass = lerp(behind, own, 0.1 + 0.15 * opacity);\n" \
+ " glass = lerp(glass, float3(0.52, 0.55, 0.59), 0.07 + 0.45 * rim);\n" \
" float found = step(0.01, detected);\n" \
" float beat = 0.55 + 0.45 * sin(t * 6.0);\n" \
" float3 amber = float3(1.0, 0.55, 0.15);\n" \
- " glass = lerp(glass, glass * amber * 1.4, found * 0.35) + found * (rim * 1.2 + 0.08) * beat * amber;\n" \
+ " float lum = dot(glass, float3(0.299, 0.587, 0.114));\n" \
+ " glass = lerp(glass, amber * (0.3 + lum), found * (0.25 + 0.3 * beat)) + found * (rim * 1.2 + 0.18) * beat * amber;\n" \
" current.rgb = glass;\n" \
" current.a = saturate(current.a / opacity);\n" \
" return current;\n" \
"}\n" \
"\n" \
"/* Enemy stealthed unit a detector found, seen as heat, the way the 2003 heat vision pass meant\n" \
- " it. The paint's own brightness runs up a thermal ramp, dark red through orange to a pale hot\n" \
- " yellow, so the shape still reads, the outline burns, and one slow broad sweep climbs it. Each\n" \
+ " it. The paint's own brightness runs up a thermal ramp, dark red through orange to a warm\n" \
+ " yellow that stops short of white, so bright paint keeps its detail and the shape reads; the\n" \
+ " outline burns, and one slow broad sweep climbs it. Each\n" \
" sweep of the detector (the strength, one at the sweep and falling after) brightens all of\n" \
" it. No fine lines: drawn a few pixels high, a zoomed out unit turned them into stripes. */\n" \
"float4 effect_revealed(float4 current, float4 position)\n" \
@@ -607,15 +624,28 @@ const unsigned NORMAL_MAPPED_LIGHTS = 4;
" effect_surface(position, world, surface, facing);\n" \
" float t = DrawEffectParameters.x;\n" \
" float pulse = DrawEffectParameters.y;\n" \
- " float heat = saturate(dot(current.rgb, float3(0.299, 0.587, 0.114)) * 1.3 + 0.1);\n" \
- " float3 ramp = lerp(float3(0.30, 0.04, 0.02), float3(1.0, 0.42, 0.08), smoothstep(0.0, 0.55, heat));\n" \
- " ramp = lerp(ramp, float3(1.0, 0.86, 0.55), smoothstep(0.55, 1.0, heat));\n" \
+ " float heat = saturate(dot(current.rgb, float3(0.299, 0.587, 0.114)) * 1.05 + 0.06);\n" \
+ " float3 ramp = lerp(float3(0.30, 0.04, 0.02), float3(0.95, 0.40, 0.08), smoothstep(0.0, 0.55, heat));\n" \
+ " ramp = lerp(ramp, float3(0.95, 0.66, 0.32), smoothstep(0.55, 1.0, heat));\n" \
" float rim = pow(1.0 - facing, 2.0);\n" \
" float sweep = smoothstep(0.9, 1.0, sin(world.z * 0.06 - t * 1.8));\n" \
- " float gain = 0.6 + 0.6 * pulse;\n" \
+ " float gain = 0.6 + 0.35 * pulse;\n" \
" current.rgb = ramp * gain + float3(1.0, 0.40, 0.12) * (rim * 0.9 + sweep * 0.35) * gain;\n" \
" return current;\n" \
"}\n" \
+ "\n" \
+ "/* Own stealthed unit drawn into the sun's map. A depth map holds a caster or not, so the\n" \
+ " cloaked one keeps a share of its texels, an ordered four by four pattern, and the receiving\n" \
+ " filter, which averages a square of taps over several texels, turns that share into a shadow\n" \
+ " that strength. Half the stealth opacity: a quarter to a half, breathing with the body. */\n" \
+ "float4 effect_cloak_shadow(float4 current, float4 position)\n" \
+ "{\n" \
+ " uint2 cell = uint2(position.xy) & 3u;\n" \
+ " uint bayer = ((cell.x ^ cell.y) & 1u) * 8u + (cell.y & 1u) * 4u\n" \
+ " + (((cell.x ^ cell.y) >> 1) & 1u) * 2u + ((cell.y >> 1) & 1u);\n" \
+ " clip(DrawEffectParameters.w * 0.5 - ((float)bayer + 0.5) / 16.0);\n" \
+ " return current;\n" \
+ "}\n" \
"\n"
// SHADOW_APPLY with the smoke in it. A particle takes the shade whatever its own brightness: the