HHS81 / c182s

Cessna C182S (1996 model) for FlightGear
GNU General Public License v2.0
27 stars 9 forks source link

Support compositor for shadows #358

Closed hbeni closed 3 years ago

hbeni commented 3 years ago

Hello, it would be cool to have the compositor renderer supported for the interior and exterior shadows :)

Is there already a branch for that, so i can test it? (I remember heiko and wlbragg to have posted screenshots, but i don't know whats to be changed to support this)

wlbragg commented 3 years ago

Did you set sim/rendering/clustered-shading/enabled to true?

Oops, that's it, thanks!

HHS81 commented 3 years ago

Did you set sim/rendering/clustered-shading/enabled to true?

Oops, that's it, thanks!

I have now updated the wiki, as this important part was missing :-)

wlbragg commented 3 years ago

Dang, I have issues. I thought my landing light problem was the clustered-shading/enabled not being set. I wasn't at home when you verified I needed it and so I assumed that was the issue. Well I got home and tried it and still no go. So I decided to pull the c182s #358 branch and check out your landing lights. Guess what, they don't work on my computer either. But, it appears all the other compositor lights do. The nav, strobe and beacon al appear to be working, just not the taxi and landing light. I get the light volumes and lighting for everything except no light for the landing and taxi, only the debug volumes show. issue Any ideas? Is there maybe a very resent addition to the code base that added the compositor landing and taxi lights? Are the nav, beacon and strobe different, as in not "spot" lights?

wlbragg commented 3 years ago

I noticed in you image above the red beacon actually illuminated the fuselage tail, is that by default that the compositor beacon light does that? beacon It doesn't appear to work on my system either.

wlbragg commented 3 years ago

c) did you never make the ALS exterior procedural light that illuminated the runway that the c172p has (nasal driven)?

I still use it for landing and taxilights. But I switch it off, when sim/rendering/clustered-shading/enabled is true

I guess you didn't understand what I was asking. Your talking about the ALS landing and taxi lights that you see from the interior view. Those use... /sim/rendering/als-secondary-lights/use-landing-light /sim/rendering/als-secondary-lights/use-alt-landing-light You can only see them from the interior view. In the c172p we also had ALS "spot" lights driven by nasal that you can see from the exterior view. I just checked and your master branch has no landing or taxi lights that illuminate the runway when in your in the exterior view. The code for that is in light-manager.nas looks like this...

# provides relative vectors from eye-point to aircraft lights
# in east/north/up coordinates the renderer uses

var light_manager = {

    lat_to_m: 110952.0,
    lon_to_m: 0.0,

    light1_xpos: 0.0,
    light1_ypos: 0.0,
    light1_zpos: 0.0,
    light1_r: 0.0,
    light1_g: 0.0,
    light1_b: 0.0,
    light1_size: 0.0,
    light1_stretch: 0.0,

    light2_xpos: 0.0,
    light2_ypos: 0.0,
    light2_zpos: 0.0,
    light2_r: 0.0,
    light2_g: 0.0,
    light2_b: 0.0,
    light2_size: 0.0,
    light2_stretch: 0.0,

    light3_xpos: 0.0,
    light3_ypos: 0.0,
    light3_zpos: 0.0,
    light3_r: 0.0,
    light3_g: 0.0,
    light3_b: 0.0,
    light3_size: 0.0,

    light4_xpos: 0.0,
    light4_ypos: 0.0,
    light4_zpos: 0.0,
    light4_r: 0.0,
    light4_g: 0.0,
    light4_b: 0.0,
    light4_size: 0.0,

    light5_xpos: 0.0,
    light5_ypos: 0.0,
    light5_zpos: 0.0,
    light5_r: 0.0,
    light5_g: 0.0,
    light5_b: 0.0,
    light5_size: 0.0,

    init: func {
        # define your lights here

        # light 1 ########
        # offsets to aircraft center
        me.light1_xpos = 30.0;
        me.light1_ypos =  1.0;
        me.light1_zpos =  2.0;

        # color values
        me.light1_r = 0.5;
        me.light1_g = 0.5;
        me.light1_b = 0.5;

        # spot size
        me.light1_size = 15.0;
        me.light1_stretch = 1.25;

        # light 2 ########
        # offsets to aircraft center
        me.light2_xpos = 15.0;
        me.light2_ypos = -1.0;
        me.light2_zpos =  2.0;

        # color values
        me.light2_r = 0.4;
        me.light2_g = 0.4;
        me.light2_b = 0.4;

        # spot size
        me.light2_size = 16.0;
        me.light2_stretch = 1.5;

        # light 3 ########
        # offsets to aircraft center
        me.light3_xpos = 1.5;
        me.light3_ypos = -6.0;
        me.light3_zpos = 2.0;

        # color values
        me.light3_r = 0.0;
        me.light3_g = 0.05;
        me.light3_b = 0.0;

        # spot size
         me.light3_size = 5.0;

        # light 4 ########
        # offsets to aircraft center
        me.light4_xpos = 1.5;
        me.light4_ypos = 6.0;
        me.light4_zpos = 2.0;

        # color values
        me.light4_r = 0.05;
        me.light4_g = 0.0;
        me.light4_b = 0.0;

        # spot size
        me.light4_size = 5.0;

        # light 5 ######## star
        # offsets to aircraft center
        me.light5_xpos = 0.7;
        me.light5_ypos = 0;
        me.light5_zpos = 2.0;

        # color values
        me.light5_r = 0.3;
        me.light5_g = 0.3;
        me.light5_b = 0.3;

        # spot size
        me.light5_size = 20.0;

        me.light_manager_timer = maketimer(0.0, func{me.update()});

        me.start();
    },

    start: func {
        setprop("/sim/rendering/als-secondary-lights/num-lightspots", 5);

        setprop("/sim/rendering/als-secondary-lights/lightspot/size", me.light1_size);
        setprop("/sim/rendering/als-secondary-lights/lightspot/size[1]", me.light2_size);
        setprop("/sim/rendering/als-secondary-lights/lightspot/size[2]", me.light3_size);
        setprop("/sim/rendering/als-secondary-lights/lightspot/size[3]", me.light4_size);
        setprop("/sim/rendering/als-secondary-lights/lightspot/size[4]", me.light4_size);

        setprop("/sim/rendering/als-secondary-lights/lightspot/stretch", me.light1_stretch);
        setprop("/sim/rendering/als-secondary-lights/lightspot/stretch[1]", me.light2_stretch);

        me.light_manager_timer.start();
    },

    stop: func {
        me.light_manager_timer.stop();
    },

    update: func {

        var apos = geo.aircraft_position();
        var vpos = geo.viewer_position();

        me.lon_to_m = math.cos(apos.lat()*math.pi/180.0) * me.lat_to_m;

        var heading = getprop("/orientation/heading-deg") * math.pi/180.0;

        var lat = apos.lat();
        var lon = apos.lon();
        var alt = apos.alt();

        var sh = math.sin(heading);
        var ch = math.cos(heading);

        # light 1 position
        var alt_agl = getprop("/position/altitude-agl-ft");

        var proj_x = alt_agl;
        var proj_z = alt_agl/10.0;

        apos.set_lat(lat + ((me.light1_xpos + proj_x) * ch + me.light1_ypos * sh) / me.lat_to_m);
        apos.set_lon(lon + ((me.light1_xpos + proj_x)* sh - me.light1_ypos * ch) / me.lon_to_m);

        var delta_x = (apos.lat() - vpos.lat()) * me.lat_to_m;
        var delta_y = -(apos.lon() - vpos.lon()) * me.lon_to_m;
        var delta_z = apos.alt()- proj_z - vpos.alt();

        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-x-m", delta_x);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-y-m", delta_y);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-z-m", delta_z);
        setprop("/sim/rendering/als-secondary-lights/lightspot/dir", heading);

        # light 2 position
        var alt_agl = getprop("/position/altitude-agl-ft");

        var proj_x = alt_agl;
        var proj_z = alt_agl/10.0;

        apos.set_lat(lat + ((me.light2_xpos + proj_x) * ch + me.light2_ypos * sh) / me.lat_to_m);
        apos.set_lon(lon + ((me.light2_xpos + proj_x)* sh - me.light2_ypos * ch) / me.lon_to_m);

        var delta_x = (apos.lat() - vpos.lat()) * me.lat_to_m;
        var delta_y = -(apos.lon() - vpos.lon()) * me.lon_to_m;
        var delta_z = apos.alt()- proj_z - vpos.alt();

        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-x-m[1]", delta_x);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-y-m[1]", delta_y);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-z-m[1]", delta_z);
        setprop("/sim/rendering/als-secondary-lights/lightspot/dir", heading);

        # light 3 position
        apos.set_lat(lat + (me.light3_xpos * ch + me.light3_ypos * sh) / me.lat_to_m);
        apos.set_lon(lon + (me.light3_xpos * sh - me.light3_ypos * ch) / me.lon_to_m);

        delta_x = (apos.lat() - vpos.lat()) * me.lat_to_m;
        delta_y = -(apos.lon() - vpos.lon()) * me.lon_to_m;
        delta_z = apos.alt() - vpos.alt();

        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-x-m[2]", delta_x);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-y-m[2]", delta_y);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-z-m[2]", delta_z);

        # light 4 position
        apos.set_lat(lat + (me.light4_xpos * ch + me.light4_ypos * sh) / me.lat_to_m);
        apos.set_lon(lon + (me.light4_xpos * sh - me.light4_ypos * ch) / me.lon_to_m);

        delta_x = (apos.lat() - vpos.lat()) * me.lat_to_m;
        delta_y = -(apos.lon() - vpos.lon()) * me.lon_to_m;
        delta_z = apos.alt() - vpos.alt();

        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-x-m[3]", delta_x);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-y-m[3]", delta_y);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-z-m[3]", delta_z);

        # light 5 position
        apos.set_lat(lat + (me.light5_xpos * ch + me.light5_ypos * sh) / me.lat_to_m);
        apos.set_lon(lon + (me.light5_xpos * sh - me.light5_ypos * ch) / me.lon_to_m);

        delta_x = (apos.lat() - vpos.lat()) * me.lat_to_m;
        delta_y = -(apos.lon() - vpos.lon()) * me.lon_to_m;
        delta_z = apos.alt() - vpos.alt();

        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-x-m[4]", delta_x);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-y-m[4]", delta_y);
        setprop("/sim/rendering/als-secondary-lights/lightspot/eyerel-z-m[4]", delta_z);

    },   

    switch_position: func(light, lightr, lightg, lightb) {
        setprop("/sim/rendering/als-secondary-lights/lightspot/lightspot-r["~light~"]", lightr);
        setprop("/sim/rendering/als-secondary-lights/lightspot/lightspot-g["~light~"]", lightg);
        setprop("/sim/rendering/als-secondary-lights/lightspot/lightspot-b["~light~"]", lightb);
    },

    enable_or_disable: func (enable, light_num) {
        if (enable) {
            if (light_num == 0)
                me.switch_position(light_num, me.light1_r, me.light1_g, me.light1_b);
            if (light_num == 1)
                me.switch_position(light_num, me.light2_r, me.light2_g, me.light2_b);
            if (light_num == 2)
                me.switch_position(light_num, me.light3_r, me.light3_g, me.light3_b);
            if (light_num == 3)
                me.switch_position(light_num, me.light4_r, me.light4_g, me.light4_b);
            if (light_num == 4)
                me.switch_position(light_num, me.light5_r, me.light5_g, me.light5_b);
        } else {
            me.switch_position(light_num, 0.0, 0.0, 0.0);
        }
    },

};

