Render heightmap to layer

This commit is contained in:
2019-01-07 23:07:55 +01:00
parent 352511a920
commit 2b02be77dc
11 changed files with 145 additions and 116 deletions

View File

@@ -241,7 +241,7 @@ void Plane::create_impl(float w, float h, int div, GLushort *idx, vertex_t *vert
}
}
bool HeightmapPlane::create(float w, float h, const Image& img, float scale)
bool HeightmapPlane::create(float w, float h, const Image& img, float scale, float height)
{
Image img_tmp;
glm::u8vec4* px = (glm::u8vec4*)img.data();
@@ -286,6 +286,7 @@ bool HeightmapPlane::create(float w, float h, const Image& img, float scale)
}
// generate indices
const glm::vec3 yscale(1, 1, height);
for (int y = 0; y < div; y++)
{
int i = y * (div + 1);
@@ -297,8 +298,8 @@ bool HeightmapPlane::create(float w, float h, const Image& img, float scale)
*pi++ = i;
*pi++ = i + div + 2;
*pi++ = i + 1;
auto n = glm::triangleNormal(xyz(vertices[i].pos),
xyz(vertices[i + div + 1].pos), xyz(vertices[i + 1].pos));
auto n = glm::triangleNormal(xyz(vertices[i].pos) * yscale,
xyz(vertices[i + div + 1].pos) * yscale, xyz(vertices[i + 1].pos) * yscale);
vertices[i].nor += n;
vertices[i + 1].nor += n;
vertices[i + div + 1].nor += n;