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!

Re: 2D shadow on ground

Postby wlbragg » Thu Mar 23, 2017 7:28 pm

Lerp fade function

vert

Code: Select all
varying float alpha_correction;

void main()
    float start_fade = 0;
    float end_fade = 100;
    float diff = end_fade - start_fade;
    float t = (alt_agl - start_fade) / diff;
    t = 1.0 - t;
    if (t > 1.0) t = 1.0;
    if (t < 0.0) t = 0.0;
    alpha_correction = t;


frag

Code: Select all
varying float alpha_correction;

void main()
gl_FragColor = fragColor * alpha_correction;


Don't forget to do the 2d vertex shader.

I tested this and it works OK. I tried tying it to a bezier curve but I either messed up the function or something weird happens to change color in the shadow at 0 agl? Just in case you want to mess with it right before alpha_correction = t; use...

Code: Select all
float p0 = 0.0;
float p1 = 0.0;
float p2 = 0.2;
float p3 = 1.0;
t = (pow(1.0-t,3)*p0) + (pow(t,3)*p3) + (3*pow(1.0-t,2)*t*p1) + (3*pow(t,2)*1.0-t*p1);


Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7587
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 » Thu Mar 23, 2017 9:24 pm

If you're not specifically keen on linear fading, the smoothstep function is one of my best friends...

Code: Select all
float t = smoothstep(start_fade, end_fade, alt_agl);
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground

Postby wlbragg » Thu Mar 23, 2017 9:41 pm

Nope, that looks good, didn't know it was an option.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7587
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 » Thu Mar 23, 2017 10:27 pm

Either we need to reverse
Code: Select all
float start_fade = 0;
float end_fade = 100;

to
Code: Select all
float start_fade = 100;
float end_fade = 0;

or use
Code: Select all
float t = smoothstep(end_fade, start_fade, alt_agl);


Is there any reason not to simply use
Code: Select all
alpha_correction = smoothstep(end_fade, start_fade, alt_agl);

instead of creating another float t?

It did appear to work on at least on my g-card.

Also I noticed on the J3Cub, because of the pitch angle of the tail dragger that if I pitch up to level flight, or actually slightly down, it screws the shadow up (as in it starts cutting it off). How do I account for the pitch?
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7587
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 Mar 24, 2017 7:35 am

That (with end_fade > start_fade)

Code: Select all
float t = smoothstep(end_fade, start_fade, alt_agl);


is going to work fine on nvidia, but give you calls for help from AMD/Radeon users - the actual GLSL spec requires the first argument smaller than the second (the joys of GLSL coding...)

You can do

Code: Select all
float t = 1.0 - smoothstep(start_fade, end_fade, alt_agl);


instead. Also, you can immediately make it alpha_correction, yes.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground

Postby wlbragg » Fri Mar 24, 2017 7:09 pm

OK, then I think I would go ahead and use
Code: Select all
alpha_correction = 1.0 - smoothstep(start_fade, end_fade, alt_agl);
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7587
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 erik » Sat Mar 25, 2017 10:00 am

Alright, all these fixes have been committed.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: 2D shadow on ground

Postby Thorsten » Sat Mar 25, 2017 12:38 pm

Erik, thanks for handling this, but as I said above - since the 2d and 3d shadow share the fragment shader, you've unfortunately just broken the 2d shadow technique which does not generate varying alpha_correction in the vertex shader and hence does no longer feed the fragment shader properly.

This needs to be defined there as well - though it can just be assigned 1.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground

Postby erik » Sat Mar 25, 2017 2:34 pm

This should be fixed now.

Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer
erik
 
Posts: 2244
Joined: Thu Nov 01, 2007 2:41 pm

Re: 2D shadow on ground

Postby wlbragg » Sat Mar 25, 2017 4:53 pm

Yes, thank you all.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7587
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 abassign » Sun Dec 24, 2017 7:41 pm

We are trying to have a decent shadow, something that could remotely resemble reality, we spend many hundreds of hours to make a decent plane model, others spend hundreds of hours to have decent scenery, others create and maintain complex code, all to give us the satisfaction of having a flight simulator as we want.
All this should be magnificently well, but we continue to neglect the essential elements for the perception of the quality of a project.
An absolutely emblematic case are the shadows generation ...

This is the C172P shadow:

Image

The shadow is really sad, in pieces, this because of the fact that the 3D shadow is made of various parts and the shadow is not 100% but with a certain level of transparency, for this reason dark stripes are formed at the junction points.

Image

