Optimize item sparkles + distance fade teleport sparkles.

This commit is contained in:
Mari the Deer 2022-12-30 11:38:33 +01:00
commit 3a00eac766
2 changed files with 68 additions and 10 deletions

View file

@ -809,6 +809,9 @@ Class SWWMTeleportDest : SWWMNonInteractiveActor
flare.flags = SPF_FULLBRIGHT;
flare.fadestep = -1;
}
double dist = Distance3DSquared(players[consoleplayer].Camera);
if ( dist >= 250000. ) return;
double alph = clamp((250000.-dist)/250000.,0.,1.);
flare.pos = pos+(0,0,28);
int numpt = Random[ExploS](0,2);
for ( int i=0; i<numpt; i++ )
@ -820,7 +823,7 @@ Class SWWMTeleportDest : SWWMNonInteractiveActor
flare.size = FRandom[ExploS](2.,4.);
flare.sizestep = FRandom[ExploS](-.02,-.01);
flare.vel = pvel;
flare.startalpha = FRandom[ExploS](.15,.3);
flare.startalpha = FRandom[ExploS](.15,.3)*alph;
level.SpawnParticle(flare);
}
}
@ -867,17 +870,22 @@ Class SWWMTeleportLine : SWWMNonInteractiveActor
}
for ( int i=0; i<numpt; i++ )
{
double d = FRandom[ExploS](0.,1.);
Vector3 ppos = bpos*d+apos*(1.-d)+(0,0,FRandom[ExploS](1,4));
Vector3 rpos = level.Vec3Diff(ppos,players[consoleplayer].Camera.pos);
double dist = rpos dot rpos;
if ( dist >= 250000. ) continue;
double alph = clamp((250000.-dist)/250000.,0.,1.);
double ang = FRandom[ExploS](0,360);
double pt = FRandom[ExploS](-90,90);
Vector3 pvel = SWWMUtility.Vec3FromAngles(ang,pt)*FRandom[ExploS](.0,.3);
double d = FRandom[ExploS](0.,1.);
flare.lifetime = Random[ExploS](120,240);
flare.size = FRandom[ExploS](2.,4.);
flare.sizestep = FRandom[ExploS](-.02,-.01);
flare.pos = bpos*d+apos*(1.-d)+(0,0,FRandom[ExploS](1,4));
flare.pos = ppos;
flare.vel = pvel;
flare.accel = (0,0,FRandom[ExploS](.05,.1));
flare.startalpha = FRandom[ExploS](.15,.3);
flare.startalpha = FRandom[ExploS](.15,.3)*alph;
level.SpawnParticle(flare);
}
}
@ -973,6 +981,50 @@ Class SWWMPickupFlash : SWWMNonInteractiveActor
s.alpha *= .5;
}
}
// needed since cube roots scale very badly when there's thousands of these on the map
private static double AlphaCubeRoot( double alpha )
{
double lut[256] =
{
0.000000000, 0.250244738, 0.297592823, 0.329340597, 0.353899503, 0.374203165, 0.391654181, 0.407042226,
0.420859807, 0.433436601, 0.445005066, 0.455735780, 0.465757939, 0.475171947, 0.484057512, 0.492479061,
0.500489477, 0.508132748, 0.515445890, 0.522460372, 0.529203190, 0.535697696, 0.541964232, 0.548020638,
0.553882655, 0.559564246, 0.565077860, 0.570434647, 0.575644637, 0.580716886, 0.585659603, 0.590480253,
0.595185647, 0.599782016, 0.604275079, 0.608670097, 0.612971920, 0.617185033, 0.621313591, 0.625361451,
0.629332199, 0.633229179, 0.637055512, 0.640814114, 0.644507720, 0.648138893, 0.651710042, 0.655223431,
0.658681194, 0.662085345, 0.665437783, 0.668740305, 0.671994612, 0.675202314, 0.678364941, 0.681483943,
0.684560698, 0.687596518, 0.690592652, 0.693550290, 0.696470567, 0.699354564, 0.702203318, 0.705017817,
0.707799006, 0.710547792, 0.713265041, 0.715951586, 0.718608224, 0.721235720, 0.723834810, 0.726406200,
0.728950569, 0.731468570, 0.733960833, 0.736427963, 0.738870544, 0.741289137, 0.743684287, 0.746056516,
0.748406329, 0.750734215, 0.753040646, 0.755326076, 0.757590947, 0.759835686, 0.762060704, 0.764266402,
0.766453167, 0.768621373, 0.770771384, 0.772903552, 0.775018219, 0.777115716, 0.779196366, 0.781260480,
0.783308363, 0.785340308, 0.787356603, 0.789357525, 0.791343346, 0.793314328, 0.795270729, 0.797212796,
0.799140774, 0.801054897, 0.802955396, 0.804842496, 0.806716415, 0.808577364, 0.810425553, 0.812261184,
0.814084452, 0.815895552, 0.817694672, 0.819481993, 0.821257696, 0.823021954, 0.824774940, 0.826516818,
0.828247753, 0.829967903, 0.831677424, 0.833376467, 0.835065182, 0.836743713, 0.838412204, 0.840070792,
0.841719614, 0.843358803, 0.844988489, 0.846608801, 0.848219862, 0.849821795, 0.851414720, 0.852998754,
0.854574013, 0.856140608, 0.857698650, 0.859248247, 0.860789506, 0.862322530, 0.863847421, 0.865364279,
0.866873203, 0.868374287, 0.869867628, 0.871353317, 0.872831445, 0.874302101, 0.875765373, 0.877221347,
0.878670107, 0.880111737, 0.881546317, 0.882973927, 0.884394645, 0.885808550, 0.887215717, 0.888616220,
0.890010132, 0.891397525, 0.892778470, 0.894153037, 0.895521294, 0.896883307, 0.898239144, 0.899588868,
0.900932545, 0.902270236, 0.903602004, 0.904927909, 0.906248011, 0.907562370, 0.908871043, 0.910174088,
0.911471559, 0.912763514, 0.914050005, 0.915331088, 0.916606813, 0.917877235, 0.919142403, 0.920402368,
0.921657180, 0.922906887, 0.924151539, 0.925391181, 0.926625862, 0.927855627, 0.929080522, 0.930300591,
0.931515878, 0.932726428, 0.933932282, 0.935133484, 0.936330074, 0.937522094, 0.938709585, 0.939892586,
0.941071137, 0.942245277, 0.943415044, 0.944580475, 0.945741609, 0.946898482, 0.948051130, 0.949199588,
0.950343894, 0.951484081, 0.952620183, 0.953752235, 0.954880270, 0.956004322, 0.957124423, 0.958240605,
0.959352900, 0.960461340, 0.961565955, 0.962666776, 0.963763834, 0.964857158, 0.965946779, 0.967032724,
0.968115023, 0.969193704, 0.970268796, 0.971340326, 0.972408321, 0.973472809, 0.974533817, 0.975591370,
0.976645495, 0.977696218, 0.978743564, 0.979787559, 0.980828227, 0.981865593, 0.982899681, 0.983930516,
0.984958121, 0.985982520, 0.987003736, 0.988021791, 0.989036710, 0.990048513, 0.991057224, 0.992062865,
0.993065456, 0.994065020, 0.995061577, 0.996055150, 0.997045758, 0.998033422, 0.999018163, 1.000000000
};
alpha *= 255;
int low = int(floor(alpha));
int high = int(ceil(alpha));
double theta = alpha-low;
return lut[low]*(1.-theta)+lut[high]*theta;
}
void A_Shimmer()
{
if ( !target || Inventory(target).Owner )
@ -1001,11 +1053,17 @@ Class SWWMPickupFlash : SWWMNonInteractiveActor
}
else if ( !target.bFLOATBOB && bFLOATBOB ) bFLOATBOB = false;
A_SetScale(FRandom[ClientSparkles](1.1,1.3));
alpha = FRandom[ClientSparkles](.9,1.)*clamp((max(0,Distance3DSquared(players[consoleplayer].Camera)-40000.)/160000000.)**.25,0.,1.);
double camdist = Distance3DSquared(players[consoleplayer].Camera);
if ( camdist <= 40000. ) alpha = 0.;
else
{
if ( (camdist-40000.) >= 160000000. ) alpha = 1.;
else alpha = AlphaCubeRoot(clamp(max(0,camdist-40000.)/160000000.,0.,1.));
alpha *= FRandom[ClientSparkles](.9,1.);
}
// nearby sparkles
if ( !SWWMUtility.SphereIntersect(self,players[consoleplayer].Camera.pos,500) )
return;
double alph = clamp((250000.-Distance3DSquared(players[consoleplayer].Camera))/250000.,0.,1.);
if ( camdist >= 250000. ) return;
double alph = clamp((250000.-camdist)/250000.,0.,1.);
if ( !flare.texture )
{
flare.color1 = Color(Args[1]*85,Args[2]*85,Args[3]*85);