Skip to content

Commit c7f68d7

Browse files
committed
remade post lines i
1 parent d6e3840 commit c7f68d7

File tree

2 files changed

+49
-33
lines changed

2 files changed

+49
-33
lines changed

post-lines-i/post.js

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ uniform sampler2D normalTexture;
2929
uniform sampler2D paperTexture;
3030
uniform sampler2D noiseTexture;
3131
uniform vec3 inkColor;
32+
uniform float noiseScale;
3233
uniform float scale;
3334
uniform float thickness;
3435
uniform float noisiness;
3536
uniform float angle;
3637
uniform float contour;
38+
uniform float divergence;
3739
3840
out vec4 fragColor;
3941
@@ -49,7 +51,7 @@ ${darken}
4951
5052
#define TAU 6.28318530718
5153
52-
#define LEVELS 50
54+
#define LEVELS 10
5355
#define fLEVELS float(LEVELS)
5456
5557
float sampleSrc(in sampler2D src, in vec2 uv) {
@@ -127,29 +129,37 @@ float texh(in vec2 p, in float lum) {
127129
return 1.;
128130
}
129131
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+
130144
void main() {
131145
vec2 size = vec2(textureSize(colorTexture, 0));
132146
133147
float hatch = 0.;
134-
float ss = scale * 1.;
148+
float ss = noiseScale * 1.;
135149
vec2 offset = noisiness * vec2(fbm3(vec3(ss*vUv,1.)), fbm3(vec3(ss*vUv.yx,1.)));
136150
vec2 uv = vUv + offset;
137151
138152
float l = luma(texture(colorTexture, uv).rgb);
139153
l = round(l * float(LEVELS)) / float(LEVELS);
140-
l *= 2.;
141-
hatch = 0.;
154+
//l *= 2.;
155+
hatch = 1.;
142156
143157
float normalEdge = length(sobel(normalTexture, uv, size, 3. * contour));
144158
normalEdge = 1.-aastep(.5, normalEdge);
145159
l *= normalEdge;
160+
l *= 2.;
146161
l = clamp(l, 0., 1.);
147162
148-
float a = angle;
149-
float s = sin(a);
150-
float c = cos(a);
151-
mat2 rot = mat2(c, -s, s, c);
152-
153163
for(int i=0; i<LEVELS; i++) {
154164
float f = float(i)/fLEVELS;
155165
float n = float(i+1)/fLEVELS;
@@ -158,26 +168,25 @@ void main() {
158168
normalEdge = aastep(.5, normalEdge);
159169
160170
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);
164172
vec2 offset = noisiness * vec2(fbm3(vec3(ss*vUv,1.)), fbm3(vec3(ss*vUv.yx,1.)));
173+
vec2 uv = vUv + offset;
165174
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;
176185
}
177186
}
178187
179188
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);
181190
//fragColor.rgb = blendDarken(fragColor.rgb, inkColor/255., 1.-normalEdge);
182191
fragColor.a = 1.;
183192
}
@@ -189,13 +198,14 @@ class Post {
189198
this.colorFBO = getFBO(1, 1);
190199
this.normalFBO = getFBO(1, 1);
191200
this.params = {
192-
scale: 0.72,
201+
scale: 0.5,
202+
noiseScale: 0.72,
193203
angle: 2,
194-
randomness: 0,
195-
thickness: 0.7,
204+
divergence: 1,
205+
thickness: 0.72,
196206
contour: 1.2,
197207
noisiness: 0.007,
198-
inkColor: new Color(18, 119, 140),
208+
inkColor: new Color(68, 107, 147),
199209
};
200210
const shader = new RawShaderMaterial({
201211
uniforms: {
@@ -205,9 +215,10 @@ class Post {
205215
noiseTexture: { value: noiseTexture },
206216
inkColor: { value: this.params.inkColor },
207217
scale: { value: this.params.scale },
208-
randomness: { value: this.params.randomness },
218+
divergence: { value: this.params.divergence },
209219
thickness: { value: this.params.thickness },
210220
contour: { value: this.params.contour },
221+
noiseScale: { value: this.params.noiseScale },
211222
noisiness: { value: this.params.noisiness },
212223
angle: { value: this.params.angle },
213224
},
@@ -238,24 +249,29 @@ class Post {
238249
generateParams(gui) {
239250
const controllers = {};
240251
controllers["scale"] = gui
241-
.add(this.params, "scale", 0.1, 1)
252+
.add(this.params, "scale", 0.1, 2)
242253
.onChange(async (v) => {
243254
this.renderPass.shader.uniforms.scale.value = v;
244255
});
245256
controllers["thickness"] = gui
246-
.add(this.params, "thickness", 0, 5)
257+
.add(this.params, "thickness", 0, 1)
247258
.onChange(async (v) => {
248259
this.renderPass.shader.uniforms.thickness.value = v;
249260
});
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+
});
250266
controllers["noisiness"] = gui
251267
.add(this.params, "noisiness", 0, 0.02)
252268
.onChange(async (v) => {
253269
this.renderPass.shader.uniforms.noisiness.value = v;
254270
});
255-
controllers["randomness"] = gui
256-
.add(this.params, "randomness", 0, 0.02)
271+
controllers["divergence"] = gui
272+
.add(this.params, "divergence", 0, 1)
257273
.onChange(async (v) => {
258-
this.renderPass.shader.uniforms.randomness.value = v;
274+
this.renderPass.shader.uniforms.divergence.value = v;
259275
});
260276
controllers["angle"] = gui
261277
.add(this.params, "angle", 0, Math.PI)

snapshots/post-lines-i.jpg

776 KB
Loading

0 commit comments

Comments
 (0)