light_manager.init();

setlistener("/sim/rendering/als-secondary-lights/use-landing-light-ext", func (node) {
    #light_manager.enable_or_disable(node.getValue(), 0);
}, 1, 0);
setlistener("/sim/rendering/als-secondary-lights/use-taxi-light-ext", func (node) {
    light_manager.enable_or_disable(node.getValue(), 1);
}, 1, 0);
setlistener("/sim/model/c172p/lighting/nav-lights/left-on", func (node) {
    light_manager.enable_or_disable(node.getValue(), 3);
}, 1, 0);
setlistener("/sim/model/c172p/lighting/nav-lights/right-on", func (node) {
    light_manager.enable_or_disable(node.getValue(), 2);
}, 1, 0);
setlistener("/sim/model/lighting/courtesy/factor", func (node) {
    light_manager.enable_or_disable(node.getValue(), 4);
}, 1, 0);

It also gave us the courtesy and nav light glow on the runway and tarmac. I guess you never had any of that until now with the compositor lighting.

wlbragg commented 3 years ago

Sorry for all the noise, I just pulled a fresh copy of fgdata, flightgear and simgear. It looks like there is a lot of clustered-shading stuff I may not have. I'll let you know if this clears all this up when I am done compiling.

hbeni commented 3 years ago

Hi wlbragg, the beacon light even has a reflection in the cockpit!

