heightmap
Defines the geometry of a height map. FN specifies the function that computes the height (Z) for a given X, Y. COLS and ROWS specify the number of columns and rows of the height map. Use HEIGHTMAP_PRIMITIVES vertex configuration with HEIGHTMAP_VERTEX_COUNT(COLS, ROWS) vertices.
Get the coordinate of vertex i
template <FN, COLS, ROWS>
vec3 heightmapCoord(int i);
Get the normal vector of vertex i
template <FN, COLS, ROWS>
vec3 heightmapNormal(int i);
Get the texture coordinate of vertex i
template <FN, COLS, ROWS>
vec2 heightmapTexCoord(int i);
The heightmapVertex<FN, COLS, ROWS> function can be used directly as the vertex shader if no coordinate transformation is needed.
Example
float heightFunction(vec2 position) {
return texture(HeightMapImage, position).r;
}
vec4 vertexShader(out vec3 normal, int index) {
vec3 coord = heightmapCoord<heightFunction, 256, 256>(index);
normal = heightmapNormal<heightFunction, 256, 256>(index);
coord = transformCoord(coord);
normal = transformNormal(normal);
return projectCoord(coord);
}
vec4 fragmentShader(in vec3 normal) {
return computeLighting(normal);
}
model HeightMapModel :
fragment_data(vec3),
vertex(vertexShader, HEIGHTMAP_PRIMITIVES, HEIGHTMAP_VERTEX_COUNT(256, 256)),
fragment(fragmentShader);