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 Thorsten » Mon Mar 09, 2015 6:30 am

Would it be possible to align the shadow with the ground normal to prevent wing clipping? Is that something that should be done XML model side?


It is trivial to tilt the shadow with the ground normal (that's what I mean when I use the words 'co-planar with the triangle') - the tree shadows exemplify that. What's not trivial is getting the normal in the first place, because you don't need it underneath the plane, you need it at the position of the shadow - but that in turn depends on terrain elevation at that position.

So it's a ray intersection problem between aircraft and terrain along the light to find the position at which you want the normal - and they're not cheap to do. In any case, yes, this needs to be done model-side, because the shader doesn't have the information to do the ray intersection problem because it only knows the local mesh (current vertex or pixel).
Thorsten
 
Posts: 11210
Joined: Mon Nov 02, 2009 8:33 am

Re: 2D shadow on ground

Postby gooneybird » Mon Mar 09, 2015 7:55 pm

wlbragg wrote in Sat Mar 07, 2015 7:11 pm:Would someone mind PM'ing me a volume shadow that is known to be working on your system.
I change the pa28 to a single poly and am getting something even stranger.



Are you still having problems with the AI pa28?
I've managed to cut it down to one object by removing a few small items and the object groups that were causing me a few problems when creating the AI version.
Download is here https://www.mediafire.com/?1se7dobb5a1dtpn
gooneybird
 
Posts: 2971
Joined: Sat May 31, 2008 1:57 pm

Re: 2D shadow on ground

Postby wlbragg » Tue Mar 10, 2015 12:44 am

I finally managed to hear what Thorsten was trying to tell me. I have it working correctly now.

But I like your model better than my final single object model so I'll use it instead.

Thank You
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4989
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

Re: 2D shadow on ground

Postby wlbragg » Fri Mar 13, 2015 7:18 am

I am having some issues trying to combine the shadow volume with the 2d shadow giving the user a choice by merely switching ALS on or off.
It wasn't a problem combining the 2d-non-ALS and 2d-ALS shadows to work using the same shadow.xml.
I don't know if it is possible to do what I am trying to do.

Here is the problem as I understand it.

I think I need to combine the 2d-shadow (shadow) and the 3dshadow volume (3dshadow) in the same .ac file and use "select" to show the preferred shadow depending on ALS being on or off. I don't know if this is possible and if there is some format that should be used.

Replacing
OBJECT world
kids 2
with
OBJECT group
kids 2
is the closest I get to being able to control the 3dshadow object, ie: I can position it initially but its translate, rotate and pitch get mucked up upon movement.

Example
Code: Select all
AC3Db
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.0000
OBJECT world
kids 2
OBJECT group
name "shadow"
kids 1
OBJECT poly
name "shadow"
data 6
shadow
texture "shadow.png"
texrep 1 1
crease 30.000000
numvert 4
-4.128285 -1.756925 5.327894
-4.128286 -1.756925 -5.316878
6.516488 -1.756925 -5.316878
6.516484 -1.756925 5.327895
numsurf 1
SURF 0x00
mat 0
refs 4
0 1.78813905904e-07 0.0
3 0.999999880791 5.960463767e-08
2 1.0 0.999999880791
1 0.0 1.0
kids 0
OBJECT group
name "3dshadow"
kids 42
OBJECT poly
name "3dshadow"
~~~~~
~~~~~
~~~~~
~~~~~


Any idea on how to do this?

The shadow.xml looks like this, maybe there is something dumb I'm doing here also.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>

    <PropertyList>

      <path>3dshadow.ac</path>
      <nopreview/>
     
     <offsets>
        <pitch-deg>4.0</pitch-deg>
        <z-m>2.0</z-m>
      </offsets>

      <animation>
        <object-name>3dshadow</object-name>
        <type>select</type>
        <condition>
          <not>
            <property>/sim/rendering/rembrandt/enabled</property>
          </not>
          <equals>
            <property>/sim/rendering/shaders/skydome</property>
       <value>true</value>
          </equals>
        </condition>
      </animation>
    
      <animation>
        <object-name>shadow</object-name>
        <type>select</type>
        <condition>
          <not>
            <property>/sim/rendering/rembrandt/enabled</property>
          </not>
        <not>
            <property>/sim/rendering/shaders/skydome</property>
          </not>
        </condition>
      </animation>
     
      <effect>
        <inherits-from>Effects/shadow-vol</inherits-from>
        <object-name>3dshadow</object-name>
      </effect>
    
      <effect>
        <inherits-from>Effects/shadow</inherits-from>
        <object-name>shadow</object-name>
      </effect>

      <animation>
        <type>noshadow</type>
        <object-name>3dshadow</object-name>
   <object-name>shadow</object-name>
      </animation>

      <!-- pitch -->
      <animation>
        <type>rotate</type>
        <object-name>3dshadow</object-name>
   <object-name>shadow</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>

      <!-- roll -->
      <animation>
        <type>rotate</type>
        <object-name>3dshadow</object-name>
   <object-name>shadow</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>

      <!--Translate to ground level  -->
      <animation>
       <type>translate</type>
       <object-name>shadow</object-name>
       <condition>
        <not>
          <property>/sim/rendering/shaders/skydome</property>
        </not>
       </condition>
       <property>/position/altitude-agl-ft</property>
       <factor>-0.3048</factor>
       <center>
         <x-m>0</x-m>
         <y-m>0</y-m>
         <z-m>0</z-m>
       </center>
       <axis>
         <x>0</x>
         <y>0</y>
         <z>1</z>
       </axis>
     </animation>

    </PropertyList>
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4989
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

Re: 2D shadow on ground

Postby wlbragg » Fri Mar 13, 2015 8:54 pm

zlsa wrote in Fri Mar 13, 2015 8:24 pm:@wlbragg, for shadows, you can enable the volume shadow only if /sim/rendering/shaders/skydome is true (meaning ALS is enabled) and the 2D shadow otherwise and just have one select animation that hides both if shadows are disabled.


Isn't this kind of what I am trying to do above?

have one select animation that hides both if shadows are disabled

I don't understand this or how this would be done?
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4989
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

Re: 2D shadow on ground

Postby zlsa » Fri Mar 13, 2015 9:24 pm

Something like this:

Code: Select all
<animation>
  <type>select</type>
  <condition>
    <and>
      <not><property>/sim/rembrandt/enabled</property></not>
      <property>/options/shadows-enabled</property> <!-- this is your own property so the user can toggle shadows -->
    </and>
  </condition>
  <object-name>2d-shadow</object-name>
  <object-name>shadow-volume</object-name>
</animation>


<animation>
  <type>select</type>
  <condition>
    <property>/sim/rendering/shaders/skydome</property>
  </condition>
  <object-name>shadow-volume</object-name>
</animation>


<animation>
  <type>select</type>
  <condition>
    <not><property>/sim/rendering/shaders/skydome</property></not>
  </condition>
  <object-name>2d-shadow</object-name>
</animation>


should work.
zlsa
 
Posts: 145
Joined: Fri Feb 14, 2014 2:29 am
Callsign: N275A
Version: 3.5 git
OS: Linux

Re: 2D shadow on ground

Postby wlbragg » Sun Mar 15, 2015 7:22 am

Image
Has anyone verified exactly how or if you can position the volume shadow where you want upon start up?
No matter what I set the "offsets", or "reference" to this is the default starting position of the volume shadow, note the z-fighting. Once the aircraft gets up to speed down the runway and lifts off the ground the shadow behaves correctly for the most part.

Thorsten, can you verify this is the correct behavior? Is there any way to lift this off the ground or change pitch slightly?

I don't seem to get a consistent behavior when trying to apply any type of positioning.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4989
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

Re: 2D shadow on ground

Postby Thorsten » Sun Mar 15, 2015 12:22 pm

Has anyone verified exactly how or if you can position the volume shadow where you want upon start up?


add a property rule to compute agl altitude in meters. Add any offsets for the shadow location here, add any offsets of the shadow projection plane via inheritance to <gear_clearance> (the z=0 plane of the model may be different from the shadow projection plane which is the ground, so you need to tell the shader that).
Thorsten
 
Posts: 11210
Joined: Mon Nov 02, 2009 8:33 am

Re: 2D shadow on ground

Postby galvedro » Wed Apr 15, 2015 5:51 pm

Hi!

I am trying out the shadow-vol effect on the ASK13. It works, but I am having trouble to wrap my mind around some of the steps involved. This is what I have understood:

  1. The effect uses a hidden object that provides the volume.
  2. It projects the vertices of that object into a plane that, in order to get the effect, has to lay just over the ground.
  3. It does the light computations to determine the color and transparency of the resulting shape.

I also understand that in order to do the projection, a distance to the ground is needed, and that altitude-agl-x is used as an approximation, since the shadow does not, in general, project exactly underneath the aircraft, and the actual projection distance is not trivial to obtain.

So far, so good. What I am having trouble to understand is this:

  • Why are rotation animations needed for the shadow-vol object? Isn't the projection completely computed within the shader?
  • altitude-agl-x refers to the origin of coordinates in the physics model. I understand that for this to work properly, the shadow-vol object is assumed to have the origin at that precise point and that any offset fiddling on top of this, regardless of where it happens, is just fine tuning. Is this correct?

I prepared the shadow volume for the ASK13 following those principles. It is a simplified shape of ~600 verts that has no material assigned (although the exporter produces a default "white" material for it). However, I am not seeing the interaction I was expecting with the weather, see here:

Image

Is there a special rendering setting that must be enabled to get the effect interact with the environment?
galvedro
 
Posts: 145
Joined: Mon Oct 07, 2013 12:55 pm
Location: Sweden

Re: 2D shadow on ground

Postby Thorsten » Thu Apr 16, 2015 5:43 am

Why are rotation animations needed for the shadow-vol object? Isn't the projection completely computed within the shader?


Well, yes.

The rotation animations end up in gl_ModelViewMatrix which puts the model from model coordinates into eye coordinates and that is used inside the shader after the projection. Doing the projection of the shadow in model coordinates where you have a 'down' direction independent of the direction the eye is currently looking is however mathematically easier.

Alternatively, one could give the shader yaw, pitch and roll explicitly and compute the shadow from there (this would in fact enable to do the projection after animation on the model have been carried out) in eye coordinate space - so the rotation matrix needs to be assembled inside the shader then, and the computation needs to be done for a variable up-direction.

Let's just say I know how to do it in principle, but as far as math goes, this is really really ugly and prone to mistakes.

altitude-agl-x refers to the origin of coordinates in the physics model.


Does it? I thought at least for one FDM it refers to the lowest contact point, but I'm not completely certain on that one. Anyway, the user is supposed to provide the offset from altitude-agl to the actual position at which the shadow should be when the wheels are on the ground, since the shader can't out-guess what the FDM actually provides.

However, I am not seeing the interaction I was expecting with the weather, see here:


Is this AW? I don't think Basic Weather sets the shadow depth parameters - the shader relies on the weather system explicitly telling 'this overcast layer leads to that light reduction' - check /environment/surface/scattering to be sure.
Thorsten
 
Posts: 11210
Joined: Mon Nov 02, 2009 8:33 am

Re: Interior shading

Postby zlsa » Thu Apr 16, 2015 9:05 pm

I'm still having problems; the volumetric shadows of the c172p-detailed and my piper-archer both don't have any transparency. I've seen screenshots of the c172p-detailed with a transparent shadow (you can see the ground beneath it), so I'm going to assume this is an Intel issue. I'll do some more debugging and see if I can find the issue, but I'm not too optimistic as FG's effects pipeline is opaqe to me (pun intended).
zlsa
 
Posts: 145
Joined: Fri Feb 14, 2014 2:29 am
Callsign: N275A
Version: 3.5 git
OS: Linux

Re: Interior shading

Postby wlbragg » Thu Apr 16, 2015 9:11 pm

volumetric shadows of the c172p-detailed and my piper-archer both don't have any transparency

No, none of the volumetric shadows have transparency yet. If your seeing transparency, your seeing the non-volume default ALS shadow.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 4989
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480

Re: Interior shading

Postby zlsa » Thu Apr 16, 2015 9:14 pm

Ah, I guess I was confused by the screenshots that showed partial transparency with volumetrics and was under the impression Thorsten had implemented the stencilbuffer fix.
zlsa
 
Posts: 145
Joined: Fri Feb 14, 2014 2:29 am
Callsign: N275A
Version: 3.5 git
OS: Linux

Re: Interior shading

Postby Thorsten » Fri Apr 17, 2015 4:53 am

No, none of the volumetric shadows have transparency yet


Please manage terminology, otherwise nobody outside FG will understand us :-) - it's not a volumetric shadow like in the renderer identifies a volume in which there is no light. It's a squished volume projected onto the ground.

This should assume the correct transparency based on ambient light - through my shadows I can definitely see the ground:

Image

What it does not do yet is take a user-specified transparency in addition to vary transparency of the shadow (in the above example you see this sort of acidentially in the way the wings cast less hard shadows.
Thorsten
 
Posts: 11210
Joined: Mon Nov 02, 2009 8:33 am

Re: Interior shading

Postby zlsa » Fri Apr 17, 2015 4:55 am

@Thorsten, by "volume", I meant it used a 3d volume mesh (as opposed to a quad with a texture). What's the proper user-facing name for the 3d shadow effect?
zlsa
 
Posts: 145
Joined: Fri Feb 14, 2014 2:29 am
Callsign: N275A
Version: 3.5 git
OS: Linux

PreviousNext

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 1 guest