Skip to content

Commit ba92ef5

Browse files
committed
Create LuminanceHighPassMaterial
1 parent cfd7f6d commit ba92ef5

File tree

5 files changed

+91
-7
lines changed

5 files changed

+91
-7
lines changed

src/effects/BloomEffect.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Uniform } from "three";
22
import { LuminancePass } from "../passes/LuminancePass.js";
33
import { MipmapBlurPass, MipmapBlurPassOptions } from "../passes/MipmapBlurPass.js";
4-
import { LuminanceMaterial } from "../materials/LuminanceMaterial.js";
4+
import { LuminanceHighPassMaterial } from "../materials/LuminanceHighPassMaterial.js";
55
import { AddBlendFunction } from "./blending/blend-functions/AddBlendFunction.js";
66
import { Effect } from "./Effect.js";
77

@@ -92,7 +92,6 @@ export class BloomEffect extends Effect implements BloomEffectOptions {
9292
const luminanceMaterial = this.luminanceMaterial;
9393
luminanceMaterial.threshold = luminanceThreshold;
9494
luminanceMaterial.smoothing = luminanceSmoothing;
95-
luminanceMaterial.colorOutput = true;
9695

9796
const mipmapBlurPass = new MipmapBlurPass({ levels, radius, fullResolutionUpsampling, clampToBorder });
9897
this.mipmapBlurPass = mipmapBlurPass;
@@ -110,7 +109,7 @@ export class BloomEffect extends Effect implements BloomEffectOptions {
110109
* The luminance high-pass material.
111110
*/
112111

113-
get luminanceMaterial(): LuminanceMaterial {
112+
get luminanceMaterial(): LuminanceHighPassMaterial {
114113

115114
return this.luminancePass.fullscreenMaterial;
116115

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { Uniform } from "three";
2+
import { FullscreenMaterial } from "./FullscreenMaterial.js";
3+
4+
import fragmentShader from "./shaders/luminance-high-pass.frag";
5+
import vertexShader from "./shaders/common.vert";
6+
7+
/**
8+
* A luminance high-pass shader material.
9+
*
10+
* @see https://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9
11+
* @see https://hsto.org/getpro/habr/post_images/2ab/69d/084/2ab69d084f9a597e032624bcd74d57a7.png
12+
* @category Materials
13+
*/
14+
15+
export class LuminanceHighPassMaterial extends FullscreenMaterial {
16+
17+
/**
18+
* Constructs a new luminance high-pass material.
19+
*/
20+
21+
constructor() {
22+
23+
super({
24+
name: "LuminanceHighPassMaterial",
25+
fragmentShader,
26+
vertexShader,
27+
uniforms: {
28+
threshold: new Uniform(0.0),
29+
smoothing: new Uniform(0.0)
30+
}
31+
});
32+
33+
}
34+
35+
/**
36+
* The luminance threshold.
37+
*/
38+
39+
get threshold(): number {
40+
41+
return this.uniforms.threshold.value as number;
42+
43+
}
44+
45+
set threshold(value: number) {
46+
47+
this.uniforms.threshold.value = value;
48+
49+
}
50+
51+
/**
52+
* The luminance smoothing.
53+
*/
54+
55+
get smoothing(): number {
56+
57+
return this.uniforms.smoothing.value as number;
58+
59+
}
60+
61+
set smoothing(value: number) {
62+
63+
this.uniforms.smoothing.value = value;
64+
65+
}
66+
67+
}

src/materials/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export * from "./EffectMaterial.js";
1212
export * from "./FullscreenMaterial.js";
1313
export * from "./GaussianBlurMaterial.js";
1414
export * from "./KawaseBlurMaterial.js";
15-
export * from "./LuminanceMaterial.js";
15+
export * from "./LuminanceHighPassMaterial.js";
1616
export * from "./MaskMaterial.js";
1717
export * from "./SkyBoxMaterial.js";
1818
export * from "./SMAAEdgeDetectionMaterial.js";
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <common>
2+
#include <pp_default_output_pars_fragment>
3+
#include <pp_input_buffer_pars_fragment>
4+
5+
uniform float threshold;
6+
uniform float smoothing;
7+
8+
in vec2 vUv;
9+
10+
void main() {
11+
12+
vec4 texel = texture(inputBuffer, vUv);
13+
float l = luminance(texel.rgb);
14+
float mask = smoothstep(threshold, threshold + smoothing, l);
15+
16+
out_Color = texel * mask;
17+
18+
}

src/passes/LuminancePass.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { WebGLRenderTarget } from "three";
22
import { TextureResource } from "../core/io/TextureResource.js";
33
import { Pass } from "../core/Pass.js";
4-
import { LuminanceMaterial } from "../materials/LuminanceMaterial.js";
4+
import { LuminanceHighPassMaterial } from "../materials/LuminanceHighPassMaterial.js";
55

66
/**
77
* A luminance pass.
88
*
99
* @category Passes
1010
*/
1111

12-
export class LuminancePass extends Pass<LuminanceMaterial> {
12+
export class LuminancePass extends Pass<LuminanceHighPassMaterial> {
1313

1414
/**
1515
* Identifies the luminance output buffer.
@@ -26,7 +26,7 @@ export class LuminancePass extends Pass<LuminanceMaterial> {
2626
super("LuminancePass");
2727

2828
this.output.setBuffer(LuminancePass.BUFFER_LUMINANCE, this.createFramebuffer());
29-
this.fullscreenMaterial = new LuminanceMaterial();
29+
this.fullscreenMaterial = new LuminanceHighPassMaterial();
3030

3131
}
3232

0 commit comments

Comments
 (0)