Special Aircraft Service

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Further refinements to lightning during thunderstorm weather  (Read 373 times)

0 Members and 1 Guest are viewing this topic.

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6040

After learning a little bit more on the journey of Java, I've revisited my earlier mod for the lightning effect. As some may recall, I issued a mod a couple or few years ago which made significant improvements. But I've discovered that further refinement is in order.

Let's first review the stock scheme, probably as implemented at year dot and left unchanged ever since.

- The lightning bolt itself has 5 variations, of differing degrees of zig-zagging, so that not every zap looks the same. They are randomly selected from at each occurrence. This is good.

- There were 2 illumination sources created; one 100m below the bolt top and of a low intensity/radius, and the other 1/3 the distance from sea level to the cloud base and of greater intensity/farther radius. The weaker, higher source is superfluous, really, for it is greatly dominated by the other. Having the 'main' light source position in altitude set with respect to sea level is problematic for higher terrain. When the ground is high enough the light source will be under the surface, with the result that objects are now illuminated from below!

- The bolt is generated so that the bottom is always at seal level, and the top is at the cloud base. This is bad for two reasons. (1) Because of the zig-zagging line of the bolt, when the terrain has any significant elevation the point where the bolt emerges from the ground could be significantly displaced on the X-Y plane from the point down at sea level. This then has the bolt offset from the center of the circle of illumination, the latter of which is always exactly over the base of the bolt. (2) Having the top of the bolt terminate exactly at the cloud base, there's often a noticeable 'gap' between bolt top and the cloud; real bolts from cloud tend to extend well up into the cloud.

============================

In my earlier treatment I has made some false assumptions about the reference heights involved in the calculations. Upon looking at this again I immediately suspected my errors, and confirmed them by temporarily adding some output code to display during play the values of any variables of concern. And so I've re-jigged Zip.class for even better behaviour.

My older changes, retained:
- The bolt extends well up inside the cloud.
- The intensity of the illumination is scaled by the Sun's angular elevation, getting stronger as twilight deepens into night. I have further tweaked the algorithm.
- The color has been changed from pure white to a slight pinkish hue characteristic of lightning.

The main, current changes:
- The lightning bolt now extends to the actual ground surface, not all the way down to sea level. This ensures the illumination circle and bolt position on the ground are coincident.
- I have eliminated the superfluous second light source at the bolt top. The 'main' light source does all the work in lighting up the environs.
- The now single light source has its height fixed at 500m above ground level. This assures consistent illumination behaviour where terrain height is variable.
- When the terrain crosses a certain threshold elevation with respect to the cloud base height, lightning effects are not generated. This ensures no such silliness as a lightning flash occurring over mountains where part or all of the cloud is below ground.
- The former duration of a flash was fixed at 0.5 seconds; now it's randomly variable between 0.3 and 0.5.
- I've increased the frequency of occurrence, in large part to represent thunderstorm activity in the tropics and at lower latitudes in general. I will likely see about incorporating a check on the map CAMOUFLAGE as well as the DECLIN value, having a flash frequency rate scaled according to two or more variables. For instance, thunder activity in winter at higher latitudes should have a lower flash frequency. ;)
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6040
Re: Further refinements to lightning during thunderstorm weather
« Reply #1 on: June 13, 2024, 10:27:22 AM »

I've added two other changes I forgot to mention, hinting at additional refinement possibly to come.

Here's the current Java for Zip.class:
Code: [Select]
package com.maddox.il2.objects.effects;

import com.maddox.JGP.Point3d;
import com.maddox.il2.ai.RangeRandom;
import com.maddox.il2.ai.World;
import com.maddox.il2.engine.*;
import com.maddox.il2.game.Main3D;
import com.maddox.il2.game.Mission;
import com.maddox.il2.objects.ActorSimpleMesh;
import com.maddox.il2.objects.air.Cockpit;
import com.maddox.il2.objects.effects.MiscEffects;
import com.maddox.il2.objects.sounds.SfxZip;
import com.maddox.rts.Destroy;
import com.maddox.rts.MsgAction;

