2016-03-02 17:09:16 +00:00
|
|
|
#version 310 es
|
|
|
|
#extension GL_EXT_tessellation_shader : require
|
|
|
|
layout(vertices = 1) out;
|
|
|
|
|
|
|
|
layout(std140) uniform UBO
|
|
|
|
{
|
|
|
|
vec4 uScale;
|
|
|
|
vec3 uCamPos;
|
|
|
|
vec2 uPatchSize;
|
|
|
|
vec2 uMaxTessLevel;
|
|
|
|
float uDistanceMod;
|
|
|
|
vec4 uFrustum[6];
|
|
|
|
} _41;
|
|
|
|
|
2017-06-21 07:39:08 +00:00
|
|
|
layout(location = 1) patch out vec2 vOutPatchPosBase;
|
|
|
|
layout(location = 2) patch out vec4 vPatchLods;
|
2018-01-04 15:22:44 +00:00
|
|
|
layout(location = 0) in vec2 vPatchPosBase[];
|
2016-03-02 17:09:16 +00:00
|
|
|
|
|
|
|
bool frustum_cull(vec2 p0)
|
|
|
|
{
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 min_xz = (p0 - vec2(10.0)) * _41.uScale.xy;
|
|
|
|
vec2 max_xz = ((p0 + _41.uPatchSize) + vec2(10.0)) * _41.uScale.xy;
|
2016-03-12 13:17:19 +00:00
|
|
|
vec3 bb_min = vec3(min_xz.x, -10.0, min_xz.y);
|
|
|
|
vec3 bb_max = vec3(max_xz.x, 10.0, max_xz.y);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec3 center = (bb_min + bb_max) * 0.5;
|
|
|
|
float radius = 0.5 * length(bb_max - bb_min);
|
2016-03-12 13:17:19 +00:00
|
|
|
vec3 f0 = vec3(dot(_41.uFrustum[0], vec4(center, 1.0)), dot(_41.uFrustum[1], vec4(center, 1.0)), dot(_41.uFrustum[2], vec4(center, 1.0)));
|
|
|
|
vec3 f1 = vec3(dot(_41.uFrustum[3], vec4(center, 1.0)), dot(_41.uFrustum[4], vec4(center, 1.0)), dot(_41.uFrustum[5], vec4(center, 1.0)));
|
2018-01-18 11:07:10 +00:00
|
|
|
vec3 _199 = f0;
|
2018-03-09 12:21:38 +00:00
|
|
|
float _200 = radius;
|
|
|
|
bool _205 = any(lessThanEqual(_199, vec3(-_200)));
|
2016-03-02 17:09:16 +00:00
|
|
|
bool _215;
|
2016-12-05 09:22:54 +00:00
|
|
|
if (!_205)
|
2016-03-02 17:09:16 +00:00
|
|
|
{
|
2018-01-18 11:07:10 +00:00
|
|
|
_215 = any(lessThanEqual(f1, vec3(-radius)));
|
2016-03-02 17:09:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_215 = _205;
|
|
|
|
}
|
2016-12-05 09:22:54 +00:00
|
|
|
return !_215;
|
2016-03-02 17:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float lod_factor(vec2 pos_)
|
|
|
|
{
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 pos = pos_ * _41.uScale.xy;
|
|
|
|
vec3 dist_to_cam = _41.uCamPos - vec3(pos.x, 0.0, pos.y);
|
|
|
|
float level = log2((length(dist_to_cam) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod);
|
2016-03-12 13:17:19 +00:00
|
|
|
return clamp(level, 0.0, _41.uMaxTessLevel.x);
|
2016-03-02 17:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec4 tess_level(vec4 lod)
|
|
|
|
{
|
2016-12-05 09:22:54 +00:00
|
|
|
return exp2(-lod) * _41.uMaxTessLevel.y;
|
2016-03-02 17:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float tess_level(float lod)
|
|
|
|
{
|
2016-12-05 09:22:54 +00:00
|
|
|
return _41.uMaxTessLevel.y * exp2(-lod);
|
2016-03-02 17:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void compute_tess_levels(vec2 p0)
|
|
|
|
{
|
|
|
|
vOutPatchPosBase = p0;
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param = p0 + (vec2(-0.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l00 = lod_factor(param);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param_1 = p0 + (vec2(0.5, -0.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l10 = lod_factor(param_1);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param_2 = p0 + (vec2(1.5, -0.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l20 = lod_factor(param_2);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param_3 = p0 + (vec2(-0.5, 0.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l01 = lod_factor(param_3);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param_4 = p0 + (vec2(0.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l11 = lod_factor(param_4);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param_5 = p0 + (vec2(1.5, 0.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l21 = lod_factor(param_5);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param_6 = p0 + (vec2(-0.5, 1.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l02 = lod_factor(param_6);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param_7 = p0 + (vec2(0.5, 1.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l12 = lod_factor(param_7);
|
2016-12-05 09:22:54 +00:00
|
|
|
vec2 param_8 = p0 + (vec2(1.5) * _41.uPatchSize);
|
2016-03-02 17:09:16 +00:00
|
|
|
float l22 = lod_factor(param_8);
|
2016-03-12 13:17:19 +00:00
|
|
|
vec4 lods = vec4(dot(vec4(l01, l11, l02, l12), vec4(0.25)), dot(vec4(l00, l10, l01, l11), vec4(0.25)), dot(vec4(l10, l20, l11, l21), vec4(0.25)), dot(vec4(l11, l21, l12, l22), vec4(0.25)));
|
2016-03-02 17:09:16 +00:00
|
|
|
vPatchLods = lods;
|
|
|
|
vec4 outer_lods = min(lods, lods.yzwx);
|
|
|
|
vec4 param_9 = outer_lods;
|
|
|
|
vec4 levels = tess_level(param_9);
|
|
|
|
gl_TessLevelOuter[0] = levels.x;
|
|
|
|
gl_TessLevelOuter[1] = levels.y;
|
|
|
|
gl_TessLevelOuter[2] = levels.z;
|
|
|
|
gl_TessLevelOuter[3] = levels.w;
|
|
|
|
float min_lod = min(min(lods.x, lods.y), min(lods.z, lods.w));
|
|
|
|
float param_10 = min(min_lod, l11);
|
|
|
|
float inner = tess_level(param_10);
|
|
|
|
gl_TessLevelInner[0] = inner;
|
|
|
|
gl_TessLevelInner[1] = inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec2 p0 = vPatchPosBase[0];
|
|
|
|
vec2 param = p0;
|
2016-12-05 09:22:54 +00:00
|
|
|
if (!frustum_cull(param))
|
2016-03-02 17:09:16 +00:00
|
|
|
{
|
2016-03-12 13:17:19 +00:00
|
|
|
gl_TessLevelOuter[0] = -1.0;
|
|
|
|
gl_TessLevelOuter[1] = -1.0;
|
|
|
|
gl_TessLevelOuter[2] = -1.0;
|
|
|
|
gl_TessLevelOuter[3] = -1.0;
|
|
|
|
gl_TessLevelInner[0] = -1.0;
|
|
|
|
gl_TessLevelInner[1] = -1.0;
|
2016-03-02 17:09:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-17 21:15:07 +00:00
|
|
|
vec2 param_1 = p0;
|
2016-03-02 17:09:16 +00:00
|
|
|
compute_tess_levels(param_1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|