With Rembrandt the situation is much better and the shadows are dynamic and the bad "tile" effect does not form when the ground is not regular.
The problem is that Rembrandt is not currently updated and therefore does not incorporate the ALS effects that are very well done.
In fact, currently the solution of the shadows is not present, satisfactorily, in FGFS with ALS. It is a real sadness :(

Our G91-R1B can not use Rembrandt as many effects that are used, especially in the cockpit, they are working properly only in ALS.
I know that someone can criticize this choice, but it was born out of the fact that it is unlikely that Rembrandt will continue to be used in the future.
We made a 3D model of the fuselage, landing gear and wing tanks, we put everything inside a .ac file and we activated it using XML as described and used, for example, by C172P.

Image

This is the code:
Code: Select all
<?xml version="1.0"?>

<PropertyList>
   
    <path>shadow-vol-g91.ac</path>
   
    <offsets>
        <x-m>0.0</x-m>
        <y-m>0.0</y-m>
        <z-m>-1.07</z-m>
        <roll-deg>0.0</roll-deg>
    </offsets>
   
    <effect>
        <inherits-from>Effects/shadow-vol</inherits-from>
        <object-name>shadow-vol-g91</object-name>
        <object-name>shadow-vol-g91_tank</object-name>
        <object-name>gear-front</object-name>
        <object-name>gear-principal</object-name>
    </effect>
   
    <animation>
        <object-name>shadow-vol-g91</object-name>
        <object-name>shadow-vol-g91_tank</object-name>
        <object-name>gear-front</object-name>
        <object-name>gear-principal</object-name>
        <type>select</type>
        <condition>
            <not>
                <property>/sim/rendering/rembrandt/enabled</property>
            </not>
            <equals>
                <property>/sim/rendering/shaders/skydome</property>
                <value>1</value>
            </equals>
        </condition>
    </animation>

    <animation>
        <type>noshadow</type>
        <object-name>shadow-vol-g91</object-name>
        <object-name>shadow-vol-g91_tank</object-name>
        <object-name>gear-front</object-name>
        <object-name>gear-principal</object-name>
    </animation>
   
    <!-- Roll -->
    <animation>
        <type>rotate</type>
        <object-name>shadow-vol-g91</object-name>
        <object-name>shadow-vol-tank</object-name>
        <object-name>gear-front</object-name>
        <object-name>gear-principal</object-name>
        <property>/orientation/roll-deg</property>
        <factor>1.0</factor>
        <center>
            <x-m>0</x-m>
            <y-m>0</y-m>
            <z-m>0</z-m>
        </center>
        <axis>
            <x>1</x>
            <y>0</y>
            <z>0</z>
        </axis>
    </animation>
   
    <!-- Pitch -->
    <animation>
        <type>rotate</type>
        <object-name>shadow-vol-g91</object-name>
        <object-name>shadow-vol-g91_tank</object-name>
        <object-name>gear-front</object-name>
        <object-name>gear-principal</object-name>
        <property>/orientation/pitch-deg</property>
        <factor>1.0</factor>
        <center>
            <x-m>0</x-m>
            <y-m>0</y-m>
            <z-m>0</z-m>
        </center>
        <axis>
            <x>0</x>
            <y>1</y>
            <z>0</z>
        </axis>
    </animation>
   
</PropertyList>   



The result is absolutely depressing, it is incomprehensible that the sun is under 180 ° compared to the real one ... someone can help me to tell me where we were wrong about the code.
Then there is the problem of the absolute black color of the shadow, there is no gradient on the edge, does anyone have an idea that we can improve it?
We hope someone can advise me on how to better program the XML. But it would be much better if the problem was resolved in a more radical way. It would be necessary to have a piece of Rembrandt in XML.

I found this article very interesting for the shadows, I do not know if it's known:
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/
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: 2D shadow on ground

Postby Thorsten » Mon Dec 25, 2017 8:50 am

Then there is the problem of the absolute black color of the shadow


You probably have no transparency set on the texture. Otherwise I may refer you to

http://wiki.flightgear.org/Atmospheric_ ... tering_FAQ
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: 2D shadow on ground

Postby abassign » Mon Dec 25, 2017 3:44 pm

Thorsten wrote in Mon Dec 25, 2017 8:50 am:
Then there is the problem of the absolute black color of the shadow


You probably have no transparency set on the texture. Otherwise I may refer you to

http://wiki.flightgear.org/Atmospheric_ ... tering_FAQ


Thank you, as you can see I applied the transparency to 50% obtaining a shadow a little more realistic:

Code: Select all
...
MATERIAL "DefaultWhite" rgb 1.0000 1.0000 1.0000  amb 0.2000 0.2000 0.2000  emis 0.0000 0.0000 0.0000  spec 0.5000 0.5000 0.5000  shi 10 trans 0.5000
...


Image

But there are other problems:
The first problem is the fact that the shadow is inverted and for example the rear wheel and the landing gear becomes gigantic as if the sun were much lower and on the opposite side. I do not understand why the .ac file that reproduces the parts of the plane was made just starting from the plane, while the XML file I got it from c172p.
The second problem is that shadows, when they are semi-transparent, are overlaid, thus generating dark junction points that make the scene much less realistic.

Can you give me a possible solution, especially for the first problem?

Thank you :)
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: 2D shadow on ground

Postby LesterBoffo » Mon Dec 25, 2017 4:09 pm

Revisiting this effects shader after 2 years, the new shader fixes are pretty awesome. The shadow volumes are now staying visible from the aircraft's view to altitudes of over 1300' AGL.
User avatar
LesterBoffo
 
Posts: 2171
Joined: Sun Oct 02, 2011 5:02 pm
Location: Oregon, USA
Callsign: LesBof
Version: 2018.3.2
OS: Win10 Pro

Re: 2D shadow on ground

Postby Thorsten » Mon Dec 25, 2017 7:56 pm

The first problem is the fact that the shadow is inverted and for example the rear wheel and the landing gear becomes gigantic as if the sun were much lower and on the opposite side.


Wrong projection plane? Attempt to rotate the model by hand (aka, via an xml definition)? Could be all sorts of things, just take the working example and compare.

The second problem is that shadows, when they are semi-transparent, are overlaid, thus generating dark junction points that make the scene much less realistic.


Find a z-buffering scheme which is at the same time agressive enough to get rid of everything but the uppermost projection surface and yet numerically stable enough to not get into clipping issues.

The shadow volumes are now staying visible from the aircraft's view to altitudes of over 1300' AGL.


Which is in fact physically wrong because diffraction extincts the shadow long before that altitude. But people seem to love it anyway...
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

PreviousNext

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 7 guests