@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.
- package/dist/assets/{index-BZ1L8ggE.js → index-CO6yA4Rj.js} +313 -11
- package/dist/assistant/zephyr-types-index.json +13834 -11679
- package/dist/index.html +1 -1
- package/dist/modules/zephyr3d_backend-webgpu.js +1 -1
- package/dist/modules/zephyr3d_backend-webgpu.js.map +1 -1
- package/dist/modules/zephyr3d_device.js +2 -2
- package/dist/modules/zephyr3d_device.js.map +1 -1
- package/dist/modules/zephyr3d_scene.js +2325 -515
- package/dist/modules/zephyr3d_scene.js.map +1 -1
- package/dist/vendor/zephyr3d/backend-webgpu/dist/renderpass_webgpu.js +1 -1
- package/dist/vendor/zephyr3d/backend-webgpu/dist/renderpass_webgpu.js.map +1 -1
- package/dist/vendor/zephyr3d/device/dist/device.js +2 -2
- package/dist/vendor/zephyr3d/device/dist/device.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/app/engine.js +3 -1
- package/dist/vendor/zephyr3d/scene/dist/app/engine.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/asset/assetmanager.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/asset/assetmanager.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/camera/camera.js +87 -0
- package/dist/vendor/zephyr3d/scene/dist/camera/camera.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/index.d.ts +158 -4
- package/dist/vendor/zephyr3d/scene/dist/index.js +3 -0
- package/dist/vendor/zephyr3d/scene/dist/index.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/material/meshmaterial.js +8 -1
- package/dist/vendor/zephyr3d/scene/dist/material/meshmaterial.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/material/shader/helper.js +6 -0
- package/dist/vendor/zephyr3d/scene/dist/material/shader/helper.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/material/skin.js +263 -0
- package/dist/vendor/zephyr3d/scene/dist/material/skin.js.map +1 -0
- package/dist/vendor/zephyr3d/scene/dist/posteffect/compositor.js +3 -0
- package/dist/vendor/zephyr3d/scene/dist/posteffect/compositor.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/posteffect/skinsss.js +194 -0
- package/dist/vendor/zephyr3d/scene/dist/posteffect/skinsss.js.map +1 -0
- package/dist/vendor/zephyr3d/scene/dist/posteffect/ssr.js +26 -49
- package/dist/vendor/zephyr3d/scene/dist/posteffect/ssr.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/posteffect/sss.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/posteffect/sss.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/posteffect/taa.js +2 -40
- package/dist/vendor/zephyr3d/scene/dist/posteffect/taa.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/abuffer_oit.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/render/abuffer_oit.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/drawable_mixin.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/render/drawable_mixin.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/fbm_wavegenerator.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/gerstner_wavegenerator.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/globalbindgroup_allocator.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/lightpass.js +4 -1
- package/dist/vendor/zephyr3d/scene/dist/render/lightpass.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/render_queue.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/render/render_queue.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/renderer.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/render/renderer.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/device_pool_allocator.js +12 -5
- package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/forward_plus_builder.js +78 -8
- package/dist/vendor/zephyr3d/scene/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/basesprite.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/basesprite.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/batchgroup.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/batchgroup.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/environment.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/environment.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/light.js +158 -154
- package/dist/vendor/zephyr3d/scene/dist/scene/light.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/mesh.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/mesh.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/msdftext.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/msdftext.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/msdftextsprite.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/particlesys.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/particlesys.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/scene.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/scene.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grass.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grassmaterial.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/terrain-cm.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/scene/water.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/scene/water.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shaders/shadow.js +617 -1
- package/dist/vendor/zephyr3d/scene/dist/shaders/shadow.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shadow/esm.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/shadow/esm.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_opt.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_pd.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shadow/pcss.js +182 -0
- package/dist/vendor/zephyr3d/scene/dist/shadow/pcss.js.map +1 -0
- package/dist/vendor/zephyr3d/scene/dist/shadow/shader.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/shadow/shader.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shadow/shadowmapper.js +183 -105
- package/dist/vendor/zephyr3d/scene/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shadow/ssm.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/shadow/ssm.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/shadow/vsm.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/shadow/vsm.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/manager.js +3 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/manager.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/batch.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js +122 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/common.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/light.js +102 -21
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/material.js +195 -3
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/mesh.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/particle.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/primitive.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/sprite.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/terrain.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/text.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/water.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/vendor/zephyr3d/scene/dist/values.js +1 -0
- package/dist/vendor/zephyr3d/scene/dist/values.js.map +1 -1
- package/electron/main.cjs +30 -6
- package/package.json +4 -4
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Vector2, Vector4 } from '@zephyr3d/base';
|
|
2
|
+
import { ShaderHelper } from '../material/shader/helper.js';
|
|
3
|
+
import '../material/lambert.js';
|
|
4
|
+
import '../material/blinn.js';
|
|
5
|
+
import '../material/unlit.js';
|
|
6
|
+
import '../material/particle.js';
|
|
7
|
+
import '../material/subsurfaceprofile.js';
|
|
8
|
+
import '../material/skin.js';
|
|
9
|
+
import '@zephyr3d/device';
|
|
10
|
+
import '../values.js';
|
|
11
|
+
import '../material/meshmaterial.js';
|
|
12
|
+
import '../material/grassmaterial.js';
|
|
13
|
+
import '../material/terrain-cm.js';
|
|
14
|
+
import '../material/pbrmr.js';
|
|
15
|
+
import '../material/pbrsg.js';
|
|
16
|
+
import '../material/mtoon.js';
|
|
17
|
+
import '../material/pbrblueprint.js';
|
|
18
|
+
import '../material/sprite.js';
|
|
19
|
+
import '../material/sprite_std.js';
|
|
20
|
+
import '../utility/blueprint/material/texture.js';
|
|
21
|
+
import { linearToGamma } from '../shaders/misc.js';
|
|
22
|
+
import { fetchSampler } from '../utility/misc.js';
|
|
23
|
+
import { AbstractPostEffect, PostEffectLayer } from './posteffect.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Stylized screen-space skin scattering pass.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* This is intentionally separate from the profile-based {@link SSS} pass. It follows the simpler
|
|
30
|
+
* depth-aware blur used by many character renderers: a skin material writes a lighting multiplier
|
|
31
|
+
* into a side buffer, then this pass performs a fixed 9x9 depth-aware blur and composites it back
|
|
32
|
+
* over the opaque color.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/ class SkinSSS extends AbstractPostEffect {
|
|
36
|
+
static _program = null;
|
|
37
|
+
_bindGroup;
|
|
38
|
+
_strength;
|
|
39
|
+
_opacity;
|
|
40
|
+
_sampleStep;
|
|
41
|
+
_depthScale;
|
|
42
|
+
_colorBoost;
|
|
43
|
+
constructor(){
|
|
44
|
+
super();
|
|
45
|
+
this._layer = PostEffectLayer.opaque;
|
|
46
|
+
this._bindGroup = null;
|
|
47
|
+
this._strength = 1;
|
|
48
|
+
this._opacity = 0.18;
|
|
49
|
+
this._sampleStep = 2;
|
|
50
|
+
this._depthScale = 80;
|
|
51
|
+
this._colorBoost = 1;
|
|
52
|
+
}
|
|
53
|
+
/** Final blend strength. */ get strength() {
|
|
54
|
+
return this._strength;
|
|
55
|
+
}
|
|
56
|
+
set strength(val) {
|
|
57
|
+
this._strength = Math.max(0, val ?? 0);
|
|
58
|
+
}
|
|
59
|
+
/** Bias subtracted from the blurred skin mask before compositing. */ get opacity() {
|
|
60
|
+
return this._opacity;
|
|
61
|
+
}
|
|
62
|
+
set opacity(val) {
|
|
63
|
+
this._opacity = Math.max(0, Math.min(1, val ?? 0));
|
|
64
|
+
}
|
|
65
|
+
/** Pixel spacing between blur taps. The reference shader uses 2. */ get sampleStep() {
|
|
66
|
+
return this._sampleStep;
|
|
67
|
+
}
|
|
68
|
+
set sampleStep(val) {
|
|
69
|
+
this._sampleStep = Math.max(0.25, val ?? 0.25);
|
|
70
|
+
}
|
|
71
|
+
/** Depth rejection scale. The reference shader uses 80. */ get depthScale() {
|
|
72
|
+
return this._depthScale;
|
|
73
|
+
}
|
|
74
|
+
set depthScale(val) {
|
|
75
|
+
this._depthScale = Math.max(0, val ?? 0);
|
|
76
|
+
}
|
|
77
|
+
/** Multiplier applied to the blurred skin lighting multiplier before compositing. */ get colorBoost() {
|
|
78
|
+
return this._colorBoost;
|
|
79
|
+
}
|
|
80
|
+
set colorBoost(val) {
|
|
81
|
+
this._colorBoost = Math.max(0, val ?? 0);
|
|
82
|
+
}
|
|
83
|
+
requireLinearDepthTexture() {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
87
|
+
if (!ctx.SkinSSSTexture || this._strength <= 0) {
|
|
88
|
+
this.passThrough(ctx, inputColorTexture, srgbOutput);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const device = ctx.device;
|
|
92
|
+
let program = SkinSSS._program;
|
|
93
|
+
if (!program) {
|
|
94
|
+
program = this.createProgram(ctx);
|
|
95
|
+
SkinSSS._program = program;
|
|
96
|
+
}
|
|
97
|
+
if (!this._bindGroup) {
|
|
98
|
+
this._bindGroup = device.createBindGroup(program.bindGroupLayouts[0]);
|
|
99
|
+
}
|
|
100
|
+
this._bindGroup.setTexture('colorTex', inputColorTexture, fetchSampler('clamp_linear'));
|
|
101
|
+
this._bindGroup.setTexture('skinTex', ctx.SkinSSSTexture, fetchSampler('clamp_linear'));
|
|
102
|
+
this._bindGroup.setTexture('depthTex', sceneDepthTexture, fetchSampler('clamp_nearest_nomip'));
|
|
103
|
+
this._bindGroup.setValue('cameraNearFar', new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane()));
|
|
104
|
+
this._bindGroup.setValue('targetSize', new Vector4(inputColorTexture.width, inputColorTexture.height, inputColorTexture.width, inputColorTexture.height));
|
|
105
|
+
this._bindGroup.setValue('strength', this._strength);
|
|
106
|
+
this._bindGroup.setValue('opacity', this._opacity);
|
|
107
|
+
this._bindGroup.setValue('sampleStep', this._sampleStep);
|
|
108
|
+
this._bindGroup.setValue('depthScale', this._depthScale);
|
|
109
|
+
this._bindGroup.setValue('colorBoost', this._colorBoost);
|
|
110
|
+
this._bindGroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
111
|
+
this._bindGroup.setValue('srgbOut', srgbOutput ? 1 : 0);
|
|
112
|
+
device.setProgram(program);
|
|
113
|
+
device.setBindGroup(0, this._bindGroup);
|
|
114
|
+
this.drawFullscreenQuad();
|
|
115
|
+
}
|
|
116
|
+
createProgram(ctx) {
|
|
117
|
+
const program = ctx.device.buildRenderProgram({
|
|
118
|
+
vertex (pb) {
|
|
119
|
+
this.flip = pb.int().uniform(0);
|
|
120
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
121
|
+
this.$outputs.uv = pb.vec2();
|
|
122
|
+
pb.main(function() {
|
|
123
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
|
|
124
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
125
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
126
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
fragment (pb) {
|
|
131
|
+
this.colorTex = pb.tex2D().uniform(0);
|
|
132
|
+
this.skinTex = pb.tex2D().uniform(0);
|
|
133
|
+
this.depthTex = pb.tex2D().uniform(0);
|
|
134
|
+
this.cameraNearFar = pb.vec2().uniform(0);
|
|
135
|
+
this.targetSize = pb.vec4().uniform(0);
|
|
136
|
+
this.strength = pb.float().uniform(0);
|
|
137
|
+
this.opacity = pb.float().uniform(0);
|
|
138
|
+
this.sampleStep = pb.float().uniform(0);
|
|
139
|
+
this.depthScale = pb.float().uniform(0);
|
|
140
|
+
this.colorBoost = pb.float().uniform(0);
|
|
141
|
+
this.srgbOut = pb.int().uniform(0);
|
|
142
|
+
this.$outputs.outColor = pb.vec4();
|
|
143
|
+
pb.func('readDepth01', [
|
|
144
|
+
pb.vec2('uv')
|
|
145
|
+
], function() {
|
|
146
|
+
this.$return(ShaderHelper.sampleLinearDepth(this, this.depthTex, this.uv, 0));
|
|
147
|
+
});
|
|
148
|
+
pb.main(function() {
|
|
149
|
+
this.$l.uv = this.$inputs.uv;
|
|
150
|
+
this.$l.baseColor = pb.textureSampleLevel(this.colorTex, this.uv, 0);
|
|
151
|
+
this.$l.result = this.baseColor.rgb;
|
|
152
|
+
this.$l.centerDepth01 = this.readDepth01(this.uv);
|
|
153
|
+
this.$if(pb.lessThan(this.centerDepth01, 1), function() {
|
|
154
|
+
this.$l.centerDepth = pb.max(pb.mul(this.centerDepth01, this.cameraNearFar.y), 1e-4);
|
|
155
|
+
this.$l.sum = pb.vec4(0);
|
|
156
|
+
this.$l.weightSum = pb.float(0);
|
|
157
|
+
this.$for(pb.int('y'), -4, 5, function() {
|
|
158
|
+
this.$for(pb.int('x'), -4, 5, function() {
|
|
159
|
+
this.$l.offsetPx = pb.mul(pb.vec2(pb.float(this.x), pb.float(this.y)), this.sampleStep);
|
|
160
|
+
this.$l.sampleUV = pb.clamp(pb.add(this.uv, pb.div(this.offsetPx, this.targetSize.xy)), pb.vec2(0), pb.vec2(1));
|
|
161
|
+
this.$l.skinSample = pb.textureSampleLevel(this.skinTex, this.sampleUV, 0);
|
|
162
|
+
this.$if(pb.lessThanEqual(this.skinSample.a, 1e-4), function() {
|
|
163
|
+
this.skinSample = pb.vec4(0, 0, 0, this.opacity);
|
|
164
|
+
});
|
|
165
|
+
this.$l.sampleDepth01 = this.readDepth01(this.sampleUV);
|
|
166
|
+
this.$l.sampleDepth = pb.max(pb.mul(this.sampleDepth01, this.cameraNearFar.y), 1e-4);
|
|
167
|
+
this.$l.depthWeight = pb.clamp(pb.sub(1, pb.div(pb.mul(pb.abs(pb.sub(this.centerDepth, this.sampleDepth)), this.depthScale), this.centerDepth)), 0, 1);
|
|
168
|
+
this.depthWeight = pb.mul(this.depthWeight, this.depthWeight, pb.sub(3, pb.mul(this.depthWeight, 2)));
|
|
169
|
+
this.sum = pb.add(this.sum, pb.mul(this.skinSample, this.depthWeight));
|
|
170
|
+
this.weightSum = pb.add(this.weightSum, this.depthWeight);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
this.$if(pb.greaterThan(this.weightSum, 1e-4), function() {
|
|
174
|
+
this.$l.blurredSkin = pb.div(this.sum, this.weightSum);
|
|
175
|
+
this.$l.alphaDelta = pb.sub(this.blurredSkin.a, this.opacity);
|
|
176
|
+
this.$l.referenceLit = pb.mul(this.baseColor.rgb, pb.add(pb.vec3(pb.sub(1, this.alphaDelta)), pb.mul(this.blurredSkin.rgb, pb.max(pb.sub(1, this.opacity), 0), this.colorBoost)));
|
|
177
|
+
this.result = pb.add(this.baseColor.rgb, pb.mul(pb.sub(this.referenceLit, this.baseColor.rgb), this.strength));
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
this.$if(pb.equal(this.srgbOut, 0), function() {
|
|
181
|
+
this.$outputs.outColor = pb.vec4(this.result, this.baseColor.a);
|
|
182
|
+
}).$else(function() {
|
|
183
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.result), this.baseColor.a);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
program.name = '@SkinSSS';
|
|
189
|
+
return program;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { SkinSSS };
|
|
194
|
+
//# sourceMappingURL=skinsss.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skinsss.js","sources":["../../src/posteffect/skinsss.ts"],"sourcesContent":["import { Vector2, Vector4 } from '@zephyr3d/base';\r\nimport type { BindGroup, GPUProgram, Texture2D } from '@zephyr3d/device';\r\nimport type { DrawContext } from '../render';\r\nimport { ShaderHelper } from '../material';\r\nimport { linearToGamma } from '../shaders/misc';\r\nimport { fetchSampler } from '../utility/misc';\r\nimport { AbstractPostEffect, PostEffectLayer } from './posteffect';\r\n\r\n/**\r\n * Stylized screen-space skin scattering pass.\r\n *\r\n * @remarks\r\n * This is intentionally separate from the profile-based {@link SSS} pass. It follows the simpler\r\n * depth-aware blur used by many character renderers: a skin material writes a lighting multiplier\r\n * into a side buffer, then this pass performs a fixed 9x9 depth-aware blur and composites it back\r\n * over the opaque color.\r\n *\r\n * @public\r\n */\r\nexport class SkinSSS extends AbstractPostEffect {\r\n private static _program: GPUProgram | null = null;\r\n private _bindGroup: BindGroup | null;\r\n private _strength: number;\r\n private _opacity: number;\r\n private _sampleStep: number;\r\n private _depthScale: number;\r\n private _colorBoost: number;\r\n\r\n constructor() {\r\n super();\r\n this._layer = PostEffectLayer.opaque;\r\n this._bindGroup = null;\r\n this._strength = 1;\r\n this._opacity = 0.18;\r\n this._sampleStep = 2;\r\n this._depthScale = 80;\r\n this._colorBoost = 1;\r\n }\r\n\r\n /** Final blend strength. */\r\n get strength() {\r\n return this._strength;\r\n }\r\n set strength(val) {\r\n this._strength = Math.max(0, val ?? 0);\r\n }\r\n\r\n /** Bias subtracted from the blurred skin mask before compositing. */\r\n get opacity() {\r\n return this._opacity;\r\n }\r\n set opacity(val) {\r\n this._opacity = Math.max(0, Math.min(1, val ?? 0));\r\n }\r\n\r\n /** Pixel spacing between blur taps. The reference shader uses 2. */\r\n get sampleStep() {\r\n return this._sampleStep;\r\n }\r\n set sampleStep(val) {\r\n this._sampleStep = Math.max(0.25, val ?? 0.25);\r\n }\r\n\r\n /** Depth rejection scale. The reference shader uses 80. */\r\n get depthScale() {\r\n return this._depthScale;\r\n }\r\n set depthScale(val) {\r\n this._depthScale = Math.max(0, val ?? 0);\r\n }\r\n\r\n /** Multiplier applied to the blurred skin lighting multiplier before compositing. */\r\n get colorBoost() {\r\n return this._colorBoost;\r\n }\r\n set colorBoost(val) {\r\n this._colorBoost = Math.max(0, val ?? 0);\r\n }\r\n\r\n requireLinearDepthTexture() {\r\n return true;\r\n }\r\n\r\n apply(ctx: DrawContext, inputColorTexture: Texture2D, sceneDepthTexture: Texture2D, srgbOutput: boolean) {\r\n if (!ctx.SkinSSSTexture || this._strength <= 0) {\r\n this.passThrough(ctx, inputColorTexture, srgbOutput);\r\n return;\r\n }\r\n const device = ctx.device;\r\n let program = SkinSSS._program;\r\n if (!program) {\r\n program = this.createProgram(ctx);\r\n SkinSSS._program = program;\r\n }\r\n if (!this._bindGroup) {\r\n this._bindGroup = device.createBindGroup(program.bindGroupLayouts[0]);\r\n }\r\n this._bindGroup.setTexture('colorTex', inputColorTexture, fetchSampler('clamp_linear'));\r\n this._bindGroup.setTexture('skinTex', ctx.SkinSSSTexture, fetchSampler('clamp_linear'));\r\n this._bindGroup.setTexture('depthTex', sceneDepthTexture, fetchSampler('clamp_nearest_nomip'));\r\n this._bindGroup.setValue('cameraNearFar', new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane()));\r\n this._bindGroup.setValue(\r\n 'targetSize',\r\n new Vector4(inputColorTexture.width, inputColorTexture.height, inputColorTexture.width, inputColorTexture.height)\r\n );\r\n this._bindGroup.setValue('strength', this._strength);\r\n this._bindGroup.setValue('opacity', this._opacity);\r\n this._bindGroup.setValue('sampleStep', this._sampleStep);\r\n this._bindGroup.setValue('depthScale', this._depthScale);\r\n this._bindGroup.setValue('colorBoost', this._colorBoost);\r\n this._bindGroup.setValue('flip', this.needFlip(device) ? 1 : 0);\r\n this._bindGroup.setValue('srgbOut', srgbOutput ? 1 : 0);\r\n device.setProgram(program);\r\n device.setBindGroup(0, this._bindGroup);\r\n this.drawFullscreenQuad();\r\n }\r\n\r\n private createProgram(ctx: DrawContext) {\r\n const program = ctx.device.buildRenderProgram({\r\n vertex(pb) {\r\n this.flip = pb.int().uniform(0);\r\n this.$inputs.pos = pb.vec2().attrib('position');\r\n this.$outputs.uv = pb.vec2();\r\n pb.main(function () {\r\n this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 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.colorTex = pb.tex2D().uniform(0);\r\n this.skinTex = pb.tex2D().uniform(0);\r\n this.depthTex = pb.tex2D().uniform(0);\r\n this.cameraNearFar = pb.vec2().uniform(0);\r\n this.targetSize = pb.vec4().uniform(0);\r\n this.strength = pb.float().uniform(0);\r\n this.opacity = pb.float().uniform(0);\r\n this.sampleStep = pb.float().uniform(0);\r\n this.depthScale = pb.float().uniform(0);\r\n this.colorBoost = pb.float().uniform(0);\r\n this.srgbOut = pb.int().uniform(0);\r\n this.$outputs.outColor = pb.vec4();\r\n pb.func('readDepth01', [pb.vec2('uv')], function () {\r\n this.$return(ShaderHelper.sampleLinearDepth(this, this.depthTex, this.uv, 0));\r\n });\r\n pb.main(function () {\r\n this.$l.uv = this.$inputs.uv;\r\n this.$l.baseColor = pb.textureSampleLevel(this.colorTex, this.uv, 0);\r\n this.$l.result = this.baseColor.rgb;\r\n this.$l.centerDepth01 = this.readDepth01(this.uv);\r\n this.$if(pb.lessThan(this.centerDepth01, 1), function () {\r\n this.$l.centerDepth = pb.max(pb.mul(this.centerDepth01, this.cameraNearFar.y), 1e-4);\r\n this.$l.sum = pb.vec4(0);\r\n this.$l.weightSum = pb.float(0);\r\n this.$for(pb.int('y'), -4, 5, function () {\r\n this.$for(pb.int('x'), -4, 5, function () {\r\n this.$l.offsetPx = pb.mul(pb.vec2(pb.float(this.x), pb.float(this.y)), this.sampleStep);\r\n this.$l.sampleUV = pb.clamp(\r\n pb.add(this.uv, pb.div(this.offsetPx, this.targetSize.xy)),\r\n pb.vec2(0),\r\n pb.vec2(1)\r\n );\r\n this.$l.skinSample = pb.textureSampleLevel(this.skinTex, this.sampleUV, 0);\r\n this.$if(pb.lessThanEqual(this.skinSample.a, 1e-4), function () {\r\n this.skinSample = pb.vec4(0, 0, 0, this.opacity);\r\n });\r\n this.$l.sampleDepth01 = this.readDepth01(this.sampleUV);\r\n this.$l.sampleDepth = pb.max(pb.mul(this.sampleDepth01, this.cameraNearFar.y), 1e-4);\r\n this.$l.depthWeight = pb.clamp(\r\n pb.sub(\r\n 1,\r\n pb.div(\r\n pb.mul(pb.abs(pb.sub(this.centerDepth, this.sampleDepth)), this.depthScale),\r\n this.centerDepth\r\n )\r\n ),\r\n 0,\r\n 1\r\n );\r\n this.depthWeight = pb.mul(\r\n this.depthWeight,\r\n this.depthWeight,\r\n pb.sub(3, pb.mul(this.depthWeight, 2))\r\n );\r\n this.sum = pb.add(this.sum, pb.mul(this.skinSample, this.depthWeight));\r\n this.weightSum = pb.add(this.weightSum, this.depthWeight);\r\n });\r\n });\r\n this.$if(pb.greaterThan(this.weightSum, 1e-4), function () {\r\n this.$l.blurredSkin = pb.div(this.sum, this.weightSum);\r\n this.$l.alphaDelta = pb.sub(this.blurredSkin.a, this.opacity);\r\n this.$l.referenceLit = pb.mul(\r\n this.baseColor.rgb,\r\n pb.add(\r\n pb.vec3(pb.sub(1, this.alphaDelta)),\r\n pb.mul(this.blurredSkin.rgb, pb.max(pb.sub(1, this.opacity), 0), this.colorBoost)\r\n )\r\n );\r\n this.result = pb.add(\r\n this.baseColor.rgb,\r\n pb.mul(pb.sub(this.referenceLit, this.baseColor.rgb), this.strength)\r\n );\r\n });\r\n });\r\n this.$if(pb.equal(this.srgbOut, 0), function () {\r\n this.$outputs.outColor = pb.vec4(this.result, this.baseColor.a);\r\n }).$else(function () {\r\n this.$outputs.outColor = pb.vec4(linearToGamma(this, this.result), this.baseColor.a);\r\n });\r\n });\r\n }\r\n })!;\r\n program.name = '@SkinSSS';\r\n return program;\r\n }\r\n}\r\n"],"names":["SkinSSS","AbstractPostEffect","_program","_bindGroup","_strength","_opacity","_sampleStep","_depthScale","_colorBoost","_layer","PostEffectLayer","opaque","strength","val","Math","max","opacity","min","sampleStep","depthScale","colorBoost","requireLinearDepthTexture","apply","ctx","inputColorTexture","sceneDepthTexture","srgbOutput","SkinSSSTexture","passThrough","device","program","createProgram","createBindGroup","bindGroupLayouts","setTexture","fetchSampler","setValue","Vector2","camera","getNearPlane","getFarPlane","Vector4","width","height","needFlip","setProgram","setBindGroup","drawFullscreenQuad","buildRenderProgram","vertex","pb","flip","int","uniform","$inputs","pos","vec2","attrib","$outputs","uv","main","$builtins","position","vec4","add","mul","xy","$if","notEqual","y","neg","fragment","colorTex","tex2D","skinTex","depthTex","cameraNearFar","targetSize","float","srgbOut","outColor","func","$return","ShaderHelper","sampleLinearDepth","$l","baseColor","textureSampleLevel","result","rgb","centerDepth01","readDepth01","lessThan","centerDepth","sum","weightSum","$for","offsetPx","x","sampleUV","clamp","div","skinSample","lessThanEqual","a","sampleDepth01","sampleDepth","depthWeight","sub","abs","greaterThan","blurredSkin","alphaDelta","referenceLit","vec3","equal","$else","linearToGamma","name"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAQA;;;;;;;;;;IAWO,MAAMA,OAAgBC,SAAAA,kBAAAA,CAAAA;AAC3B,IAAA,OAAeC,WAA8B,IAAK;IAC1CC,UAA6B;IAC7BC,SAAkB;IAClBC,QAAiB;IACjBC,WAAoB;IACpBC,WAAoB;IACpBC,WAAoB;IAE5B,WAAc,EAAA;QACZ,KAAK,EAAA;AACL,QAAA,IAAI,CAACC,MAAM,GAAGC,eAAAA,CAAgBC,MAAM;QACpC,IAAI,CAACR,UAAU,GAAG,IAAA;QAClB,IAAI,CAACC,SAAS,GAAG,CAAA;QACjB,IAAI,CAACC,QAAQ,GAAG,IAAA;QAChB,IAAI,CAACC,WAAW,GAAG,CAAA;QACnB,IAAI,CAACC,WAAW,GAAG,EAAA;QACnB,IAAI,CAACC,WAAW,GAAG,CAAA;AACrB;iCAGA,IAAII,QAAW,GAAA;QACb,OAAO,IAAI,CAACR,SAAS;AACvB;I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AAG0D,CAAAA,GAAG,CAAC,CAAA,EAAG,IAAI,CAAC5F,OAAO,CAAG,EAAA,CAAA,CAAA,EAAI,IAAI,CAACI,UAAU,CAAA,CAAA,CAAA;AAGpF,4BAAA,IAAI,CAACoE,MAAM,GAAGtC,EAAAA,CAAGc,GAAG,CAClB,IAAI,CAACsB,SAAS,CAACG,GAAG,EAClBvC,GAAGe,GAAG,CAACf,EAAG0D,CAAAA,GAAG,CAAC,IAAI,CAACK,YAAY,EAAE,IAAI,CAAC3B,SAAS,CAACG,GAAG,CAAG,EAAA,IAAI,CAAC7E,QAAQ,CAAA,CAAA;AAEvE,yBAAA,CAAA;AACF,qBAAA,CAAA;oBACA,IAAI,CAACuD,GAAG,CAACjB,EAAGiE,CAAAA,KAAK,CAAC,IAAI,CAACpC,OAAO,EAAE,CAAI,CAAA,EAAA,WAAA;AAClC,wBAAA,IAAI,CAACrB,QAAQ,CAACsB,QAAQ,GAAG9B,GAAGa,IAAI,CAAC,IAAI,CAACyB,MAAM,EAAE,IAAI,CAACF,SAAS,CAACkB,CAAC,CAAA;AAChE,qBAAA,CAAA,CAAGY,KAAK,CAAC,WAAA;AACP,wBAAA,IAAI,CAAC1D,QAAQ,CAACsB,QAAQ,GAAG9B,EAAAA,CAAGa,IAAI,CAACsD,aAAAA,CAAc,IAAI,EAAE,IAAI,CAAC7B,MAAM,CAAA,EAAG,IAAI,CAACF,SAAS,CAACkB,CAAC,CAAA;AACrF,qBAAA,CAAA;AACF,iBAAA,CAAA;AACF;AACF,SAAA,CAAA;AACA1E,QAAAA,OAAAA,CAAQwF,IAAI,GAAG,UAAA;QACf,OAAOxF,OAAAA;AACT;AACF;;;;"}
|
|
@@ -12,6 +12,7 @@ import '../material/blinn.js';
|
|
|
12
12
|
import '../material/unlit.js';
|
|
13
13
|
import '../material/particle.js';
|
|
14
14
|
import '../material/subsurfaceprofile.js';
|
|
15
|
+
import '../material/skin.js';
|
|
15
16
|
import '@zephyr3d/device';
|
|
16
17
|
import '../values.js';
|
|
17
18
|
import '../material/meshmaterial.js';
|
|
@@ -261,11 +262,9 @@ import { RGHistoryResources } from '../render/rendergraph/history_resources.js';
|
|
|
261
262
|
this.blurPass(ctx, blitterV, intersectTex, 2, blurSizeScale, kernelRadius, stdDev, depthCutoff, pingpongFramebuffer[1], pingpongFramebuffer[0]);
|
|
262
263
|
}
|
|
263
264
|
const historyManager = ctx.camera.getHistoryResourceManager();
|
|
264
|
-
const useGraphHistory = !!historyManager?.frameActive;
|
|
265
|
-
const history = useGraphHistory ? null : ctx.camera.getHistoryData();
|
|
266
265
|
let reflectanceTex = pingpongFramebuffer[0].getColorAttachments()[0];
|
|
267
|
-
const prevSSRReflectTex =
|
|
268
|
-
const prevSSRMotionVectorTex =
|
|
266
|
+
const prevSSRReflectTex = historyManager.tryGetPrevious(RGHistoryResources.SSR_REFLECT);
|
|
267
|
+
const prevSSRMotionVectorTex = historyManager.tryGetPrevious(RGHistoryResources.SSR_MOTION_VECTOR);
|
|
269
268
|
const canTemporal = ctx.camera.ssrTemporal && !!ctx.motionVectorTexture && !!prevSSRReflectTex && !!prevSSRMotionVectorTex && prevSSRReflectTex.width === reflectanceTex.width && prevSSRReflectTex.height === reflectanceTex.height;
|
|
270
269
|
if (canTemporal) {
|
|
271
270
|
this.temporal(ctx, reflectanceTex, sceneDepthTexture, prevSSRReflectTex, prevSSRMotionVectorTex, pingpongFramebuffer[1]);
|
|
@@ -273,51 +272,29 @@ import { RGHistoryResources } from '../render/rendergraph/history_resources.js';
|
|
|
273
272
|
}
|
|
274
273
|
device.popDeviceStates();
|
|
275
274
|
this.combine(ctx, inputColorTexture, reflectanceTex, srgbOutput);
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}, motionVectorSize, ctx.motionVectorTexture);
|
|
300
|
-
}
|
|
301
|
-
} else {
|
|
302
|
-
if (history.prevSSRReflectTex) {
|
|
303
|
-
device.pool.releaseTexture(history.prevSSRReflectTex);
|
|
304
|
-
history.prevSSRReflectTex = null;
|
|
305
|
-
}
|
|
306
|
-
if (history.prevSSRMotionVectorTex) {
|
|
307
|
-
device.pool.releaseTexture(history.prevSSRMotionVectorTex);
|
|
308
|
-
history.prevSSRMotionVectorTex = null;
|
|
309
|
-
}
|
|
310
|
-
if (ctx.camera.ssrTemporal) {
|
|
311
|
-
device.pool.retainTexture(reflectanceTex);
|
|
312
|
-
history.prevSSRReflectTex = reflectanceTex;
|
|
313
|
-
}
|
|
314
|
-
if (ctx.camera.ssrTemporal && ctx.motionVectorTexture) {
|
|
315
|
-
if (history.prevSSRMotionVectorTex) {
|
|
316
|
-
device.pool.releaseTexture(history.prevSSRMotionVectorTex);
|
|
317
|
-
}
|
|
318
|
-
device.pool.retainTexture(ctx.motionVectorTexture);
|
|
319
|
-
history.prevSSRMotionVectorTex = ctx.motionVectorTexture;
|
|
320
|
-
}
|
|
275
|
+
if (ctx.camera.ssrTemporal) {
|
|
276
|
+
const reflectanceSize = {
|
|
277
|
+
width: reflectanceTex.width,
|
|
278
|
+
height: reflectanceTex.height
|
|
279
|
+
};
|
|
280
|
+
historyManager.queueRetainedCommit(RGHistoryResources.SSR_REFLECT, {
|
|
281
|
+
format: reflectanceTex.format,
|
|
282
|
+
sizeMode: 'absolute',
|
|
283
|
+
width: reflectanceTex.width,
|
|
284
|
+
height: reflectanceTex.height
|
|
285
|
+
}, reflectanceSize, reflectanceTex);
|
|
286
|
+
}
|
|
287
|
+
if (ctx.camera.ssrTemporal && ctx.motionVectorTexture) {
|
|
288
|
+
const motionVectorSize = {
|
|
289
|
+
width: ctx.motionVectorTexture.width,
|
|
290
|
+
height: ctx.motionVectorTexture.height
|
|
291
|
+
};
|
|
292
|
+
historyManager.queueRetainedCommit(RGHistoryResources.SSR_MOTION_VECTOR, {
|
|
293
|
+
format: ctx.motionVectorTexture.format,
|
|
294
|
+
sizeMode: 'absolute',
|
|
295
|
+
width: ctx.motionVectorTexture.width,
|
|
296
|
+
height: ctx.motionVectorTexture.height
|
|
297
|
+
}, motionVectorSize, ctx.motionVectorTexture);
|
|
321
298
|
}
|
|
322
299
|
device.pool.releaseFrameBuffer(intersectFramebuffer);
|
|
323
300
|
device.pool.releaseFrameBuffer(pingpongFramebuffer[0]);
|