Board index FlightGear Development Effects and shaders

fgdata Commit influence

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

Re: fgdata Commit influence

Postby Thorsten » Fri Dec 05, 2014 7:29 am

FG references the depth map via FG world coordinates with origin in the center of Earth, and the world isn't just a sphere,

We do the computation in water.vert / water-ALS.vert.

Code: Select all

const float a = 6378137.0;                  //float a = equRad;
const float squash = 0.9966471893352525192801545;
const float latAdjust = 0.9999074159800018; //geotiff source for the depth map
const float lonAdjust = 0.9999537058469516; //actual extents: +-180.008333333333326/+-90.008333333333340

    rawPos = (osg_ViewMatrixInverse *gl_ModelViewMatrix * gl_Vertex).xyz;

 // Geodesy lookup for depth map
   float e2 = abs(1.0 - squash * squash);
   float ra2 = 1.0/(a * a);
   float e4 = e2 * e2;
   float XXpYY = rawPos.x * rawPos.x + rawPos.y * rawPos.y;
   float Z = rawPos.z;
   float sqrtXXpYY = sqrt(XXpYY);
   float p = XXpYY * ra2;
   float q = Z*Z*(1.0-e2)*ra2;
   float r = 1.0/6.0*(p + q - e4);
   float s = e4 * p * q/(4.0*r*r*r);
   if ( s >= 2.0 && s <= 0.0)
      s = 0.0;
   float t = pow(1.0+s+sqrt(s*2.0+s*s), 1.0/3.0);
   float u = r + r*t + r/t;
   float v = sqrt(u*u + e4*q);
   float w = (e2*u+ e2*v-e2*q)/(2.0*v);
   float k = sqrt(u+v+w*w)-w;
   float D = k*sqrtXXpYY/(k+e2);

   vec2 NormPosXY = normalize(rawPos.xy);
   vec2 NormPosXZ = normalize(vec2(D, rawPos.z));
   float signS = sign(rawPos.y);
   if (-0.00015 <= rawPos.y && rawPos.y<=.00015)
      signS = 1.0;
   float signT = sign(rawPos.z);
   if (-0.0002 <= rawPos.z && rawPos.z<=.0002)
      signT = 1.0;
   float cosLon = dot(NormPosXY, vec2(1.0,0.0));
   float cosLat = dot(abs(NormPosXZ), vec2(1.0,0.0));
   TopoUV.s = signS * lonAdjust * degrees(acos(cosLon))/180.;
   TopoUV.t = signT * latAdjust * degrees(acos(cosLat))/90.;
   TopoUV.s = TopoUV.s * 0.5 + 0.5;
   TopoUV.t = TopoUV.t * 0.5 + 0.5;


FG-wide, the computations from lat-lon to world coordinates that are used if you call the corrsponding Nasal routines are in SGGeodesy.cxx. I'm not sure how good the simple lat/lon assignment would work, it'd depend on just how the depth map is projected I guess. But it might be that it's just right by definition.
Thorsten
 
Posts: 10583
Joined: Mon Nov 02, 2009 8:33 am

Re: fgdata Commit influence

Postby radi » Fri Dec 05, 2014 1:22 pm

Thanks!

Anyone knows why this is neccessary?
Code: Select all
float signS = sign(rawPos.y);
if (-0.00015 <= rawPos.y && rawPos.y<=.00015)
   signS = 1.0;

Also, assuming sign(x) gives -1 if x is negative, and +1 if x is positive, shouldn't this
Code: Select all
float signS = sign(rawPos.y);
if (-0.00015 <= rawPos.y)
   signS = 1.0;

be equivalent but shorter?
OSM buildings for LOWI, EDDC
Custom scenery for VHXX YMML
Edit .stg via the FG Object Placement Tool
radi
 
Posts: 640
Joined: Mon Aug 25, 2008 4:24 pm
Location: YMML, EDDC

Re: fgdata Commit influence

Postby wlbragg » Fri Dec 05, 2014 4:12 pm

I'll write a python script that takes Lon/Lat and a color and changes the respective pixel

This would be used instead of editing the depth map texture?
If so, which method is lighter on the system, getting it off the depth map or calculating a region of pixels and changing their color?
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4612
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: fgdata Commit influence

Postby punkepanda » Fri Dec 05, 2014 4:38 pm

I must say I find the very dark blue/green almost black at overcast noon is more close to reality.
To my understanding the water color is mostly due to reflection of the skycolor, especially at deep sea.. Only in bright daylight and at minimal waterlevel you would ever notice the color of the sea ground. Or if the water is dirty or full of minerals and particles with some color.. Since sunlight fotons would not penetrate very deep I suggest that the water color should be more influenced by overall sky colour.
Another thing I notice is that noon and dawn gives the water a very brownish color. So to me it seems overall water is colored by the sun more than skycolour wich I found to be unrealistic.
Would it be an idea to mix skycolour with some sort of a transparent layer to make an reflection effect of the sun color and rather have the sky color its main color?
punkepanda
 
Posts: 237
Joined: Mon Nov 04, 2013 9:11 pm
Callsign: LostFlight
Version: 2.12
OS: Arch Linux

Re: fgdata Commit influence

Postby wlbragg » Fri Dec 05, 2014 4:43 pm

Yes, that should work or use the absolute value of rawPos.y. and check against .00015

I was reading it wrong in my first reply.

They may have done that for clarity. I think using the absolute value might keep the clarity.
Last edited by wlbragg on Fri Dec 05, 2014 5:12 pm, edited 2 times in total.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4612
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: fgdata Commit influence

Postby wlbragg » Fri Dec 05, 2014 4:50 pm

Only in bright daylight and at minimal waterlevel you would ever notice the color of the sea ground.


I'm not sure the map is strictly speaking just there to mimic the ground. Otherwise the land wouldn't be dark green. It would be mud color. I think it is there to allow matching the area's natural water tones that are inherited from a variety of things. Then on top of that the sky has its influence.

I edited the area of Kansas on the map and went to more brown simply because or water is most ofter dark and brown. I think most of that is caused by wind stirring up sediment and most of our water bodies are shallow. Also the heavy rains we get color the creeks and lakes.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4612
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: fgdata Commit influence

Postby Thorsten » Fri Dec 05, 2014 5:22 pm

This would be used instead of editing the depth map texture?


That would be used to edit the depth map texture. I guess doing it with gimp, it's tricky to pick the right pixel otherwise (I haven't tried...)
Thorsten
 
Posts: 10583
Joined: Mon Nov 02, 2009 8:33 am

Re: fgdata Commit influence

Postby punkepanda » Fri Dec 05, 2014 6:20 pm

wlbragg wrote in Fri Dec 05, 2014 4:50 pm: I'm not sure the map is strictly speaking just there to mimic the ground. Otherwise the land wouldn't be dark green. It would be mud color. I think it is there to allow matching the area's natural water tones that are inherited from a variety of things. Then on top of that the sky has its influence..


I would suggest this order of color influences:
1 Overall skycolor 40% (global)
2. Sun/Sunset color 20% (global)
3. Dirt/mud/particles 20% (regional / sesional)
4 SeaGround color 10% (regional / water level / depth)
5. Surounding vegitiation 10% (regional / sesional)

I dont know which or if all of this points / parameters is taken into account but I think thats what it takes to have it as realistic as possible

Brightness / intensity will then be influenced by how much sunligt fotons is hiting directly on the water surface and the water level / depht.
Last edited by punkepanda on Fri Dec 05, 2014 6:35 pm, edited 3 times in total.
punkepanda
 
Posts: 237
Joined: Mon Nov 04, 2013 9:11 pm
Callsign: LostFlight
Version: 2.12
OS: Arch Linux

Re: fgdata Commit influence

Postby wlbragg » Fri Dec 05, 2014 6:31 pm

That would be used to edit the depth map texture


OK,
I thought maybe we were talking about adding a mechanism to be able to add the "depth map texture color" procedurally through the materials and effects system.

doing it with gimp, it's tricky

Without references I had to just approximate where my boundaries were and made a crude rectangle. Surely, something I wouldn't want to commit.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4612
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: fgdata Commit influence

Postby LesterBoffo » Fri Dec 05, 2014 6:45 pm

To add to the mix, fresh water draining from various sources can have either growing or dissolved in it, and changing it's refractive base color drastically: Dissolved alkaline earth metals, tannins, alluvial silt, (like from Alpine glacier drainage) suspended, free swimming green algae, water plants growing at it's littoral edges, industrial waste and pollution.. As a pilot you're going to see much more of what's present in the first few feet of most freshwater because of your angle of view. Sky reflection will be more prevalent when at ground level.
User avatar
LesterBoffo
 
Posts: 2101
Joined: Sun Oct 02, 2011 4:02 pm
Location: Western USA
Callsign: LesBof
Version: 2016.1
OS: WinXP 32 bit

Re: fgdata Commit influence

Postby punkepanda » Fri Dec 05, 2014 7:48 pm

Link that explains most of colors, even water!
http://www.webexhibits.org/causesofcolor/5.html
punkepanda
 
Posts: 237
Joined: Mon Nov 04, 2013 9:11 pm
Callsign: LostFlight
Version: 2.12
OS: Arch Linux

Re: fgdata Commit influence

Postby radi » Sat Dec 06, 2014 5:24 am

Et voila.
https://dl.dropboxusercontent.com/u/24846517/fg/globe/colorize_ocean_depth_texture.py
If someone wants to commit this to git, go ahead.

Either give lon,lat on cmd line or supply a log file. To create a log file, enable logging (see below) and fly the ufo along your river.

I love this texture! Now I can have river Inn greenish-greyish and still have dark-blue mountain lakes around!

Code: Select all
$ ./colorize_ocean_depth_texture.py -h
usage: colorize_ocean_depth_texture.py [-h] [-i FILE] [-o FILE]
                                       RGBA [LONLAT [LONLAT ...]]

Change color of given locations in FG's ocean depth texture. By default, read and overwrite ocean_depth_1.png.

positional arguments:
  RGBA
  LONLAT

optional arguments:
  -h, --help            show this help message and exit
  -i FILE, --in-file FILE
                        read texture from FILE
  -o FILE, --out-file FILE
                        write texture to FILE

Examples:
  ./colorize_ocean_depth_texture.py -o test.png 0,0,255,255 13,51 13,52.3

  Make locations 13, 51 and 13, 52.3 deep blue, write to test.png
  ./colorize_ocean_depth_texture.py -o test.png 0,0,255,255 13,51 13,52.3

  Read and write default texture and read locations from log file
  ./colorize_ocean_depth_texture.py 0,0,255,255 < fg_log.csv

  A log file is expected to have at least three colums time, lon, lat separated
  by whitespace or a colon. Starting FG with the following options will produce
  a valid file fg_log.csv:
    --prop:/logging/log/enabled=true
    --prop:/logging/log/interval-ms=1000
    --prop:/logging/log/entry/enabled=true
    --prop:/logging/log/entry[1]/enabled=true
    --prop:/logging/log/entry[2]/enabled=true
    --prop:/logging/log/entry[5]/enabled=true
OSM buildings for LOWI, EDDC
Custom scenery for VHXX YMML
Edit .stg via the FG Object Placement Tool
radi
 
Posts: 640
Joined: Mon Aug 25, 2008 4:24 pm
Location: YMML, EDDC

Re: fgdata Commit influence

Postby wlbragg » Sat Dec 06, 2014 6:00 am

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

Re: fgdata Commit influence

Postby Thorsten » Sat Dec 06, 2014 6:57 am

Awesome!

If someone wants to commit this to git, go ahead.


I think a tool like that ought to go to FGMeta, but I don't have commit rights there - maybe you could post this on the devel list or write a PN to James or Stuart?
Thorsten
 
Posts: 10583
Joined: Mon Nov 02, 2009 8:33 am

Re: fgdata Commit influence

Postby erik » Mon Dec 08, 2014 7:29 am

Nice, so now we can model the three lakes of Mount Kelimutu :)
http://www.meteoprog.pl/pl/news/42814/
Image

Erik
erik
 
Posts: 1516
Joined: Thu Nov 01, 2007 1:41 pm

PreviousNext

Return to Effects and shaders

Who is online

Users browsing this forum: No registered users and 1 guest