feat(5): Task 5
This commit is contained in:
parent
889663355c
commit
745dfdd586
4 changed files with 72 additions and 10 deletions
|
@ -9,8 +9,32 @@
|
|||
float perlin_noise( vec3 st)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Replace with your code
|
||||
return 0;
|
||||
// Replace with your code
|
||||
vec3 i = floor(st);
|
||||
vec3 f = fract(st);
|
||||
|
||||
// Corners of 3D cube
|
||||
float n000 = dot(random_direction(i + vec3(0.0, 0.0, 0.0)), f - vec3(0.0, 0.0, 0.0));
|
||||
float n100 = dot(random_direction(i + vec3(1.0, 0.0, 0.0)), f - vec3(1.0, 0.0, 0.0));
|
||||
float n010 = dot(random_direction(i + vec3(0.0, 1.0, 0.0)), f - vec3(0.0, 1.0, 0.0));
|
||||
float n110 = dot(random_direction(i + vec3(1.0, 1.0, 0.0)), f - vec3(1.0, 1.0, 0.0));
|
||||
float n001 = dot(random_direction(i + vec3(0.0, 0.0, 1.0)), f - vec3(0.0, 0.0, 1.0));
|
||||
float n101 = dot(random_direction(i + vec3(1.0, 0.0, 1.0)), f - vec3(1.0, 0.0, 1.0));
|
||||
float n011 = dot(random_direction(i + vec3(0.0, 1.0, 1.0)), f - vec3(0.0, 1.0, 1.0));
|
||||
float n111 = dot(random_direction(i + vec3(1.0, 1.0, 1.0)), f - vec3(1.0, 1.0, 1.0));
|
||||
|
||||
// Interpolate along x the corner values
|
||||
float nx00 = mix(n000, n100, smooth_step(f.x));
|
||||
float nx10 = mix(n010, n110, smooth_step(f.x));
|
||||
float nx01 = mix(n001, n101, smooth_step(f.x));
|
||||
float nx11 = mix(n011, n111, smooth_step(f.x));
|
||||
|
||||
// Interpolate the mixd values along y
|
||||
float nxy0 = mix(nx00, nx10, smooth_step(f.y));
|
||||
float nxy1 = mix(nx01, nx11, smooth_step(f.y));
|
||||
|
||||
// Interpolate along z
|
||||
return mix(nxy0, nxy1, smooth_step(f.z));
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,36 @@ void main()
|
|||
marble_noise = clamp(marble_noise,0,1);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Replace with your code
|
||||
color = marble_noise * vec3(1,1,1);
|
||||
// Replace with your code
|
||||
// Exactly the same as 4_lit.fs, but multiply the base colors by 'marble_noise'
|
||||
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 = vec3(x, h, z);
|
||||
|
||||
// Calculate the light direction
|
||||
vec3 l = normalize(light_pos - sphere_fs_in);
|
||||
|
||||
// Calculate the view direction
|
||||
vec3 v = normalize(view_pos_fs_in.xyz - sphere_fs_in);
|
||||
v = normalize(-view_pos_fs_in.xyz);
|
||||
|
||||
// Calculate the normal direction
|
||||
vec3 n = normalize(normal_fs_in);
|
||||
|
||||
// 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
|
||||
|
||||
// Apply the marble noise to the base colors
|
||||
kd *= marble_noise;
|
||||
|
||||
// Compute the Blinn-Phong shading
|
||||
color = blinn_phong(ka, kd, ks, p, n, v, l);
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
|
|
@ -9,7 +9,15 @@
|
|||
vec3 random_direction( vec3 seed)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Replace with your code
|
||||
return vec3(1,0,0);
|
||||
// Replace with your code
|
||||
// Poolcoordinaten
|
||||
float theta = 2.0 * M_PI * random2(seed.xy).x;
|
||||
float phi = acos(2.0 * random2(seed.yz).x - 1.0);
|
||||
// Cartesische coordinaten
|
||||
return vec3(
|
||||
sin(phi) * cos(theta),
|
||||
sin(phi) * sin(theta),
|
||||
cos(phi)
|
||||
);
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
|
|
@ -9,14 +9,15 @@
|
|||
float smooth_step( float f)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Replace with your code
|
||||
return f;
|
||||
// Replace with your code
|
||||
// Use the improved version
|
||||
return 6 * pow(f, 5) - 15 * pow(f, 4) + 10 * pow(f, 3);
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
vec3 smooth_step( vec3 f)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Replace with your code
|
||||
return f;
|
||||
// Replace with your code
|
||||
return vec3(smooth_step(f.x), smooth_step(f.y), smooth_step(f.z));
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
|
Reference in a new issue