@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,301 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Camera,
|
|
3
|
+
CopyShader,
|
|
4
|
+
ExtendedShaderPass,
|
|
5
|
+
GBufferPlugin,
|
|
6
|
+
generateUiConfig,
|
|
7
|
+
getOrCall,
|
|
8
|
+
ICamera,
|
|
9
|
+
IPassID,
|
|
10
|
+
IPipelinePass,
|
|
11
|
+
IRenderManager,
|
|
12
|
+
IScene,
|
|
13
|
+
IWebGLRenderer,
|
|
14
|
+
matDefineBool,
|
|
15
|
+
MaterialExtension,
|
|
16
|
+
Matrix4,
|
|
17
|
+
PipelinePassPlugin,
|
|
18
|
+
ProgressivePlugin,
|
|
19
|
+
serialize,
|
|
20
|
+
ThreeViewer,
|
|
21
|
+
uiConfig,
|
|
22
|
+
UiObjectConfig,
|
|
23
|
+
uiToggle,
|
|
24
|
+
uiVector,
|
|
25
|
+
uniform,
|
|
26
|
+
ValOrFunc,
|
|
27
|
+
Vector2,
|
|
28
|
+
WebGLRenderTarget,
|
|
29
|
+
} from 'threepipe'
|
|
30
|
+
import {getShaders} from "../../utils/shaders";
|
|
31
|
+
|
|
32
|
+
const passId = 'taa'
|
|
33
|
+
type TemporalAAPassId = typeof passId
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Temporal Anti-Aliasing Plugin
|
|
37
|
+
*
|
|
38
|
+
* This plugin uses a temporal anti-aliasing pass to smooth out the final image when the camera or some mesh is moving
|
|
39
|
+
* @category Plugins
|
|
40
|
+
*/
|
|
41
|
+
export class TemporalAAPlugin
|
|
42
|
+
extends PipelinePassPlugin<TemporalAAPluginPass<TemporalAAPassId>, TemporalAAPassId> {
|
|
43
|
+
static readonly PluginType = 'TAA'
|
|
44
|
+
static readonly OldPluginType = 'TemporalAAPlugin' // todo swap
|
|
45
|
+
readonly passId = passId
|
|
46
|
+
|
|
47
|
+
// readonly materialExtension: MaterialExtension = uiConfigMaterialExtension(this._getUiConfig.bind(this), TemporalAAPlugin.PluginType)
|
|
48
|
+
|
|
49
|
+
constructor(enabled = true) {
|
|
50
|
+
super()
|
|
51
|
+
this.enabled = enabled
|
|
52
|
+
this.setDirty = this.setDirty.bind(this)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
private _stableNoise = true
|
|
57
|
+
/**
|
|
58
|
+
* Same as BaseRenderer.stableNoise Use total frame count, if this is set to true, then frameCount won't be reset when the viewer is set to dirty.
|
|
59
|
+
* Which will generate different random numbers for each frame during postprocessing steps. With TAA set properly, this will give a smoother result.
|
|
60
|
+
*/
|
|
61
|
+
@uiToggle('Stable Noise (Total frame count)')
|
|
62
|
+
get stableNoise(): boolean {
|
|
63
|
+
return this._viewer?.renderManager.stableNoise ?? this._stableNoise
|
|
64
|
+
}
|
|
65
|
+
set stableNoise(v: boolean) {
|
|
66
|
+
if (this._viewer) this._viewer.renderManager.stableNoise = v
|
|
67
|
+
this._stableNoise = v
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@uiConfig(undefined, {unwrapContents: true}) declare protected _pass?: TemporalAAPluginPass<TemporalAAPassId>
|
|
71
|
+
|
|
72
|
+
private _gbufferUnpackExtension = undefined as MaterialExtension|undefined
|
|
73
|
+
private _gbufferUnpackExtensionChanged = ()=>{
|
|
74
|
+
if (!this._pass || !this._viewer) throw new Error('TemporalAAPlugin: pass/viewer not created yet')
|
|
75
|
+
const newExtension = this._viewer.renderManager.gbufferUnpackExtension
|
|
76
|
+
if (this._gbufferUnpackExtension === newExtension) return
|
|
77
|
+
if (this._gbufferUnpackExtension) this._pass.material.unregisterMaterialExtensions([this._gbufferUnpackExtension])
|
|
78
|
+
this._gbufferUnpackExtension = newExtension
|
|
79
|
+
if (this._gbufferUnpackExtension) this._pass.material.registerMaterialExtensions([this._gbufferUnpackExtension])
|
|
80
|
+
else this._viewer.console.warn('TemporalAAPlugin: GBuffer unpack extension removed')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected _createPass() {
|
|
84
|
+
if (!this._viewer) throw new Error('TemporalAAPlugin: viewer not set')
|
|
85
|
+
if (!this._viewer.renderManager.gbufferTarget || !this._viewer.renderManager.gbufferUnpackExtension)
|
|
86
|
+
throw new Error('TemporalAAPlugin: GBuffer target not created. GBufferPlugin is required.')
|
|
87
|
+
const applyOnBackground = !!this._viewer.renderManager.msaa
|
|
88
|
+
const t = new TemporalAAPluginPass(this.passId, ()=>this._viewer?.getPlugin(ProgressivePlugin)?.target, applyOnBackground)
|
|
89
|
+
return t
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
dependencies = [GBufferPlugin, ProgressivePlugin] // todo use gbufferUnpackExtension from render manager to support depth buffer plugin as well.
|
|
93
|
+
|
|
94
|
+
onAdded(viewer: ThreeViewer) {
|
|
95
|
+
super.onAdded(viewer)
|
|
96
|
+
this._gbufferUnpackExtensionChanged()
|
|
97
|
+
viewer.renderManager.addEventListener('gbufferUnpackExtensionChanged', this._gbufferUnpackExtensionChanged)
|
|
98
|
+
viewer.renderManager.addEventListener('resize', this._pass!.onSizeUpdate)
|
|
99
|
+
// viewer.materialManager.registerMaterialExtension(this.materialExtension)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
onRemove(viewer: ThreeViewer) {
|
|
103
|
+
viewer.renderManager.removeEventListener('gbufferUnpackExtensionChanged', this._gbufferUnpackExtensionChanged)
|
|
104
|
+
viewer.renderManager.removeEventListener('resize', this._pass!.onSizeUpdate)
|
|
105
|
+
super.onRemove(viewer)
|
|
106
|
+
// viewer.materialManager.unregisterMaterialExtension(this.materialExtension)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
uiConfig: UiObjectConfig = {
|
|
110
|
+
type: 'folder',
|
|
111
|
+
label: 'TemporalAA Plugin',
|
|
112
|
+
onChange: this.setDirty.bind(this),
|
|
113
|
+
children: [
|
|
114
|
+
...generateUiConfig(this) || [],
|
|
115
|
+
],
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
protected _beforeRender(scene: IScene, camera: ICamera, renderManager: IRenderManager): boolean {
|
|
119
|
+
if (!super._beforeRender(scene, camera, renderManager)) return false
|
|
120
|
+
const pass = this.pass
|
|
121
|
+
const v = this._viewer
|
|
122
|
+
if (!pass || !v) return false
|
|
123
|
+
|
|
124
|
+
const frame = renderManager.frameCount
|
|
125
|
+
pass.taaEnabled = frame <= 1 && scene.renderCamera === scene.mainCamera
|
|
126
|
+
if (!pass.taaEnabled) return false
|
|
127
|
+
|
|
128
|
+
const cam = camera
|
|
129
|
+
if (!cam) return false
|
|
130
|
+
|
|
131
|
+
cam.updateMatrixWorld(true)
|
|
132
|
+
|
|
133
|
+
cam.updateShaderProperties(pass.material) // for cameraNearFar
|
|
134
|
+
|
|
135
|
+
pass.updateCameraProperties(cam)
|
|
136
|
+
|
|
137
|
+
pass.target = v.getPlugin(ProgressivePlugin)!.target as any
|
|
138
|
+
return true
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// region to be done or removed
|
|
142
|
+
|
|
143
|
+
// static AddTemporalAAData(material: IMaterial, params?: IMaterialUserData['TemporalAA'], setDirty = true): IMaterialUserData['TemporalAA']|null {
|
|
144
|
+
// const ud = material?.userData
|
|
145
|
+
// if (!ud) return null
|
|
146
|
+
// if (!ud[TemporalAAPlugin.PluginType]) {
|
|
147
|
+
// ud[TemporalAAPlugin.PluginType] = {}
|
|
148
|
+
// }
|
|
149
|
+
// const data = ud[TemporalAAPlugin.PluginType]!
|
|
150
|
+
// data.enable = true
|
|
151
|
+
// params && Object.assign(data, params)
|
|
152
|
+
// if (setDirty && material.setDirty) material.setDirty()
|
|
153
|
+
// return data
|
|
154
|
+
// }
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* This uiConfig is added to each material by extension
|
|
158
|
+
* @param material
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
// private _getUiConfig(material: IMaterial) {
|
|
162
|
+
// const config: UiObjectConfig = {
|
|
163
|
+
// type: 'folder',
|
|
164
|
+
// label: 'TemporalAA',
|
|
165
|
+
// children: [
|
|
166
|
+
// {
|
|
167
|
+
// type: 'checkbox',
|
|
168
|
+
// label: 'Enabled',
|
|
169
|
+
// get value() {
|
|
170
|
+
// return material.userData[TemporalAAPlugin.PluginType]?.enable ?? true
|
|
171
|
+
// },
|
|
172
|
+
// set value(v) {
|
|
173
|
+
// let data = material.userData[TemporalAAPlugin.PluginType]
|
|
174
|
+
// if (v === data?.enable) return
|
|
175
|
+
// if (!data) data = TemporalAAPlugin.AddTemporalAAData(material, undefined, false)!
|
|
176
|
+
// data.enable = v
|
|
177
|
+
// material.setDirty()
|
|
178
|
+
// config.uiRefresh?.(true, 'postFrame')
|
|
179
|
+
// },
|
|
180
|
+
// onChange: this.setDirty,
|
|
181
|
+
// },
|
|
182
|
+
// ],
|
|
183
|
+
// }
|
|
184
|
+
// return config
|
|
185
|
+
// }
|
|
186
|
+
|
|
187
|
+
// endregion
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export class TemporalAAPluginPass<Tid extends IPassID> extends ExtendedShaderPass implements IPipelinePass<Tid> {
|
|
191
|
+
before = ['progressive']
|
|
192
|
+
after = [] // leave empty so that this is placed right before progressive
|
|
193
|
+
required = ['render', 'progressive']
|
|
194
|
+
|
|
195
|
+
public target: ValOrFunc<WebGLRenderTarget|undefined>
|
|
196
|
+
public readonly passId: Tid
|
|
197
|
+
|
|
198
|
+
constructor(pid: Tid, target: ValOrFunc<WebGLRenderTarget|undefined>, applyOnBackground = false) {
|
|
199
|
+
super({
|
|
200
|
+
vertexShader: CopyShader.vertexShader,
|
|
201
|
+
fragmentShader: getShaders().temporalAA,
|
|
202
|
+
uniforms: {
|
|
203
|
+
currentRT: {value: null},
|
|
204
|
+
previousRT: {value: null},
|
|
205
|
+
previousRTSize: {value: new Vector2()},
|
|
206
|
+
cameraNearFar: {value: new Vector2()},
|
|
207
|
+
lastProjectionViewMatrix: {value: new Matrix4()},
|
|
208
|
+
currentProjectionViewMatrix: {value: new Matrix4()},
|
|
209
|
+
projection: {value: new Matrix4()},
|
|
210
|
+
inverseViewMatrix: {value: new Matrix4()},
|
|
211
|
+
jitterSample: {value: new Vector2()},
|
|
212
|
+
firstFrame: {value: true},
|
|
213
|
+
},
|
|
214
|
+
defines: {
|
|
215
|
+
['QUALITY']: 1,
|
|
216
|
+
['UNJITTER']: 0,
|
|
217
|
+
['BACKGROUND_TAA']: applyOnBackground ? 1 : 0,
|
|
218
|
+
},
|
|
219
|
+
|
|
220
|
+
}, 'currentRT', 'previousRT')
|
|
221
|
+
this.passId = pid
|
|
222
|
+
this.onSizeUpdate = this.onSizeUpdate.bind(this)
|
|
223
|
+
this.target = target
|
|
224
|
+
this.clear = false
|
|
225
|
+
this.needsSwap = true
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* to switch with ssaa, for internal use only, dont set from outside
|
|
231
|
+
*/
|
|
232
|
+
taaEnabled = true
|
|
233
|
+
|
|
234
|
+
render(renderer: IWebGLRenderer, writeBuffer?: WebGLRenderTarget | null, readBuffer?: WebGLRenderTarget, deltaTime?: number, maskActive?: boolean) {
|
|
235
|
+
if (!this.taaEnabled || !this.enabled) {
|
|
236
|
+
this.needsSwap = false
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
this.needsSwap = true
|
|
240
|
+
|
|
241
|
+
this.uniforms.previousRT.value = getOrCall(this.target)?.texture ?? null
|
|
242
|
+
|
|
243
|
+
super.render(renderer, writeBuffer, readBuffer, deltaTime, maskActive)
|
|
244
|
+
|
|
245
|
+
// ;(renderer as any).baseRenderer.blit(writeBuffer.texture, this.target, {clear: false}) // this is done in the progressive plugin
|
|
246
|
+
|
|
247
|
+
this.uniforms.lastProjectionViewMatrix.value.copy(this.uniforms.currentProjectionViewMatrix.value)
|
|
248
|
+
|
|
249
|
+
this.uniforms.firstFrame.value = false
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
updateCameraProperties(camera?: Camera): void {
|
|
255
|
+
if (!camera) return
|
|
256
|
+
this.uniforms.currentProjectionViewMatrix.value.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse)
|
|
257
|
+
// this.uniforms.lastProjectionViewMatrix.value.copy(this.lastProjectionViewMatrix_)
|
|
258
|
+
// this.uniforms.ProjectionMatrix.value.copy(this.projectionMatrix_)
|
|
259
|
+
this.uniforms.inverseViewMatrix.value.copy(camera.matrixWorld)
|
|
260
|
+
}
|
|
261
|
+
onSizeUpdate() {
|
|
262
|
+
this.uniforms.firstFrame.value = true
|
|
263
|
+
this.setDirty()
|
|
264
|
+
}
|
|
265
|
+
setSize(width: number, height: number) {
|
|
266
|
+
super.setSize(width, height)
|
|
267
|
+
this.onSizeUpdate()
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
@serialize() @uniform()
|
|
271
|
+
@uiVector('Feedback', undefined, 0.0001)
|
|
272
|
+
feedBack: Vector2 = new Vector2(0.88, 0.97)
|
|
273
|
+
|
|
274
|
+
@uiToggle()
|
|
275
|
+
@matDefineBool('DEBUG_VELOCITY', undefined, false, undefined, true)
|
|
276
|
+
debugVelocity = false
|
|
277
|
+
|
|
278
|
+
uiConfig: UiObjectConfig = {
|
|
279
|
+
type: 'folder',
|
|
280
|
+
label: 'Temporal AA Pass',
|
|
281
|
+
onChange: this.setDirty,
|
|
282
|
+
children: [
|
|
283
|
+
{
|
|
284
|
+
type: 'checkbox',
|
|
285
|
+
label: 'Enabled',
|
|
286
|
+
property: [this, 'enabled'],
|
|
287
|
+
onChange: ()=>this.onSizeUpdate(),
|
|
288
|
+
},
|
|
289
|
+
...generateUiConfig(this)?.filter(c=>c && (c as any).label !== 'Enabled') || [],
|
|
290
|
+
],
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
declare module 'threepipe' {
|
|
296
|
+
// interface IMaterialUserData {
|
|
297
|
+
// [TemporalAAPlugin.PluginType]?: {
|
|
298
|
+
// enable?: boolean
|
|
299
|
+
// }
|
|
300
|
+
// }
|
|
301
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#include <common>
|
|
2
|
+
varying vec2 vUv;
|
|
3
|
+
//uniform sampler2D cocTexture;
|
|
4
|
+
uniform vec2 colorTextureSize;
|
|
5
|
+
//uniform vec2 screenSize;
|
|
6
|
+
uniform vec2 direction;
|
|
7
|
+
const float MAXIMUM_BLUR_SIZE = 16.0;
|
|
8
|
+
|
|
9
|
+
const float SIGMA = 5.0;
|
|
10
|
+
const int NUM_SAMPLES = 4;
|
|
11
|
+
|
|
12
|
+
float normpdf(in float x, in float sigma)
|
|
13
|
+
{
|
|
14
|
+
return 0.39894*exp(-0.5*x*x/(sigma*sigma))/sigma;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
vec3 weightedBlur() {
|
|
18
|
+
float cocIn = 2. * cocTextureTexelToLinear(texture2D(cocTexture, vUv)).a - 1.;
|
|
19
|
+
float kernelRadius = MAXIMUM_BLUR_SIZE * cocIn;
|
|
20
|
+
vec2 invSize = 1.0 / colorTextureSize;
|
|
21
|
+
cocIn *= cocIn * cocIn;
|
|
22
|
+
float centerSpaceWeight = normpdf(0.0, SIGMA) * abs(cocIn);
|
|
23
|
+
float weightSum = centerSpaceWeight;
|
|
24
|
+
vec3 centerSample = colorTextureTexelToLinear(texture2D(colorTexture, vUv)).rgb;
|
|
25
|
+
vec3 diffuseSum = centerSample * weightSum;
|
|
26
|
+
vec2 delta = invSize * kernelRadius/float(NUM_SAMPLES);
|
|
27
|
+
for( int i = 1; i <= NUM_SAMPLES; i ++ ) { // todo unroll?
|
|
28
|
+
float spaceWeight = normpdf(float(i), SIGMA);
|
|
29
|
+
vec2 texcoord = direction * delta * float(i);
|
|
30
|
+
vec4 rightSample = colorTextureTexelToLinear(texture2D( colorTexture, vUv + texcoord));
|
|
31
|
+
vec4 leftSample = colorTextureTexelToLinear(texture2D( colorTexture, vUv - texcoord));
|
|
32
|
+
float leftCocWeight = abs(2. * cocTextureTexelToLinear(texture2D( cocTexture, vUv - texcoord)).a - 1.);
|
|
33
|
+
float rightCocWeight = abs(2. * cocTextureTexelToLinear(texture2D( cocTexture, vUv + texcoord)).a - 1.);
|
|
34
|
+
leftCocWeight *= leftCocWeight * leftCocWeight;
|
|
35
|
+
rightCocWeight *= rightCocWeight * rightCocWeight;
|
|
36
|
+
diffuseSum += ( (leftSample.rgb * leftCocWeight) + (rightSample.rgb * rightCocWeight) ) * spaceWeight;
|
|
37
|
+
weightSum += (spaceWeight * (leftCocWeight + rightCocWeight));
|
|
38
|
+
}
|
|
39
|
+
return diffuseSum/weightSum;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
void main() {
|
|
43
|
+
gl_FragColor = vec4(weightedBlur(), 1.0);
|
|
44
|
+
|
|
45
|
+
#include <colorspace_fragment>
|
|
46
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#include <common>
|
|
2
|
+
#include <packing>
|
|
3
|
+
|
|
4
|
+
varying vec2 vUv;
|
|
5
|
+
//uniform sampler2D blurTexture;
|
|
6
|
+
uniform vec2 cocTextureSize;
|
|
7
|
+
uniform vec2 nearFarBlurScale;
|
|
8
|
+
uniform vec2 cameraNearFar;
|
|
9
|
+
uniform vec2 focalDepthRange;
|
|
10
|
+
|
|
11
|
+
uniform vec2 crossCenter;
|
|
12
|
+
uniform float crossRadius;
|
|
13
|
+
uniform float crossAlpha;
|
|
14
|
+
uniform vec3 crossColor;
|
|
15
|
+
|
|
16
|
+
float smoothBoundary(float d, float smooothFactor) {
|
|
17
|
+
smooothFactor *= 0.5;
|
|
18
|
+
float value = smoothstep(-smooothFactor,smooothFactor, d);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
float circle( vec2 p, float r ) {
|
|
23
|
+
return min((length(p) - r), -(length(p) - r - 0.01));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
float computeCoc() {
|
|
27
|
+
float depth = getDepth(vUv);
|
|
28
|
+
if(depth > 1.0 - 0.01) return max(nearFarBlurScale.x, nearFarBlurScale.y);
|
|
29
|
+
depth = mix(cameraNearFar.x, cameraNearFar.y, depth);
|
|
30
|
+
float coc = (depth - focalDepthRange.x)/focalDepthRange.y;
|
|
31
|
+
coc = clamp(coc, -1., 1.);
|
|
32
|
+
return (coc > 0.0 ? coc * nearFarBlurScale.y : coc * nearFarBlurScale.x);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void main() {
|
|
36
|
+
vec4 blur = blurTextureTexelToLinear(texture2D(blurTexture, vUv));
|
|
37
|
+
float scale = 0.5;
|
|
38
|
+
blur += blurTextureTexelToLinear(texture2D(blurTexture, vUv + scale * vec2(1.0, 1.0) / cocTextureSize));
|
|
39
|
+
blur += blurTextureTexelToLinear(texture2D(blurTexture, vUv + scale * vec2(-1.0, 1.0) / cocTextureSize));
|
|
40
|
+
blur += blurTextureTexelToLinear(texture2D(blurTexture, vUv + scale * vec2(-1.0, -1.0) / cocTextureSize));
|
|
41
|
+
blur += blurTextureTexelToLinear(texture2D(blurTexture, vUv + scale * vec2(1.0, -1.0) / cocTextureSize));
|
|
42
|
+
blur /= 5.0;
|
|
43
|
+
|
|
44
|
+
vec2 uvNearest = (floor(vUv * cocTextureSize) + 0.5) / cocTextureSize;
|
|
45
|
+
float coc = abs(min(2. * cocTextureTexelToLinear(texture2D(cocTexture, uvNearest)).a - 1., computeCoc()));
|
|
46
|
+
//coc = clamp(coc * coc * 8.0, 0.0, 1.0);
|
|
47
|
+
float cocLower = 0.005;
|
|
48
|
+
float cocHigher = 0.3;
|
|
49
|
+
vec4 outColor = vec4(mix(colorTextureTexelToLinear(texture2D(colorTexture, vUv)).rgb, blur.rgb, smoothstep(cocLower, cocHigher, coc)), 1.0);
|
|
50
|
+
|
|
51
|
+
vec2 d = vUv - crossCenter;
|
|
52
|
+
|
|
53
|
+
if(length(d) > crossRadius + 0.05) {
|
|
54
|
+
float dist = circle(d, crossRadius);
|
|
55
|
+
gl_FragColor = outColor;
|
|
56
|
+
} else {
|
|
57
|
+
d.x *= cocTextureSize.x/cocTextureSize.y;
|
|
58
|
+
float dist = circle(d, crossRadius);
|
|
59
|
+
dist = smoothBoundary(dist, 2. * fwidth(dist));
|
|
60
|
+
vec4 color = outColor;
|
|
61
|
+
vec3 dofCircleColor = mix(crossColor, color.rgb, 1.-crossAlpha);
|
|
62
|
+
gl_FragColor = vec4(mix(color.rgb, dofCircleColor, dist), color.a);
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#include <colorspace_fragment>
|
|
67
|
+
|
|
68
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#include <common>
|
|
2
|
+
#include <packing>
|
|
3
|
+
varying vec2 vUv;
|
|
4
|
+
uniform vec2 nearFarBlurScale;
|
|
5
|
+
uniform vec2 cameraNearFar;
|
|
6
|
+
uniform vec2 focalDepthRange;
|
|
7
|
+
|
|
8
|
+
float computeCoc() {
|
|
9
|
+
float depth = getDepth(vUv);
|
|
10
|
+
if(depth == 1.0) return max(nearFarBlurScale.x, nearFarBlurScale.y);
|
|
11
|
+
depth = mix(cameraNearFar.x, cameraNearFar.y, depth);
|
|
12
|
+
float coc = (depth - focalDepthRange.x)/focalDepthRange.y;
|
|
13
|
+
coc = clamp(coc, -1., 1.);
|
|
14
|
+
return (coc > 0.0 ? coc * nearFarBlurScale.y : coc * nearFarBlurScale.x);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
void main() {
|
|
18
|
+
gl_FragColor = vec4(colorTextureTexelToLinear(texture2D(colorTexture, vUv)).rgb, 0.5 * computeCoc() + 0.5);
|
|
19
|
+
|
|
20
|
+
#include <colorspace_fragment>
|
|
21
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#include <common>
|
|
2
|
+
#include <gbuffer_unpack>
|
|
3
|
+
varying vec2 vUv;
|
|
4
|
+
uniform vec2 colorTextureSize;
|
|
5
|
+
uniform vec2 direction;
|
|
6
|
+
uniform vec2 nearFarBlurScale;
|
|
7
|
+
const float MAXIMUM_BLUR_SIZE = 4.0;
|
|
8
|
+
|
|
9
|
+
float expandNear(const in vec2 offset, const in bool isBackground) {
|
|
10
|
+
float coc = 0.0;
|
|
11
|
+
vec2 sampleOffsets = MAXIMUM_BLUR_SIZE * offset / 5.0;
|
|
12
|
+
float coc0 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv)).a - 1.;
|
|
13
|
+
float coc1 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv - 5.0 * sampleOffsets)).a - 1.;
|
|
14
|
+
float coc2 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv - 4.0 * sampleOffsets)).a - 1.;
|
|
15
|
+
float coc3 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv - 3.0 * sampleOffsets)).a - 1.;
|
|
16
|
+
float coc4 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv - 2.0 * sampleOffsets)).a - 1.;
|
|
17
|
+
float coc5 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv - 1.0 * sampleOffsets)).a - 1.;
|
|
18
|
+
float coc6 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv + 1.0 * sampleOffsets)).a - 1.;
|
|
19
|
+
float coc7 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv + 2.0 * sampleOffsets)).a - 1.;
|
|
20
|
+
float coc8 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv + 3.0 * sampleOffsets)).a - 1.;
|
|
21
|
+
float coc9 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv + 4.0 * sampleOffsets)).a - 1.;
|
|
22
|
+
float coc10 = 2. * colorTextureTexelToLinear(texture2D(colorTexture, vUv + 5.0 * sampleOffsets)).a - 1.;
|
|
23
|
+
|
|
24
|
+
if(isBackground){
|
|
25
|
+
coc = abs(coc0) * 0.095474 +
|
|
26
|
+
(abs(coc1) + abs(coc10)) * 0.084264 +
|
|
27
|
+
(abs(coc2) + abs(coc9)) * 0.088139 +
|
|
28
|
+
(abs(coc3) + abs(coc8)) * 0.091276 +
|
|
29
|
+
(abs(coc4) + abs(coc7)) * 0.093585 +
|
|
30
|
+
(abs(coc5) + abs(coc6)) * 0.094998;
|
|
31
|
+
} else {
|
|
32
|
+
coc = min(coc0, 0.0);
|
|
33
|
+
coc = min(coc1 * 0.3, coc);
|
|
34
|
+
coc = min(coc2 * 0.5, coc);
|
|
35
|
+
coc = min(coc3 * 0.75, coc);
|
|
36
|
+
coc = min(coc4 * 0.8, coc);
|
|
37
|
+
coc = min(coc5 * 0.95, coc);
|
|
38
|
+
coc = min(coc6 * 0.95, coc);
|
|
39
|
+
coc = min(coc7 * 0.8, coc);
|
|
40
|
+
coc = min(coc8 * 0.75, coc);
|
|
41
|
+
coc = min(coc9 * 0.5, coc);
|
|
42
|
+
coc = min(coc10 * 0.3, coc);
|
|
43
|
+
if(abs(coc0) > abs(coc))
|
|
44
|
+
coc = coc0;
|
|
45
|
+
}
|
|
46
|
+
return coc;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void main() {
|
|
50
|
+
vec2 offset = 2. * direction/colorTextureSize;
|
|
51
|
+
bool isBackground = getDepth(vUv) > 1.0 - 0.001;
|
|
52
|
+
float coc = expandNear(offset, isBackground);
|
|
53
|
+
gl_FragColor = vec4(colorTextureTexelToLinear(texture2D(colorTexture, vUv)).rgb, 0.5 * coc + 0.5);
|
|
54
|
+
|
|
55
|
+
#include <colorspace_fragment>
|
|
56
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#include <randomHelpers>
|
|
2
|
+
#include <common>
|
|
3
|
+
varying vec2 vUv;
|
|
4
|
+
//uniform sampler2D colorTexture;
|
|
5
|
+
uniform vec2 colorTextureSize;
|
|
6
|
+
uniform float blurRadius; // = 16
|
|
7
|
+
#ifndef D_frameCount
|
|
8
|
+
#define D_frameCount
|
|
9
|
+
uniform float frameCount;
|
|
10
|
+
#endif
|
|
11
|
+
//const float MAXIMUM_BLUR_SIZE = 16.0;
|
|
12
|
+
|
|
13
|
+
//float ditheringNoise(const in vec2 fragCoord, const in float frameMod) {
|
|
14
|
+
// // float fm = mod(frameMod, 2.0) == 0.0 ? 1.0 : -1.0;
|
|
15
|
+
// float fm = frameMod;
|
|
16
|
+
// float dither5 = fract((fragCoord.x + fragCoord.y * 2.0 - 1.5 + fm) / 5.0);
|
|
17
|
+
// float noise = fract(dot(vec2(171.0, 231.0) / 71.0, fragCoord.xy));
|
|
18
|
+
// return (dither5 * 5.0 + noise) * (1.2 / 6.0);
|
|
19
|
+
//}
|
|
20
|
+
|
|
21
|
+
vec4 CircularBlur() {
|
|
22
|
+
vec4 color = colorTextureTexelToLinear(texture2D(colorTexture, vUv));
|
|
23
|
+
|
|
24
|
+
#ifdef DOF_MODE
|
|
25
|
+
float blurDist = blurRadius * ( 2. * color.a - 1.);
|
|
26
|
+
#else
|
|
27
|
+
float blurDist = blurRadius * color.a;
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
// #ifdef DEPTH_BLUR
|
|
31
|
+
// float depth = texture2D(depthTexture, vUv).r;
|
|
32
|
+
// blurDist *= depth;
|
|
33
|
+
// #endif
|
|
34
|
+
|
|
35
|
+
float rnd = PI2 * random3( vec3(vUv, frameCount * 0.1) );
|
|
36
|
+
float costheta = cos(rnd);
|
|
37
|
+
float sintheta = sin(rnd);
|
|
38
|
+
vec4 rotationMatrix = vec4(costheta, -sintheta, sintheta, costheta);
|
|
39
|
+
|
|
40
|
+
vec3 colorSum = vec3(0.0);
|
|
41
|
+
float weightSum = 0.001;
|
|
42
|
+
vec2 ofs;
|
|
43
|
+
vec4 sampleColor;
|
|
44
|
+
// float cocWeight;
|
|
45
|
+
|
|
46
|
+
setPds(); // sets poisson_disk_samples
|
|
47
|
+
|
|
48
|
+
#pragma unroll_loop_start
|
|
49
|
+
for ( int i = 0; i < 16; i ++ ) {
|
|
50
|
+
ofs = poisson_disk_samples[UNROLLED_LOOP_INDEX];
|
|
51
|
+
ofs = vec2(dot(ofs, rotationMatrix.xy), dot(ofs, rotationMatrix.zw) );
|
|
52
|
+
sampleColor = colorTextureTexelToLinear(texture2D(colorTexture, vUv + blurDist * ofs / colorTextureSize.xy));
|
|
53
|
+
#ifdef DOF_MODE
|
|
54
|
+
sampleColor.a = abs(sampleColor.a * 2.0 - 1.0);
|
|
55
|
+
sampleColor.a *= sampleColor.a*sampleColor.a;
|
|
56
|
+
#endif
|
|
57
|
+
colorSum += sampleColor.rgb * sampleColor.a;
|
|
58
|
+
weightSum += sampleColor.a;
|
|
59
|
+
}
|
|
60
|
+
#pragma unroll_loop_end
|
|
61
|
+
|
|
62
|
+
// rnd = PI2 * random3( vec3(vUv, frameCount * 0.1 + 2.) );
|
|
63
|
+
// costheta = cos(rnd);
|
|
64
|
+
// sintheta = sin(rnd);
|
|
65
|
+
// rotationMatrix = vec4(costheta, -sintheta, sintheta, costheta);
|
|
66
|
+
|
|
67
|
+
// for (int i = 0; i < NUM_SAMPLES; i++) {
|
|
68
|
+
// vec2 ofs = poisson_disk_samples[i];
|
|
69
|
+
// ofs = vec2(dot(ofs, rotationMatrix.xy), dot(ofs, rotationMatrix.zw) );
|
|
70
|
+
// vec2 texcoord = vUv + blurDist * ofs / colorTextureSize.xy;
|
|
71
|
+
// vec4 sample = texture2D(colorTexture, texcoord);
|
|
72
|
+
// float cocWeight = abs(2. * sample.a - 1.);
|
|
73
|
+
// cocWeight *= cocWeight * cocWeight;
|
|
74
|
+
// colorSum += sample.rgb * cocWeight;
|
|
75
|
+
// weightSum += cocWeight;
|
|
76
|
+
// }
|
|
77
|
+
|
|
78
|
+
colorSum /= weightSum;
|
|
79
|
+
|
|
80
|
+
// return vec4(saturate(colorSum), saturate((weightSum-0.001)/16.0));
|
|
81
|
+
return vec4(min(vec3(72.), max(vec3(0.), colorSum)), 1.0);
|
|
82
|
+
// return vec4(saturate(colorSum), 1.0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
void main() {
|
|
86
|
+
gl_FragColor = CircularBlur();
|
|
87
|
+
|
|
88
|
+
#include <colorspace_fragment>
|
|
89
|
+
}
|
|
90
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
|
|
2
|
+
//float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;
|
|
3
|
+
#if defined(SSRTAO_ENABLED) && SSRTAO_ENABLED > 0
|
|
4
|
+
|
|
5
|
+
vec3 screenPos_gi = viewToScreen(vViewPosition.xyz);
|
|
6
|
+
|
|
7
|
+
#if SSRTAO_ENABLED == 2 // split mode
|
|
8
|
+
if(screenPos_gi.x > ssrtaoSplitX){
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
vec4 ssgi = tSSGIMapTexelToLinear( texture2D( tSSGIMap, screenPos_gi.xy) );
|
|
12
|
+
|
|
13
|
+
//float ssaoPower = 1.*2.;
|
|
14
|
+
//float ssgiIntensity = 1.;
|
|
15
|
+
float ambientOcclusion = 1.-ssgi.a;
|
|
16
|
+
|
|
17
|
+
ambientOcclusion = max(0. ,ambientOcclusion);
|
|
18
|
+
ambientOcclusion = pow(ambientOcclusion, ssaoPower);
|
|
19
|
+
ambientOcclusion = min(1. ,ambientOcclusion);
|
|
20
|
+
|
|
21
|
+
reflectedLight.indirectDiffuse *= ambientOcclusion;
|
|
22
|
+
|
|
23
|
+
#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0
|
|
24
|
+
|
|
25
|
+
vec3 ssgiColor = ssgi.rgb * ssgiIntensity;
|
|
26
|
+
reflectedLight.indirectDiffuse += ssgiColor * (material.diffuseColor.rgb);
|
|
27
|
+
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
#if defined( USE_ENVMAP )
|
|
31
|
+
|
|
32
|
+
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
33
|
+
//float specularOcclusion = 1.;//computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
|
|
34
|
+
float specularOcclusion = saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * material.roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
|
|
35
|
+
reflectedLight.indirectSpecular *= specularOcclusion;
|
|
36
|
+
|
|
37
|
+
#if defined(SSGI_ENABLED) && SSGI_ENABLED > 0
|
|
38
|
+
#if !defined(SSR_ENABLED) || SSR_ENABLED < 1
|
|
39
|
+
|
|
40
|
+
reflectedLight.indirectSpecular += ssgiColor * material.specularColor;
|
|
41
|
+
|
|
42
|
+
#endif
|
|
43
|
+
#endif
|
|
44
|
+
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
//reflectedLight.indirectSpecular = vec3(ssgi.rgb);
|
|
48
|
+
|
|
49
|
+
#if SSRTAO_ENABLED == 2 // split mode
|
|
50
|
+
}
|
|
51
|
+
#endif
|
|
52
|
+
|
|
53
|
+
#endif
|