From 1a1d603c7618bc201d64c7f2342e3e241f5a10d9 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Thu, 6 Dec 2018 11:22:55 +0100 Subject: [PATCH] finite differences test --- exercise2/glsl/terrain.vert | 16 ++++++++++++++++ exercise2/src/Viewer.cpp | 13 +++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/exercise2/glsl/terrain.vert b/exercise2/glsl/terrain.vert index 2db7089..1e4a7f0 100644 --- a/exercise2/glsl/terrain.vert +++ b/exercise2/glsl/terrain.vert @@ -31,6 +31,22 @@ void main() { vec2 instanced_pos = vec2(position.x + offset.x, position.z + offset.y); vec4 terrain_position = vec4(instanced_pos.x, getTerrainHeight(instanced_pos), instanced_pos.y, position.w); + + /* + // read neightbor heights using an arbitrary small offset + vec3 off = vec3(1.0, 1.0, 0.0); + float hL = getTerrainHeight(position.xz - off.xz); + float hR = getTerrainHeight(position.xz + off.xz); + float hD = getTerrainHeight(position.xz - off.zy); + float hU = getTerrainHeight(position.xz + off.zy); + + // deduce terrain normal + n.x = hL - hR; + n.y = hD - hU; + n.z = 2.0; + n = normalize(n); + */ + n = calculate_normal(terrain_position); //n = vec3(0.0, 1.0, 0.0); diff --git a/exercise2/src/Viewer.cpp b/exercise2/src/Viewer.cpp index 00b6823..2347429 100644 --- a/exercise2/src/Viewer.cpp +++ b/exercise2/src/Viewer.cpp @@ -53,7 +53,7 @@ Viewer::Viewer() for (int j = -max_offset; j < max_offset; j++) for (int i = -max_offset; i < max_offset; i++) { - offsets.emplace_back((float)(i * PATCH_SIZE), (float)(j * PATCH_SIZE)); + offsets.emplace_back((float)(i * (int32_t)PATCH_SIZE), (float)(j * (int32_t)PATCH_SIZE)); } } @@ -352,9 +352,18 @@ void Viewer::drawContents() glEnable(GL_DEPTH_TEST); terrainVAO.bind(); + /* + for (auto &i : instances) + { + std::cout << i.x() << " " << i.y() << std::endl; + } + + abort(); + */ + offsetBuffer.bind(); offsetBuffer.uploadData(instances); - glVertexAttribDivisor(offset_buffer_location, instances.size()); + glVertexAttribDivisor(offset_buffer_location, 1); terrainShader.bind();