Thread: Blink vs Fade
View Single Post
Old 05 August 2017, 16:44   #4
emufan
Registered User
 
Join Date: Feb 2012
Location: #DrainTheSwamp
Posts: 4,545
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?

Last edited by emufan; 05 August 2017 at 17:55.
emufan is offline  
 
Page generated in 0.04370 seconds with 11 queries