-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwave.frag
More file actions
61 lines (61 loc) · 1.65 KB
/
wave.frag
File metadata and controls
61 lines (61 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#version 330 compatibility
in vec3 vMC;
in vec3 vNs;
in vec3 vLs;
in vec3 vEs;
uniform float uKa, uKd, uKs;
uniform vec4 uColor;
uniform float uShininess;
uniform sampler3D Noise3;
uniform float uNoiseAmp;
uniform float uNoiseFreq;
const vec4 WHITE = { 1., 1., .8, 1. };
vec3
RotateNormal( float angx, float angy, vec3 n )
{
float cx = cos( angx );
float sx = sin( angx );
float cy = cos( angy );
float sy = sin( angy );
// rotate about x:
float yp = n.y*cx - n.z*sx; // y'
n.z = n.y*sx + n.z*cx; // z'
n.y = yp;
// n.x = n.x;
// rotate about y:
float xp = n.x*cy + n.z*sy; // x'
n.z = -n.x*sy + n.z*cy; // z'
n.x = xp;
// n.y = n.y;
return normalize( n );
}
void
main( )
{
vec4 nvx = texture3D( Noise3, uNoiseFreq*vMC );
vec4 nvy = texture3D( Noise3, uNoiseFreq*vec3(vMC.xy,vMC.z+0.5) );
float angx = nvx.r + nvx.g + nvx.b + nvx.a; // 1. -> 3.
angx = angx - 2.;
// -1. -> 1.
angx *= uNoiseAmp;
float angy = nvy.r + nvy.g + nvy.b + nvy.a; // 1. -> 3.
angy = angy - 2.;
// -1. -> 1.
angy *= uNoiseAmp;
vec3 normal = normalize( vNs );
vec3 light = normalize( vLs );
vec3 eye = normalize( vEs );
normal = RotateNormal( angx, angy, normal );
vec4 ambient = uKa * uColor;
float d = max( dot(normal,light), 0. );
d = abs( dot(normal,light));
vec4 diffuse = uKd * d * uColor;
float s = 0.;
if( dot(normal,light) > 0. ) // only do specular if the light can see the point
{
vec3 ref = normalize( 2. * normal * dot(normal,light) - light );
s = pow( max( dot(eye,ref),0. ), uShininess );
}
vec4 specular = uKs * s * WHITE;
gl_FragColor = vec4( ambient.rgb + diffuse.rgb + specular.rgb, 1. );
}