Actor dynamic translucency change

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Zeberpal
Posts: 189
Joined: Sun Apr 28, 2013 2:06 am
Location: RU

Actor dynamic translucency change

Post by Zeberpal »

I posted it earlier in the "How do I" thread, but I figured it might be a little messy discussing it out there.
Spoiler: Linedef Translucency demo
I have this script, which makes a linedef texture dynamically change it's translucency, depending on Player's location regarding that line.
I had a hard time trying to make it myself, however it was entirely redone by ZZYZX afterwards.

Code: Select all

script 1 ENTER
{
    for (int i = 1; i <= 99; i++)
        ACS_NamedExecuteWithResult("LineTransDynamic", i, 0, 0, 0);
}

script "LineTransDynamic" (int i)
{
    int cx = GetActorX(i);
    int cy = GetActorY(i);
    int cz = GetActorZ(i);

    int dst = VectorLength(GetActorZ(0)-cz, VectorLength(GetActorX(0)-cx, GetActorY(0)-cy))>>16;

    int maxdst = 512; // not 256.0

    int alpha = 0;
    if (dst <= maxdst) alpha = 255-(dst*255/maxdst);

    TranslucentLine(i, alpha, 0);

    Delay(1);
    restart;
}
I thought it would be rather easy to "convert it" for the Actors to do the same thing.
Spoiler: So what I did was..
It doesn't work. I'm trying to figure out what I did wrong. WorldendDominator pointed out to "make sure you have the activators right".
So for a moment I thought I should try something like this:
Spoiler: addition to previous code
but still.. :x
RaveYard
Posts: 186
Joined: Fri Apr 12, 2013 10:51 am

Re: Actor dynamic translucency change

Post by RaveYard »

TranslucentLine's alpha paremeter is in 0 to 255 range, but you must use fixed point value of 0.0 to 1.0 in actor's alpha.
User avatar
Zeberpal
Posts: 189
Joined: Sun Apr 28, 2013 2:06 am
Location: RU

Re: Actor dynamic translucency change

Post by Zeberpal »

RaveYard wrote:TranslucentLine's alpha paremeter is in 0 to 255 range, but you must use fixed point value of 0.0 to 1.0 in actor's alpha.
Thanks for reply RaveYard, I tried a few variants taking into account your advice
Spoiler: A
Spoiler: B
I think I understand what I did wrong, but still cant understand how to fix it. There are two type of "numbers" - X.X(fixed) and uhh.. XXX. To commence this "mixed" operation, I have to use just one type of it, so Zdoom would do a correct calculation, right? It kinda looks like 2 different operatins - calculating the distance and calculating the actor's alpha are two different ops with two different rules. I really don't know..
RaveYard
Posts: 186
Joined: Fri Apr 12, 2013 10:51 am

Re: Actor dynamic translucency change

Post by RaveYard »

I think I understand what I did wrong, but still cant understand how to fix it. There are two type of "numbers" - X.X(fixed) and uhh.. XXX. To commence this "mixed" operation, I have to use just one type of it, so Zdoom would do a correct calculation, right? It kinda looks like 2 different operatins - calculating the distance and calculating the actor's alpha are two different ops with two different rules. I really don't know..
I recommend you take look here:
https://zdoom.org/wiki/Fixed_point_number

In either case, note that here:

Code: Select all

int dst = VectorLength(GetActorZ(0)-cz, VectorLength(GetActorX(0)-cx, GetActorY(0)-cy))>>16;
The coordinates and the resulting distance is in fixed point, but there's also '>>16' at the end which turns the result into integer.

If you take the B variant and change this line:

Code: Select all

SetActorProperty(i, APROP_Alpha, FixedDiv(alpha, 256.0));
to this:

Code: Select all

SetActorProperty(i, APROP_Alpha, FixedDiv(alpha << 16, 255.0));
It should work. But I'd recommend that you actually go and redo the calculations so that the entire thing is just with fixed point instead of trying quick solutions.
User avatar
Zeberpal
Posts: 189
Joined: Sun Apr 28, 2013 2:06 am
Location: RU

Re: Actor dynamic translucency change

Post by Zeberpal »

I try my vest to understand how to do it a good way
RaveYard wrote:
[/code]
SetActorProperty(i, APROP_Alpha, FixedDiv(alpha << 16, 255.0));
[/code]
Uhh, it didn't work unfortunately.

However I tried to "recalculate" to fixed, but still Image

Code: Select all

script "ActorTransDynamic" (int i)
{
    int cx = GetActorX(i);
    int cy = GetActorY(i);
    int cz = GetActorZ(i);

    int dst = VectorLength(GetActorZ(0)-cz, VectorLength(GetActorX(0)-cx, GetActorY(0)-cy))>>16;

    int maxdst = 512<<16; //

    int alpha = 0.0;
    if (dst <= maxdst) alpha = 255<<16-(dst*255<<16/maxdst);
			SetActorProperty(i, APROP_Alpha, (alpha << 16));
			SetActorProperty(i, APROP_RenderStyle, STYLE_Normal);

    Delay(1);
    restart;
}

script 1 ENTER
{
    for (int i = 31; i <= 35; i++)
        ACS_NamedExecuteWithResult("ActorTransDynamic", i, 0, 0, 0);
}
RaveYard
Posts: 186
Joined: Fri Apr 12, 2013 10:51 am

Re: Actor dynamic translucency change

Post by RaveYard »

It works, but you are using wrong renderstyle which ignores alpha.

Use STYLE_Translucent instead.

Edit:
Instead of this:

Code: Select all

512<<16
It's much better to write this:

Code: Select all

512.0
The dot is what tells the compiler if it is fixed point or integer that you've written.
User avatar
Zeberpal
Posts: 189
Joined: Sun Apr 28, 2013 2:06 am
Location: RU

Re: Actor dynamic translucency change

Post by Zeberpal »

Oh wow, It worked! Thank you RaveYard, for calculation explanation as well, it makes much more sense now :wink:
Post Reply

Return to “Scripting”