forked from pmndrs/postprocessing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpsamplingMaterial.js
More file actions
99 lines (71 loc) · 1.6 KB
/
UpsamplingMaterial.js
File metadata and controls
99 lines (71 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { NoBlending, ShaderMaterial, Uniform, Vector2 } from "three";
import { updateFragmentShader } from "../utils/index.js";
import fragmentShader from "./glsl/convolution.upsampling.frag";
import vertexShader from "./glsl/convolution.upsampling.vert";
/**
* An upsampling material.
*
* Based on an article by Fabrice Piquet:
* https://www.froyok.fr/blog/2021-12-ue4-custom-bloom/
*
* @implements {Resizable}
*/
export class UpsamplingMaterial extends ShaderMaterial {
/**
* Constructs a new upsampling material.
*/
constructor() {
super({
name: "UpsamplingMaterial",
uniforms: {
inputBuffer: new Uniform(null),
supportBuffer: new Uniform(null),
texelSize: new Uniform(new Vector2()),
radius: new Uniform(0.85)
},
blending: NoBlending,
toneMapped: false,
depthWrite: false,
depthTest: false,
fragmentShader,
vertexShader
});
this.fragmentShader = updateFragmentShader(this.fragmentShader);
}
/**
* The input buffer.
*
* @type {Texture}
*/
set inputBuffer(value) {
this.uniforms.inputBuffer.value = value;
}
/**
* A support buffer.
*
* @type {Texture}
*/
set supportBuffer(value) {
this.uniforms.supportBuffer.value = value;
}
/**
* The blur radius.
*
* @type {Number}
*/
get radius() {
return this.uniforms.radius.value;
}
set radius(value) {
this.uniforms.radius.value = value;
}
/**
* Sets the size of this object.
*
* @param {Number} width - The width.
* @param {Number} height - The height.
*/
setSize(width, height) {
this.uniforms.texelSize.value.set(1.0 / width, 1.0 / height);
}
}