@zephyr3d/scene 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/animation.js +25 -117
- package/dist/animation/animation.js.map +1 -1
- package/dist/animation/animationset.js +164 -24
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/animationtrack.js +6 -18
- package/dist/animation/animationtrack.js.map +1 -1
- package/dist/animation/eulerrotationtrack.js +16 -6
- package/dist/animation/eulerrotationtrack.js.map +1 -1
- package/dist/animation/morphtarget.js +104 -0
- package/dist/animation/morphtarget.js.map +1 -0
- package/dist/animation/morphtrack.js +68 -0
- package/dist/animation/morphtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +15 -7
- package/dist/animation/rotationtrack.js.map +1 -1
- package/dist/animation/scaletrack.js +15 -7
- package/dist/animation/scaletrack.js.map +1 -1
- package/dist/animation/skeleton.js +101 -1
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/translationtrack.js +15 -7
- package/dist/animation/translationtrack.js.map +1 -1
- package/dist/animation/usertrack.js +2 -2
- package/dist/app.js +4 -26
- package/dist/app.js.map +1 -1
- package/dist/asset/assetmanager.js +58 -107
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/loaders/dds/dds.js +77 -3
- package/dist/asset/loaders/dds/dds.js.map +1 -1
- package/dist/asset/loaders/dds/dds_loader.js +1 -1
- package/dist/asset/loaders/gltf/gltf_loader.js +280 -37
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/image/tga_Loader.js +1 -1
- package/dist/asset/model.js +13 -0
- package/dist/asset/model.js.map +1 -1
- package/dist/blitter/blitter.js +2 -2
- package/dist/camera/camera.js +58 -3
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +3026 -2839
- package/dist/index.js +2 -5
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +9 -4
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/lambert.js +22 -17
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +11 -2
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +36 -4
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +3 -3
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +3 -3
- package/dist/material/mixins/lit.js +2 -2
- package/dist/material/mixins/pbr/common.js +433 -10
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/pbrmr.js +17 -6
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/pbrsg.js +16 -9
- package/dist/material/pbrsg.js.map +1 -1
- package/dist/material/shader/helper.js +94 -4
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/unlit.js +8 -4
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/bloom.js +33 -43
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +8 -37
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/sao.js +11 -24
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/water.js +2 -4
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/cull_visitor.js +3 -3
- package/dist/render/depthpass.js +13 -13
- package/dist/render/drawable_mixin.js +48 -6
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/envlight.js +165 -31
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/lightpass.js +35 -27
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/objectcolorpass.js +50 -0
- package/dist/render/objectcolorpass.js.map +1 -0
- package/dist/render/objectpool.js +295 -0
- package/dist/render/objectpool.js.map +1 -0
- package/dist/render/render_queue.js +189 -156
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +97 -20
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/renderpass.js +18 -14
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +14 -14
- package/dist/render/weightedblended_oit.js +11 -28
- package/dist/render/weightedblended_oit.js.map +1 -1
- package/dist/scene/environment.js +22 -1
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +0 -9
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +32 -1
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/scene.js +5 -8
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +2 -3
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +9 -0
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/patch.js +9 -0
- package/dist/scene/terrain/patch.js.map +1 -1
- package/dist/scene/terrain/quadtree.js +2 -2
- package/dist/shadow/esm.js +4 -22
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/shadowmapper.js +45 -20
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/vsm.js +4 -24
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/draco/decoder.js +116 -0
- package/dist/utility/draco/decoder.js.map +1 -0
- package/dist/values.js +18 -1
- package/dist/values.js.map +1 -1
- package/package.json +7 -6
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { applyMaterialMixins } from '../../meshmaterial.js';
|
|
2
|
-
import { Vector4 } from '@zephyr3d/base';
|
|
2
|
+
import { Vector4, Vector3, Vector2 } from '@zephyr3d/base';
|
|
3
3
|
import { getGGXLUT } from '../ggxlut.js';
|
|
4
4
|
import { mixinTextureProps } from '../texture.js';
|
|
5
5
|
import { ShaderHelper } from '../../shader/helper.js';
|
|
@@ -14,9 +14,11 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
14
14
|
if (BaseCls.pbrCommonMixed) {
|
|
15
15
|
return BaseCls;
|
|
16
16
|
}
|
|
17
|
-
const S = applyMaterialMixins(BaseCls, mixinTextureProps('occlusion'), mixinTextureProps('emissive'), mixinTextureProps('sheenColor'), mixinTextureProps('sheenRoughness'), mixinTextureProps('clearcoatIntensity'), mixinTextureProps('clearcoatRoughness'), mixinTextureProps('clearcoatNormal'));
|
|
17
|
+
const S = applyMaterialMixins(BaseCls, mixinTextureProps('occlusion'), mixinTextureProps('emissive'), mixinTextureProps('sheenColor'), mixinTextureProps('sheenRoughness'), mixinTextureProps('clearcoatIntensity'), mixinTextureProps('clearcoatRoughness'), mixinTextureProps('clearcoatNormal'), mixinTextureProps('transmission'), mixinTextureProps('thickness'), mixinTextureProps('iridescence'), mixinTextureProps('iridescenceThickness'));
|
|
18
18
|
let FEATURE_SHEEN = 0;
|
|
19
19
|
let FEATURE_CLEARCOAT = 0;
|
|
20
|
+
let FEATURE_TRANSMISSION = 0;
|
|
21
|
+
let FEATURE_IRIDESCENCE = 0;
|
|
20
22
|
const cls = class extends S {
|
|
21
23
|
static pbrCommonMixed = true;
|
|
22
24
|
_f0;
|
|
@@ -24,6 +26,12 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
24
26
|
_occlusionStrength;
|
|
25
27
|
_sheenFactor;
|
|
26
28
|
_clearcoatFactor;
|
|
29
|
+
_transmissionFactor;
|
|
30
|
+
_thicknessFactor;
|
|
31
|
+
_attenuationColor;
|
|
32
|
+
_attenuationDistance;
|
|
33
|
+
_iridescenceFactor;
|
|
34
|
+
_sceneColorTexSize;
|
|
27
35
|
constructor(){
|
|
28
36
|
super();
|
|
29
37
|
this._f0 = new Vector4(0.04, 0.04, 0.04, 1.5);
|
|
@@ -31,6 +39,12 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
31
39
|
this._emissiveFactor = new Vector4(0, 0, 0, 1);
|
|
32
40
|
this._sheenFactor = Vector4.zero();
|
|
33
41
|
this._clearcoatFactor = new Vector4(0, 0, 1, 0);
|
|
42
|
+
this._transmissionFactor = 0;
|
|
43
|
+
this._thicknessFactor = 0;
|
|
44
|
+
this._attenuationColor = Vector3.one();
|
|
45
|
+
this._attenuationDistance = 99999;
|
|
46
|
+
this._iridescenceFactor = new Vector4(0, 1.3, 100, 400);
|
|
47
|
+
this._sceneColorTexSize = new Vector2();
|
|
34
48
|
}
|
|
35
49
|
get ior() {
|
|
36
50
|
return this._f0.w;
|
|
@@ -43,6 +57,78 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
43
57
|
this.uniformChanged();
|
|
44
58
|
}
|
|
45
59
|
}
|
|
60
|
+
get transmissionFactor() {
|
|
61
|
+
return this._transmissionFactor;
|
|
62
|
+
}
|
|
63
|
+
set transmissionFactor(val) {
|
|
64
|
+
if (val !== this._transmissionFactor) {
|
|
65
|
+
this._transmissionFactor = val;
|
|
66
|
+
this.uniformChanged();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
get thicknessFactor() {
|
|
70
|
+
return this._thicknessFactor;
|
|
71
|
+
}
|
|
72
|
+
set thicknessFactor(val) {
|
|
73
|
+
if (this._thicknessFactor !== val) {
|
|
74
|
+
this._thicknessFactor = val;
|
|
75
|
+
this.uniformChanged();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
get attenuationColor() {
|
|
79
|
+
return this._attenuationColor;
|
|
80
|
+
}
|
|
81
|
+
set attenuationColor(val) {
|
|
82
|
+
if (!val.equalsTo(this._attenuationColor)) {
|
|
83
|
+
this._attenuationColor.set(val);
|
|
84
|
+
this.uniformChanged();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
get attenuationDistance() {
|
|
88
|
+
return this._attenuationDistance;
|
|
89
|
+
}
|
|
90
|
+
set attenuationDistance(val) {
|
|
91
|
+
if (val !== this._attenuationDistance) {
|
|
92
|
+
this._attenuationDistance = val;
|
|
93
|
+
this.uniformChanged();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
get iridescenceFactor() {
|
|
97
|
+
return this._iridescenceFactor.x;
|
|
98
|
+
}
|
|
99
|
+
set iridescenceFactor(val) {
|
|
100
|
+
if (this._iridescenceFactor.x !== val) {
|
|
101
|
+
this._iridescenceFactor.x = val;
|
|
102
|
+
this.uniformChanged();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
get iridescenceIor() {
|
|
106
|
+
return this._iridescenceFactor.y;
|
|
107
|
+
}
|
|
108
|
+
set iridescenceIor(val) {
|
|
109
|
+
if (this._iridescenceFactor.y !== val) {
|
|
110
|
+
this._iridescenceFactor.y = val;
|
|
111
|
+
this.uniformChanged();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
get iridescenceThicknessMin() {
|
|
115
|
+
return this._iridescenceFactor.z;
|
|
116
|
+
}
|
|
117
|
+
set iridescenceThicknessMin(val) {
|
|
118
|
+
if (this._iridescenceFactor.z !== val) {
|
|
119
|
+
this._iridescenceFactor.z = val;
|
|
120
|
+
this.uniformChanged();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
get iridescenceThicknessMax() {
|
|
124
|
+
return this._iridescenceFactor.w;
|
|
125
|
+
}
|
|
126
|
+
set iridescenceThicknessMax(val) {
|
|
127
|
+
if (this._iridescenceFactor.w !== val) {
|
|
128
|
+
this._iridescenceFactor.w = val;
|
|
129
|
+
this.uniformChanged();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
46
132
|
get occlusionStrength() {
|
|
47
133
|
return this._occlusionStrength;
|
|
48
134
|
}
|
|
@@ -72,6 +158,18 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
72
158
|
this.uniformChanged();
|
|
73
159
|
}
|
|
74
160
|
}
|
|
161
|
+
get transmission() {
|
|
162
|
+
return this.featureUsed(FEATURE_TRANSMISSION);
|
|
163
|
+
}
|
|
164
|
+
set transmission(val) {
|
|
165
|
+
this.useFeature(FEATURE_TRANSMISSION, !!val);
|
|
166
|
+
}
|
|
167
|
+
get iridescence() {
|
|
168
|
+
return this.featureUsed(FEATURE_IRIDESCENCE);
|
|
169
|
+
}
|
|
170
|
+
set iridescence(val) {
|
|
171
|
+
this.useFeature(FEATURE_IRIDESCENCE, !!val);
|
|
172
|
+
}
|
|
75
173
|
get clearcoat() {
|
|
76
174
|
return this.featureUsed(FEATURE_CLEARCOAT);
|
|
77
175
|
}
|
|
@@ -146,11 +244,25 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
146
244
|
if (this.clearcoat) {
|
|
147
245
|
scope.zClearcoatFactor = pb.vec4().uniform(2);
|
|
148
246
|
}
|
|
247
|
+
if (this.transmission) {
|
|
248
|
+
scope.zTransmissionFactor = pb.float().uniform(2);
|
|
249
|
+
scope.zThicknessFactor = pb.float().uniform(2);
|
|
250
|
+
scope.zAttenuationColor = pb.vec3().uniform(2);
|
|
251
|
+
scope.zAttenuationDistance = pb.float().uniform(2);
|
|
252
|
+
scope.zSceneColorTex = pb.tex2D().uniform(2);
|
|
253
|
+
scope.zSceneColorTexSize = pb.vec2().uniform(2);
|
|
254
|
+
}
|
|
255
|
+
if (this.iridescence) {
|
|
256
|
+
scope.zIridescenceFactor = pb.vec4().uniform(2);
|
|
257
|
+
}
|
|
149
258
|
if (this.drawContext.drawEnvLight) {
|
|
150
259
|
scope.zGGXLut = pb.tex2D().uniform(2);
|
|
151
260
|
}
|
|
152
261
|
}
|
|
153
262
|
}
|
|
263
|
+
needSceneColor() {
|
|
264
|
+
return this.transmission;
|
|
265
|
+
}
|
|
154
266
|
applyUniformValues(bindGroup, ctx, pass) {
|
|
155
267
|
super.applyUniformValues(bindGroup, ctx, pass);
|
|
156
268
|
if (this.needFragmentColor(ctx)) {
|
|
@@ -165,6 +277,18 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
165
277
|
if (this.clearcoat) {
|
|
166
278
|
bindGroup.setValue('zClearcoatFactor', this._clearcoatFactor);
|
|
167
279
|
}
|
|
280
|
+
if (this.transmission) {
|
|
281
|
+
bindGroup.setValue('zTransmissionFactor', this._transmissionFactor);
|
|
282
|
+
bindGroup.setValue('zThicknessFactor', this._thicknessFactor);
|
|
283
|
+
bindGroup.setValue('zAttenuationColor', this._attenuationColor);
|
|
284
|
+
bindGroup.setValue('zAttenuationDistance', this._attenuationDistance);
|
|
285
|
+
bindGroup.setTexture('zSceneColorTex', ctx.sceneColorTexture);
|
|
286
|
+
this._sceneColorTexSize.setXY(ctx.sceneColorTexture.width, ctx.sceneColorTexture.height);
|
|
287
|
+
bindGroup.setValue('zSceneColorTexSize', this._sceneColorTexSize);
|
|
288
|
+
}
|
|
289
|
+
if (this.iridescence) {
|
|
290
|
+
bindGroup.setValue('zIridescenceFactor', this._iridescenceFactor);
|
|
291
|
+
}
|
|
168
292
|
if (ctx.drawEnvLight) {
|
|
169
293
|
bindGroup.setTexture('zGGXLut', getGGXLUT(1024));
|
|
170
294
|
}
|
|
@@ -192,25 +316,37 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
192
316
|
pb.vec3('ccNormal'),
|
|
193
317
|
pb.float('ccNoV'),
|
|
194
318
|
pb.float('ccFresnel')
|
|
319
|
+
] : [],
|
|
320
|
+
...this.transmission ? [
|
|
321
|
+
pb.float('transmissionFactor'),
|
|
322
|
+
pb.float('thicknessFactor'),
|
|
323
|
+
pb.vec3('attenuationColor'),
|
|
324
|
+
pb.float('attenuationDistance')
|
|
325
|
+
] : [],
|
|
326
|
+
...this.iridescence ? [
|
|
327
|
+
pb.vec4('iridescenceFactor'),
|
|
328
|
+
pb.vec3('iridescenceFresnel'),
|
|
329
|
+
pb.vec3('iridescenceF0')
|
|
195
330
|
] : []
|
|
196
331
|
]);
|
|
197
332
|
}
|
|
198
|
-
getCommonData(scope, albedo, viewVec, TBN) {
|
|
333
|
+
getCommonData(scope, albedo, normal, viewVec, TBN) {
|
|
199
334
|
const pb = scope.$builder;
|
|
200
335
|
const that = this;
|
|
201
336
|
const funcName = 'Z_getCommonData';
|
|
202
337
|
pb.func(funcName, [
|
|
203
338
|
pb.vec4('albedo'),
|
|
339
|
+
pb.vec3('normal'),
|
|
204
340
|
pb.vec3('viewVec'),
|
|
205
341
|
pb.mat3('TBN')
|
|
206
342
|
], function() {
|
|
207
343
|
this.$l.data = that.getCommonDatasStruct(this)();
|
|
208
|
-
that.calculateCommonData(this, this.albedo, this.viewVec, this.TBN, this.data);
|
|
344
|
+
that.calculateCommonData(this, this.albedo, this.normal, this.viewVec, this.TBN, this.data);
|
|
209
345
|
this.$return(this.data);
|
|
210
346
|
});
|
|
211
|
-
return scope.$g[funcName](albedo, viewVec, TBN);
|
|
347
|
+
return scope.$g[funcName](albedo, normal, viewVec, TBN);
|
|
212
348
|
}
|
|
213
|
-
calculateCommonData(scope, albedo, viewVec, TBN, data) {
|
|
349
|
+
calculateCommonData(scope, albedo, normal, viewVec, TBN, data) {
|
|
214
350
|
const pb = scope.$builder;
|
|
215
351
|
if (this.sheen) {
|
|
216
352
|
if (this.sheenColorTexture) {
|
|
@@ -242,6 +378,31 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
242
378
|
data.ccFactor.y = pb.clamp(pb.mul(data.ccFactor.y, this.sampleClearcoatRoughnessTexture(scope).g), 0, 1);
|
|
243
379
|
}
|
|
244
380
|
}
|
|
381
|
+
if (this.transmission) {
|
|
382
|
+
if (this.transmissionTexture) {
|
|
383
|
+
data.transmissionFactor = pb.mul(this.sampleTransmissionTexture(scope).r, scope.zTransmissionFactor);
|
|
384
|
+
} else {
|
|
385
|
+
data.transmissionFactor = scope.zTransmissionFactor;
|
|
386
|
+
}
|
|
387
|
+
if (this.thicknessTexture) {
|
|
388
|
+
data.thicknessFactor = pb.mul(this.sampleThicknessTexture(scope).g, scope.zThicknessFactor);
|
|
389
|
+
} else {
|
|
390
|
+
data.thicknessFactor = scope.zThicknessFactor;
|
|
391
|
+
}
|
|
392
|
+
data.attenuationColor = scope.zAttenuationColor;
|
|
393
|
+
data.attenuationDistance = scope.zAttenuationDistance;
|
|
394
|
+
}
|
|
395
|
+
if (this.iridescence) {
|
|
396
|
+
data.iridescenceFactor = scope.zIridescenceFactor;
|
|
397
|
+
if (this.iridescenceTexture) {
|
|
398
|
+
data.iridescenceFactor.x = pb.mul(this.sampleIridescenceTexture(scope).r, data.iridescenceFactor.x);
|
|
399
|
+
}
|
|
400
|
+
if (this.iridescenceThicknessTexture) {
|
|
401
|
+
data.iridescenceFactor.w = pb.mix(data.iridescenceFactor.z, data.iridescenceFactor.w, this.sampleIridescenceThicknessTexture(scope).g);
|
|
402
|
+
}
|
|
403
|
+
data.iridescenceFresnel = this.evalIridescence(scope, 1, data.iridescenceFactor.y, pb.clamp(pb.dot(normal, viewVec), 0, 1), data.iridescenceFactor.w, data.f0.rgb);
|
|
404
|
+
data.iridescenceF0 = this.schlickToF0(scope, data.iridescenceFresnel, pb.vec3(1), pb.clamp(pb.dot(normal, viewVec), 0, 1));
|
|
405
|
+
}
|
|
245
406
|
}
|
|
246
407
|
calculateEmissiveColor(scope) {
|
|
247
408
|
const pb = scope.$builder;
|
|
@@ -277,6 +438,107 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
277
438
|
});
|
|
278
439
|
return scope.$g[funcNameVAshikhmin](NdotL, NdotV);
|
|
279
440
|
}
|
|
441
|
+
getVolumeTransmissionRay(scope, normal, viewVec, thickness, ior) {
|
|
442
|
+
const pb = scope.$builder;
|
|
443
|
+
const funcName = 'getVolumeTransmissionRay';
|
|
444
|
+
pb.func(funcName, [
|
|
445
|
+
pb.vec3('normal'),
|
|
446
|
+
pb.vec3('viewVec'),
|
|
447
|
+
pb.float('thickness'),
|
|
448
|
+
pb.float('ior')
|
|
449
|
+
], function() {
|
|
450
|
+
this.$l.refractionVector = pb.refract(pb.neg(this.viewVec), this.normal, pb.div(1, this.ior));
|
|
451
|
+
this.$return(pb.mul(this.refractionVector, this.$inputs.modelScale, this.thickness));
|
|
452
|
+
});
|
|
453
|
+
return pb.getGlobalScope()[funcName](normal, viewVec, thickness, ior);
|
|
454
|
+
}
|
|
455
|
+
getTransmissionSample(scope, fragCoord, roughness, ior) {
|
|
456
|
+
const pb = scope.$builder;
|
|
457
|
+
const funcName = 'getTransmissionSample';
|
|
458
|
+
pb.func(funcName, [
|
|
459
|
+
pb.vec2('fragCoord'),
|
|
460
|
+
pb.float('roughness'),
|
|
461
|
+
pb.float('ior')
|
|
462
|
+
], function() {
|
|
463
|
+
this.$l.applyIorToRoughness = pb.mul(this.roughness, pb.clamp(pb.sub(pb.mul(this.ior, 2), 2), 0.0, 1.0));
|
|
464
|
+
this.$l.framebufferLod = pb.mul(pb.log2(this.zSceneColorTexSize.x), this.applyIorToRoughness);
|
|
465
|
+
this.$return(pb.textureSampleLevel(this.zSceneColorTex, this.fragCoord, this.framebufferLod).rgb);
|
|
466
|
+
});
|
|
467
|
+
return pb.getGlobalScope()[funcName](fragCoord, roughness, ior);
|
|
468
|
+
}
|
|
469
|
+
getPunctualRadianceTransmission(scope, normal, viewVec, lightDir, alphaRoughness, f0, f90, baseColor, ior) {
|
|
470
|
+
const pb = scope.$builder;
|
|
471
|
+
const that = this;
|
|
472
|
+
const funcName = 'getPunctualRadianceTransmission';
|
|
473
|
+
pb.func(funcName, [
|
|
474
|
+
pb.vec3('normal'),
|
|
475
|
+
pb.vec3('viewVec'),
|
|
476
|
+
pb.vec3('L'),
|
|
477
|
+
pb.float('alphaRoughness'),
|
|
478
|
+
pb.vec3('f0'),
|
|
479
|
+
pb.vec3('f90'),
|
|
480
|
+
pb.vec3('baseColor'),
|
|
481
|
+
pb.float('ior')
|
|
482
|
+
], function() {
|
|
483
|
+
this.$l.transmissionRoughness = pb.mul(this.alphaRoughness, pb.clamp(pb.sub(pb.mul(this.ior, 2), 2), 0.0, 1.0));
|
|
484
|
+
this.$l.mirrorL = pb.normalize(pb.add(this.L, pb.mul(this.normal, pb.dot(pb.neg(this.L), this.normal), 2)));
|
|
485
|
+
this.$l.h = pb.normalize(pb.add(this.viewVec, this.mirrorL));
|
|
486
|
+
this.$l.D = that.distributionGGX(this, pb.clamp(pb.dot(this.normal, this.h), 0, 1), this.transmissionRoughness);
|
|
487
|
+
this.$l.F = that.fresnelSchlick(this, pb.clamp(pb.dot(this.viewVec, this.h), 0, 1), this.f0, this.f90);
|
|
488
|
+
this.$l.V = that.visGGX(this, pb.clamp(pb.dot(this.normal, this.viewVec), 0, 1), pb.clamp(pb.dot(this.normal, this.mirrorL), 0, 1), this.transmissionRoughness);
|
|
489
|
+
this.$return(pb.mul(pb.sub(pb.vec3(1), this.F), this.baseColor, this.D, this.V));
|
|
490
|
+
});
|
|
491
|
+
return pb.getGlobalScope()[funcName](normal, viewVec, lightDir, alphaRoughness, f0, f90, baseColor, ior);
|
|
492
|
+
}
|
|
493
|
+
applyVolumeAttenuation(scope, radiance, transmissionDistance, attenuationColor, attenuationDistance) {
|
|
494
|
+
const pb = scope.$builder;
|
|
495
|
+
const funcName = 'applyVolumeAttenuation';
|
|
496
|
+
pb.func(funcName, [
|
|
497
|
+
pb.vec3('radiance'),
|
|
498
|
+
pb.float('transmissionDistance'),
|
|
499
|
+
pb.vec3('attenuationColor'),
|
|
500
|
+
pb.float('attenuationDistance')
|
|
501
|
+
], function() {
|
|
502
|
+
this.$if(pb.equal(this.attenuationDistance, 0), function() {
|
|
503
|
+
this.$return(this.radiance);
|
|
504
|
+
}).$else(function() {
|
|
505
|
+
this.$l.attenuationCoefficient = pb.div(pb.neg(pb.log(this.attenuationColor)), this.attenuationDistance);
|
|
506
|
+
this.$l.transmittance = pb.exp(pb.mul(pb.neg(this.attenuationCoefficient), this.transmissionDistance));
|
|
507
|
+
this.$return(pb.mul(this.radiance, this.transmittance));
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
return pb.getGlobalScope()[funcName](radiance, transmissionDistance, attenuationColor, attenuationDistance);
|
|
511
|
+
}
|
|
512
|
+
getIBLVolumnRefraction(scope, brdf, normal, viewVec, roughness, baseColor, f0, f90, position, ior, thickness, attenuationColor, attenuationDistance) {
|
|
513
|
+
const pb = scope.$builder;
|
|
514
|
+
const funcName = 'getIBLVolumeRefraction';
|
|
515
|
+
const that = this;
|
|
516
|
+
pb.func(funcName, [
|
|
517
|
+
pb.vec2('brdf'),
|
|
518
|
+
pb.vec3('normal'),
|
|
519
|
+
pb.vec3('viewVec'),
|
|
520
|
+
pb.float('roughness'),
|
|
521
|
+
pb.vec3('baseColor'),
|
|
522
|
+
pb.vec3('f0'),
|
|
523
|
+
pb.vec3('f90'),
|
|
524
|
+
pb.vec3('position'),
|
|
525
|
+
pb.float('ior'),
|
|
526
|
+
pb.float('thickness'),
|
|
527
|
+
pb.vec3('attenuationColor'),
|
|
528
|
+
pb.float('attenuationDistance')
|
|
529
|
+
], function() {
|
|
530
|
+
this.$l.transmissionRay = that.getVolumeTransmissionRay(this, this.normal, this.viewVec, this.thickness, this.ior);
|
|
531
|
+
this.$l.transmissionRayLength = pb.length(this.transmissionRay);
|
|
532
|
+
this.$l.refractedRayExit = pb.add(this.position, this.transmissionRay);
|
|
533
|
+
this.$l.ndcPos = pb.mul(ShaderHelper.getViewProjectionMatrix(this), pb.vec4(this.refractedRayExit, 1));
|
|
534
|
+
this.$l.refractionCoords = pb.add(pb.mul(pb.div(this.ndcPos.xy, this.ndcPos.w), 0.5), pb.vec2(0.5));
|
|
535
|
+
this.$l.transmittedLight = that.getTransmissionSample(this, this.refractionCoords, this.roughness, this.ior);
|
|
536
|
+
this.$l.attColor = that.applyVolumeAttenuation(this, this.transmittedLight, this.transmissionRayLength, this.attenuationColor, this.attenuationDistance);
|
|
537
|
+
this.$l.specularColor = pb.add(pb.mul(this.f0, this.brdf.x), pb.mul(this.f90, this.brdf.y));
|
|
538
|
+
this.$return(pb.mul(pb.sub(pb.vec3(1), this.specularColor), this.attColor, this.baseColor));
|
|
539
|
+
});
|
|
540
|
+
return pb.getGlobalScope()[funcName](brdf, normal, viewVec, roughness, baseColor, f0, f90, position, ior, thickness, attenuationColor, attenuationDistance);
|
|
541
|
+
}
|
|
280
542
|
directLighting(scope, lightDir, lightColor, normal, viewVec, commonData, outColor) {
|
|
281
543
|
const pb = scope.$builder;
|
|
282
544
|
const that = this;
|
|
@@ -295,7 +557,12 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
295
557
|
this.$l.NoV = pb.clamp(pb.dot(this.normal, this.viewVec), 0, 1);
|
|
296
558
|
this.$if(pb.greaterThan(this.NoL, 0), function() {
|
|
297
559
|
this.$l.VoH = pb.clamp(pb.dot(this.viewVec, this.H), 0, 1);
|
|
298
|
-
this.$l.
|
|
560
|
+
this.$l.schlickFresnel = that.fresnelSchlick(this, this.VoH, this.data.f0.rgb, this.data.f90);
|
|
561
|
+
if (that.iridescence) {
|
|
562
|
+
this.$l.F = pb.mix(this.schlickFresnel, this.data.iridescenceFresnel, this.data.iridescenceFactor.x);
|
|
563
|
+
} else {
|
|
564
|
+
this.$l.F = this.schlickFresnel;
|
|
565
|
+
}
|
|
299
566
|
this.$l.alphaRoughness = pb.mul(this.data.roughness, this.data.roughness);
|
|
300
567
|
this.$l.D = that.distributionGGX(this, this.NoH, this.alphaRoughness);
|
|
301
568
|
this.$l.V = that.visGGX(this, this.NoV, this.NoL, this.alphaRoughness);
|
|
@@ -304,7 +571,19 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
304
571
|
this.specular = pb.mul(this.specular, this.data.sheenAlbedoScaling);
|
|
305
572
|
}
|
|
306
573
|
this.outColor = pb.add(this.outColor, this.specular);
|
|
307
|
-
|
|
574
|
+
if (that.iridescence) {
|
|
575
|
+
this.$l.iridescenceFresnelMax = pb.vec3(pb.max(pb.max(this.data.iridescenceFresnel.r, this.data.iridescenceFresnel.g), this.data.iridescenceFresnel.b));
|
|
576
|
+
this.F = pb.mix(this.schlickFresnel, this.iridescenceFresnelMax, this.data.iridescenceFactor.x);
|
|
577
|
+
}
|
|
578
|
+
this.$l.diffuseBRDF = pb.mul(pb.sub(pb.vec3(1), pb.mul(this.F, this.data.specularWeight)), pb.div(this.data.diffuse.rgb, Math.PI));
|
|
579
|
+
this.$l.diffuse = pb.mul(this.lightColor, pb.max(this.diffuseBRDF, pb.vec3(0)));
|
|
580
|
+
if (that.transmission) {
|
|
581
|
+
this.$l.transmissionRay = that.getVolumeTransmissionRay(this, this.normal, this.viewVec, this.data.thicknessFactor, this.data.f0.a);
|
|
582
|
+
this.$l.pointToLight = pb.normalize(pb.sub(this.L, this.transmissionRay));
|
|
583
|
+
this.$l.transmittedLight = pb.mul(this.lightColor, that.getPunctualRadianceTransmission(this, this.normal, this.viewVec, this.pointToLight, this.alphaRoughness, this.data.f0.rgb, this.data.f90.rgb, this.data.diffuse.rgb, this.data.f0.a));
|
|
584
|
+
this.transmittedLight = that.applyVolumeAttenuation(this, this.transmittedLight, pb.length(this.transmissionRay), this.data.attenuationColor, this.data.attenuationDistance);
|
|
585
|
+
this.diffuse = pb.mix(this.diffuse, this.transmittedLight, this.data.transmissionFactor);
|
|
586
|
+
}
|
|
308
587
|
if (that.sheen) {
|
|
309
588
|
this.diffuse = pb.mul(this.diffuse, this.data.sheenAlbedoScaling);
|
|
310
589
|
}
|
|
@@ -328,6 +607,132 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
328
607
|
});
|
|
329
608
|
scope.$g[funcName](lightDir, lightColor, normal, viewVec, commonData, outColor);
|
|
330
609
|
}
|
|
610
|
+
fresnel0ToIor(scope, fresnel0) {
|
|
611
|
+
const pb = scope.$builder;
|
|
612
|
+
const funcName = 'Z_fresnel0ToIor';
|
|
613
|
+
pb.func(funcName, [
|
|
614
|
+
pb.vec3('fresnel0')
|
|
615
|
+
], function() {
|
|
616
|
+
this.$l.sqrtF0 = pb.sqrt(this.fresnel0);
|
|
617
|
+
this.$return(pb.div(pb.add(this.sqrtF0, pb.vec3(1)), pb.sub(pb.vec3(1), this.sqrtF0)));
|
|
618
|
+
});
|
|
619
|
+
return pb.getGlobalScope()[funcName](fresnel0);
|
|
620
|
+
}
|
|
621
|
+
iorToFresnel0v(scope, transmittedIor, incidentIor) {
|
|
622
|
+
const pb = scope.$builder;
|
|
623
|
+
const funcName = 'Z_iorToFresnel0v';
|
|
624
|
+
pb.func(funcName, [
|
|
625
|
+
pb.vec3('transmittedIor'),
|
|
626
|
+
pb.float('incidentIor')
|
|
627
|
+
], function() {
|
|
628
|
+
this.$l.t = pb.div(pb.sub(this.transmittedIor, pb.vec3(this.incidentIor)), pb.add(this.transmittedIor, pb.vec3(this.incidentIor)));
|
|
629
|
+
this.$return(pb.mul(this.t, this.t));
|
|
630
|
+
});
|
|
631
|
+
return pb.getGlobalScope()[funcName](transmittedIor, incidentIor);
|
|
632
|
+
}
|
|
633
|
+
iorToFresnel0(scope, transmittedIor, incidentIor) {
|
|
634
|
+
const pb = scope.$builder;
|
|
635
|
+
const funcName = 'Z_iorToFresnel0';
|
|
636
|
+
pb.func(funcName, [
|
|
637
|
+
pb.float('transmittedIor'),
|
|
638
|
+
pb.float('incidentIor')
|
|
639
|
+
], function() {
|
|
640
|
+
this.$l.t = pb.div(pb.sub(this.transmittedIor, this.incidentIor), pb.add(this.transmittedIor, this.incidentIor));
|
|
641
|
+
this.$return(pb.mul(this.t, this.t));
|
|
642
|
+
});
|
|
643
|
+
return pb.getGlobalScope()[funcName](transmittedIor, incidentIor);
|
|
644
|
+
}
|
|
645
|
+
evalSensitivity(scope, OPD, shift) {
|
|
646
|
+
const pb = scope.$builder;
|
|
647
|
+
const funcName = 'Z_evalSensitivity';
|
|
648
|
+
pb.func(funcName, [
|
|
649
|
+
pb.float('OPD'),
|
|
650
|
+
pb.vec3('shift')
|
|
651
|
+
], function() {
|
|
652
|
+
this.$l.phase = pb.mul(Math.PI * 2, this.OPD, 1e-9);
|
|
653
|
+
this.$l.val = pb.vec3(5.4856e-13, 4.4201e-13, 5.2481e-13);
|
|
654
|
+
this.$l.pos = pb.vec3(1.681e6, 1.7953e6, 2.2084e6);
|
|
655
|
+
this.$l.va = pb.vec3(4.3278e9, 9.3046e9, 6.6121e9);
|
|
656
|
+
this.$l.xyz = pb.mul(this.val, pb.sqrt(pb.mul(Math.PI * 2, this.va)), pb.cos(pb.add(pb.mul(this.pos, this.phase), this.shift)), pb.exp(pb.neg(pb.mul(this.phase, this.phase, this.va))));
|
|
657
|
+
this.xyz.x = pb.add(this.xyz.x, pb.mul(9.747e-14, Math.sqrt(Math.PI * 2 * 4.5282e9), pb.cos(pb.add(pb.mul(this.phase, 2.2399e6), this.shift.x)), pb.exp(pb.mul(-4.5282e9, this.phase, this.phase))));
|
|
658
|
+
this.xyz = pb.div(this.xyz, 1.0685e-7);
|
|
659
|
+
this.$return(pb.mul(pb.mat3(3.2404542, -0.969266, 0.0556434, -1.5371385, 1.8760108, -0.2040259, -0.4985314, 0.041556, 1.0572252), this.xyz));
|
|
660
|
+
});
|
|
661
|
+
return pb.getGlobalScope()[funcName](OPD, shift);
|
|
662
|
+
}
|
|
663
|
+
schlickToF0(scope, f, f90, VdotH) {
|
|
664
|
+
const pb = scope.$builder;
|
|
665
|
+
const funcName = 'Z_schlickToF0';
|
|
666
|
+
pb.func(funcName, [
|
|
667
|
+
pb.vec3('f'),
|
|
668
|
+
pb.vec3('f90'),
|
|
669
|
+
pb.float('VdotH')
|
|
670
|
+
], function() {
|
|
671
|
+
this.$l.x = pb.clamp(pb.sub(1, this.VdotH), 0, 1);
|
|
672
|
+
this.$l.x2 = pb.mul(this.x, this.x);
|
|
673
|
+
this.$l.x5 = pb.clamp(pb.mul(this.x, this.x2, this.x2), 0, 0.9999);
|
|
674
|
+
this.$return(pb.div(pb.sub(this.f, pb.mul(this.f90, this.x5)), pb.sub(1, this.x5)));
|
|
675
|
+
});
|
|
676
|
+
return pb.getGlobalScope()[funcName](f, f90, VdotH);
|
|
677
|
+
}
|
|
678
|
+
evalIridescence(scope, outsideIOR, eta2, cosTheta1, thinFilmThickness, baseF0) {
|
|
679
|
+
const pb = scope.$builder;
|
|
680
|
+
const that = this;
|
|
681
|
+
const funcName = 'Z_evalIridescence';
|
|
682
|
+
pb.func(funcName, [
|
|
683
|
+
pb.float('outsideIOR'),
|
|
684
|
+
pb.float('eta2'),
|
|
685
|
+
pb.float('cosTheta1'),
|
|
686
|
+
pb.float('thinFilmThickness'),
|
|
687
|
+
pb.vec3('baseF0')
|
|
688
|
+
], function() {
|
|
689
|
+
this.$l.iridescenceIor = pb.mix(this.outsideIOR, this.eta2, pb.smoothStep(0, 0.03, this.thinFilmThickness));
|
|
690
|
+
this.$l.t = pb.div(this.outsideIOR, this.iridescenceIor);
|
|
691
|
+
this.$l.sinTheta2Sq = pb.mul(this.t, this.t, pb.sub(1, pb.mul(this.cosTheta1, this.cosTheta1)));
|
|
692
|
+
this.$l.cosTheta2Sq = pb.sub(1, this.sinTheta2Sq);
|
|
693
|
+
this.$if(pb.lessThan(this.cosTheta2Sq, 0), function() {
|
|
694
|
+
this.$return(pb.vec3(1));
|
|
695
|
+
});
|
|
696
|
+
this.$l.cosTheta2 = pb.sqrt(this.cosTheta2Sq);
|
|
697
|
+
this.$l.R0 = that.iorToFresnel0(this, this.iridescenceIor, this.outsideIOR);
|
|
698
|
+
this.$l.R12 = that.fresnelSchlick(this, this.cosTheta1, pb.vec3(this.R0), pb.vec3(1)).x;
|
|
699
|
+
this.$l.R21 = this.R12;
|
|
700
|
+
this.$l.T121 = pb.sub(1, this.R12);
|
|
701
|
+
this.$l.phi12 = pb.float(0);
|
|
702
|
+
this.$if(pb.lessThan(this.iridescenceIor, this.outsideIOR), function() {
|
|
703
|
+
this.phi12 = Math.PI;
|
|
704
|
+
});
|
|
705
|
+
this.$l.phi21 = pb.sub(Math.PI, this.phi12);
|
|
706
|
+
this.$l.baseIOR = that.fresnel0ToIor(this, pb.clamp(this.baseF0, pb.vec3(0), pb.vec3(0.9999)));
|
|
707
|
+
this.$l.R1 = that.iorToFresnel0v(this, this.baseIOR, this.iridescenceIor);
|
|
708
|
+
this.$l.R23 = that.fresnelSchlick(this, this.cosTheta2, this.R1, pb.vec3(1));
|
|
709
|
+
this.$l.phi23 = pb.vec3(0);
|
|
710
|
+
this.$if(pb.lessThan(this.baseIOR.x, this.iridescenceIor), function() {
|
|
711
|
+
this.phi23.x = Math.PI;
|
|
712
|
+
});
|
|
713
|
+
this.$if(pb.lessThan(this.baseIOR.y, this.iridescenceIor), function() {
|
|
714
|
+
this.phi23.y = Math.PI;
|
|
715
|
+
});
|
|
716
|
+
this.$if(pb.lessThan(this.baseIOR.z, this.iridescenceIor), function() {
|
|
717
|
+
this.phi23.z = Math.PI;
|
|
718
|
+
});
|
|
719
|
+
this.$l.OPD = pb.mul(this.iridescenceIor, this.thinFilmThickness, this.cosTheta2, 2);
|
|
720
|
+
this.$l.phi = pb.add(pb.vec3(this.phi21), this.phi23);
|
|
721
|
+
this.$l.R123 = pb.clamp(pb.mul(this.R12, this.R23), pb.vec3(1e-5), pb.vec3(0.9999));
|
|
722
|
+
this.$l.r123 = pb.sqrt(this.R123);
|
|
723
|
+
this.$l.Rs = pb.div(pb.mul(this.T121, this.T121, this.R23), pb.sub(pb.vec3(1), this.R123));
|
|
724
|
+
this.$l.C0 = pb.add(pb.vec3(this.R12), this.Rs);
|
|
725
|
+
this.$l.I = this.C0;
|
|
726
|
+
this.$l.Cm = pb.sub(this.Rs, pb.vec3(this.T121));
|
|
727
|
+
this.$for(pb.int('m'), 1, 3, function() {
|
|
728
|
+
this.Cm = pb.mul(this.Cm, this.r123);
|
|
729
|
+
this.$l.Sm = pb.mul(that.evalSensitivity(this, pb.mul(this.OPD, pb.float(this.m)), pb.mul(this.phi, pb.float(this.m))), 2);
|
|
730
|
+
this.I = pb.add(this.I, pb.mul(this.Cm, this.Sm));
|
|
731
|
+
});
|
|
732
|
+
this.$return(pb.max(this.I, pb.vec3(0)));
|
|
733
|
+
});
|
|
734
|
+
return pb.getGlobalScope()[funcName](outsideIOR, eta2, cosTheta1, thinFilmThickness, baseF0);
|
|
735
|
+
}
|
|
331
736
|
indirectLighting(scope, normal, viewVec, commonData, outColor) {
|
|
332
737
|
const pb = scope.$builder;
|
|
333
738
|
const that = this;
|
|
@@ -353,7 +758,11 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
353
758
|
this.$l.ggxLutSample = pb.clamp(pb.textureSampleLevel(this.zGGXLut, pb.clamp(pb.vec2(this.NoV, this.data.roughness), pb.vec2(0), pb.vec2(1)), 0), pb.vec4(0), pb.vec4(1));
|
|
354
759
|
this.$l.f_ab = this.ggxLutSample.rg;
|
|
355
760
|
this.$l.Fr = pb.sub(pb.max(pb.vec3(pb.sub(1, this.data.roughness)), this.data.f0.rgb), this.data.f0.rgb);
|
|
356
|
-
|
|
761
|
+
if (that.iridescence) {
|
|
762
|
+
this.$l.k_S = pb.mix(pb.add(this.data.f0.rgb, pb.mul(this.Fr, pb.pow(pb.sub(1, this.NoV), 5))), this.data.iridescenceFresnel, this.data.iridescenceFactor.x);
|
|
763
|
+
} else {
|
|
764
|
+
this.$l.k_S = pb.add(this.data.f0.rgb, pb.mul(this.Fr, pb.pow(pb.sub(1, this.NoV), 5)));
|
|
765
|
+
}
|
|
357
766
|
if (ctx.env.light.envLight.hasRadiance()) {
|
|
358
767
|
this.$l.radiance = ctx.env.light.envLight.getRadiance(this, pb.reflect(pb.neg(this.viewVec), this.normal), this.data.roughness);
|
|
359
768
|
this.$l.FssEss = pb.add(pb.mul(this.k_S, this.f_ab.x), pb.vec3(this.f_ab.y));
|
|
@@ -365,15 +774,27 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
365
774
|
}
|
|
366
775
|
if (ctx.env.light.envLight.hasIrradiance()) {
|
|
367
776
|
this.$l.irradiance = ctx.env.light.envLight.getIrradiance(this, this.normal);
|
|
777
|
+
if (that.iridescence) {
|
|
778
|
+
this.$l.iridescenceF0Max = pb.vec3(pb.max(pb.max(this.data.iridescenceF0.r, this.data.iridescenceF0.g), this.data.iridescenceF0.b));
|
|
779
|
+
this.$l.mixedF0 = pb.mix(this.data.f0.rgb, this.iridescenceF0Max, this.data.iridescenceFactor.x);
|
|
780
|
+
this.Fr = pb.sub(pb.max(pb.vec3(pb.sub(1, this.data.roughness)), this.mixedF0), this.mixedF0);
|
|
781
|
+
this.k_S = pb.add(this.mixedF0, pb.mul(this.Fr, pb.pow(pb.sub(1, this.NoV), 5)));
|
|
782
|
+
} else {
|
|
783
|
+
this.$l.mixedF0 = this.data.f0.rgb;
|
|
784
|
+
}
|
|
368
785
|
this.$l.FssEss = pb.add(pb.mul(this.k_S, this.f_ab.x, this.data.specularWeight), pb.vec3(this.f_ab.y));
|
|
369
786
|
this.$l.Ems = pb.sub(1, pb.add(this.f_ab.x, this.f_ab.y));
|
|
370
|
-
this.$l.F_avg = pb.mul(pb.add(this.
|
|
787
|
+
this.$l.F_avg = pb.mul(pb.add(this.mixedF0, pb.div(pb.sub(pb.vec3(1), this.mixedF0), 21)), this.data.specularWeight);
|
|
371
788
|
this.$l.FmsEms = pb.div(pb.mul(this.FssEss, this.F_avg, this.Ems), pb.sub(pb.vec3(1), pb.mul(this.F_avg, this.Ems)));
|
|
372
789
|
this.$l.k_D = pb.mul(this.data.diffuse.rgb, pb.add(pb.sub(pb.vec3(1), this.FssEss), this.FmsEms));
|
|
373
790
|
this.$l.iblDiffuse = pb.mul(pb.add(this.FmsEms, this.k_D), this.irradiance, this.occlusion);
|
|
374
791
|
if (that.sheen) {
|
|
375
792
|
this.iblDiffuse = pb.mul(this.iblDiffuse, this.data.sheenAlbedoScaling);
|
|
376
793
|
}
|
|
794
|
+
if (that.transmission) {
|
|
795
|
+
this.$l.iblTransmission = that.getIBLVolumnRefraction(this, this.ggxLutSample.rg, this.normal, this.viewVec, this.data.roughness, this.data.diffuse.rgb, this.data.f0.rgb, this.data.f90, this.$inputs.worldPos, this.data.f0.a, this.data.thicknessFactor, this.data.attenuationColor, this.data.attenuationDistance);
|
|
796
|
+
this.iblDiffuse = pb.mix(this.iblDiffuse, this.iblTransmission, this.data.transmissionFactor);
|
|
797
|
+
}
|
|
377
798
|
this.outColor = pb.add(this.outColor, this.iblDiffuse);
|
|
378
799
|
}
|
|
379
800
|
if (that.sheen && ctx.env.light.envLight.hasIrradiance()) {
|
|
@@ -446,6 +867,8 @@ import { ShaderHelper } from '../../shader/helper.js';
|
|
|
446
867
|
};
|
|
447
868
|
FEATURE_SHEEN = cls.defineFeature();
|
|
448
869
|
FEATURE_CLEARCOAT = cls.defineFeature();
|
|
870
|
+
FEATURE_TRANSMISSION = cls.defineFeature();
|
|
871
|
+
FEATURE_IRIDESCENCE = cls.defineFeature();
|
|
449
872
|
return cls;
|
|
450
873
|
}
|
|
451
874
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/material/pbrmr.js
CHANGED
|
@@ -2,6 +2,7 @@ import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
|
|
|
2
2
|
import { mixinVertexColor } from './mixins/vertexcolor.js';
|
|
3
3
|
import { mixinPBRMetallicRoughness } from './mixins/lightmodel/pbrmetallicroughness.js';
|
|
4
4
|
import { ShaderHelper } from './shader/helper.js';
|
|
5
|
+
import { RENDER_PASS_TYPE_LIGHT } from '../values.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* PBRMetallicRoughnessMaterial class
|
|
@@ -30,9 +31,15 @@ import { ShaderHelper } from './shader/helper.js';
|
|
|
30
31
|
vertexShader(scope) {
|
|
31
32
|
super.vertexShader(scope);
|
|
32
33
|
const pb = scope.$builder;
|
|
34
|
+
const worldMatrix = ShaderHelper.getWorldMatrix(scope);
|
|
33
35
|
scope.$l.oPos = ShaderHelper.resolveVertexPosition(scope);
|
|
34
|
-
scope.$outputs.worldPos = pb.mul(
|
|
35
|
-
|
|
36
|
+
scope.$outputs.worldPos = pb.mul(worldMatrix, pb.vec4(scope.oPos, 1)).xyz;
|
|
37
|
+
scope.$l.csPos = pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.worldPos, 1));
|
|
38
|
+
ShaderHelper.setClipSpacePosition(scope, scope.csPos);
|
|
39
|
+
if (this.transmission) {
|
|
40
|
+
scope.$outputs.screenUV = pb.add(pb.mul(pb.div(scope.csPos.xy, scope.csPos.w), 0.5), pb.vec2(0.5));
|
|
41
|
+
scope.$outputs.modelScale = pb.vec3(pb.length(worldMatrix[0].xyz), pb.length(worldMatrix[1].xyz), pb.length(worldMatrix[2].xyz));
|
|
42
|
+
}
|
|
36
43
|
if (this.vertexNormal) {
|
|
37
44
|
scope.$l.oNorm = ShaderHelper.resolveVertexNormal(scope);
|
|
38
45
|
scope.$outputs.wNorm = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oNorm, 0)).xyz;
|
|
@@ -51,10 +58,14 @@ import { ShaderHelper } from './shader/helper.js';
|
|
|
51
58
|
if (this.vertexColor) {
|
|
52
59
|
scope.albedo = pb.mul(scope.albedo, this.getVertexColor(scope));
|
|
53
60
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
if (this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
|
|
62
|
+
scope.$l.normalInfo = this.calculateNormalAndTBN(scope, scope.$inputs.worldPos, scope.$inputs.wNorm, scope.$inputs.wTangent, scope.$inputs.wBinormal);
|
|
63
|
+
scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);
|
|
64
|
+
scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN);
|
|
65
|
+
this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a));
|
|
66
|
+
} else {
|
|
67
|
+
this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.albedo);
|
|
68
|
+
}
|
|
58
69
|
} else {
|
|
59
70
|
this.outputFragmentColor(scope, scope.$inputs.worldPos, null);
|
|
60
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbrmr.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pbrmr.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|