This is not about generating plane geometry and then applying a shader on it. Instead, I want a big single flat plane, then apply a shader on it.
The vertex shader has a uniform vec3 realPlanePosition
and calls a height calculation function:
// Vertex shader code
uniform vec3 realPlanePosition;
varying vPosition;
float heightCalculation(vec2 verticePosition) {
// Just for pseudo-code (more black magic append here).
return magicNoise2D(verticePosition.x, verticePosition.y);
}
void main(void) {
vec3 vPosition = position;
vec2 verticePosition = vec2(vPosition.x + realPlanePosition.x,
vPosition.y - realPlanePosition.z);
vPosition.z = heightCalculation(verticePosition);
gl_Position = projectionMatrix * modelViewMatrix * vec4(vPosition, 1.0);
}
In my plane update code, I just change realPlanePosition
with player position, for example. The plane moves on (x, z) (X rotation: -PI/2.0)
. The only thing the vertex shader updates is the z (due to plane rotation)
value of gl_Position
.
Is this good practice? Also, how do I detect collisions with it? And finally, how can I control other terrain objects' generation (rocks, trees, ...)