Author Topic: Animated Backgrounds?  (Read 52524 times)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #195 on: January 04, 2020, 09:14:01 pm »
I am very pleased of the result, that was exactly what i had in mind.

Next challenge should be the scene lighting.
« Last Edit: January 04, 2020, 10:12:25 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #196 on: January 05, 2020, 06:37:29 am »
I don't think the overall effect of modulating scene lighting ("straylight") would be much different from what you have now.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #197 on: January 05, 2020, 10:13:24 am »
I was not thinking of straylight that is very obvious, but multilight using a custom color gradient to match the pulse level in Mobj_lightSettings.

And we could use this in the material file, just the same than with the new #pulse meta
#front_A (AMBIENT)
#front_D (DIFFUSE)
#front_S (SPECULAR)

#left_A (AMBIENT)
#left_D (DIFFUSE)
#left_S (SPECULAR)

#right_A (AMBIENT)
#right_D (DIFFUSE)
#right_S (SPECULAR)

#top_A (AMBIENT)
#top_D (DIFFUSE)
#top_S (SPECULAR)
« Last Edit: January 05, 2020, 11:20:05 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #198 on: January 05, 2020, 01:34:17 pm »
I think there's no need to add new notation for light pulsing at all. You can just add more numeric parameters to the existing #Light frontAmbient 0 0 0 etc. lines. That #Light notation is already too bulky in there to still extend it any further with dozens of new #metas...
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #199 on: January 05, 2020, 02:03:11 pm »
Now that the code is working well, i shall make a little code optimization to use BASS_ChannelGetLevel only once per gl_DrawScene call.
I shall try to use a colorLUT with lighting to see the effect it can produce.

Added:
Because lighting is global rather than mesh specific, the effect must be very subtle ???

