@zephyr3d/scene 0.5.0 → 0.6.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.
Files changed (198) hide show
  1. package/dist/animation/animationset.js +37 -37
  2. package/dist/animation/morphtrack.js +7 -5
  3. package/dist/animation/morphtrack.js.map +1 -1
  4. package/dist/animation/skeleton.js +11 -9
  5. package/dist/animation/skeleton.js.map +1 -1
  6. package/dist/asset/assetmanager.js +2 -2
  7. package/dist/asset/loaders/gltf/gltf_loader.js +7 -3
  8. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  9. package/dist/asset/loaders/image/webimage_loader.js +16 -0
  10. package/dist/asset/loaders/image/webimage_loader.js.map +1 -1
  11. package/dist/asset/model.js +3 -9
  12. package/dist/asset/model.js.map +1 -1
  13. package/dist/blitter/bilateralblur.js +222 -0
  14. package/dist/{render/temporalcache.js.map → blitter/bilateralblur.js.map} +1 -1
  15. package/dist/blitter/blitter.js +7 -1
  16. package/dist/blitter/blitter.js.map +1 -1
  17. package/dist/blitter/depthlimitedgaussion.js +96 -39
  18. package/dist/blitter/depthlimitedgaussion.js.map +1 -1
  19. package/dist/blitter/gaussianblur.js +21 -21
  20. package/dist/camera/camera.js +142 -1
  21. package/dist/camera/camera.js.map +1 -1
  22. package/dist/index.d.ts +1178 -745
  23. package/dist/index.js +11 -6
  24. package/dist/index.js.map +1 -1
  25. package/dist/material/blinn.js +9 -3
  26. package/dist/material/blinn.js.map +1 -1
  27. package/dist/material/lambert.js +6 -2
  28. package/dist/material/lambert.js.map +1 -1
  29. package/dist/material/material.js +3 -1
  30. package/dist/material/material.js.map +1 -1
  31. package/dist/material/meshmaterial.js +73 -33
  32. package/dist/material/meshmaterial.js.map +1 -1
  33. package/dist/material/mixins/albedocolor.js +5 -4
  34. package/dist/material/mixins/albedocolor.js.map +1 -1
  35. package/dist/material/mixins/lightmodel/blinnphong.js +17 -7
  36. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  37. package/dist/material/mixins/lightmodel/lambert.js +5 -5
  38. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +13 -4
  39. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  40. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +13 -4
  41. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  42. package/dist/material/mixins/pbr/common.js +27 -15
  43. package/dist/material/mixins/pbr/common.js.map +1 -1
  44. package/dist/material/pbrmr.js +14 -3
  45. package/dist/material/pbrmr.js.map +1 -1
  46. package/dist/material/pbrsg.js +14 -3
  47. package/dist/material/pbrsg.js.map +1 -1
  48. package/dist/material/shader/helper.js +36 -21
  49. package/dist/material/shader/helper.js.map +1 -1
  50. package/dist/posteffect/bloom.js +1 -10
  51. package/dist/posteffect/bloom.js.map +1 -1
  52. package/dist/posteffect/compositor.js +43 -24
  53. package/dist/posteffect/compositor.js.map +1 -1
  54. package/dist/posteffect/fxaa.js +3 -11
  55. package/dist/posteffect/fxaa.js.map +1 -1
  56. package/dist/posteffect/grayscale.js +3 -11
  57. package/dist/posteffect/grayscale.js.map +1 -1
  58. package/dist/posteffect/posteffect.js +4 -0
  59. package/dist/posteffect/posteffect.js.map +1 -1
  60. package/dist/posteffect/sao.js +44 -24
  61. package/dist/posteffect/sao.js.map +1 -1
  62. package/dist/posteffect/ssr.js +536 -0
  63. package/dist/{material/lit.js.map → posteffect/ssr.js.map} +1 -1
  64. package/dist/posteffect/tonemap.js +3 -11
  65. package/dist/posteffect/tonemap.js.map +1 -1
  66. package/dist/posteffect/water.js +305 -337
  67. package/dist/posteffect/water.js.map +1 -1
  68. package/dist/render/abuffer_oit.js +2 -2
  69. package/dist/render/clipmap.js +16 -19
  70. package/dist/render/clipmap.js.map +1 -1
  71. package/dist/render/cull_visitor.js +5 -3
  72. package/dist/render/cull_visitor.js.map +1 -1
  73. package/dist/render/depthpass.js +17 -1
  74. package/dist/render/depthpass.js.map +1 -1
  75. package/dist/render/drawable_mixin.js +25 -19
  76. package/dist/render/drawable_mixin.js.map +1 -1
  77. package/dist/render/envlight.js +4 -2
  78. package/dist/render/envlight.js.map +1 -1
  79. package/dist/render/fft_wavegenerator.js +989 -0
  80. package/dist/{shaders/framework.js.map → render/fft_wavegenerator.js.map} +1 -1
  81. package/dist/render/gerstner_wavegenerator.js +265 -0
  82. package/dist/{material/standard.js.map → render/gerstner_wavegenerator.js.map} +1 -1
  83. package/dist/render/globalbindgroup_allocator.js +2 -1
  84. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  85. package/dist/render/hzb.js +273 -0
  86. package/dist/{material/terrainlightmodel.js.map → render/hzb.js.map} +1 -1
  87. package/dist/render/lightpass.js +35 -3
  88. package/dist/render/lightpass.js.map +1 -1
  89. package/dist/render/objectcolorpass.js +2 -1
  90. package/dist/render/objectcolorpass.js.map +1 -1
  91. package/dist/render/render_queue.js +72 -52
  92. package/dist/render/render_queue.js.map +1 -1
  93. package/dist/render/renderbundle_wrapper.js +79 -0
  94. package/dist/render/renderbundle_wrapper.js.map +1 -1
  95. package/dist/render/renderer.js +75 -36
  96. package/dist/render/renderer.js.map +1 -1
  97. package/dist/render/renderpass.js +16 -13
  98. package/dist/render/renderpass.js.map +1 -1
  99. package/dist/render/shadowmap_pass.js +6 -0
  100. package/dist/render/shadowmap_pass.js.map +1 -1
  101. package/dist/render/sky.js +12 -13
  102. package/dist/render/sky.js.map +1 -1
  103. package/dist/render/watermesh.js +94 -828
  104. package/dist/render/watermesh.js.map +1 -1
  105. package/dist/render/wavegenerator.js +8 -0
  106. package/dist/render/wavegenerator.js.map +1 -0
  107. package/dist/scene/batchgroup.js +60 -14
  108. package/dist/scene/batchgroup.js.map +1 -1
  109. package/dist/scene/environment.js +2 -2
  110. package/dist/scene/graph_node.js +0 -5
  111. package/dist/scene/graph_node.js.map +1 -1
  112. package/dist/scene/light.js +5 -5
  113. package/dist/scene/mesh.js +34 -18
  114. package/dist/scene/mesh.js.map +1 -1
  115. package/dist/scene/octree.js +5 -2
  116. package/dist/scene/octree.js.map +1 -1
  117. package/dist/scene/raycast_visitor.js +4 -2
  118. package/dist/scene/raycast_visitor.js.map +1 -1
  119. package/dist/scene/scene.js +1 -1
  120. package/dist/scene/scene_node.js +9 -5
  121. package/dist/scene/scene_node.js.map +1 -1
  122. package/dist/scene/terrain/grass.js +3 -4
  123. package/dist/scene/terrain/grass.js.map +1 -1
  124. package/dist/scene/terrain/heightfield.js +135 -53
  125. package/dist/scene/terrain/heightfield.js.map +1 -1
  126. package/dist/scene/terrain/patch.js +3 -4
  127. package/dist/scene/terrain/patch.js.map +1 -1
  128. package/dist/scene/terrain/terrain.js +1 -1
  129. package/dist/scene/xform.js +7 -9
  130. package/dist/scene/xform.js.map +1 -1
  131. package/dist/shaders/misc.js +10 -1
  132. package/dist/shaders/misc.js.map +1 -1
  133. package/dist/shaders/noise.js +81 -16
  134. package/dist/shaders/noise.js.map +1 -1
  135. package/dist/shaders/shadow.js +1 -9
  136. package/dist/shaders/shadow.js.map +1 -1
  137. package/dist/shaders/ssr.js +442 -0
  138. package/dist/{material/terrainmat.js.map → shaders/ssr.js.map} +1 -1
  139. package/dist/shaders/water.js +377 -250
  140. package/dist/shaders/water.js.map +1 -1
  141. package/dist/shadow/shadowmapper.js +11 -11
  142. package/dist/shapes/cylinder.js +6 -5
  143. package/dist/shapes/cylinder.js.map +1 -1
  144. package/dist/utility/bounding_volume.js +1 -53
  145. package/dist/utility/bounding_volume.js.map +1 -1
  146. package/dist/utility/misc.js +93 -0
  147. package/dist/utility/misc.js.map +1 -0
  148. package/dist/utility/shprojection.js +2 -7
  149. package/dist/utility/shprojection.js.map +1 -1
  150. package/dist/utility/textures/ggxlut.js +213 -0
  151. package/dist/utility/textures/ggxlut.js.map +1 -0
  152. package/dist/utility/textures/gradientnoise.js +61 -0
  153. package/dist/utility/textures/gradientnoise.js.map +1 -0
  154. package/dist/utility/textures/randomnoise.js +41 -0
  155. package/dist/utility/textures/randomnoise.js.map +1 -0
  156. package/dist/values.js +8 -1
  157. package/dist/values.js.map +1 -1
  158. package/package.json +4 -8
  159. package/dist/animation/usertrack.js +0 -47
  160. package/dist/animation/usertrack.js.map +0 -1
  161. package/dist/material/grassmat.js +0 -127
  162. package/dist/material/grassmat.js.map +0 -1
  163. package/dist/material/lightmodel.js +0 -2074
  164. package/dist/material/lightmodel.js.map +0 -1
  165. package/dist/material/lit.js +0 -578
  166. package/dist/material/mixins/pbr/metallicroughness.js +0 -126
  167. package/dist/material/mixins/pbr/metallicroughness.js.map +0 -1
  168. package/dist/material/mixins/pbr/specularglossness.js +0 -104
  169. package/dist/material/mixins/pbr/specularglossness.js.map +0 -1
  170. package/dist/material/pbr.js +0 -27
  171. package/dist/material/pbr.js.map +0 -1
  172. package/dist/material/standard.js +0 -282
  173. package/dist/material/terrainlightmodel.js +0 -259
  174. package/dist/material/terrainmat.js +0 -357
  175. package/dist/render/depth_pass.js +0 -47
  176. package/dist/render/depth_pass.js.map +0 -1
  177. package/dist/render/forward.js +0 -186
  178. package/dist/render/forward.js.map +0 -1
  179. package/dist/render/forward_pass.js +0 -137
  180. package/dist/render/forward_pass.js.map +0 -1
  181. package/dist/render/helper.js +0 -38
  182. package/dist/render/helper.js.map +0 -1
  183. package/dist/render/objectpool.js +0 -295
  184. package/dist/render/objectpool.js.map +0 -1
  185. package/dist/render/renderscheme.js +0 -61
  186. package/dist/render/renderscheme.js.map +0 -1
  187. package/dist/render/temporalcache.js +0 -222
  188. package/dist/scene/model.js +0 -111
  189. package/dist/scene/model.js.map +0 -1
  190. package/dist/scene/octree_update_visitor.js +0 -20
  191. package/dist/scene/octree_update_visitor.js.map +0 -1
  192. package/dist/shaders/builtins.js +0 -110
  193. package/dist/shaders/builtins.js.map +0 -1
  194. package/dist/shaders/framework.js +0 -723
  195. package/dist/shaders/lighting.js +0 -335
  196. package/dist/shaders/lighting.js.map +0 -1
  197. package/dist/utility/sheenlut.js +0 -196
  198. package/dist/utility/sheenlut.js.map +0 -1
