Skip to content

Commit

Permalink
Merge pull request #385 from pmndrs/dev
Browse files Browse the repository at this point in the history
Version 6.28.4
  • Loading branch information
vanruesc authored Jul 17, 2022
2 parents 0942821 + 3138f0a commit 817192f
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 83 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postprocessing",
"version": "6.28.3",
"version": "6.28.4",
"description": "A post processing library that provides the means to implement image filter effects for three.js.",
"homepage": "https://github.com/pmndrs/postprocessing",
"main": "build/postprocessing.js",
Expand Down
74 changes: 37 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 2 additions & 14 deletions src/materials/DownsamplingMaterial.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NoBlending, ShaderMaterial, Uniform, Vector2 } from "three";

import fragmentShader from "./glsl/convolution.downsampling.frag";
import vertexShader from "./glsl/common.vert";
import vertexShader from "./glsl/convolution.downsampling.vert";

/**
* A downsampling material.
Expand All @@ -22,21 +22,9 @@ export class DownsamplingMaterial extends ShaderMaterial {

super({
name: "DownsamplingMaterial",
defines: {
SAMPLES: "13"
},
uniforms: {
inputBuffer: new Uniform(null),
texelSize: new Uniform(new Vector2()),
kernel: new Uniform(new Float32Array([
// (1 / 4) * 0.5 = 0.125
-1.0, 1.0, 0.125, 1.0, 1.0, 0.125,
-1.0, -1.0, 0.125, 1.0, -1.0, 0.125,
// (1 / 9) * 0.5 = 0.0555555
-2.0, 2.0, 0.0555555, 0.0, 2.0, 0.0555555, 2.0, 2.0, 0.0555555,
-2.0, 0.0, 0.0555555, 0.0, 0.0, 0.0555555, 2.0, 0.0, 0.0555555,
-2.0, -2.0, 0.0555555, 0.0, -2.0, 0.0555555, 2.0, -2.0, 0.0555555
]))
texelSize: new Uniform(new Vector2())
},
blending: NoBlending,
depthWrite: false,
Expand Down
12 changes: 2 additions & 10 deletions src/materials/UpsamplingMaterial.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NoBlending, ShaderMaterial, Uniform, Vector2 } from "three";

import fragmentShader from "./glsl/convolution.upsampling.frag";
import vertexShader from "./glsl/common.vert";
import vertexShader from "./glsl/convolution.upsampling.vert";

/**
* An upsampling material.
Expand All @@ -22,19 +22,11 @@ export class UpsamplingMaterial extends ShaderMaterial {

super({
name: "UpsamplingMaterial",
defines: {
SAMPLES: "9"
},
uniforms: {
inputBuffer: new Uniform(null),
supportBuffer: new Uniform(null),
texelSize: new Uniform(new Vector2()),
radius: new Uniform(0.85),
kernel: new Uniform(new Float32Array([
-1.0, 1.0, 0.0625, 0.0, 1.0, 0.125, 1.0, 1.0, 0.0625,
-1.0, 0.0, 0.125, 0.0, 0.0, 0.25, 1.0, 0.0, 0.125,
-1.0, -1.0, 0.0625, 0.0, -1.0, 0.125, 1.0, -1.0, 0.0625
]))
radius: new Uniform(0.85)
},
blending: NoBlending,
depthWrite: false,
Expand Down
62 changes: 56 additions & 6 deletions src/materials/glsl/convolution.downsampling.frag
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,72 @@

#endif

uniform vec2 texelSize;
uniform vec3 kernel[SAMPLES];
// (1 / 4) * 0.5 = 0.125
#define WEIGHT_INNER 0.125
// (1 / 9) * 0.5 = 0.0555555
#define WEIGHT_OUTER 0.0555555

varying vec2 vUv;
varying vec2 vUv00;
varying vec2 vUv01;
varying vec2 vUv02;
varying vec2 vUv03;
varying vec2 vUv04;
varying vec2 vUv05;
varying vec2 vUv06;
varying vec2 vUv07;
varying vec2 vUv08;
varying vec2 vUv09;
varying vec2 vUv10;
varying vec2 vUv11;

float clampToBorder(const in vec2 uv) {

return float(uv.s >= 0.0 && uv.s <= 1.0 && uv.t >= 0.0 && uv.t <= 1.0);

}

void main() {

vec4 c = vec4(0.0);

for(int i = 0; i < SAMPLES; ++i) {
vec4 w = WEIGHT_INNER * vec4(
clampToBorder(vUv00),
clampToBorder(vUv01),
clampToBorder(vUv02),
clampToBorder(vUv03)
);

c += w.x * texture2D(inputBuffer, vUv00);
c += w.y * texture2D(inputBuffer, vUv01);
c += w.z * texture2D(inputBuffer, vUv02);
c += w.w * texture2D(inputBuffer, vUv03);

w = WEIGHT_OUTER * vec4(
clampToBorder(vUv04),
clampToBorder(vUv05),
clampToBorder(vUv06),
clampToBorder(vUv07)
);

c += w.x * texture2D(inputBuffer, vUv04);
c += w.y * texture2D(inputBuffer, vUv05);
c += w.z * texture2D(inputBuffer, vUv06);
c += w.w * texture2D(inputBuffer, vUv07);

vec2 uv = vUv + kernel[i].xy * texelSize;
c += kernel[i].z * texture2D(inputBuffer, uv);
w = WEIGHT_OUTER * vec4(
clampToBorder(vUv08),
clampToBorder(vUv09),
clampToBorder(vUv10),
clampToBorder(vUv11)
);

}
c += w.x * texture2D(inputBuffer, vUv08);
c += w.y * texture2D(inputBuffer, vUv09);
c += w.z * texture2D(inputBuffer, vUv10);
c += w.w * texture2D(inputBuffer, vUv11);

c += WEIGHT_OUTER * texture2D(inputBuffer, vUv);
gl_FragColor = c;

#include <encodings_fragment>
Expand Down
Loading

0 comments on commit 817192f

Please sign in to comment.