See the attached code (search for // PAT: 01-05-2020)

and play with that one:

void gl_DrawScene() {
    if (gP.bGiration || gP.bUseFPS || gP.bAnimateLights || // lights/reset animation support added
        gP.bRotation || gP.bIsLerping || gP.tCurAniBkgndShader.nShaderID) // gP.bRotation, means meta #rotate is being used
        gP.bRedraw = TRUE;
    if (!gP.bRedraw || !IsWindowVisible(gP.hGL))
        return;

    gP.bDoneRender = TRUE;

    // PAT: 12-25-2019
    float rGiroStep = gP.rGiroStep;
    if (gB.channel) {
        if (gP.bSyncAudio) {
            DWORD nLevel = BASS_ChannelGetLevel(gB.channel);
            gP.audioLevel = max(LOINT(nLevel), HIINT(nLevel));
            rGiroStep = gP.audioLevel / (float)67200;

            // PAT: 01-05-2020
            // WARNING, this is for test only!
            long ColorRange = min((long) ((nLevel / 32767.0f)*32.0f), 32);
            BYTE a = 255, r = 0, g = 0, b = 0;
            ColorLUT(rand()%(33-ColorRange), r, g, b);
            //SETCOLORAMB(0);
            //SETCOLORDIF(0);
            //SETCOLORSPEC(0);
            //ColorLUT(ColorRange, r, g, b);
            SETCOLORDIF(1);
            SETCOLORDIF(2);
            SETCOLORDIF(3);


        }
    }

    static CHAR zMsg[16];
    static DWORD nCount, nFPS;
« Last Edit: January 05, 2020, 05:32:37 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #200 on: January 05, 2020, 07:04:27 pm »
Seems to compile fine. Which model should I use to test?
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #201 on: January 05, 2020, 07:45:26 pm »
you can try with robots2

try with this:
ColorLUT(ColorRange, r, g, b);
that will use the full range of the ColorLUT, mostly red in OR, because i have used the same LUT than in BassBox (for comparison purpose), but it is not well suited for OR.

you can also play with the
SETCOLORAMB
or the other settings

Patrice
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #202 on: January 06, 2020, 03:57:15 pm »
Here is a minor fix:

void gl_DrawScene() {
    if (gP.bGiration || gP.bUseFPS || gP.bAnimateLights || // lights/reset animation support added
        gP.bRotation || gP.bIsLerping || gP.tCurAniBkgndShader.nShaderID || gP.bSyncAudio) // gP.bRotation, means meta #rotate is being used
        gP.bRedraw = TRUE;


Following your previous suggestion:
Rather than individual boolean flag, we could use power of 2 for each parameter, and use CheckStyle as i have done for PulseLight.
And a new global DWORD gP.DrawScene parameter to enable disable each of them, and get rid of all the extra boolean flags.
« Last Edit: January 06, 2020, 04:14:36 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #203 on: January 06, 2020, 05:49:02 pm »
Rather than individual boolean flag, we could use power of 2 for each parameter, and use CheckStyle as i have done for PulseLight.

In MS VC++, bitfields can be scoped within a union to an ordinary struct with a unique name for each bitfield, e.g.:

union {
    struct {
        unsigned int bGiration: 1 = 0; // type name: size in bits = initialization
        unsigned int bUseFPS: 1 = 0;
        unsigned int bAnimateLights: 1 = 0;
        unsigned int bRotation: 1 = 0;
        unsigned int bIsLerping: 1 = 0;
        unsigned int bSyncAudio: 1 = 0;
        unsigned int unused: 26 = 0; // currently unused
    }
    unsigned int reDraw;
}


which enables all the bitflags to be set/reset in their respective menu events exactly as they are now, whereas int reDraw (or gP.reDraw if the union is made part of gP) may be used in gl_DrawScene() as a unified BOOL flag:

if (gP.reDraw) // gP.bGiration == 1 and/or gP.bRotation == 1 etc.
        gP.bRedraw = TRUE;


gP.reDraw will stay non-FALSE (i.e. != 0) for as long as at least one named bitflag in its sibling struct in the union remains non-FALSE (i.e. != 0).
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #204 on: January 06, 2020, 09:39:36 pm »
Thanks, i am not familiar with this bitfield construction i have to try it ;)

I have attached a new pulse animation...
« Last Edit: January 07, 2020, 10:11:21 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #205 on: January 07, 2020, 10:07:20 am »
Looks neat! :)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #206 on: January 07, 2020, 10:10:52 am »
bit fields
https://docs.microsoft.com/en-us/cpp/cpp/cpp-bit-fields?view=vs-2019

While this will preserve the current source code, it seems very specific to the C++ preprocessor, and thus hard to translate to another language more accustomed to use bitset.  :-[
« Last Edit: January 07, 2020, 10:19:46 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #207 on: January 07, 2020, 12:36:00 pm »
0. I am not likely to translate the OR code into any other language besides CPP in the foreseeable future. Are you?

1. We aren't going to use bitfields wider than 1 bit, or bitfield structures other than 32 bits wide, so we aren't going to suffer from alignment problems described in the MSDN. Thus, the bitfield structure will always be exactly as wide as a DWORD. 32 bit flags are pretty much enough for all our needs as I can see them.

2. I've been using bitfields for decades without any problem for strong typing Variant variables in FBSL whenever I needed it for interfacing with strong data types in other languages (C and asm).
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1980
    • zapsolution
Re: Animated Backgrounds?
« Reply #208 on: January 07, 2020, 03:56:26 pm »
Visual Studio shokes on the use of the equal sign

union {
    struct {
        unsigned int bGiration: 1 = 0; // type name: size in bits = initialization
        unsigned int bUseFPS: 1 = 0;
        unsigned int bAnimateLights: 1 = 0;
        unsigned int bRotation: 1 = 0;
        unsigned int bIsLerping: 1 = 0;
        unsigned int bSyncAudio: 1 = 0;
        unsigned int unused: 26 = 0; // currently unused
    }
    DWORD reDraw;
}


Saying: this operator is not alowed in a constant expression.

Please send me the correct Struct PROP to use with it.
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #209 on: January 07, 2020, 05:05:41 pm »
Struct initialization is largely dependent on the C language standard a particular compiler supports.

VC doesn't allow C structures to be initialized the way I showed (FBSL used to be compiled using GCC). The VC way to define this union should be as follows: (compile as a console app)

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    union {
        struct {
            unsigned bGiration : 1; // type name: size in bits
            unsigned bUseFPS : 1;
            unsigned bAnimateLights : 1;
            unsigned bRotation : 1;
            unsigned bIsLerping : 1;
            unsigned bSyncAudio : 1;
            unsigned unused : 26; // currently unused
        };
        unsigned reDraw;
    } bFlag = { 0, 1, 0, 1, 0, 1, 0 }; // initialization

    printf("flags: %d %d %d %d %d %d, reDraw = %d, evaluates to %s\n", bFlag.bGiration, bFlag.bUseFPS, bFlag.bAnimateLights,
        bFlag.bRotation, bFlag.bIsLerping, bFlag.bSyncAudio, bFlag.reDraw, bFlag.reDraw ? "TRUE" : "FALSE");

    bFlag.reDraw = 0; // zeroize all bitflags at once

    printf("flags: %d %d %d %d %d %d, reDraw = %d, evaluates to %s\n", bFlag.bGiration, bFlag.bUseFPS, bFlag.bAnimateLights,
        bFlag.bRotation, bFlag.bIsLerping, bFlag.bSyncAudio, bFlag.reDraw, bFlag.reDraw ? "TRUE" : "FALSE");
   
    return 0;
}


Alternatively, if the compiler supports the C99 standard, it can use what's called Designated Initialization, or selective initialization of members in an arbitrary order:

........
    } bFlag = { .bGiration = 0, .bAnimateLights = 0, .bIsLerping = 0,
                .bUseFPS = 1, .bRotation = 1, .bSyncAudio = 1 }; // initialization


to the exact same effect.

Elsewhere throughout the code, the bit flags may be assigned, compared, etc. just like any other ordinary struct or union members.

The bFlag{} union may go into the gP structure as any other of its existing member fields.
« Last Edit: January 07, 2020, 05:24:56 pm by Michael Lobko-Lobanovsky »
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)