137 lines
3.7 KiB
GLSL
137 lines
3.7 KiB
GLSL
#version 450 core
|
|
|
|
layout(quads, fractional_even_spacing, cw) in;
|
|
|
|
in TC_OUT {
|
|
vec3 position;
|
|
vec2 texCoord;
|
|
} te_in[];
|
|
|
|
layout(location = 0) uniform mat4 M;
|
|
|
|
layout(std140, binding = 0) uniform SceneUniforms
|
|
{
|
|
mat4 PV; //camera projection * view matrix
|
|
vec4 eye_w; //world-space eye position
|
|
};
|
|
|
|
out vec3 fragPosition;
|
|
|
|
layout(binding = 0) uniform sampler2D heightTexture;
|
|
uniform float displacementScale = 0.1;
|
|
|
|
void main() {
|
|
// Interpolate texture coordinates
|
|
vec2 texCoord = mix(
|
|
mix(te_in[0].texCoord, te_in[1].texCoord, gl_TessCoord[0]),
|
|
mix(te_in[3].texCoord, te_in[2].texCoord, gl_TessCoord[0]),
|
|
gl_TessCoord[1]
|
|
);
|
|
|
|
// Interpolate the original position
|
|
vec3 position = mix(
|
|
mix(te_in[0].position, te_in[1].position, gl_TessCoord[0]),
|
|
mix(te_in[3].position, te_in[2].position, gl_TessCoord[0]),
|
|
gl_TessCoord[1]
|
|
);
|
|
|
|
fragPosition = (PV*M*vec4(position, 1.0)).xyz;
|
|
gl_Position = PV*M*vec4(position, 1.0f);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// layout(quads, equal_spacing, ccw) in; // Define the type of patch (e.g., quads)
|
|
// in vec2 tcs_uv[];
|
|
|
|
// layout(binding = 0) uniform sampler2D heightTexture;
|
|
|
|
// layout(location = 0) uniform mat4 M;
|
|
|
|
// layout(std140, binding = 0) uniform SceneUniforms
|
|
// {
|
|
// mat4 PV; //camera projection * view matrix
|
|
// vec4 eye_w; //world-space eye position
|
|
// };
|
|
|
|
// in VertexData {
|
|
// vec2 tex_coord;
|
|
// } inData[];
|
|
|
|
// out vec3 frag_position; // Ensure this matches the input in fragment.glsl
|
|
|
|
// out VertexData {
|
|
// vec2 tex_coord;
|
|
// } outData;
|
|
|
|
// float getHeight(vec2 uv) {
|
|
// return texture(heightTexture, uv).r;
|
|
// }
|
|
|
|
// void main()
|
|
// {
|
|
// const float u = gl_TessCoord[0];
|
|
// const float v = gl_TessCoord[1];
|
|
|
|
// vec2 tess_coord = gl_TessCoord.xy;
|
|
// vec2 base_uv = mix(tcs_uv[0], tcs_uv[1], tess_coord.x);
|
|
// base_uv = mix(base_uv, mix(tcs_uv[3], tcs_uv[2], tess_coord.x), tess_coord.y);
|
|
// vec4 htex = texture(heightTexture, base_uv);
|
|
|
|
// const vec4 p0 = PV*M*gl_in[0].gl_Position;
|
|
// const vec4 p1 = PV*M*gl_in[1].gl_Position;
|
|
// const vec4 p2 = PV*M*gl_in[2].gl_Position;
|
|
// const vec4 p3 = PV*M*gl_in[3].gl_Position;
|
|
|
|
// vec4 a = mix(p0, p1, u);
|
|
// vec4 b = mix(p3, p2, u);
|
|
// vec4 c = mix(a, b, v);
|
|
|
|
// c.y = htex.r * 0.5f;
|
|
|
|
// float eps = 0.0002;
|
|
// float hCenter = getHeight(base_uv);
|
|
// float hRight = getHeight(base_uv + vec2(eps, 0.0));
|
|
// float hLeft = getHeight(base_uv - vec2(eps, 0.0));
|
|
// float hUp = getHeight(base_uv + vec2(0.0, eps));
|
|
// float hDown = getHeight(base_uv - vec2(0.0, eps));
|
|
|
|
// vec3 tangentX = normalize(vec3(0.002, hRight - hLeft, 0.0));
|
|
// vec3 tangentZ = normalize(vec3(0.0, hUp - hDown, 0.002));
|
|
|
|
// vec3 d0 = gl_in[0].gl_Position.xyz;
|
|
// vec3 d1 = gl_in[1].gl_Position.xyz;
|
|
// vec3 d2 = gl_in[2].gl_Position.xyz;
|
|
|
|
// vec3 n_u = d1 - d0;
|
|
// vec3 v_u = d2 - d0;
|
|
// vec3 v_normal = normalize(cross(n_u, v_u));
|
|
|
|
// vec3 normal = cross(tangentZ, tangentX);
|
|
|
|
// gl_Position = c;
|
|
// outData.tex_coord = base_uv;
|
|
// // outData.pw = vec3(c);
|
|
// // outData.nw = normal;
|
|
|
|
// // Interpolate the position using the barycentric coordinates from tessellation
|
|
// // vec3 pos = mix(mix(gl_in[0].gl_Position.xyz, gl_in[1].gl_Position.xyz, gl_TessCoord.x),
|
|
// // mix(gl_in[3].gl_Position.xyz, gl_in[2].gl_Position.xyz, gl_TessCoord.x),
|
|
// // gl_TessCoord.y);
|
|
|
|
// // frag_position = pos;
|
|
|
|
// // outData.tex_coord = mix(mix(inData[0].tex_coord, inData[1].tex_coord, gl_TessCoord.x),
|
|
// // mix(inData[3].tex_coord, inData[2].tex_coord, gl_TessCoord.x),
|
|
// // gl_TessCoord.y);
|
|
|
|
// // gl_Position = PV*M*vec4(pos, 1.0);
|
|
// }
|