@zephyr3d/scene 0.1.1 → 0.2.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 +124 -67
- 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 +10 -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 +1842 -2484
- package/dist/index.js +21 -10
- 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 +66 -194
- 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 +100 -59
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +227 -186
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/albedocolor.js +29 -100
- 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 +903 -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 +311 -103
- 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 +8 -6
- package/dist/posteffect/bloom.js.map +1 -1
- package/dist/posteffect/compositor.js +14 -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 +10 -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/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/render_queue.js +2 -1
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +191 -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 +31 -15
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/environment.js +8 -6
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/graph_node.js +3 -0
- package/dist/scene/graph_node.js.map +1 -1
- package/dist/scene/mesh.js +13 -12
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/scene.js +11 -15
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +10 -16
- 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/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 +11 -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 +13 -15
- 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 +15 -13
- package/dist/shadow/vsm.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 +9 -9
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { applyMaterialMixins } from '../../meshmaterial.js';
|
|
2
|
+
import { mixinTextureProps } from '../texture.js';
|
|
3
|
+
import { mixinPBRCommon } from './common.js';
|
|
4
|
+
import { Vector4 } from '@zephyr3d/base';
|
|
5
|
+
import { mixinLight } from '../lit.js';
|
|
6
|
+
|
|
7
|
+
function mixinPBRSpecularGlossness(BaseCls) {
|
|
8
|
+
if (BaseCls.pbrSpecularGlossnessMixed) {
|
|
9
|
+
return BaseCls;
|
|
10
|
+
}
|
|
11
|
+
const S = applyMaterialMixins(BaseCls, mixinPBRCommon, mixinLight, mixinTextureProps('specular'));
|
|
12
|
+
return class extends S {
|
|
13
|
+
static pbrSpecularGlossnessMixed = true;
|
|
14
|
+
_specularFactor;
|
|
15
|
+
_glossinessFactor;
|
|
16
|
+
constructor(){
|
|
17
|
+
super();
|
|
18
|
+
this._specularFactor = Vector4.one();
|
|
19
|
+
this._glossinessFactor = 1;
|
|
20
|
+
}
|
|
21
|
+
get specularFactor() {
|
|
22
|
+
return this._specularFactor;
|
|
23
|
+
}
|
|
24
|
+
set specularFactor(val) {
|
|
25
|
+
if (!val.equalsTo(this._specularFactor)) {
|
|
26
|
+
this._specularFactor.set(val);
|
|
27
|
+
this.optionChanged(true);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
get glossinessFactor() {
|
|
31
|
+
return this._glossinessFactor;
|
|
32
|
+
}
|
|
33
|
+
set glossinessFactor(val) {
|
|
34
|
+
if (val !== this._glossinessFactor) {
|
|
35
|
+
this._glossinessFactor = val;
|
|
36
|
+
this.optionChanged(false);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
fragmentShader(scope) {
|
|
40
|
+
super.fragmentShader(scope);
|
|
41
|
+
if (this.needFragmentColor()) {
|
|
42
|
+
const pb = scope.$builder;
|
|
43
|
+
scope.zSpecularFactor = pb.vec4().uniform(2);
|
|
44
|
+
scope.zGlossinessFactor = pb.float().uniform(2);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
applyUniformValues(bindGroup, ctx, pass) {
|
|
48
|
+
super.applyUniformValues(bindGroup, ctx, pass);
|
|
49
|
+
if (this.needFragmentColor(ctx)) {
|
|
50
|
+
bindGroup.setValue('zSpecularFactor', this._specularFactor);
|
|
51
|
+
bindGroup.setValue('zGlossinessFactor', this._glossinessFactor);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
PBRLight(scope, normal, TBN, viewVec, albedo) {
|
|
55
|
+
const pb = scope.$builder;
|
|
56
|
+
const funcName = 'z_PBRLight';
|
|
57
|
+
const that = this;
|
|
58
|
+
pb.func(funcName, [
|
|
59
|
+
pb.vec3('normal'),
|
|
60
|
+
pb.mat3('TBN'),
|
|
61
|
+
pb.vec3('viewVec'),
|
|
62
|
+
pb.vec4('albedo')
|
|
63
|
+
], function() {
|
|
64
|
+
this.$l.pbrData = that.getCommonData(this, this.albedo, this.viewVec, this.TBN);
|
|
65
|
+
this.$l.lightingColor = pb.vec3(0);
|
|
66
|
+
this.$l.emissiveColor = that.calculateEmissiveColor(this);
|
|
67
|
+
that.indirectLighting(this, this.normal, this.viewVec, this.pbrData, this.lightingColor);
|
|
68
|
+
that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, shadow) {
|
|
69
|
+
this.$l.diffuse = pb.vec3();
|
|
70
|
+
this.$l.specular = pb.vec3();
|
|
71
|
+
this.$l.lightAtten = that.calculateLightAttenuation(this, type, posRange, dirCutoff);
|
|
72
|
+
this.$l.lightDir = that.calculateLightDirection(this, type, posRange, dirCutoff);
|
|
73
|
+
this.$l.NoL = pb.clamp(pb.dot(this.normal, this.lightDir), 0, 1);
|
|
74
|
+
this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten, this.NoL);
|
|
75
|
+
if (shadow) {
|
|
76
|
+
this.lightColor = pb.mul(this.lightColor, that.calculateShadow(this, this.NoL));
|
|
77
|
+
}
|
|
78
|
+
that.directLighting(this, this.lightDir, this.lightColor, this.normal, this.viewVec, this.pbrData, this.lightingColor);
|
|
79
|
+
});
|
|
80
|
+
this.$return(pb.add(this.lightingColor, this.emissiveColor));
|
|
81
|
+
});
|
|
82
|
+
return pb.getGlobalScope()[funcName](normal, TBN, viewVec, albedo);
|
|
83
|
+
}
|
|
84
|
+
calculateCommonData(scope, albedo, viewVec, TBN, data) {
|
|
85
|
+
super.calculateCommonData(scope, albedo, viewVec, TBN, data);
|
|
86
|
+
const pb = scope.$builder;
|
|
87
|
+
if (this.specularTexture) {
|
|
88
|
+
scope.$l.specularTextureSample = this.sampleSpecularTexture(scope);
|
|
89
|
+
data.roughness = pb.sub(1, pb.mul(scope.zGlossinessFactor, scope.specularTextureSample.a));
|
|
90
|
+
data.f0 = pb.vec4(pb.mul(scope.specularTextureSample.rgb, scope.zSpecularFactor.rgb), this.getF0(scope).a);
|
|
91
|
+
} else {
|
|
92
|
+
data.roughness = pb.sub(1, scope.zGlossinessFactor);
|
|
93
|
+
data.f0 = pb.vec4(scope.zSpecularFactor.rgb, this.getF0(scope).a);
|
|
94
|
+
}
|
|
95
|
+
data.metallic = pb.max(pb.max(data.f0.r, data.f0.g), data.f0.b);
|
|
96
|
+
data.diffuse = pb.vec4(pb.mul(albedo.rgb, pb.sub(1, data.metallic)), albedo.a);
|
|
97
|
+
data.specularWeight = 1;
|
|
98
|
+
data.f90 = pb.vec3(1);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { mixinPBRSpecularGlossness };
|
|
104
|
+
//# sourceMappingURL=specularglossness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"specularglossness.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Texture property mixin
|
|
3
|
+
* @param name - Texture name
|
|
4
|
+
* @returns Texture mixin
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
*/ function mixinTextureProps(name) {
|
|
8
|
+
return function(BaseCls, vertex = false) {
|
|
9
|
+
const capName = `${name[0].toUpperCase()}${name.slice(1)}`;
|
|
10
|
+
const id = `mixinTexture${capName}`;
|
|
11
|
+
let feature = 0;
|
|
12
|
+
let featureTexIndex = 0;
|
|
13
|
+
let featureTexMatrix = 0;
|
|
14
|
+
if (BaseCls[id]) {
|
|
15
|
+
return BaseCls;
|
|
16
|
+
}
|
|
17
|
+
const cls = class extends BaseCls {
|
|
18
|
+
constructor(...args){
|
|
19
|
+
super(...args);
|
|
20
|
+
}
|
|
21
|
+
vertexShader(scope) {
|
|
22
|
+
super.vertexShader(scope);
|
|
23
|
+
if (vertex || this.needFragmentColor()) {
|
|
24
|
+
const pb = scope.$builder;
|
|
25
|
+
const that = this;
|
|
26
|
+
if (this.featureUsed(feature)) {
|
|
27
|
+
const texCoordIndex = that[`${name}TexCoordIndex`];
|
|
28
|
+
if (texCoordIndex >= 0) {
|
|
29
|
+
const semantic = `texCoord${that[`${name}TexCoordIndex`]}`;
|
|
30
|
+
if (!scope.$getVertexAttrib(semantic)) {
|
|
31
|
+
scope.$inputs[semantic] = pb.vec2().attrib(semantic);
|
|
32
|
+
}
|
|
33
|
+
if (this.featureUsed(featureTexMatrix)) {
|
|
34
|
+
scope[`z${capName}TextureMatrix`] = pb.mat4().uniform(2);
|
|
35
|
+
if (!vertex) {
|
|
36
|
+
scope.$outputs[`z${capName}TexCoord`] = pb.mul(scope[`z${capName}TextureMatrix`], pb.vec4(scope.$inputs[semantic], 0, 1)).xy;
|
|
37
|
+
}
|
|
38
|
+
} else if (!vertex) {
|
|
39
|
+
scope.$outputs[`z${capName}TexCoord`] = scope.$inputs[semantic];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
fragmentShader(scope) {
|
|
46
|
+
super.fragmentShader(scope);
|
|
47
|
+
if (this.needFragmentColor()) {
|
|
48
|
+
const pb = scope.$builder;
|
|
49
|
+
if (this.featureUsed(feature)) {
|
|
50
|
+
scope[`z${capName}Tex`] = pb.tex2D().uniform(2);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
applyUniformValues(bindGroup, ctx, pass) {
|
|
55
|
+
super.applyUniformValues(bindGroup, ctx, pass);
|
|
56
|
+
if (this.needFragmentColor(ctx)) {
|
|
57
|
+
if (this.featureUsed(feature)) {
|
|
58
|
+
const that = this;
|
|
59
|
+
bindGroup.setTexture(`z${capName}Tex`, that[`${name}Texture`], that[`${name}TextureSampler`]);
|
|
60
|
+
if (this.featureUsed(featureTexMatrix)) {
|
|
61
|
+
bindGroup.setValue(`z${capName}TextureMatrix`, that[`${name}TexCoordMatrix`]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
feature = cls.defineFeature();
|
|
68
|
+
featureTexIndex = cls.defineFeature();
|
|
69
|
+
featureTexMatrix = cls.defineFeature();
|
|
70
|
+
const proto = cls.prototype;
|
|
71
|
+
const propTexture = `__${name}Texture`;
|
|
72
|
+
const propSampler = `__${name}Sampler`;
|
|
73
|
+
const propTexCoord = `__${name}TexCoordIndex`;
|
|
74
|
+
const propMatrix = `__${name}TexMatrix`;
|
|
75
|
+
proto[propTexture] = null;
|
|
76
|
+
proto[propSampler] = null;
|
|
77
|
+
proto[propTexCoord] = 0;
|
|
78
|
+
proto[propMatrix] = null;
|
|
79
|
+
proto[`sample${capName}Texture`] = function(scope, texCoord) {
|
|
80
|
+
const tex = this[`get${capName}TextureUniform`](scope);
|
|
81
|
+
const coord = texCoord ?? this[`get${capName}TexCoord`](scope);
|
|
82
|
+
return scope.$builder.textureSample(tex, coord);
|
|
83
|
+
};
|
|
84
|
+
proto[`get${capName}TextureUniform`] = function(scope) {
|
|
85
|
+
return scope.$builder.shaderKind === 'fragment' ? scope[`z${capName}Tex`] : null;
|
|
86
|
+
};
|
|
87
|
+
proto[`get${capName}TexCoord`] = function(scope) {
|
|
88
|
+
if (proto[propTexCoord] < 0) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const pb = scope.$builder;
|
|
92
|
+
if (pb.shaderKind === 'vertex' !== !!vertex) {
|
|
93
|
+
throw new Error(`mixinTextureProps.get${capName}TexCoord(): must be called in ${vertex ? 'vertex' : 'fragment'} stage`);
|
|
94
|
+
}
|
|
95
|
+
return scope.$builder.shaderKind === 'fragment' ? scope.$inputs[`z${capName}TexCoord`] : this.featureUsed(featureTexMatrix) ? pb.mul(scope[`z${capName}TextureMatrix`], pb.vec4(scope.$inputs[`texCoord${proto[propTexCoord]}`], 0, 1)).xy : scope.$inputs[`texCoord${proto[propTexCoord]}`];
|
|
96
|
+
};
|
|
97
|
+
Object.defineProperty(proto, `${name}Texture`, {
|
|
98
|
+
get: function() {
|
|
99
|
+
return this[propTexture];
|
|
100
|
+
},
|
|
101
|
+
set: function(newValue) {
|
|
102
|
+
if (this[propTexture] !== newValue) {
|
|
103
|
+
this[propTexture] = newValue ?? null;
|
|
104
|
+
this.useFeature(feature, !!this[propTexture]);
|
|
105
|
+
if (this[propTexture]) {
|
|
106
|
+
this.useFeature(featureTexIndex, this[propTexCoord]);
|
|
107
|
+
this.useFeature(featureTexMatrix, !!this[propMatrix]);
|
|
108
|
+
this.uniformChanged();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
enumerable: true,
|
|
113
|
+
configurable: true
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(proto, `${name}TextureSampler`, {
|
|
116
|
+
get: function() {
|
|
117
|
+
return this[propSampler];
|
|
118
|
+
},
|
|
119
|
+
set: function(newValue) {
|
|
120
|
+
this[propSampler] = newValue;
|
|
121
|
+
},
|
|
122
|
+
enumerable: true,
|
|
123
|
+
configurable: true
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(proto, `${name}TexCoordMatrix`, {
|
|
126
|
+
get: function() {
|
|
127
|
+
return this[propMatrix];
|
|
128
|
+
},
|
|
129
|
+
set: function(newValue) {
|
|
130
|
+
if (this[propMatrix] !== newValue) {
|
|
131
|
+
this[propMatrix] = newValue;
|
|
132
|
+
this.useFeature(featureTexMatrix, !!this[propMatrix]);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
enumerable: true,
|
|
136
|
+
configurable: true
|
|
137
|
+
});
|
|
138
|
+
Object.defineProperty(proto, `${name}TexCoordIndex`, {
|
|
139
|
+
get: function() {
|
|
140
|
+
return this[propTexCoord];
|
|
141
|
+
},
|
|
142
|
+
set: function(newValue) {
|
|
143
|
+
if (this[propTexCoord] !== newValue) {
|
|
144
|
+
this[propTexCoord] = newValue;
|
|
145
|
+
this.useFeature(featureTexIndex, this[propTexCoord]);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
enumerable: true,
|
|
149
|
+
configurable: true
|
|
150
|
+
});
|
|
151
|
+
cls[id] = true;
|
|
152
|
+
return cls;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { mixinTextureProps };
|
|
157
|
+
//# sourceMappingURL=texture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Vertex color mixin
|
|
3
|
+
*
|
|
4
|
+
* @param BaseCls - Base class to mix in
|
|
5
|
+
* @returns Mixed class
|
|
6
|
+
*/ function mixinVertexColor(BaseCls) {
|
|
4
7
|
if (BaseCls.vertexColorMixed) {
|
|
5
8
|
return BaseCls;
|
|
6
9
|
}
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
let FEATURE_VERTEX_COLOR = 0;
|
|
11
|
+
const cls = class extends BaseCls {
|
|
9
12
|
static vertexColorMixed = true;
|
|
10
13
|
constructor(...args){
|
|
11
14
|
super(...args);
|
|
12
15
|
}
|
|
13
16
|
/** Albedo color */ get vertexColor() {
|
|
14
|
-
return this.featureUsed(FEATURE_VERTEX_COLOR
|
|
17
|
+
return this.featureUsed(FEATURE_VERTEX_COLOR);
|
|
15
18
|
}
|
|
16
19
|
set vertexColor(val) {
|
|
17
20
|
this.useFeature(FEATURE_VERTEX_COLOR, !!val);
|
|
18
21
|
}
|
|
19
|
-
vertexShader(scope
|
|
20
|
-
super.vertexShader(scope
|
|
21
|
-
if (this.needFragmentColor(
|
|
22
|
+
vertexShader(scope) {
|
|
23
|
+
super.vertexShader(scope);
|
|
24
|
+
if (this.needFragmentColor()) {
|
|
22
25
|
if (this.vertexColor) {
|
|
23
26
|
if (scope.$getVertexAttrib('diffuse')) {
|
|
24
27
|
throw new Error('mixinVertexColor.vertexShader(): diffuse vertex stream already defined');
|
|
@@ -28,8 +31,8 @@ function mixinVertexColor(BaseCls) {
|
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
|
-
getVertexColor(scope
|
|
32
|
-
if (!this.needFragmentColor(
|
|
34
|
+
getVertexColor(scope) {
|
|
35
|
+
if (!this.needFragmentColor()) {
|
|
33
36
|
throw new Error('mixinVertexColor.getVertexColor(): No need to calculate albedo color, make sure needFragmentColor() returns true');
|
|
34
37
|
}
|
|
35
38
|
if (scope.$builder.shaderKind === 'fragment') {
|
|
@@ -39,6 +42,8 @@ function mixinVertexColor(BaseCls) {
|
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
};
|
|
45
|
+
FEATURE_VERTEX_COLOR = cls.defineFeature();
|
|
46
|
+
return cls;
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
export { mixinVertexColor };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vertexcolor.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vertexcolor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
|
|
2
|
+
import { mixinVertexColor } from './mixins/vertexcolor.js';
|
|
3
|
+
import { mixinPBRMetallicRoughness } from './mixins/lightmodel/pbrmetallicroughness.js';
|
|
4
|
+
import { ShaderHelper } from './shader/helper.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* PBRMetallicRoughness material class
|
|
8
|
+
* @public
|
|
9
|
+
*/ class PBRMetallicRoughnessMaterial extends applyMaterialMixins(MeshMaterial, mixinPBRMetallicRoughness, mixinVertexColor) {
|
|
10
|
+
/** @internal */ static FEATURE_VERTEX_NORMAL = this.defineFeature();
|
|
11
|
+
/** @internal */ static FEATURE_VERTEX_TANGENT = this.defineFeature();
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of PBRMetallicRoughnessMaterial class
|
|
14
|
+
*/ constructor(){
|
|
15
|
+
super();
|
|
16
|
+
this.useFeature(PBRMetallicRoughnessMaterial.FEATURE_VERTEX_NORMAL, true);
|
|
17
|
+
}
|
|
18
|
+
/** true if vertex normal attribute presents */ get vertexNormal() {
|
|
19
|
+
return this.featureUsed(PBRMetallicRoughnessMaterial.FEATURE_VERTEX_NORMAL);
|
|
20
|
+
}
|
|
21
|
+
set vertexNormal(val) {
|
|
22
|
+
this.useFeature(PBRMetallicRoughnessMaterial.FEATURE_VERTEX_NORMAL, !!val);
|
|
23
|
+
}
|
|
24
|
+
/** true if vertex normal attribute presents */ get vertexTangent() {
|
|
25
|
+
return this.featureUsed(PBRMetallicRoughnessMaterial.FEATURE_VERTEX_TANGENT);
|
|
26
|
+
}
|
|
27
|
+
set vertexTangent(val) {
|
|
28
|
+
this.useFeature(PBRMetallicRoughnessMaterial.FEATURE_VERTEX_TANGENT, !!val);
|
|
29
|
+
}
|
|
30
|
+
vertexShader(scope) {
|
|
31
|
+
super.vertexShader(scope);
|
|
32
|
+
const pb = scope.$builder;
|
|
33
|
+
scope.$l.oPos = ShaderHelper.resolveVertexPosition(scope);
|
|
34
|
+
scope.$outputs.worldPos = pb.mul(ShaderHelper.getWorldMatrix(scope), pb.vec4(scope.oPos, 1)).xyz;
|
|
35
|
+
ShaderHelper.setClipSpacePosition(scope, pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.worldPos, 1)));
|
|
36
|
+
if (this.vertexNormal) {
|
|
37
|
+
scope.$l.oNorm = ShaderHelper.resolveVertexNormal(scope);
|
|
38
|
+
scope.$outputs.wNorm = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oNorm, 0)).xyz;
|
|
39
|
+
if (this.vertexTangent) {
|
|
40
|
+
scope.$l.oTangent = ShaderHelper.resolveVertexTangent(scope);
|
|
41
|
+
scope.$outputs.wTangent = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oTangent.xyz, 0)).xyz;
|
|
42
|
+
scope.$outputs.wBinormal = pb.mul(pb.cross(scope.$outputs.wNorm, scope.$outputs.wTangent), scope.oTangent.w);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
fragmentShader(scope) {
|
|
47
|
+
super.fragmentShader(scope);
|
|
48
|
+
const pb = scope.$builder;
|
|
49
|
+
if (this.needFragmentColor()) {
|
|
50
|
+
scope.$l.albedo = this.calculateAlbedoColor(scope);
|
|
51
|
+
if (this.vertexColor) {
|
|
52
|
+
scope.albedo = pb.mul(scope.albedo, this.getVertexColor(scope));
|
|
53
|
+
}
|
|
54
|
+
scope.$l.normalInfo = this.calculateNormalAndTBN(scope, scope.$inputs.worldPos, scope.$inputs.wNorm, scope.$inputs.wTangent, scope.$inputs.wBinormal);
|
|
55
|
+
scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);
|
|
56
|
+
scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN);
|
|
57
|
+
this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a));
|
|
58
|
+
} else {
|
|
59
|
+
this.outputFragmentColor(scope, scope.$inputs.worldPos, null);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { PBRMetallicRoughnessMaterial };
|
|
65
|
+
//# sourceMappingURL=pbrmr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbrmr.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
|
|
2
|
+
import { mixinVertexColor } from './mixins/vertexcolor.js';
|
|
3
|
+
import { mixinPBRSpecularGlossness } from './mixins/lightmodel/pbrspecularglossness.js';
|
|
4
|
+
import { ShaderHelper } from './shader/helper.js';
|
|
5
|
+
|
|
6
|
+
class PBRSpecularGlossinessMaterial extends applyMaterialMixins(MeshMaterial, mixinPBRSpecularGlossness, mixinVertexColor) {
|
|
7
|
+
static FEATURE_VERTEX_NORMAL = this.defineFeature();
|
|
8
|
+
static FEATURE_VERTEX_TANGENT = this.defineFeature();
|
|
9
|
+
constructor(){
|
|
10
|
+
super();
|
|
11
|
+
this.useFeature(PBRSpecularGlossinessMaterial.FEATURE_VERTEX_NORMAL, true);
|
|
12
|
+
}
|
|
13
|
+
/** true if vertex normal attribute presents */ get vertexNormal() {
|
|
14
|
+
return this.featureUsed(PBRSpecularGlossinessMaterial.FEATURE_VERTEX_NORMAL);
|
|
15
|
+
}
|
|
16
|
+
set vertexNormal(val) {
|
|
17
|
+
this.useFeature(PBRSpecularGlossinessMaterial.FEATURE_VERTEX_NORMAL, !!val);
|
|
18
|
+
}
|
|
19
|
+
/** true if vertex normal attribute presents */ get vertexTangent() {
|
|
20
|
+
return this.featureUsed(PBRSpecularGlossinessMaterial.FEATURE_VERTEX_TANGENT);
|
|
21
|
+
}
|
|
22
|
+
set vertexTangent(val) {
|
|
23
|
+
this.useFeature(PBRSpecularGlossinessMaterial.FEATURE_VERTEX_TANGENT, !!val);
|
|
24
|
+
}
|
|
25
|
+
vertexShader(scope) {
|
|
26
|
+
super.vertexShader(scope);
|
|
27
|
+
const pb = scope.$builder;
|
|
28
|
+
scope.$l.oPos = ShaderHelper.resolveVertexPosition(scope);
|
|
29
|
+
scope.$outputs.worldPos = pb.mul(ShaderHelper.getWorldMatrix(scope), pb.vec4(scope.oPos, 1)).xyz;
|
|
30
|
+
ShaderHelper.setClipSpacePosition(scope, pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.worldPos, 1)));
|
|
31
|
+
if (this.vertexNormal) {
|
|
32
|
+
scope.$l.oNorm = ShaderHelper.resolveVertexNormal(scope);
|
|
33
|
+
scope.$outputs.wNorm = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oNorm, 0)).xyz;
|
|
34
|
+
if (this.vertexTangent) {
|
|
35
|
+
scope.$l.oTangent = ShaderHelper.resolveVertexTangent(scope);
|
|
36
|
+
scope.$outputs.wTangent = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oTangent.xyz, 0)).xyz;
|
|
37
|
+
scope.$outputs.wBinormal = pb.mul(pb.cross(scope.$outputs.wNorm, scope.$outputs.wTangent), scope.oTangent.w);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
fragmentShader(scope) {
|
|
42
|
+
super.fragmentShader(scope);
|
|
43
|
+
const pb = scope.$builder;
|
|
44
|
+
if (this.needFragmentColor()) {
|
|
45
|
+
scope.$l.albedo = this.calculateAlbedoColor(scope);
|
|
46
|
+
if (this.vertexColor) {
|
|
47
|
+
scope.albedo = pb.mul(scope.albedo, this.getVertexColor(scope));
|
|
48
|
+
}
|
|
49
|
+
scope.$l.albedo = this.calculateAlbedoColor(scope);
|
|
50
|
+
if (this.vertexColor) {
|
|
51
|
+
scope.albedo = pb.mul(scope.albedo, this.getVertexColor(scope));
|
|
52
|
+
}
|
|
53
|
+
scope.$l.normalInfo = this.calculateNormalAndTBN(scope, scope.$inputs.worldPos, scope.$inputs.wNorm, scope.$inputs.wTangent, scope.$inputs.wBinormal);
|
|
54
|
+
scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);
|
|
55
|
+
scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN);
|
|
56
|
+
this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a));
|
|
57
|
+
} else {
|
|
58
|
+
this.outputFragmentColor(scope, scope.$inputs.worldPos, null);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { PBRSpecularGlossinessMaterial };
|
|
64
|
+
//# sourceMappingURL=pbrsg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbrsg.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|