ライトで照らされたサイン波の表面
See the Pen sin surface with a light by aadebdeb (@aadebdeb) on CodePen.
#define PI 3.14159265359
#define TWO_PI PI * 2.0
#define HALF_PI PI / 2.0
precision mediump float;
uniform float u_time;
uniform vec2 u_mouse;
uniform vec2 u_resolution;
void main(void) {
vec2 st = (gl_FragCoord.xy * 2.0 - u_resolution) / min(u_resolution.x, u_resolution.y);
vec2 mouse = (u_mouse * 2.0 - u_resolution) / min(u_resolution.x, u_resolution.y);
float d = length(st);
vec2 dir = normalize(st);
float theta = d * 30.0 - u_time * 0.006;
float v = sin(theta);
vec3 normal = normalize(vec3(dir * cos(-theta), 1.0));
vec3 light = vec3(mouse, 2.0);
vec3 vecToLight = normalize(light - vec3(st, v * 1.0));
vec3 color = mix(vec3(0.5, 0.3, 0.2), vec3(0.1, 0.2, 0.8), (v + 1.0) * 0.5);
color = color + vec3(0.7, 0.7, 0.7) * max(dot(vecToLight, normal), 0.0);
gl_FragColor = vec4(color, 1.0);
}