@zephyr3d/scene 0.1.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 +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { ProgramBuilder } from '@zephyr3d/device';
|
|
2
|
+
import { RENDER_PASS_TYPE_FORWARD, RENDER_PASS_TYPE_SHADOWMAP, RENDER_PASS_TYPE_DEPTH_ONLY } from '../values.js';
|
|
3
|
+
import { Material } from './material.js';
|
|
4
|
+
import { ShaderFramework } from '../shaders/framework.js';
|
|
5
|
+
import { encodeColorOutput, nonLinearDepthToLinearNormalized, encodeNormalizedFloatToRGBA } from '../shaders/misc.js';
|
|
6
|
+
import { Application } from '../app.js';
|
|
7
|
+
|
|
8
|
+
const allRenderPassTypes = [
|
|
9
|
+
RENDER_PASS_TYPE_FORWARD,
|
|
10
|
+
RENDER_PASS_TYPE_SHADOWMAP,
|
|
11
|
+
RENDER_PASS_TYPE_DEPTH_ONLY
|
|
12
|
+
];
|
|
13
|
+
function applyMaterialMixins(target, ...mixins) {
|
|
14
|
+
let r = target;
|
|
15
|
+
for (const m of mixins){
|
|
16
|
+
r = m(r);
|
|
17
|
+
}
|
|
18
|
+
return r;
|
|
19
|
+
}
|
|
20
|
+
class MeshMaterial extends Material {
|
|
21
|
+
static FEATURE_ALPHATEST = 'mm_alphatest';
|
|
22
|
+
static FEATURE_ALPHABLEND = 'mm_alphablend';
|
|
23
|
+
static FEATURE_ALPHATOCOVERAGE = 'mm_alphatocoverage';
|
|
24
|
+
_features;
|
|
25
|
+
_featureStates;
|
|
26
|
+
_featureIndex;
|
|
27
|
+
_alphaCutoff;
|
|
28
|
+
_blendMode;
|
|
29
|
+
_opacity;
|
|
30
|
+
constructor(){
|
|
31
|
+
super();
|
|
32
|
+
this._features = new Map();
|
|
33
|
+
this._featureStates = [];
|
|
34
|
+
this._featureStates[RENDER_PASS_TYPE_FORWARD] = [];
|
|
35
|
+
this._featureStates[RENDER_PASS_TYPE_SHADOWMAP] = [];
|
|
36
|
+
this._featureStates[RENDER_PASS_TYPE_DEPTH_ONLY] = [];
|
|
37
|
+
this._featureIndex = 0;
|
|
38
|
+
this._alphaCutoff = 0;
|
|
39
|
+
this._blendMode = 'none';
|
|
40
|
+
this._opacity = 1;
|
|
41
|
+
}
|
|
42
|
+
/** A value between 0 and 1, presents the cutoff for alpha testing */ get alphaCutoff() {
|
|
43
|
+
return this._alphaCutoff;
|
|
44
|
+
}
|
|
45
|
+
set alphaCutoff(val) {
|
|
46
|
+
if (this._alphaCutoff !== val) {
|
|
47
|
+
this.useFeature(MeshMaterial.FEATURE_ALPHATEST, val > 0);
|
|
48
|
+
this._alphaCutoff = val;
|
|
49
|
+
this.optionChanged(false);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
get alphaToCoverage() {
|
|
53
|
+
return this.featureUsed(MeshMaterial.FEATURE_ALPHATOCOVERAGE, RENDER_PASS_TYPE_FORWARD);
|
|
54
|
+
}
|
|
55
|
+
set alphaToCoverage(val) {
|
|
56
|
+
this.useFeature(MeshMaterial.FEATURE_ALPHATOCOVERAGE, !!val, RENDER_PASS_TYPE_FORWARD);
|
|
57
|
+
}
|
|
58
|
+
/** Blending mode */ get blendMode() {
|
|
59
|
+
return this._blendMode;
|
|
60
|
+
}
|
|
61
|
+
set blendMode(val) {
|
|
62
|
+
if (this._blendMode !== val) {
|
|
63
|
+
this._blendMode = val;
|
|
64
|
+
this.useFeature(MeshMaterial.FEATURE_ALPHABLEND, this._blendMode !== 'none' || this._opacity < 1, RENDER_PASS_TYPE_FORWARD);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** A value between 0 and 1, presents the opacity */ get opacity() {
|
|
68
|
+
return this._opacity;
|
|
69
|
+
}
|
|
70
|
+
set opacity(val) {
|
|
71
|
+
val = val < 0 ? 0 : val > 1 ? 1 : val;
|
|
72
|
+
if (this._opacity !== val) {
|
|
73
|
+
this._opacity = val;
|
|
74
|
+
this.useFeature(MeshMaterial.FEATURE_ALPHABLEND, this._opacity < 1, RENDER_PASS_TYPE_FORWARD);
|
|
75
|
+
this.optionChanged(false);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/** @internal */ updateBlendingState(ctx) {
|
|
79
|
+
const blending = this.featureUsed(MeshMaterial.FEATURE_ALPHABLEND, ctx.renderPass.type);
|
|
80
|
+
const a2c = this.featureUsed(MeshMaterial.FEATURE_ALPHATOCOVERAGE, ctx.renderPass.type);
|
|
81
|
+
if (blending || a2c) {
|
|
82
|
+
const blendingState = this.stateSet.useBlendingState();
|
|
83
|
+
if (blending) {
|
|
84
|
+
blendingState.enable(true);
|
|
85
|
+
if (this._blendMode === 'additive') {
|
|
86
|
+
blendingState.setBlendEquation('add', 'add');
|
|
87
|
+
blendingState.setBlendFunc('one', 'one');
|
|
88
|
+
} else if (this._blendMode === 'max') {
|
|
89
|
+
blendingState.setBlendEquation('max', 'add');
|
|
90
|
+
blendingState.setBlendFuncRGB('one', 'one');
|
|
91
|
+
blendingState.setBlendFuncAlpha('zero', 'one');
|
|
92
|
+
} else if (this._blendMode === 'min') {
|
|
93
|
+
blendingState.setBlendEquation('min', 'add');
|
|
94
|
+
blendingState.setBlendFuncRGB('one', 'one');
|
|
95
|
+
blendingState.setBlendFuncAlpha('zero', 'one');
|
|
96
|
+
} else {
|
|
97
|
+
blendingState.setBlendEquation('add', 'add');
|
|
98
|
+
blendingState.setBlendFunc('one', 'inv-src-alpha');
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
blendingState.enable(false);
|
|
102
|
+
}
|
|
103
|
+
blendingState.enableAlphaToCoverage(a2c);
|
|
104
|
+
} else if (this.stateSet.blendingState?.enabled && !blending) {
|
|
105
|
+
this.stateSet.defaultBlendingState();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
applyUniformValues(bindGroup, ctx) {
|
|
109
|
+
if (this.featureUsed(MeshMaterial.FEATURE_ALPHATEST, ctx.renderPass.type)) {
|
|
110
|
+
bindGroup.setValue('kkAlphaCutoff', this._alphaCutoff);
|
|
111
|
+
}
|
|
112
|
+
if (this.featureUsed(MeshMaterial.FEATURE_ALPHABLEND, ctx.renderPass.type)) {
|
|
113
|
+
bindGroup.setValue('kkOpacity', this._opacity);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/** true if the material is transparency */ isTransparent() {
|
|
117
|
+
return this._blendMode !== 'none' || this._opacity < 1;
|
|
118
|
+
}
|
|
119
|
+
beginDraw(ctx) {
|
|
120
|
+
this.updateBlendingState(ctx);
|
|
121
|
+
return super.beginDraw(ctx);
|
|
122
|
+
}
|
|
123
|
+
/** @internal */ createProgram(ctx) {
|
|
124
|
+
const pb = new ProgramBuilder(Application.instance.device);
|
|
125
|
+
if (ctx.renderPass.type === RENDER_PASS_TYPE_SHADOWMAP) {
|
|
126
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.renderPass.light);
|
|
127
|
+
pb.emulateDepthClamp = !!shadowMapParams.depthClampEnabled;
|
|
128
|
+
}
|
|
129
|
+
return this._createProgram(pb, ctx);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Check if a feature is in use for given render pass type.
|
|
133
|
+
*
|
|
134
|
+
* @param feature - The feature name
|
|
135
|
+
* @param renderPassType - Render pass type
|
|
136
|
+
* @returns true if the feature is in use, otherwise false.
|
|
137
|
+
*/ featureUsed(feature, renderPassType) {
|
|
138
|
+
const index = this._features.get(feature);
|
|
139
|
+
return this._featureStates[renderPassType][index];
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Use or unuse a feature of the material, this will cause the shader to be rebuild.
|
|
143
|
+
*
|
|
144
|
+
* @param feature - Which feature will be used or unused
|
|
145
|
+
* @param use - true if use the feature, otherwise false
|
|
146
|
+
*/ useFeature(feature, use, renderPassType) {
|
|
147
|
+
renderPassType = renderPassType ?? allRenderPassTypes;
|
|
148
|
+
if (typeof renderPassType === 'number') {
|
|
149
|
+
renderPassType = [
|
|
150
|
+
renderPassType
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
let index = this._features.get(feature);
|
|
154
|
+
if (index === void 0) {
|
|
155
|
+
index = this._featureIndex++;
|
|
156
|
+
this._features.set(feature, index);
|
|
157
|
+
}
|
|
158
|
+
let changed = false;
|
|
159
|
+
for (const type of renderPassType){
|
|
160
|
+
if (type !== RENDER_PASS_TYPE_FORWARD && type !== RENDER_PASS_TYPE_SHADOWMAP && type !== RENDER_PASS_TYPE_DEPTH_ONLY) {
|
|
161
|
+
console.error(`useFeature(): invalid render pass type: ${type}`);
|
|
162
|
+
}
|
|
163
|
+
if (this._featureStates[type][index] !== use) {
|
|
164
|
+
this._featureStates[type][index] = use;
|
|
165
|
+
changed = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (changed) {
|
|
169
|
+
this.optionChanged(true);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* {@inheritDoc Material._createHash}
|
|
174
|
+
* @override
|
|
175
|
+
*/ _createHash(renderPassType) {
|
|
176
|
+
return this._featureStates[renderPassType].join('');
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* {@inheritDoc Material._applyUniforms}
|
|
180
|
+
* @override
|
|
181
|
+
*/ _applyUniforms(bindGroup, ctx) {
|
|
182
|
+
this.applyUniformValues(bindGroup, ctx);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Check if the color should be computed in fragment shader, this is required for forward render pass or alpha test is in use or alpha to coverage is in use.
|
|
186
|
+
*
|
|
187
|
+
* @param ctx - The drawing context
|
|
188
|
+
* @returns - true if the color should be computed in fragment shader, otherwise false.
|
|
189
|
+
*/ needFragmentColor(ctx) {
|
|
190
|
+
return ctx.renderPass.type === RENDER_PASS_TYPE_FORWARD || this._alphaCutoff > 0 || this.alphaToCoverage;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Transform vertex position to the clip space and calcuate the world position, world normal and tangent frame if needed
|
|
194
|
+
*
|
|
195
|
+
* @remarks
|
|
196
|
+
* This function handles skin animation and geometry instancing if needed
|
|
197
|
+
*
|
|
198
|
+
* @param scope - Current shader scope
|
|
199
|
+
*/ transformVertexAndNormal(scope) {
|
|
200
|
+
ShaderFramework.ftransform(scope);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Vertex shader implementation of this material
|
|
204
|
+
* @param scope - Shader scope
|
|
205
|
+
* @param ctx - The drawing context
|
|
206
|
+
*/ vertexShader(scope, ctx) {
|
|
207
|
+
const pb = scope.$builder;
|
|
208
|
+
ShaderFramework.prepareVertexShader(pb, ctx);
|
|
209
|
+
if (ctx.target.getBoneMatrices()) {
|
|
210
|
+
scope.$inputs.kkBlendIndices = pb.vec4().attrib('blendIndices');
|
|
211
|
+
scope.$inputs.kkBlendWeights = pb.vec4().attrib('blendWeights');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Fragment shader implementation of this material
|
|
216
|
+
* @param scope - Shader scope
|
|
217
|
+
* @param ctx - The drawing context
|
|
218
|
+
*/ fragmentShader(scope, ctx) {
|
|
219
|
+
const pb = scope.$builder;
|
|
220
|
+
ShaderFramework.prepareFragmentShader(pb, ctx);
|
|
221
|
+
if (this._alphaCutoff > 0) {
|
|
222
|
+
scope.$g.kkAlphaCutoff = pb.float().uniform(2);
|
|
223
|
+
}
|
|
224
|
+
if (ctx.renderPass.type === RENDER_PASS_TYPE_FORWARD) {
|
|
225
|
+
if (this.isTransparent()) {
|
|
226
|
+
scope.$g.kkOpacity = pb.float().uniform(2);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* {@inheritDoc Material._createProgram}
|
|
232
|
+
* @override
|
|
233
|
+
*/ _createProgram(pb, ctx) {
|
|
234
|
+
const that = this;
|
|
235
|
+
const program = pb.buildRenderProgram({
|
|
236
|
+
vertex (pb) {
|
|
237
|
+
pb.main(function() {
|
|
238
|
+
that.vertexShader(this, ctx);
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
fragment (pb) {
|
|
242
|
+
this.$outputs.zFragmentOutput = pb.vec4();
|
|
243
|
+
pb.main(function() {
|
|
244
|
+
that.fragmentShader(this, ctx);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
return program;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Calculate final fragment color for output.
|
|
252
|
+
*
|
|
253
|
+
* @param scope - Shader scope
|
|
254
|
+
* @param color - Lit fragment color
|
|
255
|
+
* @param ctx - The drawing context
|
|
256
|
+
*
|
|
257
|
+
* @returns The final fragment color
|
|
258
|
+
*/ outputFragmentColor(scope, color, ctx) {
|
|
259
|
+
const pb = scope.$builder;
|
|
260
|
+
const that = this;
|
|
261
|
+
pb.func('zOutputFragmentColor', color ? [
|
|
262
|
+
pb.vec4('color')
|
|
263
|
+
] : [], function() {
|
|
264
|
+
this.$l.outColor = color ? this.color : pb.vec4();
|
|
265
|
+
if (ctx.renderPass.type === RENDER_PASS_TYPE_FORWARD) {
|
|
266
|
+
ShaderFramework.discardIfClipped(this);
|
|
267
|
+
if (!that.isTransparent() && !this.kkAlphaCutoff && !that.alphaToCoverage) {
|
|
268
|
+
this.outColor.a = 1;
|
|
269
|
+
} else if (this.kkOpacity) {
|
|
270
|
+
this.outColor.a = pb.mul(this.outColor.a, this.kkOpacity);
|
|
271
|
+
}
|
|
272
|
+
if (this.kkAlphaCutoff) {
|
|
273
|
+
this.$if(pb.lessThan(this.outColor.a, this.kkAlphaCutoff), function() {
|
|
274
|
+
pb.discard();
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
if (that.isTransparent()) {
|
|
278
|
+
this.outColor = pb.vec4(pb.mul(this.outColor.rgb, this.outColor.a), this.outColor.a);
|
|
279
|
+
}
|
|
280
|
+
ShaderFramework.applyFog(this, this.outColor, ctx);
|
|
281
|
+
this.$outputs.zFragmentOutput = encodeColorOutput(this, this.outColor);
|
|
282
|
+
} else if (ctx.renderPass.type === RENDER_PASS_TYPE_DEPTH_ONLY) {
|
|
283
|
+
if (color) {
|
|
284
|
+
this.$if(pb.lessThan(this.outColor.a, this.kkAlphaCutoff), function() {
|
|
285
|
+
pb.discard();
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
ShaderFramework.discardIfClipped(this);
|
|
289
|
+
this.$l.kkDepth = nonLinearDepthToLinearNormalized(this, this.$builtins.fragCoord.z);
|
|
290
|
+
if (Application.instance.device.type === 'webgl') {
|
|
291
|
+
this.$outputs.zFragmentOutput = encodeNormalizedFloatToRGBA(this, this.kkDepth);
|
|
292
|
+
} else {
|
|
293
|
+
this.$outputs.zFragmentOutput = pb.vec4(this.kkDepth, 0, 0, 1);
|
|
294
|
+
}
|
|
295
|
+
} else /*if (ctx.renderPass.type === RENDER_PASS_TYPE_SHADOWMAP)*/ {
|
|
296
|
+
if (color) {
|
|
297
|
+
this.$if(pb.lessThan(this.outColor.a, this.kkAlphaCutoff), function() {
|
|
298
|
+
pb.discard();
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
ShaderFramework.discardIfClipped(this);
|
|
302
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.renderPass.light);
|
|
303
|
+
this.$outputs.zFragmentOutput = shadowMapParams.impl.computeShadowMapDepth(shadowMapParams, this);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
color ? pb.getGlobalScope().zOutputFragmentColor(color) : pb.getGlobalScope().zOutputFragmentColor();
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export { MeshMaterial, applyMaterialMixins };
|
|
311
|
+
//# sourceMappingURL=meshmaterial.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meshmaterial.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Vector4 } from '@zephyr3d/base';
|
|
2
|
+
|
|
3
|
+
function mixinAlbedoColor(BaseCls) {
|
|
4
|
+
if (BaseCls.albedoColorMixed) {
|
|
5
|
+
return BaseCls;
|
|
6
|
+
}
|
|
7
|
+
const FEATURE_ALBEDO_MAP = 'z-feature-albedo-map';
|
|
8
|
+
const FEATURE_ALBEDO_TEXCOORD_INDEX = 'z-feature-albedo-texcoord-index';
|
|
9
|
+
const FEATURE_ALBEDO_TEXCOORD_MATRIX = 'z-feature-albedo-texcoord-matrix';
|
|
10
|
+
return class extends BaseCls {
|
|
11
|
+
static albedoColorMixed = true;
|
|
12
|
+
_albedoColor;
|
|
13
|
+
_albedoTexture;
|
|
14
|
+
_albedoSampler;
|
|
15
|
+
_albedoTexCoordIndex;
|
|
16
|
+
_albedoTexCoordMatrix;
|
|
17
|
+
constructor(...args){
|
|
18
|
+
super(...args);
|
|
19
|
+
this._albedoColor = Vector4.one();
|
|
20
|
+
this._albedoTexture = null;
|
|
21
|
+
this._albedoSampler = null;
|
|
22
|
+
this._albedoTexCoordIndex = 0;
|
|
23
|
+
this._albedoTexCoordMatrix = null;
|
|
24
|
+
}
|
|
25
|
+
/** Albedo color */ get albedoColor() {
|
|
26
|
+
return this._albedoColor;
|
|
27
|
+
}
|
|
28
|
+
set albedoColor(val) {
|
|
29
|
+
this._albedoColor.set(val);
|
|
30
|
+
this.optionChanged(false);
|
|
31
|
+
}
|
|
32
|
+
/** Albedo texture coordinate index */ get albedoTexCoordIndex() {
|
|
33
|
+
return this._albedoTexCoordIndex;
|
|
34
|
+
}
|
|
35
|
+
set albedoTexCoordIndex(val) {
|
|
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
|
+
}
|
|
79
|
+
const pb = scope.$builder;
|
|
80
|
+
let color = scope.kkAlbedo;
|
|
81
|
+
if (this.featureUsed(FEATURE_ALBEDO_MAP, ctx.renderPass.type)) {
|
|
82
|
+
color = pb.mul(color, pb.textureSample(scope.kkAlbedoTex, scope.$inputs.kkAlbedoTexCoord));
|
|
83
|
+
}
|
|
84
|
+
return color;
|
|
85
|
+
}
|
|
86
|
+
vertexShader(scope, ctx) {
|
|
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
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
fragmentShader(scope, ctx) {
|
|
105
|
+
super.fragmentShader(scope, ctx);
|
|
106
|
+
if (this.needFragmentColor(ctx)) {
|
|
107
|
+
const pb = scope.$builder;
|
|
108
|
+
scope.$g.kkAlbedo = pb.vec4().uniform(2);
|
|
109
|
+
if (this.featureUsed(FEATURE_ALBEDO_MAP, ctx.renderPass.type)) {
|
|
110
|
+
scope.$g.kkAlbedoTex = pb.tex2D().uniform(2);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
applyUniformValues(bindGroup, ctx) {
|
|
115
|
+
super.applyUniformValues(bindGroup, ctx);
|
|
116
|
+
if (this.needFragmentColor(ctx)) {
|
|
117
|
+
bindGroup.setValue('kkAlbedo', this._albedoColor);
|
|
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
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { mixinAlbedoColor };
|
|
130
|
+
//# sourceMappingURL=albedocolor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"albedocolor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
function mixinTextureProps(name) {
|
|
2
|
+
return function(BaseCls) {
|
|
3
|
+
const capName = `${name[0].toUpperCase()}${name.slice(1)}`;
|
|
4
|
+
const upperName = name.toUpperCase();
|
|
5
|
+
const id = `mixinTexture${capName}`;
|
|
6
|
+
const feature = `FEATURE_TEXTURE_${upperName}`;
|
|
7
|
+
const featureTexIndex = `FEATURE_TEXTURE_TEXCOORD_INDEX_${upperName}`;
|
|
8
|
+
const featureTexMatrix = `FEATURE_TEXTURE_TEXCOORD_MATRIX_${upperName}`;
|
|
9
|
+
if (BaseCls[id]) {
|
|
10
|
+
return BaseCls;
|
|
11
|
+
}
|
|
12
|
+
const cls = class extends BaseCls {
|
|
13
|
+
constructor(...args){
|
|
14
|
+
super(...args);
|
|
15
|
+
let textureValue = null;
|
|
16
|
+
let textureSampler = null;
|
|
17
|
+
let textureCoordIndex = 0;
|
|
18
|
+
let textureCoordMatrix = null;
|
|
19
|
+
this[`get${capName}TextureUniform`] = function(scope) {
|
|
20
|
+
return scope.$builder.shaderKind === 'fragment' ? scope[`kk${capName}Tex`] : null;
|
|
21
|
+
};
|
|
22
|
+
this[`get${capName}TexCoord`] = function(scope) {
|
|
23
|
+
return scope.$builder.shaderKind === 'fragment' ? scope[`kk${capName}TexCoord`] : scope.$outputs[`kk${capName}TexCoord`];
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(this, `${name}Texture`, {
|
|
26
|
+
get: ()=>textureValue,
|
|
27
|
+
set: (newValue)=>{
|
|
28
|
+
if (textureValue !== newValue) {
|
|
29
|
+
textureValue = newValue ?? null;
|
|
30
|
+
this.useFeature(feature, !!textureValue);
|
|
31
|
+
if (textureValue) {
|
|
32
|
+
this.useFeature(featureTexIndex, textureCoordIndex);
|
|
33
|
+
this.useFeature(featureTexMatrix, !!textureCoordMatrix);
|
|
34
|
+
this.optionChanged(false);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
textureValue = newValue;
|
|
38
|
+
},
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(this, `${name}TextureSampler`, {
|
|
43
|
+
get: ()=>textureSampler,
|
|
44
|
+
set: (newValue)=>null,
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(this, `${name}TexCoordIndex`, {
|
|
49
|
+
get: ()=>textureCoordMatrix,
|
|
50
|
+
set: (newValue)=>{
|
|
51
|
+
if (textureCoordMatrix !== newValue) {
|
|
52
|
+
textureCoordMatrix = newValue;
|
|
53
|
+
if (textureValue) {
|
|
54
|
+
this.useFeature(featureTexMatrix, !!textureCoordMatrix);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(this, `${name}TexCoordMatrix`, {
|
|
62
|
+
get: ()=>textureCoordIndex,
|
|
63
|
+
set: (newValue)=>{
|
|
64
|
+
if (textureCoordIndex !== newValue) {
|
|
65
|
+
textureCoordIndex = newValue;
|
|
66
|
+
if (textureValue) {
|
|
67
|
+
this.useFeature(featureTexIndex, textureCoordIndex);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
vertexShader(scope, ctx) {
|
|
76
|
+
super.vertexShader(scope, ctx);
|
|
77
|
+
if (this.needFragmentColor(ctx)) {
|
|
78
|
+
const pb = scope.$builder;
|
|
79
|
+
if (this.featureUsed(feature, ctx.renderPass.type)) {
|
|
80
|
+
const semantic = `texCoord${this[`${name}TexCoordIndex`]}`;
|
|
81
|
+
if (!scope.$getVertexAttrib(semantic)) {
|
|
82
|
+
scope.$inputs[semantic] = pb.vec2().attrib(semantic);
|
|
83
|
+
}
|
|
84
|
+
if (this.featureUsed(featureTexMatrix, ctx.renderPass.type)) {
|
|
85
|
+
scope.$g[`kk${capName}TextureMatrix`] = pb.mat4().uniform(2);
|
|
86
|
+
scope.$outputs[`kk${capName}TexCoord`] = pb.mul(scope[`kk${capName}TextureMatrix`], pb.vec4(scope.$inputs[semantic], 0, 1)).xy;
|
|
87
|
+
} else {
|
|
88
|
+
scope.$outputs[`kk${capName}TexCoord`] = scope.$inputs[semantic];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
fragmentShader(scope, ctx) {
|
|
94
|
+
super.fragmentShader(scope, ctx);
|
|
95
|
+
if (this.needFragmentColor(ctx)) {
|
|
96
|
+
const pb = scope.$builder;
|
|
97
|
+
if (this.featureUsed(feature, ctx.renderPass.type)) {
|
|
98
|
+
scope.$g[`kk${capName}Tex`] = pb.tex2D().uniform(2);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
cls[id] = true;
|
|
104
|
+
cls[`FEATURE_TEXTURE_${upperName}`] = feature;
|
|
105
|
+
return cls;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { mixinTextureProps };
|
|
110
|
+
//# sourceMappingURL=texture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"texture.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { RENDER_PASS_TYPE_FORWARD } from '../../values.js';
|
|
2
|
+
|
|
3
|
+
function mixinVertexColor(BaseCls) {
|
|
4
|
+
if (BaseCls.vertexColorMixed) {
|
|
5
|
+
return BaseCls;
|
|
6
|
+
}
|
|
7
|
+
const FEATURE_VERTEX_COLOR = 'z-feature-vertex-color';
|
|
8
|
+
return class extends BaseCls {
|
|
9
|
+
static vertexColorMixed = true;
|
|
10
|
+
constructor(...args){
|
|
11
|
+
super(...args);
|
|
12
|
+
}
|
|
13
|
+
/** Albedo color */ get vertexColor() {
|
|
14
|
+
return this.featureUsed(FEATURE_VERTEX_COLOR, RENDER_PASS_TYPE_FORWARD);
|
|
15
|
+
}
|
|
16
|
+
set vertexColor(val) {
|
|
17
|
+
this.useFeature(FEATURE_VERTEX_COLOR, !!val);
|
|
18
|
+
}
|
|
19
|
+
vertexShader(scope, ctx) {
|
|
20
|
+
super.vertexShader(scope, ctx);
|
|
21
|
+
if (this.needFragmentColor(ctx)) {
|
|
22
|
+
if (this.vertexColor) {
|
|
23
|
+
if (scope.$getVertexAttrib('diffuse')) {
|
|
24
|
+
throw new Error('mixinVertexColor.vertexShader(): diffuse vertex stream already defined');
|
|
25
|
+
}
|
|
26
|
+
scope.$inputs.zDiffuse = scope.$builder.vec4().attrib('diffuse');
|
|
27
|
+
scope.$outputs.zOutDiffuse = scope.$inputs.zDiffuse;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getVertexColor(scope, ctx) {
|
|
32
|
+
if (!this.needFragmentColor(ctx)) {
|
|
33
|
+
throw new Error('mixinVertexColor.getVertexColor(): No need to calculate albedo color, make sure needFragmentColor() returns true');
|
|
34
|
+
}
|
|
35
|
+
if (scope.$builder.shaderKind === 'fragment') {
|
|
36
|
+
return scope.$inputs.zOutDiffuse;
|
|
37
|
+
} else {
|
|
38
|
+
return scope.$inputs.zDiffuse;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { mixinVertexColor };
|
|
45
|
+
//# sourceMappingURL=vertexcolor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vertexcolor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StandardMaterial } from './standard.js';
|
|
2
|
+
import { PBRLightModelMR, PBRLightModelSG } from './lightmodel.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* PBR material for metallic-roughenss work flow
|
|
6
|
+
* @public
|
|
7
|
+
*/ class PBRMetallicRoughnessMaterial extends StandardMaterial {
|
|
8
|
+
constructor(){
|
|
9
|
+
super();
|
|
10
|
+
this.lightModel = new PBRLightModelMR();
|
|
11
|
+
}
|
|
12
|
+
get GGXLUT() {
|
|
13
|
+
return PBRLightModelMR.getGGXLUT();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* PBR material for specular-glossness workflow
|
|
18
|
+
* @public
|
|
19
|
+
*/ class PBRSpecularGlossinessMaterial extends StandardMaterial {
|
|
20
|
+
constructor(){
|
|
21
|
+
super();
|
|
22
|
+
this.lightModel = new PBRLightModelSG();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { PBRMetallicRoughnessMaterial, PBRSpecularGlossinessMaterial };
|
|
27
|
+
//# sourceMappingURL=pbr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbr.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|