finite differences test
This commit is contained in:
parent
bd0175fcda
commit
1a1d603c76
2 changed files with 27 additions and 2 deletions
|
@ -31,6 +31,22 @@ void main()
|
||||||
{
|
{
|
||||||
vec2 instanced_pos = vec2(position.x + offset.x, position.z + offset.y);
|
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);
|
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 = calculate_normal(terrain_position);
|
||||||
//n = vec3(0.0, 1.0, 0.0);
|
//n = vec3(0.0, 1.0, 0.0);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ Viewer::Viewer()
|
||||||
for (int j = -max_offset; j < max_offset; j++)
|
for (int j = -max_offset; j < max_offset; j++)
|
||||||
for (int i = -max_offset; i < max_offset; i++)
|
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);
|
glEnable(GL_DEPTH_TEST);
|
||||||
terrainVAO.bind();
|
terrainVAO.bind();
|
||||||
|
|
||||||
|
/*
|
||||||
|
for (auto &i : instances)
|
||||||
|
{
|
||||||
|
std::cout << i.x() << " " << i.y() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
abort();
|
||||||
|
*/
|
||||||
|
|
||||||
offsetBuffer.bind();
|
offsetBuffer.bind();
|
||||||
offsetBuffer.uploadData(instances);
|
offsetBuffer.uploadData(instances);
|
||||||
glVertexAttribDivisor(offset_buffer_location, instances.size());
|
glVertexAttribDivisor(offset_buffer_location, 1);
|
||||||
|
|
||||||
terrainShader.bind();
|
terrainShader.bind();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue