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 11: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 8:21 am, edited 1 time in total.
mftetsudou38125
 
Posts: 70
Joined: Mon Apr 08, 2013 11: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 8: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)
Some YouTube videos
Johan G
Moderator
 
Posts: 6629
Joined: Fri Aug 06, 2010 6:33 pm
Location: Sweden
Callsign: SE-JG
IRC name: Johan_G
Version: 2020.3.4
OS: Windows 10, 64 bit

Re: 2D shadow on ground?

Postby radi » Mon Dec 15, 2014 9: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: 659
Joined: Mon Aug 25, 2008 5:24 pm
Location: YMML, EDDC

Re: 2D shadow on ground?

Postby Thorsten » Mon Dec 15, 2014 6: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: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground?

Postby Thorsten » Tue Dec 16, 2014 1: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: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground?

Postby radi » Tue Dec 16, 2014 1: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: 659
Joined: Mon Aug 25, 2008 5:24 pm
Location: YMML, EDDC

Re: 2D shadow on ground?

Postby wlbragg » Fri Dec 19, 2014 7: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 and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7586
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: 2D shadow on ground?

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

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

Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground?

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

Ah, thank you!
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7586
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: 2D shadow on ground?

Postby wlbragg » Fri Dec 19, 2014 5: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 and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7586
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: 2D shadow on ground?

Postby Thorsten » Fri Dec 19, 2014 8: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: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground?

Postby jarl.arntzen » Sat Jan 17, 2015 12:52 am

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 10: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 5: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 and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7586
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: 2D shadow on ground?

Postby Thorsten » Sat Jan 17, 2015 7: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: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground?

Postby Hooray » Sat Jan 17, 2015 7: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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Next

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 4 guests

cron