12
12
uniform int frame_count;
13
13
#define iResolution resolution
14
14
#define iFrame frame_count
15
- #define gl_FragColor fragColor
16
15
17
16
#else
18
17
19
18
// Blossom header
19
+ layout (location = 0 ) out vec4 fragColor;
20
20
layout (location = 0 ) uniform vec4 iResolution;
21
21
layout (location = 1 ) uniform int iFrame;
22
22
@@ -45,11 +45,13 @@ vec3 noise(vec3 p, float f) {
45
45
return acc.xyz / acc.w;
46
46
}
47
47
48
+ // rotation matrix
48
49
mat2 rot(float a) {
49
50
float s= sin (a), c= cos (a);
50
51
return mat2 (c,- s,s,c);
51
52
}
52
53
54
+ // Sh4derJockey logo sdf
53
55
float logo(vec2 p) {
54
56
const float t = 0.015 ;
55
57
const float h = 0.5 * (7.0 / 18.0 + t);
@@ -65,16 +67,22 @@ float logo(vec2 p) {
65
67
float trace(vec3 ro, vec3 rd) {
66
68
float r = 1e32 ;
67
69
70
+ // intersect with one slice at a time
68
71
for (int i = - 8 ; i <= 2 ; i++ ) {
72
+
73
+ // ray-plane intersection
69
74
float t = (i - ro.y) / rd.y;
70
75
if (t < 0 ) continue ;
71
76
77
+ // compute point on plane
72
78
vec3 p = ro + rd * t;
73
79
float s = dot (p, rd);
74
80
p.xz *= rot(0.06 * p.y - 0.5 );
75
81
82
+ // evaluate logo sdf
76
83
float d = logo(p.xz);
77
84
85
+ // add noise pattern
78
86
if (i < 1 ) {
79
87
d = min (d, abs (noise(p, 5 ).x) - 0.002 );
80
88
@@ -87,35 +95,47 @@ float trace(vec3 ro, vec3 rd) {
87
95
d = min (d, min (a.x, a.y));
88
96
}
89
97
98
+ // update nearest intersection
90
99
if (d < 0.01 * (rv.x - 0.5 )) r = min (r, t);
100
+
101
+ // cycle random state
91
102
rv = rv.wxyz;
92
103
}
93
104
94
105
return r;
95
106
}
96
107
97
108
void main() {
109
+ // initialise random state
98
110
rv = 7 * cos (iFrame + gl_FragCoord );
99
111
for (int i= 0 ; i< 8 ; i++ ) shuffle();
100
112
113
+ // compute uv coordinates with anti-aliasing
101
114
vec2 aa = rv.xy * 2 - 1 ;
102
115
vec2 uv = (2 * gl_FragCoord .xy - iResolution.xy + aa) / iResolution.y;
103
116
117
+ // compute depth of field parameters
104
118
vec2 a = vec2 (1 , 2 * pi) * rv.zw;
105
119
vec2 dof = 0.6 * pow (a.x, 0.45 ) * vec2 (cos (a.y),sin (a.y));
106
120
121
+ // setup camera
107
122
const float focal = 8.0 ;
108
123
vec3 ro = vec3 (dof, - 3.5 * focal);
109
124
vec3 rd = normalize (vec3 (uv - focal * dof / length (ro), focal));
110
125
126
+ // orbit rotate camera
111
127
ro.yz *= rot(0.7 );
112
128
rd.yz *= rot(0.7 );
113
129
130
+ // update random state
114
131
shuffle();
115
132
shuffle();
116
133
shuffle();
117
134
135
+ // trace and compute color
118
136
float t = trace(ro, rd);
119
137
vec3 col = (1 + 2 * vec3 (aa, aa.x)) * exp (- 0.1 * pow (length (ro) - t - 1 , 2 ));
120
- gl_FragColor = vec4 (col, 1 );
138
+
139
+ // set output color
140
+ fragColor = vec4 (col, 1 );
121
141
}
0 commit comments