Render heightmap to layer
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user