Board index FlightGear Development Canvas

Targeting reticule with darker border effect

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Targeting reticule with darker border effect

Postby abassign » Tue Mar 06, 2018 12:32 pm

When I do a targeting reticule (SFOM) for targeting the G91R1B system have two possible ways:
1. The light comes from the outside collecting and projecting the image of the reticle (day mode)
2. The light is produced by an internal lamp (Night mode)

This is the effect:

Image

The brightness of the reticle is adjusted according to the ambient brightness and the angular distance from the sun.
But if we look better you notice the presence of a dark border:

Image

The effect is also present in the evening, although less evident, as the external brightness is darker:

Image

The effect is obtained with the NASAL code using a canvas on which is inserted a machera that I see below. Remember that the black background color indicates the transparent part:

Image

The problem increases if I use a gradient mesh version at the edges:

Image

Image

This is the code:

Code: Select all
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/button", 60, "DOUBLE");
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/inclination", 0, "DOUBLE");
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/isLightActive", 0, "DOUBLE");
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/collimatorLight", 0, "DOUBLE");
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/whiteLight", 0, "DOUBLE");
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/collimator_red", 0, "DOUBLE");
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/collimator_green", 0, "DOUBLE");
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/collimator_blue", 0, "DOUBLE");
var prop = props.globals.initNode("sim/G91/gauge/SFOM_83A/knob_intensity", 0, "DOUBLE");

sfom83A_canvas = canvas.new({"name": "SFOM83A_canvas_Collimator_glass_TargetDOWN",
                    "size": [512,512],
                    "view": [512,690],
                    "mipmapping": 1});
sfom83A_canvas.name = "SFOM83A_canvas_Collimator_glass_TargetDOWN";
sfom83A_canvas.addPlacement({"node": "Collimator_glass_TargetDOWN"});
sfom83A_canvas.setColorBackground(0.0, 0.0, 0.0, 0.0);
var root = sfom83A_canvas.createGroup();
var path = "Aircraft/G91-R1B_HD/Models/Parts/Canopy/Gauges/SFOM_83A/SFOM_83A_01_Cross.png";
var child = root.createChild("image")
        .setFile( path )
        .setTranslation(0,0)
        .setSize(512,512);

setlistener("/sim/G91/gauge/SFOM_83A/button", func {
    var valButton = props.globals.getNode("/sim/G91/gauge/SFOM_83A/button",1).getValue();
    child.setTranslation(0,valButton);
}, 1, 0);

var color_cross_SFOM83A = maketimer(0.1, func() {
    var lightIntesity = props.globals.getNode("sim/G91/gauge/SFOM_83A/knob_intensity",1).getValue();
    var ambientRedLight = 0.0;
    var ambientGreenLight = 0.0;
    var ambientBlueLight = 0.0;
    var sun_angular_deg = props.globals.getNode("sim/G91/ambient-data/sun-angular-deg",1).getValue();
    var sun_direct_Light = 0.25 + math.pow((1 - sun_angular_deg * 0.01745 / 3.1428),2) * 0.75;
    ambientRedLight = props.globals.getNode("rendering/scene/specular/red",1).getValue();
    ambientGreenLight = props.globals.getNode("rendering/scene/specular/green",1).getValue();
    ambientBlueLight = props.globals.getNode("rendering/scene/specular/blue",1).getValue();
    collimatorLight = (ambientRedLight + ambientGreenLight + ambientBlueLight) / 3;
    whiteLight_sun = collimatorLight * (1 + sun_direct_Light);
    if (lightIntesity <= 0.01) {
        setprop("sim/G91/gauge/SFOM_83A/isLightActive", 0);
        setprop("sim/G91/gauge/SFOM_83A/whiteLight", whiteLight_sun);
    } else {
        setprop("sim/G91/gauge/SFOM_83A/isLightActive", 1);
        ambientRedLight = lightIntesity;
        ambientGreenLight = 0.3 * lightIntesity;
        ambientBlueLight = 0.0;
        setprop("sim/G91/gauge/SFOM_83A/whiteLight", (1 - collimatorLight * 3));
    }
    setprop("sim/G91/gauge/SFOM_83A/collimatorLight", collimatorLight);
    setprop("sim/G91/gauge/SFOM_83A/collimator_red",ambientRedLight);
    setprop("sim/G91/gauge/SFOM_83A/collimator_green",ambientGreenLight);
    setprop("sim/G91/gauge/SFOM_83A/collimator_blue",ambientBlueLight);
});
color_cross_SFOM83A.start();


This fact prevents me to further increase the brightness of the reticle as it also increases the shadow effect at the edges!

I ask if there is a solution to this problem that seems to arise from an interpolation effect at the edges between the transparency and the reticle.

Thank for your help.
Developer of the program https://wiki.flightgear.org/Julia_photoscenery_generator
FDM developer of the G91R1B aircraft https://wiki.flightgear.org/FIAT_G91R1B
JSBSim collaborator
abassign
 
Posts: 947
Joined: Mon Feb 27, 2012 6:09 pm
Location: Italy (living 5 Km from airport LIME)
Callsign: I-BASSY
Version: 2020.4
OS: Ubuntu 20.10

Re: Targeting reticule with darker border effect

Postby Necolatis » Tue Mar 06, 2018 1:18 pm

I would think solution is to set:

sfom83A_canvas.setColorBackground(0.0, 0.0, 0.0, 0.0);

to same color as the reticle. Even though it is transparent.

Hope that help you. :)
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Targeting reticule with darker border effect

Postby Thorsten » Tue Mar 06, 2018 7:23 pm

Yep, that looks like the culprit.

And if you're not already doing it, try rendering it with an effect designed for transparency, that should also reduce artefacts (the HUD effect is probably what you want for that kind of reflected light...)
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Targeting reticule with darker border effect

Postby abassign » Wed Mar 07, 2018 2:12 am

Thorsten wrote in Tue Mar 06, 2018 7:23 pm:Yep, that looks like the culprit.
And if you're not already doing it, try rendering it with an effect designed for transparency, that should also reduce artefacts (the HUD effect is probably what you want for that kind of reflected light...)


I thank you for the idea of working on the background, I added a 20% gray and 10% green (to simulate the effect of glass thickness) and the problem has been reduced substantially.
Since the aluminized glass is natural, its transparency is lower than that of a normal glass, therefore a slight darkening produces a much more realistic effect also in terms of reproduction.

In high light condition:
Image

In lower light condition:
Image

This is the code I have modified:

Code: Select all
sfom83A_canvas.setColorBackground(0.0, 0.1, 0.0, 0.2);
Developer of the program https://wiki.flightgear.org/Julia_photoscenery_generator
FDM developer of the G91R1B aircraft https://wiki.flightgear.org/FIAT_G91R1B
JSBSim collaborator
abassign
 
Posts: 947
Joined: Mon Feb 27, 2012 6:09 pm
Location: Italy (living 5 Km from airport LIME)
Callsign: I-BASSY
Version: 2020.4
OS: Ubuntu 20.10

Re: Targeting reticule with darker border effect

Postby Necolatis » Wed Mar 07, 2018 6:03 am

Glad it worked.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10


Return to Canvas

Who is online

Users browsing this forum: No registered users and 4 guests