Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 886 vs 887 for /trunk/assets/shaders/GLSL/terrainTess.glsl

Diff revisions: vs.
  @@ -26,7 +26,7 @@
26 26
27 27 vec4 patchPosition = vec4(dvd_Vertex.xyz * posAndScale.w, 1.0);
28 28
29 - VAR._vertexW = dvd_WorldMatrix(VAR.dvd_instanceID) * vec4(patchPosition + vec4(posAndScale.xyz, 0.0));
29 + VAR._vertexW = /*dvd_WorldMatrix(VAR.dvd_instanceID) * */vec4(patchPosition + vec4(posAndScale.xyz, 0.0));
30 30
31 31 // Calcuate texture coordantes (u,v) relative to entire terrain
32 32 VAR._texCoord = calcTerrainTexCoord(VAR._vertexW);
  @@ -258,15 +258,36 @@
258 258 return mix(a, b, gl_TessCoord.y);
259 259 }
260 260
261 - vec3 getNormal(in float sampleHeight, in vec2 tex_coord) {
262 - const vec2 size = vec2(2.0, 0.0);
261 + vec4 getHeightOffsets(in vec2 tex_coord) {
263 262 const ivec3 off = ivec3(-1, 0, 1);
264 263
265 - float s11 = TERRAIN_MIN_HEIGHT + TERRAIN_HEIGHT_RANGE * sampleHeight;
266 - float s01 = TERRAIN_MIN_HEIGHT + TERRAIN_HEIGHT_RANGE * textureOffset(TexTerrainHeight, tex_coord, off.xy).x;
267 - float s21 = TERRAIN_MIN_HEIGHT + TERRAIN_HEIGHT_RANGE * textureOffset(TexTerrainHeight, tex_coord, off.zy).x;
268 - float s10 = TERRAIN_MIN_HEIGHT + TERRAIN_HEIGHT_RANGE * textureOffset(TexTerrainHeight, tex_coord, off.yx).x;
269 - float s12 = TERRAIN_MIN_HEIGHT + TERRAIN_HEIGHT_RANGE * textureOffset(TexTerrainHeight, tex_coord, off.yz).x;
264 + float s01 = textureOffset(TexTerrainHeight, tex_coord, off.xy).r;
265 + float s21 = textureOffset(TexTerrainHeight, tex_coord, off.zy).r;
266 + float s10 = textureOffset(TexTerrainHeight, tex_coord, off.yx).r;
267 + float s12 = textureOffset(TexTerrainHeight, tex_coord, off.yz).r;
268 +
269 + return vec4(s01, s21, s10, s12);
270 + }
271 +
272 + float getHeight(in vec4 heightOffsets) {
273 +
274 + float s01 = heightOffsets.r;
275 + float s21 = heightOffsets.g;
276 + float s10 = heightOffsets.b;
277 + float s12 = heightOffsets.a;
278 +
279 + return (s01 + s21 + s10 + s12) * 0.25;
280 + }
281 +
282 + vec3 getNormal(in float sampleHeight, in vec4 heightOffsets) {
283 + const vec2 size = vec2(2.0, 0.0);
284 +
285 + float s11 = sampleHeight;
286 + float s01 = heightOffsets.r;
287 + float s21 = heightOffsets.g;
288 + float s10 = heightOffsets.b;
289 + float s12 = heightOffsets.a;
290 +
270 291 vec3 va = normalize(vec3(size.xy, s21 - s01));
271 292 vec3 vb = normalize(vec3(size.yx, s12 - s10));
272 293
  @@ -290,8 +311,11 @@
290 311 // Terrain heightmap coords
291 312 vec2 terrainTexCoord = interpolate2(VAR[0]._texCoord, VAR[1]._texCoord, VAR[2]._texCoord, VAR[3]._texCoord);
292 313
314 +
315 + vec4 heightOffsets = getHeightOffsets(terrainTexCoord);
316 +
293 317 // Sample the heightmap and offset y position of vertex
294 - float sampleHeight = texture(TexTerrainHeight, terrainTexCoord).r;
318 + float sampleHeight = getHeight(heightOffsets);
295 319 gl_Position.y = TERRAIN_MIN_HEIGHT + TERRAIN_HEIGHT_RANGE * sampleHeight;
296 320
297 321 // Project the vertex to clip space and send it along
  @@ -301,7 +325,7 @@
301 325 #if !defined(SHADOW_PASS)
302 326 _out._vertexW = dvd_WorldMatrix(VAR[0].dvd_instanceID) * _out._vertexW;
303 327 mat3 normalMatrix = dvd_NormalMatrixWV(VAR[0].dvd_instanceID);
304 - vec3 normal = getNormal(sampleHeight, terrainTexCoord);
328 + vec3 normal = getNormal(sampleHeight, heightOffsets);
305 329 _out._normalWV = normalize(normalMatrix * normal);
306 330 _out._tangentWV = normalize(normalMatrix * getTangent(normal));
307 331 _out._bitangentWV = normalize(cross(_out._normalWV, _out._tangentWV));
  @@ -564,6 +588,7 @@
564 588
565 589 vec4 TerrainMappingRoutine() {
566 590 setAlbedo(getTerrainAlbedo());
591 +
567 592 return getAlbedo();//getPixelColour(VAR._texCoord);
568 593 }
569 594