目标:(九十一)中的问题175
思路是将着色器文件的源码都放入一个cpp文件的变量中,再编译链接,就将着色器文件写死在动态库中了。
秘密在rex引擎目录下的文件Shaders.cpp.in(最终该模板变成AutoGenShaders.cpp)
// ***DO NOT EDIT THIS FILE - IT IS AUTOMATICALLY GENERATED BY CMAKE***
#include <osgEarthDrivers/engine_rex/Shaders>
using namespace osgEarth::Drivers::RexTerrainEngine;
Shaders::Shaders()
{
ENGINE_VERT_MODEL = "RexEngine.vert.glsl";
_sources[ENGINE_VERT_MODEL] = "@RexEngine.vert.glsl@";
ENGINE_ELEVATION_MODEL = "RexEngine.elevation.glsl";
_sources[ENGINE_ELEVATION_MODEL] = "@RexEngine.elevation.glsl@";
MORPHING_VERT = "RexEngine.Morphing.vert.glsl";
_sources[MORPHING_VERT] = "@RexEngine.Morphing.vert.glsl@";
ENGINE_VERT_VIEW = "RexEngine.vert.view.glsl";
_sources[ENGINE_VERT_VIEW] = "@RexEngine.vert.view.glsl@";
ENGINE_FRAG = "RexEngine.frag.glsl";
_sources[ENGINE_FRAG] = "@RexEngine.frag.glsl@";
NORMAL_MAP_VERT = "RexEngine.NormalMap.vert.glsl";
_sources[NORMAL_MAP_VERT] = "@RexEngine.NormalMap.vert.glsl@";
NORMAL_MAP_FRAG = "RexEngine.NormalMap.frag.glsl";
_sources[NORMAL_MAP_FRAG] = "@RexEngine.NormalMap.frag.glsl@";
ENGINE_GEOM = "RexEngine.gs.glsl";
_sources[ENGINE_GEOM] = "@RexEngine.gs.glsl@";
SDK = "RexEngine.SDK.vert.glsl";
_sources[SDK] = "@RexEngine.SDK.vert.glsl@";
}
CMake工程对该文件做如下处理:
set(TARGET_GLSL
RexEngine.vert.glsl
RexEngine.elevation.glsl
RexEngine.vert.view.glsl
RexEngine.tcs.glsl
RexEngine.tes.glsl
RexEngine.gs.glsl
RexEngine.frag.glsl
RexEngine.NormalMap.vert.glsl
RexEngine.NormalMap.frag.glsl
RexEngine.Morphing.vert.glsl
RexEngine.SDK.vert.glsl)
set(SHADERS_CPP "${CMAKE_CURRENT_BINARY_DIR}/AutoGenShaders.cpp")
configure_shaders(
Shaders.cpp.in
${SHADERS_CPP}
${TARGET_GLSL} )
configure_shaders定义如下:
# -----------------------------------------------------------------------
# configure_shaders -gw
#
# Bakes GLSL shaders to make into a CPP file at runtime.
# Example:
#
# configure_shaders( MyTemplate.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/AutoGen.cpp file1.glsl file2.glsl )
#
macro(configure_shaders templateFile autoGenCppFile)
# set up configure variables:
set(TEMPLATE_FILE ${templateFile} )
set(GLSL_FILES ${ARGN} )
set(OUTPUT_CPP_FILE ${autoGenCppFile})
# generate the build-time script that will create out cpp file with inline shaders:
configure_file(
"${CMAKE_SOURCE_DIR}/CMakeModules/ConfigureShaders.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/ConfigureShaders.cmake"
@ONLY)
# add the custom build-time command to run the script:
add_custom_command(
OUTPUT
"${autoGenCppFile}"
COMMAND
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/ConfigureShaders.cmake"
DEPENDS
${GLSL_FILES}
"${TEMPLATE_FILE}"
"${CMAKE_SOURCE_DIR}/CMakeModules/ConfigureShaders.cmake.in" )
endmacro(configure_shaders)
经过变换后,AutoGenShaders.cpp的内容为:
// ***DO NOT EDIT THIS FILE - IT IS AUTOMATICALLY GENERATED BY CMAKE***
#include <osgEarthDrivers/engine_rex/Shaders>
using namespace osgEarth::Drivers::RexTerrainEngine;
Shaders::Shaders()
{
ENGINE_VERT_MODEL = "RexEngine.vert.glsl";
_sources[ENGINE_VERT_MODEL] = "#version $GLSL_VERSION_STR%EOL%$GLSL_DEFAULT_PRECISION_FLOAT%EOL%%EOL%#pragma vp_name REX Engine - Vertex%EOL%#pragma vp_entryPoint oe_rexEngine_vert%EOL%#pragma vp_location vertex_model%EOL%#pragma vp_order 0.0%EOL%%EOL%// uniforms%EOL%uniform vec4 oe_terrain_color;%EOL%%EOL%// outputs%EOL%out vec4 vp_Color;%EOL%out vec3 vp_Normal;%EOL%%EOL%out vec4 oe_layer_texc;%EOL%out vec4 oe_layer_tilec;%EOL%out vec3 oe_UpVectorView;%EOL%%EOL%out float oe_rex_morphFactor;%EOL%%EOL%void oe_rexEngine_vert(inout vec4 vertexModel)%EOL%{%EOL% // Texture coordinate for the tile (always 0..1)%EOL% oe_layer_tilec = gl_MultiTexCoord0;%EOL%%EOL% // Color of the underlying map geometry (untextured)%EOL% vp_Color = oe_terrain_color;%EOL% %EOL% // %QUOTE%up%QUOTE% vector at this vertex in view space, which we will later%EOL% // need in order to elevate the terrain%EOL% oe_UpVectorView = normalize(gl_NormalMatrix*vp_Normal);%EOL%%EOL% // initialize:%EOL% oe_rex_morphFactor = 0.0;%EOL%}%EOL%%EOL%";
ENGINE_ELEVATION_MODEL = "RexEngine.elevation.glsl";
_sources[ENGINE_ELEVATION_MODEL] = "#version $GLSL_VERSION_STR%EOL%%EOL%#pragma vp_name REX Engine - Elevation%EOL%#pragma vp_entryPoint oe_rexEngine_elevation%EOL%#pragma vp_location vertex_model%EOL%#pragma vp_order 0.7%EOL%%EOL%#pragma import_defines(OE_TERRAIN_RENDER_ELEVATION)%EOL%%EOL%// Vertex Markers:%EOL%#define MASK_MARKER_DISCARD 0.0%EOL%#define MASK_MARKER_NORMAL 1.0%EOL%#define MASK_MARKER_PATCH 2.0%EOL%#define MASK_MARKER_BOUNDARY 3.0%EOL%%EOL%// stage%EOL%vec3 vp_Normal; // up vector%EOL%vec4 oe_layer_texc;%EOL%vec4 oe_layer_tilec;%EOL%%EOL%// SDK functions:%EOL%float oe_terrain_getElevation(in vec2 uv);%EOL%%EOL%void oe_rexEngine_elevation(inout vec4 vertexModel)%EOL%{ %EOL%#ifdef OE_TERRAIN_RENDER_ELEVATION%EOL% float elev = %EOL% oe_layer_tilec.z == MASK_MARKER_BOUNDARY || oe_layer_tilec.z == MASK_MARKER_DISCARD ? 0.0f%EOL% : oe_terrain_getElevation( oe_layer_tilec.st );%EOL%%EOL% vertexModel.xyz += normalize(vp_Normal) * elev;%EOL%#endif%EOL%}%EOL%%EOL%";
MORPHING_VERT = "RexEngine.Morphing.vert.glsl";
_sources[MORPHING_VERT] = "#version $GLSL_VERSION_STR%EOL%$GLSL_DEFAULT_PRECISION_FLOAT%EOL%%EOL%#pragma vp_name REX Engine - Morphing%EOL%#pragma vp_entryPoint oe_rexEngine_morph%EOL%#pragma vp_location vertex_model%EOL%#pragma vp_order 0.5%EOL%%EOL%#pragma import_defines(OE_TERRAIN_MORPH_GEOMETRY, OE_TERRAIN_RENDER_ELEVATION)%EOL%%EOL%%EOL%// stage%EOL%vec3 vp_Normal; // up vector%EOL%%EOL%vec4 oe_layer_texc;%EOL%vec4 oe_layer_tilec;%EOL%%EOL%out float oe_rex_morphFactor;%EOL%%EOL%uniform vec2 oe_tile_morph;%EOL%uniform float oe_tile_size;%EOL%%EOL%// SDK functions:%EOL%float oe_terrain_getElevation(in vec2 uv);%EOL%%EOL%// Vertex Markers:%EOL%#define MASK_MARKER_DISCARD 0.0%EOL%#define MASK_MARKER_NORMAL 1.0%EOL%#define MASK_MARKER_PATCH 2.0%EOL%#define MASK_MARKER_BOUNDARY 3.0%EOL%%EOL%%EOL%// Morphs a vertex using a neighbor.%EOL%void oe_rex_MorphVertex(inout vec3 position, inout vec2 uv, in vec3 neighborPosition)%EOL%{%EOL% float halfSize = (0.5*oe_tile_size)-0.5;%EOL% float twoOverHalfSize = 2.0/(oe_tile_size-1.0);%EOL% %EOL% vec2 fractionalPart = fract(uv * halfSize) * twoOverHalfSize;%EOL% uv = clamp(uv - (fractionalPart * oe_rex_morphFactor), 0.0, 1.0);%EOL% //uv = clamp(uv, 0, 1);%EOL%%EOL% vec3 morphVector = neighborPosition.xyz - position.xyz;%EOL% position.xyz = position.xyz + morphVector*oe_rex_morphFactor;%EOL%}%EOL%%EOL%%EOL%// Compute a morphing factor based on model-space inputs:%EOL%float oe_rex_ComputeMorphFactor(in vec4 position, in vec3 up)%EOL%{%EOL% // Find the %QUOTE%would be%QUOTE% position of the vertex (the position the vertex would%EOL% // assume with no morphing)%EOL% vec4 wouldBePosition = position;%EOL%%EOL%#ifdef OE_TERRAIN_RENDER_ELEVATION%EOL% float elev = oe_terrain_getElevation( oe_layer_tilec.st );%EOL% wouldBePosition.xyz += up*elev;%EOL%#endif%EOL%%EOL% vec4 wouldBePositionView = gl_ModelViewMatrix * wouldBePosition;%EOL% %EOL% float fDistanceToEye = length(wouldBePositionView.xyz); // or just -z.%EOL% float fMorphLerpK = 1.0f - clamp( oe_tile_morph[0] - fDistanceToEye * oe_tile_morph[1], 0.0, 1.0 );%EOL% return fMorphLerpK;%EOL%}%EOL%%EOL%%EOL%void oe_rexEngine_morph(inout vec4 vertexModel)%EOL%{ %EOL% // compute the morphing factor to send down the pipe.%EOL% // we need this even if vertex-morphing is off since we use it for %EOL% // other things (like image blending)%EOL% if (oe_layer_tilec.z == MASK_MARKER_NORMAL)%EOL% {%EOL% oe_rex_morphFactor = oe_rex_ComputeMorphFactor(vertexModel, vp_Normal); %EOL%%EOL%#ifdef OE_TERRAIN_MORPH_GEOMETRY%EOL% vec3 neighborVertexModel = gl_MultiTexCoord1.xyz;%EOL% oe_rex_MorphVertex(vertexModel.xyz, oe_layer_tilec.st, neighborVertexModel.xyz);%EOL%#endif%EOL% }%EOL% else%EOL% {%EOL% oe_rex_morphFactor = 0.0;%EOL% }%EOL%}%EOL%%EOL%";
ENGINE_VERT_VIEW = "RexEngine.vert.view.glsl";
_sources[ENGINE_VERT_VIEW] = "#version $GLSL_VERSION_STR%EOL%$GLSL_DEFAULT_PRECISION_FLOAT%EOL%%EOL%#pragma vp_name REX Engine - Vertex/View%EOL%#pragma vp_entryPoint oe_rex_elevateVertexAndSetTexCoords%EOL%#pragma vp_location vertex_view%EOL%#pragma vp_order 0.4%EOL%%EOL%// Stage globals%EOL%vec4 oe_layer_tilec;%EOL%vec3 oe_UpVectorView;%EOL%vec4 oe_layer_texc;%EOL%vec4 oe_layer_texcParent;%EOL%%EOL%vec4 vp_Color;%EOL%%EOL%uniform mat4 oe_layer_texMatrix;%EOL%uniform mat4 oe_layer_texParentMatrix;%EOL%%EOL%uniform float oe_layer_minRange;%EOL%uniform float oe_layer_maxRange;%EOL%uniform float oe_layer_attenuationRange;%EOL%%EOL%out float oe_layer_rangeOpacity;%EOL%%EOL%// SDK functions:%EOL%float oe_terrain_getElevation(in vec2 uv);%EOL%%EOL%void oe_rex_elevateVertexAndSetTexCoords(inout vec4 vertexView)%EOL%{%EOL% // calculate the texture coordinates:%EOL% oe_layer_texc = oe_layer_texMatrix * oe_layer_tilec;%EOL% oe_layer_texcParent = oe_layer_texParentMatrix * oe_layer_tilec;%EOL%%EOL% float range = max(-vertexView.z, 0.0);%EOL%%EOL% float attenMin = oe_layer_minRange - oe_layer_attenuationRange;%EOL% float attenMax = oe_layer_maxRange + oe_layer_attenuationRange;%EOL%%EOL% oe_layer_rangeOpacity =%EOL% oe_layer_minRange >= oe_layer_maxRange ? 1.0 :%EOL% range >= oe_layer_minRange && range < oe_layer_maxRange ? 1.0 :%EOL% range < oe_layer_minRange ? clamp((range-attenMin)/oe_layer_attenuationRange, 0.0, 1.0) :%EOL% range > oe_layer_maxRange ? clamp((attenMax-range)/oe_layer_attenuationRange, 0.0, 1.0) :%EOL% 0.0;%EOL%}%EOL%%EOL%";
ENGINE_FRAG = "RexEngine.frag.glsl";
_sources[ENGINE_FRAG] = "#version $GLSL_VERSION_STR%EOL%$GLSL_DEFAULT_PRECISION_FLOAT%EOL%%EOL%#pragma vp_name REX Engine - Fragment%EOL%#pragma vp_entryPoint oe_rexEngine_frag%EOL%#pragma vp_location fragment_coloring%EOL%#pragma vp_order 0.5%EOL%%EOL%#pragma import_defines(OE_TERRAIN_RENDER_IMAGERY, OE_TERRAIN_MORPH_IMAGERY, OE_TERRAIN_BLEND_IMAGERY, OE_TERRAIN_CAST_SHADOWS, OE_IS_PICK_CAMERA, OE_IS_SHADOW_CAMERA)%EOL%%EOL%uniform sampler2D oe_layer_tex;%EOL%uniform int oe_layer_uid;%EOL%uniform int oe_layer_order;%EOL%uniform float oe_layer_opacity;%EOL%%EOL%#ifdef OE_TERRAIN_MORPH_IMAGERY%EOL%uniform sampler2D oe_layer_texParent;%EOL%uniform float oe_layer_texParentExists;%EOL%in vec4 oe_layer_texcParent;%EOL%in float oe_rex_morphFactor;%EOL%#endif%EOL%%EOL%in vec4 oe_layer_texc;%EOL%in vec4 oe_layer_tilec;%EOL%%EOL%in float oe_layer_rangeOpacity;%EOL%%EOL%void oe_rexEngine_frag(inout vec4 color)%EOL%{%EOL%#if defined(OE_IS_SHADOW_CAMERA) && !defined(OE_TERRAIN_CAST_SHADOWS)%EOL% discard;%EOL% return;%EOL%#endif%EOL%%EOL%#ifdef OE_IS_PICK_CAMERA%EOL% color = vec4(0);%EOL%#else%EOL%%EOL%#ifndef OE_TERRAIN_RENDER_IMAGERY%EOL% return;%EOL%#endif%EOL%%EOL% float isImageLayer = oe_layer_uid >= 0 ? 1.0 : 0.0;%EOL% vec4 texelSelf = texture(oe_layer_tex, oe_layer_texc.st);%EOL%%EOL%#ifdef OE_TERRAIN_MORPH_IMAGERY%EOL%%EOL% // sample the parent texture:%EOL% vec4 texelParent = texture(oe_layer_texParent, oe_layer_texcParent.st);%EOL%%EOL% // if the parent texture does not exist, use the current texture with alpha=0 as the parent%EOL% // so we can %QUOTE%fade in%QUOTE% an image layer that starts at LOD > 0:%EOL% texelParent = mix( vec4(texelSelf.rgb, 0.0), texelParent, oe_layer_texParentExists );%EOL%%EOL% // Resolve the final texel color:%EOL% vec4 texel = mix(texelSelf, texelParent, oe_rex_morphFactor);%EOL%%EOL% // Decide whether to use the texel or the incoming color:%EOL% texel = mix(color, texel, isImageLayer);%EOL%%EOL%#else%EOL%%EOL% // No morphing, just use the incoming color or texture:%EOL% vec4 texel = mix(color, texelSelf, isImageLayer);%EOL%%EOL%#endif%EOL%%EOL% // Integrate layer opacity into the texture:%EOL% //texel.a = mix(texel.a, texel.a*oe_layer_rangeOpacity, isImageLayer);%EOL% texel.a = mix(texel.a, texel.a*oe_layer_opacity*oe_layer_rangeOpacity, isImageLayer);%EOL% %EOL%#ifdef OE_TERRAIN_BLEND_IMAGERY%EOL%%EOL% float isFirstImageLayer = (isImageLayer == 1.0 && oe_layer_order == 0) ? 1.0 : 0.0;%EOL%%EOL% // If this is a first image layer, blend with the incoming terrian color.%EOL% // Otherwise, apply directly and let GL blending do the rest.%EOL% if (isFirstImageLayer == 1.0) {%EOL% color.rgb = texel.rgb*texel.a + color.rgb*(1.0-texel.a);%EOL% color.a = max(color.a, texel.a);%EOL% }%EOL% else color = texel;%EOL%%EOL%#else%EOL%%EOL% // No blending? The output is just the texel value.%EOL% color = texel;%EOL%%EOL%#endif // OE_TERRAIN_BLEND_IMAGERY%EOL%%EOL%#endif // OE_IS_PICK_CAMERA%EOL%}%EOL%%EOL%";
NORMAL_MAP_VERT = "RexEngine.NormalMap.vert.glsl";
_sources[NORMAL_MAP_VERT] = "#version $GLSL_VERSION_STR%EOL%$GLSL_DEFAULT_PRECISION_FLOAT%EOL%%EOL%#pragma vp_entryPoint oe_normalMapVertex%EOL%#pragma vp_location vertex_view%EOL%#pragma vp_order 0.5%EOL%%EOL%#pragma import_defines(OE_TERRAIN_RENDER_NORMAL_MAP)%EOL%%EOL%uniform mat4 oe_tile_normalTexMatrix;%EOL%uniform vec2 oe_tile_elevTexelCoeff;%EOL%%EOL%// stage globals%EOL%vec4 oe_layer_tilec;%EOL%%EOL%out vec2 oe_normalMapCoords;%EOL%out vec3 oe_normalMapBinormal;%EOL%%EOL%void oe_normalMapVertex(inout vec4 unused)%EOL%{%EOL%#ifndef OE_TERRAIN_RENDER_NORMAL_MAP%EOL% return;%EOL%#endif%EOL%%EOL% // calculate the sampling coordinates for the normal texture%EOL% //oe_normalMapCoords = (oe_tile_normalTexMatrix * oe_layer_tilec).st;%EOL% %EOL% oe_normalMapCoords = oe_layer_tilec.st%EOL% * oe_tile_elevTexelCoeff.x * oe_tile_normalTexMatrix[0][0]%EOL% + oe_tile_elevTexelCoeff.x * oe_tile_normalTexMatrix[3].st%EOL% + oe_tile_elevTexelCoeff.y;%EOL%%EOL% // send the bi-normal to the fragment shader%EOL% oe_normalMapBinormal = normalize(gl_NormalMatrix * vec3(0,1,0));%EOL%}%EOL%%EOL%";
NORMAL_MAP_FRAG = "RexEngine.NormalMap.frag.glsl";
_sources[NORMAL_MAP_FRAG] = "#version $GLSL_VERSION_STR%EOL%$GLSL_DEFAULT_PRECISION_FLOAT%EOL%%EOL%#pragma vp_entryPoint oe_normalMapFragment%EOL%#pragma vp_location fragment_coloring%EOL%#pragma vp_order 0.2%EOL%%EOL%#pragma import_defines(OE_TERRAIN_RENDER_NORMAL_MAP, OE_DEBUG_NORMALS)%EOL%%EOL%// import terrain SDK%EOL%vec4 oe_terrain_getNormalAndCurvature(in vec2);%EOL%%EOL%uniform sampler2D oe_tile_normalTex;%EOL%%EOL%in vec3 vp_Normal;%EOL%in vec3 oe_UpVectorView;%EOL%in vec2 oe_normalMapCoords;%EOL%in vec3 oe_normalMapBinormal;%EOL%%EOL%void oe_normalMapFragment(inout vec4 color)%EOL%{%EOL%#ifndef OE_TERRAIN_RENDER_NORMAL_MAP%EOL% return;%EOL%#endif%EOL%%EOL% vec4 encodedNormal = oe_terrain_getNormalAndCurvature(oe_normalMapCoords);%EOL% vec3 normal = normalize(encodedNormal.xyz*2.0-1.0);%EOL%%EOL% vec3 tangent = normalize(cross(oe_normalMapBinormal, oe_UpVectorView));%EOL% vp_Normal = normalize( mat3(tangent, oe_normalMapBinormal, oe_UpVectorView) * normal );%EOL%%EOL% // visualize curvature quantized:%EOL% //color.rgba = vec4(0.0,0,1);%EOL% //float curvature = 2.0*encodedNormal.w - 1.0;%EOL% //if (curvature > 0.0) color.r = curvature;%EOL% //if (curvature < 0.0) color.b = -curvature;%EOL% //color.a = 1.0;%EOL% %EOL%#ifdef OE_DEBUG_NORMALS%EOL% // visualize normals:%EOL% color.rgb = encodedNormal.xyz;%EOL%#endif%EOL%}%EOL%%EOL%";
ENGINE_GEOM = "RexEngine.gs.glsl";
_sources[ENGINE_GEOM] = "#version $GLSL_VERSION_STR%EOL%$GLSL_DEFAULT_PRECISION_FLOAT%EOL%%EOL%%EOL%#if 0 // currently unused - triangle discard implemented on CPU instead%EOL%%EOL%#pragma vp_name REX Engine - GS%EOL%#pragma vp_entryPoint oe_rexEngine_gs%EOL%#pragma vp_location geometry%EOL%%EOL%// Vertex Markers:%EOL%#define MASK_MARKER_DISCARD 0.0%EOL%#define MASK_MARKER_NORMAL 1.0%EOL%#define MASK_MARKER_SKIRT 2.0%EOL%#define MASK_MARKER_BOUNDARY 3.0%EOL%%EOL%layout(triangles) in;%EOL%layout(triangle_strip) out;%EOL%layout(max_vertices=3) out;%EOL%%EOL%void VP_LoadVertex(in int);%EOL%void VP_EmitModelVertex();%EOL%%EOL%in vec4 oe_layer_tilec;%EOL%%EOL%void oe_rexEngine_gs(void)%EOL%{%EOL% for(int i=0; i < 3; ++i )%EOL% {%EOL% VP_LoadVertex(i);%EOL% if ( oe_layer_tilec.z == MASK_MARKER_DISCARD )%EOL% return;%EOL% }%EOL%%EOL% for(int i=0; i < 3; ++i )%EOL% {%EOL% VP_LoadVertex(i);%EOL% gl_Position = gl_in[i].gl_Position;%EOL% VP_EmitModelVertex();%EOL% }%EOL% EndPrimitive();%EOL%}%EOL%%EOL%#endif%EOL%%EOL%";
SDK = "RexEngine.SDK.vert.glsl";
_sources[SDK] = "#version $GLSL_VERSION_STR%EOL%$GLSL_DEFAULT_PRECISION_FLOAT%EOL%%EOL%#pragma vp_name Rex Terrain SDK%EOL%%EOL%/**%EOL% * SDK functions for the Rex engine.%EOL% * Declare and call these from any shader that runs on the terrain.%EOL% */%EOL%%EOL%// uniforms from terrain engine%EOL%uniform sampler2D oe_tile_elevationTex;%EOL%uniform mat4 oe_tile_elevationTexMatrix;%EOL%uniform vec2 oe_tile_elevTexelCoeff;%EOL%%EOL%uniform sampler2D oe_tile_normalTex;%EOL%uniform mat4 oe_tile_normalTexMatrix;%EOL%%EOL%uniform vec4 oe_tile_key;%EOL%%EOL%// Stage global%EOL%vec4 oe_layer_tilec;%EOL%%EOL%%EOL%/**%EOL% * Sample the elevation data at a UV tile coordinate.%EOL% */%EOL%float oe_terrain_getElevationUnscaled(in vec2 uv)%EOL%{%EOL% // Texel-level scale and bias allow us to sample the elevation texture%EOL% // on texel center instead of edge.%EOL% vec2 elevc = uv%EOL% * oe_tile_elevTexelCoeff.x // scale%EOL% + oe_tile_elevTexelCoeff.y;%EOL%%EOL% return texture(oe_tile_elevationTex, elevc).r;%EOL%}%EOL%%EOL%/**%EOL% * Sample the elevation data at a UV tile coordinate.%EOL% */%EOL%float oe_terrain_getElevation(in vec2 uv)%EOL%{%EOL% // Texel-level scale and bias allow us to sample the elevation texture%EOL% // on texel center instead of edge.%EOL% vec2 elevc = uv%EOL% * oe_tile_elevTexelCoeff.x * oe_tile_elevationTexMatrix[0][0] // scale%EOL% + oe_tile_elevTexelCoeff.x * oe_tile_elevationTexMatrix[3].st // bias%EOL% + oe_tile_elevTexelCoeff.y;%EOL%%EOL% return texture(oe_tile_elevationTex, elevc).r;%EOL%}%EOL%%EOL%/**%EOL% * Read the elevation at the build-in tile coordinates (convenience)%EOL% */%EOL%float oe_terrain_getElevation()%EOL%{%EOL% return oe_terrain_getElevation(oe_layer_tilec.st);%EOL%}%EOL%%EOL%/**%EOL% * Read the normal vector and curvature at resolved UV tile coordinates.%EOL% */%EOL%vec4 oe_terrain_getNormalAndCurvature(in vec2 uv_scaledBiased)%EOL%{%EOL% return texture(oe_tile_normalTex, uv_scaledBiased);%EOL%}%EOL%%EOL%vec4 oe_terrain_getNormalAndCurvature()%EOL%{%EOL% vec2 uv_scaledBiased = oe_layer_tilec.st%EOL% * oe_tile_elevTexelCoeff.x * oe_tile_normalTexMatrix[0][0]%EOL% + oe_tile_elevTexelCoeff.x * oe_tile_normalTexMatrix[3].st%EOL% + oe_tile_elevTexelCoeff.y;%EOL%%EOL% return texture(oe_tile_normalTex, uv_scaledBiased);%EOL%}%EOL%%EOL%/**%EOL% * Scales repeating texture coordinate such that they are [0..1]%EOL% * at a specific reference tile LOD. %EOL% */%EOL%vec2 oe_terrain_scaleCoordsToRefLOD(in vec2 tc, in float refLOD)%EOL%{%EOL% float dL = oe_tile_key.z - refLOD;%EOL% float factor = exp2(dL);%EOL% float invFactor = 1.0/factor;%EOL% vec2 result = tc * vec2(invFactor);%EOL%%EOL% vec2 a = floor(oe_tile_key.xy * invFactor);%EOL% vec2 b = a * factor;%EOL% vec2 c = b + factor;%EOL%%EOL% float m = floor(clamp(factor,0.0,1.0)); // if factor>=1.0%EOL% result += m*(oe_tile_key.xy-b)/(c-b);%EOL%%EOL% return result;%EOL%}%EOL%%EOL%";
}
待继续分析列表:
9、earth文件中都有哪些options((九)中问题)
10、如何根据earth文件options创建不同的地理信息引擎节点((九)中问题)
11、rex地理信息引擎的四梁八柱((九)中问题)
12、osgEarth::TerrainEngineNode中setMap方法作用((十二)中问题)
13、RexTerrainEngineNode中_mapFrame的作用((十二)中问题)
14、地形变形(Terrain morphing)((十二)中问题)
15、地球瓦片过期门限的含义((十二)中问题)
16、高分辨率优先的含义((十二)中问题)
17、OSGEARTH_DEBUG_NORMALS环境变量的作用((十二)中问题)
18、活跃瓦片寄存器的作用((十二)中问题)
19、资源释放器子节点的作用((十二)中问题)
20、共享几何图形池子节点的作用((十二)中问题)
21、分页瓦片加载器子节点的作用((十二)中问题)
22、分页瓦片卸载器子节点的作用((十二)中问题)
23、栅格化器子节点的作用((十二)中问题)
24、地形子节点的作用((十二)中问题)
25、绑定渲染器的作用((十二)中问题)
26、地图回调函数的作用((十二)中问题)
27、如何将地图图层添加到rex引擎中((十二)中问题)
28、选择信息的作用((十二)中问题)
29、瓦片包围盒修改回调函数的作用((十二)中问题)
30、刷新rex引擎((十二)中问题)
31、刷新边界作用((十二)中问题)
32、osgEarth::Metrics类的意义((十四)中问题)
33、请求合并队列_mergeQueue((十四)中问题)
34、分页瓦片加载器在更新遍历时对请求处理过程((十四)中问题)
35、分页瓦片加载器在更新遍历时对已处理请求裁剪过程((十四)中问题)
36、已处理的请求队列_requests((十四)中问题)
37、DatabasePager中的_fileRequestQueue和_httpRequestQueue((十六)中问题)
38、瓦片请求的生成到处理过程详解((十六)中问题)
39、瓦片节点TileNode的创建过程((十七)中问题)
40、request请求加载瓦片优先级的含义((十七)中问题)
41、request的_internalHandle的作用((十七)中问题)
42、DatabaseRequest中_objectCache含义((十七)中问题)
42、osgEarth的多线程分析((十七)中问题)
43、osgEarth的缓存及其结构((十七)中问题)
44、DatabaseThread从缓存加载数据过程((十七)中问题)
45、DatabaseThread从文件加载数据过程((十七)中问题)
46、决定创建TileNode的时机条件((十七)中问题)
47、TerrainEngineNode的createTileModel过程详解((十七)中问题)
48、DatabaseThread中CompileSet的含义((十七)中问题)
48、PagerLoader的traverse过程详解((十七)中问题)
49、DatabaseThread的run过程详解((十七)中问题)
50、LoadTileData的invoke过程详解((十七)中问题)
51、TileNode的cull过程详解((十七)中问题)
52、遮罩生成器osgEarth::Drivers::RexTerrainEngine::MaskGenerator((十八)中问题)
53、RexTerrainEngineNode::traverse过程详解((十八)中问题)
54、TileNode节点下的场景树分析((十八)中问题)
55、地形瓦片大小尺寸和LOD的关系((十八)中问题)
56、TileNode的_tileKeyValue作用((十八)中问题)
57、TileNode的_morphConstants作用((十八)中问题)
58、TileNode的_stitchNormalMap作用((十八)中问题)
59、TileNode的_renderModel作用((十八)中问题)
60、初始化高程栅格过程详解((十八)中问题)
61、LoadTileData中的CreateTileModelFilter作用((十八)中问题)
62、TileNode节点何时会从场景树中移除((十八)中问题)
63、osgEarth::Map的Profile创建过程((二十)中问题)
64、osgEarth::TerrainTileModelFactory添加颜色层和影像层的区别((二十一)中问题)
65、osgEarth::PatchLayer修补层的作用((二十一)中问题)
66、osgEarth::TerrainLayer中的_memCache(osgEarth::MemCache)详解((二十一)中问题)
67、osgEarth::Layer::RenderType图层渲染类型的作用((二十一)中问题)
68、osgEarth::TerrainLayer中TileSource的作用((二十一)中问题)
69、earth文件没有设置高程图层会不会有默认高程层(高程均为0)((二十一)中问题)
70、TerrainTileModelFactory::addColorLayers过程详解((二十一)中问题)
71、TerrainTileModelFactory::addElevation过程详解((二十一)中问题)
72、osgearth中可能用到的几个全局实例对象(osgDB::Registry osgEarth::Registry osg::Timer osg::DisplaySetting)((二十三)中问题)
73、osgEarth::Map::addLayer过程详解((二十三)中问题)
74、TileNode::setDirty过程详解((二十三)中问题)
75、请求四个状态的含义(IDLE RUNNING MERGING FINISHED)((二十三)中问题)
76、什么时候删除TileNode节点,不会一直增加吧((二十三)中问题)
77、寄存器中请求状态活动记录的含义Registry::instance()->endActivity( req->getName() )((二十三)中问题)
78、瓦片TileNode的生命周期流程详解((二十三)中问题)
79、rex引擎如何将瓦片构造成地球形状((二十五)中问题)
80、高程、影像文件格式详解((二十五)中问题)
81、TileNode的merge过程详解((二十六)中问题)
82、osgEarth支持的空间参考坐标系详解(osgEarth::SpatialReference、osgEarth::CubeSpatialReference、osgEarth::TangentPlaneSpatialReference)((二十九)中问题)
83、osgEarth地球椭球体ellipsoid 大地基准面datum 地图投影Projection详解((二十九)中问题)
84、空间参考坐标系和坐标系统类型的关系(geocentric projected)((二十九)中问题)
85、proj4是什么((二十九)中问题)
86、为什么要删除设置过的垂直水准面((二十九)中问题)
87、osgEarth如何对投影坐标系和大地坐标系进行显示处理的((二十九)中问题)
88、TileNode的节点构成,一个surface、tilenode((三十)中问题)
89、MapFram和MapInfo的关系((三十)中问题)
90、ModifyBoundingBoxCallback的使用时机和场合((三十)中问题)
91、MapFrame为什么要单独存放高程层_elevationLayers,而不是放在图层_layers中((三十)中问题)
92、MapFrame和Map中高程池的作用osg::ref_ptr<ElevationPool> _elevationPool((三十)中问题)
93、osgEarth::Drivers::RexTerrainEngine::TileDrawable分析((三十)中问题)
94、请求读取地理信息失败会如何处理((三十二)中问题)
95、RexTerrainEngineNode的遍历过程详解((三十三)中问题)
96、osgEarth::Drivers::RexTerrainEngine::TerrainCuller的apply过程详解((三十三)中问题)
97、RexTerrainEngineNode的updateState过程详解 设置了很多着色器变量((三十三)中问题)
98、什么时候分配opengl资源((三十三)中问题)
99、TileNode释放opengl资源过程releaseGLObjects详解((三十三)中问题)
100、最近一次遍历的帧号和时间是怎么设置呢(在渲染遍历里),怎么就不会再渲染遍历该瓦片节点了((三十三)中问题)
101、osg::State和osg::StateSet的关系((三十四)中问题)
102、osgEarth::SpatialReference和osgEarth::Profile的关系((三十六)中问题)
103、osgEarth的Geographic、Geodetic、Geocentric和Project的关系((三十六)中问题)
104、TileNode绘制过程详解((三十七)中问题)
105、如何控制父子TileNode节点的显隐((三十七)中问题)
106、GeometryPool的createGeometry过程详解((三十七)中问题)
107、TileNode如何从地图中提取与其分辨率相适应的图像数据((三十七)中问题)
108、如何定制椭球体并进行椭球体间坐标转换((四十五)中问题)
109、Horizon Cull是什么意思((四十五)中问题)
110、osgEarth::Drivers::RexTerrainEngine::DrawState的作用((四十五)中问题)
111、osgEarth的线程分析((四十五)中问题)
112、从osgEarth到osg到Opengl((四十五)中问题)
113、osg::Program与osgEarth::VirtualProgram的关系((四十五)中问题)
114、rex引擎shader文件中的#pragma vp_entryPoint vp_location等含义((四十五)中问题)
115、rex引擎的着色器如何区分顶点和片段((四十五)中问题)
116、osg::Program是如何对着色器及其变量进行管理的((四十五)中问题)
117、osg的窗口是如何与opengl集成的((四十五)中问题)
118、osg是如何实现opengl的初始化的((四十五)中问题)
119、CGCS2000余WGS84坐标系的比较((四十六)中问题)
120、着色器代码文件到着色器程序的过程((五十一)中问题)
121、osgEarth::VirtualProgram默认出现在哪些位置((五十一)中问题)
122、rex引擎默认的几个着色器功能分析((五十一)中问题)
123、osgEarth::TileRasterizer功能详解((五十二)中问题)
124、osgEarth::ImageLayer如何使用VirtualProgram((五十二)中问题)
125、osgEarth::ShaderFactory osgEarth::ShaderLoader关系((五十四)中问题)
126、osgEarth::URI和osgEarth::URIContext的作用((五十四)中问题)
127、RexTerrainEngineNode中_renderBindings的作用((五十四)中问题)
128、Rex引擎如何给shader文件中的uniform变量赋值((五十四)中问题)
129、osgEarth中多个着色器的源代码的编译链接过程((五十四)中问题)
130、osgEarth::ShaderFactory osgEarth::ShaderLoader关系((五十四)中问题)
131、TileNode与DrawTileCommand的关系((五十五)中问题)
132、如何提取出指定范围的高程网格((五十五)中问题)
133、从earth文件加载高层图层的过程((五十五)中问题)
134、TerrainTileModel与TileRenderModel的关系((五十五)中问题)
135、EngineContext的作用((五十五)中问题)
136、几个uniformmap的关系((五十五)中问题)
137、DrawTileCommand中的采样器((五十五)中问题)
138、TileNode中的_surface(SurfaceNode)作用是什么((五十五)中问题)
139、stateset中的adduniform、setTextureAttribute等最后是如何反应到opengl上的((五十五)中问题)
140、状态树和渲染树的关系((五十五)中问题)
141、TileRenderModel中的RenderingPass和RenderBindings((五十五)中问题)
142、高程瓦片的绘制过程((五十五)中问题)
143、如何从高程影像变成高程网格((七十一)中问题)
144、osg::StateSet中的_binMode作用((七十二)中问题)
145、rex的瓦片高程影像和高程文件中的影像尺寸如何对应((七十二)中问题)
146、osgEarth::TerrainLayerOptions高程层选项中参数的含义((七十二)中问题)
147、从高程文件读取的高程信息如何填充rex的高程瓦片((七十二)中问题)
148、地图下载器实现原理((七十二)中问题)
149、RexTerrainEngineNode和TerrainCuller中_terrain的关系((七十二)中问题)
150、TileNodeRegistry和LayerDrawable中_tiles的关系((七十二)中问题)
151、rex引擎中绘制瓦片的调度过程原理((七十二)中问题)
152、晕眩图的制作与实现((七十八)中问题)
153、如何将高层场保存为tif、MBTiles等((七十八)中问题)
154、如何将tif和MBTiles进行格式转换((七十八)中问题)
155、如何加载百度、高德、谷歌、微软的在线地图((七十八)中问题)
156、osgEarth运行起来为什么很占CPU资源((七十九)中问题)
157、wmts与xyz、quadtree、tms的关系((七十九)中问题)
158、获取的高程图像为什么除了设置纹理还要设置栅格((八十)中问题)
159、rex引擎创建图层的过程((八十一)中问题)
160、如何设置高度单位(m、km等)((八十二)中问题)
161、网络资源加载失败还会不会继续加载((八十二)中问题)
162、rex引擎打开图层的过程((八十二)中问题)
163、osgEarth::MemCache详解((八十二)中问题)
164、OGR与GDAL的关系((八十二)中问题)
165、osgEarth::Map的cache创建过程((八十三)中问题)
166、osgEarth跨平台的头文件包含设置((八十三)中问题)
167、rex引擎如何实现淹没分析((八十八)中问题)
168、rex引擎如何实现挖方分析((八十八)中问题)
169、rex引擎如何实现地形整平((八十八)中问题)
170、rex引擎如何绘制矢量图形((八十八)中问题)
170、rex引擎如何绘制等高线((八十八)中问题)
171、rex引擎如何显示瓦片的边界((八十八)中问题)
172、边界处瓦片颜色混合的实现((九十)中问题)
173、rex自带的着色器代码会硬编码进动态库吗((九十一)中问题)
174、rex在渲染时会不会纹理单元内容频繁更改((九十一)中问题)
175、rex的自带着色器文件是如何写死在动态库中的((九十一)中问题)