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.