English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. C/C++ (https://eab.abime.net/forumdisplay.php?f=118)
-   -   Blink vs Fade (https://eab.abime.net/showthread.php?t=88125)

emufan 02 August 2017 21:09

Blink vs Fade
 
I have a blinking plugin, which i want to fade over time.
the blinking one just alternates between max and min value at the given interval.

the simple code doing the blink is this:
Code:

        //Find which value to use
        if((defInst->frame % (defInst->period * 2)) < defInst->period)
                fResult = defInst->fPer1;
        else
                fResult = defInst->fPer2;

frame = current frame
period = interval ( lets say we can make it the last frame in scene)
fPer1 = min value
fPer2 = max value

is there a simple way to make it fade ? :)

Photon 02 August 2017 21:33

Code:

        fFactor = (defInst->fPer2-defInst->fPer1) / defInst->period;

        if((defInst->frame % (defInst->period * 2)) < defInst->period)
                fResult = defInst->fPer1 + (frame % (defInst->period)) * fFactor;
        else
                fResult = defInst->fPer2 - (frame % (defInst->period)) * fFactor;


emufan 02 August 2017 21:57

*crazy* stuff - thanks alot.
we now have envelope on surface attributes. :D

emufan 05 August 2017 16:44

i've extended the version above, to do the animation only in a given interval,
defining start and end frame.
somehow it does work, but it looks a bit odd, not sure where i made a mistake:
Code:

XCALL_(void) evaluate(LWInstance inst, ShaderAccess *sa)
{
        BLINKER *defInst = (BLINKER *)(inst);

        //To hold the result
        float fResult;
        float fFactor;
        int start = defInst->period1;
        int end = defInst->period2;

//        if ((defInst->frame < start) || (defInst->frame > end))
//          return (NULL);

        //Find which value to use
        fFactor = (defInst->fPer2-defInst->fPer1) / (defInst->period2-defInst->period1);

        if((defInst->frame % (defInst->period1 * 2)) < defInst->period1)
            fResult = defInst->fPer1 + (defInst->frame % (defInst->period1)) * fFactor;
        else
            fResult = defInst->fPer2 - (defInst->frame % (defInst->period1)) * fFactor;

        //Put it onto the surface
        switch(defInst->uChannel)
        {
        case LUMINOUS:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->luminous = fResult;
                break;
        case DIFFUSE:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->diffuse = fResult;
                break;
        case SPECULAR:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->specular = fResult;
                break;
        case MIRROR:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->mirror = fResult;
                break;
        case TRANSP:
                if ((defInst->frame < start) || (defInst->frame > end))
                break;
                sa->transparency = fResult;
                break;
        }

        return;
}

fPer1 and fPer2 are min max value of the surface attribute (eg. luminosity)
frame is the current frame.

#1) i've added the whole fucntion, since i think it must be of importance,
where it checks, if we are in the range (start -> end).
but it does still some weird blinking at some point, instead of fading all the time.

does it look right, is the math with period1/period2 and start/end correct?
or is there something wrong?

emufan 06 August 2017 15:25

1 Attachment(s)
i replaced all (defInst->period1) with (defInst->period2 - defInst->period1)
it's looking better now, but not yet perfect :)

#1) removing the range check made it work as i want it to do :cool
needs some more tests with the desired range, but looking good for now.


All times are GMT +2. The time now is 04:33.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.05030 seconds with 11 queries