MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / blurInto

Method blurInto

src/main/java/fieldbox/ui/Compositor.java:315–372  ·  view source on GitHub ↗
(int taps, Scene s, String access)

Source from the content-addressed store, hash-verified

313// }
314
315 protected void blurInto(int taps, Scene s, String access) {
316 BaseMesh mesh = BaseMesh.triangleList(4, 2);
317 MeshBuilder mb = new MeshBuilder(mesh);
318 mb.v(-1, -1, 0);
319 mb.v(1, -1, 0);
320 mb.v(1, 1, 0);
321 mb.v(-1, 1, 0);
322 mb.e_quad(0, 1, 2, 3);
323 Shader shader = new Shader();
324
325 shader.addSource(Shader.Type.vertex, "#version 410\n" +
326 "layout(location=0) in vec3 position;\n" +
327 "out vec2 tc;\n" +
328 "void main()\n" +
329 "{\n" +
330 " gl_Position = vec4(position.xy, 0.5, 1.0);\n" +
331 " tc = vec2(position.xy+vec2(1,1))/2;\n" +
332 "}");
333
334 String we = "";
335 float[] weight = new float[taps * 2 + 1];
336 float tot = 0;
337 for (int i = -taps; i < taps + 1; i++) {
338 weight[i + taps] = (float) Math.exp(-Math.pow(1.1f * i / (float) (taps+1), 2));
339 tot += weight[i + taps];
340 }
341
342 for (int i = -taps; i < taps + 1; i++) {
343 we = we + (weight[i + taps] / tot) + ",";
344 }
345 we = we.substring(0, we.length() - 1);
346 shader.addSource(Shader.Type.fragment, "#version 410\n" +
347 "layout(location=0) out vec4 _output;\n" +
348 "uniform sampler2D te;\n" +
349 "uniform vec2 bounds;\n" +
350 "in vec2 tc;\n" +
351 "ivec2 cl(ivec2 v)" +
352 "{" +
353// " return v;\n"+
354 " return clamp(v, ivec2(0,0), ivec2(bounds));\n" +
355 "}" +
356 "void main()\n" +
357 "{\n" +
358 " vec4 t = vec4(0);" +
359 " const float[" + (taps * 2 + 1) + "] we = float[" + (taps * 2 + 1) + "](" + we + ");\n" +
360 " int n = " + taps + ";" +
361// " for(int i=-n;i<n+1;i++) t+=we[i+n]*texelFetch(te, cl(ivec2(gl_FragCoord.xy)+"+access+"),0);" +
362 " for(int i=-n;i<n+1;i++) t+=we[i+n]*texture(te, tc+" + access + ");" +
363 " _output = vec4(t.xyz,1);\n" +
364 "\n" +
365 "}");
366 shader.attach(new Uniform<Vec2>("bounds", () -> new Vec2(fbo.specification.width - 1, fbo.specification.height - 1)));
367 s.attach(mesh);
368 mesh.attach(shader);
369 guard = new Guard(() -> fbo, (i) -> true);
370 mesh.attach(guard);
371
372 }

Callers 2

blurXIntoMethod · 0.95
blurYIntoMethod · 0.95

Calls 6

triangleListMethod · 0.95
vMethod · 0.95
e_quadMethod · 0.95
addSourceMethod · 0.95
lengthMethod · 0.45
attachMethod · 0.45

Tested by

no test coverage detected