@zephyr3d/scene 0.5.0 → 0.6.1

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.
Files changed (199) hide show
  1. package/README.md +1 -1
  2. package/dist/animation/animationset.js +37 -37
  3. package/dist/animation/morphtrack.js +7 -5
  4. package/dist/animation/morphtrack.js.map +1 -1
  5. package/dist/animation/skeleton.js +11 -9
  6. package/dist/animation/skeleton.js.map +1 -1
  7. package/dist/asset/assetmanager.js +2 -2
  8. package/dist/asset/loaders/gltf/gltf_loader.js +7 -3
  9. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  10. package/dist/asset/loaders/image/webimage_loader.js +16 -0
  11. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  12. package/dist/asset/model.js +3 -9
  13. package/dist/asset/model.js.map +1 -1
  14. package/dist/blitter/bilateralblur.js +222 -0
  15. package/dist/{render/temporalcache.js.map → blitter/bilateralblur.js.map} +1 -1
  16. package/dist/blitter/blitter.js +7 -1
  17. package/dist/blitter/blitter.js.map +1 -1
  18. package/dist/blitter/depthlimitedgaussion.js +96 -39
  19. package/dist/blitter/depthlimitedgaussion.js.map +1 -1
  20. package/dist/blitter/gaussianblur.js +21 -21
  21. package/dist/camera/camera.js +142 -1
  22. package/dist/camera/camera.js.map +1 -1
  23. package/dist/index.d.ts +1178 -745
  24. package/dist/index.js +11 -6
  25. package/dist/index.js.map +1 -1
  26. package/dist/material/blinn.js +9 -3
  27. package/dist/material/blinn.js.map +1 -1
  28. package/dist/material/lambert.js +6 -2
  29. package/dist/material/lambert.js.map +1 -1
  30. package/dist/material/material.js +3 -1
  31. package/dist/material/material.js.map +1 -1
  32. package/dist/material/meshmaterial.js +73 -33
  33. package/dist/material/meshmaterial.js.map +1 -1
  34. package/dist/material/mixins/albedocolor.js +5 -4
  35. package/dist/material/mixins/albedocolor.js.map +1 -1
  36. package/dist/material/mixins/lightmodel/blinnphong.js +17 -7
  37. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  38. package/dist/material/mixins/lightmodel/lambert.js +5 -5
  39. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +13 -4
  40. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  41. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +13 -4
  42. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  43. package/dist/material/mixins/pbr/common.js +27 -15
  44. package/dist/material/mixins/pbr/common.js.map +1 -1
  45. package/dist/material/pbrmr.js +14 -3
  46. package/dist/material/pbrmr.js.map +1 -1
  47. package/dist/material/pbrsg.js +14 -3
  48. package/dist/material/pbrsg.js.map +1 -1
  49. package/dist/material/shader/helper.js +36 -21
  50. package/dist/material/shader/helper.js.map +1 -1
  51. package/dist/posteffect/bloom.js +1 -10
  52. package/dist/posteffect/bloom.js.map +1 -1
  53. package/dist/posteffect/compositor.js +43 -24
  54. package/dist/posteffect/compositor.js.map +1 -1
  55. package/dist/posteffect/fxaa.js +3 -11
  56. package/dist/posteffect/fxaa.js.map +1 -1
  57. package/dist/posteffect/grayscale.js +3 -11
  58. package/dist/posteffect/grayscale.js.map +1 -1
  59. package/dist/posteffect/posteffect.js +4 -0
  60. package/dist/posteffect/posteffect.js.map +1 -1
  61. package/dist/posteffect/sao.js +44 -24
  62. package/dist/posteffect/sao.js.map +1 -1
  63. package/dist/posteffect/ssr.js +536 -0
  64. package/dist/{material/lit.js.map → posteffect/ssr.js.map} +1 -1
  65. package/dist/posteffect/tonemap.js +3 -11
  66. package/dist/posteffect/tonemap.js.map +1 -1
  67. package/dist/posteffect/water.js +305 -337
  68. package/dist/posteffect/water.js.map +1 -1
  69. package/dist/render/abuffer_oit.js +2 -2
  70. package/dist/render/clipmap.js +16 -19
  71. package/dist/render/clipmap.js.map +1 -1
  72. package/dist/render/cull_visitor.js +5 -3
  73. package/dist/render/cull_visitor.js.map +1 -1
  74. package/dist/render/depthpass.js +17 -1
  75. package/dist/render/depthpass.js.map +1 -1
  76. package/dist/render/drawable_mixin.js +25 -19
  77. package/dist/render/drawable_mixin.js.map +1 -1
  78. package/dist/render/envlight.js +4 -2
  79. package/dist/render/envlight.js.map +1 -1
  80. package/dist/render/fft_wavegenerator.js +989 -0
  81. package/dist/{shaders/framework.js.map → render/fft_wavegenerator.js.map} +1 -1
  82. package/dist/render/gerstner_wavegenerator.js +265 -0
  83. package/dist/{material/standard.js.map → render/gerstner_wavegenerator.js.map} +1 -1
  84. package/dist/render/globalbindgroup_allocator.js +2 -1
  85. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  86. package/dist/render/hzb.js +273 -0
  87. package/dist/{material/terrainlightmodel.js.map → render/hzb.js.map} +1 -1
  88. package/dist/render/lightpass.js +35 -3
  89. package/dist/render/lightpass.js.map +1 -1
  90. package/dist/render/objectcolorpass.js +2 -1
  91. package/dist/render/objectcolorpass.js.map +1 -1
  92. package/dist/render/render_queue.js +72 -52
  93. package/dist/render/render_queue.js.map +1 -1
  94. package/dist/render/renderbundle_wrapper.js +79 -0
  95. package/dist/render/renderbundle_wrapper.js.map +1 -1
  96. package/dist/render/renderer.js +75 -36
  97. package/dist/render/renderer.js.map +1 -1
  98. package/dist/render/renderpass.js +16 -13
  99. package/dist/render/renderpass.js.map +1 -1
  100. package/dist/render/shadowmap_pass.js +6 -0
  101. package/dist/render/shadowmap_pass.js.map +1 -1
  102. package/dist/render/sky.js +12 -13
  103. package/dist/render/sky.js.map +1 -1
  104. package/dist/render/watermesh.js +94 -828
  105. package/dist/render/watermesh.js.map +1 -1
  106. package/dist/render/wavegenerator.js +8 -0
  107. package/dist/render/wavegenerator.js.map +1 -0
  108. package/dist/scene/batchgroup.js +60 -14
  109. package/dist/scene/batchgroup.js.map +1 -1
  110. package/dist/scene/environment.js +2 -2
  111. package/dist/scene/graph_node.js +0 -5
  112. package/dist/scene/graph_node.js.map +1 -1
  113. package/dist/scene/light.js +5 -5
  114. package/dist/scene/mesh.js +34 -18
  115. package/dist/scene/mesh.js.map +1 -1
  116. package/dist/scene/octree.js +5 -2
  117. package/dist/scene/octree.js.map +1 -1
  118. package/dist/scene/raycast_visitor.js +4 -2
  119. package/dist/scene/raycast_visitor.js.map +1 -1
  120. package/dist/scene/scene.js +1 -1
  121. package/dist/scene/scene_node.js +9 -5
  122. package/dist/scene/scene_node.js.map +1 -1
  123. package/dist/scene/terrain/grass.js +3 -4
  124. package/dist/scene/terrain/grass.js.map +1 -1
  125. package/dist/scene/terrain/heightfield.js +135 -53
  126. package/dist/scene/terrain/heightfield.js.map +1 -1
  127. package/dist/scene/terrain/patch.js +3 -4
  128. package/dist/scene/terrain/patch.js.map +1 -1
  129. package/dist/scene/terrain/terrain.js +1 -1
  130. package/dist/scene/xform.js +7 -9
  131. package/dist/scene/xform.js.map +1 -1
  132. package/dist/shaders/misc.js +10 -1
  133. package/dist/shaders/misc.js.map +1 -1
  134. package/dist/shaders/noise.js +81 -16
  135. package/dist/shaders/noise.js.map +1 -1
  136. package/dist/shaders/shadow.js +1 -9
  137. package/dist/shaders/shadow.js.map +1 -1
  138. package/dist/shaders/ssr.js +442 -0
  139. package/dist/{material/terrainmat.js.map → shaders/ssr.js.map} +1 -1
  140. package/dist/shaders/water.js +377 -250
  141. package/dist/shaders/water.js.map +1 -1
  142. package/dist/shadow/shadowmapper.js +11 -11
  143. package/dist/shapes/cylinder.js +6 -5
  144. package/dist/shapes/cylinder.js.map +1 -1
  145. package/dist/utility/bounding_volume.js +1 -53
  146. package/dist/utility/bounding_volume.js.map +1 -1
  147. package/dist/utility/misc.js +93 -0
  148. package/dist/utility/misc.js.map +1 -0
  149. package/dist/utility/shprojection.js +2 -7
  150. package/dist/utility/shprojection.js.map +1 -1
  151. package/dist/utility/textures/ggxlut.js +213 -0
  152. package/dist/utility/textures/ggxlut.js.map +1 -0
  153. package/dist/utility/textures/gradientnoise.js +61 -0
  154. package/dist/utility/textures/gradientnoise.js.map +1 -0
  155. package/dist/utility/textures/randomnoise.js +41 -0
  156. package/dist/utility/textures/randomnoise.js.map +1 -0
  157. package/dist/values.js +8 -1
  158. package/dist/values.js.map +1 -1
  159. package/package.json +4 -8
  160. package/dist/animation/usertrack.js +0 -47
  161. package/dist/animation/usertrack.js.map +0 -1
  162. package/dist/material/grassmat.js +0 -127
  163. package/dist/material/grassmat.js.map +0 -1
  164. package/dist/material/lightmodel.js +0 -2074
  165. package/dist/material/lightmodel.js.map +0 -1
  166. package/dist/material/lit.js +0 -578
  167. package/dist/material/mixins/pbr/metallicroughness.js +0 -126
  168. package/dist/material/mixins/pbr/metallicroughness.js.map +0 -1
  169. package/dist/material/mixins/pbr/specularglossness.js +0 -104
  170. package/dist/material/mixins/pbr/specularglossness.js.map +0 -1
  171. package/dist/material/pbr.js +0 -27
  172. package/dist/material/pbr.js.map +0 -1
  173. package/dist/material/standard.js +0 -282
  174. package/dist/material/terrainlightmodel.js +0 -259
  175. package/dist/material/terrainmat.js +0 -357
  176. package/dist/render/depth_pass.js +0 -47
  177. package/dist/render/depth_pass.js.map +0 -1
  178. package/dist/render/forward.js +0 -186
  179. package/dist/render/forward.js.map +0 -1
  180. package/dist/render/forward_pass.js +0 -137
  181. package/dist/render/forward_pass.js.map +0 -1
  182. package/dist/render/helper.js +0 -38
  183. package/dist/render/helper.js.map +0 -1
  184. package/dist/render/objectpool.js +0 -295
  185. package/dist/render/objectpool.js.map +0 -1
  186. package/dist/render/renderscheme.js +0 -61
  187. package/dist/render/renderscheme.js.map +0 -1
  188. package/dist/render/temporalcache.js +0 -222
  189. package/dist/scene/model.js +0 -111
  190. package/dist/scene/model.js.map +0 -1
  191. package/dist/scene/octree_update_visitor.js +0 -20
  192. package/dist/scene/octree_update_visitor.js.map +0 -1
  193. package/dist/shaders/builtins.js +0 -110
  194. package/dist/shaders/builtins.js.map +0 -1
  195. package/dist/shaders/framework.js +0 -723
  196. package/dist/shaders/lighting.js +0 -335
  197. package/dist/shaders/lighting.js.map +0 -1
  198. package/dist/utility/sheenlut.js +0 -196
  199. package/dist/utility/sheenlut.js.map +0 -1
@@ -0,0 +1,536 @@
1
+ import { AbstractPostEffect } from './posteffect.js';
2
+ import { linearToGamma } from '../shaders/misc.js';
3
+ import { sampleLinearDepth, SSR_calcJitter, screenSpaceRayTracing_HiZ, screenSpaceRayTracing_Linear2D } from '../shaders/ssr.js';
4
+ import { Vector2, Vector4, Matrix4x4 } from '@zephyr3d/base';
5
+ import { fetchSampler, copyTexture } from '../utility/misc.js';
6
+ import { BilateralBlurBlitter } from '../blitter/bilateralblur.js';
7
+
8
+ /**
9
+ * SSR post effect
10
+ *
11
+ * @remarks
12
+ * Internal used in light pass
13
+ *
14
+ * @internal
15
+ */ class SSR extends AbstractPostEffect {
16
+ static className = 'SSR';
17
+ static _programs = {};
18
+ static _resolveProgram = {};
19
+ static _combineProgram = undefined;
20
+ static _renderStateZTestGreater = null;
21
+ static _renderStateZTestEqual = null;
22
+ static _blurBlitterH = null;
23
+ static _blurBlitterV = null;
24
+ static _weights = [
25
+ 0.1847392078702266,
26
+ 0.16595854345772326,
27
+ 0.12031364177766891,
28
+ 0.07038755277896766,
29
+ 0.03322925565155569,
30
+ 0.012657819729901945,
31
+ 0.0038903040680094217,
32
+ 0.0009646503390864025,
33
+ 0.00019297087402915717,
34
+ 0.000031139936308099136,
35
+ 0.000004053309048174758,
36
+ 4.255228059965837e-7,
37
+ 3.602517634249573e-8,
38
+ 2.4592560765896795e-9,
39
+ 1.3534945386863618e-10,
40
+ 0
41
+ ];
42
+ _roughnessTex;
43
+ _normalTex;
44
+ _bindgroups;
45
+ _resolveBindGroup;
46
+ _combineBindGroup;
47
+ _debugFrameBuffer;
48
+ /**
49
+ * Creates an instance of SSR post effect
50
+ */ constructor(){
51
+ super();
52
+ this._opaque = true;
53
+ this._bindgroups = {};
54
+ this._resolveBindGroup = {};
55
+ this._combineBindGroup = null;
56
+ this._roughnessTex = null;
57
+ this._debugFrameBuffer = {};
58
+ }
59
+ get roughnessTexture() {
60
+ return this._roughnessTex;
61
+ }
62
+ set roughnessTexture(tex) {
63
+ this._roughnessTex = tex;
64
+ }
65
+ get normalTexture() {
66
+ return this._normalTex;
67
+ }
68
+ set normalTexture(tex) {
69
+ this._normalTex = tex;
70
+ }
71
+ /** {@inheritDoc AbstractPostEffect.requireLinearDepthTexture} */ requireLinearDepthTexture() {
72
+ return true;
73
+ }
74
+ /** {@inheritDoc AbstractPostEffect.requireDepthAttachment} */ requireDepthAttachment() {
75
+ return true;
76
+ }
77
+ /** @internal */ blurPass(ctx, blitter, blurSizeTex, blurSizeIndex, blurSizeScale, kernelRadius, stdDev, depthCutoff, fbFrom, fbTo) {
78
+ const size = new Vector2(fbFrom.getWidth(), fbFrom.getHeight());
79
+ blitter.kernelRadius = kernelRadius;
80
+ blitter.stdDev = stdDev;
81
+ blitter.size = size;
82
+ blitter.depthTex = ctx.linearDepthTexture;
83
+ blitter.depthCutoff = depthCutoff;
84
+ blitter.blurSizeTex = blurSizeTex;
85
+ blitter.blurSizeIndex = blurSizeIndex;
86
+ blitter.blurSizeScale = blurSizeScale;
87
+ blitter.sampler = fetchSampler('clamp_nearest_nomip');
88
+ blitter.cameraNearFar.setXY(ctx.camera.getNearPlane(), ctx.camera.getFarPlane());
89
+ blitter.srgbOut = false;
90
+ blitter.blit(fbFrom.getColorAttachments()[0], fbTo, fetchSampler('clamp_linear_nomip'));
91
+ }
92
+ /** @internal */ combine(ctx, inputColorTexture, reflectanceTex, srgbOut) {
93
+ const device = ctx.device;
94
+ let program = SSR._combineProgram;
95
+ if (program === undefined) {
96
+ program = this._createCombineProgrm(ctx);
97
+ SSR._combineProgram = program;
98
+ }
99
+ if (!this._combineBindGroup) {
100
+ this._combineBindGroup = device.createBindGroup(program.bindGroupLayouts[0]);
101
+ }
102
+ const linearSampler = fetchSampler('clamp_linear');
103
+ this._combineBindGroup.setTexture('colorTex', inputColorTexture, linearSampler);
104
+ this._combineBindGroup.setTexture('reflectanceTex', reflectanceTex, linearSampler);
105
+ this._combineBindGroup.setTexture('roughnessTex', this._roughnessTex, linearSampler);
106
+ this._combineBindGroup.setValue('targetSize', new Vector4(device.getDrawingBufferWidth(), device.getDrawingBufferHeight(), device.getDrawingBufferWidth(), device.getDrawingBufferHeight()));
107
+ this._combineBindGroup.setValue('flip', this.needFlip(device) ? 1 : 0);
108
+ this._combineBindGroup.setValue('srgbOut', srgbOut ? 1 : 0);
109
+ device.setProgram(program);
110
+ device.setBindGroup(0, this._combineBindGroup);
111
+ this.drawFullscreenQuad(this._getZTestGreaterRenderState(ctx));
112
+ }
113
+ /** @internal */ resolve(ctx, inputColorTexture, sceneDepthTexture, intersectTexture) {
114
+ const device = ctx.device;
115
+ const hash = ctx.env.light.envLight ? ctx.env.light.getHash() : '';
116
+ let program = SSR._resolveProgram[hash];
117
+ if (program === undefined) {
118
+ program = this._createResolveProgram(ctx);
119
+ SSR._resolveProgram[hash] = program;
120
+ }
121
+ let bindGroup = this._resolveBindGroup[hash];
122
+ if (!bindGroup) {
123
+ bindGroup = device.createBindGroup(program.bindGroupLayouts[0]);
124
+ this._resolveBindGroup[hash] = bindGroup;
125
+ }
126
+ const nearestSampler = fetchSampler('clamp_nearest');
127
+ const linearSampler = fetchSampler('clamp_linear');
128
+ bindGroup.setTexture('colorTex', inputColorTexture, linearSampler);
129
+ bindGroup.setTexture('intersectTex', intersectTexture, nearestSampler);
130
+ bindGroup.setTexture('roughnessTex', this._roughnessTex, nearestSampler);
131
+ bindGroup.setTexture('normalTex', this._normalTex, nearestSampler);
132
+ bindGroup.setTexture('depthTex', sceneDepthTexture, nearestSampler);
133
+ bindGroup.setValue('cameraNearFar', new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane()));
134
+ bindGroup.setValue('targetSize', new Vector4(device.getDrawingBufferWidth(), device.getDrawingBufferHeight(), sceneDepthTexture.width, sceneDepthTexture.height));
135
+ bindGroup.setValue('invProjMatrix', Matrix4x4.invert(ctx.camera.getProjectionMatrix()));
136
+ bindGroup.setValue('viewMatrix', ctx.camera.viewMatrix);
137
+ bindGroup.setValue('invViewMatrix', ctx.camera.worldMatrix);
138
+ if (ctx.env.light.envLight) {
139
+ bindGroup.setValue('envLightStrength', ctx.env.light.strength);
140
+ ctx.env.light.envLight.updateBindGroup(bindGroup);
141
+ }
142
+ bindGroup.setValue('flip', this.needFlip(device) ? 1 : 0);
143
+ device.setProgram(program);
144
+ device.setBindGroup(0, bindGroup);
145
+ this.drawFullscreenQuad(this._getZTestGreaterRenderState(ctx));
146
+ }
147
+ /** @internal */ intersect(ctx, inputColorTexture, sceneDepthTexture, blur, srgbOut) {
148
+ const device = ctx.device;
149
+ const hash = `${Number(blur)}:${ctx.env.light.envLight ? ctx.env.light.getHash() : ''}:${!!ctx.HiZTexture}:${!!ctx.primaryCamera.ssrCalcThickness}`;
150
+ let program = SSR._programs[hash];
151
+ if (program === undefined) {
152
+ program = this._createIntersectProgram(ctx, blur);
153
+ SSR._programs[hash] = program;
154
+ }
155
+ let bindGroup = this._bindgroups[hash];
156
+ if (!bindGroup) {
157
+ bindGroup = device.createBindGroup(program.bindGroupLayouts[0]);
158
+ this._bindgroups[hash] = bindGroup;
159
+ }
160
+ const nearestSampler = fetchSampler('clamp_nearest');
161
+ const linearSampler = fetchSampler('clamp_linear');
162
+ if (!blur) {
163
+ bindGroup.setTexture('colorTex', inputColorTexture, linearSampler);
164
+ if (ctx.env.light.envLight) {
165
+ bindGroup.setValue('envLightStrength', ctx.env.light.strength);
166
+ ctx.env.light.envLight.updateBindGroup(bindGroup);
167
+ }
168
+ }
169
+ bindGroup.setTexture('roughnessTex', this._roughnessTex, nearestSampler);
170
+ bindGroup.setTexture('normalTex', this._normalTex, nearestSampler);
171
+ bindGroup.setTexture('depthTex', sceneDepthTexture, nearestSampler);
172
+ bindGroup.setValue('cameraNearFar', new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane()));
173
+ bindGroup.setValue('cameraPos', ctx.camera.getWorldPosition());
174
+ bindGroup.setValue('invProjMatrix', Matrix4x4.invert(ctx.camera.getProjectionMatrix()));
175
+ bindGroup.setValue('projMatrix', ctx.camera.getProjectionMatrix());
176
+ bindGroup.setValue('viewMatrix', ctx.camera.viewMatrix);
177
+ bindGroup.setValue('invViewMatrix', ctx.camera.worldMatrix);
178
+ bindGroup.setValue('ssrParams', ctx.camera.ssrParams);
179
+ bindGroup.setValue('ssrMaxRoughness', ctx.camera.ssrMaxRoughness);
180
+ if (ctx.HiZTexture) {
181
+ bindGroup.setTexture('hizTex', ctx.HiZTexture, nearestSampler);
182
+ bindGroup.setValue('depthMipLevels', ctx.HiZTexture.mipLevelCount);
183
+ bindGroup.setValue('targetSize', new Vector4(device.getDrawingBufferWidth(), device.getDrawingBufferHeight(), ctx.HiZTexture.width, ctx.HiZTexture.height));
184
+ } else {
185
+ bindGroup.setValue('ssrStride', ctx.camera.ssrStride);
186
+ bindGroup.setValue('targetSize', new Vector4(device.getDrawingBufferWidth(), device.getDrawingBufferHeight(), sceneDepthTexture.width, sceneDepthTexture.height));
187
+ }
188
+ bindGroup.setValue('flip', this.needFlip(device) ? 1 : 0);
189
+ bindGroup.setValue('srgbOut', srgbOut ? 1 : 0);
190
+ device.setProgram(program);
191
+ device.setBindGroup(0, bindGroup);
192
+ this.drawFullscreenQuad(this._getZTestGreaterRenderState(ctx));
193
+ }
194
+ /** @internal */ debugTexture(tex, label) {
195
+ let fb = this._debugFrameBuffer[label];
196
+ if (!fb || fb.getWidth() !== tex.width || fb.getHeight() !== tex.height) {
197
+ fb?.getColorAttachments()[0]?.dispose();
198
+ fb?.dispose();
199
+ fb = tex.device.createFrameBuffer([
200
+ tex.device.createTexture2D(tex.format, tex.width, tex.height, {
201
+ samplerOptions: {
202
+ mipFilter: 'none'
203
+ }
204
+ })
205
+ ], null);
206
+ fb.getColorAttachments()[0].name = label ?? 'SSR_Debug';
207
+ this._debugFrameBuffer[label] = fb;
208
+ }
209
+ copyTexture(tex, fb, fetchSampler('clamp_nearest_nomip'));
210
+ }
211
+ /** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
212
+ const device = ctx.device;
213
+ device.pushDeviceStates();
214
+ copyTexture(inputColorTexture, device.getFramebuffer(), fetchSampler('clamp_nearest_nomip'), this._getZTestEqualRenderState(ctx));
215
+ const intersectFramebuffer = device.pool.fetchTemporalFramebuffer(false, inputColorTexture.width, inputColorTexture.height, 'rgba16f', ctx.depthTexture, false);
216
+ const pingpongFramebuffer = [
217
+ device.pool.fetchTemporalFramebuffer(false, inputColorTexture.width, inputColorTexture.height, 'rgba16f', ctx.depthTexture, false),
218
+ device.pool.fetchTemporalFramebuffer(false, inputColorTexture.width, inputColorTexture.height, 'rgba16f', ctx.depthTexture, false)
219
+ ];
220
+ device.setFramebuffer(intersectFramebuffer);
221
+ this.intersect(ctx, inputColorTexture, sceneDepthTexture, true, false);
222
+ const intersectTex = intersectFramebuffer.getColorAttachments()[0];
223
+ device.setFramebuffer(pingpongFramebuffer[0]);
224
+ this.resolve(ctx, inputColorTexture, sceneDepthTexture, intersectTex);
225
+ if (ctx.camera.ssrBlurScale > 0 && ctx.camera.ssrBlurKernelSize > 0) {
226
+ const blurSizeScale = 255 * ctx.camera.ssrBlurScale;
227
+ const kernelRadius = Math.max(1, ctx.camera.ssrBlurKernelSize >> 0) - 1 >> 1;
228
+ const stdDev = ctx.camera.ssrBlurStdDev;
229
+ const depthCutoff = ctx.camera.ssrBlurDepthCutoff;
230
+ const blitterH = SSR._blurBlitterH = SSR._blurBlitterH ?? new BilateralBlurBlitter(false);
231
+ blitterH.renderStates = this._getZTestGreaterRenderState(ctx);
232
+ this.blurPass(ctx, blitterH, intersectTex, 2, blurSizeScale, kernelRadius, stdDev, depthCutoff, pingpongFramebuffer[0], pingpongFramebuffer[1]);
233
+ const blitterV = SSR._blurBlitterV = SSR._blurBlitterV ?? new BilateralBlurBlitter(true);
234
+ blitterV.renderStates = this._getZTestGreaterRenderState(ctx);
235
+ this.blurPass(ctx, blitterV, intersectTex, 2, blurSizeScale, kernelRadius, stdDev, depthCutoff, pingpongFramebuffer[1], pingpongFramebuffer[0]);
236
+ }
237
+ device.popDeviceStates();
238
+ this.combine(ctx, inputColorTexture, pingpongFramebuffer[0].getColorAttachments()[0], srgbOutput);
239
+ device.pool.releaseFrameBuffer(intersectFramebuffer);
240
+ device.pool.releaseFrameBuffer(pingpongFramebuffer[0]);
241
+ device.pool.releaseFrameBuffer(pingpongFramebuffer[1]);
242
+ }
243
+ /** @internal */ _getZTestGreaterRenderState(ctx) {
244
+ if (!SSR._renderStateZTestGreater) {
245
+ SSR._renderStateZTestGreater = ctx.device.createRenderStateSet();
246
+ SSR._renderStateZTestGreater.useRasterizerState().setCullMode('none');
247
+ SSR._renderStateZTestGreater.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('gt');
248
+ }
249
+ return SSR._renderStateZTestGreater;
250
+ }
251
+ /** @internal */ _getZTestEqualRenderState(ctx) {
252
+ if (!SSR._renderStateZTestEqual) {
253
+ SSR._renderStateZTestEqual = ctx.device.createRenderStateSet();
254
+ SSR._renderStateZTestEqual.useRasterizerState().setCullMode('none');
255
+ SSR._renderStateZTestEqual.useDepthState().enableTest(true).enableWrite(false).setCompareFunc('eq');
256
+ }
257
+ return SSR._renderStateZTestEqual;
258
+ }
259
+ /** @internal */ _createCombineProgrm(ctx) {
260
+ return ctx.device.buildRenderProgram({
261
+ vertex (pb) {
262
+ this.flip = pb.int().uniform(0);
263
+ this.$inputs.pos = pb.vec2().attrib('position');
264
+ this.$outputs.uv = pb.vec2();
265
+ pb.main(function() {
266
+ this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
267
+ this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
268
+ this.$if(pb.notEqual(this.flip, 0), function() {
269
+ this.$builtins.position.y = pb.neg(this.$builtins.position.y);
270
+ });
271
+ });
272
+ },
273
+ fragment (pb) {
274
+ this.colorTex = pb.tex2D().uniform(0);
275
+ this.reflectanceTex = pb.tex2D().uniform(0);
276
+ this.roughnessTex = pb.tex2D().uniform(0);
277
+ this.targetSize = pb.vec4().uniform(0);
278
+ this.srgbOut = pb.int().uniform(0);
279
+ this.$outputs.outColor = pb.vec4();
280
+ pb.func('resolveSample', [
281
+ pb.vec3('sceneColor'),
282
+ pb.vec3('reflectance'),
283
+ pb.vec4('roughnessValue')
284
+ ], function() {
285
+ this.$l.r = pb.div(this.reflectance, pb.add(this.reflectance, pb.vec3(1)));
286
+ this.$l.strength = pb.clamp(this.roughnessValue.rgb, pb.vec3(0), pb.vec3(1));
287
+ this.color = pb.add(pb.mul(this.r, this.strength), pb.mul(this.sceneColor, pb.sub(pb.vec3(1), this.strength)));
288
+ this.$return(this.color);
289
+ });
290
+ pb.main(function() {
291
+ this.$l.screenUV = pb.div(pb.vec2(this.$builtins.fragCoord.xy), this.targetSize.xy);
292
+ this.$l.reflectance = pb.textureSampleLevel(this.reflectanceTex, this.screenUV, 0).rgb;
293
+ this.$l.sceneColor = pb.textureSampleLevel(this.colorTex, this.screenUV, 0).rgb;
294
+ this.$l.roughnessInfo = pb.textureSampleLevel(this.roughnessTex, this.screenUV, 0);
295
+ this.combined = this.resolveSample(this.sceneColor, this.reflectance, this.roughnessInfo);
296
+ this.$outputs.outColor = pb.vec4(this.combined, 1);
297
+ this.$if(pb.equal(this.srgbOut, 0), function() {
298
+ this.$outputs.outColor = pb.vec4(this.combined, 1);
299
+ }).$else(function() {
300
+ this.$outputs.outColor = pb.vec4(linearToGamma(this, this.combined), 1);
301
+ });
302
+ });
303
+ }
304
+ });
305
+ }
306
+ /** @internal */ _createResolveProgram(ctx) {
307
+ return ctx.device.buildRenderProgram({
308
+ vertex (pb) {
309
+ this.flip = pb.int().uniform(0);
310
+ this.$inputs.pos = pb.vec2().attrib('position');
311
+ this.$outputs.uv = pb.vec2();
312
+ if (ctx.env.light.envLight) {
313
+ ctx.env.light.envLight.initShaderBindings(pb);
314
+ }
315
+ pb.main(function() {
316
+ this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
317
+ this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
318
+ this.$if(pb.notEqual(this.flip, 0), function() {
319
+ this.$builtins.position.y = pb.neg(this.$builtins.position.y);
320
+ });
321
+ });
322
+ },
323
+ fragment (pb) {
324
+ this.colorTex = pb.tex2D().uniform(0);
325
+ this.intersectTex = pb.tex2D().uniform(0);
326
+ this.roughnessTex = pb.tex2D().uniform(0);
327
+ this.normalTex = pb.tex2D().uniform(0);
328
+ this.depthTex = pb.tex2D().uniform(0);
329
+ this.cameraNearFar = pb.vec2().uniform(0);
330
+ this.targetSize = pb.vec4().uniform(0);
331
+ this.viewMatrix = pb.mat4().uniform(0);
332
+ this.invViewMatrix = pb.mat4().uniform(0);
333
+ this.invProjMatrix = pb.mat4().uniform(0);
334
+ if (ctx.env.light.envLight) {
335
+ this.envLightStrength = pb.float().uniform(0);
336
+ ctx.env.light.envLight.initShaderBindings(pb);
337
+ }
338
+ this.$outputs.outColor = pb.vec4();
339
+ pb.func('getPosition', [
340
+ pb.vec2('uv'),
341
+ pb.mat4('mat')
342
+ ], function() {
343
+ this.$l.linearDepth = sampleLinearDepth(this, this.depthTex, this.uv, 0);
344
+ this.$l.nonLinearDepth = pb.div(pb.sub(pb.div(this.cameraNearFar.x, this.linearDepth), this.cameraNearFar.y), pb.sub(this.cameraNearFar.x, this.cameraNearFar.y));
345
+ this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.nonLinearDepth, 0, 1), 2), 1), 1);
346
+ this.$l.wPos = pb.mul(this.mat, this.clipSpacePos);
347
+ this.$return(pb.vec4(pb.div(this.wPos.xyz, this.wPos.w), this.linearDepth));
348
+ });
349
+ pb.func('resolveSample', [
350
+ pb.vec3('sceneColor'),
351
+ pb.vec3('reflectance'),
352
+ pb.vec4('roughnessValue')
353
+ ], function() {
354
+ this.$l.r = pb.div(this.reflectance, pb.add(this.reflectance, pb.vec3(1)));
355
+ this.$l.strength = pb.clamp(this.roughnessValue.rgb, pb.vec3(0), pb.vec3(1));
356
+ this.color = pb.add(pb.mul(this.r, this.strength), pb.mul(this.sceneColor, pb.sub(pb.vec3(1), this.strength)));
357
+ this.$return(this.color);
358
+ });
359
+ pb.func('resolveEnvRadiance', [
360
+ pb.vec2('uv'),
361
+ pb.vec4('roughnessInfo')
362
+ ], function() {
363
+ if (!ctx.env.light.envLight) {
364
+ this.$return(pb.vec3(0));
365
+ return;
366
+ }
367
+ this.$l.pos = this.getPosition(this.uv, this.invProjMatrix);
368
+ this.$if(pb.greaterThanEqual(this.pos.w, 1), function() {
369
+ this.$return(pb.vec3(0));
370
+ });
371
+ this.$l.roughness = this.roughnessInfo.a;
372
+ this.$l.viewPos = this.pos.xyz;
373
+ this.$l.worldNormal = pb.sub(pb.mul(pb.textureSampleLevel(this.normalTex, this.uv, 0).rgb, 2), pb.vec3(1));
374
+ this.$l.viewVec = pb.normalize(this.viewPos);
375
+ this.$l.viewNormal = pb.mul(this.viewMatrix, pb.vec4(this.worldNormal, 0)).xyz;
376
+ this.$l.reflectVec = pb.add(pb.reflect(this.viewVec, this.viewNormal), SSR_calcJitter(this, this.viewPos, this.roughness));
377
+ this.$l.reflectVecW = pb.mul(this.invViewMatrix, pb.vec4(this.reflectVec, 0)).xyz;
378
+ this.$l.roughness2 = pb.float(0);
379
+ this.$l.env = pb.mul(ctx.env.light.envLight.getRadiance(this, this.reflectVecW, this.roughness2), this.envLightStrength);
380
+ this.$return(pb.min(this.env, pb.vec3(1)));
381
+ });
382
+ pb.func('resolveReflectance', [
383
+ pb.vec2('uv'),
384
+ pb.vec3('reflectSceneColor'),
385
+ pb.vec4('roughnessInfo'),
386
+ pb.float('alpha')
387
+ ], function() {
388
+ this.$l.env = this.resolveEnvRadiance(this.uv, this.roughnessInfo);
389
+ this.$l.reflectance = pb.mix(this.env, this.reflectSceneColor, this.alpha);
390
+ this.$return(this.reflectance);
391
+ });
392
+ pb.main(function() {
393
+ this.$l.screenUV = pb.div(pb.vec2(this.$builtins.fragCoord.xy), this.targetSize.xy);
394
+ this.$l.intersectSample = pb.textureSampleLevel(this.intersectTex, this.screenUV, 0);
395
+ this.$l.roughnessInfo = pb.textureSampleLevel(this.roughnessTex, this.screenUV, 0);
396
+ this.$l.reflectance = pb.vec3();
397
+ this.$if(pb.greaterThan(this.intersectSample.w, 0), function() {
398
+ this.$l.indirectIntersectSample = pb.textureSampleLevel(this.intersectTex, this.intersectSample.xy, 0);
399
+ this.$l.indirectRoughnessInfo = pb.textureSampleLevel(this.roughnessTex, this.intersectSample.xy, 0);
400
+ this.$l.indirectReflectance = pb.vec3();
401
+ this.$if(pb.greaterThan(this.indirectIntersectSample.w, 0), function() {
402
+ this.$l.indirectReflectSceneColor = pb.textureSampleLevel(this.colorTex, this.indirectIntersectSample.xy, 0).rgb;
403
+ this.indirectReflectance = this.resolveReflectance(this.intersectSample.xy, this.indirectReflectSceneColor, this.indirectRoughnessInfo, this.indirectIntersectSample.w);
404
+ }).$else(function() {
405
+ this.indirectReflectance = this.resolveEnvRadiance(this.intersectSample.xy, this.indirectRoughnessInfo);
406
+ });
407
+ this.$l.reflectSceneColor = pb.textureSampleLevel(this.colorTex, this.intersectSample.xy, 0).rgb;
408
+ this.$l.reflectSceneColor = this.resolveSample(this.reflectSceneColor, this.indirectReflectance, this.indirectRoughnessInfo);
409
+ this.reflectance = this.resolveReflectance(this.screenUV, this.reflectSceneColor, this.roughnessInfo, this.intersectSample.w);
410
+ }).$else(function() {
411
+ this.reflectance = this.resolveEnvRadiance(this.screenUV, this.roughnessInfo);
412
+ });
413
+ this.$outputs.outColor = pb.vec4(this.reflectance, this.intersectSample.z);
414
+ });
415
+ }
416
+ });
417
+ }
418
+ /** @internal */ _createIntersectProgram(ctx, blur) {
419
+ return ctx.device.buildRenderProgram({
420
+ vertex (pb) {
421
+ this.flip = pb.int().uniform(0);
422
+ this.$inputs.pos = pb.vec2().attrib('position');
423
+ this.$outputs.uv = pb.vec2();
424
+ if (!blur && ctx.env.light.envLight) {
425
+ ctx.env.light.envLight.initShaderBindings(pb);
426
+ }
427
+ pb.main(function() {
428
+ this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
429
+ this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
430
+ this.$if(pb.notEqual(this.flip, 0), function() {
431
+ this.$builtins.position.y = pb.neg(this.$builtins.position.y);
432
+ });
433
+ });
434
+ },
435
+ fragment (pb) {
436
+ if (!blur) {
437
+ this.colorTex = pb.tex2D().uniform(0);
438
+ if (ctx.env.light.envLight) {
439
+ this.envLightStrength = pb.float().uniform(0);
440
+ ctx.env.light.envLight.initShaderBindings(pb);
441
+ }
442
+ }
443
+ this.roughnessTex = pb.tex2D().uniform(0);
444
+ this.normalTex = pb.tex2D().uniform(0);
445
+ this.depthTex = pb.tex2D().uniform(0);
446
+ this.cameraNearFar = pb.vec2().uniform(0);
447
+ this.cameraPos = pb.vec3().uniform(0);
448
+ this.invProjMatrix = pb.mat4().uniform(0);
449
+ this.projMatrix = pb.mat4().uniform(0);
450
+ this.viewMatrix = pb.mat4().uniform(0);
451
+ this.invViewMatrix = pb.mat4().uniform(0);
452
+ this.ssrParams = pb.vec4().uniform(0);
453
+ this.ssrMaxRoughness = pb.float().uniform(0);
454
+ this.targetSize = pb.vec4().uniform(0);
455
+ if (ctx.HiZTexture) {
456
+ this.hizTex = pb.tex2D().uniform(0);
457
+ this.depthMipLevels = pb.int().uniform(0);
458
+ } else {
459
+ this.ssrStride = pb.float().uniform(0);
460
+ }
461
+ this.srgbOut = pb.int().uniform(0);
462
+ this.$outputs.outColor = pb.vec4();
463
+ pb.func('getPosition', [
464
+ pb.vec2('uv'),
465
+ pb.mat4('mat')
466
+ ], function() {
467
+ this.$l.linearDepth = sampleLinearDepth(this, this.depthTex, this.uv, 0);
468
+ this.$l.nonLinearDepth = pb.div(pb.sub(pb.div(this.cameraNearFar.x, this.linearDepth), this.cameraNearFar.y), pb.sub(this.cameraNearFar.x, this.cameraNearFar.y));
469
+ this.$l.clipSpacePos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.nonLinearDepth, 0, 1), 2), 1), 1);
470
+ this.$l.wPos = pb.mul(this.mat, this.clipSpacePos);
471
+ this.$return(pb.vec4(pb.div(this.wPos.xyz, this.wPos.w), this.linearDepth));
472
+ });
473
+ pb.main(function() {
474
+ this.$l.screenUV = pb.div(pb.vec2(this.$builtins.fragCoord.xy), this.targetSize.xy);
475
+ if (!blur) {
476
+ this.$l.sceneColor = pb.textureSampleLevel(this.colorTex, this.screenUV, 0).rgb;
477
+ }
478
+ this.$l.roughnessValue = pb.textureSampleLevel(this.roughnessTex, this.screenUV, 0);
479
+ this.$l.pos = this.getPosition(this.screenUV, this.invProjMatrix);
480
+ this.$l.linearDepth = this.pos.w;
481
+ this.$l.roughness = this.roughnessValue.a;
482
+ this.$l.color = pb.vec3(0);
483
+ this.$l.a = pb.float();
484
+ this.$if(pb.greaterThanEqual(this.linearDepth, 1), function() {
485
+ if (!blur) {
486
+ this.color = this.sceneColor;
487
+ this.a = 1;
488
+ }
489
+ }).$else(function() {
490
+ this.$l.viewPos = this.pos.xyz;
491
+ this.$l.worldNormal = pb.sub(pb.mul(pb.textureSampleLevel(this.normalTex, this.screenUV, 0).rgb, 2), pb.vec3(1));
492
+ this.$l.viewVec = pb.normalize(this.viewPos);
493
+ this.$l.viewNormal = pb.mul(this.viewMatrix, pb.vec4(this.worldNormal, 0)).xyz;
494
+ this.$l.reflectVec = pb.add(pb.reflect(this.viewVec, this.viewNormal), SSR_calcJitter(this, this.viewPos, this.roughness));
495
+ this.$l.hitInfo = pb.vec4(0);
496
+ this.$if(pb.lessThan(this.roughness, this.ssrMaxRoughness), function() {
497
+ this.hitInfo = ctx.HiZTexture ? screenSpaceRayTracing_HiZ(this, this.viewPos, this.reflectVec, this.viewMatrix, this.projMatrix, this.invProjMatrix, this.cameraNearFar, this.depthMipLevels, this.ssrParams.y, this.ssrParams.z, this.targetSize, this.hizTex, this.normalTex) : screenSpaceRayTracing_Linear2D(this, this.viewPos, this.reflectVec, this.viewMatrix, this.projMatrix, this.invProjMatrix, this.cameraNearFar, this.ssrParams.x, this.ssrParams.y, this.ssrParams.z, this.ssrStride, this.targetSize, this.depthTex, this.normalTex, !!ctx.primaryCamera.ssrCalcThickness);
498
+ });
499
+ if (blur) {
500
+ this.blurRadius = pb.float(0);
501
+ this.$if(pb.greaterThan(this.roughness, 0.001), function() {
502
+ this.$l.coneAngle = pb.mul(pb.min(this.roughness, 0.999), Math.PI * 0.5);
503
+ this.$l.coneLen = this.$choice(pb.greaterThan(this.hitInfo.w, 0), this.hitInfo.z, pb.min(this.targetSize.z, this.targetSize.w));
504
+ this.$l.opLen = pb.mul(pb.tan(this.coneAngle), this.coneLen, 2);
505
+ this.$l.a2 = pb.mul(this.opLen, this.opLen);
506
+ this.$l.fh2 = pb.mul(this.coneLen, this.coneLen, 4);
507
+ this.blurRadius = pb.div(pb.mul(this.opLen, pb.sub(pb.sqrt(pb.add(this.a2, this.fh2)), this.opLen)), pb.mul(this.coneLen, 4));
508
+ });
509
+ this.a = this.hitInfo.w;
510
+ this.color = pb.vec3(this.hitInfo.xy, pb.clamp(pb.div(this.blurRadius, 255), 0, 1));
511
+ } else {
512
+ if (ctx.env.light.envLight) {
513
+ this.$l.reflectVecW = pb.mul(this.invViewMatrix, pb.vec4(this.reflectVec, 0)).xyz;
514
+ this.$l.env = pb.mul(ctx.env.light.envLight.getRadiance(this, this.reflectVecW, this.roughness), this.envLightStrength);
515
+ } else {
516
+ this.$l.env = pb.vec3(0);
517
+ }
518
+ this.$l.reflectance = pb.mix(this.env, pb.textureSampleLevel(this.colorTex, this.hitInfo.xy, 0).rgb, this.hitInfo.w);
519
+ this.reflectance = pb.div(this.reflectance, pb.add(this.reflectance, pb.vec3(1)));
520
+ this.$l.strength = pb.clamp(this.roughnessValue.rgb, pb.vec3(0), pb.vec3(1));
521
+ this.color = pb.add(pb.mul(this.reflectance, this.strength), pb.mul(this.sceneColor, pb.sub(pb.vec3(1), this.strength)));
522
+ }
523
+ });
524
+ this.$if(pb.equal(this.srgbOut, 0), function() {
525
+ this.$outputs.outColor = pb.vec4(this.color, this.a);
526
+ }).$else(function() {
527
+ this.$outputs.outColor = pb.vec4(linearToGamma(this, this.color), this.a);
528
+ });
529
+ });
530
+ }
531
+ });
532
+ }
533
+ }
534
+
535
+ export { SSR };
536
+ //# sourceMappingURL=ssr.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lit.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"ssr.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,11 +1,12 @@
1
1
  import { AbstractPostEffect } from './posteffect.js';
2
2
  import { linearToGamma } from '../shaders/misc.js';
3
+ import { fetchSampler } from '../utility/misc.js';
3
4
 
4
5
  /**
5
6
  * The tonemap post effect
6
7
  * @public
7
8
  */ class Tonemap extends AbstractPostEffect {
8
- static _nearestSampler = null;
9
+ static className = 'Tonemap';
9
10
  static _programTonemap = null;
10
11
  _bindgroupTonemap;
11
12
  _exposure;
@@ -38,7 +39,7 @@ import { linearToGamma } from '../shaders/misc.js';
38
39
  this._bindgroupTonemap.setValue('srgbOut', sRGBOutput ? 1 : 0);
39
40
  this._bindgroupTonemap.setValue('exposure', this._exposure);
40
41
  this._bindgroupTonemap.setValue('flip', this.needFlip(device) ? 1 : 0);
41
- this._bindgroupTonemap.setTexture('tex', inputColorTexture, Tonemap._nearestSampler);
42
+ this._bindgroupTonemap.setTexture('tex', inputColorTexture, fetchSampler('clamp_nearest_nomip'));
42
43
  device.setProgram(Tonemap._programTonemap);
43
44
  device.setBindGroup(0, this._bindgroupTonemap);
44
45
  this.drawFullscreenQuad();
@@ -90,15 +91,6 @@ import { linearToGamma } from '../shaders/misc.js';
90
91
  if (!this._bindgroupTonemap) {
91
92
  this._bindgroupTonemap = device.createBindGroup(Tonemap._programTonemap.bindGroupLayouts[0]);
92
93
  }
93
- if (!Tonemap._nearestSampler) {
94
- Tonemap._nearestSampler = device.createSampler({
95
- magFilter: 'nearest',
96
- minFilter: 'nearest',
97
- mipFilter: 'none',
98
- addressU: 'clamp',
99
- addressV: 'clamp'
100
- });
101
- }
102
94
  }
103
95
  /** {@inheritDoc AbstractPostEffect.dispose} */ dispose() {
104
96
  super.dispose();
@@ -1 +1 @@
1
- {"version":3,"file":"tonemap.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"tonemap.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}