]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Skip projectile alpha math if it'd be a NOP. 1410/head
authorRudolf Polzer <divVerent@gmail.com>
Mon, 30 Dec 2024 18:06:29 +0000 (13:06 -0500)
committerRudolf Polzer <divVerent@gmail.com>
Thu, 2 Jan 2025 00:07:23 +0000 (19:07 -0500)
Also, comment why it works the way it is, and what it'd take to possibly
remove it.

qcsrc/client/weapons/projectile.qc

index 893d53ae5a1cf3fd3c190ba6d725a6df7ea43fbb..eef49221d19a83d80e728c166d33d43d84355e95 100644 (file)
@@ -38,11 +38,31 @@ void Projectile_DrawTrail(entity this, vector to)
                if (from == to)
                        from.z += 1;
 
-       if (this.traileffect)
+       // TODO: Do we actually need alpha support? Consider removing this
+       // support entirely and instead making necessary adjustments in
+       // effectinfo.
+       //
+       // Right now (2024-12-30), only Crylink can generate alpha via
+       // fade_rate/fade_time, and only PROJECTILE_PORTO_* set a fixed alpha
+       // (and reuse the Arc's TE_WIZSPIKE).
+       if (this.traileffect && this.alpha > 0)
        {
-               particles_alphamin = particles_alphamax = particles_fade = sqrt(this.alpha);
+               float f = PARTICLES_DRAWASTRAIL;
+               if (this.alpha < 1)
+               {
+                       // Do some of the fading using particle count, and some of it using alpha.
+                       // Fading by particle count is less smooth but also cheaper to render.
+                       // A higher power here performs more of the fading using particle count.
+                       const float fade_power = 0.5;
+                       particles_fade = pow(this.alpha, fade_power);
+                       particles_alphamin = particles_alphamax = this.alpha / particles_fade;  // == pow(this.alpha, 1 - fade_power)
+                       f |= PARTICLES_USEALPHA | PARTICLES_USEFADE;
+                       //LOG_INFOF("particle fade: %f alpha: %f", particles_fade, particles_alphamin);
+               }
+               //else
+               //      LOG_INFOF("particle fade skipped");
                entity eff = REGISTRY_GET(Effects, this.traileffect);
-               boxparticles(particleeffectnum(eff), this, from, to, this.velocity, this.velocity, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE | PARTICLES_DRAWASTRAIL);
+               boxparticles(particleeffectnum(eff), this, from, to, this.velocity, this.velocity, 1, f);
        }
 }