tessalation started

This commit is contained in:
Confideo-IOM
2026-09-28 15:31:22 +01:00
parent 6e1a531f94
commit 7a1eaa3654
24 changed files with 384 additions and 24 deletions
@@ -0,0 +1,79 @@
//*PIXEL*
#version 460 core
#extension GL_ARB_bindless_texture : require
uint INVALID_HYDRA_ID = 4294967295;
struct MaterialStore
{
vec4 diffuse_colour;
vec4 matalic_rough;
uint diffuse_texture_id;
uint metallic_rough_texture_id;
uint normal_texture_id;
uint padding[1];
};
layout(binding = 2, std430) readonly buffer material_buffer
{
MaterialStore materials[1000];
};
layout( std430, binding = 3) readonly buffer texture_buffer {
uvec2 textures[1000];
};
layout (location=0) in TE_OUT
{
vec2 vsUV;
vec4 vsWorldPos;
vec3 vsNormal;
vec3 vsBiTangent;
vec3 vsTangent;
mat3 vsTBN;
flat uint vsChunkID;
flat uint vsMaterialID;
}vs_out;
layout (location=0) out vec4 diffuse_out;
layout (location=1) out vec4 metalic_rough_out;
layout (location=2) out vec4 normal_out;
layout (location=3) out vec4 position_out;
void main()
{
MaterialStore mat = materials[vs_out.vsMaterialID];
vec4 diffuse_val = mat.diffuse_colour;
vec4 mat_rough_val =mat.matalic_rough;
vec3 normal_val = vs_out.vsNormal;
if(mat.diffuse_texture_id != INVALID_HYDRA_ID)
{
uvec2 diffuse_handle = textures[mat.diffuse_texture_id];
diffuse_val = diffuse_val * texture(sampler2D(diffuse_handle), vs_out.vsUV.xy);
}
if(mat.metallic_rough_texture_id != INVALID_HYDRA_ID)
{
uvec2 metal_rough_handle = textures[mat.metallic_rough_texture_id];
mat_rough_val = texture(sampler2D(metal_rough_handle), vs_out.vsUV.xy);
}
if(mat.normal_texture_id != INVALID_HYDRA_ID)
{
uvec2 normal_handle = textures[mat.normal_texture_id];
normal_val = texture(sampler2D(normal_handle), vs_out.vsUV.xy).xyz;
normal_val = (normal_val * 2.0) - 1.0;
normal_val = normalize(vs_out.vsTBN * normal_val);
}
if(diffuse_val[3] <= 0.4)
{
discard;
}
diffuse_out = diffuse_val;
metalic_rough_out = mat_rough_val;
normal_out = vec4(normal_val,1);
position_out = vs_out.vsWorldPos;
}
@@ -0,0 +1,60 @@
// tessellation control shader
#version 450 core
// specify number of control points per patch output
// this value controls the size of the input and output arrays
layout (vertices=4) out;
layout (location=0) in VS_OUT
{
vec2 vsUV;
vec4 vsWorldPos;
vec3 vsNormal;
vec3 vsBiTangent;
vec3 vsTangent;
mat3 vsTBN;
flat uint vsChunkID;
flat uint vsMaterialID;
}tc_in[];
layout (location=0) out TC_OUT
{
vec2 vsUV;
vec4 vsWorldPos;
vec3 vsNormal;
vec3 vsBiTangent;
vec3 vsTangent;
mat3 vsTBN;
flat uint vsChunkID;
flat uint vsMaterialID;
}tc_out[];
void main()
{
// ----------------------------------------------------------------------
// pass attributes through
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
tc_out[gl_InvocationID].vsUV = tc_in[gl_InvocationID].vsUV;
tc_out[gl_InvocationID].vsWorldPos = tc_in[gl_InvocationID].vsWorldPos;
tc_out[gl_InvocationID].vsNormal = tc_in[gl_InvocationID].vsNormal;
tc_out[gl_InvocationID].vsBiTangent = tc_in[gl_InvocationID].vsBiTangent;
tc_out[gl_InvocationID].vsTangent = tc_in[gl_InvocationID].vsTangent;
tc_out[gl_InvocationID].vsTBN = tc_in[gl_InvocationID].vsTBN;
tc_out[gl_InvocationID].vsChunkID = tc_in[gl_InvocationID].vsChunkID;
tc_out[gl_InvocationID].vsMaterialID = tc_in[gl_InvocationID].vsMaterialID;
// ----------------------------------------------------------------------
// 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;
}
}
@@ -0,0 +1,93 @@
// tessellation evaluation shader
#version 450 core
layout (quads, equal_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;
}
@@ -0,0 +1,59 @@
#version 460 core
#extension GL_ARB_bindless_texture : require
layout(binding = 0) uniform uniform_per_frame
{
mat4 view;
mat4 proj;
vec3 viewer_pos;
uint light_count;
} ubo_per_frame;
layout(std430, binding = 1) readonly buffer positions_buffer
{
mat4 model_matrix[];
};
layout (location = 0) in vec3 inPos; //12 bytes : 0
layout (location = 1) in vec2 inUV; //8 Bytes : 12
layout (location = 2) in uvec3 inChunkID; //12 Bytes : 20
layout (location = 3) in vec3 inNormal; //8 Bytes : 12
layout (location = 4) in vec3 inBiTangent;
layout (location = 5) in vec3 inTangent;
layout(location=0) out VS_OUT
{
vec2 vsUV;
vec4 vsWorldPos;
vec3 vsNormal;
vec3 vsBiTangent;
vec3 vsTangent;
mat3 vsTBN;
flat uint vsChunkID;
flat uint vsMaterialID;
}vs_out;
out vec2 vertUV_out;
out ivec4 vertEdges_out;
out int vertChild_out;
void main()
{
uint chunkid = inChunkID[0];
mat4 model = model_matrix[chunkid];
mat4 view = ubo_per_frame.view;
mat4 proj = ubo_per_frame.proj;
//model = mat4(1);
gl_Position = proj * view * model * vec4(inPos, 1.0);
vs_out.vsWorldPos = model * vec4(inPos,1);
vs_out.vsNormal = normalize(vec3(model * vec4(normalize(inNormal),0)));
vs_out.vsTangent = normalize(vec3(model *vec4(inTangent,0))) ;
vs_out.vsBiTangent = normalize(vec3(model *vec4(inBiTangent,0)));
vs_out.vsTBN = mat3(vs_out.vsTangent, vs_out.vsBiTangent, vs_out.vsNormal);
vs_out.vsUV = inUV;
vs_out.vsChunkID = chunkid;
vs_out.vsMaterialID = inChunkID[1];
}