diff --git a/src/1_model.glsl b/src/1_model.glsl index 6d6fe6d..1af8dfe 100644 --- a/src/1_model.glsl +++ b/src/1_model.glsl @@ -26,18 +26,15 @@ 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); + // Invert rotation + theta = -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); ///////////////////////////////////////////////////////////////////////////// } 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]; ///////////////////////////////////////////////////////////////////////////// } 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; ///////////////////////////////////////////////////////////////////////////// }