This commit is contained in:
Confideo-IOM
2026-09-29 12:52:37 +01:00
parent 7a1eaa3654
commit def7bbffee
46 changed files with 1492 additions and 561 deletions
@@ -5,6 +5,14 @@
// this value controls the size of the input and output arrays
layout (vertices=4) out;
layout(binding = 0) uniform uniform_per_frame
{
mat4 view;
mat4 proj;
vec3 viewer_pos;
uint light_count;
} ubo_per_frame;
layout (location=0) in VS_OUT
{
vec2 vsUV;
@@ -29,6 +37,11 @@ layout (location=0) out TC_OUT
flat uint vsMaterialID;
}tc_out[];
float inv_lerp (float a, float b, float t)
{
return (t - a) / (b - a);
}
void main()
{
@@ -44,17 +57,31 @@ void main()
tc_out[gl_InvocationID].vsChunkID = tc_in[gl_InvocationID].vsChunkID;
tc_out[gl_InvocationID].vsMaterialID = tc_in[gl_InvocationID].vsMaterialID;
vec3 centre = (gl_in[0].gl_Position.xyz +
gl_in[1].gl_Position.xyz +
gl_in[2].gl_Position.xyz +
gl_in[3].gl_Position.xyz) / 4.0;
float patch_width = abs(length(gl_in[2].gl_Position.xyz - gl_in[0].gl_Position.xyz));
float player_dist = abs(length(centre - ubo_per_frame.viewer_pos)) * 0.1;
float tess_factor = 1.0 - inv_lerp(0, patch_width, player_dist);
tess_factor = max(0.5, tess_factor);
// ----------------------------------------------------------------------
// invocation zero controls tessellation levels for the entire patch
if (gl_InvocationID == 0)
{
int divs = 63;
gl_TessLevelOuter[0] = divs;
gl_TessLevelOuter[1] = divs;
gl_TessLevelOuter[2] = divs;
gl_TessLevelOuter[3] = divs;
gl_TessLevelInner[0] = divs;
gl_TessLevelInner[1] = divs;
float edgedivs = 32.0;
float innerdivs = tess_factor * 64.0;
gl_TessLevelOuter[0] = edgedivs;
gl_TessLevelOuter[1] = edgedivs;
gl_TessLevelOuter[2] = edgedivs;
gl_TessLevelOuter[3] = edgedivs;
gl_TessLevelInner[0] = innerdivs;
gl_TessLevelInner[1] = innerdivs;
}
}