forked from glslify/glslify-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.frag
40 lines (30 loc) · 920 Bytes
/
example.frag
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
precision mediump float;
uniform float iGlobalTime;
uniform vec3 iResolution;
vec2 doModel(vec3 p);
#pragma glslify: camera = require('glsl-turntable-camera')
#pragma glslify: noise = require('glsl-noise/simplex/4d')
#pragma glslify: raytrace = require('glsl-raytrace', map = doModel, steps = 90)
#pragma glslify: normal = require('glsl-sdf-normal', map = doModel)
vec2 doModel(vec3 p) {
float r = 1.0 + noise(vec4(p, iGlobalTime)) * 0.25;
float d = length(p) - r;
float id = 0.0;
return vec2(d, id);
}
void main() {
vec3 color = vec3(0.0);
vec3 ro, rd;
float rotation = iGlobalTime;
float height = 0.0;
float dist = 4.0;
camera(rotation, height, dist, iResolution.xy, ro, rd);
vec2 t = raytrace(ro, rd);
if (t.x > -0.5) {
vec3 pos = ro + rd * t.x;
vec3 nor = normal(pos);
color = nor * 0.5 + 0.5;
}
gl_FragColor.rgb = color;
gl_FragColor.a = 1.0;
}