Tess
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// tessellation evaluation shader
|
||||
#version 450 core
|
||||
|
||||
layout (quads, equal_spacing, ccw) in;
|
||||
layout (quads, fractional_even_spacing, ccw) in;
|
||||
|
||||
layout(std430, binding = 1) readonly buffer positions_buffer
|
||||
{
|
||||
@@ -67,6 +67,8 @@ void main()
|
||||
vec4 p10 = gl_in[2].gl_Position;
|
||||
vec4 p11 = gl_in[3].gl_Position;
|
||||
|
||||
|
||||
|
||||
// compute patch surface normal
|
||||
vec4 uVec = p01 - p00;
|
||||
vec4 vVec = p10 - p00;
|
||||
@@ -90,4 +92,7 @@ void main()
|
||||
mat4 view = ubo_per_frame.view;
|
||||
mat4 proj = ubo_per_frame.proj;
|
||||
gl_Position = proj * view * model * p;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -44,7 +44,7 @@ void main()
|
||||
mat4 view = ubo_per_frame.view;
|
||||
mat4 proj = ubo_per_frame.proj;
|
||||
//model = mat4(1);
|
||||
gl_Position = proj * view * model * vec4(inPos, 1.0);
|
||||
gl_Position = vec4(inPos, 1.0);// proj * view * model * vec4(inPos, 1.0);
|
||||
vs_out.vsWorldPos = model * vec4(inPos,1);
|
||||
|
||||
vs_out.vsNormal = normalize(vec3(model * vec4(normalize(inNormal),0)));
|
||||
|
||||
Reference in New Issue
Block a user