three-base 2.0.134 → 2.0.142
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/DirectionalLight.d.ts +6 -6
- package/DirectionalLight.js +68 -68
- package/DirectionalLight.ts +70 -0
- package/EventMap.d.ts +103 -0
- package/EventMap.js +17 -0
- package/EventMap.ts +139 -0
- package/EventMesh.d.ts +18 -18
- package/EventMesh.js +59 -59
- package/EventMesh.ts +60 -0
- package/ExtrudeMesh.d.ts +112 -112
- package/ExtrudeMesh.js +342 -366
- package/ExtrudeMesh.ts +553 -0
- package/FPScontrol.d.ts +511 -71
- package/FPScontrol.js +1799 -505
- package/FPScontrol.ts +1855 -0
- package/Fire/Fire.d.ts +28 -28
- package/Fire/Fire.js +80 -79
- package/Fire/Fire.ts +89 -0
- package/Fire/{FireGromtry.d.ts → FireGeometry.d.ts} +9 -9
- package/Fire/{FireGromtry.js → FireGeometry.js} +40 -40
- package/Fire/FireGeometry.ts +40 -0
- package/Fire/FireMaterial.d.ts +28 -28
- package/Fire/FireMaterial.js +32 -32
- package/Fire/FireMaterial.ts +89 -0
- package/Fire/index.d.ts +2 -1
- package/Fire/index.js +2 -1
- package/Fire/index.ts +2 -0
- package/GLTFDracoLoader.d.ts +71 -0
- package/GLTFDracoLoader.js +266 -0
- package/GLTFDracoLoader.ts +430 -0
- package/Grass/Grass.d.ts +8 -8
- package/Grass/Grass.js +38 -38
- package/Grass/Grass.ts +38 -0
- package/Grass/index.d.ts +2 -1
- package/Grass/index.js +2 -1
- package/Grass/index.ts +2 -0
- package/Ground1/Ground1.d.ts +10 -11
- package/Ground1/Ground1.js +95 -91
- package/Ground1/Ground1.ts +114 -0
- package/Ground1/index.d.ts +1 -1
- package/Ground1/index.js +1 -1
- package/Ground1/index.ts +1 -0
- package/MeshBase.d.ts +36 -35
- package/MeshBase.js +247 -223
- package/MeshBase.ts +253 -0
- package/Mirror.d.ts +25 -25
- package/Mirror.js +143 -139
- package/Mirror.ts +203 -0
- package/MktMesh/MktMesh.d.ts +291 -0
- package/MktMesh/MktMesh.js +1045 -0
- package/MktMesh/MktMesh.ts +1075 -0
- package/MktMesh/assetUrl.d.ts +35 -0
- package/MktMesh/assetUrl.js +69 -0
- package/MktMesh/assetUrl.ts +69 -0
- package/MktMesh/mktMappingShader.d.ts +12 -0
- package/MktMesh/mktMappingShader.js +139 -0
- package/MktMesh/mktMappingShader.ts +139 -0
- package/MktMesh/mktShader.d.ts +263 -0
- package/MktMesh/mktShader.js +1248 -0
- package/MktMesh/mktShader.ts +1344 -0
- package/MktMesh/panoBitmapTexture.d.ts +25 -0
- package/MktMesh/panoBitmapTexture.js +52 -0
- package/MktMesh/panoBitmapTexture.ts +54 -0
- package/MktMesh/panoSlotBind.d.ts +29 -0
- package/MktMesh/panoSlotBind.js +106 -0
- package/MktMesh/panoSlotBind.ts +153 -0
- package/MktMesh/panoSlotRoster.d.ts +22 -0
- package/MktMesh/panoSlotRoster.js +169 -0
- package/MktMesh/panoSlotRoster.ts +168 -0
- package/MktMesh/panoTileStitcher.d.ts +119 -0
- package/MktMesh/panoTileStitcher.js +533 -0
- package/MktMesh/panoTileStitcher.ts +616 -0
- package/MktMesh/types.d.ts +75 -0
- package/MktMesh/types.js +1 -0
- package/MktMesh/types.ts +87 -0
- package/MktMesh/wallCapTessellate.d.ts +33 -0
- package/MktMesh/wallCapTessellate.js +97 -0
- package/MktMesh/wallCapTessellate.ts +68 -0
- package/PipeMesh/PathGeometry.d.ts +44 -44
- package/PipeMesh/PathGeometry.js +307 -300
- package/PipeMesh/PathGeometry.ts +343 -0
- package/PipeMesh/PathPoint.d.ts +17 -17
- package/PipeMesh/PathPoint.js +31 -31
- package/PipeMesh/PathPoint.ts +36 -0
- package/PipeMesh/PathPointList.d.ts +31 -31
- package/PipeMesh/PathPointList.js +209 -208
- package/PipeMesh/PathPointList.ts +227 -0
- package/PipeMesh/PathTubeGeometry.d.ts +25 -25
- package/PipeMesh/PathTubeGeometry.js +130 -130
- package/PipeMesh/PathTubeGeometry.ts +146 -0
- package/PipeMesh/PipeMesh.d.ts +25 -25
- package/PipeMesh/PipeMesh.js +63 -63
- package/PipeMesh/PipeMesh.ts +76 -0
- package/PipeMesh/index.d.ts +1 -1
- package/PipeMesh/index.js +1 -1
- package/PipeMesh/index.ts +1 -0
- package/PlaneModal1/PlaneModal1.d.ts +34 -31
- package/PlaneModal1/PlaneModal1.js +109 -105
- package/PlaneModal1/PlaneModal1.ts +138 -0
- package/PlaneModal1/index.d.ts +1 -1
- package/PlaneModal1/index.js +1 -1
- package/PlaneModal1/index.ts +1 -0
- package/PlaneText.d.ts +27 -39
- package/PlaneText.js +35 -30
- package/PlaneText.ts +55 -0
- package/PlaneWithHtml.d.ts +13 -11
- package/PlaneWithHtml.js +64 -63
- package/PlaneWithHtml.ts +70 -0
- package/PointLight/PointLight.d.ts +13 -14
- package/PointLight/PointLight.js +64 -70
- package/PointLight/PointLight.ts +67 -0
- package/PointLight/index.d.ts +1 -1
- package/PointLight/index.js +1 -1
- package/PointLight/index.ts +1 -0
- package/README.md +110 -79
- package/Sky/Sky.d.ts +9 -9
- package/Sky/Sky.js +22 -22
- package/Sky/Sky.ts +22 -0
- package/Sky/index.d.ts +1 -1
- package/Sky/index.js +1 -1
- package/Sky/index.ts +1 -0
- package/SpotLight.d.ts +6 -6
- package/SpotLight.js +72 -72
- package/SpotLight.ts +74 -0
- package/SpriteModal1/SpriteModal1.d.ts +33 -30
- package/SpriteModal1/SpriteModal1.js +116 -110
- package/SpriteModal1/SpriteModal1.ts +146 -0
- package/SpriteModal1/index.d.ts +1 -1
- package/SpriteModal1/index.js +1 -1
- package/SpriteModal1/index.ts +1 -0
- package/SpriteText.d.ts +46 -45
- package/SpriteText.js +176 -163
- package/SpriteText.ts +205 -0
- package/SpriteText2.d.ts +48 -47
- package/SpriteText2.js +223 -198
- package/SpriteText2.ts +258 -0
- package/SpriteText3.d.ts +86 -0
- package/SpriteText3.js +519 -0
- package/SpriteText3.ts +599 -0
- package/SpriteWithHtml.d.ts +9 -7
- package/SpriteWithHtml.js +44 -44
- package/SpriteWithHtml.ts +50 -0
- package/Text3D/Text3D.d.ts +20 -20
- package/Text3D/Text3D.js +58 -62
- package/Text3D/Text3D.ts +77 -0
- package/Text3D/fontController.d.ts +60 -59
- package/Text3D/fontController.js +166 -199
- package/Text3D/fontController.ts +209 -0
- package/Text3D/index.d.ts +1 -1
- package/Text3D/index.js +1 -1
- package/Text3D/index.ts +1 -0
- package/ThreeBase.d.ts +248 -97
- package/ThreeBase.js +1202 -613
- package/ThreeBase.ts +1314 -0
- package/ThreeMouse.d.ts +54 -40
- package/ThreeMouse.js +453 -407
- package/ThreeMouse.ts +472 -0
- package/Transition.d.ts +45 -40
- package/Transition.js +209 -210
- package/Transition.ts +242 -0
- package/Water/Water.d.ts +5 -5
- package/Water/Water.js +44 -26
- package/Water/Water.ts +45 -0
- package/Water/index.d.ts +2 -0
- package/Water/index.js +2 -0
- package/Water/index.ts +2 -0
- package/WaterFlow/FloatingDuck.d.ts +88 -0
- package/WaterFlow/FloatingDuck.js +307 -0
- package/WaterFlow/FloatingDuck.ts +445 -0
- package/WaterFlow/GPUFluidSimulation.d.ts +56 -0
- package/WaterFlow/GPUFluidSimulation.js +785 -0
- package/WaterFlow/GPUFluidSimulation.ts +827 -0
- package/WaterFlow/ReservoirSystem.d.ts +106 -0
- package/WaterFlow/ReservoirSystem.js +621 -0
- package/WaterFlow/ReservoirSystem.ts +754 -0
- package/WaterFlow/SPHField.d.ts +35 -0
- package/WaterFlow/SPHField.js +204 -0
- package/WaterFlow/SPHField.ts +228 -0
- package/WaterFlow/ScreenSpaceFluidPass.d.ts +69 -0
- package/WaterFlow/ScreenSpaceFluidPass.js +736 -0
- package/WaterFlow/ScreenSpaceFluidPass.ts +789 -0
- package/WaterFlow/ShallowWaterSurface.d.ts +45 -0
- package/WaterFlow/ShallowWaterSurface.js +441 -0
- package/WaterFlow/ShallowWaterSurface.ts +510 -0
- package/WaterFlow/WaterFlow.d.ts +87 -0
- package/WaterFlow/WaterFlow.js +171 -0
- package/WaterFlow/WaterFlow.ts +219 -0
- package/WaterFlow/types.d.ts +161 -0
- package/WaterFlow/types.js +1 -0
- package/WaterFlow/types.ts +189 -0
- package/WaterFlow/waterFlowPass.d.ts +3 -0
- package/WaterFlow/waterFlowPass.js +20 -0
- package/WaterFlow/waterFlowPass.ts +40 -0
- package/collisionOBB.d.ts +42 -0
- package/collisionOBB.js +112 -0
- package/collisionOBB.ts +108 -0
- package/declare.d.ts +23 -165
- package/index.d.ts +1 -1
- package/index.js +1 -2
- package/index.ts +1 -0
- package/instanced/InstancedBatch.d.ts +57 -0
- package/instanced/InstancedBatch.js +348 -0
- package/instanced/InstancedBatch.ts +406 -0
- package/instanced/InstancedChild.d.ts +174 -0
- package/instanced/InstancedChild.js +264 -0
- package/instanced/InstancedChild.ts +327 -0
- package/instanced/InstancedGroup.d.ts +43 -0
- package/instanced/InstancedGroup.js +126 -0
- package/instanced/InstancedGroup.ts +137 -0
- package/{InstancedMeshBase.d.ts → instanced/InstancedMeshBase.d.ts} +38 -39
- package/{InstancedMeshBase.js → instanced/InstancedMeshBase.js} +282 -293
- package/instanced/InstancedMeshBase.ts +292 -0
- package/instanced/InstancedTemplate.d.ts +46 -0
- package/instanced/InstancedTemplate.js +125 -0
- package/instanced/InstancedTemplate.ts +188 -0
- package/keyControls.d.ts +30 -0
- package/{keyContorls.js → keyControls.js} +101 -98
- package/keyControls.ts +107 -0
- package/lensflare/LensFlare.d.ts +39 -0
- package/lensflare/LensFlare.js +373 -0
- package/lensflare/LensFlare.ts +448 -0
- package/lensflare/lensflare0.png +0 -0
- package/lensflare/lensflare3.png +0 -0
- package/lensflare/lensflare_custom.png +0 -0
- package/lensflare/lensflare_hex_ghost.png +0 -0
- package/lensflare/lensflare_hex_main.png +0 -0
- package/package.json +101 -26
- package/pass/bloom_pass.d.ts +2 -2
- package/pass/bloom_pass.js +188 -101
- package/pass/bloom_pass.ts +243 -0
- package/pass/cover_pass.d.ts +2 -2
- package/pass/cover_pass.js +122 -99
- package/pass/cover_pass.ts +182 -0
- package/pass/debugDepthState.d.ts +20 -0
- package/pass/debugDepthState.js +9 -0
- package/pass/debugDepthState.ts +22 -0
- package/pass/depthTestBias.d.ts +12 -0
- package/pass/depthTestBias.js +12 -0
- package/pass/depthTestBias.ts +12 -0
- package/pass/effectUserData.d.ts +27 -0
- package/pass/effectUserData.js +1 -0
- package/pass/effectUserData.ts +46 -0
- package/pass/frosted_glass_pass.d.ts +2 -2
- package/pass/frosted_glass_pass.js +167 -186
- package/pass/frosted_glass_pass.ts +288 -0
- package/pass/fsQuad.d.ts +9 -9
- package/pass/fsQuad.js +28 -28
- package/pass/fsQuad.ts +34 -0
- package/pass/glow_pass.d.ts +2 -2
- package/pass/glow_pass.js +449 -233
- package/pass/glow_pass.ts +654 -0
- package/pass/screen_bloom_pass.d.ts +11 -0
- package/pass/screen_bloom_pass.js +235 -0
- package/pass/screen_bloom_pass.ts +263 -0
- package/pass/ssao_pass.d.ts +88 -11
- package/pass/ssao_pass.js +802 -288
- package/pass/ssao_pass.ts +918 -0
- package/pass/stroke_pass.d.ts +2 -2
- package/pass/stroke_pass.js +329 -258
- package/pass/stroke_pass.ts +638 -0
- package/shaders/FXAAShaderMaterial.d.ts +3 -3
- package/shaders/FXAAShaderMaterial.js +23 -66
- package/shaders/FXAAShaderMaterial.ts +201 -0
- package/shaders/baseDepthVisShader.d.ts +11 -0
- package/shaders/baseDepthVisShader.js +36 -0
- package/shaders/baseDepthVisShader.ts +36 -0
- package/shaders/baseTextureToRenderShader.d.ts +2 -2
- package/shaders/baseTextureToRenderShader.js +55 -60
- package/shaders/baseTextureToRenderShader.ts +232 -0
- package/shaders/copyShader.d.ts +3 -3
- package/shaders/copyShader.js +13 -14
- package/shaders/copyShader.ts +32 -0
- package/shaders/debugDepthCompareShader.d.ts +14 -0
- package/shaders/debugDepthCompareShader.js +49 -0
- package/shaders/debugDepthCompareShader.ts +50 -0
- package/shaders/debugDepthJudgeShader.d.ts +18 -0
- package/shaders/debugDepthJudgeShader.js +52 -0
- package/shaders/debugDepthJudgeShader.ts +54 -0
- package/shaders/debugExcludedShader.d.ts +13 -0
- package/shaders/debugExcludedShader.js +46 -0
- package/shaders/debugExcludedShader.ts +48 -0
- package/spriteTextBg.d.ts +1 -0
- package/spriteTextBg.js +20 -0
- package/spriteTextBg.ts +20 -0
- package/threeLoader.d.ts +35 -34
- package/threeLoader.js +518 -527
- package/threeLoader.ts +525 -0
- package/threeUtils.d.ts +53 -52
- package/threeUtils.js +329 -330
- package/threeUtils.ts +373 -0
- package/types.d.ts +2 -0
- package/types.js +6 -0
- package/types.ts +8 -0
- package/ApngTexture.d.ts +0 -13
- package/ApngTexture.js +0 -61
- package/ApngTextureManage.d.ts +0 -18
- package/ApngTextureManage.js +0 -87
- package/KeyFrameAnimation.d.ts +0 -25
- package/KeyFrameAnimation.js +0 -78
- package/keyContorls.d.ts +0 -25
- package/lib/draco/draco_decoder.js +0 -34
- package/lib/draco/draco_decoder.wasm +0 -0
- package/lib/draco/draco_wasm_wrapper.js +0 -117
- package/shaders.d.ts +0 -5
- package/shaders.js +0 -93
package/pass/glow_pass.js
CHANGED
|
@@ -1,54 +1,79 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-05-09 00:35:17
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2025-01-28 04:13:16
|
|
6
|
-
*/
|
|
7
|
-
import { Color, DepthFormat, DepthTexture, LinearFilter, NoBlending, NormalBlending, RGBAFormat, RawShaderMaterial, Scene, ShaderChunk, ShaderMaterial,
|
|
8
|
-
import fsQuad from "./fsQuad";
|
|
9
|
-
|
|
10
|
-
const selectDepthTexture = (() => {
|
|
11
|
-
const baseDepthTexture = new DepthTexture(
|
|
12
|
-
baseDepthTexture.format = DepthFormat;
|
|
13
|
-
baseDepthTexture.type =
|
|
14
|
-
baseDepthTexture.anisotropy = 16;
|
|
15
|
-
return baseDepthTexture;
|
|
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
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2023-05-09 00:35:17
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2025-01-28 04:13:16
|
|
6
|
+
*/
|
|
7
|
+
import { Color, DepthFormat, DepthTexture, LinearFilter, NoBlending, NormalBlending, AdditiveBlending, RGBAFormat, RawShaderMaterial, Scene, ShaderChunk, ShaderMaterial, UnsignedIntType, Vector2, WebGLRenderTarget } from "three";
|
|
8
|
+
import fsQuad from "./fsQuad";
|
|
9
|
+
import { debugDepthState } from "./debugDepthState";
|
|
10
|
+
const selectDepthTexture = (() => {
|
|
11
|
+
const baseDepthTexture = new DepthTexture(1024, 1024);
|
|
12
|
+
baseDepthTexture.format = DepthFormat;
|
|
13
|
+
baseDepthTexture.type = UnsignedIntType;
|
|
14
|
+
baseDepthTexture.anisotropy = 16;
|
|
15
|
+
return baseDepthTexture;
|
|
16
|
+
})();
|
|
17
|
+
const selectTextureTarget = new WebGLRenderTarget(1024, 1024, {
|
|
18
|
+
minFilter: LinearFilter,
|
|
19
|
+
magFilter: LinearFilter,
|
|
20
|
+
format: RGBAFormat,
|
|
21
|
+
anisotropy: 16,
|
|
22
|
+
// 无 MSAA:mask 颜色与下方 selectDepthTextureTarget(深度)必须同为硬边缘,
|
|
23
|
+
// 否则 mask 边缘平滑而深度硬 → depthTestShader 判定边界与 mask 视觉边缘错位,辉光边缘锯齿。
|
|
24
|
+
// 边缘抗锯齿统一由 mask 内部 FXAA + 终处理 FXAA 兜底。
|
|
25
|
+
});
|
|
26
|
+
// 无 MSAA 的深度专用目标:仅用于导出对象深度,供 depthTestShader 做遮挡判定(深度无需抗锯齿)
|
|
27
|
+
const selectDepthTextureTarget = new WebGLRenderTarget(1024, 1024, {
|
|
28
|
+
minFilter: LinearFilter,
|
|
29
|
+
magFilter: LinearFilter,
|
|
30
|
+
format: RGBAFormat,
|
|
31
|
+
depthTexture: selectDepthTexture,
|
|
32
|
+
anisotropy: 16,
|
|
33
|
+
});
|
|
34
|
+
const selectDepthTestTextureTarget = new WebGLRenderTarget(1024, 1024, {
|
|
35
|
+
minFilter: LinearFilter,
|
|
36
|
+
magFilter: LinearFilter,
|
|
37
|
+
format: RGBAFormat,
|
|
38
|
+
anisotropy: 16,
|
|
39
|
+
// 无 MSAA:深度测试 mask 无需抗锯齿,去掉以提速
|
|
40
|
+
});
|
|
41
|
+
const blur1TextureTarget = new WebGLRenderTarget(1024, 1024, {
|
|
42
|
+
minFilter: LinearFilter,
|
|
43
|
+
magFilter: LinearFilter,
|
|
44
|
+
format: RGBAFormat,
|
|
45
|
+
});
|
|
46
|
+
const blur2TextureTarget = new WebGLRenderTarget(1024, 1024, {
|
|
47
|
+
minFilter: LinearFilter,
|
|
48
|
+
magFilter: LinearFilter,
|
|
49
|
+
format: RGBAFormat,
|
|
50
|
+
});
|
|
51
|
+
// 外扩深度临时/结果目标:depthMinBlurShader 把本体深度图随 mask 一起外扩,
|
|
52
|
+
// 外扩区取邻域最近深度(忽略背景 1.0),使外扩区 selD<1.0,depthTest 才能正确判遮挡(不漏光)。
|
|
53
|
+
const selectDepthBlurTmpTextureTarget = new WebGLRenderTarget(1024, 1024, {
|
|
54
|
+
minFilter: LinearFilter,
|
|
55
|
+
magFilter: LinearFilter,
|
|
56
|
+
format: RGBAFormat,
|
|
57
|
+
});
|
|
58
|
+
const selectDepthBlurTextureTarget = new WebGLRenderTarget(1024, 1024, {
|
|
59
|
+
minFilter: LinearFilter,
|
|
60
|
+
magFilter: LinearFilter,
|
|
61
|
+
format: RGBAFormat,
|
|
62
|
+
});
|
|
63
|
+
// 外扩辉光经深度测试后的结果(步骤 5.6):独立 target,避免回写 blur1 触发历史回归 bug
|
|
64
|
+
const blurDepthTestTextureTarget = new WebGLRenderTarget(1024, 1024, {
|
|
65
|
+
minFilter: LinearFilter,
|
|
66
|
+
magFilter: LinearFilter,
|
|
67
|
+
format: RGBAFormat,
|
|
68
|
+
});
|
|
69
|
+
const size = new Vector2();
|
|
70
|
+
const depthTestShader = new ShaderMaterial({
|
|
71
|
+
uniforms: {
|
|
72
|
+
map: { value: null },
|
|
73
|
+
baseDepth: { value: null },
|
|
74
|
+
selectDepth: { value: null },
|
|
75
|
+
cameraFar: { value: 1000.0 },
|
|
76
|
+
},
|
|
52
77
|
vertexShader: `
|
|
53
78
|
${ShaderChunk.common}
|
|
54
79
|
${ShaderChunk.logdepthbuf_pars_vertex}
|
|
@@ -58,37 +83,43 @@ const depthTestShader = new ShaderMaterial({
|
|
|
58
83
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
59
84
|
${ShaderChunk.logdepthbuf_vertex}
|
|
60
85
|
}
|
|
61
|
-
`,
|
|
86
|
+
`,
|
|
62
87
|
fragmentShader: `
|
|
63
88
|
${ShaderChunk.logdepthbuf_pars_fragment}
|
|
64
89
|
uniform sampler2D map;
|
|
65
90
|
uniform sampler2D baseDepth;
|
|
66
91
|
uniform sampler2D selectDepth;
|
|
92
|
+
uniform float cameraFar;
|
|
67
93
|
varying vec2 vUv;
|
|
68
94
|
void main() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
95
|
+
float baseD = texture2D(baseDepth, vUv).r;
|
|
96
|
+
float selD = texture2D(selectDepth, vUv).r;
|
|
97
|
+
// 参考手写版 a27bdea 的朴素对数深度比对:DepthTexture 存对数深度,「更小=更近」,
|
|
98
|
+
// base 比 select 更近即被真实场景遮挡 → discard。背景像素 base≈1.0 不小于物体 selD(<1.0)
|
|
99
|
+
// → 不丢弃,浮空物体辉光正常显示(不整片吃掉)。加极小对数容差 bias(≈0.0006) 防
|
|
100
|
+
// 自身像素浮点 z-fit 锯齿;真实更近物体深度差远大于此,不受影响。用二值 discard 而非
|
|
101
|
+
// 软遮挡:相交场景 base 深度在地板/物体间亚像素抖,软遮挡半透明渐隐边缘一抖就明显闪,
|
|
102
|
+
// 二值硬边界经后续 blur + FXAA 柔化更干净。
|
|
103
|
+
const float bias = 0.0006;
|
|
104
|
+
if (baseD < selD - bias) {
|
|
73
105
|
discard;
|
|
74
106
|
}
|
|
75
107
|
gl_FragColor = texture2D(map, vUv);
|
|
76
108
|
${ShaderChunk.logdepthbuf_fragment}
|
|
77
109
|
}
|
|
78
|
-
`,
|
|
79
|
-
blending: NoBlending,
|
|
80
|
-
depthTest: true,
|
|
81
|
-
depthWrite: true,
|
|
82
|
-
transparent: true,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
},
|
|
110
|
+
`,
|
|
111
|
+
blending: NoBlending,
|
|
112
|
+
depthTest: true,
|
|
113
|
+
depthWrite: true,
|
|
114
|
+
transparent: true,
|
|
115
|
+
});
|
|
116
|
+
const gaussianBlurHShader = new RawShaderMaterial({
|
|
117
|
+
uniforms: {
|
|
118
|
+
tDiffuse: { value: null },
|
|
119
|
+
resolution: { value: new Vector2(1 / 512, 1 / 512) },
|
|
120
|
+
radius: { value: 1.0 },
|
|
121
|
+
sigma: { value: 1.0 },
|
|
122
|
+
},
|
|
92
123
|
vertexShader: `
|
|
93
124
|
attribute vec3 position;
|
|
94
125
|
attribute vec2 uv;
|
|
@@ -96,7 +127,7 @@ const gaussianBlurHShader = new RawShaderMaterial({
|
|
|
96
127
|
void main() {
|
|
97
128
|
vUv = uv;
|
|
98
129
|
gl_Position = vec4(position, 1.0);
|
|
99
|
-
}`,
|
|
130
|
+
}`,
|
|
100
131
|
fragmentShader: `
|
|
101
132
|
#ifdef GL_ES
|
|
102
133
|
precision highp float;
|
|
@@ -107,7 +138,6 @@ const gaussianBlurHShader = new RawShaderMaterial({
|
|
|
107
138
|
uniform float sigma;
|
|
108
139
|
varying vec2 vUv;
|
|
109
140
|
|
|
110
|
-
// 高斯函数
|
|
111
141
|
float gaussian(float x, float sigma) {
|
|
112
142
|
return exp(-(x * x) / (2.0 * sigma * sigma));
|
|
113
143
|
}
|
|
@@ -116,7 +146,6 @@ const gaussianBlurHShader = new RawShaderMaterial({
|
|
|
116
146
|
vec4 color = vec4(0.0);
|
|
117
147
|
float totalWeight = 0.0;
|
|
118
148
|
|
|
119
|
-
// 计算高斯权重
|
|
120
149
|
for (int i = -10; i <= 10; i++) {
|
|
121
150
|
float x = float(i);
|
|
122
151
|
float weight = gaussian(x, sigma);
|
|
@@ -126,20 +155,19 @@ const gaussianBlurHShader = new RawShaderMaterial({
|
|
|
126
155
|
}
|
|
127
156
|
|
|
128
157
|
gl_FragColor = color / totalWeight;
|
|
129
|
-
}`,
|
|
130
|
-
blending: NoBlending,
|
|
131
|
-
depthTest: false,
|
|
132
|
-
depthWrite: false,
|
|
133
|
-
transparent: true,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
},
|
|
158
|
+
}`,
|
|
159
|
+
blending: NoBlending,
|
|
160
|
+
depthTest: false,
|
|
161
|
+
depthWrite: false,
|
|
162
|
+
transparent: true,
|
|
163
|
+
});
|
|
164
|
+
const gaussianBlurVShader = new RawShaderMaterial({
|
|
165
|
+
uniforms: {
|
|
166
|
+
tDiffuse: { value: null },
|
|
167
|
+
resolution: { value: new Vector2(1 / 512, 1 / 512) },
|
|
168
|
+
radius: { value: 1.0 },
|
|
169
|
+
sigma: { value: 1.0 },
|
|
170
|
+
},
|
|
143
171
|
vertexShader: `
|
|
144
172
|
attribute vec3 position;
|
|
145
173
|
attribute vec2 uv;
|
|
@@ -147,7 +175,7 @@ const gaussianBlurVShader = new RawShaderMaterial({
|
|
|
147
175
|
void main() {
|
|
148
176
|
vUv = uv;
|
|
149
177
|
gl_Position = vec4(position, 1.0);
|
|
150
|
-
}`,
|
|
178
|
+
}`,
|
|
151
179
|
fragmentShader: `
|
|
152
180
|
#ifdef GL_ES
|
|
153
181
|
precision highp float;
|
|
@@ -158,7 +186,6 @@ const gaussianBlurVShader = new RawShaderMaterial({
|
|
|
158
186
|
uniform float sigma;
|
|
159
187
|
varying vec2 vUv;
|
|
160
188
|
|
|
161
|
-
// 高斯函数
|
|
162
189
|
float gaussian(float x, float sigma) {
|
|
163
190
|
return exp(-(x * x) / (2.0 * sigma * sigma));
|
|
164
191
|
}
|
|
@@ -167,7 +194,6 @@ const gaussianBlurVShader = new RawShaderMaterial({
|
|
|
167
194
|
vec4 color = vec4(0.0);
|
|
168
195
|
float totalWeight = 0.0;
|
|
169
196
|
|
|
170
|
-
// 计算高斯权重
|
|
171
197
|
for (int i = -10; i <= 10; i++) {
|
|
172
198
|
float y = float(i);
|
|
173
199
|
float weight = gaussian(y, sigma);
|
|
@@ -177,20 +203,66 @@ const gaussianBlurVShader = new RawShaderMaterial({
|
|
|
177
203
|
}
|
|
178
204
|
|
|
179
205
|
gl_FragColor = color / totalWeight;
|
|
180
|
-
}`,
|
|
181
|
-
blending: NoBlending,
|
|
182
|
-
depthTest: false,
|
|
183
|
-
depthWrite: false,
|
|
184
|
-
transparent: true,
|
|
185
|
-
});
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
206
|
+
}`,
|
|
207
|
+
blending: NoBlending,
|
|
208
|
+
depthTest: false,
|
|
209
|
+
depthWrite: false,
|
|
210
|
+
transparent: true,
|
|
211
|
+
});
|
|
212
|
+
// 深度 min-blur(最近深度,忽略背景 1.0):随 mask 一起把深度图向外扩,
|
|
213
|
+
// 外扩区 selD = 物体最近深度(<1.0) 而非清屏 1.0,depthTest 在外扩区才能正确判遮挡(不漏光),
|
|
214
|
+
// 同时本体区仍靠 depthTestShader 的 EPSILON 容差防自遮挡闪烁(无缝)。separable(direction 控制 H/V)。
|
|
215
|
+
const depthMinBlurShader = new ShaderMaterial({
|
|
216
|
+
uniforms: {
|
|
217
|
+
tDepth: { value: null },
|
|
218
|
+
resolution: { value: new Vector2(1 / 512, 1 / 512) },
|
|
219
|
+
radius: { value: 1.0 },
|
|
220
|
+
direction: { value: new Vector2(1, 0) },
|
|
221
|
+
},
|
|
222
|
+
vertexShader: `
|
|
223
|
+
${ShaderChunk.common}
|
|
224
|
+
${ShaderChunk.logdepthbuf_pars_vertex}
|
|
225
|
+
varying vec2 vUv;
|
|
226
|
+
void main() {
|
|
227
|
+
vUv = uv;
|
|
228
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
229
|
+
${ShaderChunk.logdepthbuf_vertex}
|
|
230
|
+
}
|
|
231
|
+
`,
|
|
232
|
+
fragmentShader: `
|
|
233
|
+
${ShaderChunk.logdepthbuf_pars_fragment}
|
|
234
|
+
uniform sampler2D tDepth;
|
|
235
|
+
uniform vec2 resolution;
|
|
236
|
+
uniform float radius;
|
|
237
|
+
uniform vec2 direction;
|
|
238
|
+
varying vec2 vUv;
|
|
239
|
+
void main() {
|
|
240
|
+
float minD = 1.0;
|
|
241
|
+
for (int i = -10; i <= 10; i++) {
|
|
242
|
+
float x = float(i);
|
|
243
|
+
vec2 off = direction * (x * radius * resolution);
|
|
244
|
+
float d = texture2D(tDepth, vUv + off).r;
|
|
245
|
+
if (d < 0.9999) {
|
|
246
|
+
minD = min(minD, d);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
gl_FragColor = vec4(minD, 0.0, 0.0, 1.0);
|
|
250
|
+
${ShaderChunk.logdepthbuf_fragment}
|
|
251
|
+
}
|
|
252
|
+
`,
|
|
253
|
+
blending: NoBlending,
|
|
254
|
+
depthTest: false,
|
|
255
|
+
depthWrite: false,
|
|
256
|
+
transparent: true,
|
|
257
|
+
});
|
|
258
|
+
const glowCompositeShader = new RawShaderMaterial({
|
|
259
|
+
uniforms: {
|
|
260
|
+
tDiffuse: { value: null },
|
|
261
|
+
color: { value: new Color("#0f0") },
|
|
262
|
+
opacity: { value: 1.0 },
|
|
263
|
+
threshold: { value: 0.0 },
|
|
264
|
+
intensity: { value: 1.0 },
|
|
265
|
+
},
|
|
194
266
|
vertexShader: `
|
|
195
267
|
attribute vec3 position;
|
|
196
268
|
attribute vec2 uv;
|
|
@@ -198,7 +270,7 @@ const glowCompositeShader = new RawShaderMaterial({
|
|
|
198
270
|
void main() {
|
|
199
271
|
vUv = uv;
|
|
200
272
|
gl_Position = vec4(position, 1.0);
|
|
201
|
-
}`,
|
|
273
|
+
}`,
|
|
202
274
|
fragmentShader: `
|
|
203
275
|
#ifdef GL_ES
|
|
204
276
|
precision highp float;
|
|
@@ -207,35 +279,135 @@ const glowCompositeShader = new RawShaderMaterial({
|
|
|
207
279
|
uniform vec3 color;
|
|
208
280
|
uniform float opacity;
|
|
209
281
|
uniform float threshold;
|
|
282
|
+
uniform float intensity;
|
|
210
283
|
varying vec2 vUv;
|
|
211
|
-
|
|
284
|
+
|
|
212
285
|
void main() {
|
|
213
286
|
vec4 texColor = texture2D(tDiffuse, vUv);
|
|
214
287
|
float alpha = texColor.a;
|
|
215
|
-
|
|
216
|
-
// 应用阈值
|
|
288
|
+
|
|
217
289
|
if (alpha < threshold) {
|
|
218
290
|
gl_FragColor = vec4(0.0);
|
|
219
291
|
return;
|
|
220
292
|
}
|
|
221
|
-
|
|
222
|
-
// 增强alpha值,确保发光效果明显
|
|
293
|
+
|
|
223
294
|
alpha = min(1.0, alpha * 2.0);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
295
|
+
|
|
296
|
+
// intensity 让颜色亮度可超 1(配合 glow_additive 加性混合呈发光感,很亮那种)
|
|
297
|
+
gl_FragColor = vec4(color * intensity, alpha * opacity);
|
|
298
|
+
}`,
|
|
299
|
+
blending: NoBlending,
|
|
300
|
+
depthTest: false,
|
|
301
|
+
depthWrite: false,
|
|
302
|
+
transparent: true,
|
|
303
|
+
});
|
|
304
|
+
// 薄高亮层合成:对本体 mask 做 1 次像素扩张(24 方向偏移 width 像素采样),
|
|
305
|
+
// 扩张区 − 本体 = 贴着物体边缘的一圈薄亮环(rim)。上 glow 颜色,跟随 glow_additive 叠加,
|
|
306
|
+
// 与外圈柔光晕(filterSelect 结果)并存 → 选中态边缘有「实亮轮廓 + 外柔光」。
|
|
307
|
+
// ⚠️ 默认关闭(glow_highlight=false),只有对象显式开启才会执行,避免干扰既有发光合成。
|
|
308
|
+
const thinHighlightShader = new RawShaderMaterial({
|
|
309
|
+
uniforms: {
|
|
310
|
+
tMask: { value: null },
|
|
311
|
+
color: { value: new Color("#0f0") },
|
|
312
|
+
uWidth: { value: 1.0 },
|
|
313
|
+
opacity: { value: 1.0 },
|
|
314
|
+
intensity: { value: 1.0 },
|
|
315
|
+
resolution: { value: new Vector2(1 / 512, 1 / 512) },
|
|
316
|
+
uDebugVis: { value: 0.0 },
|
|
317
|
+
offset: {
|
|
318
|
+
value: [
|
|
319
|
+
new Vector2(0.000, 1.000),
|
|
320
|
+
new Vector2(0.259, 0.966),
|
|
321
|
+
new Vector2(0.500, 0.866),
|
|
322
|
+
new Vector2(0.707, 0.707),
|
|
323
|
+
new Vector2(0.866, 0.500),
|
|
324
|
+
new Vector2(0.966, 0.259),
|
|
325
|
+
new Vector2(1.000, 0.000),
|
|
326
|
+
new Vector2(0.966, -0.259),
|
|
327
|
+
new Vector2(0.866, -0.500),
|
|
328
|
+
new Vector2(0.707, -0.707),
|
|
329
|
+
new Vector2(0.500, -0.866),
|
|
330
|
+
new Vector2(0.259, -0.966),
|
|
331
|
+
new Vector2(0.000, -1.000),
|
|
332
|
+
new Vector2(-0.259, -0.966),
|
|
333
|
+
new Vector2(-0.500, -0.866),
|
|
334
|
+
new Vector2(-0.707, -0.707),
|
|
335
|
+
new Vector2(-0.866, -0.500),
|
|
336
|
+
new Vector2(-0.966, -0.259),
|
|
337
|
+
new Vector2(-1.000, -0.000),
|
|
338
|
+
new Vector2(-0.966, 0.259),
|
|
339
|
+
new Vector2(-0.866, 0.500),
|
|
340
|
+
new Vector2(-0.707, 0.707),
|
|
341
|
+
new Vector2(-0.500, 0.866),
|
|
342
|
+
new Vector2(-0.259, 0.966)
|
|
343
|
+
]
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
vertexShader: `
|
|
347
|
+
attribute vec3 position;
|
|
348
|
+
attribute vec2 uv;
|
|
349
|
+
varying vec2 vUv;
|
|
350
|
+
void main() {
|
|
351
|
+
vUv = uv;
|
|
352
|
+
gl_Position = vec4(position, 1.0);
|
|
353
|
+
}`,
|
|
354
|
+
fragmentShader: `
|
|
355
|
+
#ifdef GL_ES
|
|
356
|
+
precision highp float;
|
|
357
|
+
#endif
|
|
358
|
+
uniform sampler2D tMask;
|
|
359
|
+
uniform vec3 color;
|
|
360
|
+
uniform float uWidth;
|
|
361
|
+
uniform float opacity;
|
|
362
|
+
uniform float intensity;
|
|
363
|
+
uniform vec2 resolution;
|
|
364
|
+
uniform float uDebugVis;
|
|
365
|
+
uniform vec2 offset[24];
|
|
366
|
+
varying vec2 vUv;
|
|
367
|
+
|
|
368
|
+
void main() {
|
|
369
|
+
// ⚠️ piexl 必须 main 内局部初始化(不能在全局用 uniform 初始化,某些 driver 会静默置 0)。
|
|
370
|
+
vec2 piexl = resolution * uWidth;
|
|
371
|
+
vec4 self = texture2D(tMask, vUv);
|
|
372
|
+
float hit = 0.0;
|
|
373
|
+
for (int i = 0; i < 24; i++) {
|
|
374
|
+
vec4 c = texture2D(tMask, vUv + offset[i] * piexl);
|
|
375
|
+
if (c.a > 0.0) {
|
|
376
|
+
hit = 1.0;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
// 扩张区 − 本体 = 物体外一圈薄亮环(贴边轮廓)
|
|
380
|
+
float rim = clamp(hit - self.a, 0.0, 1.0);
|
|
381
|
+
|
|
382
|
+
// 调试可视化(window.__GLOW_HIGHLIGHT_VIS=true 开启):
|
|
383
|
+
// R=扩张命中区(hit) G=本体(self.a) B=最终 rim(薄亮环)
|
|
384
|
+
// 正常应看到:物体内部 G=1(绿),物体外紧贴一圈 B=1(蓝细环),其余全黑。
|
|
385
|
+
// 若整片有颜色 → mask/扩张参数异常。
|
|
386
|
+
if (uDebugVis > 0.5) {
|
|
387
|
+
gl_FragColor = vec4(hit, self.a, rim, 1.0);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
if (rim < 0.001) {
|
|
392
|
+
gl_FragColor = vec4(0.0);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
// 薄高亮层:只需比外圈辉光"稍亮"即可凸显,过曝会偏白、丢掉辉光本色。
|
|
396
|
+
// 向白色混合 0.3(保留 7 成辉光本色)+ 亮度乘 1.2:轮廓清晰可辨,又不抢辉光的色。
|
|
397
|
+
vec3 hl = mix(color, vec3(1.0), 0.3) * 1.2;
|
|
398
|
+
gl_FragColor = vec4(hl, rim * opacity);
|
|
399
|
+
}`,
|
|
400
|
+
blending: NoBlending,
|
|
401
|
+
depthTest: false,
|
|
402
|
+
depthWrite: false,
|
|
403
|
+
transparent: true
|
|
404
|
+
});
|
|
405
|
+
const filterSelectShader = new RawShaderMaterial({
|
|
406
|
+
uniforms: {
|
|
407
|
+
selectTexture: { value: null },
|
|
408
|
+
blurTexture: { value: null },
|
|
409
|
+
opacity: { value: 1 },
|
|
410
|
+
},
|
|
239
411
|
vertexShader: `
|
|
240
412
|
attribute vec3 position;
|
|
241
413
|
attribute vec2 uv;
|
|
@@ -244,7 +416,7 @@ const filterSelectShader = new RawShaderMaterial({
|
|
|
244
416
|
vUv = uv;
|
|
245
417
|
gl_Position = vec4(position, 1.0);
|
|
246
418
|
}
|
|
247
|
-
`,
|
|
419
|
+
`,
|
|
248
420
|
fragmentShader: `
|
|
249
421
|
#ifdef GL_ES
|
|
250
422
|
precision highp float;
|
|
@@ -255,42 +427,36 @@ const filterSelectShader = new RawShaderMaterial({
|
|
|
255
427
|
varying vec2 vUv;
|
|
256
428
|
|
|
257
429
|
void main() {
|
|
258
|
-
// 获取模糊后的纹理和原始纹理
|
|
259
430
|
vec4 blurColor = texture2D(blurTexture, vUv);
|
|
260
431
|
vec4 selectColor = texture2D(selectTexture, vUv);
|
|
261
432
|
|
|
262
|
-
// 计算辉光部分:模糊纹理 - 原始纹理,确保alpha非负
|
|
263
433
|
vec4 glowColor = blurColor - selectColor;
|
|
264
434
|
glowColor.a = max(0.0, glowColor.a);
|
|
265
435
|
|
|
266
|
-
// 应用透明度
|
|
267
436
|
glowColor.a *= opacity;
|
|
268
437
|
|
|
269
|
-
// 设置最终颜色
|
|
270
438
|
gl_FragColor = glowColor;
|
|
271
439
|
}
|
|
272
|
-
`,
|
|
273
|
-
blending: NormalBlending,
|
|
274
|
-
depthTest: false,
|
|
275
|
-
depthWrite: false,
|
|
276
|
-
transparent: true,
|
|
277
|
-
});
|
|
278
|
-
const copyShader = new ShaderMaterial({
|
|
279
|
-
uniforms: {
|
|
280
|
-
map: { value: null },
|
|
281
|
-
},
|
|
440
|
+
`,
|
|
441
|
+
blending: NormalBlending,
|
|
442
|
+
depthTest: false,
|
|
443
|
+
depthWrite: false,
|
|
444
|
+
transparent: true,
|
|
445
|
+
});
|
|
446
|
+
const copyShader = new ShaderMaterial({
|
|
447
|
+
uniforms: {
|
|
448
|
+
map: { value: null },
|
|
449
|
+
},
|
|
282
450
|
vertexShader: `
|
|
283
451
|
${ShaderChunk.common}
|
|
284
452
|
${ShaderChunk.logdepthbuf_pars_vertex}
|
|
285
453
|
varying vec2 vUv;
|
|
286
454
|
void main() {
|
|
287
455
|
vUv = uv;
|
|
288
|
-
// gl_Position = vec4(position, 1.0);
|
|
289
|
-
// gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position, 1.0);
|
|
290
456
|
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
291
457
|
${ShaderChunk.logdepthbuf_vertex}
|
|
292
458
|
}
|
|
293
|
-
`,
|
|
459
|
+
`,
|
|
294
460
|
fragmentShader: `
|
|
295
461
|
${ShaderChunk.logdepthbuf_pars_fragment}
|
|
296
462
|
uniform sampler2D map;
|
|
@@ -299,93 +465,143 @@ const copyShader = new ShaderMaterial({
|
|
|
299
465
|
gl_FragColor = texture2D(map, vUv);
|
|
300
466
|
${ShaderChunk.logdepthbuf_fragment}
|
|
301
467
|
}
|
|
302
|
-
`,
|
|
303
|
-
depthTest: true,
|
|
304
|
-
depthWrite: true,
|
|
305
|
-
transparent: true,
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
//
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
//
|
|
333
|
-
renderer.setRenderTarget(
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
fsQuad.render(renderer,
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
//
|
|
391
|
-
|
|
468
|
+
`,
|
|
469
|
+
depthTest: true,
|
|
470
|
+
depthWrite: true,
|
|
471
|
+
transparent: true,
|
|
472
|
+
});
|
|
473
|
+
const scene = new Scene();
|
|
474
|
+
export default function glow_pass(renderer, camera, object3d, baseDepthTexture, devicePixelRatio) {
|
|
475
|
+
const { glow_enable = false, glow_color = "#04fa12", glow_width = 1, glow_opacity = 1, glow_sigma = 2.0, glow_threshold = 0.0, glow_iterations = 10, glow_intensity = 1.0, glow_additive = false, glow_highlight_width = 2, // 薄高亮层粗细(像素,默认 2);设为 0 则不画薄高亮层
|
|
476
|
+
} = object3d.userData;
|
|
477
|
+
if (!glow_enable || glow_width === 0) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const originRenderTarget = renderer.getRenderTarget();
|
|
481
|
+
// 灰度图渲染目标跟随主画面尺寸(= width × effectiveRatio),与 baseRenderTarget 完全一致,
|
|
482
|
+
// 消除灰度图与主画面尺寸不一致导致的放大重采样摩尔纹
|
|
483
|
+
renderer.getSize(size);
|
|
484
|
+
size.multiplyScalar(devicePixelRatio);
|
|
485
|
+
selectTextureTarget.setSize(size.x, size.y);
|
|
486
|
+
selectDepthTextureTarget.setSize(size.x, size.y);
|
|
487
|
+
// 缺陷修复:three r167 的 WebGLRenderTarget.setSize 不会同步 depthTexture,
|
|
488
|
+
// 需手动把 selectDepthTexture 尺寸与全屏 baseDepth 对齐,否则深度比例错位导致辉光被错误 discard
|
|
489
|
+
selectDepthTexture.image.width = size.x;
|
|
490
|
+
selectDepthTexture.image.height = size.y;
|
|
491
|
+
selectDepthTexture.needsUpdate = true;
|
|
492
|
+
selectDepthTestTextureTarget.setSize(size.x, size.y);
|
|
493
|
+
blur1TextureTarget.setSize(size.x, size.y);
|
|
494
|
+
blur2TextureTarget.setSize(size.x, size.y);
|
|
495
|
+
selectDepthBlurTmpTextureTarget.setSize(size.x, size.y);
|
|
496
|
+
selectDepthBlurTextureTarget.setSize(size.x, size.y);
|
|
497
|
+
blurDepthTestTextureTarget.setSize(size.x, size.y);
|
|
498
|
+
// 1. 渲染物体本体 mask(灰度)
|
|
499
|
+
renderer.setRenderTarget(selectTextureTarget);
|
|
500
|
+
scene.children = [object3d];
|
|
501
|
+
renderer.clear();
|
|
502
|
+
renderer.render(scene, camera);
|
|
503
|
+
// 2. 渲染物体本体深度(无 MSAA,供 min-blur 外扩用)
|
|
504
|
+
renderer.setRenderTarget(selectDepthTextureTarget);
|
|
505
|
+
scene.children = [object3d];
|
|
506
|
+
renderer.clear();
|
|
507
|
+
renderer.render(scene, camera);
|
|
508
|
+
// 调试:把本次渲染的选区深度记到全局调试状态,供面板「辉光深度比对」读取
|
|
509
|
+
debugDepthState.lastSelectDepth = selectDepthTexture;
|
|
510
|
+
// 3. 深度测试(用本体 mask):被真实更近物体挡住的「本体辉光」部分 discard。
|
|
511
|
+
// 背景像素 baseDepth≈1.0(最远)永远不小于物体深度 → 不丢弃,浮空物体辉光正常显示。
|
|
512
|
+
renderer.setRenderTarget(selectDepthTestTextureTarget);
|
|
513
|
+
renderer.clear();
|
|
514
|
+
depthTestShader.uniforms.map.value = selectTextureTarget.texture;
|
|
515
|
+
depthTestShader.uniforms.baseDepth.value = baseDepthTexture;
|
|
516
|
+
depthTestShader.uniforms.selectDepth.value = selectDepthTexture;
|
|
517
|
+
depthTestShader.uniforms.cameraFar.value = camera.far;
|
|
518
|
+
fsQuad.render(renderer, depthTestShader);
|
|
519
|
+
// 4. 从「深度测试后的本体辉光」开始高斯模糊外扩(外扩环自动继承本体遮挡判定 → 不漏光)
|
|
520
|
+
const blurRadius = glow_width * 2.0;
|
|
521
|
+
gaussianBlurHShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
522
|
+
gaussianBlurVShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
523
|
+
gaussianBlurHShader.uniforms.radius.value = blurRadius;
|
|
524
|
+
gaussianBlurVShader.uniforms.radius.value = blurRadius;
|
|
525
|
+
gaussianBlurHShader.uniforms.sigma.value = glow_sigma;
|
|
526
|
+
gaussianBlurVShader.uniforms.sigma.value = glow_sigma;
|
|
527
|
+
renderer.setRenderTarget(blur1TextureTarget);
|
|
528
|
+
renderer.clear();
|
|
529
|
+
gaussianBlurHShader.uniforms.tDiffuse.value = selectDepthTestTextureTarget.texture;
|
|
530
|
+
fsQuad.render(renderer, gaussianBlurHShader);
|
|
531
|
+
renderer.setRenderTarget(blur2TextureTarget);
|
|
532
|
+
renderer.clear();
|
|
533
|
+
gaussianBlurVShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
534
|
+
fsQuad.render(renderer, gaussianBlurVShader);
|
|
535
|
+
if (glow_iterations > 1) {
|
|
536
|
+
for (let i = 1; i < glow_iterations; i++) {
|
|
537
|
+
renderer.setRenderTarget(blur1TextureTarget);
|
|
538
|
+
renderer.clear();
|
|
539
|
+
gaussianBlurHShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
540
|
+
fsQuad.render(renderer, gaussianBlurHShader);
|
|
541
|
+
renderer.setRenderTarget(blur2TextureTarget);
|
|
542
|
+
renderer.clear();
|
|
543
|
+
gaussianBlurVShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
544
|
+
fsQuad.render(renderer, gaussianBlurVShader);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
// 5. 辉光合成(上色「最终外扩辉光」blur2 → blur1)
|
|
548
|
+
renderer.setRenderTarget(blur1TextureTarget);
|
|
549
|
+
renderer.clear();
|
|
550
|
+
glowCompositeShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
551
|
+
glowCompositeShader.uniforms.color.value.set(glow_color);
|
|
552
|
+
glowCompositeShader.uniforms.opacity.value = 1.0;
|
|
553
|
+
glowCompositeShader.uniforms.threshold.value = glow_threshold;
|
|
554
|
+
glowCompositeShader.uniforms.intensity.value = glow_intensity;
|
|
555
|
+
fsQuad.render(renderer, glowCompositeShader);
|
|
556
|
+
// 5.5 ⭐ 外扩环深度测试(补齐此前只定义未调用的死代码,与 stroke_pass 同一修复):
|
|
557
|
+
// 本体深度随辉光一起外扩(separable H/V,外扩区取邻域最近深度),
|
|
558
|
+
// 再用它对外扩后的辉光做一次 depthTest —— 否则外扩环永远不参与遮挡判定,
|
|
559
|
+
// 物体被挡住时辉光依旧从遮挡物前方漏出来。
|
|
560
|
+
depthMinBlurShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
561
|
+
depthMinBlurShader.uniforms.radius.value = Math.max(1, blurRadius);
|
|
562
|
+
depthMinBlurShader.uniforms.direction.value.set(1, 0);
|
|
563
|
+
depthMinBlurShader.uniforms.tDepth.value = selectDepthTexture;
|
|
564
|
+
renderer.setRenderTarget(selectDepthBlurTmpTextureTarget);
|
|
565
|
+
renderer.clear();
|
|
566
|
+
fsQuad.render(renderer, depthMinBlurShader);
|
|
567
|
+
depthMinBlurShader.uniforms.direction.value.set(0, 1);
|
|
568
|
+
depthMinBlurShader.uniforms.tDepth.value = selectDepthBlurTmpTextureTarget.texture;
|
|
569
|
+
renderer.setRenderTarget(selectDepthBlurTextureTarget);
|
|
570
|
+
renderer.clear();
|
|
571
|
+
fsQuad.render(renderer, depthMinBlurShader);
|
|
572
|
+
// 5.6 对外扩后的辉光判遮挡(输出到独立 target,绝不回写 blur1,避免步骤 6 相减归零)
|
|
573
|
+
renderer.setRenderTarget(blurDepthTestTextureTarget);
|
|
574
|
+
renderer.clear();
|
|
575
|
+
depthTestShader.uniforms.map.value = blur1TextureTarget.texture;
|
|
576
|
+
depthTestShader.uniforms.baseDepth.value = baseDepthTexture;
|
|
577
|
+
depthTestShader.uniforms.selectDepth.value = selectDepthBlurTextureTarget.texture;
|
|
578
|
+
depthTestShader.uniforms.cameraFar.value = camera.far;
|
|
579
|
+
fsQuad.render(renderer, depthTestShader);
|
|
580
|
+
// 6. 合成到屏幕:filterSelect(blur=上色后且已判遮挡的最终外扩辉光, select=深度测试后本体辉光)
|
|
581
|
+
// = 仅保留辉光外扩环;本体被减掉。⚠️ blur 必须是最终外扩辉光,绝不能被 depthTest 结果覆盖
|
|
582
|
+
// (早期回归:误把 depthTest 结果上色进 blur1 → filterSelect 相减归零 → 辉光全不显示)。
|
|
583
|
+
renderer.setRenderTarget(originRenderTarget);
|
|
584
|
+
filterSelectShader.uniforms.selectTexture.value = selectDepthTestTextureTarget.texture;
|
|
585
|
+
filterSelectShader.uniforms.blurTexture.value = blurDepthTestTextureTarget.texture;
|
|
586
|
+
filterSelectShader.uniforms.opacity.value = glow_opacity;
|
|
587
|
+
// glow_additive=true 时用加性混合,光晕叠加到画面呈发光感(很亮那种);否则普通半透明覆盖(默认)
|
|
588
|
+
filterSelectShader.blending = glow_additive ? AdditiveBlending : NormalBlending;
|
|
589
|
+
fsQuad.render(renderer, filterSelectShader);
|
|
590
|
+
// 7. 薄高亮层:贴物体边缘的细亮环(rim),与外圈柔光晕并存 —— glow 的**默认行为,始终绘制、无开关参数**。
|
|
591
|
+
// 用本体 mask(selectDepthTestTextureTarget,深度测试后)做 1 次像素扩张 → 扩张区减本体 = 贴边薄环。
|
|
592
|
+
// 唯一可调项 glow_highlight_width(默认 2px):控制薄环粗细;=0 时扩张像素为 0,自然无可见环。
|
|
593
|
+
{
|
|
594
|
+
thinHighlightShader.uniforms.tMask.value = selectDepthTestTextureTarget.texture;
|
|
595
|
+
thinHighlightShader.uniforms.color.value.set(glow_color);
|
|
596
|
+
thinHighlightShader.uniforms.uWidth.value = glow_highlight_width;
|
|
597
|
+
thinHighlightShader.uniforms.opacity.value = glow_opacity;
|
|
598
|
+
thinHighlightShader.uniforms.intensity.value = glow_intensity;
|
|
599
|
+
thinHighlightShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
600
|
+
// 调试:window.__GLOW_HIGHLIGHT_VIS = true 时输出 rim 可视化(R=扩张区 G=本体 B=薄亮环)
|
|
601
|
+
thinHighlightShader.uniforms.uDebugVis.value = (window.__GLOW_HIGHLIGHT_VIS) ? 1.0 : 0.0;
|
|
602
|
+
// 跟随 glow_additive:加性时薄亮环也发光叠加,否则半透明覆盖
|
|
603
|
+
thinHighlightShader.blending = glow_additive ? AdditiveBlending : NormalBlending;
|
|
604
|
+
renderer.setRenderTarget(originRenderTarget);
|
|
605
|
+
fsQuad.render(renderer, thinHighlightShader);
|
|
606
|
+
}
|
|
607
|
+
}
|