Author Topic: Animated Backgrounds?  (Read 55145 times)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #150 on: December 27, 2019, 03:02:23 pm »
1. Whatever.

2. No, I don't think it will be possible or worth it to render billboards with anything other than diffuse maps.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1982
    • zapsolution
Re: Animated Backgrounds?
« Reply #151 on: December 27, 2019, 06:55:10 pm »
I am adding an extra parameter to
#playaudio Five_Circles.mp3 50 loop sync

in mobj.h
                } else if (strcmp(szBuffer, "#playaudio") == 0) {           // 10-09-2019 Bass.dll
                    s1[0] = 0; s2[0] = 0; s3[0] = 0; s4[0] = 0;
                    fgets(szBuffer, sizeof(szBuffer), pFile);
                    sscanf(szBuffer, "%s %s %s %s", s1, s2, s3, s4);
                    MultiByteToWideChar(CP_ACP, 0, s1, lstrlenA(s1), gB.playaudio, MAX_PATH);   // gB.playaudio the audio file to play
                    gB.volume = max((float) atof(s2) / 100.0f, 0.0625f);                        // gB.volume the audio volume percentage converted to float 0.0f to 1.0f
                    if (strcmp(s3, "loop") == 0) { gB.loop = TRUE; }                            // gB.loop "loop" means play in loop mode
                    if (strcmp(s4, "sync") == 0) { gP.bSyncAudio = TRUE; }                      // PAT: 12-27-2019 play animation in sync mode with audio


in gl_LoadModel from Main.cpp

    if (lstrlen(gB.playaudio)) {                                // 10-09-2019 Bass.dll
        hCtrl = GetDlgItem(gP.hMain, IDC_AUDIO);                // PAT: 11-05-2019
        SendMessage(hCtrl, BM_SETCHECK, BST_CHECKED, 0);        // PAT: 11-05-2019
        EnableWindow(hCtrl, TRUE);                              // PAT: 11-05-2019

        hCtrl = GetDlgItem(gP.hMain, IDC_GAUGE_VOLUME);         // PAT: 12-05-2019
        if (IsWindow(hCtrl)) { EnableWindow(hCtrl, TRUE); }     // PAT: 12-05-2019

        hCtrl = GetDlgItem(gP.hMain, IDC_SYNC_AUDIO);           // PAT: 12-25-2019
        EnableWindow(hCtrl, TRUE);
        if (gP.bSyncAudio) { SendMessage(hCtrl, BM_SETCHECK, BST_CHECKED, 0); } // PAT: 12-27-2019

        WCHAR zAudioFile[MAX_PATH] = { 0 };                     // 10-09-2019 Bass.dll
        Path_Combine(zAudioFile, gP.wModelPath, gB.playaudio);  // 10-09-2019 Bass.dll
        BassChannelPlay(zAudioFile);                            // 10-09-2019 Bass.dll
    }


and a small project to test with.

Strangely this simple project doesn't work with some of the shaders.
« Last Edit: December 27, 2019, 07:57:08 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1982
    • zapsolution
Re: Animated Backgrounds?
« Reply #152 on: December 28, 2019, 04:30:50 pm »
I think i have found a work around.

Looks like, at least one mesh should use map_bump  ::)
then that works with all the animations...
« Last Edit: December 28, 2019, 04:38:25 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #153 on: December 28, 2019, 04:51:24 pm »
Yes, this happens only with the models that have transparencies but no bumpmaps and are therefore rendered by FFP on default. You don't have to supply the missing bumpmaps; just uncheck the Use fixed pipeline menu, which will force the model to be rendered via a simple shader that appears fully compatible with the animated backgrounds.

Yet another argument to finally do away with the legacy immediate mode rendering... ::)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1982
    • zapsolution
Re: Animated Backgrounds?
« Reply #154 on: December 28, 2019, 07:05:09 pm »
Quote
Yet another argument to finally do away with the legacy immediate mode rendering
NO, there are things like ambient reflection that are widely used within the model collection, and so far they are working well only in legacy mode.

