Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 881 vs 882 for /trunk/assets/shaders/GLSL/terrainTess.glsl

Diff revisions: vs.
  @@ -16,8 +16,6 @@
16 16 TerrainNodeData dvd_TerrainData[];
17 17 };
18 18
19 - float tileScale = 0.0;
20 -
21 19 vec2 calcTerrainTexCoord(in vec4 pos)
22 20 {
23 21 return vec2(abs(pos.x - TerrainOrigin.x) / TerrainWidth, abs(pos.z - TerrainOrigin.z) / TerrainLength);
  @@ -28,12 +26,10 @@
28 26 computeData();
29 27
30 28 vec4 posAndScale = dvd_TerrainData[VAR.dvd_drawID]._positionAndTileScale;
31 - tileScale = posAndScale.w;
32 - vec4 offset = vec4(posAndScale.xyz, 0.0);
33 29
34 - vec4 patchPosition = vec4(dvd_Vertex.xyz * tileScale, 1.0);
30 + vec4 patchPosition = vec4(dvd_Vertex.xyz * posAndScale.w, 1.0);
35 31
36 - vec4 p = dvd_WorldMatrix(VAR.dvd_instanceID) * (patchPosition + offset);
32 + vec4 p = dvd_WorldMatrix(VAR.dvd_instanceID) * vec4(patchPosition + vec4(posAndScale.xyz, 0.0));
37 33
38 34 // Calcuate texture coordantes (u,v) relative to entire terrain
39 35 VAR._texCoord = calcTerrainTexCoord(p);
  @@ -48,7 +44,8 @@
48 44
49 45 layout(binding = TEXTURE_OPACITY) uniform sampler2D TexTerrainHeight;
50 46
51 - uniform float TerrainHeightOffset = 2000.0f;
47 + uniform float MinHeight;
48 + uniform float HeightRange;
52 49
53 50 struct TerrainNodeData {
54 51 vec4 _positionAndTileScale;
  @@ -60,12 +57,6 @@
60 57 TerrainNodeData dvd_TerrainData[];
61 58 };
62 59
63 -
64 - float tscale_negx = 0.0;
65 - float tscale_negz = 0.0;
66 - float tscale_posx = 0.0;
67 - float tscale_posz = 0.0;
68 -
69 60 //
70 61 // Outputs
71 62 //
  @@ -74,7 +65,6 @@
74 65 patch out float gl_TessLevelOuter[4];
75 66 patch out float gl_TessLevelInner[2];
76 67
77 - out vec2 tcs_terrainTexCoord[];
78 68 out float tcs_tessLevel[];
79 69
80 70 /**
  @@ -82,10 +72,10 @@
82 72 */
83 73 float dlodCameraDistance(vec4 p0, vec4 p1, vec2 t0, vec2 t1)
84 74 {
85 - vec4 samp = texture(TexTerrainHeight, t0);
86 - p0.y = samp[0] * TerrainHeightOffset;
87 - samp = texture(TexTerrainHeight, t1);
88 - p1.y = samp[0] * TerrainHeightOffset;
75 + float sampleHeight = texture(TexTerrainHeight, t0).r;
76 + p0.y = MinHeight + HeightRange * sampleHeight;
77 + sampleHeight = texture(TexTerrainHeight, t1).r;
78 + p1.y = MinHeight + HeightRange * sampleHeight;
89 79
90 80 mat4 mvMatrix = dvd_WorldViewMatrix(VAR.dvd_instanceID);
91 81
  @@ -133,10 +123,10 @@
133 123 {
134 124 float g_tessellatedTriWidth = 10.0;
135 125
136 - vec4 samp = texture(TexTerrainHeight, t0);
137 - p0.y = samp[0] * TerrainHeightOffset;
138 - samp = texture(TexTerrainHeight, t1);
139 - p1.y = samp[0] * TerrainHeightOffset;
126 + float sampleHeight = texture(TexTerrainHeight, t0).r;
127 + p0.y = MinHeight + HeightRange * sampleHeight;
128 + sampleHeight = texture(TexTerrainHeight, t1).r;
129 + p1.y = MinHeight + HeightRange * sampleHeight;
140 130
141 131
142 132 mat4 mvMatrix = dvd_WorldViewMatrix(VAR.dvd_instanceID);
  @@ -189,25 +179,32 @@
189 179
190 180 void main(void)
191 181 {
192 - tscale_negx = dvd_TerrainData[VAR.dvd_drawID]._tScale.x;
193 - tscale_negz = dvd_TerrainData[VAR.dvd_drawID]._tScale.y;
194 - tscale_posx = dvd_TerrainData[VAR.dvd_drawID]._tScale.z;
195 - tscale_posz = dvd_TerrainData[VAR.dvd_drawID]._tScale.w;
196 -
197 182 // Outer tessellation level
198 - gl_TessLevelOuter[0] = dlodCameraDistance(gl_in[3].gl_Position, gl_in[0].gl_Position, tcs_terrainTexCoord[3], tcs_terrainTexCoord[0]);
199 - gl_TessLevelOuter[1] = dlodCameraDistance(gl_in[0].gl_Position, gl_in[1].gl_Position, tcs_terrainTexCoord[0], tcs_terrainTexCoord[1]);
200 - gl_TessLevelOuter[2] = dlodCameraDistance(gl_in[1].gl_Position, gl_in[2].gl_Position, tcs_terrainTexCoord[1], tcs_terrainTexCoord[2]);
201 - gl_TessLevelOuter[3] = dlodCameraDistance(gl_in[2].gl_Position, gl_in[3].gl_Position, tcs_terrainTexCoord[2], tcs_terrainTexCoord[3]);
183 + gl_TessLevelOuter[0] = dlodCameraDistance(gl_in[3].gl_Position, gl_in[0].gl_Position, _in[3]._texCoord, _in[0]._texCoord);
184 + gl_TessLevelOuter[1] = dlodCameraDistance(gl_in[0].gl_Position, gl_in[1].gl_Position, _in[0]._texCoord, _in[1]._texCoord);
185 + gl_TessLevelOuter[2] = dlodCameraDistance(gl_in[1].gl_Position, gl_in[2].gl_Position, _in[1]._texCoord, _in[2]._texCoord);
186 + gl_TessLevelOuter[3] = dlodCameraDistance(gl_in[2].gl_Position, gl_in[3].gl_Position, _in[2]._texCoord, _in[3]._texCoord);
187 +
188 + float tscale_negx = dvd_TerrainData[VAR.dvd_drawID]._tScale.x;
189 + float tscale_negz = dvd_TerrainData[VAR.dvd_drawID]._tScale.y;
190 + float tscale_posx = dvd_TerrainData[VAR.dvd_drawID]._tScale.z;
191 + float tscale_posz = dvd_TerrainData[VAR.dvd_drawID]._tScale.w;
202 192
203 - if (tscale_negx == 2.0)
193 + if (tscale_negx == 2.0) {
204 194 gl_TessLevelOuter[0] = max(2.0, gl_TessLevelOuter[0] * 0.5);
205 - if (tscale_negz == 2.0)
195 + }
196 +
197 + if (tscale_negz == 2.0) {
206 198 gl_TessLevelOuter[1] = max(2.0, gl_TessLevelOuter[1] * 0.5);
207 - if (tscale_posx == 2.0)
199 + }
200 +
201 + if (tscale_posx == 2.0) {
208 202 gl_TessLevelOuter[2] = max(2.0, gl_TessLevelOuter[2] * 0.5);
209 - if (tscale_posz == 2.0)
203 + }
204 +
205 + if (tscale_posz == 2.0) {
210 206 gl_TessLevelOuter[3] = max(2.0, gl_TessLevelOuter[3] * 0.5);
207 + }
211 208
212 209 // Inner tessellation level
213 210 gl_TessLevelInner[0] = 0.5 * (gl_TessLevelOuter[0] + gl_TessLevelOuter[3]);
  @@ -238,8 +235,8 @@
238 235 TerrainNodeData dvd_TerrainData[];
239 236 };
240 237
241 -
242 - uniform float TerrainHeightOffset = 2000.0;
238 + uniform float MinHeight;
239 + uniform float HeightRange;
243 240
244 241 //
245 242 // Inputs
  @@ -277,8 +274,8 @@
277 274 vec2 terrainTexCoord = interpolate2(VAR[0]._texCoord, VAR[1]._texCoord, VAR[2]._texCoord, VAR[3]._texCoord);
278 275
279 276 // Sample the heightmap and offset y position of vertex
280 - vec4 samp = texture(TexTerrainHeight, terrainTexCoord);
281 - gl_Position.y = samp[0] * TerrainHeightOffset;
277 + float sampleHeight = texture(TexTerrainHeight, terrainTexCoord).r;
278 + gl_Position.y = MinHeight + HeightRange * sampleHeight;
282 279
283 280 // Project the vertex to clip space and send it along
284 281 vec3 offset = dvd_TerrainData[VAR[0].dvd_drawID]._positionAndTileScale.xyz;
  @@ -360,10 +357,10 @@
360 357 EmitVertex();
361 358 }
362 359
360 + PassData(0);
363 361 // This closes the the triangle
364 362 gl_Position = gl_in[0].gl_Position;
365 363 gs_edgeDist = vec3(ha, 0, 0);
366 - _out._texCoord = VAR[0]._texCoord;
367 364
368 365 gs_wireColor = wireColor;
369 366 EmitVertex();
  @@ -383,11 +380,11 @@
383 380 TerrainNodeData dvd_TerrainData[];
384 381 };
385 382
386 - float tileScale = dvd_TerrainData[VAR.dvd_drawID]._positionAndTileScale.w;
383 + float tileScale = 0.0;
387 384
388 385 uniform float ToggleWireframe = 1.0;
389 386
390 - layout(binding = TEXTURE_OPACITY) uniform sampler2D TexTerrainHeight;
387 + layout(binding = TEXTURE_OPACITY) uniform sampler2D TexTerrainHeight;
391 388
392 389 //
393 390 // Inputs
  @@ -404,8 +401,10 @@
404 401
405 402 void main(void)
406 403 {
407 - //vec4 color = vec4(mix(0.0, 1.0, tileScale / 1000.0), mix(1.0, 0.0, tileScale / 1000.0), 0.0, 1.0);
408 - vec4 color = vec4(1.0, 0.0, 0.0, 1.0);// texture(TexTerrainHeight, VAR._texCoord);
404 + tileScale = dvd_TerrainData[VAR.dvd_drawID]._positionAndTileScale.w;
405 +
406 + vec4 color = vec4(mix(0.0, 1.0, tileScale / 1000.0), mix(1.0, 0.0, tileScale / 1000.0), 0.0, 1.0);
407 + //vec4 color = vec4(0.0, 0.4, 0.0, 1.0);// texture(TexTerrainHeight, VAR._texCoord);
409 408
410 409 // Wireframe junk
411 410 float d = min(gs_edgeDist.x, gs_edgeDist.y);
  @@ -414,8 +413,9 @@
414 413 float LineWidth = 0.75;
415 414 float mixVal = smoothstep(LineWidth - 1, LineWidth + 1, d);
416 415
417 - if (ToggleWireframe == 1.0)
416 + if (ToggleWireframe == 1.0) {
418 417 _colourOut = mix(gs_wireColor, color, mixVal);
419 - else
418 + } else {
420 419 _colourOut = color;
420 + }
421 421 }