@@ -3,6 +3,7 @@ import { mixinTextureProps } from '../texture.js';
3
3
  import { mixinPBRCommon } from '../pbr/common.js';
4
4
  import { Vector4 } from '@zephyr3d/base';
5
5
  import { mixinLight } from '../lit.js';
6
+ import { ShaderHelper } from '../../shader/helper.js';
6
7
 
7
8
  /**
8
9
  * PBRSpecularGlossiness mixin
@@ -58,7 +59,7 @@ import { mixinLight } from '../lit.js';
58
59
  bindGroup.setValue('zGlossinessFactor', this._glossinessFactor);
59
60
  }
60
61
  }
61
- PBRLight(scope, worldPos, normal, viewVec, albedo, TBN) {
62
+ PBRLight(scope, worldPos, normal, viewVec, albedo, TBN, outRoughness) {
62
63
  const pb = scope.$builder;
63
64
  const funcName = 'Z_PBRSpecularGlossinessLight';
64
65
  const that = this;
@@ -67,12 +68,19 @@ import { mixinLight } from '../lit.js';
67
68
  pb.vec3('normal'),
68
69
  pb.mat3('TBN'),
69
70
  pb.vec3('viewVec'),
70
- pb.vec4('albedo')
71
+ pb.vec4('albedo'),
72
+ ...outRoughness ? [
73
+ pb.vec4('outRoughness').out()
74
+ ] : []
71
75
  ], function() {
72
76
  this.$l.pbrData = that.getCommonData(this, this.albedo, this.normal, this.viewVec, this.TBN);
73
77
  this.$l.lightingColor = pb.vec3(0);
74
78
  this.$l.emissiveColor = that.calculateEmissiveColor(this);
75
- that.indirectLighting(this, this.normal, this.viewVec, this.pbrData, this.lightingColor);
79
+ if (outRoughness) {
80
+ that.indirectLighting(this, this.normal, this.viewVec, this.pbrData, this.lightingColor, this.outRoughness);
81
+ } else {
82
+ that.indirectLighting(this, this.normal, this.viewVec, this.pbrData, this.lightingColor);
83
+ }
76
84
  that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, shadow) {
77
85
  this.$l.diffuse = pb.vec3();
78
86
  this.$l.specular = pb.vec3();
@@ -87,7 +95,7 @@ import { mixinLight } from '../lit.js';
87
95
  });
88
96
  this.$return(pb.add(this.lightingColor, this.emissiveColor));
89
97
  });
90
- return pb.getGlobalScope()[funcName](worldPos, normal, TBN, viewVec, albedo);
98
+ return outRoughness ? pb.getGlobalScope()[funcName](worldPos, normal, TBN, viewVec, albedo, outRoughness) : pb.getGlobalScope()[funcName](worldPos, normal, TBN, viewVec, albedo);
91
99
  }
92
100
  calculateCommonData(scope, albedo, normal, viewVec, TBN, data) {
93
101
  super.calculateCommonData(scope, albedo, normal, viewVec, TBN, data);
@@ -100,6 +108,7 @@ import { mixinLight } from '../lit.js';
100
108
  data.roughness = pb.sub(1, scope.zGlossinessFactor);
101
109
  data.f0 = pb.vec4(scope.zSpecularFactor.rgb, this.getF0(scope).a);
102
110
  }
111
+ data.roughness = pb.mul(data.roughness, ShaderHelper.getCameraRoughnessFactor(scope));
103
112
  data.metallic = pb.max(pb.max(data.f0.r, data.f0.g), data.f0.b);
104
113
  data.diffuse = pb.vec4(pb.mul(albedo.rgb, pb.sub(1, data.metallic)), albedo.a);
105
114
  data.specularWeight = 1;
@@ -1 +1 @@
1
- {"version":3,"file":"pbrspecularglossness.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"pbrspecularglossness.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,8 +1,9 @@
1
1
  import { applyMaterialMixins } from '../../meshmaterial.js';
2
2
  import { Vector4, Vector3, Vector2 } from '@zephyr3d/base';
3
- import { getGGXLUT } from '../ggxlut.js';
3
+ import { getGGXLUT } from '../../../utility/textures/ggxlut.js';
4
4
  import { mixinTextureProps } from '../texture.js';
5
5
  import { ShaderHelper } from '../../shader/helper.js';
6
+ import { RENDER_PASS_TYPE_LIGHT } from '../../../values.js';
6
7
 
7
8
  /**
8
9
  * PBR common stuff mixin
@@ -244,7 +245,7 @@ import { ShaderHelper } from '../../shader/helper.js';
244
245
  if (this.clearcoat) {
245
246
  scope.zClearcoatFactor = pb.vec4().uniform(2);
246
247
  }
247
- if (this.transmission) {
248
+ if (this.transmission && this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
248
249
  scope.zTransmissionFactor = pb.float().uniform(2);
249
250
  scope.zThicknessFactor = pb.float().uniform(2);
250
251
  scope.zAttenuationColor = pb.vec3().uniform(2);
@@ -277,7 +278,7 @@ import { ShaderHelper } from '../../shader/helper.js';
277
278
  if (this.clearcoat) {
278
279
  bindGroup.setValue('zClearcoatFactor', this._clearcoatFactor);
279
280
  }
280
- if (this.transmission) {
281
+ if (this.transmission && ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
281
282
  bindGroup.setValue('zTransmissionFactor', this._transmissionFactor);
282
283
  bindGroup.setValue('zThicknessFactor', this._thicknessFactor);
283
284
  bindGroup.setValue('zAttenuationColor', this._attenuationColor);
@@ -317,7 +318,7 @@ import { ShaderHelper } from '../../shader/helper.js';
317
318
  pb.float('ccNoV'),
318
319
  pb.float('ccFresnel')
319
320
  ] : [],
320
- ...this.transmission ? [
321
+ ...this.transmission && this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT ? [
321
322
  pb.float('transmissionFactor'),
322
323
  pb.float('thicknessFactor'),
323
324
  pb.vec3('attenuationColor'),
@@ -378,7 +379,7 @@ import { ShaderHelper } from '../../shader/helper.js';
378
379
  data.ccFactor.y = pb.clamp(pb.mul(data.ccFactor.y, this.sampleClearcoatRoughnessTexture(scope).g), 0, 1);
379
380
  }
380
381
  }
381
- if (this.transmission) {
382
+ if (this.transmission && this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
382
383
  if (this.transmissionTexture) {
383
384
  data.transmissionFactor = pb.mul(this.sampleTransmissionTexture(scope).r, scope.zTransmissionFactor);
384
385
  } else {
@@ -577,7 +578,7 @@ import { ShaderHelper } from '../../shader/helper.js';
577
578
  }
578
579
  this.$l.diffuseBRDF = pb.mul(pb.sub(pb.vec3(1), pb.mul(this.F, this.data.specularWeight)), pb.div(this.data.diffuse.rgb, Math.PI));
579
580
  this.$l.diffuse = pb.mul(this.lightColor, pb.max(this.diffuseBRDF, pb.vec3(0)));
580
- if (that.transmission) {
581
+ if (that.transmission && that.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
581
582
  this.$l.transmissionRay = that.getVolumeTransmissionRay(this, this.normal, this.viewVec, this.data.thicknessFactor, this.data.f0.a);
582
583
  this.$l.pointToLight = pb.normalize(pb.sub(this.L, this.transmissionRay));
583
584
  this.$l.transmittedLight = pb.mul(this.lightColor, that.getPunctualRadianceTransmission(this, this.normal, this.viewVec, this.pointToLight, this.alphaRoughness, this.data.f0.rgb, this.data.f90.rgb, this.data.diffuse.rgb, this.data.f0.a));
@@ -733,7 +734,7 @@ import { ShaderHelper } from '../../shader/helper.js';
733
734
  });
734
735
  return pb.getGlobalScope()[funcName](outsideIOR, eta2, cosTheta1, thinFilmThickness, baseF0);
735
736
  }
736
- indirectLighting(scope, normal, viewVec, commonData, outColor) {
737
+ indirectLighting(scope, normal, viewVec, commonData, outColor, outRoughness) {
737
738
  const pb = scope.$builder;
738
739
  const that = this;
739
740
  const ctx = that.drawContext;
@@ -742,7 +743,10 @@ import { ShaderHelper } from '../../shader/helper.js';
742
743
  pb.vec3('normal'),
743
744
  pb.vec3('viewVec'),
744
745
  that.getCommonDatasStruct(scope)('data'),
745
- pb.vec3('outColor').inout()
746
+ pb.vec3('outColor').inout(),
747
+ ...outRoughness ? [
748
+ pb.vec4('outRoughness').out()
749
+ ] : []
746
750
  ], function() {
747
751
  if (!ctx.drawEnvLight || !ctx.env.light.envLight.hasRadiance() && !ctx.env.light.envLight.hasIrradiance()) {
748
752
  return;
@@ -763,14 +767,18 @@ import { ShaderHelper } from '../../shader/helper.js';
763
767
  } else {
764
768
  this.$l.k_S = pb.add(this.data.f0.rgb, pb.mul(this.Fr, pb.pow(pb.sub(1, this.NoV), 5)));
765
769
  }
766
- if (ctx.env.light.envLight.hasRadiance()) {
767
- this.$l.radiance = ctx.env.light.envLight.getRadiance(this, pb.reflect(pb.neg(this.viewVec), this.normal), this.data.roughness);
770
+ if (outRoughness || ctx.env.light.envLight.hasRadiance()) {
768
771
  this.$l.FssEss = pb.add(pb.mul(this.k_S, this.f_ab.x), pb.vec3(this.f_ab.y));
769
- this.$l.iblSpecular = pb.mul(this.radiance, this.FssEss, this.data.specularWeight, this.occlusion);
772
+ this.$l.specularFactor = pb.mul(this.FssEss, this.data.specularWeight, this.occlusion);
770
773
  if (that.sheen) {
771
- this.iblSpecular = pb.mul(this.iblSpecular, this.data.sheenAlbedoScaling);
774
+ this.specularFactor = pb.mul(this.specularFactor, this.data.sheenAlbedoScaling);
775
+ }
776
+ if (outRoughness) {
777
+ this.outRoughness = pb.vec4(this.specularFactor /*this.data.f0.rgb*/ , this.data.roughness);
778
+ } else if (ctx.env.light.envLight.hasRadiance()) {
779
+ this.$l.radiance = ctx.env.light.envLight.getRadiance(this, pb.reflect(pb.neg(this.viewVec), this.normal), this.data.roughness);
780
+ this.outColor = pb.add(this.outColor, pb.mul(this.radiance, this.specularFactor));
772
781
  }
773
- this.outColor = pb.add(this.outColor, this.iblSpecular);
774
782
  }
775
783
  if (ctx.env.light.envLight.hasIrradiance()) {
776
784
  this.$l.irradiance = ctx.env.light.envLight.getIrradiance(this, this.normal);
@@ -791,7 +799,7 @@ import { ShaderHelper } from '../../shader/helper.js';
791
799
  if (that.sheen) {
792
800
  this.iblDiffuse = pb.mul(this.iblDiffuse, this.data.sheenAlbedoScaling);
793
801
  }
794
- if (that.transmission) {
802
+ if (that.transmission && that.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
795
803
  this.$l.iblTransmission = that.getIBLVolumnRefraction(this, this.ggxLutSample.rg, this.normal, this.viewVec, this.data.roughness, this.data.diffuse.rgb, this.data.f0.rgb, this.data.f90, this.$inputs.worldPos, this.data.f0.a, this.data.thicknessFactor, this.data.attenuationColor, this.data.attenuationDistance);
796
804
  this.iblDiffuse = pb.mix(this.iblDiffuse, this.iblTransmission, this.data.transmissionFactor);
797
805
  }
@@ -814,7 +822,11 @@ import { ShaderHelper } from '../../shader/helper.js';
814
822
  this.outColor = pb.add(this.outColor, pb.mul(this.ccSpecular, this.data.ccFactor.x));
815
823
  }
816
824
  });
817
- scope.$g[funcName](normal, viewVec, commonData, outColor);
825
+ if (outRoughness) {
826
+ scope.$g[funcName](normal, viewVec, commonData, outColor, outRoughness);
827
+ } else {
828
+ scope.$g[funcName](normal, viewVec, commonData, outColor);
829
+ }
818
830
  }
819
831
  fresnelSchlick(scope, cosTheta, F0, F90) {
820
832
  const pb = scope.$builder;
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"common.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,7 +2,7 @@ import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
2
2
  import { mixinVertexColor } from './mixins/vertexcolor.js';
3
3
  import { mixinPBRMetallicRoughness } from './mixins/lightmodel/pbrmetallicroughness.js';
4
4
  import { ShaderHelper } from './shader/helper.js';
5
- import { RENDER_PASS_TYPE_LIGHT } from '../values.js';
5
+ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
6
6
 
7
7
  /**
8
8
  * PBRMetallicRoughnessMaterial class
@@ -61,8 +61,19 @@ import { RENDER_PASS_TYPE_LIGHT } from '../values.js';
61
61
  if (this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
62
62
  scope.$l.normalInfo = this.calculateNormalAndTBN(scope, scope.$inputs.worldPos, scope.$inputs.wNorm, scope.$inputs.wTangent, scope.$inputs.wBinormal);
63
63
  scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);
64
- scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN);
65
- this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a));
64
+ if (this.drawContext.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {
65
+ scope.$l.outRoughness = pb.vec4();
66
+ scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN, scope.outRoughness);
67
+ /*
68
+ scope.outRoughness = pb.vec4(
69
+ pb.add(pb.mul(scope.normalInfo.normal, 0.5), pb.vec3(0.5)),
70
+ scope.outRoughness.a
71
+ );
72
+ */ this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a), scope.outRoughness, pb.vec4(pb.add(pb.mul(scope.normalInfo.normal, 0.5), pb.vec3(0.5)), 1));
73
+ } else {
74
+ scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN);
75
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a));
76
+ }
66
77
  } else {
67
78
  this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.albedo);
68
79
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pbrmr.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"pbrmr.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,7 +2,7 @@ import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
2
2
  import { mixinVertexColor } from './mixins/vertexcolor.js';
3
3
  import { mixinPBRSpecularGlossness } from './mixins/lightmodel/pbrspecularglossness.js';
4
4
  import { ShaderHelper } from './shader/helper.js';
5
- import { RENDER_PASS_TYPE_LIGHT } from '../values.js';
5
+ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
6
6
 
7
7
  /**
8
8
  * PBRSpecularGlossinessMaterial class
@@ -61,8 +61,19 @@ import { RENDER_PASS_TYPE_LIGHT } from '../values.js';
61
61
  if (this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
62
62
  scope.$l.normalInfo = this.calculateNormalAndTBN(scope, scope.$inputs.worldPos, scope.$inputs.wNorm, scope.$inputs.wTangent, scope.$inputs.wBinormal);
63
63
  scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);
64
- scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN);
65
- this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a));
64
+ if (this.drawContext.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {
65
+ scope.$l.outRoughness = pb.vec4();
66
+ scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN, scope.outRoughness);
67
+ /*
68
+ scope.outRoughness = pb.vec4(
69
+ pb.add(pb.mul(scope.normalInfo.normal, 0.5), pb.vec3(0.5)),
70
+ scope.outRoughness.a
71
+ );
72
+ */ this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a), scope.outRoughness, pb.vec4(pb.add(pb.mul(scope.normalInfo.normal, 0.5), pb.vec3(0.5)), 1));
73
+ } else {
74
+ scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN);
75
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a));
76
+ }
66
77
  } else {
67
78
  this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.albedo);
68
79
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pbrsg.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"pbrsg.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,8 +1,9 @@
1
1
  import { Vector3, Vector4 } from '@zephyr3d/base';
2
- import { RENDER_PASS_TYPE_SHADOWMAP, RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_OBJECT_COLOR, RENDER_PASS_TYPE_LIGHT, MAX_CLUSTERED_LIGHTS, MORPH_WEIGHTS_VECTOR_COUNT, MORPH_TARGET_POSITION, MORPH_TARGET_NORMAL, MORPH_TARGET_TANGENT, MORPH_ATTRIBUTE_VECTOR_COUNT } from '../../values.js';
2
+ import { RENDER_PASS_TYPE_SHADOWMAP, RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_OBJECT_COLOR, RENDER_PASS_TYPE_LIGHT, MAX_CLUSTERED_LIGHTS, MORPH_WEIGHTS_VECTOR_COUNT, MORPH_TARGET_POSITION, MORPH_TARGET_NORMAL, MORPH_TARGET_TANGENT, MORPH_ATTRIBUTE_VECTOR_COUNT, MaterialVaryingFlags } from '../../values.js';
3
3
  import { ScatteringLut } from '../../render/scatteringlut.js';
4
+ import { ProgramBuilder } from '@zephyr3d/device';
4
5
  import { linearToGamma } from '../../shaders/misc.js';
5
- import '../../app.js';
6
+ import { Application } from '../../app.js';
6
7
 
7
8
  const UNIFORM_NAME_GLOBAL = 'Z_UniformGlobal';
8
9
  const UNIFORM_NAME_LIGHT_BUFFER = 'Z_UniformLightBuffer';
@@ -31,6 +32,7 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
31
32
  static BILLBOARD_SYLINDRAL = 2;
32
33
  /** @internal */ static defaultSunDir = Vector3.one().inplaceNormalize();
33
34
  /** @internal */ static SKIN_MATRIX_NAME = 'Z_SkinMatrix';
35
+ /** @internal */ static _drawableBindGroupLayouts = {};
34
36
  /** @internal */ static _lightUniformShadow = {
35
37
  light: {
36
38
  sunDir: new Vector3(),
@@ -86,6 +88,25 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
86
88
  static getLightBufferUniformName() {
87
89
  return UNIFORM_NAME_LIGHT_BUFFER;
88
90
  }
91
+ static getDrawableBindGroupLayout(skinning, morphing, instancing) {
92
+ const hash = `${skinning ? 1 : 0}${morphing ? 1 : 0}${instancing ? 1 : 0}`;
93
+ let bindGroupLayout = this._drawableBindGroupLayouts[hash];
94
+ if (!bindGroupLayout) {
95
+ const device = Application.instance.device;
96
+ const buildInfo = new ProgramBuilder(device).buildRender({
97
+ vertex (pb) {
98
+ ShaderHelper.vertexShaderDrawableStuff(this, skinning, morphing, instancing);
99
+ pb.main(function() {});
100
+ },
101
+ fragment (pb) {
102
+ pb.main(function() {});
103
+ }
104
+ });
105
+ bindGroupLayout = buildInfo[2][1];
106
+ this._drawableBindGroupLayouts[hash] = bindGroupLayout;
107
+ }
108
+ return bindGroupLayout;
109
+ }
89
110
  /**
90
111
  * Prepares the fragment shader which is going to be used in our material system
91
112
  *
@@ -117,7 +138,8 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
117
138
  pb.mat4('viewProjectionMatrix'),
118
139
  pb.mat4('viewMatrix'),
119
140
  pb.mat4('projectionMatrix'),
120
- pb.vec4('params')
141
+ pb.vec4('params'),
142
+ pb.float('roughnessFactor')
121
143
  ]);
122
144
  if (ctx.renderPass.type === RENDER_PASS_TYPE_SHADOWMAP) {
123
145
  const lightStruct = pb.defineStruct([
@@ -464,23 +486,8 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
464
486
  }
465
487
  }
466
488
  /** @internal */ static prepareVertexShaderCommon(pb, ctx) {
467
- this.vertexShaderDrawableStuff(pb.getGlobalScope(), !!ctx.skinAnimation, !!ctx.morphAnimation, !!ctx.instancing);
468
- /*
469
- const skinning = !!ctx.target?.getBoneMatrices();
470
- const scope = pb.getGlobalScope();
471
- if (ctx.instanceData) {
472
- scope[UNIFORM_NAME_INSTANCE_DATA_STRIDE] = pb.uint().uniform(1);
473
- scope[UNIFORM_NAME_INSTANCE_DATA_OFFSET] = pb.uint().uniform(1);
474
- scope[UNIFORM_NAME_INSTANCE_DATA] = pb.vec4[65536 >> 4]().uniformBuffer(3);
475
- } else {
476
- scope[UNIFORM_NAME_WORLD_MATRIX] = pb.mat4().uniform(1);
477
- }
478
- if (skinning) {
479
- scope[UNIFORM_NAME_BONE_MATRICES] = pb.tex2D().uniform(1).sampleType('unfilterable-float');
480
- scope[UNIFORM_NAME_BONE_INV_BIND_MATRIX] = pb.mat4().uniform(1);
481
- scope[UNIFORM_NAME_BONE_TEXTURE_SIZE] = pb.int().uniform(1);
482
- }
483
- */ }
489
+ this.vertexShaderDrawableStuff(pb.getGlobalScope(), !!(ctx.materialFlags & MaterialVaryingFlags.SKIN_ANIMATION), !!(ctx.materialFlags & MaterialVaryingFlags.MORPH_ANIMATION), !!(ctx.materialFlags & MaterialVaryingFlags.INSTANCING));
490
+ }
484
491
  /** @internal */ static setCameraUniforms(bindGroup, camera, flip, linear) {
485
492
  const pos = camera.getWorldPosition();
486
493
  const cameraStruct = {
@@ -489,7 +496,8 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
489
496
  viewProjectionMatrix: camera.viewProjectionMatrix,
490
497
  viewMatrix: camera.viewMatrix,
491
498
  projectionMatrix: camera.getProjectionMatrix(),
492
- params: new Vector4(camera.getNearPlane(), camera.getFarPlane(), flip ? -1 : 1, linear ? 0 : 1)
499
+ params: new Vector4(camera.getNearPlane(), camera.getFarPlane(), flip ? -1 : 1, linear ? 0 : 1),
500
+ roughnessFactor: camera.SSR ? camera.ssrRoughnessFactor : 1
493
501
  };
494
502
  bindGroup.setValue(UNIFORM_NAME_GLOBAL, {
495
503
  camera: cameraStruct
@@ -571,6 +579,13 @@ const UNIFORM_NAME_MORPH_INFO = 'Z_UniformMorphInfo';
571
579
  return scope[UNIFORM_NAME_GLOBAL].camera.position.xyz;
572
580
  }
573
581
  /**
582
+ * Gets the uniform variable of type float which holds the roughness factor
583
+ * @param scope - Current shader scope
584
+ * @returns The roughness factor
585
+ */ static getCameraRoughnessFactor(scope) {
586
+ return scope[UNIFORM_NAME_GLOBAL].camera.roughnessFactor;
587
+ }
588
+ /**
574
589
  * Discard the fragment if it was clipped by the clip plane
575
590
  * @param scope - Current shader scope
576
591
  */ static discardIfClipped(scope, worldPos) {
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"helper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -5,7 +5,7 @@ import { Vector4, Vector2 } from '@zephyr3d/base';
5
5
  * The bloom post effect
6
6
  * @public
7
7
  */ class Bloom extends AbstractPostEffect {
8
- static _nearestSampler = null;
8
+ static className = 'Bloom';
9
9
  static _programDownsampleH = null;
10
10
  static _programDownsampleV = null;
11
11
  static _programUpsample = null;
@@ -363,15 +363,6 @@ import { Vector4, Vector2 } from '@zephyr3d/base';
363
363
  if (!this._bindgroupDownsampleV) {
364
364
  this._bindgroupDownsampleV = device.createBindGroup(Bloom._programDownsampleV.bindGroupLayouts[0]);
365
365
  }
366
- if (!Bloom._nearestSampler) {
367
- Bloom._nearestSampler = device.createSampler({
368
- magFilter: 'nearest',
369
- minFilter: 'nearest',
370
- mipFilter: 'none',
371
- addressU: 'clamp',
372
- addressV: 'clamp'
373
- });
374
- }
375
366
  if (!Bloom._renderStateAdditive) {
376
367
  Bloom._renderStateAdditive = device.createRenderStateSet();
377
368
  Bloom._renderStateAdditive.useRasterizerState().setCullMode('none');
@@ -1 +1 @@
1
- {"version":3,"file":"bloom.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"bloom.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +1,15 @@
1
1
  import { linearToGamma } from '../shaders/misc.js';
2
+ import { MaterialVaryingFlags } from '../values.js';
3
+ import { SSR } from './ssr.js';
4
+ import { fetchSampler } from '../utility/misc.js';
2
5
 
3
6
  /**
4
7
  * Post processing compositor
5
8
  * @public
6
9
  */ class Compositor {
10
+ /** @internal */ static _SSRPostEffect = null;
7
11
  /** @internal */ _postEffectsOpaque;
8
12
  /** @internal */ _postEffectsTransparency;
9
- /** @internal */ static _blitSampler = null;
10
13
  /** @internal */ static _blitProgram = null;
11
14
  /** @internal */ static _blitBindgroup = null;
12
15
  /** @internal */ static _blitRenderStates = null;
@@ -17,14 +20,14 @@ import { linearToGamma } from '../shaders/misc.js';
17
20
  this._postEffectsOpaque = [];
18
21
  this._postEffectsTransparency = [];
19
22
  }
20
- /** @internal */ requireLinearDepth() {
23
+ /** @internal */ requireLinearDepth(ctx) {
21
24
  for (const postEffect of this._postEffectsOpaque){
22
- if (postEffect.requireLinearDepthTexture()) {
25
+ if (postEffect.requireLinearDepthTexture(ctx)) {
23
26
  return true;
24
27
  }
25
28
  }
26
29
  for (const postEffect of this._postEffectsTransparency){
27
- if (postEffect.requireLinearDepthTexture()) {
30
+ if (postEffect.requireLinearDepthTexture(ctx)) {
28
31
  return true;
29
32
  }
30
33
  }
@@ -76,6 +79,11 @@ import { linearToGamma } from '../shaders/misc.js';
76
79
  ];
77
80
  }
78
81
  /** @internal */ begin(ctx) {
82
+ const ssr = !!(ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS);
83
+ if (this._postEffectsOpaque.length === 0 && this._postEffectsTransparency.length === 0 && ctx.primaryCamera.sampleCount === 1 && !ssr) {
84
+ ctx.compositorContex = null;
85
+ return;
86
+ }
79
87
  const device = ctx.device;
80
88
  const format = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';
81
89
  const finalFramebuffer = device.getFramebuffer();
@@ -83,8 +91,13 @@ import { linearToGamma } from '../shaders/misc.js';
83
91
  let msFramebuffer = null;
84
92
  const w = depth ? depth.width : ctx.viewportWidth;
85
93
  const h = depth ? depth.height : ctx.viewportHeight;
86
- if (ctx.primaryCamera.sampleCount > 1) {
87
- msFramebuffer = device.pool.fetchTemporalFramebuffer(true, w, h, format, depth, false, ctx.primaryCamera.sampleCount);
94
+ if (ctx.primaryCamera.sampleCount > 1 || ssr) {
95
+ const fmt2 = ssr ? device.type === 'webgl' ? format : 'rgba8unorm' : format;
96
+ msFramebuffer = device.pool.fetchTemporalFramebuffer(true, w, h, ssr ? [
97
+ format,
98
+ fmt2,
99
+ fmt2
100
+ ] : format, depth, ssr, ctx.primaryCamera.sampleCount);
88
101
  }
89
102
  const pingpongFramebuffers = [
90
103
  device.pool.fetchTemporalFramebuffer(true, w, h, format, depth ?? ctx.depthFormat, false),
@@ -106,6 +119,14 @@ import { linearToGamma } from '../shaders/misc.js';
106
119
  msTexture: msFramebuffer,
107
120
  writeIndex
108
121
  };
122
+ if (ssr) {
123
+ if (!Compositor._SSRPostEffect) {
124
+ Compositor._SSRPostEffect = new SSR();
125
+ }
126
+ Compositor._SSRPostEffect.roughnessTexture = msFramebuffer.getColorAttachments()[1];
127
+ Compositor._SSRPostEffect.normalTexture = msFramebuffer.getColorAttachments()[2];
128
+ this._postEffectsOpaque.unshift(Compositor._SSRPostEffect);
129
+ }
109
130
  }
110
131
  /** @internal */ drawPostEffects(ctx, opaque, sceneDepthTexture) {
111
132
  const postEffects = opaque ? this._postEffectsOpaque : this._postEffectsTransparency;
@@ -118,7 +139,7 @@ import { linearToGamma } from '../shaders/misc.js';
118
139
  }
119
140
  const inputTexture = device.getFramebuffer().getColorAttachments()[0];
120
141
  const isLast = this.isLastPostEffect(opaque, i);
121
- const finalEffect = isLast && (!postEffect.requireDepthAttachment() || !!ctx.compositorContex.finalFramebuffer);
142
+ const finalEffect = isLast && (!postEffect.requireDepthAttachment(ctx) || !!ctx.compositorContex.finalFramebuffer);
122
143
  if (finalEffect) {
123
144
  device.setFramebuffer(ctx.compositorContex.finalFramebuffer);
124
145
  device.setViewport(null);
@@ -134,15 +155,20 @@ import { linearToGamma } from '../shaders/misc.js';
134
155
  }
135
156
  }
136
157
  /** @internal */ end(ctx) {
137
- const device = ctx.device;
138
- if (device.getFramebuffer() !== ctx.compositorContex.finalFramebuffer) {
139
- const srcTex = device.getFramebuffer().getColorAttachments()[0];
140
- device.setFramebuffer(ctx.compositorContex.finalFramebuffer);
141
- device.setViewport(null);
142
- device.setScissor(null);
143
- Compositor._blit(device, srcTex, !ctx.compositorContex.finalFramebuffer);
144
- }
145
- ctx.compositorContex = null;
158
+ if (ctx.compositorContex) {
159
+ const device = ctx.device;
160
+ if (device.getFramebuffer() !== ctx.compositorContex.finalFramebuffer) {
161
+ const srcTex = device.getFramebuffer().getColorAttachments()[0];
162
+ device.setFramebuffer(ctx.compositorContex.finalFramebuffer);
163
+ device.setViewport(null);
164
+ device.setScissor(null);
165
+ Compositor._blit(device, srcTex, !ctx.compositorContex.finalFramebuffer);
166
+ }
167
+ ctx.compositorContex = null;
168
+ }
169
+ if (this._postEffectsOpaque[0] === Compositor._SSRPostEffect) {
170
+ this._postEffectsOpaque.shift();
171
+ }
146
172
  }
147
173
  /** @internal */ isLastPostEffect(opaque, index) {
148
174
  const list = opaque ? this._postEffectsOpaque : this._postEffectsTransparency;
@@ -217,18 +243,11 @@ import { linearToGamma } from '../shaders/misc.js';
217
243
  }
218
244
  ]
219
245
  });
220
- this._blitSampler = device.createSampler({
221
- minFilter: 'nearest',
222
- magFilter: 'nearest',
223
- mipFilter: 'none',
224
- addressU: 'clamp',
225
- addressV: 'clamp'
226
- });
227
246
  this._blitRenderStates = device.createRenderStateSet();
228
247
  this._blitRenderStates.useRasterizerState().setCullMode('none');
229
248
  this._blitRenderStates.useDepthState().enableTest(false).enableWrite(false);
230
249
  }
231
- this._blitBindgroup.setTexture('srcTex', srcTex, this._blitSampler);
250
+ this._blitBindgroup.setTexture('srcTex', srcTex, fetchSampler('clamp_nearest_nomip'));
232
251
  this._blitBindgroup.setValue('srgbOutput', srgbOutput ? 1 : 0);
233
252
  this._blitBindgroup.setValue('flip', device.type === 'webgpu' && !!device.getFramebuffer() ? 1 : 0);
234
253
  device.setRenderStates(this._blitRenderStates);
@@ -1 +1 @@
1
- {"version":3,"file":"compositor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"compositor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,13 +1,14 @@
1
1
  import { Vector2 } from '@zephyr3d/base';
2
2
  import { AbstractPostEffect } from './posteffect.js';
3
3
  import { linearToGamma } from '../shaders/misc.js';
4
+ import { fetchSampler } from '../utility/misc.js';
4
5
 
5
6
  /**
6
7
  * FXAA post effect
7
8
  * @public
8
9
  */ class FXAA extends AbstractPostEffect {
10
+ static className = 'FXAA';
9
11
  static _program = null;
10
- static _sampler = null;
11
12
  _bindgroup;
12
13
  _invTexSize;
13
14
  /**
@@ -33,7 +34,7 @@ import { linearToGamma } from '../shaders/misc.js';
33
34
  const device = ctx.device;
34
35
  this._prepare(device);
35
36
  this._invTexSize.setXY(1 / inputColorTexture.width, 1 / inputColorTexture.height);
36
- this._bindgroup.setTexture('srcTex', inputColorTexture, FXAA._sampler);
37
+ this._bindgroup.setTexture('srcTex', inputColorTexture, fetchSampler('clamp_linear_nomip'));
37
38
  this._bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
38
39
  this._bindgroup.setValue('srgbOut', srgbOutput ? 1 : 0);
39
40
  this._bindgroup.setValue('invTexSize', this._invTexSize);
@@ -271,15 +272,6 @@ import { linearToGamma } from '../shaders/misc.js';
271
272
  }
272
273
  });
273
274
  }
274
- if (!FXAA._sampler) {
275
- FXAA._sampler = device.createSampler({
276
- magFilter: 'linear',
277
- minFilter: 'linear',
278
- mipFilter: 'none',
279
- addressU: 'clamp',
280
- addressV: 'clamp'
281
- });
282
- }
283
275
  if (!this._bindgroup) {
284
276
  this._bindgroup = device.createBindGroup(FXAA._program.bindGroupLayouts[0]);
285
277
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fxaa.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"fxaa.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +1,13 @@
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
  * Grayscale post effect
6
7
  * @public
7
8
  */ class Grayscale extends AbstractPostEffect {
9
+ static className = 'Grayscale';
8
10
  static _program = null;
9
- static _sampler = null;
10
11
  _bindgroup;
11
12
  /**
12
13
  * Creates an instance of grayscale post effect
@@ -29,7 +30,7 @@ import { linearToGamma } from '../shaders/misc.js';
29
30
  /** {@inheritDoc AbstractPostEffect.apply} */ apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
30
31
  const device = ctx.device;
31
32
  this._prepare(device);
32
- this._bindgroup.setTexture('srcTex', inputColorTexture, Grayscale._sampler);
33
+ this._bindgroup.setTexture('srcTex', inputColorTexture, fetchSampler('clamp_nearest_nomip'));
33
34
  this._bindgroup.setValue('flip', this.needFlip(device) ? 1 : 0);
34
35
  this._bindgroup.setValue('srgbOut', srgbOutput ? 1 : 0);
35
36
  device.setProgram(Grayscale._program);
@@ -67,15 +68,6 @@ import { linearToGamma } from '../shaders/misc.js';
67
68
  }
68
69
  });
69
70
  }
70
- if (!Grayscale._sampler) {
71
- Grayscale._sampler = device.createSampler({
72
- magFilter: 'nearest',
73
- minFilter: 'nearest',
74
- mipFilter: 'none',
75
- addressU: 'clamp',
76
- addressV: 'clamp'
77
- });
78
- }
79
71
  if (!this._bindgroup) {
80
72
  this._bindgroup = device.createBindGroup(Grayscale._program.bindGroupLayouts[0]);
81
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"grayscale.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"grayscale.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}