osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/engine_droam/AMRShaders.h

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003 * Copyright 2008-2010 Pelican Mapping
00004 * http://osgearth.org
00005 *
00006 * osgEarth is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU Lesser General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU Lesser General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU Lesser General Public License
00017 * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018 */
00019 
00020 // --------------------------------------------------------------------------
00021 
00022 static char source_xyzToLatLonHeight[] =
00023 
00024 "vec3 xyz_to_lat_lon_height(in vec3 xyz) \n"
00025 "{ \n"
00026 "   float X = xyz.x; \n"
00027 "   float Y = xyz.y; \n"
00028 "   float Z = xyz.z; \n"
00029 "   float _radiusEquator = 6378137.0; \n"
00030 "   float _radiusPolar   = 6356752.3142; \n"
00031 "   float flattening = (_radiusEquator-_radiusPolar)/_radiusEquator;\n"
00032 "   float _eccentricitySquared = 2*flattening - flattening*flattening;\n"
00033 "   float p = sqrt(X*X + Y*Y);\n"
00034 "   float theta = atan(Z*_radiusEquator , (p*_radiusPolar));\n"
00035 "   float eDashSquared = (_radiusEquator*_radiusEquator - _radiusPolar*_radiusPolar)/(_radiusPolar*_radiusPolar);\n"
00036 "   float sin_theta = sin(theta);\n"
00037 "   float cos_theta = cos(theta);\n"
00038 "\n"
00039 "   float latitude = atan( (Z + eDashSquared*_radiusPolar*sin_theta*sin_theta*sin_theta), (p - _eccentricitySquared*_radiusEquator*cos_theta*cos_theta*cos_theta) );\n"
00040 "   float longitude = atan(Y,X);\n"
00041 "   float sin_latitude = sin(latitude);\n"
00042 "   float N = _radiusEquator / sqrt( 1.0 - _eccentricitySquared*sin_latitude*sin_latitude);\n"
00043 "   float height = p/cos(latitude) - N;\n"
00044 "   return vec3(longitude, latitude, height);\n"
00045 "}\n";
00046 
00047 static char source_geodeticToXYZ[] =
00048 
00049 "vec3 geodeticToXYZ(in vec3 geodetic) \n"
00050 "{ \n"
00051 "  float RADIUS_EQUATOR = 6378137.0; \n"
00052 "  float RADIUS_POLAR   = 6356752.3142; \n"
00053 "  float FLATTENING     = (RADIUS_EQUATOR-RADIUS_POLAR)/RADIUS_EQUATOR; \n"
00054 "  float ECC2           = (2.0*FLATTENING) - (FLATTENING*FLATTENING); \n"
00055 "\n"
00056 "  float lat = geodetic.y; \n"
00057 "  float lon = geodetic.x; \n"
00058 "  float alt = geodetic.z; \n"
00059 "  float sinLat = sin(lat); \n"
00060 "  float cosLat = cos(lat); \n"
00061 "  float n = RADIUS_EQUATOR / sqrt( 1.0 - ECC2*sinLat*sinLat ); \n"
00062 "  float x = (n+alt)*cosLat*cos(lon); \n"
00063 "  float y = (n+alt)*cosLat*sin(lon); \n"
00064 "  float z = (n*(1.0 - ECC2) + alt) * sinLat; \n"
00065 "  return vec3(x,y,z); \n"
00066 "} \n";
00067 
00068 static char source_rotVecToGeodetic[] =
00069 
00070 "vec3 rotVecToGeodetic(in vec3 r) \n"
00071 "{ \n"
00072 "  float latitude = -asin(r.y); \n"
00073 "  float longitude = (r.x*r.x + r.z*r.z < 0.0005 ) ? 0.0 : atan2(r.x,r.z); \n"
00074 "  return vec3( longitude, latitude, 0.0 ); \n"
00075 "} \n";
00076 
00077 // --------------------------------------------------------------------------
00078 
00079 
00080 
00081 // --------------------------------------------------------------------------
00082 
00083 static char source_slerp[] =
00084 
00085 "vec3 slerp(in vec3 p0, in vec3 p1, in float t) \n"
00086 "{ \n"
00087 "   float theta = acos( dot(p0,p1) ); \n"
00088 "   vec3 s = ( (p0*sin(1.0-t)*theta) + p1*sin(t*theta) ) / sin(theta); \n"
00089 "   return s * ( length(p0)+length(p1) ) * 0.5; \n"
00090 "} \n";
00091 
00092 // --------------------------------------------------------------------------
00093 
00094 static char source_fnormal[] = 
00095 
00096 "vec3 fnormal(void)\n"
00097 "{\n"
00098 "    //Compute the normal \n"
00099 "    vec3 normal = gl_NormalMatrix * gl_Normal; \n"
00100 "    normal = normalize(normal); \n"
00101 "    return normal; \n"
00102 "}\n";
00103 
00104 // --------------------------------------------------------------------------
00105 
00106 static char source_directionalLight[] = 
00107 
00108 "void directionalLight(in int i, \n"
00109 "                      in vec3 normal, \n"
00110 "                      inout vec4 ambient, \n"
00111 "                      inout vec4 diffuse, \n"
00112 "                      inout vec4 specular) \n"
00113 "{ \n"
00114 "   float nDotVP;         // normal . light direction \n"
00115 "   float nDotHV;         // normal . light half vector \n"
00116 "   float pf;             // power factor \n"
00117 " \n"
00118 "   nDotVP = max(0.0, dot(normal, normalize(vec3 (gl_LightSource[i].position)))); \n"
00119 "   nDotHV = max(0.0, dot(normal, vec3 (gl_LightSource[i].halfVector))); \n"
00120 " \n"
00121 "   if (nDotVP == 0.0) \n"
00122 "   { \n"
00123 "       pf = 0.0; \n"
00124 "   } \n"
00125 "   else \n"
00126 "   { \n"
00127 "       pf = pow(nDotHV, gl_FrontMaterial.shininess); \n"
00128 " \n"
00129 "   } \n"
00130 "   ambient  += gl_LightSource[i].ambient; \n"
00131 "   diffuse  += gl_LightSource[i].diffuse * nDotVP; \n"
00132 "   specular += gl_LightSource[i].specular * pf; \n"
00133 "} \n";
00134 
00135 // --------------------------------------------------------------------------
00136 
00137 static char source_vertShaderMain_slerpMethod[] =
00138 
00139 "uniform vec3 c0, c1, c2; \n"
00140 "uniform vec2 t0, t1, t2; \n"
00141 "uniform vec3 n0, n1, n2; \n"
00142 "varying vec2 texCoord0; \n"
00143 "\n"
00144 "void main (void) \n"
00145 "{ \n"
00146 "   // interpolate vert form barycentric coords \n"
00147 "   float u = gl_Vertex.x; \n"
00148 "   float v = gl_Vertex.y; \n"
00149 "   float w = gl_Vertex.z; // 1-u-v  \n"
00150 "   vec3 interpNormal = normalize(n0*u + n1*v + n2*w); \n"
00151 "   vec3 geodetic = rotVecToGeodetic( interpNormal ); \n"
00152 "   vec4 outVertex = vec4( geodeticToXYZ(geodetic), gl_Vertex.w ); \n"
00153 "   gl_Position = gl_ModelViewProjectionMatrix * outVertex; \n"
00154 "\n"
00155 "   // set up the tex coords for the frad shader: \n"
00156 "   u = gl_MultiTexCoord0.s; \n"
00157 "   v = gl_MultiTexCoord0.t; \n"
00158 "   w = 1.0 - u - v; \n"
00159 "   texCoord0 = t0*u + t1*v + t2*w; \n"
00160 "} \n";
00161 
00162 static char source_vertShaderMain_latLonMethod[] =
00163 
00164 "uniform vec3 c0, c1, c2; \n"
00165 "uniform vec2 t0, t1, t2; \n"
00166 "varying vec2 texCoord0; \n"
00167 "\n"
00168 "void main (void) \n"
00169 "{ \n"
00170 "   // interpolate vert form barycentric coords \n"
00171 "   float u = gl_Vertex.x; \n"
00172 "   float v = gl_Vertex.y; \n"
00173 "   float w = gl_Vertex.z; // 1-u-v  \n"
00174 "   vec3 outCoord3 = c0*u + c1*v + c2*w; \n"
00175 "   vec4 outVert4 = vec4( lonLatAlt_to_XYZ( outCoord3 ), gl_Vertex.w ); \n"
00176 "   gl_Position = gl_ModelViewProjectionMatrix * outVert4; \n"
00177 "\n"
00178 "   // set up the tex coords for the frad shader: \n"
00179 "   u = gl_MultiTexCoord0.s; \n"
00180 "   v = gl_MultiTexCoord0.t; \n"
00181 "   w = 1.0 - u - v; \n"
00182 "   texCoord0 = t0*u + t1*v + t2*w; \n"
00183 "} \n";
00184 
00185 static char source_vertShaderMain_geocentricMethod[] =
00186 
00187 "uniform vec3 v0, v1, v2; \n"
00188 "uniform vec2 t0, t1, t2; \n"
00189 "varying vec2 texCoord0; \n"
00190 "\n"
00191 "void main (void) \n"
00192 "{ \n"
00193 "   // interpolate vert form barycentric coords \n"
00194 "   float u = gl_Vertex.x; \n"
00195 "   float v = gl_Vertex.y; \n"
00196 "   float w = gl_Vertex.z; // 1-u-v  \n"
00197 "   vec3 outVert3 = v0*u + v1*v + v2*w; \n"
00198 "   float h = length(v0)*u + length(v1)*v + length(v2)*w; // interpolate height \n"
00199 "   vec4 outVert4 = vec4( normalize(outVert3) * h, gl_Vertex.w ); \n"
00200 "   gl_Position = gl_ModelViewProjectionMatrix * outVert4; \n"
00201 "\n"
00202 "   // set up the tex coords for the frad shader: \n"
00203 "   u = gl_MultiTexCoord0.s; \n"
00204 "   v = gl_MultiTexCoord0.t; \n"
00205 "   w = 1.0 - u - v; \n"
00206 "   texCoord0 = t0*u + t1*v + t2*w; \n"
00207 "} \n";
00208 
00209 static char source_vertShaderMain_flatMethod[] =
00210 
00211 "uniform vec3 v0, v1, v2; \n"
00212 "uniform vec2 t0, t1, t2; \n"
00213 "varying vec2 texCoord0; \n"
00214 "\n"
00215 "void main (void) \n"
00216 "{ \n"
00217 "   // interpolate vert form barycentric coords \n"
00218 "   float u = gl_Vertex.x; \n"
00219 "   float v = gl_Vertex.y; \n"
00220 "   float w = gl_Vertex.z; // 1-u-v  \n"
00221 "   vec4 outVert4 = vec4( v0*u + v1*v + v2*w, gl_Vertex.w); \n"
00222 "   gl_Position = gl_ModelViewProjectionMatrix * outVert4; \n"
00223 "\n"
00224 "   // set up the tex coords for the frad shader: \n"
00225 "   u = gl_MultiTexCoord0.s; \n"
00226 "   v = gl_MultiTexCoord0.t; \n"
00227 "   w = 1.0 - u - v; \n"
00228 "   texCoord0 = t0*u + t1*v + t2*w; \n"
00229 "} \n";
00230 
00231 // --------------------------------------------------------------------------
00232 
00233 char source_fragShaderMain[] = 
00234 
00235 "varying vec2 texCoord0; \n"
00236 "uniform sampler2D tex0; \n"
00237 "\n"
00238 "void main (void) \n"
00239 "{ \n"
00240 "    gl_FragColor = texture2D( tex0, texCoord0 ); \n"
00241 "} \n";
00242 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines