@ignifx/core 0.21.0 → 0.22.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/README.md +22 -0
- package/dist/{agx-tone-mapping-Cgt844j6.js → agx-tone-mapping-CCdGk_ly.js} +2 -2
- package/dist/agx-tone-mapping-CCdGk_ly.js.map +1 -0
- package/dist/auto-exposure-uzPn0beO.js.map +1 -1
- package/dist/{bloom-hdr-CLtQj-oY.js → bloom-hdr-xPwkIdHG.js} +5 -6
- package/dist/bloom-hdr-xPwkIdHG.js.map +1 -0
- package/dist/contact-shadows-T523EXaP.js.map +1 -1
- package/dist/effect-task-CMbuO6Kb.js.map +1 -1
- package/dist/{environment-Bf4aphSb.js → environment-7fJbN402.js} +2 -2
- package/dist/{environment-Bf4aphSb.js.map → environment-7fJbN402.js.map} +1 -1
- package/dist/{gtao-Bpu5-0Ne.js → gtao-CVAYWBEJ.js} +10 -11
- package/dist/gtao-CVAYWBEJ.js.map +1 -0
- package/dist/{hdr-output-DBQwMphy.js → hdr-output-_2TU-jWy.js} +8 -8
- package/dist/hdr-output-_2TU-jWy.js.map +1 -0
- package/dist/index.d.ts +61 -48
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +148 -129
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-B-fXKSrY.js → instanced-mesh-instance-BLdAJTj8.js} +3 -3
- package/dist/instanced-mesh-instance-BLdAJTj8.js.map +1 -0
- package/dist/{light-probe-asset-BqfSrJe9.js → light-probe-asset-DGNIwKNb.js} +2 -2
- package/dist/light-probe-asset-DGNIwKNb.js.map +1 -0
- package/dist/{light-probes-DDojYajw.js → light-probes-C8jharz9.js} +6 -6
- package/dist/light-probes-C8jharz9.js.map +1 -0
- package/dist/lightmaps-BUUIIkt9.js.map +1 -1
- package/dist/material-myMbl9mW.js.map +1 -1
- package/dist/{material-plugin-DapJNj04.js → material-plugin-BBxIy6eo.js} +4 -4
- package/dist/material-plugin-BBxIy6eo.js.map +1 -0
- package/dist/{overlay-CjVgsfrm.js → overlay-DokHzP6_.js} +2 -3
- package/dist/overlay-DokHzP6_.js.map +1 -0
- package/dist/{post-effect-Cu3Enpz7.js → post-effect-DEZD-r0I.js} +3 -3
- package/dist/post-effect-DEZD-r0I.js.map +1 -0
- package/dist/{post-effect-compiler-cCq9lcHt.js → post-effect-compiler-unDD3hod.js} +4 -4
- package/dist/post-effect-compiler-unDD3hod.js.map +1 -0
- package/dist/{prefab-overrides-C2GsgOQc.js → prefab-overrides-Bb7jVm7A.js} +3 -3
- package/dist/prefab-overrides-Bb7jVm7A.js.map +1 -0
- package/dist/{prefab-overrides-htDc_5Po.d.ts → prefab-overrides-CkwXhp5A.d.ts} +84 -64
- package/dist/{prefab-overrides-htDc_5Po.d.ts.map → prefab-overrides-CkwXhp5A.d.ts.map} +1 -1
- package/dist/prefab.d.ts +1 -1
- package/dist/prefab.js +1 -1
- package/dist/{reflection-probe-QkD1Fo_d.js → reflection-probe-C2jcreI1.js} +5 -5
- package/dist/reflection-probe-C2jcreI1.js.map +1 -0
- package/dist/{reflection-probes-CAzSuqf8.js → reflection-probes-BMVQfbhm.js} +10 -10
- package/dist/reflection-probes-BMVQfbhm.js.map +1 -0
- package/dist/{render-path-D11i_7X8.js → render-path-CWXHrRa2.js} +2 -2
- package/dist/render-path-CWXHrRa2.js.map +1 -0
- package/dist/scene-color-passes-CM_T2KF-.js +177 -0
- package/dist/scene-color-passes-CM_T2KF-.js.map +1 -0
- package/dist/scene-inputs-CbTkrkOw.js +489 -0
- package/dist/scene-inputs-CbTkrkOw.js.map +1 -0
- package/dist/{shader-declaration-5q__jycG.js → shader-declaration-BGprFBLq.js} +4 -4
- package/dist/shader-declaration-BGprFBLq.js.map +1 -0
- package/dist/{shader-material-TM4f8eKA.js → shader-material-C9sYMGWw.js} +8 -9
- package/dist/shader-material-C9sYMGWw.js.map +1 -0
- package/dist/{shader-material-CJIDFvSb.js → shader-material-vmkJ25II.js} +3 -3
- package/dist/shader-material-vmkJ25II.js.map +1 -0
- package/dist/{shader-pragma-ljmAbVc2.js → shader-pragma-D0MjCOIg.js} +3 -3
- package/dist/shader-pragma-D0MjCOIg.js.map +1 -0
- package/dist/ssgi-Dk20U3oR.js +492 -0
- package/dist/ssgi-Dk20U3oR.js.map +1 -0
- package/dist/{surface-shader-rpPpeosD.js → surface-shader-BfADq9Wx.js} +6 -6
- package/dist/surface-shader-BfADq9Wx.js.map +1 -0
- package/dist/{taa-BwBZLy11.js → taa-nxVA78Ur.js} +5 -6
- package/dist/taa-nxVA78Ur.js.map +1 -0
- package/dist/vec3-2C3LBZnt.js.map +1 -1
- package/package.json +1 -1
- package/dist/agx-tone-mapping-Cgt844j6.js.map +0 -1
- package/dist/bloom-hdr-CLtQj-oY.js.map +0 -1
- package/dist/gtao-Bpu5-0Ne.js.map +0 -1
- package/dist/hdr-output-DBQwMphy.js.map +0 -1
- package/dist/instanced-mesh-instance-B-fXKSrY.js.map +0 -1
- package/dist/light-probe-asset-BqfSrJe9.js.map +0 -1
- package/dist/light-probes-DDojYajw.js.map +0 -1
- package/dist/material-plugin-DapJNj04.js.map +0 -1
- package/dist/overlay-CjVgsfrm.js.map +0 -1
- package/dist/post-effect-Cu3Enpz7.js.map +0 -1
- package/dist/post-effect-compiler-cCq9lcHt.js.map +0 -1
- package/dist/prefab-overrides-C2GsgOQc.js.map +0 -1
- package/dist/reflection-probe-QkD1Fo_d.js.map +0 -1
- package/dist/reflection-probes-CAzSuqf8.js.map +0 -1
- package/dist/render-path-D11i_7X8.js.map +0 -1
- package/dist/scene-color-passes-B93qTOka.js +0 -88
- package/dist/scene-color-passes-B93qTOka.js.map +0 -1
- package/dist/scene-inputs-BxGOsnIZ.js +0 -318
- package/dist/scene-inputs-BxGOsnIZ.js.map +0 -1
- package/dist/shader-declaration-5q__jycG.js.map +0 -1
- package/dist/shader-material-CJIDFvSb.js.map +0 -1
- package/dist/shader-material-TM4f8eKA.js.map +0 -1
- package/dist/shader-pragma-ljmAbVc2.js.map +0 -1
- package/dist/ssgi-DSnhqotl.js +0 -113
- package/dist/ssgi-DSnhqotl.js.map +0 -1
- package/dist/surface-shader-rpPpeosD.js.map +0 -1
- package/dist/taa-BwBZLy11.js.map +0 -1
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { n as Mat4 } from "./mat4-D6exvAuO.js";
|
|
2
|
+
import { o as rebuildMaterialPipelines } from "./material-myMbl9mW.js";
|
|
3
|
+
import { createCopyToTextureTask, createEffectRenderTask, createEffectWrapper, createScreenSpaceGlobalIlluminationPostProcessTask, createSurfaceRenderTargetTexture, disposeEffectWrapper, disposeRenderTargetTexture, getEffectiveAspectRatio, getPbrUnlit, getViewProjectionMatrix, isPbrMaterial, onRenderTargetTextureResize, setEffectTexture, setEffectUniforms } from "@babylonjs/lite";
|
|
4
|
+
//#region src/lite/gpu/ssgi.ts
|
|
5
|
+
/**
|
|
6
|
+
* The frame-graph task names, in the order they run; `denoise` is followed by the pass index.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
const SSGI_TASK_NAMES = {
|
|
11
|
+
trace: "ignifx:ssgi",
|
|
12
|
+
copy: "ignifx:ssgi-copy",
|
|
13
|
+
uniforms: "ignifx:ssgi-uniforms",
|
|
14
|
+
denoise: "ignifx:ssgi-denoise-",
|
|
15
|
+
composite: "ignifx:ssgi-composite"
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The most denoise passes a pass builds; the last one's taps are 8 texels apart.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
const SSGI_MAX_DENOISE_PASSES = 4;
|
|
23
|
+
/**
|
|
24
|
+
* The environment plugin's name.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
const SSGI_ENVIRONMENT_PLUGIN_NAME = "ignifx-ssgi-environment";
|
|
29
|
+
/** The format of the bounce targets: the one Lite's `illuminationTexture` has. */
|
|
30
|
+
const BOUNCE_FORMAT = "rgba16float";
|
|
31
|
+
/** Uniform floats per effect: an inverse view-projection, the eye, and one `vec4` of parameters. */
|
|
32
|
+
const UNIFORM_FLOATS = 24;
|
|
33
|
+
/**
|
|
34
|
+
* The distance off the centre pixel's surface plane at which a tap's weight has fallen to `1 / e`,
|
|
35
|
+
* as a fraction of the pixel's distance from the eye: 1.2 cm a metre away.
|
|
36
|
+
*/
|
|
37
|
+
const PLANE_TOLERANCE = .012;
|
|
38
|
+
/** The power the agreement of two normals is raised to; higher stops the blur at gentler creases. */
|
|
39
|
+
const NORMAL_POWER = 4;
|
|
40
|
+
/** The blend that adds a pass's colour to the target and leaves the target's alpha alone. */
|
|
41
|
+
const ADDITIVE_BLEND = {
|
|
42
|
+
color: {
|
|
43
|
+
operation: "add",
|
|
44
|
+
srcFactor: "one",
|
|
45
|
+
dstFactor: "one"
|
|
46
|
+
},
|
|
47
|
+
alpha: {
|
|
48
|
+
operation: "add",
|
|
49
|
+
srcFactor: "zero",
|
|
50
|
+
dstFactor: "one"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* What both shaders declare: the uniform block and the reads of the scene inputs.
|
|
55
|
+
*
|
|
56
|
+
* @remarks
|
|
57
|
+
* `params` is `(stride or intensity, plane tolerance, normal power, display flag)`. `ssgiSceneTexel` maps
|
|
58
|
+
* a bounce texel to the scene texel under its centre, the identity at full resolution.
|
|
59
|
+
*
|
|
60
|
+
* @returns The WGSL.
|
|
61
|
+
*/
|
|
62
|
+
function sharedWgsl() {
|
|
63
|
+
return `struct SsgiFilter{invViewProj:mat4x4<f32>,eye:vec4<f32>,params:vec4<f32>};
|
|
64
|
+
@group(0)@binding(0)var<uniform>ssgi:SsgiFilter;
|
|
65
|
+
@group(0)@binding(1)var bounce:texture_2d<f32>;
|
|
66
|
+
@group(0)@binding(2)var sceneDepth:texture_depth_2d;
|
|
67
|
+
@group(0)@binding(3)var sceneNormals:texture_2d<f32>;
|
|
68
|
+
fn ssgiSceneTexel(texel:vec2<i32>,bounceSize:vec2<f32>,sceneSize:vec2<f32>)->vec2<i32>{
|
|
69
|
+
let uv=(vec2<f32>(texel)+vec2<f32>(0.5))/bounceSize;
|
|
70
|
+
return clamp(vec2<i32>(uv*sceneSize),vec2<i32>(0),vec2<i32>(sceneSize)-vec2<i32>(1));}
|
|
71
|
+
fn ssgiWorld(texel:vec2<i32>,depth:f32,sceneSize:vec2<f32>)->vec3<f32>{
|
|
72
|
+
let uv=(vec2<f32>(texel)+vec2<f32>(0.5))/sceneSize;
|
|
73
|
+
let clip=ssgi.invViewProj*vec4<f32>(uv.x*2.0-1.0,1.0-uv.y*2.0,depth,1.0);
|
|
74
|
+
return clip.xyz/clip.w;}
|
|
75
|
+
fn ssgiNormal(texel:vec2<i32>)->vec3<f32>{
|
|
76
|
+
let n=textureLoad(sceneNormals,texel,0).xyz*2.0-vec3<f32>(1.0);
|
|
77
|
+
return n*inverseSqrt(max(dot(n,n),1e-8));}
|
|
78
|
+
fn ssgiTolerance(position:vec3<f32>)->f32{return max(distance(position,ssgi.eye.xyz),1e-3)*ssgi.params.y;}
|
|
79
|
+
fn ssgiSurfaceWeight(position:vec3<f32>,normal:vec3<f32>,tolerance:f32,otherPosition:vec3<f32>,otherNormal:vec3<f32>)->f32{
|
|
80
|
+
let plane=abs(dot(normal,otherPosition-position));
|
|
81
|
+
return exp(-plane/tolerance)*pow(max(dot(normal,otherNormal),0.0),ssgi.params.z);}
|
|
82
|
+
fn ssgiBounce(texel:vec2<i32>)->vec3<f32>{
|
|
83
|
+
return min(max(textureLoad(bounce,texel,0).rgb,vec3<f32>(0.0)),vec3<f32>(65000.0));}`;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The denoise pass's fragment shader: a 3×3 filter with taps `params.x` texels apart, each weighted
|
|
87
|
+
* by the kernel `(1, 0.5)` per axis and by how well it shares the centre pixel's surface.
|
|
88
|
+
*
|
|
89
|
+
* @returns The WGSL, with Lite's `effectFragment` entry point.
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
92
|
+
*/
|
|
93
|
+
function ssgiDenoiseFragmentWgsl() {
|
|
94
|
+
return `${sharedWgsl()}
|
|
95
|
+
@fragment fn effectFragment(fragment:EffectVertexOutput)->@location(0)vec4<f32>{
|
|
96
|
+
let bounceSize=vec2<f32>(textureDimensions(bounce));
|
|
97
|
+
let sceneSize=vec2<f32>(textureDimensions(sceneDepth));
|
|
98
|
+
let texel=vec2<i32>(fragment.position.xy);
|
|
99
|
+
let sceneTexel=ssgiSceneTexel(texel,bounceSize,sceneSize);
|
|
100
|
+
let depth=textureLoad(sceneDepth,sceneTexel,0);
|
|
101
|
+
if(depth<=0.0){return vec4<f32>(0.0,0.0,0.0,1.0);}
|
|
102
|
+
let position=ssgiWorld(sceneTexel,depth,sceneSize);
|
|
103
|
+
let normal=ssgiNormal(sceneTexel);
|
|
104
|
+
let tolerance=ssgiTolerance(position);
|
|
105
|
+
let stride=max(i32(ssgi.params.x),1);
|
|
106
|
+
let last=vec2<i32>(bounceSize)-vec2<i32>(1);
|
|
107
|
+
var sum=ssgiBounce(texel);var total=1.0;
|
|
108
|
+
for(var y=-1;y<=1;y++){for(var x=-1;x<=1;x++){
|
|
109
|
+
if(x==0&&y==0){continue;}
|
|
110
|
+
let other=texel+vec2<i32>(x,y)*stride;
|
|
111
|
+
if(any(other<vec2<i32>(0))||any(other>last)){continue;}
|
|
112
|
+
let otherScene=ssgiSceneTexel(other,bounceSize,sceneSize);
|
|
113
|
+
let otherDepth=textureLoad(sceneDepth,otherScene,0);
|
|
114
|
+
if(otherDepth<=0.0){continue;}
|
|
115
|
+
let kernel=select(1.0,0.5,x!=0)*select(1.0,0.5,y!=0);
|
|
116
|
+
let weight=kernel*ssgiSurfaceWeight(position,normal,tolerance,ssgiWorld(otherScene,otherDepth,sceneSize),ssgiNormal(otherScene));
|
|
117
|
+
sum+=ssgiBounce(other)*weight;total+=weight;}}
|
|
118
|
+
return vec4<f32>(sum/total,1.0);}`;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The composite's fragment shader: the bounce at the pixel, taken from the four bounce texels
|
|
122
|
+
* around it by bilinear weight and shared surface, times the surface's albedo and `params.x`.
|
|
123
|
+
* Meant for {@link ADDITIVE_BLEND}.
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
* With `params.w` set the colour is display-encoded (no `rendering.hdr`), and so is the bounce
|
|
127
|
+
* traced from it. Albedo is linear, and a display value times a linear one, added to a display
|
|
128
|
+
* value, comes out several times too bright, so the bounce is first taken to roughly linear light
|
|
129
|
+
* with a 2.2 power. The sum is still made in display values, which only `rendering.hdr` avoids.
|
|
130
|
+
*
|
|
131
|
+
* @returns The WGSL, with Lite's `effectFragment` entry point.
|
|
132
|
+
*
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
function ssgiCompositeFragmentWgsl() {
|
|
136
|
+
return `${sharedWgsl()}
|
|
137
|
+
@group(0)@binding(4)var sceneAlbedo:texture_2d<f32>;
|
|
138
|
+
@fragment fn effectFragment(fragment:EffectVertexOutput)->@location(0)vec4<f32>{
|
|
139
|
+
let bounceSize=vec2<f32>(textureDimensions(bounce));
|
|
140
|
+
let sceneSize=vec2<f32>(textureDimensions(sceneDepth));
|
|
141
|
+
let texel=vec2<i32>(fragment.position.xy);
|
|
142
|
+
let depth=textureLoad(sceneDepth,texel,0);
|
|
143
|
+
if(depth<=0.0){return vec4<f32>(0.0);}
|
|
144
|
+
let albedo=textureLoad(sceneAlbedo,texel,0).rgb;
|
|
145
|
+
let position=ssgiWorld(texel,depth,sceneSize);
|
|
146
|
+
let normal=ssgiNormal(texel);
|
|
147
|
+
let tolerance=ssgiTolerance(position);
|
|
148
|
+
let at=(vec2<f32>(texel)+vec2<f32>(0.5))/sceneSize*bounceSize-vec2<f32>(0.5);
|
|
149
|
+
let base=floor(at);let f=at-base;
|
|
150
|
+
let last=vec2<i32>(bounceSize)-vec2<i32>(1);
|
|
151
|
+
var sum=vec3<f32>(0.0);var total=0.0;
|
|
152
|
+
for(var j=0;j<2;j++){for(var i=0;i<2;i++){
|
|
153
|
+
let other=clamp(vec2<i32>(base)+vec2<i32>(i,j),vec2<i32>(0),last);
|
|
154
|
+
let otherScene=ssgiSceneTexel(other,bounceSize,sceneSize);
|
|
155
|
+
let otherDepth=textureLoad(sceneDepth,otherScene,0);
|
|
156
|
+
if(otherDepth<=0.0){continue;}
|
|
157
|
+
let bilinear=select(1.0-f.x,f.x,i==1)*select(1.0-f.y,f.y,j==1);
|
|
158
|
+
// The small constant keeps a pixel none of whose four texels share its surface from going black.
|
|
159
|
+
let weight=bilinear*(ssgiSurfaceWeight(position,normal,tolerance,ssgiWorld(otherScene,otherDepth,sceneSize),ssgiNormal(otherScene))+1e-4);
|
|
160
|
+
sum+=ssgiBounce(other)*weight;total+=weight;}}
|
|
161
|
+
if(total<=0.0){return vec4<f32>(0.0);}
|
|
162
|
+
var light=sum/total;
|
|
163
|
+
if(ssgi.params.w>0.5){light=pow(light,vec3<f32>(2.2));}
|
|
164
|
+
return vec4<f32>(albedo*light*ssgi.params.x,0.0);}`;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Clamps a `denoisePasses` value to what a pass can build.
|
|
168
|
+
*
|
|
169
|
+
* @param passes - The record's value.
|
|
170
|
+
* @returns A whole number from 0 to {@link SSGI_MAX_DENOISE_PASSES}; 0 for a value that is not a number.
|
|
171
|
+
*
|
|
172
|
+
* @internal
|
|
173
|
+
*/
|
|
174
|
+
function clampSsgiDenoisePasses(passes) {
|
|
175
|
+
if (Number.isNaN(passes)) return 0;
|
|
176
|
+
return Math.min(4, Math.max(0, Math.round(passes)));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Writes one effect's uniform block.
|
|
180
|
+
*
|
|
181
|
+
* @param values - What to write.
|
|
182
|
+
* @param out - {@link UNIFORM_FLOATS} floats, overwritten.
|
|
183
|
+
* @returns `out`.
|
|
184
|
+
*
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
function writeSsgiFilterUniforms(values, out) {
|
|
188
|
+
for (let index = 0; index < 16; index += 1) out[index] = values.inverseViewProjection[index] ?? 0;
|
|
189
|
+
out[16] = values.cameraWorld[12] ?? 0;
|
|
190
|
+
out[17] = values.cameraWorld[13] ?? 0;
|
|
191
|
+
out[18] = values.cameraWorld[14] ?? 0;
|
|
192
|
+
out[19] = 1;
|
|
193
|
+
out[20] = values.first;
|
|
194
|
+
out[21] = PLANE_TOLERANCE;
|
|
195
|
+
out[22] = NORMAL_POWER;
|
|
196
|
+
out[23] = values.isDisplayEncoded ? 1 : 0;
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Creates an SSGI pass.
|
|
201
|
+
*
|
|
202
|
+
* @param engine - The engine.
|
|
203
|
+
* @param scene - The scene, whose materials get the plugin.
|
|
204
|
+
* @param inputs - A scene-inputs lease acquired with `albedo: true`; the caller releases it.
|
|
205
|
+
* @param camera - The camera the inputs were drawn from.
|
|
206
|
+
* @param options - The initial tuning and the creation-time choices.
|
|
207
|
+
* @param options.tuning - The initial tuning.
|
|
208
|
+
* @param options.halfResolution - Whether the rays are traced, and the bounce filtered, at half resolution.
|
|
209
|
+
* @param options.denoisePasses - How many denoise passes run, 0 to {@link SSGI_MAX_DENOISE_PASSES}.
|
|
210
|
+
* @param options.isLinear - Whether the scene colour is linear (`rendering.hdr`) and not display-encoded.
|
|
211
|
+
* @param options.usePlugin - Whether Lite's plugin bridges are installed, so the plugin can be used.
|
|
212
|
+
* @returns The pass.
|
|
213
|
+
*
|
|
214
|
+
* @internal
|
|
215
|
+
*/
|
|
216
|
+
function createSsgiPass(engine, scene, inputs, camera, options) {
|
|
217
|
+
let built = null;
|
|
218
|
+
let tuning = options.tuning;
|
|
219
|
+
let plugin = null;
|
|
220
|
+
let pluginValue = NaN;
|
|
221
|
+
return {
|
|
222
|
+
inPlace: true,
|
|
223
|
+
create(colour) {
|
|
224
|
+
const trace = createScreenSpaceGlobalIlluminationPostProcessTask({
|
|
225
|
+
name: SSGI_TASK_NAMES.trace,
|
|
226
|
+
sourceTexture: colour,
|
|
227
|
+
depthTexture: inputs.depthTarget,
|
|
228
|
+
camera,
|
|
229
|
+
resolutionScale: options.halfResolution ? .5 : 1,
|
|
230
|
+
rayLength: tuning.radius,
|
|
231
|
+
stepCount: tuning.samples,
|
|
232
|
+
rayCount: tuning.rays,
|
|
233
|
+
composition: "none"
|
|
234
|
+
}, engine, scene);
|
|
235
|
+
const passCount = clampSsgiDenoisePasses(options.denoisePasses);
|
|
236
|
+
const createTarget = (label) => createSurfaceRenderTargetTexture(engine, {
|
|
237
|
+
lbl: label,
|
|
238
|
+
format: BOUNCE_FORMAT,
|
|
239
|
+
samples: 1,
|
|
240
|
+
size: options.halfResolution ? {
|
|
241
|
+
surface: engine,
|
|
242
|
+
scale: .5
|
|
243
|
+
} : engine
|
|
244
|
+
});
|
|
245
|
+
const targets = [createTarget("ignifx:ssgi-bounce")];
|
|
246
|
+
if (passCount > 0) targets.push(createTarget("ignifx:ssgi-bounce-2"));
|
|
247
|
+
const targetAt = (index) => {
|
|
248
|
+
const target = targets[index % targets.length];
|
|
249
|
+
if (target === void 0) throw new RangeError(`SSGI has no bounce target ${String(index)}.`);
|
|
250
|
+
return target;
|
|
251
|
+
};
|
|
252
|
+
const tasks = [trace, createCopyToTextureTask({
|
|
253
|
+
name: SSGI_TASK_NAMES.copy,
|
|
254
|
+
sourceTexture: trace.illuminationTexture,
|
|
255
|
+
targetTexture: targetAt(0).rt
|
|
256
|
+
}, engine, scene)];
|
|
257
|
+
const denoiseWgsl = ssgiDenoiseFragmentWgsl();
|
|
258
|
+
const effects = [];
|
|
259
|
+
const sources = [];
|
|
260
|
+
const denoiseTasks = [];
|
|
261
|
+
for (let pass = 0; pass < passCount; pass += 1) {
|
|
262
|
+
const name = `${SSGI_TASK_NAMES.denoise}${String(pass)}`;
|
|
263
|
+
const effect = createEffectWrapper(engine, {
|
|
264
|
+
name,
|
|
265
|
+
fragmentWGSL: denoiseWgsl,
|
|
266
|
+
bindings: [
|
|
267
|
+
{
|
|
268
|
+
name: "ssgi",
|
|
269
|
+
binding: 0,
|
|
270
|
+
kind: "uniform",
|
|
271
|
+
uniformByteLength: 96
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: "bounce",
|
|
275
|
+
binding: 1,
|
|
276
|
+
kind: "texture"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
name: "sceneDepth",
|
|
280
|
+
binding: 2,
|
|
281
|
+
kind: "texture",
|
|
282
|
+
textureSampleType: "depth"
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "sceneNormals",
|
|
286
|
+
binding: 3,
|
|
287
|
+
kind: "texture"
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
});
|
|
291
|
+
effects.push(effect);
|
|
292
|
+
sources.push(() => targetAt(pass).texture);
|
|
293
|
+
denoiseTasks.push(createEffectTask(engine, scene, name, effect, targetAt(pass + 1).rt));
|
|
294
|
+
}
|
|
295
|
+
const composite = createEffectWrapper(engine, {
|
|
296
|
+
name: SSGI_TASK_NAMES.composite,
|
|
297
|
+
fragmentWGSL: ssgiCompositeFragmentWgsl(),
|
|
298
|
+
bindings: [
|
|
299
|
+
{
|
|
300
|
+
name: "ssgi",
|
|
301
|
+
binding: 0,
|
|
302
|
+
kind: "uniform",
|
|
303
|
+
uniformByteLength: 96
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
name: "bounce",
|
|
307
|
+
binding: 1,
|
|
308
|
+
kind: "texture"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: "sceneDepth",
|
|
312
|
+
binding: 2,
|
|
313
|
+
kind: "texture",
|
|
314
|
+
textureSampleType: "depth"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: "sceneNormals",
|
|
318
|
+
binding: 3,
|
|
319
|
+
kind: "texture"
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: "sceneAlbedo",
|
|
323
|
+
binding: 4,
|
|
324
|
+
kind: "texture"
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
blend: ADDITIVE_BLEND
|
|
328
|
+
});
|
|
329
|
+
effects.push(composite);
|
|
330
|
+
sources.push(() => targetAt(passCount).texture);
|
|
331
|
+
const bind = () => {
|
|
332
|
+
const albedo = inputs.albedo;
|
|
333
|
+
for (let index = 0; index < effects.length; index += 1) {
|
|
334
|
+
const effect = effects[index];
|
|
335
|
+
const source = sources[index];
|
|
336
|
+
if (effect === void 0 || source === void 0) continue;
|
|
337
|
+
setEffectTexture(effect, 1, source());
|
|
338
|
+
setEffectTexture(effect, 2, inputs.depth);
|
|
339
|
+
setEffectTexture(effect, 3, inputs.normals);
|
|
340
|
+
}
|
|
341
|
+
if (albedo !== null) setEffectTexture(composite, 4, albedo);
|
|
342
|
+
};
|
|
343
|
+
bind();
|
|
344
|
+
const stops = [inputs.onChange(bind), ...targets.map((target) => onRenderTargetTextureResize(target, bind))];
|
|
345
|
+
const viewProjection = new Mat4();
|
|
346
|
+
const inverse = new Mat4();
|
|
347
|
+
const uniforms = new Float32Array(UNIFORM_FLOATS);
|
|
348
|
+
const values = {
|
|
349
|
+
inverseViewProjection: inverse.elements,
|
|
350
|
+
cameraWorld: camera.worldMatrix,
|
|
351
|
+
first: 0,
|
|
352
|
+
isDisplayEncoded: !options.isLinear
|
|
353
|
+
};
|
|
354
|
+
const uniformsTask = {
|
|
355
|
+
name: SSGI_TASK_NAMES.uniforms,
|
|
356
|
+
engine,
|
|
357
|
+
scene,
|
|
358
|
+
_passes: [],
|
|
359
|
+
record() {},
|
|
360
|
+
execute() {
|
|
361
|
+
const width = inputs.depth.width;
|
|
362
|
+
const height = inputs.depth.height;
|
|
363
|
+
if (width <= 0 || height <= 0) return 0;
|
|
364
|
+
const current = getViewProjectionMatrix(camera, getEffectiveAspectRatio(camera, width, height));
|
|
365
|
+
const elements = viewProjection.elements;
|
|
366
|
+
for (let index = 0; index < 16; index += 1) elements[index] = current[index] ?? 0;
|
|
367
|
+
if (!Mat4.invertToRef(elements, inverse)) inverse.identity();
|
|
368
|
+
for (let index = 0; index < effects.length; index += 1) {
|
|
369
|
+
const effect = effects[index];
|
|
370
|
+
if (effect === void 0) continue;
|
|
371
|
+
values.first = effect === composite ? Math.min(4, Math.max(0, tuning.intensity)) : 2 ** index;
|
|
372
|
+
setEffectUniforms(effect, writeSsgiFilterUniforms(values, uniforms));
|
|
373
|
+
}
|
|
374
|
+
return 0;
|
|
375
|
+
},
|
|
376
|
+
dispose() {}
|
|
377
|
+
};
|
|
378
|
+
tasks.push(uniformsTask, ...denoiseTasks, createEffectTask(engine, scene, SSGI_TASK_NAMES.composite, composite, colour));
|
|
379
|
+
built = {
|
|
380
|
+
trace,
|
|
381
|
+
effects,
|
|
382
|
+
targets,
|
|
383
|
+
stops
|
|
384
|
+
};
|
|
385
|
+
return tasks;
|
|
386
|
+
},
|
|
387
|
+
update(next, isSceneRegistered) {
|
|
388
|
+
tuning = next;
|
|
389
|
+
if (built === null) return;
|
|
390
|
+
built.trace.rayLength = next.radius;
|
|
391
|
+
built.trace.stepCount = next.samples;
|
|
392
|
+
built.trace.rayCount = next.rays;
|
|
393
|
+
if (!options.usePlugin) return;
|
|
394
|
+
const value = Math.min(1, Math.max(0, next.environmentDiffuse));
|
|
395
|
+
if (value >= 1) {
|
|
396
|
+
if (plugin !== null) {
|
|
397
|
+
attachPlugin(scene, null, isSceneRegistered);
|
|
398
|
+
plugin = null;
|
|
399
|
+
pluginValue = NaN;
|
|
400
|
+
}
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
if (plugin === null || value !== pluginValue) {
|
|
404
|
+
pluginValue = value;
|
|
405
|
+
plugin = createSsgiEnvironmentPlugin(value);
|
|
406
|
+
}
|
|
407
|
+
attachPlugin(scene, plugin, isSceneRegistered);
|
|
408
|
+
},
|
|
409
|
+
dispose(isSceneRegistered) {
|
|
410
|
+
if (plugin !== null) {
|
|
411
|
+
attachPlugin(scene, null, isSceneRegistered);
|
|
412
|
+
plugin = null;
|
|
413
|
+
}
|
|
414
|
+
if (built === null) return;
|
|
415
|
+
for (const stop of built.stops) stop();
|
|
416
|
+
for (const effect of built.effects) disposeEffectWrapper(effect);
|
|
417
|
+
for (const target of built.targets) disposeRenderTargetTexture(target);
|
|
418
|
+
built = null;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Creates a task that draws an effect over a target without clearing it, and that leaves the target
|
|
424
|
+
* alone when disposed.
|
|
425
|
+
*
|
|
426
|
+
* @remarks
|
|
427
|
+
* Lite's effect task frees its target on `dispose` (`lib/effect/effect-renderer.js`,
|
|
428
|
+
* `disposeRenderTarget(task._rt)`). The composite's target is the scene colour, which the rest of
|
|
429
|
+
* the frame graph keeps drawing into, and the bounce targets are freed by the pass.
|
|
430
|
+
*
|
|
431
|
+
* @param engine - The engine.
|
|
432
|
+
* @param scene - The scene.
|
|
433
|
+
* @param name - The task's name.
|
|
434
|
+
* @param effect - The effect.
|
|
435
|
+
* @param target - The target it draws into.
|
|
436
|
+
* @returns The task.
|
|
437
|
+
*/
|
|
438
|
+
function createEffectTask(engine, scene, name, effect, target) {
|
|
439
|
+
const task = createEffectRenderTask({
|
|
440
|
+
name,
|
|
441
|
+
effect,
|
|
442
|
+
target,
|
|
443
|
+
clear: false
|
|
444
|
+
}, engine, scene);
|
|
445
|
+
task.dispose = () => {};
|
|
446
|
+
return task;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Builds the plugin that leaves `environmentDiffuse` of the environment's diffuse light.
|
|
450
|
+
*
|
|
451
|
+
* @param environmentDiffuse - What remains, 0 to 1. Baked into the WGSL, so a change compiles anew.
|
|
452
|
+
* @returns The plugin.
|
|
453
|
+
*
|
|
454
|
+
* @internal
|
|
455
|
+
*/
|
|
456
|
+
function createSsgiEnvironmentPlugin(environmentDiffuse) {
|
|
457
|
+
const fragment = {
|
|
458
|
+
CUSTOM_FRAGMENT_DEFINITIONS: "var<private> finalIrradiance: vec3<f32>;var<private> ignifxSsgiRemoved: vec3<f32>;",
|
|
459
|
+
CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: `color-=(finalIrradiance-ignifxSsgiRemoved)*${(1 - environmentDiffuse).toFixed(4)};ignifxSsgiRemoved=finalIrradiance;`
|
|
460
|
+
};
|
|
461
|
+
return {
|
|
462
|
+
name: SSGI_ENVIRONMENT_PLUGIN_NAME,
|
|
463
|
+
priority: -1,
|
|
464
|
+
getCustomCode: (stage) => stage === "fragment" ? fragment : null
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Puts a plugin on every lit PBR material in the scene, replacing an older one of the same name,
|
|
469
|
+
* or takes it off every material when `plugin` is `null`.
|
|
470
|
+
*
|
|
471
|
+
* @param scene - The scene.
|
|
472
|
+
* @param plugin - The current plugin, or `null` to remove.
|
|
473
|
+
* @param isSceneRegistered - Whether a changed material's pipelines must be rebuilt.
|
|
474
|
+
*/
|
|
475
|
+
function attachPlugin(scene, plugin, isSceneRegistered) {
|
|
476
|
+
const meshes = scene.meshes;
|
|
477
|
+
for (let index = 0; index < meshes.length; index += 1) {
|
|
478
|
+
const material = meshes[index]?.material;
|
|
479
|
+
if (material === void 0 || material === null || !isPbrMaterial(material)) continue;
|
|
480
|
+
const current = material.plugins ?? [];
|
|
481
|
+
const wanted = plugin !== null && getPbrUnlit(material) === void 0;
|
|
482
|
+
if (wanted && current.includes(plugin)) continue;
|
|
483
|
+
const kept = current.filter((other) => other.name !== SSGI_ENVIRONMENT_PLUGIN_NAME);
|
|
484
|
+
if (!wanted && kept.length === current.length) continue;
|
|
485
|
+
material.plugins = wanted ? [...kept, plugin] : kept;
|
|
486
|
+
if (isSceneRegistered) rebuildMaterialPipelines(scene, material);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
//#endregion
|
|
490
|
+
export { SSGI_ENVIRONMENT_PLUGIN_NAME, SSGI_MAX_DENOISE_PASSES, SSGI_TASK_NAMES, clampSsgiDenoisePasses, createSsgiEnvironmentPlugin, createSsgiPass, ssgiCompositeFragmentWgsl, ssgiDenoiseFragmentWgsl, writeSsgiFilterUniforms };
|
|
491
|
+
|
|
492
|
+
//# sourceMappingURL=ssgi-Dk20U3oR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ssgi-Dk20U3oR.js","names":[],"sources":["../src/lite/gpu/ssgi.ts"],"sourcesContent":["import {\n createCopyToTextureTask,\n createEffectRenderTask,\n createEffectWrapper,\n createScreenSpaceGlobalIlluminationPostProcessTask,\n createSurfaceRenderTargetTexture,\n disposeEffectWrapper,\n disposeRenderTargetTexture,\n getEffectiveAspectRatio,\n getPbrUnlit,\n getViewProjectionMatrix,\n isPbrMaterial,\n onRenderTargetTextureResize,\n setEffectTexture,\n setEffectUniforms,\n} from \"@babylonjs/lite\";\nimport { Mat4 } from \"../../math/mat4.js\";\nimport { rebuildMaterialPipelines } from \"../material.js\";\nimport type { SceneColorPass } from \"./scene-color-passes.js\";\nimport type { SceneInputs } from \"./scene-inputs.js\";\nimport type {\n Camera,\n EffectWrapper,\n EngineContext,\n MaterialPlugin,\n RenderTarget,\n RenderTargetTextureResult,\n SceneContext,\n ScreenSpaceGlobalIlluminationPostProcessTask,\n Task,\n Texture2D,\n} from \"@babylonjs/lite\";\n\n/**\n * Screen-space global illumination (`docs/architecture/07-rendering.md` §2.7). Its own chunk,\n * loaded only while a `PostProcessStack` enables `ssgi` (`CONSTITUTION.md` §2.5).\n *\n * ```text\n * colour ─→ trace (Lite) ─→ copy ─→ bounce ─ denoise × n ─→ bounce ─┐\n * └──────────────── colour += bounce · albedo · intensity ←───────┘\n * ```\n *\n * - **Trace.** Lite's `createScreenSpaceGlobalIlluminationPostProcessTask` (`index.d.ts` 3681)\n * with `composition: \"none\"`: it marches `rays` rays per pixel through the shared\n * scene-input depth, averages the lit colour they reach over 64 frames, and leaves the result in\n * its `illuminationTexture`. That is the light arriving at each pixel, not yet reflected.\n * - **Why not Lite's composite.** Its additive composite is `colour + bounce · intensity`, with no\n * term for the surface the light lands on: a black surface is lit like a white one, and the frame\n * washes out. The composite here multiplies by the surface's diffuse albedo, a scene input\n * (`./scene-inputs.ts`), so a PBR surface reflects the bounce in its own colour and a metal\n * reflects none. That input has two limits, both Lite's: a Standard material's `diffuse` colour\n * is not in it, and an unlit PBR material has an albedo like a lit one.\n * - **Copy.** Lite exposes its result as a `RenderTarget`, which an effect cannot sample, so it is\n * copied into a target that has a `Texture2D`, as the scene inputs copy their attachments.\n * - **Denoise.** A few rays per pixel leave grain the temporal average does not remove. Each pass is\n * a 3×3 filter whose taps are `stride` texels apart, the stride doubling per pass (à-trous,\n * Dammertz et al., \"Edge-avoiding À-Trous wavelet transform for fast global illumination\n * filtering\", HPG 2010). A tap counts by how close it lies to the centre pixel's surface plane\n * and how far its normal agrees, both read from the scene inputs, so the blur runs along a\n * surface and stops at its edges.\n * - **Composite.** Additive through the blend unit, into the colour the trace read\n * (`SceneColorPass.inPlace`). At half resolution it takes the four bounce texels around the\n * pixel, weighted the same way, so a low-resolution texel does not bleed across an edge. The\n * bounce targets are `floor(size / 2)` and Lite's result `round(size / 2)`, so on an odd canvas\n * the copy resamples by one texel instead of copying texel for texel.\n *\n * **The environment plugin.** The environment's irradiance (`finalIrradiance`,\n * `lib/material/pbr/fragments/ibl-fragment.js` line 6) stands in for all indirect light, so a\n * project can turn it down while SSGI adds the near part: the plugin subtracts\n * `(1 - environmentDiffuse)` of `finalIrradiance` from the colour, specular left alone. At the\n * default of 1 no plugin is attached.\n *\n * **How the plugin compiles everywhere.** `CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION` is injected\n * at both the `AI` and the `NI` slot, which follow each other, and `finalIrradiance` exists only\n * when the material has an environment. The plugin declares a module-scope `finalIrradiance` of\n * zero, which the IBL code's own `let` shadows where it exists, and subtracts only what changed\n * since its last run, so the two injections together subtract once whichever side of the IBL code\n * they land on, and a material without an environment subtracts nothing. Priority -1 puts it ahead\n * of the HDR linear-output save (priority 0), which then keeps the adjusted colour.\n *\n * Plugins need Lite's bridges, which `rendering.hdr` and the `materialPlugins` feature install, so\n * without either the plugin is not attached and the environment is left as it is.\n */\n\n/**\n * The tuning a recorded pass follows live.\n *\n * @internal\n */\nexport interface SsgiTuning {\n /** How strongly the bounce is added, 0 to 4; 1 is what the surface would reflect. */\n readonly intensity: number;\n /** How far each ray marches, in world units. */\n readonly radius: number;\n /** March steps per ray, 1 to 64. */\n readonly samples: number;\n /** Rays per pixel, 1 to 8. */\n readonly rays: number;\n /** How much of the environment's diffuse light remains, 0 to 1. */\n readonly environmentDiffuse: number;\n}\n\n/**\n * An SSGI pass: its tasks once created, its per-frame update, and what it owns.\n *\n * @internal\n */\nexport interface SsgiPass extends SceneColorPass {\n /**\n * Writes the tuning onto the tasks and, when plugins are available, keeps every lit PBR\n * material's environment plugin in step.\n *\n * @param tuning - The stack's `ssgi` record.\n * @param isSceneRegistered - Whether a patched material's pipelines must be rebuilt.\n */\n update(tuning: SsgiTuning, isSceneRegistered: boolean): void;\n /**\n * Takes the plugin off every material again and frees the effects and targets. The tasks\n * themselves are disposed by the installer, which must run first.\n *\n * @param isSceneRegistered - Whether a patched material's pipelines must be rebuilt.\n */\n dispose(isSceneRegistered: boolean): void;\n}\n\n/**\n * The frame-graph task names, in the order they run; `denoise` is followed by the pass index.\n *\n * @internal\n */\nexport const SSGI_TASK_NAMES = {\n trace: \"ignifx:ssgi\",\n copy: \"ignifx:ssgi-copy\",\n uniforms: \"ignifx:ssgi-uniforms\",\n denoise: \"ignifx:ssgi-denoise-\",\n composite: \"ignifx:ssgi-composite\",\n} as const;\n\n/**\n * The most denoise passes a pass builds; the last one's taps are 8 texels apart.\n *\n * @internal\n */\nexport const SSGI_MAX_DENOISE_PASSES = 4;\n\n/**\n * The environment plugin's name.\n *\n * @internal\n */\nexport const SSGI_ENVIRONMENT_PLUGIN_NAME = \"ignifx-ssgi-environment\";\n\n/** The format of the bounce targets: the one Lite's `illuminationTexture` has. */\nconst BOUNCE_FORMAT: GPUTextureFormat = \"rgba16float\";\n\n/** Uniform floats per effect: an inverse view-projection, the eye, and one `vec4` of parameters. */\nconst UNIFORM_FLOATS = 24;\n\n/**\n * The distance off the centre pixel's surface plane at which a tap's weight has fallen to `1 / e`,\n * as a fraction of the pixel's distance from the eye: 1.2 cm a metre away.\n */\nconst PLANE_TOLERANCE = 0.012;\n\n/** The power the agreement of two normals is raised to; higher stops the blur at gentler creases. */\nconst NORMAL_POWER = 4;\n\n/** The blend that adds a pass's colour to the target and leaves the target's alpha alone. */\nconst ADDITIVE_BLEND: GPUBlendState = {\n color: { operation: \"add\", srcFactor: \"one\", dstFactor: \"one\" },\n alpha: { operation: \"add\", srcFactor: \"zero\", dstFactor: \"one\" },\n};\n\n/**\n * What both shaders declare: the uniform block and the reads of the scene inputs.\n *\n * @remarks\n * `params` is `(stride or intensity, plane tolerance, normal power, display flag)`. `ssgiSceneTexel` maps\n * a bounce texel to the scene texel under its centre, the identity at full resolution.\n *\n * @returns The WGSL.\n */\nfunction sharedWgsl(): string {\n return `struct SsgiFilter{invViewProj:mat4x4<f32>,eye:vec4<f32>,params:vec4<f32>};\n@group(0)@binding(0)var<uniform>ssgi:SsgiFilter;\n@group(0)@binding(1)var bounce:texture_2d<f32>;\n@group(0)@binding(2)var sceneDepth:texture_depth_2d;\n@group(0)@binding(3)var sceneNormals:texture_2d<f32>;\nfn ssgiSceneTexel(texel:vec2<i32>,bounceSize:vec2<f32>,sceneSize:vec2<f32>)->vec2<i32>{\nlet uv=(vec2<f32>(texel)+vec2<f32>(0.5))/bounceSize;\nreturn clamp(vec2<i32>(uv*sceneSize),vec2<i32>(0),vec2<i32>(sceneSize)-vec2<i32>(1));}\nfn ssgiWorld(texel:vec2<i32>,depth:f32,sceneSize:vec2<f32>)->vec3<f32>{\nlet uv=(vec2<f32>(texel)+vec2<f32>(0.5))/sceneSize;\nlet clip=ssgi.invViewProj*vec4<f32>(uv.x*2.0-1.0,1.0-uv.y*2.0,depth,1.0);\nreturn clip.xyz/clip.w;}\nfn ssgiNormal(texel:vec2<i32>)->vec3<f32>{\nlet n=textureLoad(sceneNormals,texel,0).xyz*2.0-vec3<f32>(1.0);\nreturn n*inverseSqrt(max(dot(n,n),1e-8));}\nfn ssgiTolerance(position:vec3<f32>)->f32{return max(distance(position,ssgi.eye.xyz),1e-3)*ssgi.params.y;}\nfn ssgiSurfaceWeight(position:vec3<f32>,normal:vec3<f32>,tolerance:f32,otherPosition:vec3<f32>,otherNormal:vec3<f32>)->f32{\nlet plane=abs(dot(normal,otherPosition-position));\nreturn exp(-plane/tolerance)*pow(max(dot(normal,otherNormal),0.0),ssgi.params.z);}\nfn ssgiBounce(texel:vec2<i32>)->vec3<f32>{\nreturn min(max(textureLoad(bounce,texel,0).rgb,vec3<f32>(0.0)),vec3<f32>(65000.0));}`;\n}\n\n/**\n * The denoise pass's fragment shader: a 3×3 filter with taps `params.x` texels apart, each weighted\n * by the kernel `(1, 0.5)` per axis and by how well it shares the centre pixel's surface.\n *\n * @returns The WGSL, with Lite's `effectFragment` entry point.\n *\n * @internal\n */\nexport function ssgiDenoiseFragmentWgsl(): string {\n return `${sharedWgsl()}\n@fragment fn effectFragment(fragment:EffectVertexOutput)->@location(0)vec4<f32>{\nlet bounceSize=vec2<f32>(textureDimensions(bounce));\nlet sceneSize=vec2<f32>(textureDimensions(sceneDepth));\nlet texel=vec2<i32>(fragment.position.xy);\nlet sceneTexel=ssgiSceneTexel(texel,bounceSize,sceneSize);\nlet depth=textureLoad(sceneDepth,sceneTexel,0);\nif(depth<=0.0){return vec4<f32>(0.0,0.0,0.0,1.0);}\nlet position=ssgiWorld(sceneTexel,depth,sceneSize);\nlet normal=ssgiNormal(sceneTexel);\nlet tolerance=ssgiTolerance(position);\nlet stride=max(i32(ssgi.params.x),1);\nlet last=vec2<i32>(bounceSize)-vec2<i32>(1);\nvar sum=ssgiBounce(texel);var total=1.0;\nfor(var y=-1;y<=1;y++){for(var x=-1;x<=1;x++){\nif(x==0&&y==0){continue;}\nlet other=texel+vec2<i32>(x,y)*stride;\nif(any(other<vec2<i32>(0))||any(other>last)){continue;}\nlet otherScene=ssgiSceneTexel(other,bounceSize,sceneSize);\nlet otherDepth=textureLoad(sceneDepth,otherScene,0);\nif(otherDepth<=0.0){continue;}\nlet kernel=select(1.0,0.5,x!=0)*select(1.0,0.5,y!=0);\nlet weight=kernel*ssgiSurfaceWeight(position,normal,tolerance,ssgiWorld(otherScene,otherDepth,sceneSize),ssgiNormal(otherScene));\nsum+=ssgiBounce(other)*weight;total+=weight;}}\nreturn vec4<f32>(sum/total,1.0);}`;\n}\n\n/**\n * The composite's fragment shader: the bounce at the pixel, taken from the four bounce texels\n * around it by bilinear weight and shared surface, times the surface's albedo and `params.x`.\n * Meant for {@link ADDITIVE_BLEND}.\n *\n * @remarks\n * With `params.w` set the colour is display-encoded (no `rendering.hdr`), and so is the bounce\n * traced from it. Albedo is linear, and a display value times a linear one, added to a display\n * value, comes out several times too bright, so the bounce is first taken to roughly linear light\n * with a 2.2 power. The sum is still made in display values, which only `rendering.hdr` avoids.\n *\n * @returns The WGSL, with Lite's `effectFragment` entry point.\n *\n * @internal\n */\nexport function ssgiCompositeFragmentWgsl(): string {\n return `${sharedWgsl()}\n@group(0)@binding(4)var sceneAlbedo:texture_2d<f32>;\n@fragment fn effectFragment(fragment:EffectVertexOutput)->@location(0)vec4<f32>{\nlet bounceSize=vec2<f32>(textureDimensions(bounce));\nlet sceneSize=vec2<f32>(textureDimensions(sceneDepth));\nlet texel=vec2<i32>(fragment.position.xy);\nlet depth=textureLoad(sceneDepth,texel,0);\nif(depth<=0.0){return vec4<f32>(0.0);}\nlet albedo=textureLoad(sceneAlbedo,texel,0).rgb;\nlet position=ssgiWorld(texel,depth,sceneSize);\nlet normal=ssgiNormal(texel);\nlet tolerance=ssgiTolerance(position);\nlet at=(vec2<f32>(texel)+vec2<f32>(0.5))/sceneSize*bounceSize-vec2<f32>(0.5);\nlet base=floor(at);let f=at-base;\nlet last=vec2<i32>(bounceSize)-vec2<i32>(1);\nvar sum=vec3<f32>(0.0);var total=0.0;\nfor(var j=0;j<2;j++){for(var i=0;i<2;i++){\nlet other=clamp(vec2<i32>(base)+vec2<i32>(i,j),vec2<i32>(0),last);\nlet otherScene=ssgiSceneTexel(other,bounceSize,sceneSize);\nlet otherDepth=textureLoad(sceneDepth,otherScene,0);\nif(otherDepth<=0.0){continue;}\nlet bilinear=select(1.0-f.x,f.x,i==1)*select(1.0-f.y,f.y,j==1);\n// The small constant keeps a pixel none of whose four texels share its surface from going black.\nlet weight=bilinear*(ssgiSurfaceWeight(position,normal,tolerance,ssgiWorld(otherScene,otherDepth,sceneSize),ssgiNormal(otherScene))+1e-4);\nsum+=ssgiBounce(other)*weight;total+=weight;}}\nif(total<=0.0){return vec4<f32>(0.0);}\nvar light=sum/total;\nif(ssgi.params.w>0.5){light=pow(light,vec3<f32>(2.2));}\nreturn vec4<f32>(albedo*light*ssgi.params.x,0.0);}`;\n}\n\n/**\n * Clamps a `denoisePasses` value to what a pass can build.\n *\n * @param passes - The record's value.\n * @returns A whole number from 0 to {@link SSGI_MAX_DENOISE_PASSES}; 0 for a value that is not a number.\n *\n * @internal\n */\nexport function clampSsgiDenoisePasses(passes: number): number {\n if (Number.isNaN(passes)) {\n return 0;\n }\n return Math.min(SSGI_MAX_DENOISE_PASSES, Math.max(0, Math.round(passes)));\n}\n\n/**\n * What one effect's uniform block is written from.\n *\n * @internal\n */\nexport interface SsgiFilterUniforms {\n /** The inverse of the camera's view-projection, 16 floats. */\n readonly inverseViewProjection: ArrayLike<number>;\n /** The camera's world matrix, whose translation is the eye. */\n readonly cameraWorld: ArrayLike<number>;\n /** `params.x`: the tap stride of a denoise pass, the intensity of the composite. */\n readonly first: number;\n /** `params.w`: whether the colour the pass works on is display-encoded. */\n readonly isDisplayEncoded: boolean;\n}\n\n/**\n * Writes one effect's uniform block.\n *\n * @param values - What to write.\n * @param out - {@link UNIFORM_FLOATS} floats, overwritten.\n * @returns `out`.\n *\n * @internal\n */\nexport function writeSsgiFilterUniforms(values: SsgiFilterUniforms, out: Float32Array): Float32Array {\n for (let index = 0; index < 16; index += 1) {\n out[index] = values.inverseViewProjection[index] ?? 0;\n }\n out[16] = values.cameraWorld[12] ?? 0;\n out[17] = values.cameraWorld[13] ?? 0;\n out[18] = values.cameraWorld[14] ?? 0;\n out[19] = 1;\n out[20] = values.first;\n out[21] = PLANE_TOLERANCE;\n out[22] = NORMAL_POWER;\n out[23] = values.isDisplayEncoded ? 1 : 0;\n return out;\n}\n\n/** What `create` built, kept for the per-frame update and the teardown. */\ninterface Built {\n readonly trace: ScreenSpaceGlobalIlluminationPostProcessTask;\n readonly effects: readonly EffectWrapper[];\n readonly targets: readonly RenderTargetTextureResult[];\n readonly stops: readonly (() => void)[];\n}\n\n/**\n * Creates an SSGI pass.\n *\n * @param engine - The engine.\n * @param scene - The scene, whose materials get the plugin.\n * @param inputs - A scene-inputs lease acquired with `albedo: true`; the caller releases it.\n * @param camera - The camera the inputs were drawn from.\n * @param options - The initial tuning and the creation-time choices.\n * @param options.tuning - The initial tuning.\n * @param options.halfResolution - Whether the rays are traced, and the bounce filtered, at half resolution.\n * @param options.denoisePasses - How many denoise passes run, 0 to {@link SSGI_MAX_DENOISE_PASSES}.\n * @param options.isLinear - Whether the scene colour is linear (`rendering.hdr`) and not display-encoded.\n * @param options.usePlugin - Whether Lite's plugin bridges are installed, so the plugin can be used.\n * @returns The pass.\n *\n * @internal\n */\nexport function createSsgiPass(\n engine: EngineContext,\n scene: SceneContext,\n inputs: SceneInputs,\n camera: Camera,\n options: {\n readonly tuning: SsgiTuning;\n readonly halfResolution: boolean;\n readonly denoisePasses: number;\n readonly isLinear: boolean;\n readonly usePlugin: boolean;\n },\n): SsgiPass {\n let built: Built | null = null;\n let tuning = options.tuning;\n let plugin: MaterialPlugin | null = null;\n let pluginValue = Number.NaN;\n return {\n inPlace: true,\n create(colour: RenderTarget): readonly Task[] {\n const trace = createScreenSpaceGlobalIlluminationPostProcessTask(\n {\n name: SSGI_TASK_NAMES.trace,\n sourceTexture: colour,\n depthTexture: inputs.depthTarget,\n camera,\n resolutionScale: options.halfResolution ? 0.5 : 1,\n rayLength: tuning.radius,\n stepCount: tuning.samples,\n rayCount: tuning.rays,\n composition: \"none\",\n },\n engine,\n scene,\n );\n const passCount = clampSsgiDenoisePasses(options.denoisePasses);\n const createTarget = (label: string): RenderTargetTextureResult =>\n createSurfaceRenderTargetTexture(engine, {\n lbl: label,\n format: BOUNCE_FORMAT,\n samples: 1,\n size: options.halfResolution ? { surface: engine, scale: 0.5 } : engine,\n });\n const targets = [createTarget(\"ignifx:ssgi-bounce\")];\n if (passCount > 0) {\n targets.push(createTarget(\"ignifx:ssgi-bounce-2\"));\n }\n const targetAt = (index: number): RenderTargetTextureResult => {\n const target = targets[index % targets.length];\n if (target === undefined) {\n throw new RangeError(`SSGI has no bounce target ${String(index)}.`);\n }\n return target;\n };\n const tasks: Task[] = [\n trace,\n createCopyToTextureTask(\n { name: SSGI_TASK_NAMES.copy, sourceTexture: trace.illuminationTexture, targetTexture: targetAt(0).rt },\n engine,\n scene,\n ),\n ];\n\n // One effect per pass: each has its own uniform block. Pass `n` reads target `n` and writes\n // target `n + 1`, the two alternating.\n const denoiseWgsl = ssgiDenoiseFragmentWgsl();\n const effects: EffectWrapper[] = [];\n const sources: (() => Texture2D)[] = [];\n const denoiseTasks: Task[] = [];\n for (let pass = 0; pass < passCount; pass += 1) {\n const name = `${SSGI_TASK_NAMES.denoise}${String(pass)}`;\n const effect = createEffectWrapper(engine, {\n name,\n fragmentWGSL: denoiseWgsl,\n bindings: [\n { name: \"ssgi\", binding: 0, kind: \"uniform\", uniformByteLength: UNIFORM_FLOATS * 4 },\n { name: \"bounce\", binding: 1, kind: \"texture\" },\n { name: \"sceneDepth\", binding: 2, kind: \"texture\", textureSampleType: \"depth\" },\n { name: \"sceneNormals\", binding: 3, kind: \"texture\" },\n ],\n });\n effects.push(effect);\n sources.push(() => targetAt(pass).texture);\n denoiseTasks.push(createEffectTask(engine, scene, name, effect, targetAt(pass + 1).rt));\n }\n const composite = createEffectWrapper(engine, {\n name: SSGI_TASK_NAMES.composite,\n fragmentWGSL: ssgiCompositeFragmentWgsl(),\n bindings: [\n { name: \"ssgi\", binding: 0, kind: \"uniform\", uniformByteLength: UNIFORM_FLOATS * 4 },\n { name: \"bounce\", binding: 1, kind: \"texture\" },\n { name: \"sceneDepth\", binding: 2, kind: \"texture\", textureSampleType: \"depth\" },\n { name: \"sceneNormals\", binding: 3, kind: \"texture\" },\n { name: \"sceneAlbedo\", binding: 4, kind: \"texture\" },\n ],\n blend: ADDITIVE_BLEND,\n });\n effects.push(composite);\n sources.push(() => targetAt(passCount).texture);\n\n const bind = (): void => {\n const albedo = inputs.albedo;\n for (let index = 0; index < effects.length; index += 1) {\n const effect = effects[index];\n const source = sources[index];\n if (effect === undefined || source === undefined) {\n continue;\n }\n setEffectTexture(effect, 1, source());\n setEffectTexture(effect, 2, inputs.depth);\n setEffectTexture(effect, 3, inputs.normals);\n }\n if (albedo !== null) {\n setEffectTexture(composite, 4, albedo);\n }\n };\n bind();\n // A resize swaps the textures behind the facades; a wrapper's cached bind group keeps the old\n // view until a texture write marks it dirty.\n const stops = [inputs.onChange(bind), ...targets.map((target) => onRenderTargetTextureResize(target, bind))];\n\n const viewProjection = new Mat4();\n const inverse = new Mat4();\n const uniforms = new Float32Array(UNIFORM_FLOATS);\n // One object for every effect and frame: nothing is allocated while drawing.\n const values = {\n inverseViewProjection: inverse.elements,\n cameraWorld: camera.worldMatrix,\n first: 0,\n isDisplayEncoded: !options.isLinear,\n };\n const uniformsTask: Task & { readonly _passes: unknown[] } = {\n name: SSGI_TASK_NAMES.uniforms,\n engine,\n scene,\n _passes: [],\n record(): void {\n // Nothing to record: the work is uploads, done in `execute`.\n },\n execute(): number {\n const width = inputs.depth.width;\n const height = inputs.depth.height;\n if (width <= 0 || height <= 0) {\n return 0;\n }\n // The matrix Lite's trace uses this frame (`lib/post-process/screen-space-global-illumination.js`).\n const current = getViewProjectionMatrix(camera, getEffectiveAspectRatio(camera, width, height));\n const elements = viewProjection.elements;\n for (let index = 0; index < 16; index += 1) {\n elements[index] = current[index] ?? 0;\n }\n if (!Mat4.invertToRef(elements, inverse)) {\n inverse.identity();\n }\n for (let index = 0; index < effects.length; index += 1) {\n const effect = effects[index];\n if (effect === undefined) {\n continue;\n }\n values.first = effect === composite ? Math.min(4, Math.max(0, tuning.intensity)) : 2 ** index;\n setEffectUniforms(effect, writeSsgiFilterUniforms(values, uniforms));\n }\n return 0;\n },\n dispose(): void {\n // The effects and targets are freed by the pass's own `dispose`.\n },\n };\n tasks.push(\n uniformsTask,\n ...denoiseTasks,\n createEffectTask(engine, scene, SSGI_TASK_NAMES.composite, composite, colour),\n );\n built = { trace, effects, targets, stops };\n return tasks;\n },\n update(next: SsgiTuning, isSceneRegistered: boolean): void {\n tuning = next;\n if (built === null) {\n return;\n }\n built.trace.rayLength = next.radius;\n built.trace.stepCount = next.samples;\n built.trace.rayCount = next.rays;\n if (!options.usePlugin) {\n return;\n }\n const value = Math.min(1, Math.max(0, next.environmentDiffuse));\n if (value >= 1) {\n // Nothing to subtract: leave the materials as they are.\n if (plugin !== null) {\n attachPlugin(scene, null, isSceneRegistered);\n plugin = null;\n pluginValue = Number.NaN;\n }\n return;\n }\n if (plugin === null || value !== pluginValue) {\n pluginValue = value;\n plugin = createSsgiEnvironmentPlugin(value);\n }\n attachPlugin(scene, plugin, isSceneRegistered);\n },\n dispose(isSceneRegistered: boolean): void {\n if (plugin !== null) {\n attachPlugin(scene, null, isSceneRegistered);\n plugin = null;\n }\n if (built === null) {\n return;\n }\n for (const stop of built.stops) {\n stop();\n }\n for (const effect of built.effects) {\n disposeEffectWrapper(effect);\n }\n for (const target of built.targets) {\n disposeRenderTargetTexture(target);\n }\n built = null;\n },\n };\n}\n\n/**\n * Creates a task that draws an effect over a target without clearing it, and that leaves the target\n * alone when disposed.\n *\n * @remarks\n * Lite's effect task frees its target on `dispose` (`lib/effect/effect-renderer.js`,\n * `disposeRenderTarget(task._rt)`). The composite's target is the scene colour, which the rest of\n * the frame graph keeps drawing into, and the bounce targets are freed by the pass.\n *\n * @param engine - The engine.\n * @param scene - The scene.\n * @param name - The task's name.\n * @param effect - The effect.\n * @param target - The target it draws into.\n * @returns The task.\n */\nfunction createEffectTask(\n engine: EngineContext,\n scene: SceneContext,\n name: string,\n effect: EffectWrapper,\n target: RenderTarget,\n): Task {\n const task: Task = createEffectRenderTask({ name, effect, target, clear: false }, engine, scene);\n task.dispose = (): void => {\n // The pipeline and bind group are the wrapper's; the target is not this task's to free.\n };\n return task;\n}\n\n/**\n * Builds the plugin that leaves `environmentDiffuse` of the environment's diffuse light.\n *\n * @param environmentDiffuse - What remains, 0 to 1. Baked into the WGSL, so a change compiles anew.\n * @returns The plugin.\n *\n * @internal\n */\nexport function createSsgiEnvironmentPlugin(environmentDiffuse: number): MaterialPlugin {\n const removed = (1 - environmentDiffuse).toFixed(4);\n const fragment = {\n CUSTOM_FRAGMENT_DEFINITIONS: \"var<private> finalIrradiance: vec3<f32>;var<private> ignifxSsgiRemoved: vec3<f32>;\",\n CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: `color-=(finalIrradiance-ignifxSsgiRemoved)*${removed};ignifxSsgiRemoved=finalIrradiance;`,\n };\n return {\n name: SSGI_ENVIRONMENT_PLUGIN_NAME,\n priority: -1,\n getCustomCode: (stage) => (stage === \"fragment\" ? fragment : null),\n };\n}\n\n/**\n * Puts a plugin on every lit PBR material in the scene, replacing an older one of the same name,\n * or takes it off every material when `plugin` is `null`.\n *\n * @param scene - The scene.\n * @param plugin - The current plugin, or `null` to remove.\n * @param isSceneRegistered - Whether a changed material's pipelines must be rebuilt.\n */\nfunction attachPlugin(scene: SceneContext, plugin: MaterialPlugin | null, isSceneRegistered: boolean): void {\n const meshes = scene.meshes;\n for (let index = 0; index < meshes.length; index += 1) {\n const material = meshes[index]?.material;\n // Declared non-null, but Lite's mesh factories create meshes with `material: null`.\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n if (material === undefined || material === null || !isPbrMaterial(material)) {\n continue;\n }\n const current = material.plugins ?? [];\n const wanted = plugin !== null && getPbrUnlit(material) === undefined;\n if (wanted && current.includes(plugin)) {\n continue;\n }\n const kept = current.filter((other) => other.name !== SSGI_ENVIRONMENT_PLUGIN_NAME);\n if (!wanted && kept.length === current.length) {\n continue;\n }\n material.plugins = wanted ? [...kept, plugin] : kept;\n if (isSceneRegistered) {\n rebuildMaterialPipelines(scene, material);\n }\n }\n}\n"],"mappings":";;;;;;;;;AAkIA,MAAa,kBAAkB;CAC7B,OAAO;CACP,MAAM;CACN,UAAU;CACV,SAAS;CACT,WAAW;AACb;;;;;;AAOA,MAAa,0BAA0B;;;;;;AAOvC,MAAa,+BAA+B;;AAG5C,MAAM,gBAAkC;;AAGxC,MAAM,iBAAiB;;;;;AAMvB,MAAM,kBAAkB;;AAGxB,MAAM,eAAe;;AAGrB,MAAM,iBAAgC;CACpC,OAAO;EAAE,WAAW;EAAO,WAAW;EAAO,WAAW;CAAM;CAC9D,OAAO;EAAE,WAAW;EAAO,WAAW;EAAQ,WAAW;CAAM;AACjE;;;;;;;;;;AAWA,SAAS,aAAqB;CAC5B,OAAO;;;;;;;;;;;;;;;;;;;;;AAqBT;;;;;;;;;AAUA,SAAgB,0BAAkC;CAChD,OAAO,GAAG,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;AAyBzB;;;;;;;;;;;;;;;;AAiBA,SAAgB,4BAAoC;CAClD,OAAO,GAAG,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BzB;;;;;;;;;AAUA,SAAgB,uBAAuB,QAAwB;CAC7D,I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2
|
import { t as Color } from "./color-DrR6GFTd.js";
|
|
3
3
|
import { a as markMaterialDirty, o as rebuildMaterialPipelines } from "./material-myMbl9mW.js";
|
|
4
|
-
import { d as SURFACE_HOOK_NAMES, f as SURFACE_UNIFORM_BLOCK } from "./shader-declaration-
|
|
5
|
-
import { a as defineMaterialPlugin, s as uniformComponentCount } from "./material-plugin-
|
|
6
|
-
import { t as shaderMaterialsOf } from "./shader-material-
|
|
4
|
+
import { d as SURFACE_HOOK_NAMES, f as SURFACE_UNIFORM_BLOCK } from "./shader-declaration-BGprFBLq.js";
|
|
5
|
+
import { a as defineMaterialPlugin, s as uniformComponentCount } from "./material-plugin-BBxIy6eo.js";
|
|
6
|
+
import { t as shaderMaterialsOf } from "./shader-material-C9sYMGWw.js";
|
|
7
7
|
//#region src/lite/gpu/material-plugin.ts
|
|
8
8
|
/** The Lite point names that belong to the vertex stage. */
|
|
9
9
|
const VERTEX_POINTS = Object.freeze([
|
|
@@ -129,7 +129,7 @@ function detachLiteMaterialPlugins(material) {
|
|
|
129
129
|
//#region src/render/gpu/surface-shader-host.ts
|
|
130
130
|
/**
|
|
131
131
|
* The device-only half of surface shaders: the Lite plugin a compiled `.surface.wgsl` becomes, and
|
|
132
|
-
* the host-material writes that follow it (
|
|
132
|
+
* the host-material writes that follow it (ADR-0024).
|
|
133
133
|
*
|
|
134
134
|
* Each entry point takes the app or the host as a nullable and returns early when it is `null`, so
|
|
135
135
|
* `../surface-shader.ts` keeps no headless branch of its own.
|
|
@@ -154,7 +154,7 @@ function resolveSurfaceHost(material, isHeadless) {
|
|
|
154
154
|
* Re-uploads the host material's uniform block after a value write.
|
|
155
155
|
*
|
|
156
156
|
* @remarks
|
|
157
|
-
* Lite ignores `dynamic` for a PBR host and re-reads the plugin slice only after this
|
|
157
|
+
* Lite ignores `dynamic` for a PBR host and re-reads the plugin slice only after this;
|
|
158
158
|
* a Standard host re-uploads every frame because the plugin sets `dynamic`.
|
|
159
159
|
*
|
|
160
160
|
* @param host - The host material, or `null`.
|
|
@@ -1397,4 +1397,4 @@ function describeNames(names) {
|
|
|
1397
1397
|
//#endregion
|
|
1398
1398
|
export { SurfaceShaderBinding, attachSurfaceShaders, detachSurfaceShaders, surfaceShaderBinding, surfaceShaderName, surfaceShaders };
|
|
1399
1399
|
|
|
1400
|
-
//# sourceMappingURL=surface-shader-
|
|
1400
|
+
//# sourceMappingURL=surface-shader-BfADq9Wx.js.map
|