@threepipe/webgi-plugins 0.6.3 → 0.7.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/CHANGELOG.md +93 -0
- package/README.md +13 -23
- package/THIRD_PARTY_NOTICES.md +243 -0
- package/dist/dependencies.txt +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4537 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4546 -19
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/buffer/VelocityBufferPlugin.d.ts.map +1 -1
- package/dist/plugins/extras/AdvancedGroundPlugin.d.ts +3 -2
- package/dist/plugins/extras/AdvancedGroundPlugin.d.ts.map +1 -1
- package/dist/plugins/extras/AnisotropyPlugin.d.ts.map +1 -1
- package/dist/plugins/extras/WatchHandsPlugin.d.ts.map +1 -1
- package/dist/plugins/index.d.ts +24 -24
- package/dist/plugins/postprocessing/SSGIPlugin.d.ts +3 -2
- package/dist/plugins/postprocessing/SSGIPlugin.d.ts.map +1 -1
- package/dist/plugins/postprocessing/SSReflectionPlugin.d.ts +1 -1
- package/dist/utils/ShadowMapBaker.d.ts +1 -1
- package/dist/utils/ShadowMapBaker.d.ts.map +1 -1
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1633 -0
- package/docs/classes/AdvancedGroundPlugin.html +69 -0
- package/docs/classes/AnisotropyPlugin.html +40 -0
- package/docs/classes/BloomPlugin.html +37 -0
- package/docs/classes/BloomPluginPass.html +34 -0
- package/docs/classes/DepthOfFieldPlugin.html +41 -0
- package/docs/classes/DepthOfFieldPluginPass.html +37 -0
- package/docs/classes/OutlinePlugin.html +75 -0
- package/docs/classes/OutlineRenderPass.html +25 -0
- package/docs/classes/SSContactShadowsPlugin.html +37 -0
- package/docs/classes/SSGIPlugin.html +42 -0
- package/docs/classes/SSGIPluginPass.html +44 -0
- package/docs/classes/SSReflectionPlugin.html +43 -0
- package/docs/classes/SSReflectionPluginPass.html +45 -0
- package/docs/classes/SSVelocityMaterial.html +7 -0
- package/docs/classes/TemporalAAPlugin.html +37 -0
- package/docs/classes/TemporalAAPluginPass.html +33 -0
- package/docs/classes/VelocityBufferPlugin.html +41 -0
- package/docs/classes/WatchHandsPlugin.html +39 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +1 -0
- package/docs/types/OutlinePluginPass.html +1 -0
- package/docs/types/OutlinePluginTarget.html +1 -0
- package/docs/types/SSGIPluginTarget.html +1 -0
- package/docs/types/SSReflectionPluginTarget.html +1 -0
- package/docs/types/VelocityBufferPluginPass.html +1 -0
- package/docs/types/VelocityBufferPluginTarget.html +1 -0
- package/docs/variables/anisotropyGLTFExtension.html +1 -0
- package/docs/variables/webgiPlugins.html +1 -0
- package/package.json +23 -22
- package/src/global.d.ts +27 -0
- package/src/index.ts +1 -0
- package/src/passes/BilateralFilterPass.ts +62 -0
- package/src/passes/shaders/ssaoBilateral.glsl +89 -0
- package/src/plugins/buffer/VelocityBufferPlugin.ts +270 -0
- package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.frag.glsl +46 -0
- package/src/plugins/buffer/shaders/VelocityBufferPlugin.mat.vert.glsl +51 -0
- package/src/plugins/buffer/shaders/VelocityBufferPlugin.unpack.glsl +8 -0
- package/src/plugins/extras/AdvancedGroundPlugin.ts +385 -0
- package/src/plugins/extras/AnisotropyPlugin.ts +519 -0
- package/src/plugins/extras/WatchHandsPlugin.ts +156 -0
- package/src/plugins/extras/shaders/anisotropyBsdf.glsl +64 -0
- package/src/plugins/extras/shaders/anisotropyTBN.glsl +35 -0
- package/src/plugins/index.ts +38 -0
- package/src/plugins/postprocessing/BloomPlugin.ts +374 -0
- package/src/plugins/postprocessing/DepthOfFieldPlugin.ts +470 -0
- package/src/plugins/postprocessing/OutlinePlugin.ts +476 -0
- package/src/plugins/postprocessing/SSContactShadowsPlugin.ts +374 -0
- package/src/plugins/postprocessing/SSGIPlugin.ts +597 -0
- package/src/plugins/postprocessing/SSReflectionPlugin.ts +563 -0
- package/src/plugins/postprocessing/TemporalAAPlugin.ts +301 -0
- package/src/plugins/postprocessing/shaders/dofBlurBox.glsl +46 -0
- package/src/plugins/postprocessing/shaders/dofCombine.glsl +68 -0
- package/src/plugins/postprocessing/shaders/dofComputeCoC.glsl +21 -0
- package/src/plugins/postprocessing/shaders/dofExpandCoC.glsl +56 -0
- package/src/plugins/postprocessing/shaders/dofPoissonBox.glsl +90 -0
- package/src/plugins/postprocessing/shaders/giPatch.glsl +53 -0
- package/src/plugins/postprocessing/shaders/hdrBloom.glsl +101 -0
- package/src/plugins/postprocessing/shaders/outline.glsl +60 -0
- package/src/plugins/postprocessing/shaders/outlineDepthFrag.glsl +22 -0
- package/src/plugins/postprocessing/shaders/outlineDepthVert.glsl +26 -0
- package/src/plugins/postprocessing/shaders/poissonDiskSamples.glsl +19 -0
- package/src/plugins/postprocessing/shaders/samplePointHelpers.glsl +3 -0
- package/src/plugins/postprocessing/shaders/ssrPatch.glsl +145 -0
- package/src/plugins/postprocessing/shaders/ssreflectionMain.glsl +69 -0
- package/src/plugins/postprocessing/shaders/ssrt.glsl +118 -0
- package/src/utils/FSShadowMaterial.ts +65 -0
- package/src/utils/RandomizedDirectionalLight.ts +288 -0
- package/src/utils/Reflector2.ts +309 -0
- package/src/utils/ShadowMapBaker.ts +527 -0
- package/src/utils/shaders/computeScreenSpaceVelocity.glsl +16 -0
- package/src/utils/shaders/getWorldPositionFromViewZ.glsl +9 -0
- package/src/utils/shaders/poissonDiskSamples.glsl +19 -0
- package/src/utils/shaders/reflectorSample.glsl +54 -0
- package/src/utils/shaders/seperableBlurShaderMasked.glsl +28 -0
- package/src/utils/shaders/seperableShadowBlur.glsl +21 -0
- package/src/utils/shaders/ssreflection.glsl +141 -0
- package/src/utils/shaders/ssrtao.glsl +275 -0
- package/src/utils/shaders/temporalaa.glsl +233 -0
- package/src/utils/shaders.ts +24 -0
- package/tsconfig.json +39 -44
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AViewerPluginSync, BaseGroundPlugin,
|
|
3
|
+
GBufferPlugin,
|
|
4
|
+
glsl,
|
|
5
|
+
IShaderPropertiesUpdater,
|
|
6
|
+
IWebGLRenderer,
|
|
7
|
+
matDefine,
|
|
8
|
+
MaterialExtension,
|
|
9
|
+
Matrix4,
|
|
10
|
+
PhysicalMaterial,
|
|
11
|
+
ProgressivePlugin,
|
|
12
|
+
serialize,
|
|
13
|
+
shaderReplaceString,
|
|
14
|
+
ThreeViewer,
|
|
15
|
+
uiFolderContainer,
|
|
16
|
+
uiSlider,
|
|
17
|
+
uiToggle,
|
|
18
|
+
updateMaterialDefines,
|
|
19
|
+
Vector2, uniform,
|
|
20
|
+
Vector3, onChange, RenderManager,
|
|
21
|
+
} from 'threepipe'
|
|
22
|
+
import ssrtShader from './shaders/ssrt.glsl'
|
|
23
|
+
|
|
24
|
+
const ShaderChunk = RenderManager.ShaderChunk
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* SS Contact Shadows Plugin
|
|
28
|
+
* Adds a material extension to PhysicalMaterial screen space ray traced contact shadows.
|
|
29
|
+
* It also adds a UI to the material to edit the settings.
|
|
30
|
+
* todo - remove It uses WEBGI_materials_clearcoat_tint glTF extension to save the settings in glTF files.
|
|
31
|
+
* @category Plugins
|
|
32
|
+
*/
|
|
33
|
+
@uiFolderContainer('SS Contact Shadows')
|
|
34
|
+
export class SSContactShadowsPlugin extends AViewerPluginSync {
|
|
35
|
+
static readonly PluginType = 'SSContactShadows'
|
|
36
|
+
static readonly OldPluginType = 'SSContactShadowsPlugin' // todo swap
|
|
37
|
+
|
|
38
|
+
@uiToggle('Enabled')
|
|
39
|
+
@serialize()
|
|
40
|
+
@onChange(SSContactShadowsPlugin.prototype.setDirty)
|
|
41
|
+
enabled = true
|
|
42
|
+
|
|
43
|
+
private _uniforms: any = {
|
|
44
|
+
sscsRadius: {value: 0.03},
|
|
45
|
+
sscsIntensity: {value: 1},
|
|
46
|
+
sscsTolerance: {value: 1.5},
|
|
47
|
+
|
|
48
|
+
// tLastFrame: {value: null}, // not needed since we dont need color
|
|
49
|
+
|
|
50
|
+
frameCount: {value: 0},
|
|
51
|
+
|
|
52
|
+
projection: {value: new Matrix4()},
|
|
53
|
+
cameraPositionWorld: {value: new Vector3()},
|
|
54
|
+
cameraNearFar: {value: new Vector2(0.1, 1000)},
|
|
55
|
+
|
|
56
|
+
sceneBoundingRadius: {value: 0},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@uniform({propKey: 'sscsRadius', onChange: SSContactShadowsPlugin.prototype.setDirty})
|
|
60
|
+
@uiSlider('Radius', [0.0001, 0.1], 0.0001)
|
|
61
|
+
@serialize() radius = 0.015
|
|
62
|
+
@uniform({propKey: 'sscsIntensity', onChange: SSContactShadowsPlugin.prototype.setDirty})
|
|
63
|
+
@uiSlider('Intensity', [0.0001, 1], 0.0001)
|
|
64
|
+
@serialize() intensity = 1
|
|
65
|
+
@uniform({propKey: 'sscsTolerance', onChange: SSContactShadowsPlugin.prototype.setDirty})
|
|
66
|
+
@uiSlider('Tolerance', [0.1, 5])
|
|
67
|
+
@serialize() tolerance = 1.5
|
|
68
|
+
|
|
69
|
+
private _defines: any = {
|
|
70
|
+
['PERSPECTIVE_CAMERA']: 1, // set in PerspectiveCamera2
|
|
71
|
+
}
|
|
72
|
+
@matDefine('SSCS_DEBUG', undefined, true, SSContactShadowsPlugin.prototype.setDirty)
|
|
73
|
+
@uiToggle('Debug only SSCS') @serialize() onlySSCSDebug = false
|
|
74
|
+
|
|
75
|
+
@matDefine('SSCS_STEP_COUNT', undefined, true, SSContactShadowsPlugin.prototype.setDirty)
|
|
76
|
+
@uiSlider('Step count', [1, 8], 1)
|
|
77
|
+
@serialize() stepCount = 2
|
|
78
|
+
|
|
79
|
+
dependencies = [GBufferPlugin]
|
|
80
|
+
|
|
81
|
+
// private _defines: any = {
|
|
82
|
+
// // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
83
|
+
// CLEARCOAT_TINT_DEBUG: false,
|
|
84
|
+
// }
|
|
85
|
+
|
|
86
|
+
// static AddSSContactShadows(material: PhysicalMaterial, params?: IMaterialUserData['_clearcoatTint']): IMaterialUserData['_clearcoatTint']|null {
|
|
87
|
+
// const ud = material?.userData
|
|
88
|
+
// if (!ud) return null
|
|
89
|
+
// if (!ud._clearcoatTint) ud._clearcoatTint = {}
|
|
90
|
+
// const tf = ud._clearcoatTint!
|
|
91
|
+
// tf.enableTint = true
|
|
92
|
+
// if (tf.tintColor === undefined) tf.tintColor = '#ffffff'
|
|
93
|
+
// if (tf.thickness === undefined) tf.thickness = 0.1
|
|
94
|
+
// if (tf.ior === undefined) tf.ior = 1.5
|
|
95
|
+
// params && Object.assign(tf, params)
|
|
96
|
+
// if (material.setDirty) material.setDirty()
|
|
97
|
+
// return tf
|
|
98
|
+
// }
|
|
99
|
+
|
|
100
|
+
// private _multiplyPass?: MultiplyPass
|
|
101
|
+
readonly materialExtension: MaterialExtension = {
|
|
102
|
+
uuid: SSContactShadowsPlugin.PluginType,
|
|
103
|
+
priority: 5,
|
|
104
|
+
shaderExtender: (shader, _material, _renderer) => {
|
|
105
|
+
if (!(shader as any).defines.SSCS_ENABLED) return
|
|
106
|
+
const rsS = 'float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {'
|
|
107
|
+
const lsS = glsl`
|
|
108
|
+
#ifndef D_sceneBoundingRadius
|
|
109
|
+
#define D_sceneBoundingRadius
|
|
110
|
+
uniform float sceneBoundingRadius;
|
|
111
|
+
#endif
|
|
112
|
+
#ifndef D_frameCount
|
|
113
|
+
#define D_frameCount
|
|
114
|
+
uniform float frameCount;
|
|
115
|
+
#endif
|
|
116
|
+
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, vec3 lightDirection ) {
|
|
117
|
+
vec3 ray_origin_view = -vViewPosition;
|
|
118
|
+
float rnd = interleavedGradientNoise(gl_FragCoord.xy, frameCount+34.);
|
|
119
|
+
float cameraDist = length(cameraPositionWorld);
|
|
120
|
+
// float radius = mix((cameraNearFar.y) + ray_origin_view.z, -ray_origin_view.z - cameraNearFar.x, rnd * 0.5 + 0.5)*sscsRadius;
|
|
121
|
+
float radius = mix((cameraDist + sceneBoundingRadius) + ray_origin_view.z, -ray_origin_view.z - max(0.0, cameraDist - sceneBoundingRadius), rnd * 0.5 + 0.5)*sscsRadius;
|
|
122
|
+
vec3 state = vec3(1.,(rnd+0.5)/float(SSCS_STEP_COUNT),2.);
|
|
123
|
+
traceRay(ray_origin_view, normalize(lightDirection) * radius, sscsTolerance * radius * 2., state, SSCS_STEP_COUNT);
|
|
124
|
+
state.z = state.z > 0.99 ? 1. : max(0.,min(state.z * state.z * (1.-sscsIntensity), 1.));
|
|
125
|
+
#if defined(SSCS_DEBUG) && SSCS_DEBUG > 0
|
|
126
|
+
return state.z;
|
|
127
|
+
#endif
|
|
128
|
+
`
|
|
129
|
+
const shadowChunk = `
|
|
130
|
+
#if SSCS_ENABLED
|
|
131
|
+
|
|
132
|
+
uniform float sscsIntensity;
|
|
133
|
+
uniform float sscsRadius;
|
|
134
|
+
uniform float sscsTolerance;
|
|
135
|
+
|
|
136
|
+
#define THREE_PACKING_INCLUDED // by threejs
|
|
137
|
+
#include <cameraHelpers>
|
|
138
|
+
#include <randomHelpers>
|
|
139
|
+
${ssrtShader}
|
|
140
|
+
|
|
141
|
+
#endif
|
|
142
|
+
` + shaderReplaceString(ShaderChunk.shadowmap_pars_fragment, rsS, `${lsS}\n`).replace('return mix( 1.0, shadow, shadowIntensity );', 'return mix( 1.0, min(shadow, state.z), shadowIntensity );')
|
|
143
|
+
|
|
144
|
+
// todo shaderReplaceString
|
|
145
|
+
shader.fragmentShader = shaderReplaceString(shader.fragmentShader, '#include <shadowmap_pars_fragment>', shadowChunk)
|
|
146
|
+
|
|
147
|
+
// Because this frag is also patched in Anisotropy
|
|
148
|
+
// no need for warning here.
|
|
149
|
+
shader.fragmentShader = shader.fragmentShader.replace('#include <lights_fragment_begin>', ShaderChunk.lights_fragment_begin)
|
|
150
|
+
|
|
151
|
+
shader.fragmentShader = shaderReplaceString(shader.fragmentShader,
|
|
152
|
+
'directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;',
|
|
153
|
+
'directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ], directLight.direction ) : 1.0;'
|
|
154
|
+
)
|
|
155
|
+
shader.fragmentShader = shaderReplaceString(shader.fragmentShader,
|
|
156
|
+
'directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;',
|
|
157
|
+
'directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ], directLight.direction ) : 1.0;')
|
|
158
|
+
|
|
159
|
+
// todo: point light?
|
|
160
|
+
// const rsL = ''
|
|
161
|
+
// const lsL = 'directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ], directLight.direction ) : 1.0;'
|
|
162
|
+
// const lightsFragmentBegin = ShaderChunk.lights_fragment_begin.replace(rsL, lsL)
|
|
163
|
+
|
|
164
|
+
// shader.fragmentShader = shader.fragmentShader.replace('#include <lightmap_fragment>', '')
|
|
165
|
+
// ;(shader as any).defines.USE_UV = ''
|
|
166
|
+
|
|
167
|
+
this._gbufferUnpackExtension?.shaderExtender?.(shader, _material, _renderer)
|
|
168
|
+
},
|
|
169
|
+
onObjectRender: (_, material, renderer: IWebGLRenderer) => {
|
|
170
|
+
const enabled: any = this.enabled &&
|
|
171
|
+
renderer.userData.screenSpaceRendering !== false &&
|
|
172
|
+
!material.userData?.pluginsDisabled &&
|
|
173
|
+
!material.userData?.sscsDisabled ? 1 : 0
|
|
174
|
+
|
|
175
|
+
// const tfUd = material.userData._clearcoatTint
|
|
176
|
+
// if (!tfUd?.enableTint) return
|
|
177
|
+
//
|
|
178
|
+
// this._uniforms.ccTintColor.value.set(tfUd.tintColor) // could be number or string also, apart from Color
|
|
179
|
+
// this._uniforms.ccThickness.value = tfUd.thickness
|
|
180
|
+
// this._uniforms.ccIor.value = tfUd.ior
|
|
181
|
+
updateMaterialDefines({
|
|
182
|
+
...this._defines,
|
|
183
|
+
['SSCS_ENABLED']: enabled,
|
|
184
|
+
}, material)
|
|
185
|
+
},
|
|
186
|
+
extraUniforms: {
|
|
187
|
+
...this._uniforms, // todo should not be static because of multiple viewers
|
|
188
|
+
},
|
|
189
|
+
extraDefines: {},
|
|
190
|
+
computeCacheKey: (_: PhysicalMaterial) => {
|
|
191
|
+
return this.isDisabled() ? '0' : '1'
|
|
192
|
+
},
|
|
193
|
+
isCompatible: (material1: PhysicalMaterial) => {
|
|
194
|
+
return material1.isPhysicalMaterial
|
|
195
|
+
},
|
|
196
|
+
// getUiConfig: (material: PhysicalMaterial) => {
|
|
197
|
+
// const viewer = this._viewer!
|
|
198
|
+
// if (material.userData._clearcoatTint === undefined) material.userData._clearcoatTint = {}
|
|
199
|
+
// const state = material.userData._clearcoatTint
|
|
200
|
+
// const config: UiObjectConfig = {
|
|
201
|
+
// type: 'folder',
|
|
202
|
+
// label: 'Clearcoat Tint',
|
|
203
|
+
// onChange: (ev)=>{
|
|
204
|
+
// if (!ev.config) return
|
|
205
|
+
// this.setDirty()
|
|
206
|
+
// },
|
|
207
|
+
// children: [
|
|
208
|
+
// {
|
|
209
|
+
// type: 'checkbox',
|
|
210
|
+
// label: 'Enabled',
|
|
211
|
+
// get value() {
|
|
212
|
+
// return state.enableTint || false
|
|
213
|
+
// },
|
|
214
|
+
// set value(v) {
|
|
215
|
+
// if (v === state.enableTint) return
|
|
216
|
+
// if (v) {
|
|
217
|
+
// if (!SSContactShadowsPlugin.AddSSContactShadows(material))
|
|
218
|
+
// viewer.dialog.alert('Cannot add clearcoat tint.')
|
|
219
|
+
// } else {
|
|
220
|
+
// state.enableTint = false
|
|
221
|
+
// if (material.setDirty) material.setDirty()
|
|
222
|
+
// }
|
|
223
|
+
// config.uiRefresh?.(true, 'postFrame')
|
|
224
|
+
// },
|
|
225
|
+
// },
|
|
226
|
+
// {
|
|
227
|
+
// type: 'color',
|
|
228
|
+
// label: 'Tint color',
|
|
229
|
+
// hidden: () => !state.enableTint,
|
|
230
|
+
// property: [state, 'tintColor'],
|
|
231
|
+
// },
|
|
232
|
+
// {
|
|
233
|
+
// type: 'input',
|
|
234
|
+
// label: 'Thickness',
|
|
235
|
+
// hidden: () => !state.enableTint,
|
|
236
|
+
// property: [state, 'thickness'],
|
|
237
|
+
// },
|
|
238
|
+
// {
|
|
239
|
+
// type: 'slider',
|
|
240
|
+
// bounds: [0.8, 2.5],
|
|
241
|
+
// label: 'IOR',
|
|
242
|
+
// hidden: () => !state.enableTint,
|
|
243
|
+
// property: [state, 'ior'],
|
|
244
|
+
// },
|
|
245
|
+
// ],
|
|
246
|
+
// }
|
|
247
|
+
// return config
|
|
248
|
+
// },
|
|
249
|
+
updaters: ()=>
|
|
250
|
+
[
|
|
251
|
+
// this._viewer?.getPlugin(GBufferPlugin),
|
|
252
|
+
this._viewer?.getPlugin(ProgressivePlugin),
|
|
253
|
+
this._viewer?.scene.renderCamera,
|
|
254
|
+
this._viewer?.renderManager,
|
|
255
|
+
this._viewer?.scene,
|
|
256
|
+
] as IShaderPropertiesUpdater[],
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
setDirty() {
|
|
260
|
+
this.materialExtension?.setDirty?.()
|
|
261
|
+
this._viewer?.setDirty()
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// private _loaderCreate({loader}: {loader: GLTFLoader2}) {
|
|
265
|
+
// if (!loader.isGLTFLoader2) return
|
|
266
|
+
// loader.register((p) => new GLTFMaterialsSSContactShadowsExtensionImport(p))
|
|
267
|
+
// }
|
|
268
|
+
|
|
269
|
+
constructor(enabled = true) {
|
|
270
|
+
super()
|
|
271
|
+
// this._loaderCreate = this._loaderCreate.bind(this)
|
|
272
|
+
this.enabled = enabled
|
|
273
|
+
|
|
274
|
+
// // for tweakpane UI. todo
|
|
275
|
+
// ;(this as any).userData = {setDirty: ()=>{
|
|
276
|
+
// this._viewer?.setDirty()
|
|
277
|
+
// }}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
onAdded(v: ThreeViewer) {
|
|
281
|
+
super.onAdded(v)
|
|
282
|
+
// v.addEventListener('preRender', this._preRender)
|
|
283
|
+
v.assetManager.materials.registerMaterialExtension(this.materialExtension)
|
|
284
|
+
if (v.getPlugin(BaseGroundPlugin)) v.getPlugin(BaseGroundPlugin)!.material!.userData.sscsDisabled = false // todo remove after threepipe update
|
|
285
|
+
this._gbufferUnpackExtensionChanged()
|
|
286
|
+
v.renderManager.addEventListener('gbufferUnpackExtensionChanged', this._gbufferUnpackExtensionChanged)
|
|
287
|
+
// v.assetManager.importer.addEventListener('loaderCreate', this._loaderCreate as any)
|
|
288
|
+
// v.assetManager.exporter.getExporter('gltf', 'glb')?.extensions?.push(glTFMaterialsSSContactShadowsExtensionExport)
|
|
289
|
+
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
onRemove(v: ThreeViewer) {
|
|
293
|
+
v.assetManager.materials?.unregisterMaterialExtension(this.materialExtension)
|
|
294
|
+
v.renderManager.removeEventListener('gbufferUnpackExtensionChanged', this._gbufferUnpackExtensionChanged)
|
|
295
|
+
// v.assetManager.importer?.removeEventListener('loaderCreate', this._loaderCreate as any)
|
|
296
|
+
// const exporter = v.assetManager.exporter.getExporter('gltf', 'glb')
|
|
297
|
+
// if (exporter) {
|
|
298
|
+
// const index = exporter.extensions?.indexOf(glTFMaterialsSSContactShadowsExtensionExport)
|
|
299
|
+
// if (index !== undefined && index >= 0) exporter.extensions?.splice(index, 1)
|
|
300
|
+
// }
|
|
301
|
+
return super.onRemove(v)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
private _gbufferUnpackExtension = undefined as MaterialExtension|undefined
|
|
305
|
+
|
|
306
|
+
private _gbufferUnpackExtensionChanged = ()=>{
|
|
307
|
+
if (!this._viewer) throw new Error('SSContactShadowPlugin: pass/viewer not created yet')
|
|
308
|
+
const newExtension = this._viewer.renderManager.gbufferUnpackExtension
|
|
309
|
+
if (this._gbufferUnpackExtension === newExtension) return
|
|
310
|
+
if (this._gbufferUnpackExtension) this.setGBufferUnpackExtension(undefined)
|
|
311
|
+
this._gbufferUnpackExtension = newExtension
|
|
312
|
+
if (this._gbufferUnpackExtension) this.setGBufferUnpackExtension(this._gbufferUnpackExtension)
|
|
313
|
+
else this._viewer.console.warn('SSContactShadowPlugin: GBuffer unpack extension removed')
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
setGBufferUnpackExtension(extension: MaterialExtension|undefined) {
|
|
317
|
+
this._gbufferUnpackExtension = extension
|
|
318
|
+
if (!this._gbufferUnpackExtension) return
|
|
319
|
+
|
|
320
|
+
// todo not possible to remove it?
|
|
321
|
+
Object.assign(this.materialExtension.extraUniforms!, this._gbufferUnpackExtension.extraUniforms)
|
|
322
|
+
Object.assign(this.materialExtension.extraDefines!, this._gbufferUnpackExtension.extraDefines)
|
|
323
|
+
}
|
|
324
|
+
// public static readonly CLEARCOAT_TINT_GLTF_EXTENSION = 'WEBGI_materials_clearcoat_tint'
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// declare module '../../core/IMaterial' {
|
|
329
|
+
// interface IMaterialUserData {
|
|
330
|
+
// _clearcoatTint?: {
|
|
331
|
+
// enableTint?: boolean
|
|
332
|
+
// tintColor?: Color|number|string
|
|
333
|
+
// thickness?: number
|
|
334
|
+
// ior?: number
|
|
335
|
+
// }
|
|
336
|
+
// }
|
|
337
|
+
// }
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* SSContactShadows Materials Extension
|
|
341
|
+
*
|
|
342
|
+
* Specification: https://webgi.xyz/docs/gltf-extensions/WEBGI_materials_clearcoat_tint.html
|
|
343
|
+
*/
|
|
344
|
+
// class GLTFMaterialsSSContactShadowsExtensionImport implements GLTFLoaderPlugin {
|
|
345
|
+
// public name: string
|
|
346
|
+
// public parser: GLTFParser
|
|
347
|
+
//
|
|
348
|
+
// constructor(parser: GLTFParser) {
|
|
349
|
+
// this.parser = parser
|
|
350
|
+
// this.name = SSContactShadowsPlugin.CLEARCOAT_TINT_GLTF_EXTENSION
|
|
351
|
+
// }
|
|
352
|
+
//
|
|
353
|
+
// async extendMaterialParams(materialIndex: number, materialParams: any) {
|
|
354
|
+
// const parser = this.parser
|
|
355
|
+
// const materialDef = parser.json.materials[materialIndex]
|
|
356
|
+
// if (!materialDef.extensions || !materialDef.extensions[this.name]) return
|
|
357
|
+
// const extension = materialDef.extensions[this.name]
|
|
358
|
+
// if (!materialParams.userData) materialParams.userData = {}
|
|
359
|
+
// SSContactShadowsPlugin.AddSSContactShadows(materialParams)
|
|
360
|
+
// ThreeSerialization.Deserialize(extension, materialParams.userData._clearcoatTint)
|
|
361
|
+
// }
|
|
362
|
+
// }
|
|
363
|
+
//
|
|
364
|
+
// const glTFMaterialsSSContactShadowsExtensionExport = (w: GLTFWriter2)=> ({
|
|
365
|
+
// writeMaterial: (material: any, materialDef: any) => {
|
|
366
|
+
// if (!material.isMeshStandardMaterial || !material.userData._clearcoatTint?.enableTint) return
|
|
367
|
+
// materialDef.extensions = materialDef.extensions || {}
|
|
368
|
+
//
|
|
369
|
+
// const extensionDef: any = ThreeSerialization.Serialize(material.userData._clearcoatTint)
|
|
370
|
+
//
|
|
371
|
+
// materialDef.extensions[ SSContactShadowsPlugin.CLEARCOAT_TINT_GLTF_EXTENSION ] = extensionDef
|
|
372
|
+
// w.extensionsUsed[ SSContactShadowsPlugin.CLEARCOAT_TINT_GLTF_EXTENSION ] = true
|
|
373
|
+
// },
|
|
374
|
+
// })
|