Compare commits

...

4 commits

3 changed files with 23 additions and 14 deletions

View file

@ -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);
/////////////////////////////////////////////////////////////////////////////
}

View file

@ -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];
/////////////////////////////////////////////////////////////////////////////
}

View file

@ -36,9 +36,14 @@ void main()
/////////////////////////////////////////////////////////////////////////////
// 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;
/////////////////////////////////////////////////////////////////////////////
}