Skip to content

Commit 02d948a

Browse files
Starkkuchaserli
andauthored
Voxel turret & multi-section shadow reimplementation (#1209)
* rewrite again * Improvements & customization options to shadow scaling plus docs * exponentially shrink the shadow with Pade 2/2 should be smarter than WW's LUTs --------- Co-authored-by: chaserli <914137150@qq.com>
1 parent ca339aa commit 02d948a

File tree

9 files changed

+395
-40
lines changed

9 files changed

+395
-40
lines changed

CREDITS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ This page lists all the individual contributions to the project by their author.
292292
- EIP 00529A14 crash fix on Linux
293293
- Teleport timer reset after load game fix
294294
- Teleport, Tunnel and Fly loco visual tilt fix
295+
- Turret/Barrel/NoSpawnAlt/Multi-section voxel shadow, dynamic voxel shadow
295296
- Skip units' turret rotation and jumpjets' wobbling under EMP
296297
- Droppod properties dehardcode
297298
- Waypoint entering building together with engineer/agent bug fix

docs/Fixed-or-Improved-Logics.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,30 @@ NoWobbles=false ; boolean
688688
### Voxel body multi-section shadows
689689

690690
- It is also now possible for vehicles and aircraft to display shadows for multiple sections of the voxel body at once, instead of just one section specified by `ShadowIndex`, by specifying the section indices in `ShadowIndices` (which defaults to `ShadowIndex`) in unit's `artmd.ini` entry.
691+
- `ShadowIndex.Frame` and `ShadowIndices.Frame` can be used to customize which frame of the HVA animation for the section from `ShadowIndex` and `ShadowIndices` is used to display the shadow, respectively. -1 is special value which means currently shown frame is used, and `ShadowIndices.Frame` defaults to this.
691692

692693
In `artmd.ini`:
693694
```ini
694-
[SOMETECHNO] ; TechnoType
695-
ShadowIndices= ; list of integers (voxel section indices)
695+
[SOMETECHNO] ; TechnoType
696+
ShadowIndices= ; list of integers (voxel section indices)
697+
ShadowIndex.Frame=0 ; integer (HVA animation frame index)
698+
ShadowIndices.Frame= ; list of integers (HVA animation frame indices)
699+
```
700+
701+
### Voxel shadow scaling in air
702+
703+
- It is now possible to adjust how voxel air units (`VehicleType` & `AircraftType`) shadows scale in air. By default the shadows scale by `AirShadowBaseScale` (defaults to 0.5) amount if unit is `ConsideredAircraft=true`.
704+
- If `HeightShadowScaling=true`, the shadow is scaled by amount that is determined by following formula: `Max(AirShadowBaseScale ^ (currentHeight / ShadowSizeCharacteristicHeight), HeightShadowScaling.MinScale)`, where `currentHeight` is unit's current height in leptons, `ShadowSizeCharacteristicHeight` overrideable value that defaults to the maximum cruise height (`JumpjetHeight`, `FlightLevel` etc) and `HeightShadowScaling.MinScale` sets a floor for the scale.
705+
706+
In `rulesmd.ini`:
707+
```ini
708+
[AudioVisual]
709+
AirShadowBaseScale=0.5 ; floating point value
710+
HeightShadowScaling=false ; boolean
711+
HeightShadowScaling.MinScale=0.0 ; floating point value
712+
713+
[SOMETECHNO] ; TechnoType
714+
ShadowSizeCharacteristicHeight= ; integer, height in leptons
696715
```
697716

698717
### Forbid parallel AI queues
@@ -837,6 +856,8 @@ IronCurtain.KeptOnDeploy= ; boolean, default to [CombatDamage]->IronCurtain.K
837856
### Voxel turret shadow
838857

839858
- Vehicle voxel turrets can now draw shadows if `[AudioVisual]` -> `DrawTurretShadow` is set to true. This can be overridden per VehicleType by setting `TurretShadow` in the vehicle's `artmd.ini` section.
859+
- If you don't want to render the body's shadow at all, set `ShadowIndex` to an invalid number.
860+
840861
In `rulesmd.ini`:
841862
```ini
842863
[AudioVisual]

docs/Whats-New.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ New:
323323
- TechnoType conversion on ownership change (by Trsdy)
324324
- Unlimited skirmish colors (by Morton)
325325
- Example custom locomotor that circles around the target (*NOTE: For developer use only*) (by Kerbiter, CCHyper, with help from Otamaa; based on earlier experiment by CnCVK)
326-
- Vehicle voxel turret shadows & body multi-section shadows (by TwinkleStar)
326+
- Vehicle voxel turret shadows & body multi-section shadows (by TwinkleStar & Trsdy)
327327
- Crushing tilt and slowdown customization (by Starkku)
328328
- Extra warhead detonations on weapon (by Starkku)
329329
- Chrono sparkle animation display customization and improvements (by Starkku)
@@ -368,6 +368,7 @@ New:
368368
- Allow to change the speed of gas particles (by ZivDero)
369369
- Allow upgrade animations to use `Powered` & `PoweredLight/Effect/Special` keys (by Starkku)
370370
- Toggle for `Explodes=true` BuildingTypes to not explode during buildup or being sold (by Starkku)
371+
- Toggleable height-based shadow scaling for voxel air units (by Trsdy & Starkku)
371372
372373
Vanilla fixes:
373374
- Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy)

src/Ext/Rules/Body.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
117117
this->AnimRemapDefaultColorScheme.Read(exINI, GameStrings::AudioVisual, "AnimRemapDefaultColorScheme");
118118
this->TimerBlinkColorScheme.Read(exINI, GameStrings::AudioVisual, "TimerBlinkColorScheme");
119119
this->ShowDesignatorRange.Read(exINI, GameStrings::AudioVisual, "ShowDesignatorRange");
120+
Nullable<double>AirShadowBaseScale;
121+
AirShadowBaseScale.Read(exINI, GameStrings::AudioVisual, "AirShadowBaseScale");
122+
if (AirShadowBaseScale.isset() && AirShadowBaseScale.Get() > 0)
123+
this->AirShadowBaseScale_log = -std::log(std::min(AirShadowBaseScale.Get(), 1.0));
124+
125+
this->HeightShadowScaling.Read(exINI, GameStrings::AudioVisual, "HeightShadowScaling");
126+
this->HeightShadowScaling_MinScale.Read(exINI, GameStrings::AudioVisual, "HeightShadowScaling.MinScale");
120127

121128
this->AllowParallelAIQueues.Read(exINI, "GlobalControls", "AllowParallelAIQueues");
122129
this->ForbidParallelAIQueues_Aircraft.Read(exINI, "GlobalControls", "ForbidParallelAIQueues.Infantry");
@@ -260,6 +267,9 @@ void RulesExt::ExtData::Serialize(T& Stm)
260267
.Process(this->Pips_Tiberiums_DisplayOrder)
261268
.Process(this->Pips_Tiberiums_WeedFrame)
262269
.Process(this->Pips_Tiberiums_WeedEmptyFrame)
270+
.Process(this->AirShadowBaseScale_log)
271+
.Process(this->HeightShadowScaling)
272+
.Process(this->HeightShadowScaling_MinScale)
263273
.Process(this->AllowParallelAIQueues)
264274
.Process(this->ForbidParallelAIQueues_Aircraft)
265275
.Process(this->ForbidParallelAIQueues_Building)

src/Ext/Rules/Body.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ class RulesExt
7878
Valueable<int> Pips_Tiberiums_WeedFrame;
7979
Valueable<int> Pips_Tiberiums_WeedEmptyFrame;
8080

81+
Valueable<bool> HeightShadowScaling;
82+
Valueable<double> HeightShadowScaling_MinScale;
83+
double AirShadowBaseScale_log;
84+
8185
Valueable<bool> AllowParallelAIQueues;
8286
Valueable<bool> ForbidParallelAIQueues_Aircraft;
8387
Valueable<bool> ForbidParallelAIQueues_Building;
@@ -159,6 +163,11 @@ class RulesExt
159163
, Pips_Tiberiums_DisplayOrder {}
160164
, Pips_Tiberiums_WeedFrame { 1 }
161165
, Pips_Tiberiums_WeedEmptyFrame { 0 }
166+
167+
, HeightShadowScaling { false }
168+
, HeightShadowScaling_MinScale { 0.0 }
169+
, AirShadowBaseScale_log { 0.693376137 }
170+
162171
, AllowParallelAIQueues { true }
163172
, ForbidParallelAIQueues_Aircraft { false }
164173
, ForbidParallelAIQueues_Building { false }

src/Ext/TechnoType/Body.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
220220
this->NoSecondaryWeaponFallback_AllowAA.Read(exINI, pSection, "NoSecondaryWeaponFallback.AllowAA");
221221

222222
this->JumpjetRotateOnCrash.Read(exINI, pSection, "JumpjetRotateOnCrash");
223+
this->ShadowSizeCharacteristicHeight.Read(exINI, pSection, "ShadowSizeCharacteristicHeight");
223224

224225
this->DeployingAnim_AllowAnyDirection.Read(exINI, pSection, "DeployingAnim.AllowAnyDirection");
225226
this->DeployingAnim_KeepUnitVisible.Read(exINI, pSection, "DeployingAnim.KeepUnitVisible");
@@ -327,7 +328,21 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
327328

328329
this->TurretOffset.Read(exArtINI, pArtSection, "TurretOffset");
329330
this->TurretShadow.Read(exArtINI, pArtSection, "TurretShadow");
330-
this->ShadowIndices.Read(exArtINI, pArtSection, "ShadowIndices");
331+
ValueableVector<int> shadow_indices;
332+
shadow_indices.Read(exArtINI, pArtSection, "ShadowIndices");
333+
ValueableVector<int> shadow_indices_frame;
334+
shadow_indices_frame.Read(exArtINI, pArtSection, "ShadowIndices.Frame");
335+
if (shadow_indices_frame.size() != shadow_indices.size())
336+
{
337+
if (!shadow_indices_frame.empty())
338+
Debug::LogGame("[Developer warning] %s ShadowIndices.Frame size (%d) does not match ShadowIndices size (%d) \n"
339+
, pSection, shadow_indices_frame.size(), shadow_indices.size());
340+
shadow_indices_frame.resize(shadow_indices.size(), -1);
341+
}
342+
for (size_t i = 0; i < shadow_indices.size(); i++)
343+
this->ShadowIndices[shadow_indices[i]] = shadow_indices_frame[i];
344+
345+
this->ShadowIndex_Frame.Read(exArtINI, pArtSection, "ShadowIndex.Frame");
331346

332347
this->LaserTrailData.clear();
333348
for (size_t i = 0; ; ++i)
@@ -440,6 +455,7 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
440455
.Process(this->TurretOffset)
441456
.Process(this->TurretShadow)
442457
.Process(this->ShadowIndices)
458+
.Process(this->ShadowIndex_Frame)
443459
.Process(this->Spawner_LimitRange)
444460
.Process(this->Spawner_ExtraLimitRange)
445461
.Process(this->Spawner_DelayFrames)
@@ -520,7 +536,7 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
520536
.Process(this->NoAmmoWeapon)
521537
.Process(this->NoAmmoAmount)
522538
.Process(this->JumpjetRotateOnCrash)
523-
539+
.Process(this->ShadowSizeCharacteristicHeight)
524540
.Process(this->DeployingAnim_AllowAnyDirection)
525541
.Process(this->DeployingAnim_KeepUnitVisible)
526542
.Process(this->DeployingAnim_ReverseForUndeploy)

src/Ext/TechnoType/Body.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class TechnoTypeExt
3838

3939
Valueable<PartialVector3D<int>> TurretOffset;
4040
Nullable<bool> TurretShadow;
41-
ValueableVector<int> ShadowIndices;
41+
Valueable<int> ShadowIndex_Frame;
42+
std::map<int, int> ShadowIndices;
4243
Valueable<bool> Spawner_LimitRange;
4344
Valueable<int> Spawner_ExtraLimitRange;
4445
Nullable<int> Spawner_DelayFrames;
@@ -127,6 +128,7 @@ class TechnoTypeExt
127128
Valueable<int> NoAmmoAmount;
128129

129130
Valueable<bool> JumpjetRotateOnCrash;
131+
Nullable<int> ShadowSizeCharacteristicHeight;
130132

131133
Valueable<bool> DeployingAnim_AllowAnyDirection;
132134
Valueable<bool> DeployingAnim_KeepUnitVisible;
@@ -229,6 +231,7 @@ class TechnoTypeExt
229231
, TurretOffset { { 0, 0, 0 } }
230232
, TurretShadow { }
231233
, ShadowIndices { }
234+
, ShadowIndex_Frame { 0 }
232235
, Spawner_LimitRange { false }
233236
, Spawner_ExtraLimitRange { 0 }
234237
, Spawner_DelayFrames {}
@@ -280,7 +283,7 @@ class TechnoTypeExt
280283
, NoAmmoWeapon { -1 }
281284
, NoAmmoAmount { 0 }
282285
, JumpjetRotateOnCrash { true }
283-
286+
, ShadowSizeCharacteristicHeight { }
284287
, DeployingAnim_AllowAnyDirection { false }
285288
, DeployingAnim_KeepUnitVisible { false }
286289
, DeployingAnim_ReverseForUndeploy { true }

0 commit comments

Comments
 (0)