-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathraymarch.glsl
47 lines (36 loc) · 1.24 KB
/
raymarch.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
46
47
vec3 render(in vec3 ro, in vec3 rd) {
// TODO
return rd; // camera ray direction debug view
}
mat3 setCamera(in vec3 ro, in vec3 ta, float cr) {
// Starter code from iq's Raymarching Primitives
// https://www.shadertoy.com/view/Xds3zN
vec3 cw = normalize(ta - ro);
vec3 cp = vec3(sin(cr), cos(cr), 0.0);
vec3 cu = normalize(cross(cw, cp));
vec3 cv = normalize(cross(cu, cw));
return mat3(cu, cv, cw);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
// Starter code from iq's Raymarching Primitives
// https://www.shadertoy.com/view/Xds3zN
vec2 q = fragCoord.xy / iResolution.xy;
vec2 p = -1.0 + 2.0 * q;
p.x *= iResolution.x / iResolution.y;
vec2 mo = iMouse.xy / iResolution.xy;
float time = 15.0 + iGlobalTime;
// camera
vec3 ro = vec3(
-0.5 + 3.5 * cos(0.1 * time + 6.0 * mo.x),
1.0 + 2.0 * mo.y,
0.5 + 3.5 * sin(0.1 * time + 6.0 * mo.x));
vec3 ta = vec3(-0.5, -0.4, 0.5);
// camera-to-world transformation
mat3 ca = setCamera(ro, ta, 0.0);
// ray direction
vec3 rd = ca * normalize(vec3(p.xy, 2.0));
// render
vec3 col = render(ro, rd);
col = pow(col, vec3(0.4545));
fragColor = vec4(col, 1.0);
}