// tessellation evaluation shader #version 450 core layout (quads, fractional_even_spacing, ccw) in; layout(std430, binding = 1) readonly buffer positions_buffer { mat4 model_matrix[]; }; layout(binding = 0) uniform uniform_per_frame { mat4 view; mat4 proj; vec3 viewer_pos; uint light_count; } ubo_per_frame; // received from Tessellation Control Shader - all texture coordinates for the patch vertices // varying input from vertex shader layout (location=0) in TC_OUT { vec2 vsUV; vec4 vsWorldPos; vec3 vsNormal; vec3 vsBiTangent; vec3 vsTangent; mat3 vsTBN; flat uint vsChunkID; flat uint vsMaterialID; }te_in[]; layout (location=0) out TE_OUT { vec2 vsUV; vec4 vsWorldPos; vec3 vsNormal; vec3 vsBiTangent; vec3 vsTangent; mat3 vsTBN; flat uint vsChunkID; flat uint vsMaterialID; }te_out; void main() { // get patch coordinate te_out.vsUV.x = gl_TessCoord.x; te_out.vsUV.y = gl_TessCoord.y; // ---------------------------------------------------------------------- // retrieve control point texture coordinates vec2 t00 = te_in[0].vsUV; vec2 t01 = te_in[1].vsUV; vec2 t10 = te_in[2].vsUV; vec2 t11 = te_in[3].vsUV; // t00|t10 // ------- // t10|t11 // ---------------------------------------------------------------------- // retrieve control point position coordinates vec4 p00 = gl_in[0].gl_Position; vec4 p01 = gl_in[1].gl_Position; 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; vec4 normal = normalize( vec4(cross(uVec.xyz, vVec.xyz), 1)); te_out.vsNormal = normal.xyz; // bilinearly interpolate position coordinate across patch vec4 p0 = (p01 - p00) * te_out.vsUV.x + p00; vec4 p1 = (p11 - p10) * te_out.vsUV.x + p10; vec4 p = (p1 - p0) * te_out.vsUV.y + p0; // displace point along normal // p += -normal * height; //height = 0; //p[3] = 1; // ---------------------------------------------------------------------- // output patch point position in clip space mat4 model = model_matrix[te_in[0].vsChunkID]; mat4 view = ubo_per_frame.view; mat4 proj = ubo_per_frame.proj; gl_Position = proj * view * model * p; }