@zephyr3d/scene 0.1.2 → 0.3.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/asset/assetmanager.js +83 -34
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/builtin.js +2 -2
- package/dist/asset/loaders/gltf/gltf_loader.js +105 -59
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
- package/dist/asset/loaders/hdr/hdr.js +1 -1
- package/dist/blitter/blitter.js +0 -1
- package/dist/blitter/blitter.js.map +1 -1
- package/dist/blitter/depthlimitedgaussion.js +0 -1
- package/dist/blitter/depthlimitedgaussion.js.map +1 -1
- package/dist/blitter/gaussianblur.js +0 -1
- package/dist/blitter/gaussianblur.js.map +1 -1
- package/dist/camera/camera.js +11 -8
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/orbit.js +24 -7
- package/dist/camera/orbit.js.map +1 -1
- package/dist/index.d.ts +3220 -3680
- package/dist/index.js +23 -11
- package/dist/index.js.map +1 -1
- package/dist/material/blinn.js +47 -57
- package/dist/material/blinn.js.map +1 -1
- package/dist/material/grassmat.js +127 -0
- package/dist/material/grassmat.js.map +1 -0
- package/dist/material/grassmaterial.js +58 -186
- package/dist/material/grassmaterial.js.map +1 -1
- package/dist/material/lambert.js +48 -22
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/lightmodel.js +4 -4
- package/dist/material/material.js +124 -105
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +321 -145
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +32 -99
- package/dist/material/mixins/albedocolor.js.map +1 -1
- package/dist/material/mixins/foliage.js +47 -0
- package/dist/material/mixins/foliage.js.map +1 -0
- package/dist/material/mixins/ggxlut.js +213 -0
- package/dist/material/mixins/ggxlut.js.map +1 -0
- package/dist/material/mixins/lightmodel/blinnphong.js +89 -0
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -0
- package/dist/material/mixins/lightmodel/lambert.js +58 -0
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -0
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +132 -0
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -0
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +105 -0
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -0
- package/dist/material/mixins/lit.js +464 -0
- package/dist/material/mixins/lit.js.map +1 -0
- package/dist/material/mixins/pbr/common.js +451 -0
- package/dist/material/mixins/pbr/common.js.map +1 -0
- package/dist/material/mixins/pbr/metallicroughness.js +126 -0
- package/dist/material/mixins/pbr/metallicroughness.js.map +1 -0
- package/dist/material/mixins/pbr/specularglossness.js +104 -0
- package/dist/material/mixins/pbr/specularglossness.js.map +1 -0
- package/dist/material/mixins/texture.js +157 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +16 -11
- package/dist/material/mixins/vertexcolor.js.map +1 -1
- package/dist/material/pbrmr.js +65 -0
- package/dist/material/pbrmr.js.map +1 -0
- package/dist/material/pbrsg.js +64 -0
- package/dist/material/pbrsg.js.map +1 -0
- package/dist/material/shader/helper.js +905 -0
- package/dist/material/shader/helper.js.map +1 -0
- package/dist/material/terrainmat.js +357 -0
- package/dist/material/terrainmat.js.map +1 -0
- package/dist/material/terrainmaterial.js +302 -94
- package/dist/material/terrainmaterial.js.map +1 -1
- package/dist/material/unlit.js +12 -9
- package/dist/material/unlit.js.map +1 -1
- package/dist/posteffect/bloom.js +9 -6
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +15 -6
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/posteffect.js +1 -1
- package/dist/posteffect/sao.js +8 -5
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/tonemap.js +2 -2
- package/dist/posteffect/water.js +11 -8
- package/dist/posteffect/water.js.map +1 -1
- package/dist/render/cluster_light.js +6 -5
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/cull_visitor.js +24 -3
- package/dist/render/cull_visitor.js.map +1 -1
- package/dist/render/depthpass.js +46 -0
- package/dist/render/depthpass.js.map +1 -0
- package/dist/render/envlight.js +26 -24
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/fullscreenquad.js +38 -0
- package/dist/render/fullscreenquad.js.map +1 -0
- package/dist/render/lightpass.js +98 -0
- package/dist/render/lightpass.js.map +1 -0
- package/dist/render/primitive.js +31 -0
- package/dist/render/primitive.js.map +1 -1
- package/dist/render/render_queue.js +113 -39
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +200 -0
- package/dist/render/renderer.js.map +1 -0
- package/dist/render/renderpass.js +10 -8
- package/dist/render/renderpass.js.map +1 -1
- package/dist/render/shadowmap_pass.js +3 -4
- package/dist/render/shadowmap_pass.js.map +1 -1
- package/dist/render/sky.js +33 -19
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/batchgroup.js +126 -0
- package/dist/scene/batchgroup.js.map +1 -0
- package/dist/scene/environment.js +9 -6
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +11 -0
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +48 -14
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/octree.js +37 -72
- package/dist/scene/octree.js.map +1 -1
- package/dist/scene/octree_update_visitor.js +5 -1
- package/dist/scene/octree_update_visitor.js.map +1 -1
- package/dist/scene/scene.js +17 -31
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +59 -52
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/terrain/grass.js +4 -14
- package/dist/scene/terrain/grass.js.map +1 -1
- package/dist/scene/terrain/patch.js +3 -3
- package/dist/scene/terrain/terrain.js +4 -9
- package/dist/scene/terrain/terrain.js.map +1 -1
- package/dist/scene/xform.js +61 -36
- package/dist/scene/xform.js.map +1 -1
- package/dist/shaders/framework.js +17 -3
- package/dist/shaders/framework.js.map +1 -1
- package/dist/shaders/misc.js +13 -161
- package/dist/shaders/misc.js.map +1 -1
- package/dist/shaders/noise.js +7 -7
- package/dist/shaders/pbr.js +1 -82
- package/dist/shaders/pbr.js.map +1 -1
- package/dist/shaders/shadow.js +33 -31
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shaders/water.js +3 -9
- package/dist/shaders/water.js.map +1 -1
- package/dist/shadow/esm.js +12 -9
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +15 -15
- package/dist/shadow/pcf_pd.js +15 -15
- package/dist/shadow/shadowmapper.js +35 -21
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +21 -55
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +16 -13
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/shapes/box.js +15 -6
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/cylinder.js +1 -4
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/shape.js +5 -0
- package/dist/shapes/shape.js.map +1 -1
- package/dist/shapes/sphere.js +3 -0
- package/dist/shapes/sphere.js.map +1 -1
- package/dist/shapes/torus.js +2 -2
- package/dist/utility/bounding_volume.js +27 -27
- package/dist/utility/pmrem.js +4 -4
- package/dist/utility/sheenlut.js +196 -0
- package/dist/utility/sheenlut.js.map +1 -0
- package/dist/utility/shprojection.js +0 -1
- package/dist/utility/shprojection.js.map +1 -1
- package/dist/values.js +11 -8
- package/dist/values.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,126 +1,59 @@
|
|
|
1
1
|
import { Vector4 } from '@zephyr3d/base';
|
|
2
|
+
import { applyMaterialMixins } from '../meshmaterial.js';
|
|
3
|
+
import { mixinTextureProps } from './texture.js';
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Albedo color mixin
|
|
7
|
+
* @param BaseCls - Class to mix in
|
|
8
|
+
* @returns Mixed class
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/ function mixinAlbedoColor(BaseCls) {
|
|
4
12
|
if (BaseCls.albedoColorMixed) {
|
|
5
13
|
return BaseCls;
|
|
6
14
|
}
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
return class extends BaseCls {
|
|
15
|
+
const S = applyMaterialMixins(BaseCls, mixinTextureProps('albedo'));
|
|
16
|
+
const ALBEDO_COLOR_UNIFORM = S.defineInstanceUniform('albedoColor', 'vec4');
|
|
17
|
+
return class extends S {
|
|
11
18
|
static albedoColorMixed = true;
|
|
12
19
|
_albedoColor;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_albedoTexCoordIndex;
|
|
16
|
-
_albedoTexCoordMatrix;
|
|
17
|
-
constructor(...args){
|
|
18
|
-
super(...args);
|
|
20
|
+
constructor(){
|
|
21
|
+
super();
|
|
19
22
|
this._albedoColor = Vector4.one();
|
|
20
|
-
this._albedoTexture = null;
|
|
21
|
-
this._albedoSampler = null;
|
|
22
|
-
this._albedoTexCoordIndex = 0;
|
|
23
|
-
this._albedoTexCoordMatrix = null;
|
|
24
23
|
}
|
|
25
24
|
/** Albedo color */ get albedoColor() {
|
|
26
25
|
return this._albedoColor;
|
|
27
26
|
}
|
|
28
27
|
set albedoColor(val) {
|
|
29
28
|
this._albedoColor.set(val);
|
|
30
|
-
this.
|
|
29
|
+
this.uniformChanged();
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
return this.
|
|
31
|
+
getUniformValueAlbedoColor(scope) {
|
|
32
|
+
return this.drawContext.instanceData ? this.getInstancedUniform(scope, ALBEDO_COLOR_UNIFORM) : scope.zAlbedo;
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
if (val !== this._albedoTexCoordIndex) {
|
|
37
|
-
this._albedoTexCoordIndex = val;
|
|
38
|
-
if (this._albedoTexture) {
|
|
39
|
-
this.useFeature(FEATURE_ALBEDO_TEXCOORD_INDEX, this._albedoTexCoordIndex);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/** Albedo texture */ get albedoTexture() {
|
|
44
|
-
return this._albedoTexture;
|
|
45
|
-
}
|
|
46
|
-
set albedoTexture(tex) {
|
|
47
|
-
if (this._albedoTexture !== tex) {
|
|
48
|
-
this.useFeature(FEATURE_ALBEDO_MAP, !!tex);
|
|
49
|
-
if (tex) {
|
|
50
|
-
this.useFeature(FEATURE_ALBEDO_TEXCOORD_INDEX, this._albedoTexCoordIndex);
|
|
51
|
-
this.useFeature(FEATURE_ALBEDO_TEXCOORD_MATRIX, !!this._albedoTexCoordMatrix);
|
|
52
|
-
}
|
|
53
|
-
this._albedoTexture = tex ?? null;
|
|
54
|
-
this.optionChanged(false);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/** Albedo texture sampler */ get albedoTextureSampler() {
|
|
58
|
-
return this._albedoSampler;
|
|
59
|
-
}
|
|
60
|
-
set albedoTextureSampler(sampler) {
|
|
61
|
-
this._albedoSampler = sampler ?? null;
|
|
62
|
-
}
|
|
63
|
-
/** Albedo texture coordinate transform matrix */ get albedoTexMatrix() {
|
|
64
|
-
return this._albedoTexCoordMatrix;
|
|
65
|
-
}
|
|
66
|
-
set albedoTexMatrix(val) {
|
|
67
|
-
if (val !== this._albedoTexCoordMatrix) {
|
|
68
|
-
this._albedoTexCoordMatrix = val;
|
|
69
|
-
if (this._albedoTexture) {
|
|
70
|
-
this.useFeature(FEATURE_ALBEDO_TEXCOORD_MATRIX, !!this._albedoTexCoordMatrix);
|
|
71
|
-
}
|
|
72
|
-
this.optionChanged(false);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
calculateAlbedoColor(scope, ctx) {
|
|
76
|
-
if (!this.needFragmentColor(ctx)) {
|
|
77
|
-
throw new Error('mixinAlbedoColor.calculateAlbedoColor(): No need to calculate albedo color, make sure needFragmentColor() returns true');
|
|
78
|
-
}
|
|
34
|
+
calculateAlbedoColor(scope, uv) {
|
|
79
35
|
const pb = scope.$builder;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
36
|
+
if (!this.needFragmentColor()) {
|
|
37
|
+
console.warn('mixinAlbedoColor.calculateAlbedoColor(): No need to calculate albedo color, make sure needFragmentColor() returns true');
|
|
38
|
+
return pb.vec4(1);
|
|
83
39
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
super.vertexShader(scope, ctx);
|
|
88
|
-
if (this.needFragmentColor(ctx)) {
|
|
89
|
-
const pb = scope.$builder;
|
|
90
|
-
if (this.featureUsed(FEATURE_ALBEDO_MAP, ctx.renderPass.type)) {
|
|
91
|
-
const semantic = `texCoord${this.albedoTexCoordIndex}`;
|
|
92
|
-
if (!scope.$getVertexAttrib(semantic)) {
|
|
93
|
-
scope.$inputs[semantic] = pb.vec2().attrib(semantic);
|
|
94
|
-
}
|
|
95
|
-
if (this.featureUsed(FEATURE_ALBEDO_TEXCOORD_MATRIX, ctx.renderPass.type)) {
|
|
96
|
-
scope.$g.kkAlbedoTextureMatrix = pb.mat4().uniform(2);
|
|
97
|
-
scope.$outputs.kkAlbedoTexCoord = pb.mul(scope.kkAlbedoTextureMatrix, pb.vec4(scope.$inputs[semantic], 0, 1)).xy;
|
|
98
|
-
} else {
|
|
99
|
-
scope.$outputs.kkAlbedoTexCoord = scope.$inputs[semantic];
|
|
100
|
-
}
|
|
101
|
-
}
|
|
40
|
+
let color = this.getUniformValueAlbedoColor(scope);
|
|
41
|
+
if (this.albedoTexture) {
|
|
42
|
+
color = pb.mul(color, this.sampleAlbedoTexture(scope, uv));
|
|
102
43
|
}
|
|
44
|
+
return color;
|
|
103
45
|
}
|
|
104
|
-
fragmentShader(scope
|
|
105
|
-
super.fragmentShader(scope
|
|
106
|
-
if (this.needFragmentColor(
|
|
46
|
+
fragmentShader(scope) {
|
|
47
|
+
super.fragmentShader(scope);
|
|
48
|
+
if (this.needFragmentColor()) {
|
|
107
49
|
const pb = scope.$builder;
|
|
108
|
-
scope
|
|
109
|
-
if (this.featureUsed(FEATURE_ALBEDO_MAP, ctx.renderPass.type)) {
|
|
110
|
-
scope.$g.kkAlbedoTex = pb.tex2D().uniform(2);
|
|
111
|
-
}
|
|
50
|
+
scope.zAlbedo = pb.vec4().uniform(2);
|
|
112
51
|
}
|
|
113
52
|
}
|
|
114
|
-
applyUniformValues(bindGroup, ctx) {
|
|
115
|
-
super.applyUniformValues(bindGroup, ctx);
|
|
53
|
+
applyUniformValues(bindGroup, ctx, pass) {
|
|
54
|
+
super.applyUniformValues(bindGroup, ctx, pass);
|
|
116
55
|
if (this.needFragmentColor(ctx)) {
|
|
117
|
-
bindGroup.setValue('
|
|
118
|
-
if (this.featureUsed(FEATURE_ALBEDO_MAP, ctx.renderPass.type)) {
|
|
119
|
-
bindGroup.setTexture('kkAlbedoTex', this._albedoTexture, this._albedoSampler);
|
|
120
|
-
if (this.featureUsed(FEATURE_ALBEDO_TEXCOORD_MATRIX, ctx.renderPass.type)) {
|
|
121
|
-
bindGroup.setValue('kkAlbedoTextureMatrix', this._albedoTexCoordMatrix);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
56
|
+
bindGroup.setValue('zAlbedo', this._albedoColor);
|
|
124
57
|
}
|
|
125
58
|
}
|
|
126
59
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"albedocolor.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"albedocolor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Foliage mixin
|
|
3
|
+
*
|
|
4
|
+
* @param BaseCls - Class to mix in
|
|
5
|
+
* @returns Mixed class
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/ function mixinFoliage(BaseCls) {
|
|
9
|
+
if (BaseCls.foliageMixed) {
|
|
10
|
+
return BaseCls;
|
|
11
|
+
}
|
|
12
|
+
return class extends BaseCls {
|
|
13
|
+
static foliageMixed = true;
|
|
14
|
+
constructor(...args){
|
|
15
|
+
super(...args);
|
|
16
|
+
this.cullMode = 'none';
|
|
17
|
+
}
|
|
18
|
+
calculateFoliageAlbedo(scope, albedoColor, texelCoord) {
|
|
19
|
+
const pb = scope.$builder;
|
|
20
|
+
const that = this;
|
|
21
|
+
const funcNameCalcMipLevel = 'Z_CalcFoliageMipLevel';
|
|
22
|
+
pb.func(funcNameCalcMipLevel, [
|
|
23
|
+
pb.vec2('coord')
|
|
24
|
+
], function() {
|
|
25
|
+
this.$l.dx = pb.dpdx(this.coord);
|
|
26
|
+
this.$l.dy = pb.dpdy(this.coord);
|
|
27
|
+
this.$l.deltaMaxSqr = pb.max(pb.dot(this.dx, this.dx), pb.dot(this.dy, this.dy));
|
|
28
|
+
this.$return(pb.max(0, pb.mul(pb.log2(this.deltaMaxSqr), 0.5)));
|
|
29
|
+
});
|
|
30
|
+
const funcNameCalcFoliageAlbedo = 'Z_calcFoliageAlbedo';
|
|
31
|
+
pb.func(funcNameCalcFoliageAlbedo, [
|
|
32
|
+
pb.vec4('albedo'),
|
|
33
|
+
pb.vec2('coord')
|
|
34
|
+
], function() {
|
|
35
|
+
this.$l.a = pb.mul(this.albedo.a, pb.add(1, pb.mul(pb.max(0, scope[funcNameCalcMipLevel](this.coord)), 0.25)));
|
|
36
|
+
if (that.alphaToCoverage) {
|
|
37
|
+
this.a = pb.add(pb.div(pb.sub(this.a, 0.4), pb.max(pb.fwidth(this.albedo.a), 0.0001)), 0.5);
|
|
38
|
+
}
|
|
39
|
+
this.$return(pb.vec4(this.albedo.rgb, this.a));
|
|
40
|
+
});
|
|
41
|
+
return pb.getGlobalScope()[funcNameCalcFoliageAlbedo](albedoColor, texelCoord);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { mixinFoliage };
|
|
47
|
+
//# sourceMappingURL=foliage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"foliage.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { Application } from '../../app.js';
|
|
2
|
+
|
|
3
|
+
const ggxLut = new Map();
|
|
4
|
+
function getGGXLUT(size) {
|
|
5
|
+
let lut = ggxLut.get(size);
|
|
6
|
+
if (!lut) {
|
|
7
|
+
lut = createGGXLUT(size);
|
|
8
|
+
ggxLut.set(size, lut);
|
|
9
|
+
}
|
|
10
|
+
return lut;
|
|
11
|
+
}
|
|
12
|
+
function createGGXLUT(size) {
|
|
13
|
+
const device = Application.instance.device;
|
|
14
|
+
const program = device.buildRenderProgram({
|
|
15
|
+
vertex (pb) {
|
|
16
|
+
this.$inputs.pos = pb.vec2().attrib('position');
|
|
17
|
+
this.$outputs.uv = pb.vec2();
|
|
18
|
+
pb.main(function() {
|
|
19
|
+
this.$builtins.position = pb.vec4(this.$inputs.pos, 0, 1);
|
|
20
|
+
this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
|
|
21
|
+
if (device.type === 'webgpu') {
|
|
22
|
+
this.$builtins.position.y = pb.neg(this.$builtins.position.y);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
fragment (pb) {
|
|
27
|
+
this.$outputs.color = pb.vec4();
|
|
28
|
+
const SAMPLE_COUNT = 1024;
|
|
29
|
+
if (device.type === 'webgl') {
|
|
30
|
+
pb.func('radicalInverse_VdC', [
|
|
31
|
+
pb.int('bits')
|
|
32
|
+
], function() {
|
|
33
|
+
this.$l.rand = pb.float(0);
|
|
34
|
+
this.$l.denom = pb.float(1);
|
|
35
|
+
this.$l.invBase = pb.float(0.5);
|
|
36
|
+
this.$l.n = this.bits;
|
|
37
|
+
this.$for(pb.int('i'), 0, 32, function() {
|
|
38
|
+
this.denom = pb.mul(this.denom, 2);
|
|
39
|
+
this.rand = pb.add(this.rand, pb.div(pb.mod(pb.float(this.n), 2), this.denom));
|
|
40
|
+
this.n = pb.div(this.n, 2);
|
|
41
|
+
this.$if(pb.equal(this.n, 0), function() {
|
|
42
|
+
this.$break();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
this.$return(this.rand);
|
|
46
|
+
});
|
|
47
|
+
pb.func('hammersley2d', [
|
|
48
|
+
pb.int('i'),
|
|
49
|
+
pb.int('N')
|
|
50
|
+
], function() {
|
|
51
|
+
this.$return(pb.vec2(pb.div(pb.float(this.i), pb.float(this.N)), this.radicalInverse_VdC(this.i)));
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
pb.func('radicalInverse_VdC', [
|
|
55
|
+
pb.uint('bits')
|
|
56
|
+
], function() {
|
|
57
|
+
this.$l.n = this.bits;
|
|
58
|
+
this.n = pb.compOr(pb.sal(this.n, 16), pb.sar(this.n, 16));
|
|
59
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x55555555), 1), pb.sar(pb.compAnd(this.n, 0xaaaaaaaa), 1));
|
|
60
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x33333333), 2), pb.sar(pb.compAnd(this.n, 0xcccccccc), 2));
|
|
61
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x0f0f0f0f), 4), pb.sar(pb.compAnd(this.n, 0xf0f0f0f0), 4));
|
|
62
|
+
this.n = pb.compOr(pb.sal(pb.compAnd(this.n, 0x00ff00ff), 8), pb.sar(pb.compAnd(this.n, 0xff00ff00), 8));
|
|
63
|
+
this.$return(pb.mul(pb.float(this.n), 2.3283064365386963e-10));
|
|
64
|
+
});
|
|
65
|
+
pb.func('hammersley2d', [
|
|
66
|
+
pb.int('i'),
|
|
67
|
+
pb.int('N')
|
|
68
|
+
], function() {
|
|
69
|
+
this.$return(pb.vec2(pb.div(pb.float(this.i), pb.float(this.N)), this.radicalInverse_VdC(pb.uint(this.i))));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
pb.func('generateTBN', [
|
|
73
|
+
pb.vec3('normal')
|
|
74
|
+
], function() {
|
|
75
|
+
this.$l.bitangent = pb.vec3(0, 1, 0);
|
|
76
|
+
this.$l.NoU = this.normal.y;
|
|
77
|
+
this.$l.epsl = 0.0000001;
|
|
78
|
+
this.$if(pb.lessThanEqual(pb.sub(1, pb.abs(this.normal.y)), this.epsl), function() {
|
|
79
|
+
this.bitangent = this.$choice(pb.greaterThan(this.normal.y, 0), pb.vec3(0, 0, 1), pb.vec3(0, 0, -1));
|
|
80
|
+
});
|
|
81
|
+
this.$l.tangent = pb.normalize(pb.cross(this.bitangent, this.normal));
|
|
82
|
+
this.bitangent = pb.cross(this.normal, this.tangent);
|
|
83
|
+
this.$return(pb.mat3(this.tangent, this.bitangent, this.normal));
|
|
84
|
+
});
|
|
85
|
+
pb.func('D_Charlie', [
|
|
86
|
+
pb.float('sheenRoughness'),
|
|
87
|
+
pb.float('NdotH')
|
|
88
|
+
], function() {
|
|
89
|
+
this.$l.roughness = pb.max(this.sheenRoughness, 0.000001);
|
|
90
|
+
this.$l.invR = pb.div(1, this.roughness);
|
|
91
|
+
this.$l.cos2h = pb.mul(this.NdotH, this.NdotH);
|
|
92
|
+
this.$l.sin2h = pb.sub(1, this.cos2h);
|
|
93
|
+
this.$return(pb.div(pb.mul(pb.add(this.invR, 2), pb.pow(this.sin2h, pb.mul(this.invR, 0.5))), Math.PI * 2));
|
|
94
|
+
});
|
|
95
|
+
pb.func('smithGGXCorrelated', [
|
|
96
|
+
pb.float('NoV'),
|
|
97
|
+
pb.float('NoL'),
|
|
98
|
+
pb.float('roughness')
|
|
99
|
+
], function() {
|
|
100
|
+
this.$l.a2 = pb.mul(this.roughness, this.roughness, this.roughness, this.roughness);
|
|
101
|
+
this.$l.GGXV = pb.mul(this.NoL, pb.sqrt(pb.add(pb.mul(this.NoV, this.NoV, pb.sub(1, this.a2)), this.a2)));
|
|
102
|
+
this.$l.GGXL = pb.mul(this.NoV, pb.sqrt(pb.add(pb.mul(this.NoL, this.NoL, pb.sub(1, this.a2)), this.a2)));
|
|
103
|
+
this.$return(pb.div(0.5, pb.add(this.GGXV, this.GGXL)));
|
|
104
|
+
});
|
|
105
|
+
pb.func('V_Ashikhmin', [
|
|
106
|
+
pb.float('NdotL'),
|
|
107
|
+
pb.float('NdotV')
|
|
108
|
+
], function() {
|
|
109
|
+
this.$return(pb.clamp(pb.div(1, pb.mul(pb.sub(pb.add(this.NdotL, this.NdotV), pb.mul(this.NdotL, this.NdotV)), 4)), 0, 1));
|
|
110
|
+
});
|
|
111
|
+
pb.func('importanceSample', [
|
|
112
|
+
pb.vec2('xi'),
|
|
113
|
+
pb.vec3('normal'),
|
|
114
|
+
pb.float('roughness'),
|
|
115
|
+
pb.vec3('ggx').out(),
|
|
116
|
+
pb.vec3('charlie').out()
|
|
117
|
+
], function() {
|
|
118
|
+
this.$l.alphaRoughness = pb.mul(this.roughness, this.roughness);
|
|
119
|
+
this.$l.cosTheta = pb.clamp(pb.sqrt(pb.div(pb.sub(1, this.xi.y), pb.add(1, pb.mul(pb.sub(pb.mul(this.alphaRoughness, this.alphaRoughness), 1), this.xi.y)))), 0, 1);
|
|
120
|
+
this.$l.sinTheta = pb.sqrt(pb.sub(1, pb.mul(this.cosTheta, this.cosTheta)));
|
|
121
|
+
this.$l.phi = pb.mul(this.xi.x, Math.PI * 2);
|
|
122
|
+
this.$l.TBN = this.generateTBN(this.normal);
|
|
123
|
+
this.$l.localSpaceDir = pb.normalize(pb.vec3(pb.mul(this.sinTheta, pb.cos(this.phi)), pb.mul(this.sinTheta, pb.sin(this.phi)), this.cosTheta));
|
|
124
|
+
this.ggx = pb.mul(this.TBN, this.localSpaceDir);
|
|
125
|
+
this.sinTheta = pb.pow(this.xi.y, pb.div(this.alphaRoughness, pb.add(pb.mul(this.alphaRoughness, 2), 1)));
|
|
126
|
+
this.cosTheta = pb.sqrt(pb.sub(1, pb.mul(this.sinTheta, this.sinTheta)));
|
|
127
|
+
this.localSpaceDir = pb.normalize(pb.vec3(pb.mul(this.sinTheta, pb.cos(this.phi)), pb.mul(this.sinTheta, pb.sin(this.phi)), this.cosTheta));
|
|
128
|
+
this.charlie = pb.mul(this.TBN, this.localSpaceDir);
|
|
129
|
+
});
|
|
130
|
+
pb.func('integrateBRDF', [
|
|
131
|
+
pb.float('NoV'),
|
|
132
|
+
pb.float('roughness')
|
|
133
|
+
], function() {
|
|
134
|
+
this.$l.V = pb.vec3(pb.sub(1, pb.mul(this.NoV, this.NoV)), 0, this.NoV);
|
|
135
|
+
this.$l.a = pb.float(0);
|
|
136
|
+
this.$l.b = pb.float(0);
|
|
137
|
+
this.$l.c = pb.float(0);
|
|
138
|
+
this.$l.n = pb.vec3(0, 0, 1);
|
|
139
|
+
this.$for(pb.int('i'), 0, SAMPLE_COUNT, function() {
|
|
140
|
+
this.$l.xi = this.hammersley2d(this.i, SAMPLE_COUNT);
|
|
141
|
+
this.$l.ggxSample = pb.vec3();
|
|
142
|
+
this.$l.charlieSample = pb.vec3();
|
|
143
|
+
this.importanceSample(this.xi, this.n, this.roughness, this.ggxSample, this.charlieSample);
|
|
144
|
+
this.$l.ggxL = pb.normalize(pb.reflect(pb.neg(this.V), this.ggxSample.xyz));
|
|
145
|
+
this.$l.ggxNoL = pb.clamp(this.ggxL.z, 0, 1);
|
|
146
|
+
this.$l.ggxNoH = pb.clamp(this.ggxSample.z, 0, 1);
|
|
147
|
+
this.$l.ggxVoH = pb.clamp(pb.dot(this.V, this.ggxSample.xyz), 0, 1);
|
|
148
|
+
this.$l.charlieL = pb.normalize(pb.reflect(pb.neg(this.V), this.charlieSample.xyz));
|
|
149
|
+
this.$l.charlieNoL = pb.clamp(this.charlieL.z, 0, 1);
|
|
150
|
+
this.$l.charlieNoH = pb.clamp(this.charlieSample.z, 0, 1);
|
|
151
|
+
this.$l.charlieVoH = pb.clamp(pb.dot(this.V, this.charlieSample.xyz), 0, 1);
|
|
152
|
+
this.$if(pb.greaterThan(this.ggxNoL, 0), function() {
|
|
153
|
+
this.$l.pdf = pb.div(pb.mul(this.smithGGXCorrelated(this.NoV, this.ggxNoL, this.roughness), this.ggxVoH, this.ggxNoL), this.ggxNoH);
|
|
154
|
+
this.$l.Fc = pb.pow(pb.sub(1, this.ggxVoH), 5);
|
|
155
|
+
this.a = pb.add(this.a, pb.mul(pb.sub(1, this.Fc), this.pdf));
|
|
156
|
+
this.b = pb.add(this.b, pb.mul(this.Fc, this.pdf));
|
|
157
|
+
});
|
|
158
|
+
this.$if(pb.greaterThan(this.charlieNoL, 0), function() {
|
|
159
|
+
this.$l.sheenDistribution = this.D_Charlie(this.roughness, this.charlieNoH);
|
|
160
|
+
this.$l.sheenVis = this.V_Ashikhmin(this.charlieNoL, this.NoV);
|
|
161
|
+
this.c = pb.add(this.c, pb.mul(this.sheenVis, this.sheenDistribution, this.charlieNoL, this.charlieVoH));
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
this.$return(pb.div(pb.vec3(pb.mul(this.a, 4), pb.mul(this.b, 4), pb.mul(this.c, 8 * Math.PI)), SAMPLE_COUNT));
|
|
165
|
+
});
|
|
166
|
+
pb.main(function() {
|
|
167
|
+
this.$outputs.color = pb.vec4(this.integrateBRDF(this.$inputs.uv.x, this.$inputs.uv.y), 1);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const vertexLayout = device.createVertexLayout({
|
|
172
|
+
vertexBuffers: [
|
|
173
|
+
{
|
|
174
|
+
buffer: device.createVertexBuffer('position_f32x2', new Float32Array([
|
|
175
|
+
-1,
|
|
176
|
+
-1,
|
|
177
|
+
1,
|
|
178
|
+
-1,
|
|
179
|
+
-1,
|
|
180
|
+
1,
|
|
181
|
+
1,
|
|
182
|
+
1
|
|
183
|
+
]))
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
});
|
|
187
|
+
const rs = device.createRenderStateSet();
|
|
188
|
+
rs.useRasterizerState().setCullMode('none');
|
|
189
|
+
rs.useDepthState().enableTest(false).enableWrite(false);
|
|
190
|
+
const tex = device.createTexture2D('rgba8unorm', size, size, {
|
|
191
|
+
samplerOptions: {
|
|
192
|
+
mipFilter: 'none'
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
tex.name = 'GGXLUT';
|
|
196
|
+
const fb = device.createFrameBuffer([
|
|
197
|
+
tex
|
|
198
|
+
], null);
|
|
199
|
+
device.pushDeviceStates();
|
|
200
|
+
device.setProgram(program);
|
|
201
|
+
device.setVertexLayout(vertexLayout);
|
|
202
|
+
device.setRenderStates(rs);
|
|
203
|
+
device.setFramebuffer(fb);
|
|
204
|
+
device.draw('triangle-strip', 0, 4);
|
|
205
|
+
device.popDeviceStates();
|
|
206
|
+
fb.dispose();
|
|
207
|
+
vertexLayout.dispose();
|
|
208
|
+
program.dispose();
|
|
209
|
+
return tex;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export { getGGXLUT };
|
|
213
|
+
//# sourceMappingURL=ggxlut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ggxlut.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { applyMaterialMixins } from '../../meshmaterial.js';
|
|
2
|
+
import { mixinLight } from '../lit.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Blinn-phong lighting model mixin
|
|
6
|
+
* @param BaseCls - Class to mix in
|
|
7
|
+
* @returns Mixed class
|
|
8
|
+
* @public
|
|
9
|
+
*/ function mixinBlinnPhong(BaseCls) {
|
|
10
|
+
if (BaseCls.blinnPhongMixed) {
|
|
11
|
+
return BaseCls;
|
|
12
|
+
}
|
|
13
|
+
const S = applyMaterialMixins(BaseCls, mixinLight);
|
|
14
|
+
return class extends S {
|
|
15
|
+
static blinnPhongMixed = true;
|
|
16
|
+
_shininess;
|
|
17
|
+
constructor(){
|
|
18
|
+
super();
|
|
19
|
+
this._shininess = 32;
|
|
20
|
+
}
|
|
21
|
+
/** Shininess */ get shininess() {
|
|
22
|
+
return this._shininess;
|
|
23
|
+
}
|
|
24
|
+
set shininess(val) {
|
|
25
|
+
if (val !== this._shininess) {
|
|
26
|
+
this._shininess = val;
|
|
27
|
+
this.uniformChanged();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
fragmentShader(scope) {
|
|
31
|
+
super.fragmentShader(scope);
|
|
32
|
+
const pb = scope.$builder;
|
|
33
|
+
if (this.needFragmentColor()) {
|
|
34
|
+
scope.zShininess = pb.float().uniform(2);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
applyUniformValues(bindGroup, ctx, pass) {
|
|
38
|
+
super.applyUniformValues(bindGroup, ctx, pass);
|
|
39
|
+
if (this.needFragmentColor()) {
|
|
40
|
+
bindGroup.setValue('zShininess', this._shininess);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
blinnPhongLight(scope, worldPos, normal, viewVec, albedo) {
|
|
44
|
+
const pb = scope.$builder;
|
|
45
|
+
const funcName = 'Z_blinnPhongLight';
|
|
46
|
+
const that = this;
|
|
47
|
+
pb.func(funcName, [
|
|
48
|
+
pb.vec3('worldPos'),
|
|
49
|
+
pb.vec3('normal'),
|
|
50
|
+
pb.vec3('viewVec'),
|
|
51
|
+
pb.vec4('albedo')
|
|
52
|
+
], function() {
|
|
53
|
+
if (!that.needFragmentColor()) {
|
|
54
|
+
this.$return(this.albedo.rgb);
|
|
55
|
+
} else {
|
|
56
|
+
if (that.needCalculateEnvLight()) {
|
|
57
|
+
this.$l.diffuseColor = that.getEnvLightIrradiance(this, this.normal);
|
|
58
|
+
} else {
|
|
59
|
+
this.$l.diffuseColor = pb.vec3(0);
|
|
60
|
+
}
|
|
61
|
+
this.$l.specularColor = pb.vec3(0);
|
|
62
|
+
that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, shadow) {
|
|
63
|
+
this.$l.lightAtten = that.calculateLightAttenuation(this, type, this.worldPos, posRange, dirCutoff);
|
|
64
|
+
this.$l.lightDir = that.calculateLightDirection(this, type, this.worldPos, posRange, dirCutoff);
|
|
65
|
+
this.$l.NoL = pb.clamp(pb.dot(this.normal, this.lightDir), 0, 1);
|
|
66
|
+
this.$l.halfVec = pb.normalize(pb.add(this.viewVec, this.lightDir));
|
|
67
|
+
this.$l.NoH = pb.clamp(pb.dot(this.normal, this.halfVec), 0, 1);
|
|
68
|
+
this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten);
|
|
69
|
+
this.$l.diffuse = pb.mul(this.lightColor, this.NoL);
|
|
70
|
+
this.$l.specular = pb.mul(this.lightColor, pb.pow(this.NoH, this.zShininess));
|
|
71
|
+
if (shadow) {
|
|
72
|
+
this.$l.shadow = pb.vec3(that.calculateShadow(this, this.worldPos, this.NoL));
|
|
73
|
+
this.diffuse = pb.mul(this.diffuse, this.shadow);
|
|
74
|
+
this.specular = pb.mul(this.specular, this.shadow);
|
|
75
|
+
}
|
|
76
|
+
this.diffuseColor = pb.add(this.diffuseColor, this.diffuse);
|
|
77
|
+
this.specularColor = pb.add(this.specularColor, this.specular);
|
|
78
|
+
});
|
|
79
|
+
this.$l.litColor = pb.add(pb.mul(this.albedo.rgb, this.diffuseColor), this.specularColor);
|
|
80
|
+
this.$return(this.litColor);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
return pb.getGlobalScope()[funcName](worldPos, normal, viewVec, albedo);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { mixinBlinnPhong };
|
|
89
|
+
//# sourceMappingURL=blinnphong.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blinnphong.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { applyMaterialMixins } from '../../meshmaterial.js';
|
|
2
|
+
import { mixinLight } from '../lit.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Lambert lighting model mixin
|
|
6
|
+
* @param BaseCls - Class to mix in
|
|
7
|
+
* @returns Mixed class
|
|
8
|
+
* @public
|
|
9
|
+
*/ function mixinLambert(BaseCls) {
|
|
10
|
+
if (BaseCls.lambertMixed) {
|
|
11
|
+
return BaseCls;
|
|
12
|
+
}
|
|
13
|
+
const S = applyMaterialMixins(BaseCls, mixinLight);
|
|
14
|
+
return class extends S {
|
|
15
|
+
static lambertMixed = true;
|
|
16
|
+
constructor(){
|
|
17
|
+
super();
|
|
18
|
+
}
|
|
19
|
+
lambertLight(scope, worldPos, normal, albedo) {
|
|
20
|
+
const pb = scope.$builder;
|
|
21
|
+
const funcName = 'Z_lambertLight';
|
|
22
|
+
const that = this;
|
|
23
|
+
pb.func(funcName, [
|
|
24
|
+
pb.vec3('worldPos'),
|
|
25
|
+
pb.vec3('normal'),
|
|
26
|
+
pb.vec4('albedo')
|
|
27
|
+
], function() {
|
|
28
|
+
if (!that.needFragmentColor()) {
|
|
29
|
+
this.$return(this.albedo.rgb);
|
|
30
|
+
} else {
|
|
31
|
+
if (that.needCalculateEnvLight()) {
|
|
32
|
+
this.$l.diffuseColor = that.getEnvLightIrradiance(this, this.normal);
|
|
33
|
+
} else {
|
|
34
|
+
this.$l.diffuseColor = pb.vec3(0);
|
|
35
|
+
}
|
|
36
|
+
that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, shadow) {
|
|
37
|
+
this.$l.lightAtten = that.calculateLightAttenuation(this, type, this.worldPos, posRange, dirCutoff);
|
|
38
|
+
this.$l.lightDir = that.calculateLightDirection(this, type, this.worldPos, posRange, dirCutoff);
|
|
39
|
+
this.$l.NoL = pb.clamp(pb.dot(this.normal, this.lightDir), 0, 1);
|
|
40
|
+
this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten);
|
|
41
|
+
this.$l.diffuse = pb.mul(this.lightColor, this.NoL);
|
|
42
|
+
if (shadow) {
|
|
43
|
+
this.$l.shadow = pb.vec3(that.calculateShadow(this, this.worldPos, this.NoL));
|
|
44
|
+
this.diffuse = pb.mul(this.diffuse, this.shadow);
|
|
45
|
+
}
|
|
46
|
+
this.diffuseColor = pb.add(this.diffuseColor, this.diffuse);
|
|
47
|
+
});
|
|
48
|
+
this.$l.litColor = pb.mul(this.albedo.rgb, this.diffuseColor);
|
|
49
|
+
this.$return(this.litColor);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return pb.getGlobalScope()[funcName](worldPos, normal, albedo);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { mixinLambert };
|
|
58
|
+
//# sourceMappingURL=lambert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambert.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|