@zephyr3d/editor 0.3.8 → 0.3.9

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 (137) hide show
  1. package/dist/assets/{index-BZ1L8ggE.js → index-CO6yA4Rj.js} +313 -11
  2. package/dist/assistant/zephyr-types-index.json +13834 -11679
  3. package/dist/index.html +1 -1
  4. package/dist/modules/zephyr3d_backend-webgpu.js +1 -1
  5. package/dist/modules/zephyr3d_backend-webgpu.js.map +1 -1
  6. package/dist/modules/zephyr3d_device.js +2 -2
  7. package/dist/modules/zephyr3d_device.js.map +1 -1
  8. package/dist/modules/zephyr3d_scene.js +2325 -515
  9. package/dist/modules/zephyr3d_scene.js.map +1 -1
  10. package/dist/vendor/zephyr3d/backend-webgpu/dist/renderpass_webgpu.js +1 -1
  11. package/dist/vendor/zephyr3d/backend-webgpu/dist/renderpass_webgpu.js.map +1 -1
  12. package/dist/vendor/zephyr3d/device/dist/device.js +2 -2
  13. package/dist/vendor/zephyr3d/device/dist/device.js.map +1 -1
  14. package/dist/vendor/zephyr3d/scene/dist/app/engine.js +3 -1
  15. package/dist/vendor/zephyr3d/scene/dist/app/engine.js.map +1 -1
  16. package/dist/vendor/zephyr3d/scene/dist/asset/assetmanager.js +1 -0
  17. package/dist/vendor/zephyr3d/scene/dist/asset/assetmanager.js.map +1 -1
  18. package/dist/vendor/zephyr3d/scene/dist/camera/camera.js +87 -0
  19. package/dist/vendor/zephyr3d/scene/dist/camera/camera.js.map +1 -1
  20. package/dist/vendor/zephyr3d/scene/dist/index.d.ts +158 -4
  21. package/dist/vendor/zephyr3d/scene/dist/index.js +3 -0
  22. package/dist/vendor/zephyr3d/scene/dist/index.js.map +1 -1
  23. package/dist/vendor/zephyr3d/scene/dist/material/meshmaterial.js +8 -1
  24. package/dist/vendor/zephyr3d/scene/dist/material/meshmaterial.js.map +1 -1
  25. package/dist/vendor/zephyr3d/scene/dist/material/shader/helper.js +6 -0
  26. package/dist/vendor/zephyr3d/scene/dist/material/shader/helper.js.map +1 -1
  27. package/dist/vendor/zephyr3d/scene/dist/material/skin.js +263 -0
  28. package/dist/vendor/zephyr3d/scene/dist/material/skin.js.map +1 -0
  29. package/dist/vendor/zephyr3d/scene/dist/posteffect/compositor.js +3 -0
  30. package/dist/vendor/zephyr3d/scene/dist/posteffect/compositor.js.map +1 -1
  31. package/dist/vendor/zephyr3d/scene/dist/posteffect/skinsss.js +194 -0
  32. package/dist/vendor/zephyr3d/scene/dist/posteffect/skinsss.js.map +1 -0
  33. package/dist/vendor/zephyr3d/scene/dist/posteffect/ssr.js +26 -49
  34. package/dist/vendor/zephyr3d/scene/dist/posteffect/ssr.js.map +1 -1
  35. package/dist/vendor/zephyr3d/scene/dist/posteffect/sss.js +1 -0
  36. package/dist/vendor/zephyr3d/scene/dist/posteffect/sss.js.map +1 -1
  37. package/dist/vendor/zephyr3d/scene/dist/posteffect/taa.js +2 -40
  38. package/dist/vendor/zephyr3d/scene/dist/posteffect/taa.js.map +1 -1
  39. package/dist/vendor/zephyr3d/scene/dist/render/abuffer_oit.js +1 -0
  40. package/dist/vendor/zephyr3d/scene/dist/render/abuffer_oit.js.map +1 -1
  41. package/dist/vendor/zephyr3d/scene/dist/render/drawable_mixin.js +1 -0
  42. package/dist/vendor/zephyr3d/scene/dist/render/drawable_mixin.js.map +1 -1
  43. package/dist/vendor/zephyr3d/scene/dist/render/fbm_wavegenerator.js +1 -0
  44. package/dist/vendor/zephyr3d/scene/dist/render/fbm_wavegenerator.js.map +1 -1
  45. package/dist/vendor/zephyr3d/scene/dist/render/gerstner_wavegenerator.js +1 -0
  46. package/dist/vendor/zephyr3d/scene/dist/render/gerstner_wavegenerator.js.map +1 -1
  47. package/dist/vendor/zephyr3d/scene/dist/render/globalbindgroup_allocator.js +1 -0
  48. package/dist/vendor/zephyr3d/scene/dist/render/globalbindgroup_allocator.js.map +1 -1
  49. package/dist/vendor/zephyr3d/scene/dist/render/lightpass.js +4 -1
  50. package/dist/vendor/zephyr3d/scene/dist/render/lightpass.js.map +1 -1
  51. package/dist/vendor/zephyr3d/scene/dist/render/render_queue.js +1 -0
  52. package/dist/vendor/zephyr3d/scene/dist/render/render_queue.js.map +1 -1
  53. package/dist/vendor/zephyr3d/scene/dist/render/renderer.js +1 -0
  54. package/dist/vendor/zephyr3d/scene/dist/render/renderer.js.map +1 -1
  55. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/device_pool_allocator.js +12 -5
  56. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  57. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/forward_plus_builder.js +78 -8
  58. package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  59. package/dist/vendor/zephyr3d/scene/dist/scene/basesprite.js +1 -0
  60. package/dist/vendor/zephyr3d/scene/dist/scene/basesprite.js.map +1 -1
  61. package/dist/vendor/zephyr3d/scene/dist/scene/batchgroup.js +1 -0
  62. package/dist/vendor/zephyr3d/scene/dist/scene/batchgroup.js.map +1 -1
  63. package/dist/vendor/zephyr3d/scene/dist/scene/environment.js +1 -0
  64. package/dist/vendor/zephyr3d/scene/dist/scene/environment.js.map +1 -1
  65. package/dist/vendor/zephyr3d/scene/dist/scene/light.js +158 -154
  66. package/dist/vendor/zephyr3d/scene/dist/scene/light.js.map +1 -1
  67. package/dist/vendor/zephyr3d/scene/dist/scene/mesh.js +1 -0
  68. package/dist/vendor/zephyr3d/scene/dist/scene/mesh.js.map +1 -1
  69. package/dist/vendor/zephyr3d/scene/dist/scene/msdftext.js +1 -0
  70. package/dist/vendor/zephyr3d/scene/dist/scene/msdftext.js.map +1 -1
  71. package/dist/vendor/zephyr3d/scene/dist/scene/msdftextsprite.js +1 -0
  72. package/dist/vendor/zephyr3d/scene/dist/scene/msdftextsprite.js.map +1 -1
  73. package/dist/vendor/zephyr3d/scene/dist/scene/particlesys.js +1 -0
  74. package/dist/vendor/zephyr3d/scene/dist/scene/particlesys.js.map +1 -1
  75. package/dist/vendor/zephyr3d/scene/dist/scene/scene.js +1 -0
  76. package/dist/vendor/zephyr3d/scene/dist/scene/scene.js.map +1 -1
  77. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grass.js +1 -0
  78. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grass.js.map +1 -1
  79. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grassmaterial.js +1 -0
  80. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  81. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/terrain-cm.js +1 -0
  82. package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  83. package/dist/vendor/zephyr3d/scene/dist/scene/water.js +1 -0
  84. package/dist/vendor/zephyr3d/scene/dist/scene/water.js.map +1 -1
  85. package/dist/vendor/zephyr3d/scene/dist/shaders/shadow.js +617 -1
  86. package/dist/vendor/zephyr3d/scene/dist/shaders/shadow.js.map +1 -1
  87. package/dist/vendor/zephyr3d/scene/dist/shadow/esm.js +1 -0
  88. package/dist/vendor/zephyr3d/scene/dist/shadow/esm.js.map +1 -1
  89. package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_opt.js +1 -0
  90. package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_opt.js.map +1 -1
  91. package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_pd.js +1 -0
  92. package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_pd.js.map +1 -1
  93. package/dist/vendor/zephyr3d/scene/dist/shadow/pcss.js +182 -0
  94. package/dist/vendor/zephyr3d/scene/dist/shadow/pcss.js.map +1 -0
  95. package/dist/vendor/zephyr3d/scene/dist/shadow/shader.js +1 -0
  96. package/dist/vendor/zephyr3d/scene/dist/shadow/shader.js.map +1 -1
  97. package/dist/vendor/zephyr3d/scene/dist/shadow/shadow_impl.js.map +1 -1
  98. package/dist/vendor/zephyr3d/scene/dist/shadow/shadowmapper.js +183 -105
  99. package/dist/vendor/zephyr3d/scene/dist/shadow/shadowmapper.js.map +1 -1
  100. package/dist/vendor/zephyr3d/scene/dist/shadow/ssm.js +1 -0
  101. package/dist/vendor/zephyr3d/scene/dist/shadow/ssm.js.map +1 -1
  102. package/dist/vendor/zephyr3d/scene/dist/shadow/vsm.js +1 -0
  103. package/dist/vendor/zephyr3d/scene/dist/shadow/vsm.js.map +1 -1
  104. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/manager.js +3 -1
  105. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/manager.js.map +1 -1
  106. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js +1 -0
  107. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js.map +1 -1
  108. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/batch.js +1 -0
  109. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/batch.js.map +1 -1
  110. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js +122 -0
  111. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js.map +1 -1
  112. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/common.js +1 -0
  113. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/common.js.map +1 -1
  114. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/light.js +102 -21
  115. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/light.js.map +1 -1
  116. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/material.js +195 -3
  117. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/material.js.map +1 -1
  118. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/mesh.js +1 -0
  119. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/mesh.js.map +1 -1
  120. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js +1 -0
  121. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js.map +1 -1
  122. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/particle.js +1 -0
  123. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/particle.js.map +1 -1
  124. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/primitive.js +1 -0
  125. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/primitive.js.map +1 -1
  126. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/sprite.js +1 -0
  127. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/sprite.js.map +1 -1
  128. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/terrain.js +1 -0
  129. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/terrain.js.map +1 -1
  130. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/text.js +1 -0
  131. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/text.js.map +1 -1
  132. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/water.js +1 -0
  133. package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/water.js.map +1 -1
  134. package/dist/vendor/zephyr3d/scene/dist/values.js +1 -0
  135. package/dist/vendor/zephyr3d/scene/dist/values.js.map +1 -1
  136. package/electron/main.cjs +30 -6
  137. package/package.json +4 -4
@@ -0,0 +1,263 @@
1
+ import { Vector4 } from '@zephyr3d/base';
2
+ import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
3
+ import { mixinLight } from './mixins/lit.js';
4
+ import { mixinVertexColor } from './mixins/vertexcolor.js';
5
+ import { mixinTextureProps } from './mixins/texture.js';
6
+ import { ShaderHelper } from './shader/helper.js';
7
+ import { RENDER_PASS_TYPE_LIGHT, LIGHT_TYPE_POINT, MaterialVaryingFlags } from '../values.js';
8
+
9
+ /**
10
+ * Stylized realtime skin material.
11
+ *
12
+ * @remarks
13
+ * This material is designed for the {@link SkinSSS} post effect. It renders a regular lit color,
14
+ * and when `camera.skinSSS` is enabled it also writes a skin lighting multiplier into the
15
+ * `SkinSSSTexture` MRT. The post effect blurs that side buffer in screen space to create a soft
16
+ * character-skin look similar to simple game/anime skin renderers.
17
+ *
18
+ * The optional `subsurfaceTexture` uses R as skin mask and G as local softness.
19
+ *
20
+ * @public
21
+ */ class SkinMaterial extends applyMaterialMixins(MeshMaterial, mixinLight, mixinVertexColor, mixinTextureProps('subsurface')) {
22
+ static FEATURE_VERTEX_NORMAL = this.defineFeature();
23
+ static FEATURE_VERTEX_TANGENT = this.defineFeature();
24
+ _shininess;
25
+ _specularStrength;
26
+ _diffuseWrap;
27
+ _diffuseSoftness;
28
+ _scatterWrap;
29
+ _scatterStrength;
30
+ _scatterColor;
31
+ constructor(){
32
+ super();
33
+ this._shininess = 72;
34
+ this._specularStrength = 0.22;
35
+ this._diffuseWrap = 0.28;
36
+ this._diffuseSoftness = 0.45;
37
+ this._scatterWrap = 0.65;
38
+ this._scatterStrength = 0.7;
39
+ this._scatterColor = new Vector4(1, 0.42, 0.28, 1);
40
+ this.useFeature(SkinMaterial.FEATURE_VERTEX_NORMAL, true);
41
+ }
42
+ /** Marker used by the forward render graph to allocate the SkinSSS MRT. */ get skinSSS() {
43
+ return true;
44
+ }
45
+ clone() {
46
+ const other = new SkinMaterial();
47
+ other.copyFrom(this);
48
+ return other;
49
+ }
50
+ copyFrom(other) {
51
+ super.copyFrom(other);
52
+ this.vertexNormal = other.vertexNormal;
53
+ this.vertexTangent = other.vertexTangent;
54
+ this.shininess = other.shininess;
55
+ this.specularStrength = other.specularStrength;
56
+ this.diffuseWrap = other.diffuseWrap;
57
+ this.diffuseSoftness = other.diffuseSoftness;
58
+ this.scatterWrap = other.scatterWrap;
59
+ this.scatterStrength = other.scatterStrength;
60
+ this.scatterColor = other.scatterColor;
61
+ }
62
+ /** true if vertex normal attribute presents */ get vertexNormal() {
63
+ return this.featureUsed(SkinMaterial.FEATURE_VERTEX_NORMAL);
64
+ }
65
+ set vertexNormal(val) {
66
+ this.useFeature(SkinMaterial.FEATURE_VERTEX_NORMAL, !!val);
67
+ }
68
+ /** true if vertex tangent attribute presents */ get vertexTangent() {
69
+ return this.featureUsed(SkinMaterial.FEATURE_VERTEX_TANGENT);
70
+ }
71
+ set vertexTangent(val) {
72
+ this.useFeature(SkinMaterial.FEATURE_VERTEX_TANGENT, !!val);
73
+ }
74
+ /** Blinn specular exponent. Higher values produce smaller highlights. */ get shininess() {
75
+ return this._shininess;
76
+ }
77
+ set shininess(val) {
78
+ const next = Math.max(1, val ?? 1);
79
+ if (next !== this._shininess) {
80
+ this._shininess = next;
81
+ this.uniformChanged();
82
+ }
83
+ }
84
+ /** Direct specular strength. Keep this restrained for soft skin. */ get specularStrength() {
85
+ return this._specularStrength;
86
+ }
87
+ set specularStrength(val) {
88
+ const next = Math.max(0, val ?? 0);
89
+ if (next !== this._specularStrength) {
90
+ this._specularStrength = next;
91
+ this.uniformChanged();
92
+ }
93
+ }
94
+ /** Wrap amount for visible diffuse lighting. */ get diffuseWrap() {
95
+ return this._diffuseWrap;
96
+ }
97
+ set diffuseWrap(val) {
98
+ const next = Math.max(0, val ?? 0);
99
+ if (next !== this._diffuseWrap) {
100
+ this._diffuseWrap = next;
101
+ this.uniformChanged();
102
+ }
103
+ }
104
+ /** Blend from hard Lambert lighting to wrapped diffuse lighting. */ get diffuseSoftness() {
105
+ return this._diffuseSoftness;
106
+ }
107
+ set diffuseSoftness(val) {
108
+ const next = Math.max(0, Math.min(1, val ?? 0));
109
+ if (next !== this._diffuseSoftness) {
110
+ this._diffuseSoftness = next;
111
+ this.uniformChanged();
112
+ }
113
+ }
114
+ /** Wider wrap used only for the post-process scattering source. */ get scatterWrap() {
115
+ return this._scatterWrap;
116
+ }
117
+ set scatterWrap(val) {
118
+ const next = Math.max(0, val ?? 0);
119
+ if (next !== this._scatterWrap) {
120
+ this._scatterWrap = next;
121
+ this.uniformChanged();
122
+ }
123
+ }
124
+ /** Strength of the multiplier written into the SkinSSS side buffer. */ get scatterStrength() {
125
+ return this._scatterStrength;
126
+ }
127
+ set scatterStrength(val) {
128
+ const next = Math.max(0, val ?? 0);
129
+ if (next !== this._scatterStrength) {
130
+ this._scatterStrength = next;
131
+ this.uniformChanged();
132
+ }
133
+ }
134
+ /** Warm tint for the blurred skin lighting contribution. */ get scatterColor() {
135
+ return this._scatterColor;
136
+ }
137
+ set scatterColor(val) {
138
+ if (!val.equalsTo(this._scatterColor)) {
139
+ this._scatterColor.set(val);
140
+ this.uniformChanged();
141
+ }
142
+ }
143
+ vertexShader(scope) {
144
+ super.vertexShader(scope);
145
+ const pb = scope.$builder;
146
+ scope.$l.oPos = ShaderHelper.resolveVertexPosition(scope);
147
+ scope.$outputs.worldPos = pb.mul(ShaderHelper.getWorldMatrix(scope), pb.vec4(scope.oPos, 1)).xyz;
148
+ ShaderHelper.setClipSpacePosition(scope, pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.worldPos, 1)));
149
+ if (this.vertexNormal) {
150
+ scope.$l.oNorm = ShaderHelper.resolveVertexNormal(scope);
151
+ scope.$outputs.wNorm = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oNorm, 0)).xyz;
152
+ if (this.vertexTangent) {
153
+ scope.$l.oTangent = ShaderHelper.resolveVertexTangent(scope);
154
+ scope.$outputs.wTangent = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oTangent.xyz, 0)).xyz;
155
+ scope.$outputs.wBinormal = pb.mul(pb.cross(scope.$outputs.wNorm, scope.$outputs.wTangent), scope.oTangent.w);
156
+ }
157
+ }
158
+ }
159
+ fragmentShader(scope) {
160
+ super.fragmentShader(scope);
161
+ const pb = scope.$builder;
162
+ const that = this;
163
+ if (this.needFragmentColorInput()) {
164
+ if (this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
165
+ scope.zSkinShininess = pb.float().uniform(2);
166
+ scope.zSkinSpecularStrength = pb.float().uniform(2);
167
+ scope.zSkinDiffuseWrap = pb.float().uniform(2);
168
+ scope.zSkinDiffuseSoftness = pb.float().uniform(2);
169
+ scope.zSkinScatterWrap = pb.float().uniform(2);
170
+ scope.zSkinScatterStrength = pb.float().uniform(2);
171
+ scope.zSkinScatterColor = pb.vec4().uniform(2);
172
+ }
173
+ scope.$l.albedo = this.calculateAlbedoColor(scope);
174
+ if (this.vertexColor) {
175
+ scope.albedo = pb.mul(scope.albedo, this.getVertexColor(scope));
176
+ }
177
+ if (this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
178
+ const baseLightPass = !this.drawContext.lightBlending;
179
+ scope.$l.normal = this.calculateNormal(scope, scope.$inputs.worldPos, scope.$inputs.wNorm, scope.$inputs.wTangent, scope.$inputs.wBinormal);
180
+ scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);
181
+ scope.$l.roughness = pb.sqrt(pb.div(2, pb.add(scope.zSkinShininess, 2)));
182
+ scope.$l.skinMask = pb.float(1);
183
+ scope.$l.skinSoftness = pb.float(0);
184
+ if (this.subsurfaceTexture) {
185
+ scope.$l.subsurfaceTexel = this.sampleSubsurfaceTexture(scope);
186
+ scope.skinMask = pb.clamp(scope.subsurfaceTexel.r, 0, 1);
187
+ scope.skinSoftness = pb.clamp(scope.subsurfaceTexel.g, 0, 1);
188
+ }
189
+ scope.$l.diffuseLighting = pb.vec3(0);
190
+ scope.$l.scatterLighting = pb.vec3(0);
191
+ scope.$l.specularLighting = pb.vec3(0);
192
+ if (this.needCalculateEnvLight() && baseLightPass) {
193
+ scope.$l.envDiffuse = this.getEnvLightIrradiance(scope, scope.normal);
194
+ scope.diffuseLighting = pb.add(scope.diffuseLighting, scope.envDiffuse);
195
+ scope.scatterLighting = pb.add(scope.scatterLighting, pb.mul(scope.envDiffuse, pb.add(0.7, pb.mul(scope.skinSoftness, 0.45))));
196
+ scope.$l.reflectVec = this.calculateReflectionVector(scope, scope.normal, scope.viewVec);
197
+ scope.specularLighting = pb.add(scope.specularLighting, pb.mul(this.getEnvLightRadiance(scope, scope.reflectVec, scope.roughness), scope.zSkinSpecularStrength));
198
+ }
199
+ this.forEachLight(scope, function(type, posRange, dirCutoff, colorIntensity, extra, shadow) {
200
+ this.$l.diffuseScale = pb.float(1);
201
+ this.$l.specularScale = pb.float(1);
202
+ this.$l.sourceRadiusFactor = pb.float(0);
203
+ this.$if(pb.equal(type, LIGHT_TYPE_POINT), function() {
204
+ this.diffuseScale = extra.x;
205
+ this.specularScale = extra.y;
206
+ this.sourceRadiusFactor = pb.div(extra.z, pb.max(pb.distance(posRange.xyz, this.$inputs.worldPos), 0.0001));
207
+ });
208
+ this.$l.lightAtten = that.calculateLightAttenuation(this, type, this.$inputs.worldPos, posRange, dirCutoff);
209
+ this.$l.lightDir = that.calculateLightDirection(this, type, this.$inputs.worldPos, posRange, dirCutoff);
210
+ this.$l.rawNoL = pb.dot(this.normal, this.lightDir);
211
+ this.$l.NoL = pb.clamp(this.rawNoL, 0, 1);
212
+ this.$l.NoLWrap = pb.clamp(pb.div(pb.add(this.rawNoL, this.zSkinDiffuseWrap), pb.add(1, this.zSkinDiffuseWrap)), 0, 1);
213
+ this.$l.NoLScatter = pb.clamp(pb.div(pb.add(this.rawNoL, this.zSkinScatterWrap), pb.add(1, this.zSkinScatterWrap)), 0, 1);
214
+ this.$l.shadowTerm = pb.float(1);
215
+ if (shadow) {
216
+ this.$if(pb.greaterThan(this.NoLWrap, 0), function() {
217
+ this.shadowTerm = that.calculateShadow(this, this.$inputs.worldPos, pb.max(this.NoL, 1e-5));
218
+ });
219
+ }
220
+ this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten, this.shadowTerm);
221
+ this.$l.halfVec = pb.normalize(pb.add(this.viewVec, this.lightDir));
222
+ this.$l.NoH = pb.clamp(pb.dot(this.normal, this.halfVec), 0, 1);
223
+ this.$l.pointShininess = pb.max(pb.div(this.zSkinShininess, pb.add(1, pb.mul(this.sourceRadiusFactor, 32))), 1);
224
+ this.$l.hardDiffuse = pb.mul(this.lightColor, this.NoL, this.diffuseScale, 1 / Math.PI);
225
+ this.$l.softDiffuse = pb.mul(this.lightColor, this.NoLWrap, this.diffuseScale, 1 / Math.PI);
226
+ this.$l.softness = pb.clamp(pb.add(this.zSkinDiffuseSoftness, pb.mul(this.skinSoftness, 0.35)), 0, 1);
227
+ this.diffuseLighting = pb.add(this.diffuseLighting, pb.mix(this.hardDiffuse, this.softDiffuse, this.softness));
228
+ this.scatterLighting = pb.add(this.scatterLighting, pb.mul(this.lightColor, this.NoLScatter, pb.add(0.7, pb.mul(this.skinSoftness, 0.55)), this.diffuseScale, 1 / Math.PI));
229
+ this.$l.specular = pb.mul(this.lightColor, pb.pow(this.NoH, this.pointShininess), this.zSkinSpecularStrength, this.specularScale, this.NoLWrap);
230
+ this.specularLighting = pb.add(this.specularLighting, this.specular);
231
+ });
232
+ scope.$l.litColor = pb.add(pb.mul(scope.albedo.rgb, scope.diffuseLighting), scope.specularLighting);
233
+ scope.$l.scatterMultiplier = pb.add(baseLightPass ? pb.vec3(1) : pb.vec3(0), pb.mul(scope.albedo.rgb, scope.scatterLighting, scope.zSkinScatterColor.rgb, scope.zSkinScatterStrength, pb.add(0.75, pb.mul(scope.skinSoftness, 0.45))));
234
+ scope.$l.skinSSS = pb.vec4(scope.scatterMultiplier, scope.skinMask);
235
+ if (this.drawContext.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {
236
+ scope.$l.outRoughness = pb.vec4(pb.mul(scope.albedo.rgb, pb.sub(1, scope.roughness), scope.zSkinSpecularStrength), pb.mul(scope.roughness, ShaderHelper.getCameraRoughnessFactor(scope)));
237
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a), scope.outRoughness, pb.vec4(pb.add(pb.mul(scope.normal, 0.5), pb.vec3(0.5)), 1), undefined, undefined, undefined, undefined, false, scope.skinSSS);
238
+ } else {
239
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a), undefined, undefined, undefined, undefined, undefined, undefined, false, scope.skinSSS);
240
+ }
241
+ } else {
242
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.albedo);
243
+ }
244
+ } else {
245
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, null);
246
+ }
247
+ }
248
+ applyUniformValues(bindGroup, ctx, pass) {
249
+ super.applyUniformValues(bindGroup, ctx, pass);
250
+ if (this.needFragmentColor(ctx) && ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
251
+ bindGroup.setValue('zSkinShininess', this._shininess);
252
+ bindGroup.setValue('zSkinSpecularStrength', this._specularStrength);
253
+ bindGroup.setValue('zSkinDiffuseWrap', this._diffuseWrap);
254
+ bindGroup.setValue('zSkinDiffuseSoftness', this._diffuseSoftness);
255
+ bindGroup.setValue('zSkinScatterWrap', this._scatterWrap);
256
+ bindGroup.setValue('zSkinScatterStrength', this._scatterStrength);
257
+ bindGroup.setValue('zSkinScatterColor', this._scatterColor);
258
+ }
259
+ }
260
+ }
261
+
262
+ export { SkinMaterial };
263
+ //# sourceMappingURL=skin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skin.js","sources":["../../src/material/skin.ts"],"sourcesContent":["import type { BindGroup, PBFunctionScope } from '@zephyr3d/device';\r\nimport type { Clonable, Immutable } from '@zephyr3d/base';\r\nimport { Vector4 } from '@zephyr3d/base';\r\nimport { MeshMaterial, applyMaterialMixins } from './meshmaterial';\r\nimport { mixinLight } from './mixins/lit';\r\nimport { mixinVertexColor } from './mixins/vertexcolor';\r\nimport { mixinTextureProps } from './mixins/texture';\r\nimport { ShaderHelper } from './shader/helper';\r\nimport type { DrawContext } from '../render';\r\nimport { LIGHT_TYPE_POINT, MaterialVaryingFlags, RENDER_PASS_TYPE_LIGHT } from '../values';\r\n\r\n/**\r\n * Stylized realtime skin material.\r\n *\r\n * @remarks\r\n * This material is designed for the {@link SkinSSS} post effect. It renders a regular lit color,\r\n * and when `camera.skinSSS` is enabled it also writes a skin lighting multiplier into the\r\n * `SkinSSSTexture` MRT. The post effect blurs that side buffer in screen space to create a soft\r\n * character-skin look similar to simple game/anime skin renderers.\r\n *\r\n * The optional `subsurfaceTexture` uses R as skin mask and G as local softness.\r\n *\r\n * @public\r\n */\r\nexport class SkinMaterial\r\n extends applyMaterialMixins(MeshMaterial, mixinLight, mixinVertexColor, mixinTextureProps('subsurface'))\r\n implements Clonable<SkinMaterial>\r\n{\r\n private static readonly FEATURE_VERTEX_NORMAL = this.defineFeature();\r\n private static readonly FEATURE_VERTEX_TANGENT = this.defineFeature();\r\n private _shininess: number;\r\n private _specularStrength: number;\r\n private _diffuseWrap: number;\r\n private _diffuseSoftness: number;\r\n private _scatterWrap: number;\r\n private _scatterStrength: number;\r\n private readonly _scatterColor: Vector4;\r\n\r\n constructor() {\r\n super();\r\n this._shininess = 72;\r\n this._specularStrength = 0.22;\r\n this._diffuseWrap = 0.28;\r\n this._diffuseSoftness = 0.45;\r\n this._scatterWrap = 0.65;\r\n this._scatterStrength = 0.7;\r\n this._scatterColor = new Vector4(1, 0.42, 0.28, 1);\r\n this.useFeature(SkinMaterial.FEATURE_VERTEX_NORMAL, true);\r\n }\r\n\r\n /** Marker used by the forward render graph to allocate the SkinSSS MRT. */\r\n get skinSSS() {\r\n return true;\r\n }\r\n\r\n clone() {\r\n const other = new SkinMaterial();\r\n other.copyFrom(this);\r\n return other;\r\n }\r\n\r\n copyFrom(other: this) {\r\n super.copyFrom(other);\r\n this.vertexNormal = other.vertexNormal;\r\n this.vertexTangent = other.vertexTangent;\r\n this.shininess = other.shininess;\r\n this.specularStrength = other.specularStrength;\r\n this.diffuseWrap = other.diffuseWrap;\r\n this.diffuseSoftness = other.diffuseSoftness;\r\n this.scatterWrap = other.scatterWrap;\r\n this.scatterStrength = other.scatterStrength;\r\n this.scatterColor = other.scatterColor;\r\n }\r\n\r\n /** true if vertex normal attribute presents */\r\n get vertexNormal() {\r\n return this.featureUsed<boolean>(SkinMaterial.FEATURE_VERTEX_NORMAL);\r\n }\r\n set vertexNormal(val) {\r\n this.useFeature(SkinMaterial.FEATURE_VERTEX_NORMAL, !!val);\r\n }\r\n\r\n /** true if vertex tangent attribute presents */\r\n get vertexTangent() {\r\n return this.featureUsed<boolean>(SkinMaterial.FEATURE_VERTEX_TANGENT);\r\n }\r\n set vertexTangent(val) {\r\n this.useFeature(SkinMaterial.FEATURE_VERTEX_TANGENT, !!val);\r\n }\r\n\r\n /** Blinn specular exponent. Higher values produce smaller highlights. */\r\n get shininess() {\r\n return this._shininess;\r\n }\r\n set shininess(val) {\r\n const next = Math.max(1, val ?? 1);\r\n if (next !== this._shininess) {\r\n this._shininess = next;\r\n this.uniformChanged();\r\n }\r\n }\r\n\r\n /** Direct specular strength. Keep this restrained for soft skin. */\r\n get specularStrength() {\r\n return this._specularStrength;\r\n }\r\n set specularStrength(val) {\r\n const next = Math.max(0, val ?? 0);\r\n if (next !== this._specularStrength) {\r\n this._specularStrength = next;\r\n this.uniformChanged();\r\n }\r\n }\r\n\r\n /** Wrap amount for visible diffuse lighting. */\r\n get diffuseWrap() {\r\n return this._diffuseWrap;\r\n }\r\n set diffuseWrap(val) {\r\n const next = Math.max(0, val ?? 0);\r\n if (next !== this._diffuseWrap) {\r\n this._diffuseWrap = next;\r\n this.uniformChanged();\r\n }\r\n }\r\n\r\n /** Blend from hard Lambert lighting to wrapped diffuse lighting. */\r\n get diffuseSoftness() {\r\n return this._diffuseSoftness;\r\n }\r\n set diffuseSoftness(val) {\r\n const next = Math.max(0, Math.min(1, val ?? 0));\r\n if (next !== this._diffuseSoftness) {\r\n this._diffuseSoftness = next;\r\n this.uniformChanged();\r\n }\r\n }\r\n\r\n /** Wider wrap used only for the post-process scattering source. */\r\n get scatterWrap() {\r\n return this._scatterWrap;\r\n }\r\n set scatterWrap(val) {\r\n const next = Math.max(0, val ?? 0);\r\n if (next !== this._scatterWrap) {\r\n this._scatterWrap = next;\r\n this.uniformChanged();\r\n }\r\n }\r\n\r\n /** Strength of the multiplier written into the SkinSSS side buffer. */\r\n get scatterStrength() {\r\n return this._scatterStrength;\r\n }\r\n set scatterStrength(val) {\r\n const next = Math.max(0, val ?? 0);\r\n if (next !== this._scatterStrength) {\r\n this._scatterStrength = next;\r\n this.uniformChanged();\r\n }\r\n }\r\n\r\n /** Warm tint for the blurred skin lighting contribution. */\r\n get scatterColor(): Immutable<Vector4> {\r\n return this._scatterColor;\r\n }\r\n set scatterColor(val: Immutable<Vector4>) {\r\n if (!val.equalsTo(this._scatterColor)) {\r\n this._scatterColor.set(val);\r\n this.uniformChanged();\r\n }\r\n }\r\n\r\n vertexShader(scope: PBFunctionScope) {\r\n super.vertexShader(scope);\r\n const pb = scope.$builder;\r\n scope.$l.oPos = ShaderHelper.resolveVertexPosition(scope);\r\n scope.$outputs.worldPos = pb.mul(ShaderHelper.getWorldMatrix(scope), pb.vec4(scope.oPos, 1)).xyz;\r\n ShaderHelper.setClipSpacePosition(\r\n scope,\r\n pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.worldPos, 1))\r\n );\r\n if (this.vertexNormal) {\r\n scope.$l.oNorm = ShaderHelper.resolveVertexNormal(scope);\r\n scope.$outputs.wNorm = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oNorm, 0)).xyz;\r\n if (this.vertexTangent) {\r\n scope.$l.oTangent = ShaderHelper.resolveVertexTangent(scope);\r\n scope.$outputs.wTangent = pb.mul(\r\n ShaderHelper.getNormalMatrix(scope),\r\n pb.vec4(scope.oTangent.xyz, 0)\r\n ).xyz;\r\n scope.$outputs.wBinormal = pb.mul(\r\n pb.cross(scope.$outputs.wNorm, scope.$outputs.wTangent),\r\n scope.oTangent.w\r\n );\r\n }\r\n }\r\n }\r\n\r\n fragmentShader(scope: PBFunctionScope) {\r\n super.fragmentShader(scope);\r\n const pb = scope.$builder;\r\n const that = this;\r\n if (this.needFragmentColorInput()) {\r\n if (this.drawContext.renderPass!.type === RENDER_PASS_TYPE_LIGHT) {\r\n scope.zSkinShininess = pb.float().uniform(2);\r\n scope.zSkinSpecularStrength = pb.float().uniform(2);\r\n scope.zSkinDiffuseWrap = pb.float().uniform(2);\r\n scope.zSkinDiffuseSoftness = pb.float().uniform(2);\r\n scope.zSkinScatterWrap = pb.float().uniform(2);\r\n scope.zSkinScatterStrength = pb.float().uniform(2);\r\n scope.zSkinScatterColor = pb.vec4().uniform(2);\r\n }\r\n scope.$l.albedo = this.calculateAlbedoColor(scope);\r\n if (this.vertexColor) {\r\n scope.albedo = pb.mul(scope.albedo, this.getVertexColor(scope));\r\n }\r\n if (this.drawContext.renderPass!.type === RENDER_PASS_TYPE_LIGHT) {\r\n const baseLightPass = !this.drawContext.lightBlending;\r\n scope.$l.normal = this.calculateNormal(\r\n scope,\r\n scope.$inputs.worldPos,\r\n scope.$inputs.wNorm,\r\n scope.$inputs.wTangent,\r\n scope.$inputs.wBinormal\r\n );\r\n scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);\r\n scope.$l.roughness = pb.sqrt(pb.div(2, pb.add(scope.zSkinShininess, 2)));\r\n scope.$l.skinMask = pb.float(1);\r\n scope.$l.skinSoftness = pb.float(0);\r\n if (this.subsurfaceTexture) {\r\n scope.$l.subsurfaceTexel = this.sampleSubsurfaceTexture(scope);\r\n scope.skinMask = pb.clamp(scope.subsurfaceTexel.r, 0, 1);\r\n scope.skinSoftness = pb.clamp(scope.subsurfaceTexel.g, 0, 1);\r\n }\r\n scope.$l.diffuseLighting = pb.vec3(0);\r\n scope.$l.scatterLighting = pb.vec3(0);\r\n scope.$l.specularLighting = pb.vec3(0);\r\n if (this.needCalculateEnvLight() && baseLightPass) {\r\n scope.$l.envDiffuse = this.getEnvLightIrradiance(scope, scope.normal);\r\n scope.diffuseLighting = pb.add(scope.diffuseLighting, scope.envDiffuse);\r\n scope.scatterLighting = pb.add(\r\n scope.scatterLighting,\r\n pb.mul(scope.envDiffuse, pb.add(0.7, pb.mul(scope.skinSoftness, 0.45)))\r\n );\r\n scope.$l.reflectVec = this.calculateReflectionVector(scope, scope.normal, scope.viewVec);\r\n scope.specularLighting = pb.add(\r\n scope.specularLighting,\r\n pb.mul(\r\n this.getEnvLightRadiance(scope, scope.reflectVec, scope.roughness),\r\n scope.zSkinSpecularStrength\r\n )\r\n );\r\n }\r\n this.forEachLight(scope, function (type, posRange, dirCutoff, colorIntensity, extra, shadow) {\r\n this.$l.diffuseScale = pb.float(1);\r\n this.$l.specularScale = pb.float(1);\r\n this.$l.sourceRadiusFactor = pb.float(0);\r\n this.$if(pb.equal(type, LIGHT_TYPE_POINT), function () {\r\n this.diffuseScale = extra.x;\r\n this.specularScale = extra.y;\r\n this.sourceRadiusFactor = pb.div(\r\n extra.z,\r\n pb.max(pb.distance(posRange.xyz, this.$inputs.worldPos), 0.0001)\r\n );\r\n });\r\n this.$l.lightAtten = that.calculateLightAttenuation(\r\n this,\r\n type,\r\n this.$inputs.worldPos,\r\n posRange,\r\n dirCutoff\r\n );\r\n this.$l.lightDir = that.calculateLightDirection(\r\n this,\r\n type,\r\n this.$inputs.worldPos,\r\n posRange,\r\n dirCutoff\r\n );\r\n this.$l.rawNoL = pb.dot(this.normal, this.lightDir);\r\n this.$l.NoL = pb.clamp(this.rawNoL, 0, 1);\r\n this.$l.NoLWrap = pb.clamp(\r\n pb.div(pb.add(this.rawNoL, this.zSkinDiffuseWrap), pb.add(1, this.zSkinDiffuseWrap)),\r\n 0,\r\n 1\r\n );\r\n this.$l.NoLScatter = pb.clamp(\r\n pb.div(pb.add(this.rawNoL, this.zSkinScatterWrap), pb.add(1, this.zSkinScatterWrap)),\r\n 0,\r\n 1\r\n );\r\n this.$l.shadowTerm = pb.float(1);\r\n if (shadow) {\r\n this.$if(pb.greaterThan(this.NoLWrap, 0), function () {\r\n this.shadowTerm = that.calculateShadow(this, this.$inputs.worldPos, pb.max(this.NoL, 1e-5));\r\n });\r\n }\r\n this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten, this.shadowTerm);\r\n this.$l.halfVec = pb.normalize(pb.add(this.viewVec, this.lightDir));\r\n this.$l.NoH = pb.clamp(pb.dot(this.normal, this.halfVec), 0, 1);\r\n this.$l.pointShininess = pb.max(\r\n pb.div(this.zSkinShininess, pb.add(1, pb.mul(this.sourceRadiusFactor, 32))),\r\n 1\r\n );\r\n this.$l.hardDiffuse = pb.mul(this.lightColor, this.NoL, this.diffuseScale, 1 / Math.PI);\r\n this.$l.softDiffuse = pb.mul(this.lightColor, this.NoLWrap, this.diffuseScale, 1 / Math.PI);\r\n this.$l.softness = pb.clamp(\r\n pb.add(this.zSkinDiffuseSoftness, pb.mul(this.skinSoftness, 0.35)),\r\n 0,\r\n 1\r\n );\r\n this.diffuseLighting = pb.add(\r\n this.diffuseLighting,\r\n pb.mix(this.hardDiffuse, this.softDiffuse, this.softness)\r\n );\r\n this.scatterLighting = pb.add(\r\n this.scatterLighting,\r\n pb.mul(\r\n this.lightColor,\r\n this.NoLScatter,\r\n pb.add(0.7, pb.mul(this.skinSoftness, 0.55)),\r\n this.diffuseScale,\r\n 1 / Math.PI\r\n )\r\n );\r\n this.$l.specular = pb.mul(\r\n this.lightColor,\r\n pb.pow(this.NoH, this.pointShininess),\r\n this.zSkinSpecularStrength,\r\n this.specularScale,\r\n this.NoLWrap\r\n );\r\n this.specularLighting = pb.add(this.specularLighting, this.specular);\r\n });\r\n scope.$l.litColor = pb.add(pb.mul(scope.albedo.rgb, scope.diffuseLighting), scope.specularLighting);\r\n scope.$l.scatterMultiplier = pb.add(\r\n baseLightPass ? pb.vec3(1) : pb.vec3(0),\r\n pb.mul(\r\n scope.albedo.rgb,\r\n scope.scatterLighting,\r\n scope.zSkinScatterColor.rgb,\r\n scope.zSkinScatterStrength,\r\n pb.add(0.75, pb.mul(scope.skinSoftness, 0.45))\r\n )\r\n );\r\n scope.$l.skinSSS = pb.vec4(scope.scatterMultiplier, scope.skinMask);\r\n if (this.drawContext.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {\r\n scope.$l.outRoughness = pb.vec4(\r\n pb.mul(scope.albedo.rgb, pb.sub(1, scope.roughness), scope.zSkinSpecularStrength),\r\n pb.mul(scope.roughness, ShaderHelper.getCameraRoughnessFactor(scope))\r\n );\r\n this.outputFragmentColor(\r\n scope,\r\n scope.$inputs.worldPos,\r\n pb.vec4(scope.litColor, scope.albedo.a),\r\n scope.outRoughness,\r\n pb.vec4(pb.add(pb.mul(scope.normal, 0.5), pb.vec3(0.5)), 1),\r\n undefined,\r\n undefined,\r\n undefined,\r\n undefined,\r\n false,\r\n scope.skinSSS\r\n );\r\n } else {\r\n this.outputFragmentColor(\r\n scope,\r\n scope.$inputs.worldPos,\r\n pb.vec4(scope.litColor, scope.albedo.a),\r\n undefined,\r\n undefined,\r\n undefined,\r\n undefined,\r\n undefined,\r\n undefined,\r\n false,\r\n scope.skinSSS\r\n );\r\n }\r\n } else {\r\n this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.albedo);\r\n }\r\n } else {\r\n this.outputFragmentColor(scope, scope.$inputs.worldPos, null);\r\n }\r\n }\r\n\r\n applyUniformValues(bindGroup: BindGroup, ctx: DrawContext, pass: number) {\r\n super.applyUniformValues(bindGroup, ctx, pass);\r\n if (this.needFragmentColor(ctx) && ctx.renderPass!.type === RENDER_PASS_TYPE_LIGHT) {\r\n bindGroup.setValue('zSkinShininess', this._shininess);\r\n bindGroup.setValue('zSkinSpecularStrength', this._specularStrength);\r\n bindGroup.setValue('zSkinDiffuseWrap', this._diffuseWrap);\r\n bindGroup.setValue('zSkinDiffuseSoftness', this._diffuseSoftness);\r\n bindGroup.setValue('zSkinScatterWrap', this._scatterWrap);\r\n bindGroup.setValue('zSkinScatterStrength', this._scatterStrength);\r\n bindGroup.setValue('zSkinScatterColor', this._scatterColor);\r\n }\r\n }\r\n}\r\n"],"names":["SkinMaterial","applyMaterialMixins","MeshMaterial","mixinLight","mixinVertexColor","mixinTextureProps","FEATURE_VERTEX_NORMAL","defineFeature","FEATURE_VERTEX_TANGENT","_shininess","_specularStrength","_diffuseWrap","_diffuseSoftness","_scatterWrap","_scatterStrength","_scatterColor","Vector4","useFeature","skinSSS","clone","other","copyFrom","vertexNormal","vertexTangent","shininess","specularStrength","diffuseWrap","diffuseSoftness","scatterWrap","scatterStrength","scatterColor","featureUsed","val","next","Math","max","uniformChanged","min","equalsTo","set","vertexShader","scope","pb","$builder","$l","oPos","ShaderHelper","resolveVertexPosition","$outputs","worldPos","mul","getWorldMatrix","vec4","xyz","setClipSpacePosition","getViewProjectionMatrix","oNorm","resolveVertexNormal","wNorm","getNormalMatrix","oTangent","resolveVertexTangent","wTangent","wBinormal","cross","w","fragmentShader","that","needFragmentColorInput","drawContext","renderPass","type","RENDER_PASS_TYPE_LIGHT","zSkinShininess","float","uniform","zSkinSpecularStrength","zSkinDiffuseWrap","zSkinDiffuseSoftness","zSkinScatterWrap","zSkinScatterStrength","zSkinScatterColor","albedo","calculateAlbedoColor","vertexColor","getVertexColor","baseLightPass","lightBlending","normal","calculateNormal","$inputs","viewVec","calculateViewVector","roughness","sqrt","div","add","skinMask","skinSoftness","subsurfaceTexture","subsurfaceTexel","sampleSubsurfaceTexture","clamp","r","g","diffuseLighting","vec3","scatterLighting","specularLighting","needCalculateEnvLight","envDiffuse","getEnvLightIrradiance","reflectVec","calculateReflectionVector","getEnvLightRadiance","forEachLight","posRange","dirCutoff","colorIntensity","extra","shadow","diffuseScale","specularScale","sourceRadiusFactor","$if","equal","LIGHT_TYPE_POINT","x","y","z","distance","lightAtten","calculateLightAttenuation","lightDir","calculateLightDirection","rawNoL","dot","NoL","NoLWrap","NoLScatter","shadowTerm","greaterThan","calculateShadow","lightColor","rgb","a","halfVec","normalize","NoH","pointShininess","hardDiffuse","PI","softDiffuse","softness","mix","specular","pow","litColor","scatterMultiplier","materialFlags","MaterialVaryingFlags","SSR_STORE_ROUGHNESS","outRoughness","sub","getCameraRoughnessFactor","outputFragmentColor","undefined","applyUniformValues","bindGroup","ct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CAAMyC,MAAM,CAAA;AACtE;SACK,MAAA;YACL,IAAI,CAACmF,mBAAmB,CAAC5H,KAAAA,EAAOA,MAAMiD,OAAO,CAACzC,QAAQ,EAAE,IAAA,CAAA;AAC1D;AACF;AAEAsH,IAAAA,kBAAAA,CAAmBC,SAAoB,EAAEC,GAAgB,EAAEC,IAAY,EAAE;QACvE,KAAK,CAACH,kBAAmBC,CAAAA,SAAAA,EAAWC,GAAKC,EAAAA,IAAAA,CAAAA;QACzC,IAAI,IAAI,CAACC,iBAAiB,CAACF,GAAAA,CAAAA,IAAQA,IAAInG,UAAU,CAAEC,IAAI,KAAKC,sBAAwB,EAAA;AAClFgG,YAAAA,SAAAA,CAAUI,QAAQ,CAAC,gBAAkB,EAAA,IAAI,CAACnK,UAAU,CAAA;AACpD+J,YAAAA,SAAAA,CAAUI,QAAQ,CAAC,uBAAyB,EAAA,IAAI,CAAClK,iBAAiB,CAAA;AAClE8J,YAAAA,SAAAA,CAAUI,QAAQ,CAAC,kBAAoB,EAAA,IAAI,CAACjK,YAAY,CAAA;AACxD6J,YAAAA,SAAAA,CAAUI,QAAQ,CAAC,sBAAwB,EAAA,IAAI,CAAChK,gBAAgB,CAAA;AAChE4J,YAAAA,SAAAA,CAAUI,QAAQ,CAAC,kBAAoB,EAAA,IAAI,CAAC/J,YAAY,CAAA;AACxD2J,YAAAA,SAAAA,CAAUI,QAAQ,CAAC,sBAAwB,EAAA,IAAI,CAAC9J,gBAAgB,CAAA;AAChE0J,YAAAA,SAAAA,CAAUI,QAAQ,CAAC,mBAAqB,EAAA,IAAI,CAAC7J,aAAa,CAAA;AAC5D;AACF;AACF;;;;"}
@@ -106,6 +106,9 @@ import { DRef } from '@zephyr3d/base';
106
106
  if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_TRANSMISSION) {
107
107
  attachments.push(ctx.SSSTransmissionTexture);
108
108
  }
