forked from gwaldron/osgearth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtess-terrain.earth
146 lines (113 loc) · 6.69 KB
/
tess-terrain.earth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!--
osgEarth Sample - OpenGL Tessellation Shaders
This example injects a Tessellation Control Shader (TCS) and
Tessellation Evaluation Shader (TES) into the terrain rendering
pipeline. This is EXPERIMENTAL so please be advised of the
following caveats:
* Terrain skirts will not render. Set "skirt_ratio" to zero or you
will get GL errors.
* Set gpu_tessellation="true" on the terrain options.
* EarthManipulator doesn't like GL_PATCHES (yet). Use the viewpoints.
Press 'w' for wireframe mode to see the tessellation!
-->
<map name="readymap.org" type="geocentric">
<options>
<terrain driver="mp" gpu_tessellation="true" min_lod="25" tile_size="8" />
</options>
<image name="readymap_imagery" driver="tms">
<url>http://readymap.org/readymap/tiles/1.0.0/7/</url>
</image>
<elevation name="readymap_elevation" driver="tms">
<url>http://readymap.org/readymap/tiles/1.0.0/116/</url>
</elevation>
<extensions>
<terrainshader>
<code><![CDATA[
#version 400 compatibility
#pragma vp_entryPoint "configureTess"
#pragma vp_location "tess_control"
layout(vertices = 3) out;
uniform float pixelsPerEdge = 7.5;
uniform vec2 viewportSize = vec2(1024,1024);
// convert model position to viewport coordinates.
vec2 toPixels(in vec4 pos)
{
vec4 clip = gl_ModelViewProjectionMatrix * pos;
return (clip.xy/clip.w) * (viewportSize*0.5);
}
// calculate a tessellation level based on the maximum edge length uniform.
float tessLevel(in vec2 v0, in vec2 v1)
{
return clamp(distance(v0,v1)/pixelsPerEdge, 1.0, 128.0);
}
void configureTess()
{
// Only required for the first invocation:
if ( gl_InvocationID == 0 )
{
vec2 U = toPixels( gl_in[0].gl_Position );
vec2 V = toPixels( gl_in[1].gl_Position );
vec2 W = toPixels( gl_in[2].gl_Position );
float E0 = tessLevel(V, W);
float E1 = tessLevel(W, U);
float E2 = tessLevel(U, V);
gl_TessLevelOuter[0] = E0;
gl_TessLevelOuter[1] = E1;
gl_TessLevelOuter[2] = E2;
gl_TessLevelInner[0] = (E0+E1+E2)/3.0;
}
}
]]></code>
</terrainshader>
<terrainshader>
<code><![CDATA[
#version 410
#pragma vp_name "Terrain TES Shader"
#pragma vp_entryPoint "generateVertex"
#pragma vp_location "tess_eval"
// osgEarth terrain is always CCW winding
layout(triangles, equal_spacing, ccw) in;
// Internal helpers:
void VP_Interpolate3();
void VP_EmitVertex();
float VP_Interpolate3(float a, float b, float c) {
return dot(gl_TessCoord.xyz, vec3(a,b,c));
}
vec2 VP_Interpolate3(vec2 a, vec2 b, vec2 c) {
return vec2(dot(gl_TessCoord.xyz, vec3(a.x,b.x,c.x)),
dot(gl_TessCoord.xyz, vec3(a.y,b.y,c.y)));
}
vec3 VP_Interpolate3(vec3 a, vec3 b, vec3 c) {
return vec3(dot(gl_TessCoord.xyz, vec3(a.x,b.x,c.x)),
dot(gl_TessCoord.xyz, vec3(a.y,b.y,c.y)),
dot(gl_TessCoord.xyz, vec3(a.z,b.z,c.z)));
}
vec4 VP_Interpolate3(vec4 a, vec4 b, vec4 c) {
return vec4(dot(gl_TessCoord.xyz, vec3(a.x,b.x,c.x)),
dot(gl_TessCoord.xyz, vec3(a.y,b.y,c.y)),
dot(gl_TessCoord.xyz, vec3(a.z,b.z,c.z)),
dot(gl_TessCoord.xyz, vec3(a.w,b.w,c.w)));
}
vec3 vp_Normal;
// simplest possible pass-though:
void generateVertex()
{
VP_Interpolate3();
// Must re-normalize the normal vector since interpolation was linear?
vp_Normal = normalize(vp_Normal);
VP_EmitVertex();
}
]]></code>
</terrainshader>
<viewpoints>
<viewpoint name="San Francisco" heading="8.806974516644791" height="4465.397310772911" lat="37.55814749233749" long="-122.334535784141" pitch="-34.79540299384382" range="78142.53643278375" srs="+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs " />
<viewpoint name="Mt R. Nadir 30K" heading="0.5013023037097585" height="4101.627114404924" lat="46.85909894548915" long="-121.7598368518208" pitch="-89.43249895879129" range="29029.34246828893"/>
<viewpoint name="Mt R. Oblique 30K" heading="17.33521725357022" height="2462.60273069609" lat="46.82181702111031" long="-121.7814936386096" pitch="-21.29241356548601" range="23926.75258864516"/>
<viewpoint name="Mt R. Closeup" heading="-109.6842970297122" height="3843.486737414263" lat="46.85528453766688" long="-121.7455004166102" pitch="-4.617466338845979" range="951.4780720092711"/>
<viewpoint name="Mt R. Trees" heading="-98.36122712710565" height="1639.304918398149" lat="46.78673277044066" long="-121.743286318636" pitch="-10.85365380742088" range="257.5853045645545"/>
<viewpoint name="Nepal" heading="-72.70835146844568" height="6334.845537136309" lat="27.94213038800919" long="86.9936567556778" pitch="-18.63803872963365" range="13611.24948464565"/>
<viewpoint name="Nepal NF" heading="-49.14546953546358" height="6334.332569343038" lat="27.9421778947837" long="86.9935949004298" pitch="-3.643325527310435" range="13302.81192964212"/>
<viewpoint name="Matterhorn" heading="-1.429462844200832" height="2282.858508689329" lat="45.95106319557" long="7.642741711675961" pitch="-25.12269405854052" range="26690.10606054494"/>
</viewpoints>
</extensions>
</map>