Compare commits
2 commits
745dfdd586
...
fa72983f52
Author | SHA1 | Date | |
---|---|---|---|
fa72983f52 | |||
33f6d1a261 |
6 changed files with 58 additions and 18 deletions
|
@ -31,14 +31,13 @@ void main()
|
||||||
|
|
||||||
float x = r * cos(2.0 * M_PI * animation_seconds / f);
|
float x = r * cos(2.0 * M_PI * animation_seconds / f);
|
||||||
float z = r * sin(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
|
// 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
|
// Calculate the view direction
|
||||||
vec3 v = normalize(view_pos_fs_in.xyz - sphere_fs_in);
|
vec3 v = normalize(-view_pos_fs_in.xyz);
|
||||||
v = normalize(-view_pos_fs_in.xyz);
|
|
||||||
|
|
||||||
// Calculate the normal direction
|
// Calculate the normal direction
|
||||||
vec3 n = normalize(normal_fs_in);
|
vec3 n = normalize(normal_fs_in);
|
||||||
|
|
|
@ -48,14 +48,13 @@ void main()
|
||||||
|
|
||||||
float x = r * cos(2.0 * M_PI * animation_seconds / f);
|
float x = r * cos(2.0 * M_PI * animation_seconds / f);
|
||||||
float z = r * sin(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
|
// 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
|
// Calculate the view direction
|
||||||
vec3 v = normalize(view_pos_fs_in.xyz - sphere_fs_in);
|
vec3 v = normalize(-view_pos_fs_in.xyz);
|
||||||
v = normalize(-view_pos_fs_in.xyz);
|
|
||||||
|
|
||||||
// Calculate the normal direction
|
// Calculate the normal direction
|
||||||
vec3 n = normalize(normal_fs_in);
|
vec3 n = normalize(normal_fs_in);
|
||||||
|
|
|
@ -11,8 +11,9 @@ vec3 random_direction( vec3 seed)
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Replace with your code
|
// Replace with your code
|
||||||
// Poolcoordinaten
|
// Poolcoordinaten
|
||||||
float theta = 2.0 * M_PI * random2(seed.xy).x;
|
vec2 rand = random2(seed);
|
||||||
float phi = acos(2.0 * random2(seed.yz).x - 1.0);
|
float theta = 2.0 * M_PI * rand.x;
|
||||||
|
float phi = acos(2.0 * rand.y - 1.0);
|
||||||
// Cartesische coordinaten
|
// Cartesische coordinaten
|
||||||
return vec3(
|
return vec3(
|
||||||
sin(phi) * cos(theta),
|
sin(phi) * cos(theta),
|
||||||
|
|
|
@ -25,7 +25,43 @@ void main()
|
||||||
float terrain_color = clamp(1+5*b,0,1);
|
float terrain_color = clamp(1+5*b,0,1);
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Replace with your code
|
// Replace with your code
|
||||||
color = terrain_color * vec3(1,1,1);
|
float r = 10.0;
|
||||||
|
float h = 8.0;
|
||||||
|
float f = 8.0;
|
||||||
|
float p = 1000.0;
|
||||||
|
|
||||||
|
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 = (view * vec4(vec3(x, h, z), 1.0)).xyz;
|
||||||
|
|
||||||
|
// Calculate the light direction
|
||||||
|
vec3 l = normalize(light_pos - view_pos_fs_in.xyz);
|
||||||
|
|
||||||
|
// Calculate the view direction
|
||||||
|
vec3 v = normalize(-view_pos_fs_in.xyz);
|
||||||
|
|
||||||
|
// Calculate the normal direction
|
||||||
|
/* 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 pos = sphere_fs_in;
|
||||||
|
float eps = 0.0001;
|
||||||
|
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
|
||||||
|
vec3 ka = vec3(0.1, 0.1, 0.1); // Ambient color
|
||||||
|
vec3 kd = is_moon ? vec3(0.5, 0.45, 0.5) : vec3(0.2, 0.3, 0.8); // Diffuse color
|
||||||
|
vec3 ks = vec3(1.0, 1.0, 1.0); // Specular color
|
||||||
|
|
||||||
|
// Compute the Blinn-Phong shading
|
||||||
|
color = blinn_phong(ka, kd * terrain_color, ks, p, n, v, l);
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
vec3 bump_position(bool is_moon , vec3 s)
|
vec3 bump_position(bool is_moon , vec3 s)
|
||||||
{
|
{
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Replace with your code
|
// Replace with your code
|
||||||
return s;
|
/* p' = p + bump * n but on a unit sphere object */
|
||||||
|
return s + bump_height(is_moon, s) * s;
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,16 @@
|
||||||
// N 3D unit normal vector
|
// N 3D unit normal vector
|
||||||
// Outputs:
|
// Outputs:
|
||||||
// T 3D unit tangent vector
|
// 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)
|
void tangent(in vec3 N, out vec3 T, out vec3 B)
|
||||||
{
|
{
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Replace with your code
|
// Replace with your code
|
||||||
T = vec3(1,0,0);
|
// Calculate a vector that is perpendicular to N
|
||||||
B = vec3(0,1,0);
|
vec3 doesnotmatter = abs(N.y) < 0.999 ? vec3(0,1,0) : vec3(1,0,0);
|
||||||
|
T = normalize(cross(doesnotmatter, N));
|
||||||
|
// Now T is perpendicular to N
|
||||||
|
// Take B as the cross product of N and T, to make it perpendicular to both
|
||||||
|
B = cross(N, T);
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue