Skip to content

Commit 1212188

Browse files
committed
Use Spring.SetUnitAlwaysUpdateMatrix to draw cloak fading units (thanks ivand).
Tweak visuals a little.
1 parent 6275833 commit 1212188

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

LuaRules/Gadgets/cus_gl4.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ local initiated = false
347347
local featuresDefsWithAlpha = {} -- featureDefIDs (ie trees) that should be drawn with alpha.
348348
local unitDefsUseSkinning = {} -- unitDefIDs that use the bones and stretchy skin system
349349

350-
local ENEMY_CLOAK_FRAMES = false -- 4 -- How many extra frames to show enemy units for.
350+
local ENEMY_CLOAK_FRAMES = 10 -- How many extra frames to show enemy units for.
351351
local cloakDeferFrame = {}
352352
local keepDrawFlagChecking = false -- a list of units that need draw flag checking
353353

@@ -1425,24 +1425,27 @@ local function RemoveObject(objectID, reason) -- we get pos/neg objectID here
14251425
end
14261426
end
14271427

1428-
local function ProcessCusUnit(unitID, drawFlag, gameFrame, reason)
1428+
local function ProcessCusUnit(unitID, drawFlag, gameFrame, reason)
14291429
if debugmode then Spring.Echo("ProcessUnits", unitID, drawFlag, reason) end
14301430

14311431
if cloakDeferFrame[unitID] and ((not drawFlag) or drawFlag == 0) then
14321432
if cloakDeferFrame[unitID] < gameFrame then
14331433
cloakDeferFrame[unitID] = nil
14341434
end
14351435
if not Spring.ValidUnitID(unitID) then
1436+
cloakDeferFrame[unitID] = nil
14361437
return
14371438
end
14381439
if cloakDeferFrame[unitID] then
14391440
drawFlag = 1
14401441
keepDrawFlagChecking = keepDrawFlagChecking or {}
14411442
keepDrawFlagChecking[#keepDrawFlagChecking + 1] = unitID
1443+
else
1444+
Spring.SetUnitAlwaysUpdateMatrix(unitID, false)
14421445
end
14431446
end
14441447
if not drawFlag then
1445-
drawFlag = Spring.GetUnitDrawFlag(unitID)
1448+
drawFlag = Spring.GetUnitDrawFlag(unitID) or 0
14461449
end
14471450

14481451
if math_bit_and(drawFlag, 34) > 0 then -- has alpha (2) or alphashadow(32) flag
@@ -2071,6 +2074,7 @@ function gadget:UnitCloaked(unitID)
20712074
gl.SetUnitBufferUniforms(unitID, uniformCache, 12)
20722075
wantTranparent[unitID] = true
20732076
if not allyUnit then
2077+
Spring.SetUnitAlwaysUpdateMatrix(unitID, true)
20742078
keepDrawFlagChecking = keepDrawFlagChecking or {}
20752079
keepDrawFlagChecking[#keepDrawFlagChecking + 1] = unitID
20762080
cloakDeferFrame[unitID] = frame + ENEMY_CLOAK_FRAMES

LuaRules/Gadgets/lups_cloak_fx.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ local CloakEffect = {
8282
{ class='Sound',options={ file="sounds/cloak.wav",volume=0.9 } },
8383
}
8484
local EnemyCloakEffect = {
85-
{ class='UnitCloaker',options={ life=30} },
85+
--{ class='UnitCloaker',options={ life=30} },
8686
{ class='Sound',options={ file="sounds/cloak.wav",volume=0.9 } },
8787
}
8888

ModelMaterials_GL4/templates/cus_gl4.frag.glsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,16 +1302,16 @@ void main(void){
13021302
if (cloakTime > 0){
13031303
if (isEnemy) {
13041304
cloakTime = cloakTime - 1000000.0;
1305-
cloakedness = (timeInfo.x - cloakTime) / 4.0;
1306-
if (cloakedness > 2.0) {
1305+
cloakedness = (timeInfo.x - cloakTime) / 9.0;
1306+
if (cloakedness > 1.5) {
13071307
// Enough time has passed to fully hide the unit, must be a spectator with a bad state
13081308
isEnemy = false;
13091309
} else {
13101310
outlineValue = 0.0;
13111311
}
13121312
cloakedness = clamp(cloakedness, 0.0, 1.0);
13131313
} else {
1314-
cloakedness = clamp((timeInfo.x - cloakTime) / 8.0, 0.0, 1.0);
1314+
cloakedness = clamp((timeInfo.x - cloakTime) / 9.0, 0.0, 1.0);
13151315
}
13161316
//outColor.g = 1.0;
13171317
}
@@ -1329,11 +1329,11 @@ void main(void){
13291329
float perlinline2 = clamp(1.0 - 20* abs(myPerlin.g - fract(simFrame * 0.005 + 0.5)), 0.0, 1.0);
13301330
float cloaknoise = cloakedness*perlinline1 + cloakedness*perlinline2;
13311331
if (isEnemy) {
1332-
texColor2.a = 1.0 - clamp(cloakedness * (1.0 + cloaknoise * 5.0), 0.0, 1.0);
1332+
texColor2.a = 1.0 - clamp(cloakedness * (1.0 + cloaknoise * 2.0), 0.0, 1.0);
13331333
} else {
1334-
outColor.rgb = mix(outColor.rgb, teamCol.rgb, cloakedness*0.5);
1334+
outColor.rgb = mix(outColor.rgb, teamCol.rgb, cloakedness*(0.2 + (perlinline2 + perlinline2) * 1.5));
13351335
}
1336-
outColor.rgb += cloaknoise * 0.85;
1336+
outColor.rgb += cloaknoise * 0.8;
13371337

13381338
#if 1
13391339
float dotcamera = dot(worldNormal, V);

0 commit comments

Comments
 (0)