From 385a06f5318958854c2e7d2aa882b6591c6b9eea Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Fri, 6 Dec 2024 14:16:51 +0100 Subject: [PATCH 1/4] style(1): Switch to industry standard --- src/1_model.glsl | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/1_model.glsl b/src/1_model.glsl index 6d6fe6d..21c6a33 100644 --- a/src/1_model.glsl +++ b/src/1_model.glsl @@ -26,18 +26,13 @@ mat4 model(bool is_moon, float time) // Based on: // https://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/#cumulating-transformations - mat4 scale_matrix = uniform_scale(0.30); - float r = 2.0; - mat4 translation_matrix = translate(vec3(r, 0, 0)); - - // TODO Why is PI not defined? - float full_rotation = 2 * 3.14159; + float full_rotation = 2 * M_PI; float theta = full_rotation * time / 4.0; - mat4 rotation_matrix = rotate_about_y(theta); - // Small hack to make the moon rotate around the origin - // Usually you would rotate first, then translate - return rotation_matrix * translation_matrix * scale_matrix; + float x = r * cos(theta); + float z = r * sin(theta); + + return translate(vec3(x, 0, z)) * rotate_about_y(theta) * uniform_scale(0.30); ///////////////////////////////////////////////////////////////////////////// } From 0afa923678e3fbc1541af59994e96f6bd0142246 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Fri, 6 Dec 2024 14:18:48 +0100 Subject: [PATCH 2/4] chore(1): Invert rotation direction --- src/1_model.glsl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/1_model.glsl b/src/1_model.glsl index 21c6a33..1af8dfe 100644 --- a/src/1_model.glsl +++ b/src/1_model.glsl @@ -29,6 +29,8 @@ mat4 model(bool is_moon, float time) float r = 2.0; float full_rotation = 2 * M_PI; float theta = full_rotation * time / 4.0; + // Invert rotation + theta = -theta; float x = r * cos(theta); float z = r * sin(theta); From 7832cb21acbc453a9afd0d57a5b8caadbfd5e71a Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Fri, 6 Dec 2024 14:19:00 +0100 Subject: [PATCH 3/4] feat(2): Task 2 --- src/2_tessellate_5.tcs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/2_tessellate_5.tcs b/src/2_tessellate_5.tcs index ce569ee..bc6575b 100644 --- a/src/2_tessellate_5.tcs +++ b/src/2_tessellate_5.tcs @@ -14,7 +14,14 @@ void main() { ///////////////////////////////////////////////////////////////////////////// // Replace with your code: - pos_es_in[gl_InvocationID] = pos_cs_in[gl_InvocationID]; + // Hard-code each tessellation level to 5 + gl_TessLevelOuter[0] = 5; + gl_TessLevelOuter[1] = 5; + gl_TessLevelOuter[2] = 5; + gl_TessLevelInner[0] = 5; + + // Pass through the input vertices + pos_es_in[gl_InvocationID] = pos_cs_in[gl_InvocationID]; ///////////////////////////////////////////////////////////////////////////// } From 29c45e43e84ddd5c021403868f6cb7056c0d1f56 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Fri, 6 Dec 2024 15:04:49 +0100 Subject: [PATCH 4/4] feat(3): Task 3 --- src/3_snap_to_sphere.tes | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/3_snap_to_sphere.tes b/src/3_snap_to_sphere.tes index 873e025..0e2a1b6 100644 --- a/src/3_snap_to_sphere.tes +++ b/src/3_snap_to_sphere.tes @@ -35,10 +35,15 @@ void main() // (so before model, view, proj are applied) ///////////////////////////////////////////////////////////////////////////// - // Replace with your code + // Replace with your code + // Based on: + // https://learnopengl.com/Guest-Articles/2021/Tessellation/Tessellation + sphere_fs_in = normalize(interp_pos.xyz); + view_pos_fs_in = view * model(is_moon, animation_seconds) * vec4(sphere_fs_in, 1.0); + normal_fs_in = normalize(mat3(view * model(is_moon, animation_seconds)) * sphere_fs_in); + pos_fs_in = proj * view_pos_fs_in; - - gl_Position = interp_pos; + gl_Position = pos_fs_in; ///////////////////////////////////////////////////////////////////////////// }