Board index FlightGear Development Effects and shaders

2D shadow on ground

An exciting "new" option in FlightGear, that includes reflections, lightmaps, the particle system etc.. A lot is yet to be discovered/implemented!

2D shadow on ground

Postby mftetsudou38125 » Sun Dec 14, 2014 10:51 pm

As a former YSFlight pilot, I feel like the only thing FlightGear is missing (besides from the many things that YSFlight doesn't have) is the shadow on the ground. When I'm coming in to land, it used to give me the approximation of the height of the plane.

Image

(Yes I know, FlightGear has much better graphics than YSFlight, but this picture is just to show you the shadow effect)

I did try the full 3D shader effect, but that dropped my frame rate to 1 fps.
Is it possible to do a simple, 2D shadow of the plane just on the ground? I don't think that should require much graphics performance, does it? If it's not possible, is there a reason why?

Just wondering.

Cheers,
mftetsudou
Last edited by mftetsudou38125 on Sun Feb 15, 2015 7:21 am, edited 1 time in total.
Newton's Law states that what goes up, must come down. Our Company Commander's Law states that what goes up and comes down had damn well better be able to go back up again. -Tay Ninh
mftetsudou38125
 
Posts: 69
Joined: Mon Apr 08, 2013 10:18 pm
Location: Yokohama, Japan
Callsign: BAW128
Version: 3.2
OS: OS X

Re: 2D shadow on ground?

Postby Johan G » Mon Dec 15, 2014 7:51 am

A few aircraft have a fake shadow, in essence a flat silhouette of the aircraft floating maybe a feet above ground. The silhouette get there using a few properties, possibly driving some calculations and basically the same kind of animations as is used to for example animate the control surfaces. I do not remember having seen a list with aircraft using a fake shadow, but I think that for example Helijah's Diamond twin has one. The big drawback with a fake shadow is that it has to float to not get broken through by even the slightest undulations in the ground, while still will not work as soon as there is a slope.
Low-level flying — It's all fun and games till someone looses an engine. (Paraphrased from a YouTube video)
Improving the Dassault Mirage F1 (Wiki, Forum, GitLab. Work in slow progress)
Johan G
Moderator
 
Posts: 5266
Joined: Fri Aug 06, 2010 5:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 3.0.0
OS: Windows 7, 32 bit

Re: 2D shadow on ground?

Postby radi » Mon Dec 15, 2014 8:45 am

I'm no expert on this, but I guess it shouldn't be too expansive to get the terrain slope at ONE reference point on the ground depending on sun angle such that one can make the fake shadow project correctly most of the time. Thorsten is doing basically the same to get the tree shadows.
OSM buildings for LOWI, EDDC
Custom scenery for VHXX YMML
Edit .stg via the FG Object Placement Tool
radi
 
Posts: 618
Joined: Mon Aug 25, 2008 4:24 pm
Location: YMML, EDDC

Re: 2D shadow on ground?

Postby Thorsten » Mon Dec 15, 2014 5:32 pm

When I'm coming in to land, it used to give me the approximation of the height of the plane.


I would doubt that realistically you're even able to see it from the cockpit under most conditions (many weather situations have only ambient light and there aren't shadows, then the sun has to be such that you see a long shadow ahead of you right onto the runway, i.e. low and behind you, you don't see it at night...) - which is why it is far too unreliable to be a useful cue.

The main visual cue for closeness of the ground is the detail level of the runway, which we simulate just fine.

Having said that, quoting myself:

As the tree shadow code has shown, it's near-trivial to do the projective geometry not by an animation but in the vertex shader, i.e. fake shadows can be placed where the sun casts them, stretched by the projection, depth adjusted to weather condition and if the current terrain normal is passed, they can even be put co-planar with the local triangle, i.e. they'd project correctly even on sloped runways and terrain.

At a computational cost of almost zero, because you just process the four vertices of the shadow quad, and four is a number which isn't even a warm-up exercise for a GPU used to crunch millions of vertices. But of course, it wouldn't be a real shadow, in particular it wouldn't project correctly onto trees and buildings as a stencil buffer or shadow map solution would.
Thorsten
 
Posts: 9368
Joined: Mon Nov 02, 2009 8:33 am

Re: 2D shadow on ground?

Postby Thorsten » Tue Dec 16, 2014 12:00 pm

Having said that, it is fairly simple to do. Here's an implementation for the EC-130 which comes with an animation based fake shadow out of the box, switching the shadow projection to a GLSL shader:

The animation just puts the shadow onto the ground. The GLSL code can do some projection of the shadow, i.e. it magnifies a bit for low sun and changes position:

Image
Image

The shader can do a full light calculation of the surrounding scene, so the depth of the shadow can be varied according to the ambient to diffuse light balance:

Image
Image

Also, once the aircraft is in the air, it projects the shadow along the light ray rather than underneath the aircraft:

Image
Image

And of course, all that means shadow depth adjusts to weather conditions - no shadows in overcast skies:

Image

Implementation (using current git) - make the quads displaying the fake shadow inherit from Effects/shadow.eff, don't translate the shadow (the shader expects it to be correctly positioned for the sun in the zenith for an aircraft standing on the runway), don't try to correct for low sun or to adjust shadow texture transparency, the shader just uses the texture alpha channel.
Thorsten
 
Posts: 9368
Joined: Mon Nov 02, 2009 8:33 am

Re: 2D shadow on ground?

Postby radi » Tue Dec 16, 2014 12:17 pm

Excellent! And you demonstrate a fairly good usecase for this: judging the height above ground in external view.
OSM buildings for LOWI, EDDC
Custom scenery for VHXX YMML
Edit .stg via the FG Object Placement Tool
radi
 
Posts: 618
Joined: Mon Aug 25, 2008 4:24 pm
Location: YMML, EDDC

Re: 2D shadow on ground?

Postby wlbragg » Fri Dec 19, 2014 6:47 am

make the quads displaying the fake shadow inherit from Effects/shadow.eff

I don't understand how this is done. Could you show an example or link to your implementation of the EC-130?
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 3945
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: 2D shadow on ground?

Postby Thorsten » Fri Dec 19, 2014 8:51 am

Code: Select all
  <effect>
    <inherits-from>Effects/shadow</inherits-from>
    <object-name>shadow_fuselage</object-name>
  </effect>

Thorsten
 
Posts: 9368
Joined: Mon Nov 02, 2009 8:33 am

Re: 2D shadow on ground?

Postby wlbragg » Fri Dec 19, 2014 8:54 am

Ah, thank you!
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 3945
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: 2D shadow on ground?

Postby wlbragg » Fri Dec 19, 2014 4:36 pm

Once again, outstanding.
Image
Note:
The offsets pitch-deg appears to have no adverse effect.
The offsets z-m broke it as stated about translate.

I'm not sure about the size of the shadow as I gain altitude. It seemed to be smaller, would this be correct?

Does it matter were the effect is placed in order?
I put it after select but prior to rotate roll and pitch.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 3945
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: 2D shadow on ground?

Postby Thorsten » Fri Dec 19, 2014 7:48 pm

I'm not sure about the size of the shadow as I gain altitude. It seemed to be smaller, would this be correct?


It'd be surprising... I haven't seen this, but I haven't bee looking too much. The code should actually be incapable of just getting the shadow smaller.

Does it matter were the effect is placed in order?


No. Animations change the actual position of a model, they're all done before the rendering pipeline is entered. Effects change the appearance of a model (including where it appears in this case ;-) ).

The difference being important for collision detection - any model displacement you do in the vertex shader is non-existent in the actual scenegraph and hence can't trigger a collision. Which is irrelevant for the question at hand since the shadow isn't solid in the first place.
Thorsten
 
Posts: 9368
Joined: Mon Nov 02, 2009 8:33 am

Re: 2D shadow on ground?

Postby jarl.arntzen » Fri Jan 16, 2015 11:52 pm

Hi. I'm really interested in getting a proper 2D shadow on the ground. I did try looking around but didn't really understand the final requirement
Where should I put this? Into one of the *.eff files of any aircraft?
Code: Select all
  <effect>
    <inherits-from>Effects/shadow</inherits-from>
    <object-name>shadow_fuselage</object-name>
  </effect>
Frequent Flyer. Occasional Lander.
jarl.arntzen
 
Posts: 106
Joined: Thu Jan 03, 2013 9:43 pm
IRC name: Jarl Arntzen
Version: 2017.1.1
OS: Ubuntu 14.04

Re: 2D shadow on ground?

Postby wlbragg » Sat Jan 17, 2015 4:11 am

For the Cub I added it to
Code: Select all
F:\FlightGear\fgdata\Aircraft\Cub\Models\Effects\shadow.xml


and I changed the code to read
Code: Select all
<effect>
    <inherits-from>Effects/shadow</inherits-from>
    <object-name>shadow</object-name>
  </effect>


because the Cub "object-name" is "shadow" instead of "shadow_fuselage"
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 3945
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: 2D shadow on ground?

Postby Thorsten » Sat Jan 17, 2015 6:27 am

Where should I put this? Into one of the *.eff files of any aircraft?


* you need the shadow itself as a model (a textured quad). In ac3d (blender,...) that has an object name - in my example shadow_fuselage. You can give it any you want

* in the aircraft-set.xml (or files included there), animations, effects, sounds,... are declared and models included. In the scope where your shadow quad is included, you declare shadow.eff as your effect. What wlbragg has has done (inheriting a copy of the shadow effect under the aircraft effect directory) is probably more by the book, but not strictly necessary unless you want to pass parameters to the effect.
Thorsten
 
Posts: 9368
Joined: Mon Nov 02, 2009 8:33 am

Re: 2D shadow on ground?

Postby Hooray » Sat Jan 17, 2015 6:42 am

radi wrote:
Johan G wrote:The big drawback with a fake shadow is that it has to float to not get broken through by even the slightest undulations in the ground, while still will not work as soon as there is a slope.
I'm no expert on this, but I guess it shouldn't be too expansive to get the terrain slope at ONE reference point on the ground depending on sun angle such that one can make the fake shadow project correctly most of the time. Thorsten is doing basically the same to get the tree shadows.


For the sake of completeness, and I am not saying that you should do this (and it almost certainly going to be much worse performance-wise than any shaders) - but if you want the shadow to be accurate despite potential terrain sloping, you could apply a Canvas texture onto the surface (admittedly, this is much more straightforward in the case of an actual 3D model like a carrier) - otherwise, you'll also want to use a workaround and attach the texture to the 3D model (aka main aircraft). But people have been using Canvas for all sorts of purposes, including even liveries: http://wiki.flightgear.org/Howto:Dynami ... via_Canvas

But unlike glsl/shaders, a Canvas is not primarily a GPU thing, i.e. there's lots of CPU-level stuff going on affecting performance.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11100
Joined: Tue Mar 25, 2008 8:40 am

Next

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 3 guests