Here is a new Glow project that i am using to combine billboard and animations.
« Last Edit: December 28, 2019, 07:06:43 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #155 on: December 28, 2019, 09:31:42 pm »
NO, there are things like ambient reflection that are widely used within the model collection, and so far they are working well only in legacy mode.

No Patrice,

All such projects like Mark 17, Binome, R2D2, Pyramide, Projector etc. are working better with the simple Blinn-Phong shader that's capable of displaying "ambient reflection" much more precise, lighting-wise, than legacy immediate mode!  ::)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1982
    • zapsolution
Re: Animated Backgrounds?
« Reply #156 on: December 28, 2019, 10:24:20 pm »
Then please, take either Planar or Chromosaurus, and show me with the current OR, how to create the same effect with the simple Blin-Phong shader, to replace the code below in red, with the same result.

If you can do it, then i am eager to learn how to do it myself.

in Planar
newmtl planar
#rotate 0.15 0 1 0
Ka 1 1 1
Kd 1 1 1
Ks 3.5 2.5 2.5
Ns 512
d 0.9
illum 3
refl smoke.png


in Chromosaurus
newmtl chrome
Ka 0.71 0.71 0.71
Kd 1 1 1
Ks 2 2 2
Ns 225
illum 3
refl steel6.png


newmtl gold
Ka 0.71 0.71 0.71
Kd 1 1 1
Ks 2 2 2
Ns 12
illum 3
refl gold.png


« Last Edit: December 28, 2019, 11:32:20 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #157 on: December 29, 2019, 12:31:36 am »
Heh, while I'm scrutinizing you task ;), enjoy the following two very simple shaders. I think you're going to like them:

LightRays.fs:

Code: [Select]
uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)

float rayStrength(vec2 raySource, vec2 rayRefDirection, vec2 coord, float seedA, float seedB, float speed) {
vec2 sourceToCoord = coord - raySource;
float cosAngle = dot(normalize(sourceToCoord), rayRefDirection);

return clamp(
(0.45 + 0.15 * sin(cosAngle * seedA + iTime * speed)) +
(0.3 + 0.2 * cos(-cosAngle * seedB + iTime * speed)),
0.0, 1.0) *
clamp((iResolution.x - length(sourceToCoord)) / iResolution.x, 0.5, 1.0);
}

void main() {
vec2 uv = gl_FragCoord.xy / iResolution.xy;
uv.y = 1.0 - uv.y;
vec2 coord = vec2(gl_FragCoord.x, iResolution.y - gl_FragCoord.y);


// Set the parameters of the sun rays
vec2 rayPos1 = vec2(iResolution.x * 0.7, iResolution.y * -0.4);
vec2 rayRefDir1 = normalize(vec2(1.0, -0.116));
float raySeedA1 = 36.2214;
float raySeedB1 = 21.11349;
float raySpeed1 = 1.5;

vec2 rayPos2 = vec2(iResolution.x * 0.8, iResolution.y * -0.6);
vec2 rayRefDir2 = normalize(vec2(1.0, 0.241));
const float raySeedA2 = 22.39910;
const float raySeedB2 = 18.0234;
const float raySpeed2 = 1.1;

// Calculate the colour of the sun rays on the current fragment
vec4 rays1 =
vec4(1.0, 1.0, 1.0, 1.0) *
rayStrength(rayPos1, rayRefDir1, coord, raySeedA1, raySeedB1, raySpeed1);

vec4 rays2 =
vec4(1.0, 1.0, 1.0, 1.0) *
rayStrength(rayPos2, rayRefDir2, coord, raySeedA2, raySeedB2, raySpeed2);

gl_FragColor = rays1 * 0.5 + rays2 * 0.4;

// Attenuate brightness towards the bottom, simulating light-loss due to depth.
// Give the whole thing a blue-green tinge as well.
float brightness = 1.0 - (coord.y / iResolution.y);
gl_FragColor.x *= 0.1 + (brightness * 0.8);
gl_FragColor.y *= 0.3 + (brightness * 0.6);
gl_FragColor.z *= 0.5 + (brightness * 0.5);
    gl_FragColor.a = 1.0;
}

