-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot.vs
62 lines (49 loc) · 1.64 KB
/
dot.vs
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
62
/*
* Simple Vertex
* Simple vertex shader, except that we add the UV coordinate
* All we do is pass this to the fragment shader
*/
/* number of dots over the UV range */
uniform float dots;
/* how big are the circles */
uniform float radius;
/* amount of blur - -1 means do it "correctly" */
uniform float blur;
float fdot(vec2 uv) {
float x = uv.x * dots;
float y = uv.y * dots;
float xc = floor(x);
float yc = floor(y);
float dx = x-xc-.5;
float dy = y-yc-.5;
float d = sqrt(dx*dx + dy*dy);
// if the blur is positive, use it for blurring
// if the blur is negative - compute the amount of bluring using fwidth
float a = blur;
float dc = 1.0-smoothstep(radius-a,radius+a,d);
return dc;
}
// uniform mat4 modelViewMatrix;
// uniform mat4 projectionMatrix;
// in vec3 position;
// in vec3 normal;
// The varying is the "output" to the fragment shader
// I call it v_normal to remind myself that it is for the vertex
// the fragment shader will get interpolated values
/* pass interpolated variables to the fragment */
varying vec2 v_uv;
varying vec3 l_normal;
varying vec3 v_world_position;
void main() {
v_uv = uv;
float d = fdot(uv);
vec4 world_pos = (modelMatrix * vec4(position,1.0));
v_world_position = world_pos.xyz;
// the main output of the shader (the vertex position)
gl_Position = projectionMatrix * viewMatrix * world_pos;
// compute the normal and pass it to fragment
// note - this is in world space, but uses a hack that
// assumes the model matrix is its own adjoint
// (which is true, sometimes)
l_normal = (modelMatrix * vec4(normal,0)).xyz;
}