@@ -29,11 +29,13 @@ uniform sampler2D normalTexture;
29
29
uniform sampler2D paperTexture;
30
30
uniform sampler2D noiseTexture;
31
31
uniform vec3 inkColor;
32
+ uniform float noiseScale;
32
33
uniform float scale;
33
34
uniform float thickness;
34
35
uniform float noisiness;
35
36
uniform float angle;
36
37
uniform float contour;
38
+ uniform float divergence;
37
39
38
40
out vec4 fragColor;
39
41
@@ -49,7 +51,7 @@ ${darken}
49
51
50
52
#define TAU 6.28318530718
51
53
52
- #define LEVELS 50
54
+ #define LEVELS 10
53
55
#define fLEVELS float(LEVELS)
54
56
55
57
float sampleSrc(in sampler2D src, in vec2 uv) {
@@ -127,29 +129,37 @@ float texh(in vec2 p, in float lum) {
127
129
return 1.;
128
130
}
129
131
132
+ float lines( in float l, in vec2 fragCoord, in vec2 resolution, in float thickness){
133
+ vec2 center = vec2(resolution.x/2., resolution.y/2.);
134
+ vec2 uv = fragCoord.xy * resolution;
135
+
136
+ float c = (.5 + .5 * sin(uv.x*.5));
137
+ float f = (c+thickness)*l;
138
+ float e = 1. * length(vec2(dFdx(fragCoord.x), dFdy(fragCoord.y)));
139
+ f = smoothstep(.5-e, .5+e, f);
140
+ return f;
141
+ }
142
+
143
+
130
144
void main() {
131
145
vec2 size = vec2(textureSize(colorTexture, 0));
132
146
133
147
float hatch = 0.;
134
- float ss = scale * 1.;
148
+ float ss = noiseScale * 1.;
135
149
vec2 offset = noisiness * vec2(fbm3(vec3(ss*vUv,1.)), fbm3(vec3(ss*vUv.yx,1.)));
136
150
vec2 uv = vUv + offset;
137
151
138
152
float l = luma(texture(colorTexture, uv).rgb);
139
153
l = round(l * float(LEVELS)) / float(LEVELS);
140
- l *= 2.;
141
- hatch = 0 .;
154
+ // l *= 2.;
155
+ hatch = 1 .;
142
156
143
157
float normalEdge = length(sobel(normalTexture, uv, size, 3. * contour));
144
158
normalEdge = 1.-aastep(.5, normalEdge);
145
159
l *= normalEdge;
160
+ l *= 2.;
146
161
l = clamp(l, 0., 1.);
147
162
148
- float a = angle;
149
- float s = sin(a);
150
- float c = cos(a);
151
- mat2 rot = mat2(c, -s, s, c);
152
-
153
163
for(int i=0; i<LEVELS; i++) {
154
164
float f = float(i)/fLEVELS;
155
165
float n = float(i+1)/fLEVELS;
@@ -158,26 +168,25 @@ void main() {
158
168
normalEdge = aastep(.5, normalEdge);
159
169
160
170
if(l<=f) {
161
-
162
- float f = float(i) / float(LEVELS);
163
- float ss = scale * mix(1., 4., f);
171
+ float ss = noiseScale * mix(1., 4., f);
164
172
vec2 offset = noisiness * vec2(fbm3(vec3(ss*vUv,1.)), fbm3(vec3(ss*vUv.yx,1.)));
173
+ vec2 uv = vUv + offset;
165
174
166
- uv = rot * uv;// (uv - .5) + .5 ;
167
-
168
- float threshold = mix(fLEVELS, 200., f );
169
- float v = abs(mod(uv.y*size.y+f*threshold, threshold) );
170
- if (v < 1.+thickness) {
171
- v = 1. ;
172
- } else {
173
- v = 0. ;
174
- }
175
- hatch + = v;
175
+ float a = angle + divergence * mix(0., 3.2 * TAU, f) ;
176
+ float s = sin(a);
177
+ float c = cos(a );
178
+ mat2 rot = mat2(c, -s, s, c );
179
+
180
+ uv = rot * (uv - .5) + .5 ;
181
+
182
+ float w = l/f ;
183
+ float v = lines(w, scale * mix(5.,1., f) * uv, size, w*(1.-thickness));
184
+ hatch * = v;
176
185
}
177
186
}
178
187
179
188
vec4 paper = texture(paperTexture, .00025 * vUv*size);
180
- fragColor.rgb = blendDarken(paper.rgb, inkColor/255., hatch);
189
+ fragColor.rgb = blendDarken(paper.rgb, inkColor/255., 1.- hatch);
181
190
//fragColor.rgb = blendDarken(fragColor.rgb, inkColor/255., 1.-normalEdge);
182
191
fragColor.a = 1.;
183
192
}
@@ -189,13 +198,14 @@ class Post {
189
198
this . colorFBO = getFBO ( 1 , 1 ) ;
190
199
this . normalFBO = getFBO ( 1 , 1 ) ;
191
200
this . params = {
192
- scale : 0.72 ,
201
+ scale : 0.5 ,
202
+ noiseScale : 0.72 ,
193
203
angle : 2 ,
194
- randomness : 0 ,
195
- thickness : 0.7 ,
204
+ divergence : 1 ,
205
+ thickness : 0.72 ,
196
206
contour : 1.2 ,
197
207
noisiness : 0.007 ,
198
- inkColor : new Color ( 18 , 119 , 140 ) ,
208
+ inkColor : new Color ( 68 , 107 , 147 ) ,
199
209
} ;
200
210
const shader = new RawShaderMaterial ( {
201
211
uniforms : {
@@ -205,9 +215,10 @@ class Post {
205
215
noiseTexture : { value : noiseTexture } ,
206
216
inkColor : { value : this . params . inkColor } ,
207
217
scale : { value : this . params . scale } ,
208
- randomness : { value : this . params . randomness } ,
218
+ divergence : { value : this . params . divergence } ,
209
219
thickness : { value : this . params . thickness } ,
210
220
contour : { value : this . params . contour } ,
221
+ noiseScale : { value : this . params . noiseScale } ,
211
222
noisiness : { value : this . params . noisiness } ,
212
223
angle : { value : this . params . angle } ,
213
224
} ,
@@ -238,24 +249,29 @@ class Post {
238
249
generateParams ( gui ) {
239
250
const controllers = { } ;
240
251
controllers [ "scale" ] = gui
241
- . add ( this . params , "scale" , 0.1 , 1 )
252
+ . add ( this . params , "scale" , 0.1 , 2 )
242
253
. onChange ( async ( v ) => {
243
254
this . renderPass . shader . uniforms . scale . value = v ;
244
255
} ) ;
245
256
controllers [ "thickness" ] = gui
246
- . add ( this . params , "thickness" , 0 , 5 )
257
+ . add ( this . params , "thickness" , 0 , 1 )
247
258
. onChange ( async ( v ) => {
248
259
this . renderPass . shader . uniforms . thickness . value = v ;
249
260
} ) ;
261
+ controllers [ "noiseScale" ] = gui
262
+ . add ( this . params , "noiseScale" , 0.1 , 1 )
263
+ . onChange ( async ( v ) => {
264
+ this . renderPass . shader . uniforms . noiseScale . value = v ;
265
+ } ) ;
250
266
controllers [ "noisiness" ] = gui
251
267
. add ( this . params , "noisiness" , 0 , 0.02 )
252
268
. onChange ( async ( v ) => {
253
269
this . renderPass . shader . uniforms . noisiness . value = v ;
254
270
} ) ;
255
- controllers [ "randomness " ] = gui
256
- . add ( this . params , "randomness " , 0 , 0.02 )
271
+ controllers [ "divergence " ] = gui
272
+ . add ( this . params , "divergence " , 0 , 1 )
257
273
. onChange ( async ( v ) => {
258
- this . renderPass . shader . uniforms . randomness . value = v ;
274
+ this . renderPass . shader . uniforms . divergence . value = v ;
259
275
} ) ;
260
276
controllers [ "angle" ] = gui
261
277
. add ( this . params , "angle" , 0 , Math . PI )
0 commit comments