@poggi/three-effects 0.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BasePass.d.ts +14 -0
- package/BasePass.js +54 -0
- package/BloomPass.d.ts +9 -0
- package/BloomPass.js +69 -0
- package/OutlinePass.d.ts +7 -0
- package/OutlinePass.js +48 -0
- package/antiAliasPass.d.ts +4 -0
- package/index.d.ts +5 -0
- package/index.js +19 -0
- package/package.json +20 -0
- package/types.d.ts +19 -0
package/BasePass.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Scene } from 'three';
|
|
2
|
+
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
|
|
3
|
+
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
|
|
4
|
+
import { Container } from '@poggi/three-core';
|
|
5
|
+
export declare class BasePass {
|
|
6
|
+
private container;
|
|
7
|
+
composer: EffectComposer;
|
|
8
|
+
renderPass: RenderPass;
|
|
9
|
+
renderBeforeFunc?: () => void;
|
|
10
|
+
renderAfterFunc?: () => void;
|
|
11
|
+
constructor(container: Container, garden: Scene, msaa?: boolean);
|
|
12
|
+
colorCorrection(): void;
|
|
13
|
+
render(delta?: number): void;
|
|
14
|
+
}
|
package/BasePass.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { Vector2, WebGLRenderTarget, SRGBColorSpace, UnsignedByteType, RGBAFormat } from "three";
|
|
8
|
+
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
|
|
9
|
+
import { RenderPass } from "three/examples/jsm/postprocessing/RenderPass.js";
|
|
10
|
+
import { OutputPass } from "three/examples/jsm/postprocessing/OutputPass.js";
|
|
11
|
+
class BasePass {
|
|
12
|
+
//渲染后逻辑
|
|
13
|
+
constructor(container, garden, msaa) {
|
|
14
|
+
__publicField(this, "container");
|
|
15
|
+
__publicField(this, "composer");
|
|
16
|
+
__publicField(this, "renderPass");
|
|
17
|
+
__publicField(this, "renderBeforeFunc");
|
|
18
|
+
//渲染前逻辑
|
|
19
|
+
__publicField(this, "renderAfterFunc");
|
|
20
|
+
this.container = container;
|
|
21
|
+
const size = container.renderer.getDrawingBufferSize(new Vector2());
|
|
22
|
+
if (msaa) {
|
|
23
|
+
const renderTarget = new WebGLRenderTarget(size.width, size.height, {
|
|
24
|
+
samples: 4,
|
|
25
|
+
format: RGBAFormat,
|
|
26
|
+
type: UnsignedByteType,
|
|
27
|
+
colorSpace: SRGBColorSpace
|
|
28
|
+
});
|
|
29
|
+
this.composer = new EffectComposer(container.renderer, renderTarget);
|
|
30
|
+
this.composer.setSize(this.container.sizes.width, this.container.sizes.height);
|
|
31
|
+
} else {
|
|
32
|
+
this.composer = new EffectComposer(this.container.renderer);
|
|
33
|
+
this.composer.setSize(this.container.sizes.width, this.container.sizes.height);
|
|
34
|
+
}
|
|
35
|
+
const renderPass = new RenderPass(garden, this.container.camera);
|
|
36
|
+
this.composer.addPass(renderPass);
|
|
37
|
+
this.renderPass = renderPass;
|
|
38
|
+
}
|
|
39
|
+
// 色彩修正
|
|
40
|
+
colorCorrection() {
|
|
41
|
+
const outputpass = new OutputPass();
|
|
42
|
+
this.composer.addPass(outputpass);
|
|
43
|
+
}
|
|
44
|
+
render(delta) {
|
|
45
|
+
if (this.renderBeforeFunc)
|
|
46
|
+
this.renderBeforeFunc();
|
|
47
|
+
this.composer.render(delta);
|
|
48
|
+
if (this.renderAfterFunc)
|
|
49
|
+
this.renderAfterFunc();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
BasePass
|
|
54
|
+
};
|
package/BloomPass.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Container, Scene } from '@poggi/three-core';
|
|
2
|
+
import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js';
|
|
3
|
+
import { BasePass } from './BasePass';
|
|
4
|
+
import { IBloomParameter } from './types';
|
|
5
|
+
declare const createBloomPass: (container: Container, garden: Scene, basePass: BasePass, parameter?: IBloomParameter) => {
|
|
6
|
+
bloomRender: () => void;
|
|
7
|
+
mixPass: ShaderPass;
|
|
8
|
+
};
|
|
9
|
+
export { createBloomPass, };
|
package/BloomPass.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { MeshBasicMaterial, Layers, Vector2, ShaderMaterial, Mesh } from "@poggi/three-core";
|
|
2
|
+
import { EffectComposer } from "three/examples/jsm/postprocessing/EffectComposer.js";
|
|
3
|
+
import { UnrealBloomPass } from "three/examples/jsm/postprocessing/UnrealBloomPass.js";
|
|
4
|
+
import { ShaderPass } from "three/examples/jsm/postprocessing/ShaderPass.js";
|
|
5
|
+
const darkMaterial = new MeshBasicMaterial({ color: "black" });
|
|
6
|
+
const createBloomPass = function(container, garden, basePass, parameter) {
|
|
7
|
+
const bloomLayer = new Layers();
|
|
8
|
+
bloomLayer.set((parameter == null ? void 0 : parameter.layer) || 1);
|
|
9
|
+
const bloomPass = new UnrealBloomPass(
|
|
10
|
+
new Vector2(container.sizes.width, container.sizes.height),
|
|
11
|
+
(parameter == null ? void 0 : parameter.strength) || 1,
|
|
12
|
+
(parameter == null ? void 0 : parameter.radius) || 0.4,
|
|
13
|
+
(parameter == null ? void 0 : parameter.threshold) || 0
|
|
14
|
+
);
|
|
15
|
+
const bloomComposer = new EffectComposer(container.renderer);
|
|
16
|
+
bloomComposer.renderToScreen = false;
|
|
17
|
+
bloomComposer.addPass(basePass.renderPass);
|
|
18
|
+
bloomComposer.addPass(bloomPass);
|
|
19
|
+
const mixPass = new ShaderPass(
|
|
20
|
+
new ShaderMaterial({
|
|
21
|
+
uniforms: {
|
|
22
|
+
baseTexture: { value: null },
|
|
23
|
+
bloomTexture: { value: bloomComposer.renderTarget2.texture }
|
|
24
|
+
},
|
|
25
|
+
vertexShader: `
|
|
26
|
+
varying vec2 vUv;
|
|
27
|
+
void main() {
|
|
28
|
+
vUv = uv;
|
|
29
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
30
|
+
}
|
|
31
|
+
`,
|
|
32
|
+
fragmentShader: `
|
|
33
|
+
uniform sampler2D baseTexture;
|
|
34
|
+
uniform sampler2D bloomTexture;
|
|
35
|
+
varying vec2 vUv;
|
|
36
|
+
void main() {
|
|
37
|
+
gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );
|
|
38
|
+
}
|
|
39
|
+
`,
|
|
40
|
+
defines: {}
|
|
41
|
+
}),
|
|
42
|
+
"baseTexture"
|
|
43
|
+
);
|
|
44
|
+
mixPass.needsSwap = true;
|
|
45
|
+
basePass.composer.addPass(mixPass);
|
|
46
|
+
const materials = {};
|
|
47
|
+
const bloomRender = function() {
|
|
48
|
+
garden.traverse((child) => {
|
|
49
|
+
if (child instanceof Mesh && bloomLayer.test(child.layers) === false) {
|
|
50
|
+
materials[child.uuid] = child.material;
|
|
51
|
+
child.material = darkMaterial;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
bloomComposer.render();
|
|
55
|
+
garden.traverse((child) => {
|
|
56
|
+
if (child instanceof Mesh && materials[child.uuid]) {
|
|
57
|
+
child.material = materials[child.uuid];
|
|
58
|
+
delete materials[child.uuid];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
bloomRender,
|
|
64
|
+
mixPass
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
export {
|
|
68
|
+
createBloomPass
|
|
69
|
+
};
|
package/OutlinePass.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Container, Object3D, Scene } from '@poggi/three-core';
|
|
2
|
+
import { OutlinePass } from 'three/examples/jsm/postprocessing/OutlinePass.js';
|
|
3
|
+
import { IOutlineParameter } from './types';
|
|
4
|
+
declare const createOutlinePass: (container: Container, garden: Scene, parameter?: IOutlineParameter) => OutlinePass | undefined;
|
|
5
|
+
declare const addObjectsToOutline: (outlinePass: OutlinePass, objs: Object3D | Object3D[]) => void;
|
|
6
|
+
declare const removeFromOutline: (outlinePass: OutlinePass, obj: Object3D) => void;
|
|
7
|
+
export { OutlinePass, createOutlinePass, addObjectsToOutline, removeFromOutline };
|
package/OutlinePass.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Vector2 } from "@poggi/three-core";
|
|
2
|
+
import { OutlinePass } from "three/examples/jsm/postprocessing/OutlinePass.js";
|
|
3
|
+
import { OutlinePass as OutlinePass2 } from "three/examples/jsm/postprocessing/OutlinePass.js";
|
|
4
|
+
import { Console } from "@poggi/utils";
|
|
5
|
+
const createOutlinePass = function(container, garden, parameter = {}) {
|
|
6
|
+
if (!container.camera) {
|
|
7
|
+
Console.error("[@poggi/three-effects]: OutlinePass: 还未挂载摄像机");
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let resolution, outlinePass;
|
|
11
|
+
resolution = new Vector2(container.sizes.width, container.sizes.height);
|
|
12
|
+
outlinePass = new OutlinePass(resolution, garden, container.camera);
|
|
13
|
+
outlinePass.edgeStrength = parameter.edgeStrength || 10;
|
|
14
|
+
if (parameter.edgeGlow)
|
|
15
|
+
outlinePass.edgeGlow = parameter.edgeGlow;
|
|
16
|
+
outlinePass.edgeThickness = parameter.edgeThickness || 4;
|
|
17
|
+
if (parameter.pulsePeriod)
|
|
18
|
+
outlinePass.pulsePeriod = parameter.pulsePeriod;
|
|
19
|
+
outlinePass.visibleEdgeColor.setHex(parameter.visibleEdgeColor || 65280);
|
|
20
|
+
outlinePass.hiddenEdgeColor.setHex(parameter.hiddenEdgeColor || 16701184);
|
|
21
|
+
return outlinePass;
|
|
22
|
+
};
|
|
23
|
+
const addObjectsToOutlineSingle = function(outlinePass, obj) {
|
|
24
|
+
const idx = outlinePass.selectedObjects.findIndex((item) => item.uuid === obj.uuid);
|
|
25
|
+
if (idx !== -1) {
|
|
26
|
+
outlinePass.selectedObjects.splice(idx);
|
|
27
|
+
}
|
|
28
|
+
outlinePass.selectedObjects.push(obj);
|
|
29
|
+
};
|
|
30
|
+
const addObjectsToOutline = function(outlinePass, objs) {
|
|
31
|
+
if (Array.isArray(objs)) {
|
|
32
|
+
objs.forEach((item) => {
|
|
33
|
+
addObjectsToOutlineSingle(outlinePass, item);
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
addObjectsToOutlineSingle(outlinePass, objs);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const removeFromOutline = function(outlinePass, obj) {
|
|
40
|
+
const idx = outlinePass.selectedObjects.findIndex((item) => item.uuid === obj.uuid);
|
|
41
|
+
idx !== -1 && outlinePass.selectedObjects.splice(idx, 1);
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
OutlinePass2 as OutlinePass,
|
|
45
|
+
addObjectsToOutline,
|
|
46
|
+
createOutlinePass,
|
|
47
|
+
removeFromOutline
|
|
48
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SMAAPass } from 'three/examples/jsm/postprocessing/SMAAPass.js';
|
|
2
|
+
import { FXAAPass } from 'three/examples/jsm/postprocessing/FXAAPass.js';
|
|
3
|
+
import { SSAARenderPass } from 'three/examples/jsm/postprocessing/SSAARenderPass.js';
|
|
4
|
+
export { SMAAPass, FXAAPass, SSAARenderPass, };
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BasePass } from "./BasePass.js";
|
|
2
|
+
import { addObjectsToOutline, createOutlinePass, removeFromOutline } from "./OutlinePass.js";
|
|
3
|
+
import { createBloomPass } from "./BloomPass.js";
|
|
4
|
+
import { SMAAPass } from "three/examples/jsm/postprocessing/SMAAPass.js";
|
|
5
|
+
import { FXAAPass } from "three/examples/jsm/postprocessing/FXAAPass.js";
|
|
6
|
+
import { SSAARenderPass } from "three/examples/jsm/postprocessing/SSAARenderPass.js";
|
|
7
|
+
export * from "three/examples/jsm/postprocessing/SSRPass.js";
|
|
8
|
+
import { OutlinePass } from "three/examples/jsm/postprocessing/OutlinePass.js";
|
|
9
|
+
export {
|
|
10
|
+
BasePass,
|
|
11
|
+
FXAAPass,
|
|
12
|
+
OutlinePass,
|
|
13
|
+
SMAAPass,
|
|
14
|
+
SSAARenderPass,
|
|
15
|
+
addObjectsToOutline,
|
|
16
|
+
createBloomPass,
|
|
17
|
+
createOutlinePass,
|
|
18
|
+
removeFromOutline
|
|
19
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@poggi/three-effects",
|
|
3
|
+
"version": "0.0.1-alpha.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"description": "三维后期特效",
|
|
7
|
+
"author": "poggi",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"typings": "./index.d.ts",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"three": "^0.185.1"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@poggi/three-core": "0.0.1-alpha.0"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"registry": "https://registry.npmjs.org/"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare enum EAntiAlias {
|
|
2
|
+
SSAA = 0,
|
|
3
|
+
FXAA = 1,
|
|
4
|
+
SMAA = 2
|
|
5
|
+
}
|
|
6
|
+
export interface IOutlineParameter {
|
|
7
|
+
edgeStrength?: number;
|
|
8
|
+
edgeGlow?: number;
|
|
9
|
+
edgeThickness?: number;
|
|
10
|
+
pulsePeriod?: number;
|
|
11
|
+
visibleEdgeColor?: number;
|
|
12
|
+
hiddenEdgeColor?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface IBloomParameter {
|
|
15
|
+
layer?: number;
|
|
16
|
+
strength?: number;
|
|
17
|
+
radius?: number;
|
|
18
|
+
threshold?: number;
|
|
19
|
+
}
|