SideScroll.fs:

Code: [Select]
uniform vec4 iDate; // (year, month, day, time in seconds) MLL: year/month/day not used
uniform vec3 iMouse; // mouse pixel coords. xy: current (if MLB down); if vec3 then z: click
uniform vec2 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)
uniform sampler2D stone_jpg;

void main() {
vec2 q = (gl_FragCoord.xy / iResolution.xy);
    vec2 uv = q - vec2(0.85);

    // Create a 3D point
    float h = 0.125; // MLL: horizon height
vec3 p = vec3(uv.x, uv.y - h - 1.0, uv.y - h);

    // Projecting back to 2D space
    vec2 uvm7 = p.xy / p.z;

    // Texture scaling if you need
    float scale = 0.5;
    uvm7 *= scale;

    // Rotations if needed
    float a = iTime * 0.05; // MLL: scroll speed
    mat2 rotation = mat2(cos(a), - sin(a), sin(a), cos(a));
    uvm7 *= rotation;

    // Read background texture
    vec3 col = texture(stone_jpg, uvm7).xyz;

    // Darkness based on the horizon
    col *= abs(uv.y - h - 0.005); // MLL: the smaller the number, the darker

    // Output the color
gl_FragColor = vec4(col, 1.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: 1982
    • zapsolution
Re: Animated Backgrounds?
« Reply #158 on: December 29, 2019, 10:47:41 am »
Thank you!

Here is a link for more tileable textures

http://www.texturise.club

For sidescroll.fs i prefer to use the attached asphalt.jpg or concrete.jpg rather than stone.jpg
« Last Edit: December 29, 2019, 08:41:50 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #159 on: December 29, 2019, 11:03:10 am »
BTW if you goto line 17 in TinyClouds.fs and change it to

        p.xz -= iTime;


you'll have the clouds flowing in the opposite direction, which will make the shader perfectly suitable for all sorts of your aircraft models facing the viewer as originally intended.

 :D
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1982
    • zapsolution
Re: Animated Backgrounds?
« Reply #160 on: December 29, 2019, 05:07:33 pm »
I am fixing the model right now to move transparent materials in sync with the body, also fixing a few triangulate errors resulting of the merging of several meshes altogether...
« Last Edit: December 29, 2019, 05:10:02 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #161 on: December 29, 2019, 06:40:28 pm »
In the meantime, watch the Spitfire crossing La Manche. ;D

The scene is a merger of your new model, static aero wallpaper, and 2DClouds.fs shader with a reversed direction of cloud movement.  8)
« Last Edit: December 29, 2019, 08:40:35 pm by Patrice Terrier »
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1982
    • zapsolution
Re: Animated Backgrounds?
« Reply #162 on: December 29, 2019, 07:33:22 pm »
Excellent!

Here is the fully reworked model, even the pilot's head his moving slowly.
Everything is now fully in sync (not an easy task), and the small artefacts have been fixed.

Note: the audio track is the sound of a true Rolls Royce Merlin engine.

I did put a copy of the c4d project, to have a backup elsewhere ;)

The combination of sound and animation brings the models to life. ;)
Patrice
(Always working with the latest Windows version available...)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 1481
Re: Animated Backgrounds?
« Reply #163 on: December 29, 2019, 07:53:38 pm »
Awesome work, Patrice!

Thank you very much!
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1982
    • zapsolution
Transformer
« Reply #164 on: December 30, 2019, 06:31:07 pm »
For the fun of it...
Patrice
(Always working with the latest Windows version available...)