public class Zip
    implements Destroy
{

    protected void zipPsss()
    {
        if(isDestroyed())
        {
            return;
        } else
        {
            light1.setEmit(0.0F, 0.0F);
            zipMesh.drawing(false);
            new MsgAction(rnd.nextFloat(2F, 4F))
{
                public void doAction()
                {
                    zipBuhhh();
                }
            };
            return;
        }
    }

    protected void zipBuhhh()
    {
        if(isDestroyed())
            return;
        if(!Mission.isPlaying())
            return;
        if(!Main3D.cur3D().clouds.getRandomCloudPos(temp))
{
double cldCenter = temp.z;
World.cur();
ground.z = World.land().HQ_Air(temp.x, temp.y);
double sfcPoint = ground.z;
if (cldCenter < sfcPoint + 1000D || (double) height < sfcPoint + 300D)
return;
            new MsgAction(rnd.nextFloat(2F, 4F))
{
                public void doAction()
                {
                    zipBuhhh();
                }
            };
            return;
        } else
        {
double cldCenter = temp.z;
World.cur();
ground.z = World.land().HQ_Air(temp.x, temp.y);
double sfcPoint = ground.z;  //point on terrain under cloud
brtnsFactor = MiscEffects.cvt(World.Sun().ToSun.z, -0.3F, 0.1F, 1.0F, 0.5F);
rangeFactor = MiscEffects.cvt(World.Sun().ToSun.z, -0.3F, 0.1F, 1.0F, 0.5F);
temp.z = sfcPoint + 500D;
            new SfxZip(temp);
            light1.setPos(temp);
            light1.setEmit(1F * brtnsFactor, 2000F * rangeFactor);
            light1.setColor(1.0F, 0.85F, 0.98F);
temp.z = sfcPoint - 10.0D;
            zipMesh.pos.setAbs(temp);
            zipMesh.pos.reset();
            zipMesh.mesh().setScale(((float) cldCenter - (float) sfcPoint) / 2000F);
            zipMesh.mesh().setFrame(rnd.nextInt(0, 4));
            zipMesh.drawing(true);
            Cockpit.lightningStrike(temp);
            new MsgAction(rnd.nextDouble(0.3D, 0.5D))
{
                public void doAction()
                {
                    zipPsss();
                }
            };
            return;
        }
    }

    public Zip(float f)
    {
        height = 2000F;
        temp = new Point3d();
ground = new Point3d();
        light1 = null;
        rnd = new RangeRandom();
        height = f;
        light1 = new LightPointWorld();
        zipMesh = new ActorSimpleMesh("3do/effects/fireworks/hammerofthor/mono.sim");
        zipMesh.draw = new ActorMeshDraw()
{
            public void render(Actor actor)
            {
                if(Main3D.cur3D().bEnableFog)
                    Render.enableFog(false);
                super.render(actor);
                if(Main3D.cur3D().bEnableFog)
                    Render.enableFog(true);
            }
        };
        zipMesh.drawing(false);
        new MsgAction(15)
{
            public void doAction()
            {
                zipBuhhh();
            }
        };
    }

    public boolean isDestroyed()
    {
        return light1 == null;
    }

    public void destroy()
    {
        if(isDestroyed())
            return;
        light1.destroy();
        light1 = null;
        if(Actor.isValid(zipMesh))
        {
            zipMesh.destroy();
            zipMesh = null;
        }
    }

    private float height;
    Point3d temp;
Point3d ground;
    LightPointWorld light1;
    private RangeRandom rnd;
    private ActorSimpleMesh zipMesh;
    private static final float dT = 4F;
private float brtnsFactor;
private float rangeFactor;
private float fLo;
private float fHi;
}
Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

WxTech

  • Modder
  • member
  • Offline Offline
  • Posts: 6040
Re: Further refinements to lightning during thunderstorm weather
« Reply #2 on: June 13, 2024, 11:13:46 AM »

An example, at nearly full night. The upper panel is a view from 6km away, the lower obviously from much nearer to the strike. The main aspect to note here is the more diffuse illumination, being not so intense as to hugely blow out the objects to blinding white and also having a more gradual gradient, or fall-off with distance. Moreover, the general ground and object brightness is much more in line with that of the cloud, where the lower albedo of the former would not generally result in a brightness of illumination that would exceed that of the higher albedo cloud.

This more natural appearance is afforded principally by a much reduced intensity given the light point actor, as well as retention of a large radius by which the illumination is more spread out.

Compare this to the stock handling, where the buildings and other objects near the bolt will be blasted into a near supernova level of blinding white.  ;)

Logged
Great minds discuss ideas. Average minds discuss events. Small minds discuss people. - Hyman Rickover (but probably predating his use.)

sercrets

  • Missioneer
  • member
  • Offline Offline
  • Posts: 164
    • Discord:
Re: Further refinements to lightning during thunderstorm weather
« Reply #3 on: June 13, 2024, 12:05:09 PM »

Hmm very nice. Yes I do not appreciate the blinding lights second only to the light of the sun itself of the current lightening... Reminds me of this song...



cheers,

sercrets
Logged
You get what you give.
Pages: [1]   Go Up
 

Page created in 0.034 seconds with 24 queries.