]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix case of trails not being drawn on CSQC models with unset alpha.
authorRudolf Polzer <divVerent@gmail.com>
Thu, 2 Jan 2025 23:58:19 +0000 (18:58 -0500)
committerRudolf Polzer <divVerent@gmail.com>
Thu, 2 Jan 2025 23:58:19 +0000 (18:58 -0500)
That bug was found by Mario in
https://gitlab.com/xonotic/xonotic-data.pk3dir/-/merge_requests/1410#note_2279399941
and was actually pre-existing even before the change, as it was passing
0 to both alpha and count modifiers.

qcsrc/client/weapons/projectile.qc

index eef49221d19a83d80e728c166d33d43d84355e95..a10b09df9efcf428e109b8cb9afb4ffa8f7b2cc8 100644 (file)
@@ -38,6 +38,10 @@ void Projectile_DrawTrail(entity this, vector to)
                if (from == to)
                        from.z += 1;
 
+       // Note: alpha value 0 actually means 1 on entities.
+       // This can be relevant when coming from CSQCModel_Effects_Apply.
+       float a = (this.alpha == 0) ? 1 : this.alpha;
+
        // TODO: Do we actually need alpha support? Consider removing this
        // support entirely and instead making necessary adjustments in
        // effectinfo.
@@ -45,17 +49,17 @@ void Projectile_DrawTrail(entity this, vector to)
        // 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)
+       if (this.traileffect && a > 0)
        {
                float f = PARTICLES_DRAWASTRAIL;
-               if (this.alpha < 1)
+               if (a < 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)
+                       particles_fade = pow(a, fade_power);
+                       particles_alphamin = particles_alphamax = a / particles_fade;  // == pow(a, 1 - fade_power)
                        f |= PARTICLES_USEALPHA | PARTICLES_USEFADE;
                        //LOG_INFOF("particle fade: %f alpha: %f", particles_fade, particles_alphamin);
                }