73 lines
2.5 KiB
GLSL
73 lines
2.5 KiB
GLSL
// This is just like lit.fs, but you need to multiply the base color
|
|
// of the planet and moon by 'marble_noise' to get a marble-like texture.
|
|
// Do this multiplication before passing the blue and grey colors to blinn_phong()
|
|
|
|
// Uniforms:
|
|
uniform mat4 view;
|
|
uniform mat4 proj;
|
|
uniform float animation_seconds;
|
|
uniform bool is_moon;
|
|
// Inputs:
|
|
in vec3 sphere_fs_in;
|
|
in vec3 normal_fs_in;
|
|
in vec4 pos_fs_in;
|
|
in vec4 view_pos_fs_in;
|
|
// Outputs:
|
|
out vec3 color; // rgb color of this pixel
|
|
|
|
// expects: blinn_phong, perlin_noise
|
|
void main()
|
|
{
|
|
// build up marble noise from layers of perlin noise with different scales
|
|
float s = sin(20*(sphere_fs_in.y + (1-0.5*float(is_moon))*perlin_noise( sphere_fs_in ))) *
|
|
(0.991+0.009*perlin_noise( (2.0 + 2*float(is_moon)) * sphere_fs_in));
|
|
float s2 = (
|
|
+0.25*perlin_noise( 1.0 * sphere_fs_in )
|
|
+0.25*perlin_noise( 4.0 * sphere_fs_in )
|
|
+0.25*perlin_noise( 8.0 * sphere_fs_in )
|
|
+0.25*perlin_noise(16.0 * sphere_fs_in ));
|
|
float s3 = max(s+0.4,0) *
|
|
pow(min(
|
|
(0.5+0.5*(
|
|
(0.2*sin(10*(sphere_fs_in.x + perlin_noise( 8*sphere_fs_in )))+
|
|
0.2*sin(15*(sphere_fs_in.z + perlin_noise( 8*sphere_fs_in )))
|
|
+ 0.2*perlin_noise(16*sphere_fs_in))
|
|
+ 0.6*perlin_noise(32*sphere_fs_in)
|
|
))
|
|
,1.0),2);
|
|
float marble_noise = 1-clamp( 0.1*pow(s*0.5+0.5,20) + 0.7*(0.5*s2+0.5) + 0.2*s3, 0,1) ;
|
|
marble_noise = clamp(marble_noise,0,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 = (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
|
|
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);
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
}
|