ZDoom / gzdoom

GZDoom is a feature centric port for all Doom engine games, based on ZDoom, adding an OpenGL renderer and powerful scripting capabilities
http://zdoom.org
GNU General Public License v3.0
2.47k stars 540 forks source link

SPF_ACTORSCALE for textured particles #2556

Open MajorCooke opened 5 months ago

MajorCooke commented 5 months ago

Messing with particle scales is difficult and trying to match them to an actor requires a lot of tweaking. I think it'd be helpful to have a flag that gives the same scaling as actors for particles.

Of course, that name is just placeholder. Call it whatever you'd like.

jekyllgrim commented 5 months ago

Replied in Discord, will reply here in the inerest of completeness: actor scaling can be approximated with the formula texture size * actor scale * 2. But without separate X/Y sizing adding a whole flag for this doesn't strike me as particularly necessary.

Example:


class pptest : DoomImpBall
{
    Default
    {
        scale 0.34822; //use any weird scale
    }
    override void Tick()
    {
        Super.Tick();
        if (isFrozen()) return;
        FSpawnParticleParams p;
        TextureID tex = curstate.GetSpriteTexture(0);
        if (!tex || !tex.IsValid()) return;
        p.size = TexMan.GetSize(tex) * scale.x * 2;
        p.style = GetRenderstyle();
        p.color1 = "";
        p.texture = tex;
        p.flags = SPF_ROLL;
        p.startroll = 180;
        p.startalpha = 1.0;
        p.lifetime = 35;
        p.fadestep = -1;
        p.pos = pos;
        Level.SpawnParticle(p);
    }
}```
MajorCooke commented 4 months ago

That doesn't work appropriately. I tried a variety of things but couldn't get it to match. Even copying your code directly.

madame-rachelle commented 4 months ago

The particles are slightly shrunk. Also GZDoom seems to force actors to be 1 or 2 texels wider than the particle renderer does, for some odd reason. Not sure why or how that works, I can only speak for the scaling that I added to try and make particles approximately close to the same size that they were before they were turned into true squares.

This was the math to shrink it: scalefac *= 2 * ps / (ps * ps + 1); - all that needs to be done is to reverse that. Essentially with default scaling it is multiplying by (2.4 / 2.44). These values could be subject to change, however.

MajorCooke commented 4 months ago

Huh. Alright then I'll give that a try.

madame-rachelle commented 4 months ago

I think it's worth noting - for VisualThinkers and Actors, if you activate the +ROLL flag on either of those, they will use the same math to shrink themselves down to the square pixel ratio also. Again, it was to try and make them appear to be somewhat the same size that they were, even if they got a little stretched on the X axis to accommodate the change. So if you want your actors to be the same size, activating the +ROLL will instantly do that. But keep in mind what I said before - Actors, for some reason, do still expand themselves out by a texel or two.

MajorCooke commented 4 months ago

Jekyll suggested a flag to change that so that stretching behavior can be toggled for particles. That sounds like a wise idea to include.