To create a shader program that varies the tessellation level based on the depth, use the following steps:
- Use the vertex shader and tessellation evaluation shader from the Tessellating a 3D surface recipe.
- Use the following code for the tessellation control shader:
layout( vertices=16 ) out; uniform int MinTessLevel; uniform int MaxTessLevel; uniform float MaxDepth; uniform float MinDepth; uniform mat4 ModelViewMatrix; void main() { // Position in camera coordinates vec4 p = ModelViewMatrix * gl_in[gl_InvocationID].gl_Position; // "Distance" from camera scaled between 0 and 1 float depth = clamp( (abs(p.z) - MinDepth) / (MaxDepth - MinDepth), 0.0, 1.0 ); // Interpolate between min/max tess levels float tessLevel = mix(MaxTessLevel, ...