@zephyr3d/scene 0.9.6 → 0.9.8
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/animation/animationset.js +52 -55
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/joint_dynamics/controller.js +92 -32
- package/dist/animation/joint_dynamics/controller.js.map +1 -1
- package/dist/animation/joint_dynamics/convex_collider.js +320 -0
- package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
- package/dist/animation/joint_dynamics/solver.js +71 -27
- package/dist/animation/joint_dynamics/solver.js.map +1 -1
- package/dist/animation/joint_dynamics_modifier.js +4 -3
- package/dist/animation/joint_dynamics_modifier.js.map +1 -1
- package/dist/animation/skeleton.js +7 -10
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/app/engine.js +3 -9
- package/dist/app/engine.js.map +1 -1
- package/dist/app/scriptregistry.js +47 -16
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +3 -1
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/model.js +346 -7
- package/dist/asset/model.js.map +1 -1
- package/dist/avatar/wardrobe.js +7 -3
- package/dist/avatar/wardrobe.js.map +1 -1
- package/dist/camera/camera.js +240 -34
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +1350 -622
- package/dist/index.js +6 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +1 -1
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +1 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +23 -1
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +178 -23
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +4 -4
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +2 -1
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +100 -27
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +1 -1
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +276 -65
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/mixins/texture.js +3 -3
- package/dist/material/mixins/texture.js.map +1 -1
- package/dist/material/mixins/vertexcolor.js +2 -2
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/mtoon.js +574 -0
- package/dist/material/mtoon.js.map +1 -0
- package/dist/material/pbrblueprint.js +494 -331
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +118 -100
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +1 -1
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +45 -15
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/subsurfaceprofile.js +812 -0
- package/dist/material/subsurfaceprofile.js.map +1 -0
- package/dist/material/unlit.js +1 -1
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/compositor.js +46 -11
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/ssr.js +413 -87
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +1053 -0
- package/dist/posteffect/sss.js.map +1 -0
- package/dist/posteffect/taa.js +61 -60
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +63 -12
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/cluster_light.js +6 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/drawable.js +1 -5
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/drawable_mixin.js +2 -1
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +2 -1
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +2 -1
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +2 -1
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/lightpass.js +105 -18
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +51 -8
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +73 -59
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +8 -0
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +481 -95
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +55 -0
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
- package/dist/render/rendergraph/history_resources.js +3 -1
- package/dist/render/rendergraph/history_resources.js.map +1 -1
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/renderpass.js +10 -4
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/sky.js +31 -1
- package/dist/render/sky.js.map +1 -1
- package/dist/render/weightedblended_oit.js +23 -5
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/basesprite.js +4 -2
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +3 -1
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +11 -1
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +21 -3
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +29 -14
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/meshdrawable.js +6 -0
- package/dist/scene/meshdrawable.js.map +1 -1
- package/dist/scene/msdftext.js +5 -2
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +5 -3
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +3 -1
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +6 -5
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +4 -2
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grassmaterial.js +2 -1
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +4 -2
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +4 -2
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +26 -393
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +112 -12
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +2 -2
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +19 -10
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/shader.js +58 -7
- package/dist/shadow/shader.js.map +1 -1
- package/dist/shadow/shadow_impl.js +6 -0
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadow_region.js +229 -0
- package/dist/shadow/shadow_region.js.map +1 -0
- package/dist/shadow/shadowmapper.js +67 -59
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +45 -19
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/blueprint/common/constants.js +8 -8
- package/dist/utility/blueprint/common/constants.js.map +1 -1
- package/dist/utility/blueprint/material/pbr.js +31 -4
- package/dist/utility/blueprint/material/pbr.js.map +1 -1
- package/dist/utility/blueprint/material/texture.js +1 -17
- package/dist/utility/blueprint/material/texture.js.map +1 -1
- package/dist/utility/serialization/manager.js +66 -98
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +5 -2
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +4 -1
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +249 -54
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +37 -1
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +42 -3
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +1112 -646
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +7 -4
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +31 -12
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +4 -1
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +3 -1
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +18 -0
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +6 -3
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +5 -2
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +3 -1
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +4 -1
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/textures/ltcdata.js +6 -0
- package/dist/utility/textures/ltcdata.js.map +1 -0
- package/dist/utility/textures/ltclut.js +61 -0
- package/dist/utility/textures/ltclut.js.map +1 -0
- package/dist/values.js +9 -1
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,1053 @@
|
|
|
1
|
+
import { Vector2, Vector4, Matrix4x4 } 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 { SubsurfaceProfile } from '../material/subsurfaceprofile.js';
|
|
8
|
+
import '@zephyr3d/device';
|
|
9
|
+
import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, LIGHT_TYPE_RECT } from '../values.js';
|
|
10
|
+
import '../material/meshmaterial.js';
|
|
11
|
+
import '../material/grassmaterial.js';
|
|
12
|
+
import '../material/terrain-cm.js';
|
|
13
|
+
import '../material/pbrmr.js';
|
|
14
|
+
import '../material/pbrsg.js';
|
|
15
|
+
import '../material/mtoon.js';
|
|
16
|
+
import '../material/pbrblueprint.js';
|
|
17
|
+
import '../material/sprite.js';
|
|
18
|
+
import '../material/sprite_std.js';
|
|
19
|
+
import '../utility/blueprint/material/texture.js';
|
|
20
|
+
import { linearToGamma } from '../shaders/misc.js';
|
|
21
|
+
import { fetchSampler } from '../utility/misc.js';
|
|
22
|
+
import { AbstractPostEffect, PostEffectLayer } from './posteffect.js';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Screen-space subsurface scattering post effect.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* Uses a depth/normal-aware separable blur driven by per-pixel SSS profiles
|
|
29
|
+
* written by skin materials during the main shading pass.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/ class SSS extends AbstractPostEffect {
|
|
33
|
+
static _profileLUTWidth = 256;
|
|
34
|
+
static _profileLUTHeight = 7;
|
|
35
|
+
static _profileRadiusEncodeMax = 8;
|
|
36
|
+
static _profileWorldScaleEncodeMax = 4;
|
|
37
|
+
static _profileNormalScaleEncodeMax = 2;
|
|
38
|
+
static _profileExtinctionEncodeMax = 4;
|
|
39
|
+
static _debugViewMap = {
|
|
40
|
+
none: 0,
|
|
41
|
+
scatter_mask: 1,
|
|
42
|
+
scatter_softness: 2,
|
|
43
|
+
scatter_radius: 3,
|
|
44
|
+
scatter_falloff: 4,
|
|
45
|
+
profile_energy: 5,
|
|
46
|
+
profile_transmission: 6,
|
|
47
|
+
profile_boundary: 7,
|
|
48
|
+
diffuse: 8,
|
|
49
|
+
blur: 9,
|
|
50
|
+
screen_thinness: 10,
|
|
51
|
+
thin_transmission_mask: 11,
|
|
52
|
+
thin_lighting: 12,
|
|
53
|
+
transmission_shadow: 13
|
|
54
|
+
};
|
|
55
|
+
static _blurPrograms = {};
|
|
56
|
+
static _combinePrograms = {};
|
|
57
|
+
static _profileLUT = null;
|
|
58
|
+
static _profileLUTVersion = -1;
|
|
59
|
+
_blurBindGroups;
|
|
60
|
+
_combineBindGroups;
|
|
61
|
+
constructor(){
|
|
62
|
+
super();
|
|
63
|
+
this._layer = PostEffectLayer.opaque;
|
|
64
|
+
this._blurBindGroups = {};
|
|
65
|
+
this._combineBindGroups = {};
|
|
66
|
+
}
|
|
67
|
+
static profileRowV(row) {
|
|
68
|
+
return (row + 0.5) / SSS._profileLUTHeight;
|
|
69
|
+
}
|
|
70
|
+
getCombineShadowLight(ctx) {
|
|
71
|
+
const shadowMapInfo = ctx.shadowMapInfo;
|
|
72
|
+
if (!shadowMapInfo) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const mainDirectionalLight = ctx.sunLight ?? ctx.primaryDirectionalLight;
|
|
76
|
+
if (mainDirectionalLight && shadowMapInfo.has(mainDirectionalLight)) {
|
|
77
|
+
return mainDirectionalLight;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
getCombineProgramKey(ctx, shadowLight) {
|
|
82
|
+
const shadowMapParams = shadowLight ? ctx.shadowMapInfo?.get(shadowLight) : null;
|
|
83
|
+
return shadowMapParams?.shaderHash ? `shadow:${shadowMapParams.shaderHash}` : 'default';
|
|
84
|
+
}
|
|
85
|
+
requireLinearDepthTexture() {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
requireDepthAttachment() {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
apply(ctx, inputColorTexture, sceneDepthTexture, srgbOutput) {
|
|
92
|
+
const device = ctx.device;
|
|
93
|
+
const outputFramebuffer = device.getFramebuffer();
|
|
94
|
+
const sssSettings = ctx.camera.sssResolvedSettings;
|
|
95
|
+
if (!ctx.SSS || !ctx.SSSProfileTexture || !ctx.SSSParamTexture || ctx.camera.sssStrength <= 0 || ctx.camera.sssBlurScale <= 0 && ctx.camera.sssTransmissionStrength <= 0) {
|
|
96
|
+
this.passThrough(ctx, inputColorTexture, srgbOutput);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const kernelRadius = Math.max(1, sssSettings.blurKernelSize >> 0) - 1 >> 1;
|
|
100
|
+
const blurEnabled = ctx.camera.sssBlurScale > 0 && kernelRadius > 0;
|
|
101
|
+
const profileLUT = this.ensureProfileLUT(ctx);
|
|
102
|
+
const inputScatterTexture = ctx.SSSDiffuseTexture ?? inputColorTexture;
|
|
103
|
+
const blurWidth = blurEnabled && sssSettings.halfRes ? Math.max(1, Math.ceil(inputScatterTexture.width * 0.5)) : inputScatterTexture.width;
|
|
104
|
+
const blurHeight = blurEnabled && sssSettings.halfRes ? Math.max(1, Math.ceil(inputScatterTexture.height * 0.5)) : inputScatterTexture.height;
|
|
105
|
+
let blurredTexture = inputScatterTexture;
|
|
106
|
+
let blurFramebufferH = null;
|
|
107
|
+
let blurFramebufferV = null;
|
|
108
|
+
if (blurEnabled) {
|
|
109
|
+
blurFramebufferH = device.pool.fetchTemporalFramebuffer(false, blurWidth, blurHeight, inputScatterTexture.format, null, false);
|
|
110
|
+
blurFramebufferV = device.pool.fetchTemporalFramebuffer(false, blurWidth, blurHeight, inputScatterTexture.format, null, false);
|
|
111
|
+
device.setFramebuffer(blurFramebufferH);
|
|
112
|
+
this.blur(ctx, inputScatterTexture, sceneDepthTexture, profileLUT, blurWidth, blurHeight, kernelRadius, true, sssSettings);
|
|
113
|
+
device.setFramebuffer(blurFramebufferV);
|
|
114
|
+
this.blur(ctx, blurFramebufferH.getColorAttachments()[0], sceneDepthTexture, profileLUT, blurWidth, blurHeight, kernelRadius, false, sssSettings);
|
|
115
|
+
blurredTexture = blurFramebufferV.getColorAttachments()[0];
|
|
116
|
+
}
|
|
117
|
+
device.setFramebuffer(outputFramebuffer);
|
|
118
|
+
// The SSS combine pass only rewrites pixels that pass the foreground depth test.
|
|
119
|
+
// Preserve the current scene color first so sky/image backgrounds are not left
|
|
120
|
+
// uninitialized when no geometry-backed pixel is written by the combine pass.
|
|
121
|
+
this.passThrough(ctx, inputColorTexture, srgbOutput);
|
|
122
|
+
this.combine(ctx, inputColorTexture, blurredTexture, sceneDepthTexture, profileLUT, srgbOutput);
|
|
123
|
+
if (blurFramebufferH) {
|
|
124
|
+
device.pool.releaseFrameBuffer(blurFramebufferH);
|
|
125
|
+
}
|
|
126
|
+
if (blurFramebufferV) {
|
|
127
|
+
device.pool.releaseFrameBuffer(blurFramebufferV);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
blur(ctx, inputColorTexture, sceneDepthTexture, profileLUT, targetWidth, targetHeight, kernelRadius, horizontal, sssSettings) {
|
|
131
|
+
const device = ctx.device;
|
|
132
|
+
const sssNormalTexture = ctx.SSRNormalTexture ?? ctx.SSSParamTexture;
|
|
133
|
+
const hasNormalTexture = !!ctx.SSRNormalTexture;
|
|
134
|
+
const key = `${horizontal ? 'h' : 'v'}:${kernelRadius}`;
|
|
135
|
+
let program = SSS._blurPrograms[key];
|
|
136
|
+
if (!program) {
|
|
137
|
+
program = this.createBlurProgram(ctx, kernelRadius, horizontal);
|
|
138
|
+
SSS._blurPrograms[key] = program;
|
|
139
|
+
}
|
|
140
|
+
let bindGroup = this._blurBindGroups[key];
|
|
141
|
+
if (!bindGroup) {
|
|
142
|
+
bindGroup = device.createBindGroup(program.bindGroupLayouts[0]);
|
|
143
|
+
this._blurBindGroups[key] = bindGroup;
|
|
144
|
+
}
|
|
145
|
+
bindGroup.setTexture('colorTex', inputColorTexture, fetchSampler('clamp_linear'));
|
|
146
|
+
bindGroup.setTexture('profileTex', ctx.SSSProfileTexture, fetchSampler('clamp_nearest_nomip'));
|
|
147
|
+
bindGroup.setTexture('paramTex', ctx.SSSParamTexture, fetchSampler('clamp_nearest_nomip'));
|
|
148
|
+
bindGroup.setTexture('profileLUTTex', profileLUT, fetchSampler('clamp_nearest_nomip'));
|
|
149
|
+
bindGroup.setTexture('normalTex', sssNormalTexture, fetchSampler('clamp_nearest_nomip'));
|
|
150
|
+
bindGroup.setTexture('depthTex', sceneDepthTexture, fetchSampler('clamp_nearest_nomip'));
|
|
151
|
+
bindGroup.setValue('cameraNearFar', new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane()));
|
|
152
|
+
bindGroup.setValue('targetSize', new Vector4(targetWidth, targetHeight, targetWidth, targetHeight));
|
|
153
|
+
bindGroup.setValue('sampleOffsets', this.createSampleOffsets(kernelRadius));
|
|
154
|
+
bindGroup.setValue('blurScale', ctx.camera.sssBlurScale);
|
|
155
|
+
bindGroup.setValue('blurStdDev', sssSettings.blurStdDev);
|
|
156
|
+
bindGroup.setValue('depthCutoff', sssSettings.blurDepthCutoff);
|
|
157
|
+
bindGroup.setValue('normalCutoff', sssSettings.normalCutoff);
|
|
158
|
+
bindGroup.setValue('hasNormalTex', hasNormalTexture ? 1 : 0);
|
|
159
|
+
bindGroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
160
|
+
device.setProgram(program);
|
|
161
|
+
device.setBindGroup(0, bindGroup);
|
|
162
|
+
this.drawFullscreenQuad();
|
|
163
|
+
}
|
|
164
|
+
combine(ctx, inputColorTexture, blurredTexture, sceneDepthTexture, profileLUT, srgbOutput) {
|
|
165
|
+
const device = ctx.device;
|
|
166
|
+
const sssRoughnessTexture = ctx.SSRRoughnessTexture ?? ctx.SSSParamTexture;
|
|
167
|
+
const sssNormalTexture = ctx.SSRNormalTexture ?? ctx.SSSParamTexture;
|
|
168
|
+
const hasRoughnessTexture = !!ctx.SSRRoughnessTexture;
|
|
169
|
+
const hasNormalTexture = !!ctx.SSRNormalTexture;
|
|
170
|
+
const shadowLight = this.getCombineShadowLight(ctx);
|
|
171
|
+
const programKey = this.getCombineProgramKey(ctx, shadowLight);
|
|
172
|
+
let program = SSS._combinePrograms[programKey];
|
|
173
|
+
if (!program) {
|
|
174
|
+
program = this.createCombineProgram(ctx, shadowLight);
|
|
175
|
+
SSS._combinePrograms[programKey] = program;
|
|
176
|
+
}
|
|
177
|
+
let bindGroup = this._combineBindGroups[programKey];
|
|
178
|
+
if (!bindGroup) {
|
|
179
|
+
bindGroup = device.createBindGroup(program.bindGroupLayouts[0]);
|
|
180
|
+
this._combineBindGroups[programKey] = bindGroup;
|
|
181
|
+
}
|
|
182
|
+
const mainDirectionalLight = ctx.sunLight ?? ctx.primaryDirectionalLight;
|
|
183
|
+
const mainTransmissionLight = mainDirectionalLight ?? ctx.primaryTransmissionLight;
|
|
184
|
+
const sunDir = mainDirectionalLight ? mainDirectionalLight.directionAndCutoff.xyz().scaleBy(-1) : mainTransmissionLight ? mainTransmissionLight.directionAndCutoff.xyz() : {
|
|
185
|
+
x: 0,
|
|
186
|
+
y: 0,
|
|
187
|
+
z: 1
|
|
188
|
+
};
|
|
189
|
+
const sunColorIntensity = mainTransmissionLight ? mainTransmissionLight.diffuseAndIntensity : {
|
|
190
|
+
x: 1,
|
|
191
|
+
y: 1,
|
|
192
|
+
z: 1,
|
|
193
|
+
w: 0
|
|
194
|
+
};
|
|
195
|
+
const mainLightPosRange = mainTransmissionLight ? mainTransmissionLight.positionAndRange : {
|
|
196
|
+
x: 0,
|
|
197
|
+
y: 0,
|
|
198
|
+
z: 0,
|
|
199
|
+
w: 1
|
|
200
|
+
};
|
|
201
|
+
const mainLightDirCutoff = mainTransmissionLight ? mainTransmissionLight.directionAndCutoff : {
|
|
202
|
+
x: 0,
|
|
203
|
+
y: 0,
|
|
204
|
+
z: -1,
|
|
205
|
+
w: 0
|
|
206
|
+
};
|
|
207
|
+
const mainLightType = mainTransmissionLight ? mainTransmissionLight.isDirectionLight() ? LIGHT_TYPE_DIRECTIONAL : mainTransmissionLight.isPointLight() ? LIGHT_TYPE_POINT : mainTransmissionLight.isSpotLight() ? LIGHT_TYPE_SPOT : LIGHT_TYPE_RECT : LIGHT_TYPE_DIRECTIONAL;
|
|
208
|
+
bindGroup.setTexture('colorTex', inputColorTexture, fetchSampler('clamp_linear'));
|
|
209
|
+
bindGroup.setTexture('diffuseTex', ctx.SSSDiffuseTexture ?? inputColorTexture, fetchSampler('clamp_linear'));
|
|
210
|
+
bindGroup.setTexture('blurTex', blurredTexture, fetchSampler('clamp_linear'));
|
|
211
|
+
bindGroup.setTexture('transmissionTex', ctx.SSSTransmissionTexture ?? ctx.SSSDiffuseTexture ?? inputColorTexture, fetchSampler('clamp_linear'));
|
|
212
|
+
bindGroup.setTexture('profileTex', ctx.SSSProfileTexture, fetchSampler('clamp_nearest_nomip'));
|
|
213
|
+
bindGroup.setTexture('paramTex', ctx.SSSParamTexture, fetchSampler('clamp_nearest_nomip'));
|
|
214
|
+
bindGroup.setTexture('profileLUTTex', profileLUT, fetchSampler('clamp_nearest_nomip'));
|
|
215
|
+
bindGroup.setTexture('roughnessTex', sssRoughnessTexture, fetchSampler('clamp_linear_nomip'));
|
|
216
|
+
bindGroup.setTexture('normalTex', sssNormalTexture, fetchSampler('clamp_nearest_nomip'));
|
|
217
|
+
bindGroup.setTexture('depthTex', sceneDepthTexture, fetchSampler('clamp_nearest_nomip'));
|
|
218
|
+
bindGroup.setValue('cameraNearFar', new Vector2(ctx.camera.getNearPlane(), ctx.camera.getFarPlane()));
|
|
219
|
+
bindGroup.setValue('targetSize', new Vector4(inputColorTexture.width, inputColorTexture.height, inputColorTexture.width, inputColorTexture.height));
|
|
220
|
+
bindGroup.setValue('invProjMatrix', Matrix4x4.invert(ctx.camera.getProjectionMatrix()));
|
|
221
|
+
bindGroup.setValue('invViewMatrix', ctx.camera.worldMatrix);
|
|
222
|
+
bindGroup.setValue('sunDir', new Float32Array([
|
|
223
|
+
sunDir.x,
|
|
224
|
+
sunDir.y,
|
|
225
|
+
sunDir.z
|
|
226
|
+
]));
|
|
227
|
+
bindGroup.setValue('mainLightPosRange', new Float32Array([
|
|
228
|
+
mainLightPosRange.x,
|
|
229
|
+
mainLightPosRange.y,
|
|
230
|
+
mainLightPosRange.z,
|
|
231
|
+
mainLightPosRange.w
|
|
232
|
+
]));
|
|
233
|
+
bindGroup.setValue('mainLightDirCutoff', new Float32Array([
|
|
234
|
+
mainLightDirCutoff.x,
|
|
235
|
+
mainLightDirCutoff.y,
|
|
236
|
+
mainLightDirCutoff.z,
|
|
237
|
+
mainLightDirCutoff.w
|
|
238
|
+
]));
|
|
239
|
+
bindGroup.setValue('mainLightType', mainLightType);
|
|
240
|
+
bindGroup.setValue('sunColorIntensity', new Float32Array([
|
|
241
|
+
sunColorIntensity.x,
|
|
242
|
+
sunColorIntensity.y,
|
|
243
|
+
sunColorIntensity.z,
|
|
244
|
+
sunColorIntensity.w
|
|
245
|
+
]));
|
|
246
|
+
bindGroup.setValue('sssStrength', ctx.camera.sssStrength);
|
|
247
|
+
bindGroup.setValue('transmissionStrength', ctx.camera.sssTransmissionStrength);
|
|
248
|
+
bindGroup.setValue('transmissionPower', ctx.camera.sssTransmissionPower);
|
|
249
|
+
bindGroup.setValue('multiScatter', ctx.camera.sssMultiScatter);
|
|
250
|
+
bindGroup.setValue('hasDiffuseTex', ctx.SSSDiffuseTexture ? 1 : 0);
|
|
251
|
+
bindGroup.setValue('hasTransmissionTex', ctx.SSSTransmissionTexture ? 1 : 0);
|
|
252
|
+
bindGroup.setValue('hasRoughnessTex', hasRoughnessTexture ? 1 : 0);
|
|
253
|
+
bindGroup.setValue('hasNormalTex', hasNormalTexture ? 1 : 0);
|
|
254
|
+
bindGroup.setValue('debugView', SSS._debugViewMap[ctx.camera.sssDebugView] ?? 0);
|
|
255
|
+
bindGroup.setValue('flip', this.needFlip(device) ? 1 : 0);
|
|
256
|
+
bindGroup.setValue('srgbOut', srgbOutput ? 1 : 0);
|
|
257
|
+
if (shadowLight) {
|
|
258
|
+
const shadowMapParams = ctx.shadowMapInfo.get(shadowLight);
|
|
259
|
+
const cameraPos = ctx.camera.getWorldPosition();
|
|
260
|
+
bindGroup.setValue('camera', {
|
|
261
|
+
position: new Vector4(cameraPos.x, cameraPos.y, cameraPos.z, 0),
|
|
262
|
+
params: new Vector4(ctx.camera.getNearPlane(), ctx.camera.getFarPlane(), 1, 1),
|
|
263
|
+
shadowDebugCascades: ctx.camera.shadowDebugCascades ? 1 : 0
|
|
264
|
+
});
|
|
265
|
+
bindGroup.setValue('light', {
|
|
266
|
+
sunDir: new Float32Array([
|
|
267
|
+
sunDir.x,
|
|
268
|
+
sunDir.y,
|
|
269
|
+
sunDir.z
|
|
270
|
+
]),
|
|
271
|
+
envLightStrength: ctx.env?.light.strength ?? 0,
|
|
272
|
+
envLightSpecularStrength: ctx.env?.light.specularStrength ?? 1,
|
|
273
|
+
shadowStrength: shadowLight.shadow.shadowStrength,
|
|
274
|
+
shadowCascades: shadowMapParams.numShadowCascades,
|
|
275
|
+
positionAndRange: shadowLight.positionAndRange,
|
|
276
|
+
directionAndCutoff: shadowLight.directionAndCutoff,
|
|
277
|
+
diffuseAndIntensity: shadowLight.diffuseAndIntensity,
|
|
278
|
+
extraParams: shadowLight.extraParams,
|
|
279
|
+
cascadeDistances: shadowMapParams.cascadeDistances,
|
|
280
|
+
depthBiasValues: shadowMapParams.depthBiasValues[0],
|
|
281
|
+
shadowCameraParams: shadowMapParams.cameraParams,
|
|
282
|
+
depthBiasScales: shadowMapParams.depthBiasScales,
|
|
283
|
+
shadowMatrices: new Float32Array(shadowMapParams.shadowMatrices)
|
|
284
|
+
});
|
|
285
|
+
bindGroup.setTexture('Z_UniformShadowMap', shadowMapParams.shadowMap, shadowMapParams.shadowMapSampler);
|
|
286
|
+
}
|
|
287
|
+
device.setProgram(program);
|
|
288
|
+
device.setBindGroup(0, bindGroup);
|
|
289
|
+
this.drawFullscreenQuad(AbstractPostEffect.getDefaultRenderState(ctx, 'gt'));
|
|
290
|
+
}
|
|
291
|
+
createBlurProgram(ctx, kernelRadius, horizontal) {
|
|
292
|
+
const sampleCount = Math.max(1, Math.ceil(kernelRadius / 2));
|
|
293
|
+
const program = ctx.device.buildRenderProgram({
|
|
294
|
+
vertex (pb) {
|
|
295
|
+
this.flip = pb.int().uniform(0);
|
|
296
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
297
|
+
this.$outputs.uv = pb.vec2();
|
|
298
|
+
pb.main(function() {
|
|
299
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
|
|
300
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
301
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
302
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
},
|
|
306
|
+
fragment (pb) {
|
|
307
|
+
this.colorTex = pb.tex2D().uniform(0);
|
|
308
|
+
this.profileTex = pb.tex2D().uniform(0);
|
|
309
|
+
this.paramTex = pb.tex2D().uniform(0);
|
|
310
|
+
this.profileLUTTex = pb.tex2D().uniform(0);
|
|
311
|
+
this.normalTex = pb.tex2D().uniform(0);
|
|
312
|
+
this.depthTex = pb.tex2D().uniform(0);
|
|
313
|
+
this.cameraNearFar = pb.vec2().uniform(0);
|
|
314
|
+
this.targetSize = pb.vec4().uniform(0);
|
|
315
|
+
this.sampleOffsets = pb.vec4[sampleCount + 1]().uniform(0);
|
|
316
|
+
this.blurScale = pb.float().uniform(0);
|
|
317
|
+
this.blurStdDev = pb.float().uniform(0);
|
|
318
|
+
this.depthCutoff = pb.float().uniform(0);
|
|
319
|
+
this.normalCutoff = pb.float().uniform(0);
|
|
320
|
+
this.hasNormalTex = pb.int().uniform(0);
|
|
321
|
+
this.$outputs.outColor = pb.vec4();
|
|
322
|
+
pb.func('max3', [
|
|
323
|
+
pb.vec3('value')
|
|
324
|
+
], function() {
|
|
325
|
+
this.$return(pb.max(this.value.x, pb.max(this.value.y, this.value.z)));
|
|
326
|
+
});
|
|
327
|
+
pb.func('readProfileRadius', [
|
|
328
|
+
pb.float('slot')
|
|
329
|
+
], function() {
|
|
330
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(0));
|
|
331
|
+
this.$return(pb.mul(pb.textureSampleLevel(this.profileLUTTex, this.uv, 0).rgb, SSS._profileRadiusEncodeMax));
|
|
332
|
+
});
|
|
333
|
+
pb.func('readProfileFalloff', [
|
|
334
|
+
pb.float('slot')
|
|
335
|
+
], function() {
|
|
336
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(1));
|
|
337
|
+
this.$return(pb.textureSampleLevel(this.profileLUTTex, this.uv, 0).rgb);
|
|
338
|
+
});
|
|
339
|
+
pb.func('readProfileSettingsA', [
|
|
340
|
+
pb.float('slot')
|
|
341
|
+
], function() {
|
|
342
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(4));
|
|
343
|
+
this.$l.raw = pb.textureSampleLevel(this.profileLUTTex, this.uv, 0);
|
|
344
|
+
this.$return(pb.vec4(pb.mul(this.raw.x, SSS._profileWorldScaleEncodeMax), this.raw.y, pb.mul(this.raw.z, SSS._profileNormalScaleEncodeMax), this.raw.w));
|
|
345
|
+
});
|
|
346
|
+
pb.func('readProfileSettingsB', [
|
|
347
|
+
pb.float('slot')
|
|
348
|
+
], function() {
|
|
349
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(6));
|
|
350
|
+
this.$l.raw = pb.textureSampleLevel(this.profileLUTTex, this.uv, 0);
|
|
351
|
+
this.$return(pb.vec4(pb.mul(this.raw.x, SSS._profileExtinctionEncodeMax), pb.mul(this.raw.y, SSS._profileWorldScaleEncodeMax), pb.mul(this.raw.z, 2), this.raw.w));
|
|
352
|
+
});
|
|
353
|
+
pb.func('burleyKernel1', [
|
|
354
|
+
pb.float('distance'),
|
|
355
|
+
pb.float('radius'),
|
|
356
|
+
pb.float('falloff'),
|
|
357
|
+
pb.float('distribution'),
|
|
358
|
+
pb.float('scatterScale')
|
|
359
|
+
], function() {
|
|
360
|
+
this.$l.safeRadius = pb.max(this.radius, 0.045);
|
|
361
|
+
this.$l.safeDistribution = pb.clamp(this.distribution, 0, 1);
|
|
362
|
+
this.$l.safeScatterScale = pb.clamp(pb.div(this.scatterScale, SSS._profileWorldScaleEncodeMax), 0.05, 1);
|
|
363
|
+
this.$l.falloffShape = pb.mix(0.72, 1.46, pb.clamp(this.falloff, 0.05, 1));
|
|
364
|
+
this.$l.distributionShape = pb.mix(0.82, 1.38, this.safeDistribution);
|
|
365
|
+
this.$l.scatterShape = pb.mix(0.84, 1.28, this.safeScatterScale);
|
|
366
|
+
this.$l.diffusionDistance = pb.max(pb.mul(this.blurStdDev, this.safeRadius, this.falloffShape, this.distributionShape, this.scatterShape), 0.16);
|
|
367
|
+
this.$l.dr = pb.div(pb.abs(this.distance), this.diffusionDistance);
|
|
368
|
+
this.$return(pb.div(pb.add(pb.exp(pb.neg(this.dr)), pb.exp(pb.neg(pb.div(this.dr, 3)))), pb.max(pb.mul(8, this.diffusionDistance), 1e-4)));
|
|
369
|
+
});
|
|
370
|
+
pb.func('computeKernelWeight', [
|
|
371
|
+
pb.float('distance'),
|
|
372
|
+
pb.vec3('relativeRadius'),
|
|
373
|
+
pb.vec3('falloff'),
|
|
374
|
+
pb.float('distribution'),
|
|
375
|
+
pb.float('scatterScale'),
|
|
376
|
+
pb.float('strengthScale')
|
|
377
|
+
], function() {
|
|
378
|
+
this.$l.safeDistribution = pb.clamp(this.distribution, 0, 1);
|
|
379
|
+
this.$l.safeStrengthScale = pb.clamp(pb.mul(this.strengthScale, 0.5), 0.05, 1);
|
|
380
|
+
this.$l.burleyWeight = pb.vec3(this.burleyKernel1(this.distance, this.relativeRadius.x, this.falloff.x, this.safeDistribution, this.scatterScale), this.burleyKernel1(this.distance, this.relativeRadius.y, this.falloff.y, this.safeDistribution, this.scatterScale), this.burleyKernel1(this.distance, this.relativeRadius.z, this.falloff.z, this.safeDistribution, this.scatterScale));
|
|
381
|
+
this.$l.forwardScatter = pb.vec3(this.burleyKernel1(this.distance, pb.max(pb.mul(this.relativeRadius.x, 0.58), 0.03), pb.mix(this.falloff.x, 1, 0.3), pb.mix(this.safeDistribution, 1, 0.18), pb.mul(this.scatterScale, 0.92)), this.burleyKernel1(this.distance, pb.max(pb.mul(this.relativeRadius.y, 0.58), 0.03), pb.mix(this.falloff.y, 1, 0.3), pb.mix(this.safeDistribution, 1, 0.18), pb.mul(this.scatterScale, 0.92)), this.burleyKernel1(this.distance, pb.max(pb.mul(this.relativeRadius.z, 0.58), 0.03), pb.mix(this.falloff.z, 1, 0.3), pb.mix(this.safeDistribution, 1, 0.18), pb.mul(this.scatterScale, 0.92)));
|
|
382
|
+
this.$l.forwardWeight = pb.mix(0.08, 0.28, this.safeStrengthScale);
|
|
383
|
+
this.$return(pb.add(pb.mul(this.burleyWeight, pb.sub(1, this.forwardWeight)), pb.mul(this.forwardScatter, this.forwardWeight)));
|
|
384
|
+
});
|
|
385
|
+
pb.func('decodeNormal', [
|
|
386
|
+
pb.vec2('uv')
|
|
387
|
+
], function() {
|
|
388
|
+
this.$if(pb.equal(this.hasNormalTex, 0), function() {
|
|
389
|
+
this.$return(pb.vec3(0, 0, 1));
|
|
390
|
+
});
|
|
391
|
+
this.$l.n = pb.sub(pb.mul(pb.textureSampleLevel(this.normalTex, this.uv, 0).rgb, 2), pb.vec3(1));
|
|
392
|
+
this.$return(pb.normalize(this.n));
|
|
393
|
+
});
|
|
394
|
+
pb.func('readDepth01', [
|
|
395
|
+
pb.vec2('uv')
|
|
396
|
+
], function() {
|
|
397
|
+
this.$return(ShaderHelper.sampleLinearDepth(this, this.depthTex, this.uv, 0));
|
|
398
|
+
});
|
|
399
|
+
pb.func('sampleColor', [
|
|
400
|
+
pb.vec2('uv')
|
|
401
|
+
], function() {
|
|
402
|
+
this.$return(pb.textureSampleLevel(this.colorTex, this.uv, 0));
|
|
403
|
+
});
|
|
404
|
+
pb.func('readProfileSlot', [
|
|
405
|
+
pb.vec4('param')
|
|
406
|
+
], function() {
|
|
407
|
+
this.$return(pb.floor(pb.add(pb.mul(this.param.r, 255), 0.5)));
|
|
408
|
+
});
|
|
409
|
+
pb.main(function() {
|
|
410
|
+
this.$l.uv = this.$inputs.uv;
|
|
411
|
+
this.$l.centerColor = pb.textureSampleLevel(this.colorTex, this.uv, 0);
|
|
412
|
+
this.$l.centerProfile = pb.textureSampleLevel(this.profileTex, this.uv, 0);
|
|
413
|
+
this.$l.centerParam = pb.textureSampleLevel(this.paramTex, this.uv, 0);
|
|
414
|
+
this.$l.centerActive = pb.greaterThan(this.centerParam.a, 0.5);
|
|
415
|
+
this.$l.centerStrength = this.max3(this.centerProfile.rgb);
|
|
416
|
+
this.$l.centerSlot = this.readProfileSlot(this.centerParam);
|
|
417
|
+
this.$l.centerDepth01 = this.readDepth01(this.uv);
|
|
418
|
+
this.$if(pb.or(pb.or(pb.or(pb.lessThanEqual(this.centerStrength, 1e-4), pb.lessThanEqual(this.centerSlot, 0)), pb.not(this.centerActive)), pb.greaterThanEqual(this.centerDepth01, 1)), function() {
|
|
419
|
+
this.$outputs.outColor = this.centerColor;
|
|
420
|
+
}).$else(function() {
|
|
421
|
+
this.$l.widthStrength = pb.clamp(this.centerParam.g, 0, 0.999);
|
|
422
|
+
this.$l.centerDepth = pb.mul(this.centerDepth01, this.cameraNearFar.y);
|
|
423
|
+
this.$l.centerLogDepth = pb.log(pb.add(this.centerDepth, 1));
|
|
424
|
+
this.$l.profileSettingsA = this.readProfileSettingsA(this.centerSlot);
|
|
425
|
+
this.$l.profileSettingsB = this.readProfileSettingsB(this.centerSlot);
|
|
426
|
+
this.$l.profileWorldScale = pb.clamp(this.profileSettingsA.x, 0.05, SSS._profileWorldScaleEncodeMax);
|
|
427
|
+
this.$l.profileBoundaryBleed = pb.clamp(this.profileSettingsA.y, 0, 1);
|
|
428
|
+
this.$l.profileNormalScale = pb.clamp(this.profileSettingsA.z, 0, SSS._profileNormalScaleEncodeMax);
|
|
429
|
+
this.$l.profileDistribution = pb.clamp(this.profileSettingsA.w, 0, 1);
|
|
430
|
+
this.$l.profileScatterScale = pb.clamp(this.profileSettingsB.y, 0.05, SSS._profileWorldScaleEncodeMax);
|
|
431
|
+
this.$l.profileStrengthScale = pb.clamp(this.profileSettingsB.z, 0.05, 2);
|
|
432
|
+
this.$l.profileWorldScaleNorm = pb.clamp(pb.div(this.profileWorldScale, SSS._profileWorldScaleEncodeMax), 0, 1);
|
|
433
|
+
this.$l.profileScatterScaleNorm = pb.clamp(pb.div(this.profileScatterScale, SSS._profileWorldScaleEncodeMax), 0, 1);
|
|
434
|
+
this.$l.profileStrengthNorm = pb.clamp(pb.mul(this.profileStrengthScale, 0.5), 0, 1);
|
|
435
|
+
this.$l.depthThreshold = pb.div(pb.mul(this.depthCutoff, pb.add(0.45, pb.mul(this.widthStrength, 0.42)), pb.mix(0.88, 1.16, this.profileWorldScaleNorm)), pb.max(pb.sub(pb.log(pb.add(this.cameraNearFar.y, 1)), pb.log(pb.add(this.cameraNearFar.x, 1))), 1e-4));
|
|
436
|
+
this.$l.normalThreshold = pb.clamp(pb.add(pb.max(pb.sub(this.normalCutoff, pb.mul(this.widthStrength, 0.12)), 0.58), pb.sub(pb.mul(this.profileNormalScale, 0.08), 0.08), pb.neg(pb.mul(this.profileBoundaryBleed, 0.04))), 0.52, 0.985);
|
|
437
|
+
this.$l.centerNormal = this.decodeNormal(this.uv);
|
|
438
|
+
this.$l.profileRadius = pb.mul(this.readProfileRadius(this.centerSlot), this.profileWorldScale, pb.mix(0.76, 1.44, this.profileScatterScaleNorm), pb.mix(0.92, 1.08, this.profileStrengthNorm));
|
|
439
|
+
this.$l.profileFalloff = this.readProfileFalloff(this.centerSlot);
|
|
440
|
+
this.$l.maxProfileRadius = pb.max(this.max3(this.profileRadius), 1e-4);
|
|
441
|
+
this.$l.relativeRadius = pb.div(this.profileRadius, this.maxProfileRadius);
|
|
442
|
+
this.$l.profileSpread = pb.clamp(pb.div(this.maxProfileRadius, pb.add(this.maxProfileRadius, 0.65)), 0, 1);
|
|
443
|
+
this.$l.profileDiffusionSoftness = pb.clamp(pb.add(pb.add(0.34, pb.mul(this.profileSpread, 0.34)), pb.add(pb.mul(this.profileDistribution, 0.18), pb.mul(this.profileStrengthNorm, 0.18))), 0.2, 1);
|
|
444
|
+
this.$l.radius = pb.max(pb.mul(pb.add(0.18, pb.mul(this.widthStrength, 1.9), pb.mul(this.profileSpread, 0.85)), this.blurScale, pb.add(0.18, pb.mul(this.maxProfileRadius, 0.82)), pb.mix(0.86, 1.22, this.profileStrengthNorm), pb.mix(0.9, 1.14, this.profileDiffusionSoftness), 0.23), 1);
|
|
445
|
+
this.$l.centerKernel = this.computeKernelWeight(0, this.relativeRadius, this.profileFalloff, this.profileDistribution, this.profileScatterScale, this.profileStrengthScale);
|
|
446
|
+
this.$l.centerWeight = pb.max(pb.mul(this.centerProfile.rgb, pb.mix(0.92, 1.18, this.profileStrengthNorm), pb.mix(0.94, 1.08, this.profileDiffusionSoftness)), pb.vec3(pb.mul(this.widthStrength, 0.05)));
|
|
447
|
+
this.$l.centerSample = this.sampleColor(this.uv).rgb;
|
|
448
|
+
this.$l.colorSum = pb.mul(this.centerSample, this.centerWeight, this.centerKernel);
|
|
449
|
+
this.$l.weightSum = pb.max(pb.mul(this.centerWeight, this.centerKernel), pb.vec3(1e-4));
|
|
450
|
+
this.$for(pb.int('i'), 1, sampleCount, function() {
|
|
451
|
+
this.$l.data = this.sampleOffsets.at(this.i);
|
|
452
|
+
this.$l.axisOffset = pb.mul(this.data.x, this.radius);
|
|
453
|
+
this.$l.offset = pb.div(horizontal ? pb.vec2(this.axisOffset, 0) : pb.vec2(0, this.axisOffset), this.targetSize.xy);
|
|
454
|
+
this.$l.kernelWeight = this.computeKernelWeight(this.data.x, this.relativeRadius, this.profileFalloff, this.profileDistribution, this.profileScatterScale, this.profileStrengthScale);
|
|
455
|
+
this.$for(pb.int('side'), 0, 2, function() {
|
|
456
|
+
this.$l.sampleUV = this.$choice(pb.equal(this.side, 0), pb.add(this.uv, this.offset), pb.sub(this.uv, this.offset));
|
|
457
|
+
this.$l.sampleProfile = pb.textureSampleLevel(this.profileTex, this.sampleUV, 0);
|
|
458
|
+
this.$l.sampleParam = pb.textureSampleLevel(this.paramTex, this.sampleUV, 0);
|
|
459
|
+
this.$l.sampleStrength = this.max3(this.sampleProfile.rgb);
|
|
460
|
+
this.$l.sampleActive = pb.greaterThan(this.sampleParam.a, 0.5);
|
|
461
|
+
this.$l.sampleWidthStrength = pb.clamp(this.sampleParam.g, 0, 0.999);
|
|
462
|
+
this.$l.sampleWeight = pb.max(this.sampleProfile.rgb, pb.vec3(pb.mul(this.sampleWidthStrength, 0.05)));
|
|
463
|
+
this.$if(pb.and(this.sampleActive, pb.greaterThan(this.sampleStrength, 1e-4)), function() {
|
|
464
|
+
this.$l.depth01Sample = this.readDepth01(this.sampleUV);
|
|
465
|
+
this.$if(pb.lessThan(this.depth01Sample, 1), function() {
|
|
466
|
+
this.$l.sampleDepth = pb.mul(this.depth01Sample, this.cameraNearFar.y);
|
|
467
|
+
this.$l.sampleLogDepth = pb.log(pb.add(this.sampleDepth, 1));
|
|
468
|
+
this.$if(pb.lessThan(pb.abs(pb.sub(this.sampleLogDepth, this.centerLogDepth)), this.depthThreshold), function() {
|
|
469
|
+
this.$l.sampleNormal = this.decodeNormal(this.sampleUV);
|
|
470
|
+
this.$if(pb.greaterThan(pb.dot(this.sampleNormal, this.centerNormal), this.normalThreshold), function() {
|
|
471
|
+
this.$l.sampleColor = this.sampleColor(this.sampleUV).rgb;
|
|
472
|
+
this.$l.w = pb.mul(this.kernelWeight, this.sampleWeight);
|
|
473
|
+
this.colorSum = pb.add(this.colorSum, pb.mul(this.sampleColor, this.w));
|
|
474
|
+
this.weightSum = pb.add(this.weightSum, this.w);
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
});
|
|
481
|
+
this.$outputs.outColor = pb.vec4(pb.div(this.colorSum, pb.max(this.weightSum, pb.vec3(1e-4))), this.centerColor.a);
|
|
482
|
+
});
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
program.name = horizontal ? '@SSS_Blur_H' : '@SSS_Blur_V';
|
|
487
|
+
return program;
|
|
488
|
+
}
|
|
489
|
+
createCombineProgram(ctx, shadowLight) {
|
|
490
|
+
const shadowMapParams = shadowLight ? ctx.shadowMapInfo?.get(shadowLight) : null;
|
|
491
|
+
const shadowEnabled = !!(shadowLight && shadowMapParams?.shadowMap && shadowMapParams.impl);
|
|
492
|
+
const program = ctx.device.buildRenderProgram({
|
|
493
|
+
vertex (pb) {
|
|
494
|
+
this.flip = pb.int().uniform(0);
|
|
495
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
496
|
+
this.$outputs.uv = pb.vec2();
|
|
497
|
+
pb.main(function() {
|
|
498
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
|
|
499
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
500
|
+
this.$if(pb.notEqual(this.flip, 0), function() {
|
|
501
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
},
|
|
505
|
+
fragment (pb) {
|
|
506
|
+
if (shadowEnabled) {
|
|
507
|
+
const cameraStruct = pb.defineStruct([
|
|
508
|
+
pb.vec4('position'),
|
|
509
|
+
pb.vec4('params'),
|
|
510
|
+
pb.float('shadowDebugCascades')
|
|
511
|
+
]);
|
|
512
|
+
const lightStruct = pb.defineStruct([
|
|
513
|
+
pb.vec3('sunDir'),
|
|
514
|
+
pb.float('envLightStrength'),
|
|
515
|
+
pb.float('envLightSpecularStrength'),
|
|
516
|
+
pb.float('shadowStrength'),
|
|
517
|
+
pb.int('shadowCascades'),
|
|
518
|
+
pb.vec4('positionAndRange'),
|
|
519
|
+
pb.vec4('directionAndCutoff'),
|
|
520
|
+
pb.vec4('diffuseAndIntensity'),
|
|
521
|
+
pb.vec4('extraParams'),
|
|
522
|
+
pb.vec4('cascadeDistances'),
|
|
523
|
+
pb.vec4('depthBiasValues'),
|
|
524
|
+
pb.vec4('shadowCameraParams'),
|
|
525
|
+
pb.vec4('depthBiasScales'),
|
|
526
|
+
pb.vec4[16]('shadowMatrices')
|
|
527
|
+
]);
|
|
528
|
+
this.camera = cameraStruct().uniform(0);
|
|
529
|
+
this.light = lightStruct().uniform(0);
|
|
530
|
+
const shadowMap = shadowMapParams.shadowMap;
|
|
531
|
+
const shadowTex = shadowMap.isTextureCube() ? shadowMap.isDepth() ? pb.texCubeShadow() : pb.texCube() : shadowMap.isTexture2D() ? shadowMap.isDepth() ? pb.tex2DShadow() : pb.tex2D() : shadowMap.isDepth() ? pb.tex2DArrayShadow() : pb.tex2DArray();
|
|
532
|
+
if (!shadowMap.isDepth() && !ctx.device.getDeviceCaps().textureCaps.getTextureFormatInfo(shadowMap.format).filterable) {
|
|
533
|
+
shadowTex.sampleType('unfilterable-float');
|
|
534
|
+
}
|
|
535
|
+
this.Z_UniformShadowMap = shadowTex.uniform(0);
|
|
536
|
+
}
|
|
537
|
+
this.colorTex = pb.tex2D().uniform(0);
|
|
538
|
+
this.diffuseTex = pb.tex2D().uniform(0);
|
|
539
|
+
this.blurTex = pb.tex2D().uniform(0);
|
|
540
|
+
this.transmissionTex = pb.tex2D().uniform(0);
|
|
541
|
+
this.profileTex = pb.tex2D().uniform(0);
|
|
542
|
+
this.paramTex = pb.tex2D().uniform(0);
|
|
543
|
+
this.profileLUTTex = pb.tex2D().uniform(0);
|
|
544
|
+
this.roughnessTex = pb.tex2D().uniform(0);
|
|
545
|
+
this.normalTex = pb.tex2D().uniform(0);
|
|
546
|
+
this.depthTex = pb.tex2D().uniform(0);
|
|
547
|
+
this.cameraNearFar = pb.vec2().uniform(0);
|
|
548
|
+
this.targetSize = pb.vec4().uniform(0);
|
|
549
|
+
this.invProjMatrix = pb.mat4().uniform(0);
|
|
550
|
+
this.invViewMatrix = pb.mat4().uniform(0);
|
|
551
|
+
this.sunDir = pb.vec3().uniform(0);
|
|
552
|
+
this.mainLightPosRange = pb.vec4().uniform(0);
|
|
553
|
+
this.mainLightDirCutoff = pb.vec4().uniform(0);
|
|
554
|
+
this.mainLightType = pb.int().uniform(0);
|
|
555
|
+
this.sunColorIntensity = pb.vec4().uniform(0);
|
|
556
|
+
this.sssStrength = pb.float().uniform(0);
|
|
557
|
+
this.transmissionStrength = pb.float().uniform(0);
|
|
558
|
+
this.transmissionPower = pb.float().uniform(0);
|
|
559
|
+
this.multiScatter = pb.float().uniform(0);
|
|
560
|
+
this.hasDiffuseTex = pb.int().uniform(0);
|
|
561
|
+
this.hasTransmissionTex = pb.int().uniform(0);
|
|
562
|
+
this.hasRoughnessTex = pb.int().uniform(0);
|
|
563
|
+
this.hasNormalTex = pb.int().uniform(0);
|
|
564
|
+
this.debugView = pb.int().uniform(0);
|
|
565
|
+
this.srgbOut = pb.int().uniform(0);
|
|
566
|
+
this.$outputs.outColor = pb.vec4();
|
|
567
|
+
pb.func('max3', [
|
|
568
|
+
pb.vec3('value')
|
|
569
|
+
], function() {
|
|
570
|
+
this.$return(pb.max(this.value.x, pb.max(this.value.y, this.value.z)));
|
|
571
|
+
});
|
|
572
|
+
pb.func('readProfileRadius', [
|
|
573
|
+
pb.float('slot')
|
|
574
|
+
], function() {
|
|
575
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(0));
|
|
576
|
+
this.$return(pb.mul(pb.textureSampleLevel(this.profileLUTTex, this.uv, 0).rgb, SSS._profileRadiusEncodeMax));
|
|
577
|
+
});
|
|
578
|
+
pb.func('readProfileFalloff', [
|
|
579
|
+
pb.float('slot')
|
|
580
|
+
], function() {
|
|
581
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(1));
|
|
582
|
+
this.$return(pb.textureSampleLevel(this.profileLUTTex, this.uv, 0).rgb);
|
|
583
|
+
});
|
|
584
|
+
pb.func('readProfileTintBias', [
|
|
585
|
+
pb.float('slot')
|
|
586
|
+
], function() {
|
|
587
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(2));
|
|
588
|
+
this.$return(pb.textureSampleLevel(this.profileLUTTex, this.uv, 0).rgb);
|
|
589
|
+
});
|
|
590
|
+
pb.func('readProfilePresetResponse', [
|
|
591
|
+
pb.float('slot')
|
|
592
|
+
], function() {
|
|
593
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(3));
|
|
594
|
+
this.$l.raw = pb.textureSampleLevel(this.profileLUTTex, this.uv, 0);
|
|
595
|
+
this.$return(pb.vec4(this.raw.x, this.raw.y, pb.sub(pb.mul(this.raw.z, 0.75), 0.25), pb.sub(pb.mul(this.raw.w, 0.75), 0.25)));
|
|
596
|
+
});
|
|
597
|
+
pb.func('readProfileSettingsA', [
|
|
598
|
+
pb.float('slot')
|
|
599
|
+
], function() {
|
|
600
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(4));
|
|
601
|
+
this.$l.raw = pb.textureSampleLevel(this.profileLUTTex, this.uv, 0);
|
|
602
|
+
this.$return(pb.vec4(pb.mul(this.raw.x, SSS._profileWorldScaleEncodeMax), this.raw.y, pb.mul(this.raw.z, SSS._profileNormalScaleEncodeMax), this.raw.w));
|
|
603
|
+
});
|
|
604
|
+
pb.func('readProfileTransmissionTint', [
|
|
605
|
+
pb.float('slot')
|
|
606
|
+
], function() {
|
|
607
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(5));
|
|
608
|
+
this.$return(pb.textureSampleLevel(this.profileLUTTex, this.uv, 0).rgb);
|
|
609
|
+
});
|
|
610
|
+
pb.func('readProfileSettingsB', [
|
|
611
|
+
pb.float('slot')
|
|
612
|
+
], function() {
|
|
613
|
+
this.$l.uv = pb.vec2(pb.div(pb.add(this.slot, 0.5), SSS._profileLUTWidth), SSS.profileRowV(6));
|
|
614
|
+
this.$l.raw = pb.textureSampleLevel(this.profileLUTTex, this.uv, 0);
|
|
615
|
+
this.$return(pb.vec4(pb.mul(this.raw.x, SSS._profileExtinctionEncodeMax), pb.mul(this.raw.y, SSS._profileWorldScaleEncodeMax), pb.mul(this.raw.z, 2), this.raw.w));
|
|
616
|
+
});
|
|
617
|
+
pb.func('readProfileSlot', [
|
|
618
|
+
pb.vec4('param')
|
|
619
|
+
], function() {
|
|
620
|
+
this.$return(pb.floor(pb.add(pb.mul(this.param.r, 255), 0.5)));
|
|
621
|
+
});
|
|
622
|
+
pb.func('readProfilePreset', [
|
|
623
|
+
pb.vec4('param')
|
|
624
|
+
], function() {
|
|
625
|
+
this.$return(pb.floor(pb.add(pb.mul(this.param.b, 255), 0.5)));
|
|
626
|
+
});
|
|
627
|
+
pb.func('decodeNormal', [
|
|
628
|
+
pb.vec2('uv')
|
|
629
|
+
], function() {
|
|
630
|
+
this.$if(pb.equal(this.hasNormalTex, 0), function() {
|
|
631
|
+
this.$return(pb.vec3(0, 0, 1));
|
|
632
|
+
});
|
|
633
|
+
this.$l.n = pb.sub(pb.mul(pb.textureSampleLevel(this.normalTex, this.uv, 0).rgb, 2), pb.vec3(1));
|
|
634
|
+
this.$return(pb.normalize(this.n));
|
|
635
|
+
});
|
|
636
|
+
pb.func('readDepth01', [
|
|
637
|
+
pb.vec2('uv')
|
|
638
|
+
], function() {
|
|
639
|
+
this.$return(ShaderHelper.sampleLinearDepth(this, this.depthTex, this.uv, 0));
|
|
640
|
+
});
|
|
641
|
+
pb.func('estimateScreenThinnessComponents', [
|
|
642
|
+
pb.vec2('uv'),
|
|
643
|
+
pb.float('depth01'),
|
|
644
|
+
pb.vec3('normalWS'),
|
|
645
|
+
pb.float('radiusScale')
|
|
646
|
+
], function() {
|
|
647
|
+
this.$l.pixelStep = pb.div(pb.add(pb.vec2(1.2), pb.mul(pb.vec2(2.4), this.radiusScale)), this.targetSize.xy);
|
|
648
|
+
this.$l.depthAccum = pb.float(0);
|
|
649
|
+
this.$l.normalAccum = pb.float(0);
|
|
650
|
+
this.$l.sampleCount = pb.float(0);
|
|
651
|
+
const sampleAt = (offsetX, offsetY)=>{
|
|
652
|
+
this.$l.sampleUV = pb.clamp(pb.add(this.uv, pb.mul(this.pixelStep, pb.vec2(offsetX, offsetY))), pb.vec2(0), pb.vec2(1));
|
|
653
|
+
this.$l.sampleDepth01 = this.readDepth01(this.sampleUV);
|
|
654
|
+
this.depthAccum = pb.add(this.depthAccum, pb.abs(pb.sub(this.sampleDepth01, this.depth01)));
|
|
655
|
+
this.$if(pb.notEqual(this.hasNormalTex, 0), function() {
|
|
656
|
+
this.normalAccum = pb.add(this.normalAccum, pb.clamp(pb.sub(1, pb.dot(this.decodeNormal(this.sampleUV), this.normalWS)), 0, 1));
|
|
657
|
+
});
|
|
658
|
+
this.sampleCount = pb.add(this.sampleCount, 1);
|
|
659
|
+
};
|
|
660
|
+
sampleAt(1, 0);
|
|
661
|
+
sampleAt(-1, 0);
|
|
662
|
+
sampleAt(0, 1);
|
|
663
|
+
sampleAt(0, -1);
|
|
664
|
+
sampleAt(1, 1);
|
|
665
|
+
sampleAt(-1, -1);
|
|
666
|
+
this.$l.depthMean = pb.div(this.depthAccum, pb.max(this.sampleCount, 1));
|
|
667
|
+
this.$l.normalMean = pb.div(this.normalAccum, pb.max(this.sampleCount, 1));
|
|
668
|
+
this.$l.depthThin = pb.clamp(pb.mul(this.depthMean, pb.add(52, pb.mul(this.radiusScale, 18))), 0, 1);
|
|
669
|
+
this.$l.normalThin = pb.clamp(pb.mul(this.normalMean, pb.add(1.4, pb.mul(this.radiusScale, 0.5))), 0, 1);
|
|
670
|
+
this.$l.combinedThin = pb.clamp(pb.add(pb.mul(this.depthThin, 0.72), pb.mul(this.normalThin, 0.52)), 0, 1);
|
|
671
|
+
this.$return(pb.vec3(this.depthThin, this.normalThin, this.combinedThin));
|
|
672
|
+
});
|
|
673
|
+
pb.func('reconstructViewPos', [
|
|
674
|
+
pb.vec2('uv'),
|
|
675
|
+
pb.float('linearDepth')
|
|
676
|
+
], function() {
|
|
677
|
+
this.$l.viewDepth = pb.max(pb.mul(this.linearDepth, this.cameraNearFar.y), 1e-5);
|
|
678
|
+
this.$l.nonLinearDepth = pb.div(pb.sub(pb.div(pb.mul(this.cameraNearFar.x, this.cameraNearFar.y), this.viewDepth), this.cameraNearFar.y), pb.sub(this.cameraNearFar.x, this.cameraNearFar.y));
|
|
679
|
+
this.$l.clipPos = pb.vec4(pb.sub(pb.mul(this.uv, 2), pb.vec2(1)), pb.sub(pb.mul(pb.clamp(this.nonLinearDepth, 0, 1), 2), 1), 1);
|
|
680
|
+
this.$l.viewPos = pb.mul(this.invProjMatrix, this.clipPos);
|
|
681
|
+
this.$return(pb.div(this.viewPos.xyz, pb.max(this.viewPos.w, 1e-5)));
|
|
682
|
+
});
|
|
683
|
+
pb.func('calculateMainLightDirection', [
|
|
684
|
+
pb.vec3('worldPos'),
|
|
685
|
+
pb.int('lightType'),
|
|
686
|
+
pb.vec4('posRange'),
|
|
687
|
+
pb.vec4('dirCutoff'),
|
|
688
|
+
pb.vec3('fallbackDir')
|
|
689
|
+
], function() {
|
|
690
|
+
this.$return(this.$choice(pb.equal(this.lightType, LIGHT_TYPE_DIRECTIONAL), pb.normalize(this.fallbackDir), pb.normalize(pb.sub(this.posRange.xyz, this.worldPos))));
|
|
691
|
+
});
|
|
692
|
+
pb.func('calculateMainLightAttenuation', [
|
|
693
|
+
pb.vec3('worldPos'),
|
|
694
|
+
pb.int('lightType'),
|
|
695
|
+
pb.vec4('posRange'),
|
|
696
|
+
pb.vec4('dirCutoff')
|
|
697
|
+
], function() {
|
|
698
|
+
this.$if(pb.equal(this.lightType, LIGHT_TYPE_DIRECTIONAL), function() {
|
|
699
|
+
this.$return(pb.float(1));
|
|
700
|
+
});
|
|
701
|
+
this.$l.dist = pb.distance(this.posRange.xyz, this.worldPos);
|
|
702
|
+
this.$l.falloff = pb.max(0, pb.sub(1, pb.div(this.dist, pb.max(this.posRange.w, 1e-4))));
|
|
703
|
+
this.$if(pb.or(pb.equal(this.lightType, LIGHT_TYPE_POINT), pb.equal(this.lightType, LIGHT_TYPE_RECT)), function() {
|
|
704
|
+
this.$return(pb.mul(this.falloff, this.falloff));
|
|
705
|
+
});
|
|
706
|
+
this.$l.spotFactor = pb.dot(pb.normalize(pb.sub(this.worldPos, this.posRange.xyz)), this.dirCutoff.xyz);
|
|
707
|
+
this.spotFactor = pb.smoothStep(this.dirCutoff.w, pb.mix(this.dirCutoff.w, 1, 0.5), this.spotFactor);
|
|
708
|
+
this.$return(pb.mul(this.spotFactor, this.falloff, this.falloff));
|
|
709
|
+
});
|
|
710
|
+
if (shadowEnabled) {
|
|
711
|
+
pb.func('calculateTransmissionShadow', [
|
|
712
|
+
pb.vec3('worldPos'),
|
|
713
|
+
pb.float('depth01'),
|
|
714
|
+
pb.float('NoL')
|
|
715
|
+
], function() {
|
|
716
|
+
if (shadowMapParams.numShadowCascades > 1) {
|
|
717
|
+
this.$l.linearDepth = pb.mul(this.depth01, this.camera.params.y);
|
|
718
|
+
this.$l.splitDistances = this.light.cascadeDistances;
|
|
719
|
+
this.$l.comparison = pb.vec4(pb.greaterThan(pb.vec4(this.linearDepth), this.splitDistances));
|
|
720
|
+
this.$l.cascadeFlags = pb.vec4(pb.float(pb.greaterThan(this.light.shadowCascades, 0)), pb.float(pb.greaterThan(this.light.shadowCascades, 1)), pb.float(pb.greaterThan(this.light.shadowCascades, 2)), pb.float(pb.greaterThan(this.light.shadowCascades, 3)));
|
|
721
|
+
this.$l.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));
|
|
722
|
+
if (ctx.device.type === 'webgl') {
|
|
723
|
+
this.$l.shadowVertex = pb.vec4();
|
|
724
|
+
this.$for(pb.int('cascade'), 0, 4, function() {
|
|
725
|
+
this.$if(pb.equal(this.cascade, this.split), function() {
|
|
726
|
+
this.shadowVertex = ShaderHelper.calculateShadowSpaceVertex(this, pb.vec4(this.worldPos, 1), this.cascade);
|
|
727
|
+
this.$break();
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
} else {
|
|
731
|
+
this.$l.shadowVertex = ShaderHelper.calculateShadowSpaceVertex(this, pb.vec4(this.worldPos, 1), this.split);
|
|
732
|
+
}
|
|
733
|
+
this.$l.shadow = shadowMapParams.impl.computeShadowCSM(shadowMapParams, this, this.shadowVertex, this.NoL, this.split);
|
|
734
|
+
this.$l.shadowDistance = this.light.shadowCameraParams.w;
|
|
735
|
+
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(this.camera.position.xyz, this.worldPos)));
|
|
736
|
+
this.shadow = pb.mix(1, this.shadow, this.light.shadowStrength);
|
|
737
|
+
this.shadow = pb.clamp(this.shadow, 0, 1);
|
|
738
|
+
this.$return(this.shadow);
|
|
739
|
+
}
|
|
740
|
+
this.$l.shadowVertex = ShaderHelper.calculateShadowSpaceVertex(this, pb.vec4(this.worldPos, 1));
|
|
741
|
+
this.$l.shadow = shadowMapParams.impl.computeShadow(shadowMapParams, this, this.shadowVertex, this.NoL);
|
|
742
|
+
this.$l.shadowDistance = this.light.shadowCameraParams.w;
|
|
743
|
+
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(this.camera.position.xyz, this.worldPos)));
|
|
744
|
+
this.shadow = pb.mix(1, this.shadow, this.light.shadowStrength);
|
|
745
|
+
this.shadow = pb.clamp(this.shadow, 0, 1);
|
|
746
|
+
this.$return(this.shadow);
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
pb.main(function() {
|
|
750
|
+
this.$l.uv = this.$inputs.uv;
|
|
751
|
+
this.$l.baseColor = pb.textureSampleLevel(this.colorTex, this.uv, 0);
|
|
752
|
+
this.$l.baseDiffuseColor = pb.textureSampleLevel(this.diffuseTex, this.uv, 0).rgb;
|
|
753
|
+
this.$l.baseTransmissionColor = pb.vec3(0);
|
|
754
|
+
this.$l.debugThinness = pb.float(0);
|
|
755
|
+
this.$l.debugThinnessLayers = pb.vec3(0);
|
|
756
|
+
this.$l.debugTransmissionMask = pb.float(0);
|
|
757
|
+
this.$l.debugThinLighting = pb.vec3(0);
|
|
758
|
+
this.$l.debugProfileEnergy = pb.vec3(0);
|
|
759
|
+
this.$l.debugProfileTransmission = pb.vec3(0);
|
|
760
|
+
this.$l.debugProfileBoundary = pb.vec3(0);
|
|
761
|
+
this.$l.debugTransmissionShadow = pb.float(0);
|
|
762
|
+
this.$if(pb.notEqual(this.hasTransmissionTex, 0), function() {
|
|
763
|
+
this.baseTransmissionColor = pb.textureSampleLevel(this.transmissionTex, this.uv, 0).rgb;
|
|
764
|
+
});
|
|
765
|
+
this.$l.profile = pb.textureSampleLevel(this.profileTex, this.uv, 0);
|
|
766
|
+
this.$l.param = pb.textureSampleLevel(this.paramTex, this.uv, 0);
|
|
767
|
+
this.$l.profileActive = pb.greaterThan(this.param.a, 0.5);
|
|
768
|
+
this.$l.scatterSoftnessAuthor = pb.clamp(pb.mul(pb.sub(this.param.a, 0.75), 4), 0, 1);
|
|
769
|
+
this.$l.roughnessInfo = pb.textureSampleLevel(this.roughnessTex, this.uv, 0);
|
|
770
|
+
this.$l.profileStrength = this.max3(this.profile.rgb);
|
|
771
|
+
this.$l.materialTransmissionMask = pb.clamp(this.profile.a, 0, 1);
|
|
772
|
+
this.debugTransmissionMask = this.materialTransmissionMask;
|
|
773
|
+
this.$l.profileSlot = this.readProfileSlot(this.param);
|
|
774
|
+
this.$l.profilePreset = this.readProfilePreset(this.param);
|
|
775
|
+
this.$l.depth01 = this.readDepth01(this.uv);
|
|
776
|
+
this.$l.result = this.baseColor.rgb;
|
|
777
|
+
this.$if(pb.and(pb.and(pb.and(pb.greaterThan(this.profileStrength, 1e-4), pb.greaterThan(this.profileSlot, 0)), this.profileActive), pb.lessThan(this.depth01, 1)), function() {
|
|
778
|
+
this.$l.widthStrength = pb.clamp(this.param.g, 0, 0.999);
|
|
779
|
+
this.$l.profileSettingsA = this.readProfileSettingsA(this.profileSlot);
|
|
780
|
+
this.$l.profileTransmissionTint = this.readProfileTransmissionTint(this.profileSlot);
|
|
781
|
+
this.$l.profileSettingsB = this.readProfileSettingsB(this.profileSlot);
|
|
782
|
+
this.$l.profileWorldScale = pb.clamp(this.profileSettingsA.x, 0.05, SSS._profileWorldScaleEncodeMax);
|
|
783
|
+
this.$l.profileBoundaryBleed = pb.clamp(this.profileSettingsA.y, 0, 1);
|
|
784
|
+
this.$l.profileNormalScale = pb.clamp(this.profileSettingsA.z, 0, SSS._profileNormalScaleEncodeMax);
|
|
785
|
+
this.$l.profileDistribution = pb.clamp(this.profileSettingsA.w, 0, 1);
|
|
786
|
+
this.$l.profileExtinctionScale = pb.clamp(this.profileSettingsB.x, 0, SSS._profileExtinctionEncodeMax);
|
|
787
|
+
this.$l.profileScatterScale = pb.clamp(this.profileSettingsB.y, 0.05, SSS._profileWorldScaleEncodeMax);
|
|
788
|
+
this.$l.profileStrengthScale = pb.clamp(this.profileSettingsB.z, 0.05, 2);
|
|
789
|
+
this.$l.profileWorldScaleNorm = pb.clamp(pb.div(this.profileWorldScale, SSS._profileWorldScaleEncodeMax), 0, 1);
|
|
790
|
+
this.$l.profileScatterScaleNorm = pb.clamp(pb.div(this.profileScatterScale, SSS._profileWorldScaleEncodeMax), 0, 1);
|
|
791
|
+
this.$l.profileStrengthNorm = pb.clamp(pb.mul(this.profileStrengthScale, 0.5), 0, 1);
|
|
792
|
+
this.$l.extinctionNorm = pb.clamp(pb.div(this.profileExtinctionScale, SSS._profileExtinctionEncodeMax), 0, 1);
|
|
793
|
+
this.$l.profileRadius = pb.mul(this.readProfileRadius(this.profileSlot), this.profileWorldScale, pb.mix(0.78, 1.42, this.profileScatterScaleNorm), pb.mix(0.92, 1.08, this.profileStrengthNorm));
|
|
794
|
+
this.$l.profileFalloff = this.readProfileFalloff(this.profileSlot);
|
|
795
|
+
this.$l.maxProfileRadius = pb.max(this.max3(this.profileRadius), 1e-4);
|
|
796
|
+
this.$l.radiusTint = pb.div(this.profileRadius, this.maxProfileRadius);
|
|
797
|
+
this.$l.avgFalloff = pb.mul(pb.add(this.profileFalloff.x, pb.add(this.profileFalloff.y, this.profileFalloff.z)), 0.3333333);
|
|
798
|
+
this.$l.profileSpread = pb.clamp(pb.div(this.maxProfileRadius, pb.add(this.maxProfileRadius, 0.65)), 0, 1);
|
|
799
|
+
this.$l.profileDiffusionSoftness = pb.clamp(pb.add(pb.add(0.32, pb.mul(this.profileSpread, 0.34)), pb.add(pb.mul(this.profileDistribution, 0.18), pb.mul(this.profileStrengthNorm, 0.2))), 0.18, 1);
|
|
800
|
+
this.$l.profileEnergyScale = pb.clamp(pb.mul(pb.add(pb.add(0.52, pb.mul(this.profileScatterScaleNorm, 0.42)), pb.mul(this.profileStrengthNorm, 0.28)), pb.add(0.9, pb.mul(this.profileWorldScaleNorm, 0.16))), 0.45, 1.55);
|
|
801
|
+
this.$l.profileTransmissionScale = pb.clamp(pb.mul(pb.add(pb.add(0.44, pb.mul(this.profileScatterScaleNorm, 0.36)), pb.add(pb.mul(this.profileStrengthNorm, 0.26), pb.mul(this.profileBoundaryBleed, 0.08))), pb.mix(1.1, 0.72, this.extinctionNorm)), 0.28, 1.35);
|
|
802
|
+
this.$l.profileTintBase = pb.div(pb.max(pb.mul(pb.pow(this.profileFalloff, pb.vec3(0.8)), pb.mix(pb.vec3(0.72), pb.vec3(1.35), this.radiusTint)), pb.vec3(1e-4)), pb.max(this.max3(pb.mul(pb.pow(this.profileFalloff, pb.vec3(0.8)), pb.mix(pb.vec3(0.72), pb.vec3(1.35), this.radiusTint))), 1e-4));
|
|
803
|
+
this.$l.presetTintBias = this.readProfileTintBias(this.profileSlot);
|
|
804
|
+
this.$l.presetResponse = this.readProfilePresetResponse(this.profileSlot);
|
|
805
|
+
this.$l.presetFrontScatter = this.presetResponse.x;
|
|
806
|
+
this.$l.presetSoftness = this.presetResponse.y;
|
|
807
|
+
this.$l.presetEnergyBoost = this.presetResponse.z;
|
|
808
|
+
this.$l.presetTransmissionBoost = this.presetResponse.w;
|
|
809
|
+
this.$l.presetTint = pb.mul(this.profileTintBase, this.presetTintBias, pb.mix(pb.vec3(1), this.profileTransmissionTint, pb.mul(this.profileBoundaryBleed, 0.22)));
|
|
810
|
+
this.$l.tint = pb.div(pb.max(this.presetTint, pb.vec3(1e-4)), pb.max(this.max3(this.presetTint), 1e-4));
|
|
811
|
+
this.$l.baseLuma = pb.dot(this.baseColor.rgb, pb.vec3(0.2126, 0.7152, 0.0722));
|
|
812
|
+
this.$l.shadowMask = pb.clamp(pb.sub(0.82, this.baseLuma), 0, 1);
|
|
813
|
+
this.$l.radiusResponse = pb.clamp(pb.add(pb.mul(this.widthStrength, 0.9), pb.mul(this.profileSpread, 0.62), pb.add(pb.mul(this.profileDiffusionSoftness, 0.18), pb.add(pb.mul(this.avgFalloff, 0.16), pb.mul(this.profileEnergyScale, 0.08)))), 0, 1);
|
|
814
|
+
this.$l.normalWS = this.decodeNormal(this.uv);
|
|
815
|
+
this.$l.viewPos = this.reconstructViewPos(this.uv, this.depth01);
|
|
816
|
+
this.$l.worldPos = pb.mul(this.invViewMatrix, pb.vec4(this.viewPos, 1)).xyz;
|
|
817
|
+
this.$l.sunDirWS = this.calculateMainLightDirection(this.worldPos, this.mainLightType, this.mainLightPosRange, this.mainLightDirCutoff, this.sunDir);
|
|
818
|
+
this.$l.mainLightAttenuation = this.calculateMainLightAttenuation(this.worldPos, this.mainLightType, this.mainLightPosRange, this.mainLightDirCutoff);
|
|
819
|
+
this.$l.frontLit = pb.mul(pb.dot(this.normalWS, this.sunDirWS), this.mainLightAttenuation);
|
|
820
|
+
this.$l.transmissionShadowRaw = pb.float(1);
|
|
821
|
+
this.$l.transmissionShadow = pb.float(1);
|
|
822
|
+
if (shadowEnabled) {
|
|
823
|
+
this.transmissionShadowRaw = this.calculateTransmissionShadow(this.worldPos, this.depth01, pb.clamp(pb.abs(pb.dot(this.normalWS, this.sunDirWS)), 0, 1));
|
|
824
|
+
}
|
|
825
|
+
this.transmissionShadow = this.transmissionShadowRaw;
|
|
826
|
+
this.$l.transmissionLightAttenuation = pb.mul(this.mainLightAttenuation, this.transmissionShadow);
|
|
827
|
+
this.$l.thinnessComponents = this.estimateScreenThinnessComponents(this.uv, this.depth01, this.normalWS, this.radiusResponse);
|
|
828
|
+
this.$l.depthThinness = this.thinnessComponents.x;
|
|
829
|
+
this.$l.curvatureThinness = this.thinnessComponents.y;
|
|
830
|
+
this.$l.screenThinness = this.thinnessComponents.z;
|
|
831
|
+
this.debugThinness = this.screenThinness;
|
|
832
|
+
this.debugThinnessLayers = pb.vec3(this.depthThinness, this.curvatureThinness, 0);
|
|
833
|
+
this.$l.wrappedFront = pb.smoothStep(pb.add(-0.32, pb.mul(this.profileSpread, 0.08)), pb.add(0.42, pb.mul(this.radiusResponse, 0.16)), pb.add(this.frontLit, pb.mul(this.radiusResponse, 0.18)));
|
|
834
|
+
this.$l.terminatorWrap = pb.clamp(pb.mul(pb.max(pb.sub(this.wrappedFront, pb.clamp(this.frontLit, 0, 1)), 0), pb.add(0.85, pb.mul(this.avgFalloff, 0.3), pb.mul(this.profileSpread, 0.22))), 0, 1);
|
|
835
|
+
this.$l.surfaceScatterMask = pb.clamp(pb.add(pb.add(pb.mul(this.shadowMask, 0.58), pb.mul(this.terminatorWrap, 0.82)), pb.add(pb.add(pb.mul(pb.clamp(pb.sub(1, pb.max(this.frontLit, 0)), 0, 1), 0.12), pb.mul(this.profileSpread, 0.06)), pb.mul(this.screenThinness, pb.add(pb.add(0.08, pb.mul(this.profileSpread, 0.08)), pb.mul(this.profileBoundaryBleed, 0.08))))), 0.05, 1);
|
|
836
|
+
this.$l.materialScatterBoost = pb.clamp(pb.add(pb.mul(pb.max(pb.sub(this.profileStrength, 0.9), 0), 0.72), pb.add(pb.mul(pb.max(pb.sub(this.widthStrength, 0.55), 0), 1.45), pb.add(pb.mul(pb.max(pb.sub(this.profileSpread, 0.58), 0), 0.42), pb.add(pb.mul(pb.sub(this.profileDistribution, 0.5), 0.28), pb.mul(this.profileStrengthNorm, 0.18))))), 0, 1);
|
|
837
|
+
this.$l.materialTransmissionResponse = pb.clamp(pb.mul(this.materialTransmissionMask, pb.add(pb.add(0.7, pb.mul(this.profileSpread, 0.14)), pb.add(pb.add(pb.mul(this.presetTransmissionBoost, 0.52), pb.mul(this.presetSoftness, 0.22)), pb.add(pb.mul(this.profileBoundaryBleed, 0.08), pb.add(pb.mul(pb.sub(1, this.extinctionNorm), 0.1), pb.mul(this.profileTransmissionScale, 0.14)))))), 0, 1);
|
|
838
|
+
this.$l.materialTransmissionSoftness = pb.clamp(pb.add(pb.mul(this.materialTransmissionResponse, 0.42), pb.add(pb.mul(this.widthStrength, 0.08), pb.mul(this.profileSpread, 0.06))), 0, 0.65);
|
|
839
|
+
this.$l.materialThicknessField = pb.clamp(pb.add(pb.add(pb.mul(this.materialTransmissionResponse, 0.82), pb.mul(this.materialTransmissionSoftness, 0.28)), pb.add(pb.mul(this.widthStrength, 0.06), pb.mul(this.profileSpread, 0.08))), 0, 1);
|
|
840
|
+
this.debugProfileEnergy = pb.clamp(pb.vec3(this.profileStrengthNorm, pb.div(this.profileEnergyScale, 1.55), this.materialScatterBoost), pb.vec3(0), pb.vec3(1));
|
|
841
|
+
this.debugProfileTransmission = pb.clamp(pb.vec3(pb.div(this.profileTransmissionScale, 1.35), this.materialTransmissionResponse, this.materialThicknessField), pb.vec3(0), pb.vec3(1));
|
|
842
|
+
this.debugProfileBoundary = pb.clamp(pb.vec3(this.profileBoundaryBleed, this.profileDiffusionSoftness, this.materialTransmissionSoftness), pb.vec3(0), pb.vec3(1));
|
|
843
|
+
this.$l.edgeThinBoost = pb.clamp(pb.mul(this.screenThinness, pb.add(0.14, pb.mul(this.materialThicknessField, 0.22))), 0, 0.32);
|
|
844
|
+
this.$l.curvatureThinBoost = pb.clamp(pb.mul(this.curvatureThinness, pb.add(pb.add(0.08, pb.mul(this.materialThicknessField, 0.12)), pb.mul(pb.sub(this.profileNormalScale, 1), 0.08))), 0, 0.18);
|
|
845
|
+
this.$l.scatterMask = pb.clamp(pb.add(this.surfaceScatterMask, pb.add(pb.add(pb.mul(this.materialScatterBoost, 0.28), this.presetFrontScatter), pb.add(pb.mul(pb.clamp(pb.sub(1, pb.max(this.frontLit, 0)), 0, 1), pb.add(pb.mul(this.materialScatterBoost, 0.22), pb.mul(this.presetFrontScatter, 0.7))), pb.mul(this.screenThinness, pb.add(0.12, pb.mul(this.presetSoftness, 0.08), pb.mul(this.presetFrontScatter, 0.08))), pb.mul(this.materialTransmissionSoftness, 0.1)))), pb.add(pb.add(0.05, pb.mul(this.materialScatterBoost, 0.12)), pb.mul(this.presetFrontScatter, 0.3)), 1);
|
|
846
|
+
this.$l.scatterMix = pb.add(pb.add(0.54, pb.mul(this.radiusResponse, 0.94)), pb.add(pb.add(pb.mul(this.avgFalloff, 0.22), pb.mul(this.profileSpread, 0.08)), pb.add(pb.mul(this.materialScatterBoost, 0.3), this.presetSoftness)));
|
|
847
|
+
this.$l.scatterStrength = pb.clamp(pb.mul(pb.max(pb.mul(this.profileStrength, pb.mix(0.88, 1.24, this.profileStrengthNorm)), pb.mul(this.widthStrength, 0.45)), this.sssStrength, this.profileEnergyScale, pb.add(pb.add(0.62, pb.mul(this.avgFalloff, 0.56)), pb.add(pb.add(pb.mul(this.profileSpread, 0.28), pb.mul(this.screenThinness, 0.18)), pb.add(pb.add(pb.mul(this.materialScatterBoost, 0.42), pb.mul(this.presetSoftness, 0.5)), pb.mul(this.materialTransmissionSoftness, 0.22))))), 0, pb.add(pb.add(pb.add(1.05, pb.mul(this.materialScatterBoost, 1.1)), pb.add(pb.mul(this.presetSoftness, 0.8), pb.mul(this.profileEnergyScale, 0.24))), pb.mul(this.screenThinness, 0.22)));
|
|
848
|
+
this.$l.blurred = pb.textureSampleLevel(this.blurTex, this.uv, 0).rgb;
|
|
849
|
+
this.$l.roughness = pb.float(1);
|
|
850
|
+
this.$l.specMask = pb.float(0.12);
|
|
851
|
+
this.$if(pb.notEqual(this.hasRoughnessTex, 0), function() {
|
|
852
|
+
this.roughness = this.roughnessInfo.a;
|
|
853
|
+
this.specMask = pb.clamp(pb.mul(this.max3(this.roughnessInfo.rgb), pb.add(0.45, pb.mul(pb.sub(1, this.roughness), 0.75))), 0, 1);
|
|
854
|
+
});
|
|
855
|
+
this.$if(pb.equal(this.hasDiffuseTex, 0), function() {
|
|
856
|
+
this.$l.specularFallback = pb.mul(this.baseColor.rgb, pb.clamp(pb.add(pb.mul(this.specMask, pb.add(0.12, pb.mul(pb.sub(1, this.roughness), 0.28))), pb.mul(this.profileStrength, 0.06)), 0, 0.5));
|
|
857
|
+
this.baseDiffuseColor = pb.max(pb.sub(this.baseColor.rgb, this.specularFallback), pb.vec3(0));
|
|
858
|
+
});
|
|
859
|
+
this.$l.baseDiffuseSafe = pb.max(this.baseDiffuseColor, pb.vec3(1e-4));
|
|
860
|
+
this.$l.baseDiffuseLuma = pb.dot(this.baseDiffuseSafe, pb.vec3(0.2126, 0.7152, 0.0722));
|
|
861
|
+
this.$l.epidermalMix = pb.clamp(pb.add(pb.add(0.24, pb.mul(this.avgFalloff, 0.08)), pb.add(pb.mul(this.materialScatterBoost, 0.1), pb.mul(this.presetSoftness, 0.08))), 0.18, 0.48);
|
|
862
|
+
this.$l.deepMix = pb.clamp(pb.add(pb.add(0.52, pb.mul(this.profileSpread, 0.08)), pb.add(pb.mul(this.materialScatterBoost, 0.12), pb.mul(this.presetTransmissionBoost, 0.08))), 0.42, 0.72);
|
|
863
|
+
this.$l.skinTint = pb.normalize(pb.max(pb.mix(this.baseDiffuseSafe, pb.mul(this.baseDiffuseSafe, pb.mix(this.tint, this.profileTransmissionTint, pb.mul(this.profileBoundaryBleed, 0.2))), this.epidermalMix), pb.vec3(1e-4)));
|
|
864
|
+
this.$l.deepTint = pb.normalize(pb.max(pb.mix(this.skinTint, pb.mul(this.tint, pb.mix(pb.vec3(1), this.profileTransmissionTint, pb.clamp(pb.add(pb.mul(this.profileBoundaryBleed, 0.35), pb.mul(pb.sub(1, pb.clamp(pb.div(this.profileExtinctionScale, SSS._profileExtinctionEncodeMax), 0, 1)), 0.28)), 0, 0.8))), this.deepMix), pb.vec3(1e-4)));
|
|
865
|
+
this.$l.baseSpecular = pb.max(pb.sub(this.baseColor.rgb, this.baseDiffuseColor), pb.vec3(0));
|
|
866
|
+
this.$l.scatterBlend = pb.clamp(pb.mul(this.scatterStrength, pb.add(0.12, pb.mul(this.scatterMix, 0.24)), this.scatterMask), 0, pb.add(pb.add(0.7, pb.mul(this.materialScatterBoost, 0.22)), this.$choice(pb.equal(this.profilePreset, 1), 0.12, this.$choice(pb.equal(this.profilePreset, 2), 0.08, 0))));
|
|
867
|
+
this.$l.blurredLuma = pb.dot(this.blurred, pb.vec3(0.2126, 0.7152, 0.0722));
|
|
868
|
+
this.$l.profileBlurred = pb.mix(this.blurred, pb.mul(this.blurred, pb.mix(pb.vec3(1), this.skinTint, pb.clamp(pb.add(pb.add(0.2, pb.mul(this.avgFalloff, 0.26)), pb.add(pb.mul(this.materialScatterBoost, 0.16), pb.mul(this.presetSoftness, 0.18))), 0, 0.72))), pb.clamp(pb.add(pb.add(0.14, pb.mul(this.radiusResponse, 0.18)), pb.add(pb.mul(this.avgFalloff, 0.08), pb.add(pb.mul(this.materialScatterBoost, 0.16), pb.mul(this.presetSoftness, 0.16)))), 0, 0.58));
|
|
869
|
+
this.$l.warmBlur = pb.mul(pb.max(this.blurredLuma, pb.mul(this.baseDiffuseLuma, 0.82)), this.deepTint);
|
|
870
|
+
this.profileBlurred = pb.mix(this.profileBlurred, this.warmBlur, pb.clamp(pb.add(pb.add(0.1, pb.mul(this.avgFalloff, 0.08)), pb.add(pb.mul(this.materialScatterBoost, 0.12), pb.mul(this.presetSoftness, 0.08))), 0.08, 0.32));
|
|
871
|
+
this.$l.blurredClamped = pb.min(this.profileBlurred, pb.add(this.baseDiffuseColor, pb.mul(this.deepTint, pb.mul(this.scatterMask, pb.add(pb.add(0.06, pb.mul(this.radiusResponse, 0.18)), pb.add(pb.mul(this.avgFalloff, 0.08), pb.add(pb.mul(this.materialScatterBoost, 0.2), pb.mul(this.presetEnergyBoost, 0.18))))))));
|
|
872
|
+
this.$l.scattered = pb.mix(this.baseDiffuseColor, this.blurredClamped, this.scatterBlend);
|
|
873
|
+
this.$l.terminatorLift = pb.mul(this.baseDiffuseColor, this.deepTint, this.scatterStrength, this.terminatorWrap, pb.add(pb.add(0.014, pb.mul(this.radiusResponse, 0.022)), pb.add(pb.mul(this.profileSpread, 0.012), pb.add(pb.mul(this.materialScatterBoost, 0.02), pb.mul(this.presetSoftness, 0.012)))), pb.sub(1, pb.mul(this.specMask, 0.45)));
|
|
874
|
+
this.$l.multiScatterLift = pb.mul(pb.max(pb.sub(this.blurredClamped, this.baseDiffuseColor), pb.vec3(0)), this.scatterStrength, this.multiScatter, this.scatterMask, pb.add(0.08, pb.mul(this.radiusResponse, pb.add(pb.add(0.09, pb.mul(this.materialScatterBoost, 0.08)), pb.add(pb.mul(this.presetSoftness, 0.06), pb.add(pb.mul(pb.sub(this.profileScatterScale, 1), 0.04), pb.mul(this.profileDiffusionSoftness, 0.03)))))));
|
|
875
|
+
this.$l.subdermalFill = pb.mul(this.deepTint, this.scatterStrength, pb.add(pb.mul(this.shadowMask, pb.add(pb.add(0.026, pb.mul(this.radiusResponse, 0.08)), pb.add(pb.mul(this.profileSpread, 0.045), pb.mul(this.materialScatterBoost, 0.05)))), pb.add(pb.add(0.004, pb.mul(this.avgFalloff, 0.012)), pb.add(pb.mul(this.profileSpread, 0.004), pb.mul(this.materialScatterBoost, 0.008)))), this.scatterMask, pb.sub(1, pb.mul(this.specMask, 0.62)));
|
|
876
|
+
this.$l.veilColor = pb.mix(this.blurredClamped, pb.mul(this.blurredClamped, this.skinTint), 0.16);
|
|
877
|
+
this.$l.softVeil = pb.mul(this.veilColor, this.scatterStrength, this.scatterMask, pb.add(pb.add(pb.add(0.002, pb.mul(this.materialScatterBoost, 0.004)), pb.mul(this.presetSoftness, 0.004)), pb.mul(this.radiusResponse, pb.add(pb.add(0.007, pb.mul(this.avgFalloff, 0.007)), pb.add(pb.mul(this.profileSpread, 0.003), pb.add(pb.mul(this.materialScatterBoost, 0.006), pb.mul(this.presetSoftness, 0.004)))))), pb.sub(1, pb.mul(this.specMask, 0.55)));
|
|
878
|
+
this.$l.scatteredDiffuse = pb.add(this.scattered, pb.add(this.terminatorLift, pb.add(this.multiScatterLift, pb.add(this.subdermalFill, this.softVeil))));
|
|
879
|
+
this.$l.energyLimit = pb.add(this.baseDiffuseColor, pb.mul(this.deepTint, this.scatterStrength, this.scatterMask, pb.add(pb.add(pb.add(0.1, pb.mul(this.radiusResponse, 0.18)), pb.add(pb.mul(this.avgFalloff, 0.08), pb.mul(this.profileSpread, 0.04))), pb.add(pb.mul(this.materialScatterBoost, 0.28), this.presetEnergyBoost))));
|
|
880
|
+
this.$l.scatterBudget = pb.max(pb.sub(this.energyLimit, this.baseDiffuseColor), pb.vec3(0));
|
|
881
|
+
this.$l.scatterDelta = pb.max(pb.sub(this.scatteredDiffuse, this.baseDiffuseColor), pb.vec3(0));
|
|
882
|
+
this.$l.scatteredDiffuse = pb.add(this.baseDiffuseColor, pb.min(this.scatterDelta, this.scatterBudget));
|
|
883
|
+
this.$l.transmissionBudget = pb.mul(this.deepTint, this.scatterStrength, this.materialTransmissionResponse, this.transmissionStrength, this.profileTransmissionScale, pb.add(pb.add(pb.add(0.12, pb.mul(this.radiusResponse, 0.2)), pb.mul(this.materialTransmissionSoftness, 0.2)), pb.add(pb.mul(this.avgFalloff, 0.12), pb.add(pb.mul(this.profileSpread, 0.12), pb.add(pb.mul(this.materialScatterBoost, 0.12), pb.mul(this.presetTransmissionBoost, 0.22))))), pb.mix(0.82, 1.18, this.profileScatterScaleNorm));
|
|
884
|
+
this.$l.diffuseHeadroom = pb.mul(this.transmissionBudget, pb.add(pb.add(1.65, pb.mul(this.materialTransmissionResponse, 0.9)), pb.add(pb.add(pb.mul(this.materialTransmissionSoftness, 0.55), pb.mul(this.profileSpread, 0.2)), pb.mul(this.profileTransmissionScale, 0.22))));
|
|
885
|
+
this.result = pb.add(this.baseSpecular, this.scatteredDiffuse);
|
|
886
|
+
this.$if(pb.greaterThan(this.transmissionStrength, 0), function() {
|
|
887
|
+
this.$l.viewDirVS = pb.normalize(pb.neg(this.viewPos));
|
|
888
|
+
this.$l.viewDirWS = pb.normalize(pb.mul(this.invViewMatrix, pb.vec4(this.viewDirVS, 0)).xyz);
|
|
889
|
+
this.$l.rim = pb.pow(pb.clamp(pb.sub(1, pb.abs(pb.dot(this.normalWS, this.viewDirWS))), 0, 1), pb.max(this.transmissionPower, 0.1));
|
|
890
|
+
this.$l.transmissionShadowSoftness = pb.clamp(pb.add(pb.add(0.08, pb.mul(this.profileDiffusionSoftness, 0.18)), pb.add(pb.mul(this.materialTransmissionSoftness, 0.18), pb.add(pb.mul(this.screenThinness, 0.12), pb.mul(this.profileBoundaryBleed, 0.08)))), 0, 0.6);
|
|
891
|
+
this.$l.transmissionShadowFloor = pb.clamp(pb.add(pb.add(pb.mul(this.materialThicknessField, 0.06), pb.mul(this.edgeThinBoost, 0.48)), pb.add(pb.mul(this.curvatureThinBoost, 0.32), pb.add(pb.mul(this.profileBoundaryBleed, 0.06), pb.mul(this.profileTransmissionScale, 0.08)))), 0, 0.34);
|
|
892
|
+
this.transmissionShadow = pb.clamp(pb.max(pb.mix(this.transmissionShadowRaw, pb.pow(pb.clamp(this.transmissionShadowRaw, 1e-4, 1), 0.7), this.transmissionShadowSoftness), this.transmissionShadowFloor), 0.04, 1);
|
|
893
|
+
this.transmissionLightAttenuation = pb.mul(this.mainLightAttenuation, this.transmissionShadow);
|
|
894
|
+
this.debugTransmissionShadow = this.transmissionShadow;
|
|
895
|
+
this.debugProfileBoundary = pb.clamp(pb.vec3(this.profileBoundaryBleed, this.transmissionShadowSoftness, this.transmissionShadowFloor), pb.vec3(0), pb.vec3(1));
|
|
896
|
+
this.debugProfileTransmission = pb.clamp(pb.vec3(pb.div(this.profileTransmissionScale, 1.35), this.materialTransmissionResponse, this.transmissionShadow), pb.vec3(0), pb.vec3(1));
|
|
897
|
+
this.$l.backLit = pb.mul(pb.pow(pb.clamp(pb.dot(pb.neg(this.normalWS), this.sunDirWS), 0, 1), 1.5), this.transmissionLightAttenuation);
|
|
898
|
+
this.$l.thicknessBackScatter = pb.clamp(pb.add(pb.add(pb.mul(this.backLit, 0.82), pb.mul(this.rim, 0.24)), pb.mul(this.materialThicknessField, 0.08)), 0, 1);
|
|
899
|
+
this.$l.thinPotential = pb.clamp(pb.add(pb.add(pb.mul(this.materialThicknessField, 0.78), this.edgeThinBoost), pb.add(this.curvatureThinBoost, pb.mul(pb.sqrt(pb.max(pb.mul(this.depthThinness, this.curvatureThinness), 0)), pb.add(pb.add(0.08, pb.mul(this.profileSpread, 0.06)), pb.mul(pb.sub(this.profileDistribution, 0.5), 0.06))))), 0, 1);
|
|
900
|
+
this.$l.transmissionFocus = pb.clamp(pb.mul(pb.add(pb.mul(this.materialThicknessField, 0.72), pb.mul(this.thinPotential, 0.38)), pb.add(pb.add(0.22, pb.mul(this.thicknessBackScatter, 0.72)), pb.mul(this.backLit, 0.08))), 0, 1);
|
|
901
|
+
this.$l.thinRegion = pb.clamp(pb.add(pb.add(pb.mul(this.materialThicknessField, 0.86), pb.mul(this.transmissionFocus, 0.74)), pb.add(pb.add(pb.mul(this.edgeThinBoost, 0.9), pb.mul(this.curvatureThinBoost, 0.5)), pb.add(pb.mul(this.backLit, 0.1), pb.mul(this.profileSpread, 0.05)))), 0, 1);
|
|
902
|
+
this.$l.debugBlueSeed = pb.clamp(pb.mul(this.materialThicknessField, pb.max(pb.mul(this.thinRegion, pb.add(0.72, pb.mul(this.backLit, 0.18))), pb.mul(this.curvatureThinness, pb.add(0.34, pb.mul(this.materialThicknessField, 0.22)))), pb.clamp(pb.add(pb.add(pb.add(0.16, pb.mul(this.backLit, 0.26)), pb.mul(this.edgeThinBoost, 0.85)), pb.add(pb.mul(this.curvatureThinBoost, 0.4), pb.mul(pb.sub(1, this.depthThinness), 0.18))), 0, 1), pb.add(0.72, pb.mul(this.profileSpread, 0.08))), 0, 1);
|
|
903
|
+
this.$l.debugBlueDisplay = pb.pow(pb.clamp(pb.mul(pb.clamp(pb.sub(this.debugBlueSeed, 0.015), 0, 1), 2.15), 0, 1), 0.72);
|
|
904
|
+
this.$l.debugGreenDisplay = pb.clamp(pb.mul(this.curvatureThinness, pb.sub(1, pb.mul(this.depthThinness, 0.78)), pb.sub(1, pb.mul(this.debugBlueDisplay, 0.26))), 0, 1);
|
|
905
|
+
this.debugThinnessLayers = pb.vec3(pb.clamp(pb.mul(pb.clamp(pb.sub(this.depthThinness, pb.mul(this.curvatureThinness, 0.16)), 0, 1), pb.sub(1, pb.mul(this.debugBlueDisplay, 0.98))), 0, 1), this.debugGreenDisplay, this.debugBlueDisplay);
|
|
906
|
+
this.$l.sunColor = pb.min(pb.mul(this.sunColorIntensity.rgb, this.sunColorIntensity.a, this.transmissionLightAttenuation), pb.vec3(4));
|
|
907
|
+
this.$l.capturedTransmission = pb.mul(pb.mix(this.baseTransmissionColor, pb.mul(this.baseTransmissionColor, this.deepTint, this.profileTransmissionTint), pb.clamp(pb.add(pb.add(0.16, pb.mul(this.avgFalloff, 0.12)), pb.add(pb.mul(this.materialScatterBoost, 0.1), pb.mul(this.presetTransmissionBoost, 0.18))), 0, 0.45)), pb.mix(1.08, 0.64, this.extinctionNorm), this.materialTransmissionResponse, pb.sub(1, pb.mul(this.specMask, 0.18)));
|
|
908
|
+
this.$l.capturedTransmissionStrength = this.max3(this.capturedTransmission);
|
|
909
|
+
this.$l.profileTransmission = pb.mul(this.capturedTransmission, this.transmissionStrength, this.scatterStrength, this.transmissionShadow, pb.add(pb.add(0.88, pb.mul(this.radiusResponse, 0.18)), pb.add(pb.add(pb.mul(this.profileSpread, 0.08), pb.mul(this.thinRegion, 0.12)), pb.add(pb.mul(this.materialScatterBoost, 0.12), pb.mul(this.presetTransmissionBoost, 0.18)))), pb.add(pb.add(0.26, pb.mul(this.thicknessBackScatter, 0.48)), pb.add(pb.mul(this.materialThicknessField, 0.22), pb.mul(this.thinRegion, 0.08))));
|
|
910
|
+
this.$l.backScatterCore = pb.mul(this.deepTint, pb.max(this.blurredLuma, pb.mul(this.baseDiffuseLuma, 0.3)), this.materialThicknessField, this.materialTransmissionResponse, this.transmissionStrength, this.transmissionShadow, pb.add(pb.add(pb.add(pb.add(0.12, pb.mul(this.thicknessBackScatter, 0.34)), pb.add(pb.mul(this.materialThicknessField, 0.22), pb.mul(this.thinRegion, 0.12))), pb.mul(this.materialTransmissionSoftness, 0.14)), pb.add(pb.mul(this.radiusResponse, 0.08), pb.mul(this.presetTransmissionBoost, 0.12))), pb.add(pb.add(0.26, pb.mul(this.thicknessBackScatter, 0.52)), pb.add(pb.mul(this.materialThicknessField, 0.22), pb.mul(this.thinRegion, 0.12))), pb.sub(1, pb.mul(this.specMask, 0.35)));
|
|
911
|
+
this.$l.rimFallback = pb.mul(this.rim, this.materialTransmissionResponse, this.transmissionStrength, this.scatterStrength, this.transmissionShadow, this.radiusResponse, pb.add(pb.add(pb.add(0.028, pb.mul(this.avgFalloff, 0.04)), pb.mul(this.materialTransmissionSoftness, 0.03)), pb.add(pb.mul(this.profileSpread, 0.03), pb.add(pb.mul(this.materialScatterBoost, 0.04), pb.mul(this.presetTransmissionBoost, 0.06)))));
|
|
912
|
+
this.$l.warmTransmissionTint = pb.normalize(pb.max(pb.mix(pb.mix(this.deepTint, this.profileTransmissionTint, 0.35), pb.mul(this.profileTransmissionTint, pb.vec3(1.0, 0.36, 0.24)), pb.clamp(pb.add(pb.add(0.18, pb.mul(this.presetTransmissionBoost, 0.26)), pb.add(pb.mul(this.materialThicknessField, 0.24), pb.mul(this.thicknessBackScatter, 0.22))), 0, 0.72)), pb.vec3(1e-4)));
|
|
913
|
+
this.$l.warmTransmissionStrength = pb.clamp(pb.mul(pb.add(pb.add(0.08, pb.mul(this.materialThicknessField, 0.2)), pb.add(pb.mul(this.thicknessBackScatter, 0.26), pb.mul(this.presetTransmissionBoost, 0.12))), pb.mix(1.06, 0.72, this.extinctionNorm)), 0.06, 0.48);
|
|
914
|
+
this.$l.broadTransmission = pb.mul(this.warmTransmissionTint, this.sunColor, this.materialThicknessField, this.materialTransmissionResponse, this.transmissionStrength, this.scatterStrength, pb.add(pb.add(0.1, pb.mul(this.thicknessBackScatter, 0.42)), pb.add(pb.mul(this.materialTransmissionSoftness, 0.12), pb.mul(this.thinRegion, 0.08))), pb.add(pb.add(0.24, pb.mul(this.materialThicknessField, 0.26)), pb.mul(this.profileSpread, 0.08)), pb.sub(1, pb.mul(this.specMask, 0.3)));
|
|
915
|
+
this.$l.subdermalTransmission = pb.mul(this.warmTransmissionTint, pb.max(this.baseDiffuseLuma, pb.mul(this.blurredLuma, 0.8)), this.materialThicknessField, this.materialTransmissionResponse, this.transmissionStrength, this.scatterStrength, this.transmissionShadow, this.warmTransmissionStrength, pb.add(pb.add(0.18, pb.mul(this.thicknessBackScatter, 0.38)), pb.add(pb.mul(this.thinRegion, 0.12), pb.mul(this.materialTransmissionSoftness, 0.08))), pb.sub(1, pb.mul(this.specMask, 0.28)));
|
|
916
|
+
this.$l.thin = pb.mul(this.thicknessBackScatter, this.materialThicknessField, this.materialTransmissionResponse, pb.add(this.thicknessBackScatter, pb.add(pb.mul(this.thinRegion, pb.add(0.18, pb.mul(this.presetTransmissionBoost, 0.16))), pb.mul(this.widthStrength, pb.add(pb.add(0.14, pb.mul(this.materialScatterBoost, 0.08)), pb.mul(this.presetTransmissionBoost, 0.08))), pb.mul(this.profileSpread, pb.add(pb.add(0.08, pb.mul(this.materialScatterBoost, 0.06)), pb.mul(this.presetTransmissionBoost, 0.08))))), this.transmissionStrength, this.scatterStrength, this.transmissionShadow, pb.add(pb.add(0.16, pb.mul(this.avgFalloff, 0.34)), pb.add(pb.add(pb.mul(this.profileSpread, 0.18), pb.mul(this.thinRegion, 0.22)), pb.add(pb.mul(this.materialScatterBoost, 0.12), this.presetTransmissionBoost))), pb.sub(1, pb.mul(this.specMask, 0.42)));
|
|
917
|
+
this.$l.transmissionColor = pb.add(pb.add(pb.add(pb.add(this.profileTransmission, this.backScatterCore), this.broadTransmission), this.subdermalTransmission), pb.mul(pb.add(pb.mul(this.warmTransmissionTint, this.sunColor, this.thin), pb.mul(this.skinTint, this.rimFallback)), this.$choice(pb.equal(this.hasTransmissionTex, 0), 1, pb.clamp(pb.add(0.08, pb.mul(pb.clamp(pb.sub(1, pb.mul(this.capturedTransmissionStrength, 2.4)), 0, 1), 0.22)), 0.08, 0.3))));
|
|
918
|
+
this.$l.transmissionHeadroom = pb.add(this.diffuseHeadroom, pb.mul(this.warmTransmissionTint, this.materialThicknessField, this.materialTransmissionResponse, this.transmissionStrength, pb.add(pb.add(0.04, pb.mul(this.thicknessBackScatter, 0.12)), pb.mul(this.thinRegion, 0.06))));
|
|
919
|
+
this.$l.transmittedDiffuse = pb.min(this.transmissionColor, this.transmissionHeadroom);
|
|
920
|
+
this.$l.transmittedDiffuseLuma = pb.dot(this.transmittedDiffuse, pb.vec3(0.2126, 0.7152, 0.0722));
|
|
921
|
+
this.$l.visibleTransmissionMask = pb.clamp(pb.add(pb.add(pb.mul(this.materialThicknessField, 0.72), pb.mul(this.thinRegion, 0.34)), pb.add(pb.mul(this.thicknessBackScatter, 0.28), pb.add(pb.mul(this.materialTransmissionSoftness, 0.08), pb.add(pb.mul(this.profileTransmissionScale, 0.12), pb.mul(this.profileDiffusionSoftness, 0.06))))), 0, 1);
|
|
922
|
+
this.$l.visibleTransmissionChroma = pb.clamp(pb.add(pb.add(0.66, pb.mul(this.visibleTransmissionMask, 0.32)), pb.add(pb.mul(this.thicknessBackScatter, 0.24), pb.mul(this.presetTransmissionBoost, 0.14))), 0.52, 1);
|
|
923
|
+
this.$l.visibleTransmissionTint = pb.normalize(pb.max(pb.mix(this.warmTransmissionTint, pb.mul(this.profileTransmissionTint, pb.vec3(1.0, 0.14, 0.08)), pb.clamp(pb.add(pb.add(0.5, pb.mul(this.visibleTransmissionMask, 0.22)), pb.mul(this.thicknessBackScatter, 0.18)), 0, 0.92)), pb.vec3(1e-4)));
|
|
924
|
+
this.$l.visibleTransmissionWarm = pb.mix(this.transmittedDiffuse, pb.mul(this.visibleTransmissionTint, this.transmittedDiffuseLuma), this.visibleTransmissionChroma);
|
|
925
|
+
this.$l.visibleTransmissionGain = pb.clamp(pb.add(pb.add(2.35, pb.mul(this.visibleTransmissionMask, 1.85)), pb.add(pb.mul(this.thicknessBackScatter, 1.3), pb.add(pb.mul(this.materialTransmissionSoftness, 0.42), pb.mul(this.profileTransmissionScale, 0.72)))), 2, 6.4);
|
|
926
|
+
this.$l.visibleTransmissionHeadroom = pb.add(pb.mul(this.transmissionHeadroom, pb.add(pb.add(2.15, pb.mul(this.visibleTransmissionMask, 1.1)), pb.mul(this.thicknessBackScatter, 0.72))), pb.mul(this.visibleTransmissionTint, this.visibleTransmissionMask, this.transmittedDiffuseLuma, pb.add(pb.add(0.12, pb.mul(this.thicknessBackScatter, 0.18)), pb.mul(this.materialThicknessField, 0.14))));
|
|
927
|
+
this.$l.visibleTransmission = pb.min(pb.mul(this.visibleTransmissionWarm, this.visibleTransmissionGain, this.transmissionShadow), this.visibleTransmissionHeadroom);
|
|
928
|
+
this.$l.visibleTransmissionReveal = pb.clamp(pb.mul(this.visibleTransmissionMask, this.transmissionShadow, pb.add(pb.add(0.1, pb.mul(this.thicknessBackScatter, 0.25)), pb.mul(this.materialThicknessField, 0.12))), 0, 0.38);
|
|
929
|
+
this.result = pb.mix(this.result, pb.mul(this.result, pb.vec3(0.84, 0.68, 0.64)), this.visibleTransmissionReveal);
|
|
930
|
+
this.debugThinLighting = this.visibleTransmission;
|
|
931
|
+
this.result = pb.add(this.result, this.visibleTransmission);
|
|
932
|
+
});
|
|
933
|
+
});
|
|
934
|
+
this.$if(pb.notEqual(this.debugView, 0), function() {
|
|
935
|
+
this.$if(pb.lessThan(this.depth01, 1), function() {
|
|
936
|
+
this.$if(pb.equal(this.debugView, 1), function() {
|
|
937
|
+
this.result = this.$choice(this.profileActive, pb.vec3(this.profileStrength), pb.vec3(0));
|
|
938
|
+
}).$elseif(pb.equal(this.debugView, 2), function() {
|
|
939
|
+
this.result = this.$choice(this.profileActive, pb.vec3(this.scatterSoftnessAuthor), pb.vec3(0));
|
|
940
|
+
}).$elseif(pb.equal(this.debugView, 3), function() {
|
|
941
|
+
this.$l.debugSlot = this.readProfileSlot(this.param);
|
|
942
|
+
this.result = this.$choice(this.profileActive, pb.clamp(pb.div(this.readProfileRadius(this.debugSlot), pb.vec3(8)), pb.vec3(0), pb.vec3(1)), pb.vec3(0));
|
|
943
|
+
}).$elseif(pb.equal(this.debugView, 4), function() {
|
|
944
|
+
this.$l.debugSlot = this.readProfileSlot(this.param);
|
|
945
|
+
this.result = this.$choice(this.profileActive, pb.clamp(this.readProfileFalloff(this.debugSlot), pb.vec3(0), pb.vec3(1)), pb.vec3(0));
|
|
946
|
+
}).$elseif(pb.equal(this.debugView, 5), function() {
|
|
947
|
+
this.result = this.$choice(this.profileActive, this.debugProfileEnergy, pb.vec3(0));
|
|
948
|
+
}).$elseif(pb.equal(this.debugView, 6), function() {
|
|
949
|
+
this.result = this.$choice(this.profileActive, this.debugProfileTransmission, pb.vec3(0));
|
|
950
|
+
}).$elseif(pb.equal(this.debugView, 7), function() {
|
|
951
|
+
this.result = this.$choice(this.profileActive, this.debugProfileBoundary, pb.vec3(0));
|
|
952
|
+
}).$elseif(pb.equal(this.debugView, 8), function() {
|
|
953
|
+
this.result = this.baseDiffuseColor;
|
|
954
|
+
}).$elseif(pb.equal(this.debugView, 9), function() {
|
|
955
|
+
this.result = this.$choice(this.profileActive, pb.textureSampleLevel(this.blurTex, this.uv, 0).rgb, pb.vec3(0));
|
|
956
|
+
}).$elseif(pb.equal(this.debugView, 10), function() {
|
|
957
|
+
this.result = this.$choice(this.profileActive, this.debugThinnessLayers, pb.vec3(0));
|
|
958
|
+
}).$elseif(pb.equal(this.debugView, 11), function() {
|
|
959
|
+
this.result = this.$choice(this.profileActive, pb.vec3(this.debugTransmissionMask, this.debugTransmissionMask, this.debugTransmissionMask), pb.vec3(0));
|
|
960
|
+
}).$elseif(pb.equal(this.debugView, 12), function() {
|
|
961
|
+
this.result = this.$choice(this.profileActive, this.debugThinLighting, pb.vec3(0));
|
|
962
|
+
}).$elseif(pb.equal(this.debugView, 13), function() {
|
|
963
|
+
this.result = this.$choice(this.profileActive, pb.vec3(this.debugTransmissionShadow, this.debugTransmissionShadow, this.debugTransmissionShadow), pb.vec3(0));
|
|
964
|
+
});
|
|
965
|
+
}).$else(function() {
|
|
966
|
+
this.result = pb.vec3(0);
|
|
967
|
+
});
|
|
968
|
+
});
|
|
969
|
+
this.$if(pb.equal(this.srgbOut, 0), function() {
|
|
970
|
+
this.$outputs.outColor = pb.vec4(this.result, this.baseColor.a);
|
|
971
|
+
}).$else(function() {
|
|
972
|
+
this.$outputs.outColor = pb.vec4(linearToGamma(this, this.result), this.baseColor.a);
|
|
973
|
+
});
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
});
|
|
977
|
+
program.name = '@SSS_Combine';
|
|
978
|
+
return program;
|
|
979
|
+
}
|
|
980
|
+
createSampleOffsets(kernelRadius) {
|
|
981
|
+
const sampleCount = Math.max(1, Math.ceil(kernelRadius / 2));
|
|
982
|
+
const data = new Float32Array(4 * (sampleCount + 1));
|
|
983
|
+
for(let i = 1; i <= sampleCount; i++){
|
|
984
|
+
const tap0 = i * 2 - 1;
|
|
985
|
+
const tap1 = Math.min(i * 2, kernelRadius);
|
|
986
|
+
data[i * 4 + 0] = tap1 !== tap0 ? (tap0 + tap1) * 0.5 : tap0;
|
|
987
|
+
}
|
|
988
|
+
return data;
|
|
989
|
+
}
|
|
990
|
+
ensureProfileLUT(ctx) {
|
|
991
|
+
const device = ctx.device;
|
|
992
|
+
if (!SSS._profileLUT || SSS._profileLUT.device !== device) {
|
|
993
|
+
SSS._profileLUT = device.createTexture2D('rgba8unorm', SSS._profileLUTWidth, SSS._profileLUTHeight, {
|
|
994
|
+
mipmapping: false
|
|
995
|
+
});
|
|
996
|
+
SSS._profileLUTVersion = -1;
|
|
997
|
+
}
|
|
998
|
+
if (SSS._profileLUTVersion !== SubsurfaceProfile.version) {
|
|
999
|
+
const data = new Uint8Array(SSS._profileLUTWidth * SSS._profileLUTHeight * 4);
|
|
1000
|
+
const encodeUnit = (value)=>Math.max(0, Math.min(255, Math.round(value * 255)));
|
|
1001
|
+
const encodeScaled = (value, maxValue)=>Math.max(0, Math.min(255, Math.round(Math.max(0, Math.min(maxValue, value)) / maxValue * 255)));
|
|
1002
|
+
for(let slot = 1; slot < SSS._profileLUTWidth; slot++){
|
|
1003
|
+
const profile = SubsurfaceProfile.getProfileBySlot(slot);
|
|
1004
|
+
if (!profile) {
|
|
1005
|
+
continue;
|
|
1006
|
+
}
|
|
1007
|
+
const presetTintBias = profile.getDerivedTintBias();
|
|
1008
|
+
const presetResponse = profile.getDerivedTransmissionResponse();
|
|
1009
|
+
const radiusOffset = slot * 4;
|
|
1010
|
+
data[radiusOffset + 0] = encodeScaled(profile.scatterRadius.x, SSS._profileRadiusEncodeMax);
|
|
1011
|
+
data[radiusOffset + 1] = encodeScaled(profile.scatterRadius.y, SSS._profileRadiusEncodeMax);
|
|
1012
|
+
data[radiusOffset + 2] = encodeScaled(profile.scatterRadius.z, SSS._profileRadiusEncodeMax);
|
|
1013
|
+
data[radiusOffset + 3] = 255;
|
|
1014
|
+
const falloffOffset = (SSS._profileLUTWidth + slot) * 4;
|
|
1015
|
+
data[falloffOffset + 0] = encodeUnit(profile.falloffColor.x);
|
|
1016
|
+
data[falloffOffset + 1] = encodeUnit(profile.falloffColor.y);
|
|
1017
|
+
data[falloffOffset + 2] = encodeUnit(profile.falloffColor.z);
|
|
1018
|
+
data[falloffOffset + 3] = 255;
|
|
1019
|
+
const tintBiasOffset = (SSS._profileLUTWidth * 2 + slot) * 4;
|
|
1020
|
+
data[tintBiasOffset + 0] = encodeUnit(presetTintBias[0]);
|
|
1021
|
+
data[tintBiasOffset + 1] = encodeUnit(presetTintBias[1]);
|
|
1022
|
+
data[tintBiasOffset + 2] = encodeUnit(presetTintBias[2]);
|
|
1023
|
+
data[tintBiasOffset + 3] = 255;
|
|
1024
|
+
const responseOffset = (SSS._profileLUTWidth * 3 + slot) * 4;
|
|
1025
|
+
data[responseOffset + 0] = encodeUnit(presetResponse[0]);
|
|
1026
|
+
data[responseOffset + 1] = encodeUnit(presetResponse[1]);
|
|
1027
|
+
data[responseOffset + 2] = encodeUnit((presetResponse[2] + 0.25) / 0.75);
|
|
1028
|
+
data[responseOffset + 3] = encodeUnit((presetResponse[3] + 0.25) / 0.75);
|
|
1029
|
+
const settingsAOffset = (SSS._profileLUTWidth * 4 + slot) * 4;
|
|
1030
|
+
data[settingsAOffset + 0] = encodeScaled(profile.worldUnitScale, SSS._profileWorldScaleEncodeMax);
|
|
1031
|
+
data[settingsAOffset + 1] = encodeUnit(profile.boundaryColorBleed);
|
|
1032
|
+
data[settingsAOffset + 2] = encodeScaled(profile.normalScale, SSS._profileNormalScaleEncodeMax);
|
|
1033
|
+
data[settingsAOffset + 3] = encodeUnit(profile.scatteringDistribution);
|
|
1034
|
+
const tintOffset = (SSS._profileLUTWidth * 5 + slot) * 4;
|
|
1035
|
+
data[tintOffset + 0] = encodeUnit(profile.transmissionTintColor.x);
|
|
1036
|
+
data[tintOffset + 1] = encodeUnit(profile.transmissionTintColor.y);
|
|
1037
|
+
data[tintOffset + 2] = encodeUnit(profile.transmissionTintColor.z);
|
|
1038
|
+
data[tintOffset + 3] = 255;
|
|
1039
|
+
const settingsBOffset = (SSS._profileLUTWidth * 6 + slot) * 4;
|
|
1040
|
+
data[settingsBOffset + 0] = encodeScaled(profile.extinctionScale, SSS._profileExtinctionEncodeMax);
|
|
1041
|
+
data[settingsBOffset + 1] = encodeScaled(profile.scale, SSS._profileWorldScaleEncodeMax);
|
|
1042
|
+
data[settingsBOffset + 2] = encodeUnit(profile.strength / 2);
|
|
1043
|
+
data[settingsBOffset + 3] = 255;
|
|
1044
|
+
}
|
|
1045
|
+
SSS._profileLUT.update(data, 0, 0, SSS._profileLUTWidth, SSS._profileLUTHeight);
|
|
1046
|
+
SSS._profileLUTVersion = SubsurfaceProfile.version;
|
|
1047
|
+
}
|
|
1048
|
+
return SSS._profileLUT;
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
export { SSS };
|
|
1053
|
+
//# sourceMappingURL=sss.js.map
|