feat(6): Task 6
This commit is contained in:
parent
33f6d1a261
commit
fa72983f52
3 changed files with 15 additions and 13 deletions
|
@ -33,24 +33,27 @@ void main()
|
|||
|
||||
float x = r * cos(2.0 * M_PI * animation_seconds / f);
|
||||
float z = r * sin(2.0 * M_PI * animation_seconds / f);
|
||||
vec3 light_pos = vec3(x, h, z);
|
||||
vec3 light_pos = (view * vec4(vec3(x, h, z), 1.0)).xyz;
|
||||
|
||||
// Calculate the light direction
|
||||
vec3 l = normalize(light_pos - sphere_fs_in);
|
||||
vec3 l = normalize(light_pos - view_pos_fs_in.xyz);
|
||||
|
||||
// Calculate the view direction
|
||||
vec3 v = normalize(view_pos_fs_in.xyz - sphere_fs_in);
|
||||
v = normalize(-view_pos_fs_in.xyz);
|
||||
vec3 v = normalize(-view_pos_fs_in.xyz);
|
||||
|
||||
// Calculate the normal direction
|
||||
vec3 n = normalize(normal_fs_in);
|
||||
/* I calculate bumps etc. in the space that has not yet have applied model and view conversion. */
|
||||
vec3 T, B;
|
||||
tangent(s, T, B);
|
||||
|
||||
// Apply the bump map
|
||||
vec3 T;
|
||||
vec3 B;
|
||||
tangent(n, T, B);
|
||||
vec3 pos = sphere_fs_in;
|
||||
float eps = 0.0001;
|
||||
n = ((bump_position(is_moon, n + eps * T) - bump_position(is_moon, s)) / eps)
|
||||
* ((bump_position(is_moon, n + eps * B) - bump_position(is_moon, s)) / eps);
|
||||
vec3 n = cross(
|
||||
(bump_position(is_moon, pos + eps * T) - bump_position(is_moon, pos)) / eps,
|
||||
(bump_position(is_moon, pos + eps * B) - bump_position(is_moon, pos)) / eps);
|
||||
/* Convert the normal to the view space */
|
||||
n = (view * model(is_moon, animation_seconds) * vec4(n, 0.0)).xyz;
|
||||
n = normalize(n);
|
||||
|
||||
// Base colors
|
||||
|
@ -59,6 +62,6 @@ void main()
|
|||
vec3 ks = vec3(1.0, 1.0, 1.0); // Specular color
|
||||
|
||||
// Compute the Blinn-Phong shading
|
||||
color = blinn_phong(ka, kd, ks, p, n, v, l);
|
||||
color = blinn_phong(ka, kd * terrain_color, ks, p, n, v, l);
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ vec3 bump_position(bool is_moon , vec3 s)
|
|||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Replace with your code
|
||||
float bump = bump_height(is_moon, s);
|
||||
/* p' = p + bump * n but on a unit sphere object */
|
||||
return s + bump_height(is_moon, s) * s;
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// N 3D unit normal vector
|
||||
// Outputs:
|
||||
// T 3D unit tangent vector
|
||||
// B 3D unit bitangent vector
|
||||
// B 3D unit bitangent vectors
|
||||
void tangent(in vec3 N, out vec3 T, out vec3 B)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Reference in a new issue