109
+ if (ctx.materialFlags & MaterialVaryingFlags.SKIN_SSS_STORE) {
110
+ attachments.push(ctx.SkinSSSTexture);
111
+ }
109
112
  const tmpFramebuffer = device.pool.fetchTemporalFramebuffer(true, w, h, attachments.length === 1 ? attachments[0] : attachments, depth ?? ctx.depthFormat);
110
113
  device.setFramebuffer(tmpFramebuffer);
111
114
  }
@@ -1 +1 @@
1
- {"version":3,"file":"compositor.js","sources":["../../src/posteffect/compositor.ts"],"sourcesContent":["import { linearToGamma } from '../shaders/misc';\r\nimport type { DrawContext } from '../render';\r\nimport type {\r\n AbstractDevice,\r\n BindGroup,\r\n FrameBuffer,\r\n GPUProgram,\r\n RenderStateSet,\r\n Texture2D,\r\n TextureFormat,\r\n VertexLayout\r\n} from '@zephyr3d/device';\r\nimport type { AbstractPostEffect } from './posteffect';\r\nimport { PostEffectLayer } from './posteffect';\r\nimport { MaterialVaryingFlags } from '../values';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport { DRef } from '@zephyr3d/base';\r\n\r\n/**\r\n * Posteffect rendering context\r\n * @public\r\n */\r\nexport interface CompositorContext {\r\n pingpongFramebuffers: FrameBuffer[];\r\n finalFramebuffer: FrameBuffer;\r\n writeIndex: number;\r\n}\r\n/**\r\n * Post processing compositor\r\n * @public\r\n */\r\nexport class Compositor {\r\n /** @internal */\r\n protected _postEffects: DRef<AbstractPostEffect>[][];\r\n /** @internal */\r\n private _finalFramebuffer: Nullable<FrameBuffer>;\r\n /** @internal */\r\n private _prevInputTexture: Nullable<Texture2D>;\r\n /** @internal */\r\n private _prevFrameBuffer: Nullable<FrameBuffer>;\r\n /** @internal */\r\n private _textureFormat: TextureFormat;\r\n /** @internal */\r\n private static _blitProgram: Nullable<GPUProgram> = null;\r\n /** @internal */\r\n private static _blitBindgroup: Nullable<BindGroup> = null;\r\n /** @internal */\r\n private static _blitRenderStates: Nullable<RenderStateSet> = null;\r\n /** @internal */\r\n private static _blitVertexLayout: Nullable<VertexLayout> = null;\r\n /**\r\n * Creates an instance of Compositor\r\n */\r\n constructor() {\r\n this._postEffects = [];\r\n this._postEffects[PostEffectLayer.opaque] = [];\r\n this._postEffects[PostEffectLayer.transparent] = [];\r\n this._postEffects[PostEffectLayer.end] = [];\r\n this._finalFramebuffer = null;\r\n this._prevInputTexture = null;\r\n this._prevFrameBuffer = null;\r\n this._textureFormat = 'rgba16f';\r\n }\r\n /** @internal */\r\n requireLinearDepth(ctx: DrawContext) {\r\n for (const list of this._postEffects) {\r\n for (const postEffect of list) {\r\n if (postEffect.get()!.requireLinearDepthTexture(ctx)) {\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Adds a posteffect\r\n *\r\n * @param postEffect - The post effect to add\r\n * @param opaque - true if the post effect should be applied after the opaque pass and before the transparent pass, otherwise the post effect should be applied after the transparent pass\r\n */\r\n appendPostEffect(postEffect: AbstractPostEffect) {\r\n if (postEffect) {\r\n for (const list of this._postEffects) {\r\n if (list.findIndex((val) => val.get() === postEffect) >= 0) {\r\n console.error(`Posteffect cannot be added to same compositor multiple times`);\r\n return;\r\n }\r\n }\r\n this._postEffects[postEffect.layer].push(new DRef(postEffect));\r\n }\r\n }\r\n /**\r\n * Removes a posteffect that was previously added\r\n *\r\n * @param postEffect - The posteffect to be remove.\r\n */\r\n removePostEffect(postEffect: AbstractPostEffect) {\r\n for (const list of this._postEffects) {\r\n const index = list.findIndex((val) => val.get() === postEffect);\r\n if (index >= 0) {\r\n list[index].dispose();\r\n list.splice(index, 1);\r\n return;\r\n }\r\n }\r\n }\r\n /**\r\n * Removes all post effects\r\n */\r\n clear() {\r\n for (const list of this._postEffects) {\r\n for (const p of list) {\r\n p.dispose();\r\n }\r\n list.splice(0, list.length);\r\n }\r\n }\r\n /** @internal */\r\n begin(ctx: DrawContext) {\r\n const device = ctx.device;\r\n this._textureFormat =\r\n ctx.camera.HDR && device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer\r\n ? 'rgba16f'\r\n : 'rgba8unorm';\r\n this._finalFramebuffer = device.getFramebuffer();\r\n if (this._postEffects.every((list) => list.length === 0)) {\r\n return;\r\n }\r\n const depth = this._finalFramebuffer?.getDepthAttachment() as Texture2D;\r\n const w = depth ? depth.width : device.getDrawingBufferWidth();\r\n const h = depth ? depth.height : device.getDrawingBufferHeight();\r\n const attachments: any[] = [this._textureFormat];\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {\r\n attachments.push(ctx.SSRRoughnessTexture!, ctx.SSRNormalTexture!);\r\n } else if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_NORMAL) {\r\n attachments.push(ctx.SSRNormalTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_PROFILE) {\r\n attachments.push(ctx.SSSProfileTexture!, ctx.SSSParamTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_DIFFUSE) {\r\n attachments.push(ctx.SSSDiffuseTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_TRANSMISSION) {\r\n attachments.push(ctx.SSSTransmissionTexture!);\r\n }\r\n const tmpFramebuffer = device.pool.fetchTemporalFramebuffer(\r\n true,\r\n w,\r\n h,\r\n attachments.length === 1 ? attachments[0] : attachments,\r\n depth ?? ctx.depthFormat\r\n );\r\n device.setFramebuffer(tmpFramebuffer);\r\n }\r\n /** @internal */\r\n drawPostEffects(ctx: DrawContext, layer: PostEffectLayer, sceneDepthTexture: Texture2D) {\r\n const postEffects = this._postEffects[layer];\r\n if (postEffects.length > 0) {\r\n const device = ctx.device;\r\n const inputFramebuffer = device.getFramebuffer()!;\r\n const inputTexture = inputFramebuffer!.getColorAttachments()[0] as Texture2D;\r\n let tmpTexture: Nullable<Texture2D> = null;\r\n for (let i = 0; i < postEffects.length; i++) {\r\n const postEffect = postEffects[i].get()!;\r\n if (!postEffect.enabled) {\r\n continue;\r\n }\r\n if (this._prevFrameBuffer) {\r\n device.pool.releaseFrameBuffer(this._prevFrameBuffer);\r\n this._prevFrameBuffer = null;\r\n }\r\n const isLast = this.isLastPostEffect(layer, i);\r\n const finalEffect = isLast && (!postEffect.requireDepthAttachment(ctx) || !!this._finalFramebuffer);\r\n let singleColorFramebuffer: Nullable<FrameBuffer> = null;\r\n if (finalEffect) {\r\n singleColorFramebuffer = this.createSingleColorFramebuffer(\r\n device,\r\n this._finalFramebuffer,\r\n postEffect.requireDepthAttachment(ctx)\r\n );\r\n device.setFramebuffer(singleColorFramebuffer ?? this._finalFramebuffer);\r\n } else {\r\n this._prevFrameBuffer = device.pool.fetchTemporalFramebuffer(\r\n false,\r\n inputFramebuffer.getWidth(),\r\n inputFramebuffer.getHeight(),\r\n this._textureFormat,\r\n inputFramebuffer.getDepthAttachment() ?? null\r\n );\r\n device.setFramebuffer(this._prevFrameBuffer);\r\n }\r\n const inputColorTexture = tmpTexture ?? inputTexture;\r\n try {\r\n postEffect.apply(ctx, inputColorTexture, sceneDepthTexture, !device.getFramebuffer());\r\n } finally {\r\n if (singleColorFramebuffer) {\r\n device.setFramebuffer(this._finalFramebuffer);\r\n device.pool.releaseFrameBuffer(singleColorFramebuffer);\r\n }\r\n }\r\n if (this._prevInputTexture) {\r\n device.pool.releaseTexture(this._prevInputTexture);\r\n this._prevInputTexture = null;\r\n }\r\n if (this._prevFrameBuffer) {\r\n tmpTexture = this._prevFrameBuffer.getColorAttachments()[0] as Texture2D;\r\n device.pool.retainTexture(tmpTexture);\r\n this._prevInputTexture = tmpTexture;\r\n }\r\n }\r\n }\r\n }\r\n /** @internal */\r\n end(ctx: DrawContext) {\r\n const device = ctx.device;\r\n if (device.getFramebuffer() !== this._finalFramebuffer) {\r\n const srcTex = device.getFramebuffer()!.getColorAttachments()[0] as Texture2D;\r\n const singleColorFramebuffer = this.createSingleColorFramebuffer(device, this._finalFramebuffer, false);\r\n device.setFramebuffer(singleColorFramebuffer ?? this._finalFramebuffer);\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n try {\r\n Compositor._blit(device, srcTex, !this._finalFramebuffer);\r\n } finally {\r\n if (singleColorFramebuffer) {\r\n device.setFramebuffer(this._finalFramebuffer);\r\n device.pool.releaseFrameBuffer(singleColorFramebuffer);\r\n }\r\n }\r\n }\r\n if (this._prevInputTexture) {\r\n device.pool.releaseTexture(this._prevInputTexture);\r\n this._prevInputTexture = null;\r\n }\r\n if (this._prevFrameBuffer) {\r\n device.pool.releaseFrameBuffer(this._prevFrameBuffer);\r\n this._prevFrameBuffer = null;\r\n }\r\n }\r\n /** @internal */\r\n private isLastPostEffect(layer: PostEffectLayer, index: number) {\r\n for (let i = layer; i < this._postEffects.length; i++) {\r\n const start = i === layer ? index + 1 : 0;\r\n for (let j = start; j < this._postEffects[i].length; j++) {\r\n if (this._postEffects[i][j].get()!.enabled) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n /** @internal */\r\n private createSingleColorFramebuffer(\r\n device: AbstractDevice,\r\n framebuffer: Nullable<FrameBuffer>,\r\n withDepth: boolean\r\n ) {\r\n const colorAttachment = framebuffer?.getColorAttachments()[0] ?? null;\r\n if (!framebuffer || framebuffer.getColorAttachments().length <= 1 || !colorAttachment) {\r\n return null;\r\n }\r\n return device.pool.fetchTemporalFramebuffer(\r\n false,\r\n 0,\r\n 0,\r\n colorAttachment,\r\n withDepth ? framebuffer.getDepthAttachment() : null,\r\n false\r\n );\r\n }\r\n /** @internal */\r\n static _blit(device: AbstractDevice, srcTex: Texture2D, srgbOutput: boolean) {\r\n if (!this._blitProgram) {\r\n this._blitProgram = device.buildRenderProgram({\r\n vertex(pb) {\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n this.flip = pb.int().uniform(0);\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));\r\n this.$if(pb.notEqual(this.flip, 0), function () {\r\n this.$builtins.position.y = pb.neg(this.$builtins.position.y);\r\n });\r\n });\r\n },\r\n fragment(pb) {\r\n this.srcTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);\r\n this.srgbOutput = pb.int().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$outputs.outColor = pb.textureSample(this.srcTex, this.$inputs.uv);\r\n this.$if(pb.notEqual(this.srgbOutput, 0), function () {\r\n this.$outputs.outColor = pb.vec4(linearToGamma(this, this.$outputs.outColor.rgb), 1);\r\n });\r\n });\r\n }\r\n })!;\r\n this._blitProgram.name = '@Compositor_blit';\r\n this._blitBindgroup = device.createBindGroup(this._blitProgram.bindGroupLayouts[0]);\r\n this._blitVertexLayout = device.createVertexLayout({\r\n vertexBuffers: [\r\n {\r\n buffer: device.createVertexBuffer(\r\n 'position_f32x2',\r\n new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1])\r\n )!\r\n }\r\n ]\r\n });\r\n this._blitRenderStates = device.createRenderStateSet();\r\n this._blitRenderStates.useRasterizerState().setCullMode('none');\r\n this._blitRenderStates.useDepthState().enableTest(false).enableWrite(false);\r\n }\r\n this._blitBindgroup!.setTexture('srcTex', srcTex, fetchSampler('clamp_nearest_nomip'));\r\n this._blitBindgroup!.setValue('srgbOutput', srgbOutput ? 1 : 0);\r\n this._blitBindgroup!.setValue('flip', device.type === 'webgpu' && !!device.getFramebuffer() ? 1 : 0);\r\n device.setRenderStates(this._blitRenderStates);\r\n device.setProgram(this._blitProgram);\r\n device.setBindGroup(0, this._blitBindgroup!);\r\n device.setVertexLayout(this._blitVertexLayout);\r\n device.draw('triangle-strip', 0, 4);\r\n }\r\n}\r\n"],"names":["Compositor","_blitProgram","_blitBindgroup","_blitRenderStates","_blitVertexLayout","_postEffects","PostEffectLayer","opaque","transparent","end","_finalFramebuffer","_prevInputTexture","_prevFrameBuffer","_textureFormat","requireLinearDepth","ctx","list","postEffect","get","requireLinearDepthTexture","appendPostEffect","findIndex","val","console","error","layer","push","DRef","removePostEffect","index","dispose","splice","clear","p","length","begin","device","camera","HDR","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","getFramebuffer","every","depth","getDepthAttachment","w","width","getDrawingBufferWidth","h","height","getDrawingBufferHeight","attachments","materialFlags","MaterialVaryingFlags","SSR_STORE_ROUGHNESS","SSRRoughnessTexture","SSRNormalTexture","SSS_STORE_NORMAL","SSS_STORE_PROFILE","SSSProfileTexture","SSSParamTexture","SSS_STORE_DIFFUSE","SSSDiffuseTexture","SSS_STORE_TRANSMISSION","SSSTransmissionTexture","tmpFramebuffer","pool","fetchTemporalFramebuffer","depthFormat","setFramebuffer","drawPostEffects","sceneDepthTexture","postEffects","inputFramebuffer","inputTexture","getColorAttachments","tmpTexture","i","enabled","releaseFrameBuffer","isLast","isLastPostEffect","finalEffect","requireDepthAttachment","singleColorFramebuffer","createSingleColorFramebuffer","getWidth","getHeight","inputColorTexture","apply","releaseTexture","retainTexture","srcTex","setViewport","setScissor","_blit","start","j","framebuffer","withDepth","colorAttachment","srgbOutput","buildRenderProgram","vertex","pb","$inputs","pos","vec2","attrib","$outputs","uv","flip","int","uniform","main","$builtins","position","vec4","add","mul","xy","$if","notEqual","y","neg","fragment","tex2D","sampleType","outColor","textureSample","linearToGamma","rgb","name","createBindGroup","bindGroupLayouts","createVertexLayout","vertexBuffers","buffer","createVertexBuffer","Float32Array","createRenderStateSet","useRasterizerState","setCullMode","useDepthState","enableTest","enableWrite","setTexture","fetchSampler","setValue","type","setRenderStates","setProgram","setBindGroup","setVertexLayout","draw"],"mappings":";;;;;;AA4BA;;;AAGC,IACM,MAAMA,UAAAA,CAAAA;qBAEX,YAAqD;qBAErD,iBAAiD;qBAEjD,iBAA+C;qBAE/C,gBAAgD;qBAEhD,cAAsC;qBAEtC,OAAeC,YAAAA,GAAqC,IAAK;qBAEzD,OAAeC,cAAAA,GAAsC,IAAK;qBAE1D,OAAeC,iBAAAA,GAA8C,IAAK;qBAElE,OAAeC,iBAAAA,GAA4C,IAAK;AAChE;;AAEC,MACD,WAAc,EAAA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linearToGamma } from '../shaders/misc';\r\nimport type { DrawContext } from '../render';\r\nimport type {\r\n AbstractDevice,\r\n BindGroup,\r\n FrameBuffer,\r\n GPUProgram,\r\n RenderStateSet,\r\n Texture2D,\r\n TextureFormat,\r\n VertexLayout\r\n} from '@zephyr3d/device';\r\nimport type { AbstractPostEffect } from './posteffect';\r\nimport { PostEffectLayer } from './posteffect';\r\nimport { MaterialVaryingFlags } from '../values';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport type { Nullable } from '@zephyr3d/base';\r\nimport { DRef } from '@zephyr3d/base';\r\n\r\n/**\r\n * Posteffect rendering context\r\n * @public\r\n */\r\nexport interface CompositorContext {\r\n pingpongFramebuffers: FrameBuffer[];\r\n finalFramebuffer: FrameBuffer;\r\n writeIndex: number;\r\n}\r\n/**\r\n * Post processing compositor\r\n * @public\r\n */\r\nexport class Compositor {\r\n /** @internal */\r\n protected _postEffects: DRef<AbstractPostEffect>[][];\r\n /** @internal */\r\n private _finalFramebuffer: Nullable<FrameBuffer>;\r\n /** @internal */\r\n private _prevInputTexture: Nullable<Texture2D>;\r\n /** @internal */\r\n private _prevFrameBuffer: Nullable<FrameBuffer>;\r\n /** @internal */\r\n private _textureFormat: TextureFormat;\r\n /** @internal */\r\n private static _blitProgram: Nullable<GPUProgram> = null;\r\n /** @internal */\r\n private static _blitBindgroup: Nullable<BindGroup> = null;\r\n /** @internal */\r\n private static _blitRenderStates: Nullable<RenderStateSet> = null;\r\n /** @internal */\r\n private static _blitVertexLayout: Nullable<VertexLayout> = null;\r\n /**\r\n * Creates an instance of Compositor\r\n */\r\n constructor() {\r\n this._postEffects = [];\r\n this._postEffects[PostEffectLayer.opaque] = [];\r\n this._postEffects[PostEffectLayer.transparent] = [];\r\n this._postEffects[PostEffectLayer.end] = [];\r\n this._finalFramebuffer = null;\r\n this._prevInputTexture = null;\r\n this._prevFrameBuffer = null;\r\n this._textureFormat = 'rgba16f';\r\n }\r\n /** @internal */\r\n requireLinearDepth(ctx: DrawContext) {\r\n for (const list of this._postEffects) {\r\n for (const postEffect of list) {\r\n if (postEffect.get()!.requireLinearDepthTexture(ctx)) {\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n }\r\n /**\r\n * Adds a posteffect\r\n *\r\n * @param postEffect - The post effect to add\r\n * @param opaque - true if the post effect should be applied after the opaque pass and before the transparent pass, otherwise the post effect should be applied after the transparent pass\r\n */\r\n appendPostEffect(postEffect: AbstractPostEffect) {\r\n if (postEffect) {\r\n for (const list of this._postEffects) {\r\n if (list.findIndex((val) => val.get() === postEffect) >= 0) {\r\n console.error(`Posteffect cannot be added to same compositor multiple times`);\r\n return;\r\n }\r\n }\r\n this._postEffects[postEffect.layer].push(new DRef(postEffect));\r\n }\r\n }\r\n /**\r\n * Removes a posteffect that was previously added\r\n *\r\n * @param postEffect - The posteffect to be remove.\r\n */\r\n removePostEffect(postEffect: AbstractPostEffect) {\r\n for (const list of this._postEffects) {\r\n const index = list.findIndex((val) => val.get() === postEffect);\r\n if (index >= 0) {\r\n list[index].dispose();\r\n list.splice(index, 1);\r\n return;\r\n }\r\n }\r\n }\r\n /**\r\n * Removes all post effects\r\n */\r\n clear() {\r\n for (const list of this._postEffects) {\r\n for (const p of list) {\r\n p.dispose();\r\n }\r\n list.splice(0, list.length);\r\n }\r\n }\r\n /** @internal */\r\n begin(ctx: DrawContext) {\r\n const device = ctx.device;\r\n this._textureFormat =\r\n ctx.camera.HDR && device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer\r\n ? 'rgba16f'\r\n : 'rgba8unorm';\r\n this._finalFramebuffer = device.getFramebuffer();\r\n if (this._postEffects.every((list) => list.length === 0)) {\r\n return;\r\n }\r\n const depth = this._finalFramebuffer?.getDepthAttachment() as Texture2D;\r\n const w = depth ? depth.width : device.getDrawingBufferWidth();\r\n const h = depth ? depth.height : device.getDrawingBufferHeight();\r\n const attachments: any[] = [this._textureFormat];\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {\r\n attachments.push(ctx.SSRRoughnessTexture!, ctx.SSRNormalTexture!);\r\n } else if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_NORMAL) {\r\n attachments.push(ctx.SSRNormalTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_PROFILE) {\r\n attachments.push(ctx.SSSProfileTexture!, ctx.SSSParamTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_DIFFUSE) {\r\n attachments.push(ctx.SSSDiffuseTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_TRANSMISSION) {\r\n attachments.push(ctx.SSSTransmissionTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SKIN_SSS_STORE) {\r\n attachments.push(ctx.SkinSSSTexture!);\r\n }\r\n const tmpFramebuffer = device.pool.fetchTemporalFramebuffer(\r\n true,\r\n w,\r\n h,\r\n attachments.length === 1 ? attachments[0] : attachments,\r\n depth ?? ctx.depthFormat\r\n );\r\n device.setFramebuffer(tmpFramebuffer);\r\n }\r\n /** @internal */\r\n drawPostEffects(ctx: DrawContext, layer: PostEffectLayer, sceneDepthTexture: Texture2D) {\r\n const postEffects = this._postEffects[layer];\r\n if (postEffects.length > 0) {\r\n const device = ctx.device;\r\n const inputFramebuffer = device.getFramebuffer()!;\r\n const inputTexture = inputFramebuffer!.getColorAttachments()[0] as Texture2D;\r\n let tmpTexture: Nullable<Texture2D> = null;\r\n for (let i = 0; i < postEffects.length; i++) {\r\n const postEffect = postEffects[i].get()!;\r\n if (!postEffect.enabled) {\r\n continue;\r\n }\r\n if (this._prevFrameBuffer) {\r\n device.pool.releaseFrameBuffer(this._prevFrameBuffer);\r\n this._prevFrameBuffer = null;\r\n }\r\n const isLast = this.isLastPostEffect(layer, i);\r\n const finalEffect = isLast && (!postEffect.requireDepthAttachment(ctx) || !!this._finalFramebuffer);\r\n let singleColorFramebuffer: Nullable<FrameBuffer> = null;\r\n if (finalEffect) {\r\n singleColorFramebuffer = this.createSingleColorFramebuffer(\r\n device,\r\n this._finalFramebuffer,\r\n postEffect.requireDepthAttachment(ctx)\r\n );\r\n device.setFramebuffer(singleColorFramebuffer ?? this._finalFramebuffer);\r\n } else {\r\n this._prevFrameBuffer = device.pool.fetchTemporalFramebuffer(\r\n false,\r\n inputFramebuffer.getWidth(),\r\n inputFramebuffer.getHeight(),\r\n this._textureFormat,\r\n inputFramebuffer.getDepthAttachment() ?? null\r\n );\r\n device.setFramebuffer(this._prevFrameBuffer);\r\n }\r\n const inputColorTexture = tmpTexture ?? inputTexture;\r\n try {\r\n postEffect.apply(ctx, inputColorTexture, sceneDepthTexture, !device.getFramebuffer());\r\n } finally {\r\n if (singleColorFramebuffer) {\r\n device.setFramebuffer(this._finalFramebuffer);\r\n device.pool.releaseFrameBuffer(singleColorFramebuffer);\r\n }\r\n }\r\n if (this._prevInputTexture) {\r\n device.pool.releaseTexture(this._prevInputTexture);\r\n this._prevInputTexture = null;\r\n }\r\n if (this._prevFrameBuffer) {\r\n tmpTexture = this._prevFrameBuffer.getColorAttachments()[0] as Texture2D;\r\n device.pool.retainTexture(tmpTexture);\r\n this._prevInputTexture = tmpTexture;\r\n }\r\n }\r\n }\r\n }\r\n /** @internal */\r\n end(ctx: DrawContext) {\r\n const device = ctx.device;\r\n if (device.getFramebuffer() !== this._finalFramebuffer) {\r\n const srcTex = device.getFramebuffer()!.getColorAttachments()[0] as Texture2D;\r\n const singleColorFramebuffer = this.createSingleColorFramebuffer(device, this._finalFramebuffer, false);\r\n device.setFramebuffer(singleColorFramebuffer ?? this._finalFramebuffer);\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n try {\r\n Compositor._blit(device, srcTex, !this._finalFramebuffer);\r\n } finally {\r\n if (singleColorFramebuffer) {\r\n device.setFramebuffer(this._finalFramebuffer);\r\n device.pool.releaseFrameBuffer(singleColorFramebuffer);\r\n }\r\n }\r\n }\r\n if (this._prevInputTexture) {\r\n device.pool.releaseTexture(this._prevInputTexture);\r\n this._prevInputTexture = null;\r\n }\r\n if (this._prevFrameBuffer) {\r\n device.pool.releaseFrameBuffer(this._prevFrameBuffer);\r\n this._prevFrameBuffer = null;\r\n }\r\n }\r\n /** @internal */\r\n private isLastPostEffect(layer: PostEffectLayer, index: number) {\r\n for (let i = layer; i < this._postEffects.length; i++) {\r\n const start = i === layer ? index + 1 : 0;\r\n for (let j = start; j < this._postEffects[i].length; j++) {\r\n if (this._postEffects[i][j].get()!.enabled) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n /** @internal */\r\n private createSingleColorFramebuffer(\r\n device: AbstractDevice,\r\n framebuffer: Nullable<FrameBuffer>,\r\n withDepth: boolean\r\n ) {\r\n const colorAttachment = framebuffer?.getColorAttachments()[0] ?? null;\r\n if (!framebuffer || framebuffer.getColorAttachments().length <= 1 || !colorAttachment) {\r\n return null;\r\n }\r\n return device.pool.fetchTemporalFramebuffer(\r\n false,\r\n 0,\r\n 0,\r\n colorAttachment,\r\n withDepth ? framebuffer.getDepthAttachment() : null,\r\n false\r\n );\r\n }\r\n /** @internal */\r\n static _blit(device: AbstractDevice, srcTex: Texture2D, srgbOutput: boolean) {\r\n if (!this._blitProgram) {\r\n this._blitProgram = device.buildRenderProgram({\r\n vertex(pb) {\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n this.flip = pb.int().uniform(0);\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);\r\n this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));\r\n this.$if(pb.notEqual(this.flip, 0), function () {\r\n this.$builtins.position.y = pb.neg(this.$builtins.position.y);\r\n });\r\n });\r\n },\r\n fragment(pb) {\r\n this.srcTex = pb.tex2D().sampleType('unfilterable-float').uniform(0);\r\n this.srgbOutput = pb.int().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.main(function () {\r\n this.$outputs.outColor = pb.textureSample(this.srcTex, this.$inputs.uv);\r\n this.$if(pb.notEqual(this.srgbOutput, 0), function () {\r\n this.$outputs.outColor = pb.vec4(linearToGamma(this, this.$outputs.outColor.rgb), 1);\r\n });\r\n });\r\n }\r\n })!;\r\n this._blitProgram.name = '@Compositor_blit';\r\n this._blitBindgroup = device.createBindGroup(this._blitProgram.bindGroupLayouts[0]);\r\n this._blitVertexLayout = device.createVertexLayout({\r\n vertexBuffers: [\r\n {\r\n buffer: device.createVertexBuffer(\r\n 'position_f32x2',\r\n new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1])\r\n )!\r\n }\r\n ]\r\n });\r\n this._blitRenderStates = device.createRenderStateSet();\r\n this._blitRenderStates.useRasterizerState().setCullMode('none');\r\n this._blitRenderStates.useDepthState().enableTest(false).enableWrite(false);\r\n }\r\n this._blitBindgroup!.setTexture('srcTex', srcTex, fetchSampler('clamp_nearest_nomip'));\r\n this._blitBindgroup!.setValue('srgbOutput', srgbOutput ? 1 : 0);\r\n this._blitBindgroup!.setValue('flip', device.type === 'webgpu' && !!device.getFramebuffer() ? 1 : 0);\r\n device.setRenderStates(this._blitRenderStates);\r\n device.setProgram(this._blitProgram);\r\n device.setBindGroup(0, this._blitBindgroup!);\r\n device.setVertexLayout(this._blitVertexLayout);\r\n device.draw('triangle-strip', 0, 4);\r\n }\r\n}\r\n"],"names":["Compositor","_blitProgram","_blitBindgroup","_blitRenderStates","_blitVertexLayout","_postEffects","PostEffectLayer","opaque","transparent","end","_finalFramebuffer","_prevInputTexture","_prevFrameBuffer","_textureFormat","requireLinearDepth","ctx","list","postEffect","get","requireLinearDepthTexture","appendPostEffect","findIndex","val","console","error","layer","push","DRef","removePostEffect","index","dispose","splice","clear","p","length","begin","device","camera","HDR","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","getFramebuffer","every","depth","getDepthAttachment","w","width","getDrawingBufferWidth","h","height","getDrawingBufferHeight","attachments","materialFlags","MaterialVaryingFlags","SSR_STORE_ROUGHNESS","SSRRoughnessTexture","SSRNormalTexture","SSS_STORE_NORMAL","SSS_STORE_PROFILE","SSSProfileTexture","SSSParamTexture","SSS_STORE_DIFFUSE","SSSDiffuseTexture","SSS_STORE_TRANSMISSION","SSSTransmissionTexture","SKIN_SSS_STORE","SkinSSSTexture","tmpFramebuffer","pool","fetchTemporalFramebuffer","depthFormat","setFramebuffer","drawPostEffects","sceneDepthTexture","postEffects","inputFramebuffer","inputTexture","getColorAttachments","tmpTexture","i","enabled","releaseFrameBuffer","isLast","isLastPostEffect","finalEffect","requireDepthAttachment","singleColorFramebuffer","createSingleColorFramebuffer","getWidth","getHeight","inputColorTexture","apply","releaseTexture","retainTexture","srcTex","setViewport","setScissor","_blit","start","j","framebuffer","withDepth","colorAttachment","srgbOutput","buildRenderProgram","vertex","pb","$inputs","pos","vec2","attrib","$outputs","uv","flip","int","uniform","main","$builtins","position","vec4","add","mul","xy","$if","notEqual","y","neg","fragment","tex2D","sampleType","outColor","textureSample","linearToGamma","rgb","name","createBindGroup","bindGroupLayouts","createVertexLayout","vertexBuffers","buffer","createVertexBuffer","Float32Array","createRenderStateSet","useRasterizerState","setCullMode","useDepthState","enableTest","enableWrite","setTexture","fetchSampler","setValue","type","setRenderStates","setProgram","setBindGroup","setVertexLayout","draw"],"mappings":";;;;;;AA4BA;;;AAGC,IACM,MAAMA,UAAAA,CAAAA;qBAEX,YAAqD;qBAErD,iBAAiD;qBAEjD,iBAA+C;qBAE/C,gBAAgD;qBAEhD,cAAsC;qBAEtC,OAAeC,YAAAA,GAAqC,IAAK;qBAEzD,OAAeC,cAAAA,GAAsC,IAAK;qBAE1D,OAAeC,iBAAAA,GAA8C,IAAK;qBAElE,OAAeC,iBAAAA,GAA4C,IAAK;AAChE;;AAEC,MACD,WAAc,EAAA;QACZ,IAAI,CAACC,YAAY,GAAG,EAAE;AACtB,QAAA,IAAI,CAACA,YAAY,CAACC,gBAAgBC,MAAM,CAAC,GAAG,EAAE;AAC9C,QA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