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!)

Actor dynamic translucency change

Postby Zeberpal » Sun Nov 19, 2017 8:01 am

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 allExpand view
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
User avatar
Zeberpal
 
Joined: 28 Apr 2013
Location: RU

Re: Actor dynamic translucency change

Postby RaveYard » Sun Nov 19, 2017 8:29 am

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.
RaveYard
 
Joined: 12 Apr 2013

Re: Actor dynamic translucency change

Postby Zeberpal » Sun Nov 19, 2017 9:10 am

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..
User avatar
Zeberpal
 
Joined: 28 Apr 2013
Location: RU

Re: Actor dynamic translucency change

Postby RaveYard » Sun Nov 19, 2017 9:28 am

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 allExpand view
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 allExpand view
SetActorProperty(i, APROP_Alpha, FixedDiv(alpha, 256.0));

to this:
Code: Select allExpand view
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.
RaveYard
 
Joined: 12 Apr 2013

Re: Actor dynamic translucency change

Postby Zeberpal » Sun Nov 19, 2017 10:47 am

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 allExpand view
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);
}
User avatar
Zeberpal
 
Joined: 28 Apr 2013
Location: RU

Re: Actor dynamic translucency change

Postby RaveYard » Sun Nov 19, 2017 1:49 pm

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

Use STYLE_Translucent instead.

Edit:
Instead of this:
Code: Select allExpand view
512<<16

It's much better to write this:
Code: Select allExpand view
512.0


The dot is what tells the compiler if it is fixed point or integer that you've written.
RaveYard
 
Joined: 12 Apr 2013

Re: Actor dynamic translucency change

Postby Zeberpal » Sun Nov 19, 2017 3:08 pm

Oh wow, It worked! Thank you RaveYard, for calculation explanation as well, it makes much more sense now :wink:
User avatar
Zeberpal
 
Joined: 28 Apr 2013
Location: RU


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest