-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path091-2d-random.glsl
45 lines (33 loc) · 1.3 KB
/
091-2d-random.glsl
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
#ifdef GL_ES
precision mediump float;
#endif
#include "./libs/random.glsl"
uniform vec2 u_resolution;
uniform float u_time;
void main(){
//vec2 mouse = u_mouse.xy / u_resolution.xy
vec2 st = gl_FragCoord.xy / u_resolution.xy;
//1
float c = rand(st.x);
// 2 try out several combination
//c = rand(st.x)*rand(st.x);
//c = sqrt(rand(st.x));
//c = pow(rand(st.x),5.);
// 3 Ok. But how can we implement the random function in 2d?, to both the x and y?
// we need a way to return a float starting from a 2d vector.
// there is function in glsl that takes a vec2 and returns a float
// and it is the dot function. the dot function returns the dot product between two vectors.
// that means, for example, that taking vec2 a and vec2 b,
// the dot product returns a.x⋅b.x + a.y⋅b.y
// https://kidscancode.org/godot_recipes/math/dot_cross_product/
// https://thebookofshaders.com/glossary/?search=dot
c = rand( st );
// 5 exercises
// try to change the values in the rand function above
// try to make your own random function. It's ok if it contains repetition that you like ;)
// 6 pass add u_time to st as parameter
// vec2 sst = st;
// sst.x += u_time * 0.000001;
// c = rand( sst );
gl_FragColor=vec4(vec3(c), 1.0);
}