wlbragg commented 3 years ago

It looks so cool, I am anxiously awaiting my compiler to finish .I want to see this on my system and all the aircraft I work on.

wlbragg commented 3 years ago

Again, sorry for all the noise. That was the problem, I was out of date. I guess a couple weeks is too old. It all works great. Unfortunately it's 3:30 am, no more time to play. Hopefully by tomorrow night I will have some really cool illuminations in the Cub, c172p and maybe even the AirCrane. Thanks for all the help and explanations.

HHS81 commented 3 years ago

Did you set sim/rendering/clustered-shading/enabled to true?

Oops, that's it, thanks!

I have now updated the wiki, as this important part was missing :-)

Obsolete: http://wiki.flightgear.org/index.php?title=Compositor&curid=18596&diff=129813&oldid=129786 "This property is no longer active. Clustered shading is enabled all the time on the latest 'next' and can't be disabled via a property"

HHS81 commented 3 years ago

c) did you never make the ALS exterior procedural light that illuminated the runway that the c172p has (nasal driven)?

I still use it for landing and taxilights. But I switch it off, when sim/rendering/clustered-shading/enabled is true

I guess you didn't understand what I was asking. Your talking about the ALS landing and taxi lights that you see from the interior view. Those use... /sim/rendering/als-secondary-lights/use-landing-light /sim/rendering/als-secondary-lights/use-alt-landing-light You can only see them from the interior view. In the c172p we also had ALS "spot" lights driven by nasal that you can see from the exterior view. I just checked and your master branch has no landing or taxi lights that illuminate the runway when in your in the exterior view. The code for that is in light-manager.nas looks like this...

# provides relative vectors from eye-point to aircraft lights
# in east/north/up coordinates the renderer uses

var light_manager = {

    lat_to_m: 110952.0,

It also gave us the courtesy and nav light glow on the runway and tarmac. I guess you never had any of that until now with the compositor lighting.

Indeed, Never had.

HHS81 commented 3 years ago

Hi wlbragg, the beacon light even has a reflection in the cockpit!

still too strong, hmm.....

HHS81 commented 3 years ago

@hbeni @wlbragg I´m still busy with real life, but supporting compositor is here on the very top of my list. Stay tuned

hbeni commented 3 years ago

Stay tuned

Always!

HHS81 commented 3 years ago

@hbeni Done-so we can close this issue?

hbeni commented 3 years ago

Cool!