@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 @@
|
|
|
1
|
+
{"version":3,"file":"lightmodel.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,578 @@
|
|
|
1
|
+
import { RENDER_PASS_TYPE_FORWARD, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
|
|
2
|
+
import { ShaderFramework } from '../shaders/framework.js';
|
|
3
|
+
import { nonLinearDepthToLinear } from '../shaders/misc.js';
|
|
4
|
+
import { Application } from '../app.js';
|
|
5
|
+
import { MeshMaterial } from './meshmaterial.js';
|
|
6
|
+
|
|
7
|
+
class LitMaterial extends MeshMaterial {
|
|
8
|
+
static FEATURE_DOUBLE_SIDED_LIGHTING = 'lm_doublesided_lighting';
|
|
9
|
+
static FEATURE_VERTEX_NORMAL = 'lm_vertexnormal';
|
|
10
|
+
static FEATURE_VERTEX_TANGENT = 'lm_vertextangent';
|
|
11
|
+
static FEATURE_NORMAL_TEXTURE = 'lm_normaltexture';
|
|
12
|
+
static FEATURE_NORMAL_TEXCOORD_INDEX = 'lm_normaltexcoord';
|
|
13
|
+
static FEATURE_NORMAL_TEXTURE_MATRIX = 'lm_normal_texture_matrix';
|
|
14
|
+
static FEATURE_OBJECT_SPACE_NORMALMAP = 'lm_objectspace_normalmap';
|
|
15
|
+
_normalTexture;
|
|
16
|
+
_normalSampler;
|
|
17
|
+
_normalTexCoordIndex;
|
|
18
|
+
_normalTexCoordMatrix;
|
|
19
|
+
_normalScale;
|
|
20
|
+
constructor(){
|
|
21
|
+
super();
|
|
22
|
+
this._normalTexture = null;
|
|
23
|
+
this._normalSampler = null;
|
|
24
|
+
this._normalTexCoordIndex = 0;
|
|
25
|
+
this._normalTexCoordMatrix = null;
|
|
26
|
+
this._normalScale = 1;
|
|
27
|
+
this.useFeature(LitMaterial.FEATURE_VERTEX_NORMAL, true);
|
|
28
|
+
}
|
|
29
|
+
get normalScale() {
|
|
30
|
+
return this._normalScale;
|
|
31
|
+
}
|
|
32
|
+
set normalScale(val) {
|
|
33
|
+
if (val !== this._normalScale) {
|
|
34
|
+
this._normalScale = val;
|
|
35
|
+
this.optionChanged(false);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
get normalMapMode() {
|
|
39
|
+
return this.featureUsed(LitMaterial.FEATURE_OBJECT_SPACE_NORMALMAP, RENDER_PASS_TYPE_FORWARD);
|
|
40
|
+
}
|
|
41
|
+
set normalMapMode(val) {
|
|
42
|
+
this.useFeature(LitMaterial.FEATURE_OBJECT_SPACE_NORMALMAP, val, RENDER_PASS_TYPE_FORWARD);
|
|
43
|
+
}
|
|
44
|
+
/** true if double sided lighting is used */ get doubleSidedLighting() {
|
|
45
|
+
return this.featureUsed(LitMaterial.FEATURE_DOUBLE_SIDED_LIGHTING, RENDER_PASS_TYPE_FORWARD);
|
|
46
|
+
}
|
|
47
|
+
set doubleSidedLighting(val) {
|
|
48
|
+
this.useFeature(LitMaterial.FEATURE_DOUBLE_SIDED_LIGHTING, !!val, RENDER_PASS_TYPE_FORWARD);
|
|
49
|
+
}
|
|
50
|
+
/** true if vertex normal attribute presents */ get vertexNormal() {
|
|
51
|
+
return this.featureUsed(LitMaterial.FEATURE_VERTEX_NORMAL, RENDER_PASS_TYPE_FORWARD);
|
|
52
|
+
}
|
|
53
|
+
set vertexNormal(val) {
|
|
54
|
+
this.useFeature(LitMaterial.FEATURE_VERTEX_NORMAL, !!val);
|
|
55
|
+
}
|
|
56
|
+
/** true if vertex normal attribute presents */ get vertexTangent() {
|
|
57
|
+
return this.featureUsed(LitMaterial.FEATURE_VERTEX_TANGENT, RENDER_PASS_TYPE_FORWARD);
|
|
58
|
+
}
|
|
59
|
+
set vertexTangent(val) {
|
|
60
|
+
this.useFeature(LitMaterial.FEATURE_VERTEX_TANGENT, !!val);
|
|
61
|
+
}
|
|
62
|
+
/** Normal texture */ get normalTexture() {
|
|
63
|
+
return this._normalTexture;
|
|
64
|
+
}
|
|
65
|
+
set normalTexture(tex) {
|
|
66
|
+
if (this._normalTexture !== tex) {
|
|
67
|
+
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXTURE, !!tex);
|
|
68
|
+
if (tex) {
|
|
69
|
+
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXCOORD_INDEX, this._normalTexCoordIndex);
|
|
70
|
+
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXTURE_MATRIX, !!this._normalTexCoordMatrix);
|
|
71
|
+
}
|
|
72
|
+
this._normalTexture = tex ?? null;
|
|
73
|
+
this.optionChanged(false);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Normal texture sampler */ get normalTextureSampler() {
|
|
77
|
+
return this._normalSampler;
|
|
78
|
+
}
|
|
79
|
+
set normalTextureSampler(sampler) {
|
|
80
|
+
this._normalSampler = sampler ?? null;
|
|
81
|
+
}
|
|
82
|
+
/** Normal texture coordinate index */ get normalTexCoordIndex() {
|
|
83
|
+
return this._normalTexCoordIndex;
|
|
84
|
+
}
|
|
85
|
+
set normalTexCoordIndex(val) {
|
|
86
|
+
if (val !== this._normalTexCoordIndex) {
|
|
87
|
+
this._normalTexCoordIndex = val;
|
|
88
|
+
if (this._normalTexture) {
|
|
89
|
+
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXCOORD_INDEX, this._normalTexCoordIndex);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/** Normal texture coordinate transform matrix */ get normalTexMatrix() {
|
|
94
|
+
return this._normalTexCoordMatrix;
|
|
95
|
+
}
|
|
96
|
+
set normalTexMatrix(val) {
|
|
97
|
+
if (val !== this._normalTexCoordMatrix) {
|
|
98
|
+
this._normalTexCoordMatrix = val;
|
|
99
|
+
if (this._normalTexture) {
|
|
100
|
+
this.useFeature(LitMaterial.FEATURE_NORMAL_TEXTURE_MATRIX, !!this._normalTexCoordMatrix);
|
|
101
|
+
}
|
|
102
|
+
this.optionChanged(false);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Calculates the normalized vector from world coordinates to the viewpoint.
|
|
107
|
+
*
|
|
108
|
+
* @param scope - Shader scope
|
|
109
|
+
* @returns The view vector
|
|
110
|
+
*/ calculateViewVector(scope) {
|
|
111
|
+
const pb = scope.$builder;
|
|
112
|
+
return pb.normalize(pb.sub(ShaderFramework.getCameraPosition(scope), ShaderFramework.getWorldPosition(scope).xyz));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Calculate the reflection vector of the view vector with respect to the normal.
|
|
116
|
+
*
|
|
117
|
+
* @param scope - Shader scope
|
|
118
|
+
* @param normal - Surface normal
|
|
119
|
+
* @param viewVec - The view vector
|
|
120
|
+
* @returns The reflection vector
|
|
121
|
+
*/ calculateReflectionVector(scope, normal, viewVec) {
|
|
122
|
+
const pb = scope.$builder;
|
|
123
|
+
return pb.reflect(pb.neg(viewVec), normal);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Calculate the normal vector for current fragment
|
|
127
|
+
* @param scope - The shader scope
|
|
128
|
+
* @param ctx - The drawing context
|
|
129
|
+
* @returns Normal vector for current fragment
|
|
130
|
+
*/ calculateNormal(scope, ctx) {
|
|
131
|
+
const pb = scope.$builder;
|
|
132
|
+
const that = this;
|
|
133
|
+
const args = [];
|
|
134
|
+
const params = [];
|
|
135
|
+
const worldNormal = ShaderFramework.getWorldNormal(scope);
|
|
136
|
+
const worldTangent = ShaderFramework.getWorldTangent(scope);
|
|
137
|
+
const worldBinormal = ShaderFramework.getWorldBinormal(scope);
|
|
138
|
+
if (worldNormal) {
|
|
139
|
+
params.push(pb.vec3('worldNormal'));
|
|
140
|
+
args.push(worldNormal);
|
|
141
|
+
if (worldTangent) {
|
|
142
|
+
params.push(pb.vec3('worldTangent'), pb.vec3('worldBinormal'));
|
|
143
|
+
args.push(worldTangent, worldBinormal);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
pb.func('kkCalculateNormal', params, function() {
|
|
147
|
+
const posW = ShaderFramework.getWorldPosition(this).xyz;
|
|
148
|
+
this.$l.uv = that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type) ? scope.$inputs.kkNormalTexCoord ?? pb.vec2(0) : that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type) ? scope.$inputs.kkAlbedoTexCoord ?? pb.vec2(0) : pb.vec2(0);
|
|
149
|
+
this.$l.TBN = pb.mat3();
|
|
150
|
+
if (!worldNormal) {
|
|
151
|
+
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
152
|
+
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
153
|
+
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
154
|
+
this.uv_dx = pb.vec3(1, 0, 0);
|
|
155
|
+
this.uv_dy = pb.vec3(0, 1, 0);
|
|
156
|
+
});
|
|
157
|
+
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(posW), this.uv_dy.y), pb.mul(pb.dpdy(posW), this.uv_dx.y)), pb.sub(pb.mul(this.uv_dx.x, this.uv_dy.y), pb.mul(this.uv_dx.y, this.uv_dy.x)));
|
|
158
|
+
this.$l.ng = pb.normalize(pb.cross(pb.dpdx(posW), pb.dpdy(posW)));
|
|
159
|
+
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
160
|
+
this.$l.b = pb.cross(this.ng, this.t);
|
|
161
|
+
if (that.doubleSidedLighting) {
|
|
162
|
+
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
163
|
+
this.t = pb.mul(this.t, -1);
|
|
164
|
+
this.b = pb.mul(this.b, -1);
|
|
165
|
+
this.ng = pb.mul(this.ng, -1);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
this.TBN = pb.mat3(this.t, this.b, this.ng);
|
|
169
|
+
} else if (!worldTangent) {
|
|
170
|
+
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
171
|
+
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
172
|
+
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
173
|
+
this.uv_dx = pb.vec3(1, 0, 0);
|
|
174
|
+
this.uv_dy = pb.vec3(0, 1, 0);
|
|
175
|
+
});
|
|
176
|
+
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(posW), this.uv_dy.y), pb.mul(pb.dpdy(posW), this.uv_dx.y)), pb.sub(pb.mul(this.uv_dx.x, this.uv_dy.y), pb.mul(this.uv_dx.y, this.uv_dy.x)));
|
|
177
|
+
this.$l.ng = pb.normalize(this.worldNormal);
|
|
178
|
+
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
179
|
+
this.$l.b = pb.cross(this.ng, this.t);
|
|
180
|
+
if (that.doubleSidedLighting) {
|
|
181
|
+
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
182
|
+
this.t = pb.mul(this.t, -1);
|
|
183
|
+
this.b = pb.mul(this.b, -1);
|
|
184
|
+
this.ng = pb.mul(this.ng, -1);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
this.TBN = pb.mat3(this.t, this.b, this.ng);
|
|
188
|
+
} else {
|
|
189
|
+
this.TBN = pb.mat3(pb.normalize(this.worldTangent), pb.normalize(this.worldBinormal), pb.normalize(this.worldNormal));
|
|
190
|
+
}
|
|
191
|
+
if (that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type)) {
|
|
192
|
+
if (that.normalMapMode === 'object-space') {
|
|
193
|
+
const pixel = pb.sub(pb.mul(pb.textureSample(this.kkNormalTexture, this.uv).rgb, 2), pb.vec3(1));
|
|
194
|
+
const normalTex = pb.mul(pixel, pb.vec3(pb.vec3(this.kkNormalScale).xx, 1));
|
|
195
|
+
this.$return(pb.normalize(normalTex));
|
|
196
|
+
} else {
|
|
197
|
+
const pixel = pb.sub(pb.mul(pb.textureSample(this.kkNormalTexture, this.uv).rgb, 2), pb.vec3(1));
|
|
198
|
+
const normalTex = pb.mul(pixel, pb.vec3(pb.vec3(this.kkNormalScale).xx, 1));
|
|
199
|
+
this.$return(pb.normalize(pb.mul(this.TBN, normalTex)));
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
this.$return(this.TBN[2]);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return pb.getGlobalScope().kkCalculateNormal(...args);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Calculate the normal vector for current fragment
|
|
209
|
+
* @param scope - The shader scope
|
|
210
|
+
* @param ctx - The drawing context
|
|
211
|
+
* @returns Structure that contains normal vector and TBN matrix
|
|
212
|
+
*/ calculateNormalAndTBN(scope, ctx) {
|
|
213
|
+
const pb = scope.$builder;
|
|
214
|
+
const NormalStruct = pb.defineStruct([
|
|
215
|
+
pb.mat3('TBN'),
|
|
216
|
+
pb.vec3('normal')
|
|
217
|
+
]);
|
|
218
|
+
const that = this;
|
|
219
|
+
const args = [];
|
|
220
|
+
const params = [];
|
|
221
|
+
const worldNormal = ShaderFramework.getWorldNormal(scope);
|
|
222
|
+
const worldTangent = ShaderFramework.getWorldTangent(scope);
|
|
223
|
+
const worldBinormal = ShaderFramework.getWorldBinormal(scope);
|
|
224
|
+
if (worldNormal) {
|
|
225
|
+
params.push(pb.vec3('worldNormal'));
|
|
226
|
+
args.push(worldNormal);
|
|
227
|
+
if (worldTangent) {
|
|
228
|
+
params.push(pb.vec3('worldTangent'), pb.vec3('worldBinormal'));
|
|
229
|
+
args.push(worldTangent, worldBinormal);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
pb.func('kkCalculateNormalAndTBN', params, function() {
|
|
233
|
+
const posW = ShaderFramework.getWorldPosition(this).xyz;
|
|
234
|
+
this.$l.uv = that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type) ? scope.$inputs.kkNormalTexCoord ?? pb.vec2(0) : that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type) ? scope.$inputs.kkAlbedoTexCoord ?? pb.vec2(0) : pb.vec2(0);
|
|
235
|
+
this.$l.TBN = pb.mat3();
|
|
236
|
+
if (!worldNormal) {
|
|
237
|
+
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
238
|
+
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
239
|
+
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
240
|
+
this.uv_dx = pb.vec3(1, 0, 0);
|
|
241
|
+
this.uv_dy = pb.vec3(0, 1, 0);
|
|
242
|
+
});
|
|
243
|
+
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(posW), this.uv_dy.y), pb.mul(pb.dpdy(posW), this.uv_dx.y)), pb.sub(pb.mul(this.uv_dx.x, this.uv_dy.y), pb.mul(this.uv_dx.y, this.uv_dy.x)));
|
|
244
|
+
this.$l.ng = pb.normalize(pb.cross(pb.dpdx(posW), pb.dpdy(posW)));
|
|
245
|
+
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
246
|
+
this.$l.b = pb.cross(this.ng, this.t);
|
|
247
|
+
if (that.doubleSidedLighting) {
|
|
248
|
+
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
249
|
+
this.t = pb.mul(this.t, -1);
|
|
250
|
+
this.b = pb.mul(this.b, -1);
|
|
251
|
+
this.ng = pb.mul(this.ng, -1);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
this.TBN = pb.mat3(this.t, this.b, this.ng);
|
|
255
|
+
} else if (!worldTangent) {
|
|
256
|
+
this.$l.uv_dx = pb.dpdx(pb.vec3(this.uv, 0));
|
|
257
|
+
this.$l.uv_dy = pb.dpdy(pb.vec3(this.uv, 0));
|
|
258
|
+
this.$if(pb.lessThanEqual(pb.add(pb.length(this.uv_dx), pb.length(this.uv_dy)), 0.000001), function() {
|
|
259
|
+
this.uv_dx = pb.vec3(1, 0, 0);
|
|
260
|
+
this.uv_dy = pb.vec3(0, 1, 0);
|
|
261
|
+
});
|
|
262
|
+
this.$l.t_ = pb.div(pb.sub(pb.mul(pb.dpdx(posW), this.uv_dy.y), pb.mul(pb.dpdy(posW), this.uv_dx.y)), pb.sub(pb.mul(this.uv_dx.x, this.uv_dy.y), pb.mul(this.uv_dx.y, this.uv_dy.x)));
|
|
263
|
+
this.$l.ng = pb.normalize(this.worldNormal);
|
|
264
|
+
this.$l.t = pb.normalize(pb.sub(this.t_, pb.mul(this.ng, pb.dot(this.ng, this.t_))));
|
|
265
|
+
this.$l.b = pb.cross(this.ng, this.t);
|
|
266
|
+
if (that.doubleSidedLighting) {
|
|
267
|
+
this.$if(pb.not(this.$builtins.frontFacing), function() {
|
|
268
|
+
this.t = pb.mul(this.t, -1);
|
|
269
|
+
this.b = pb.mul(this.b, -1);
|
|
270
|
+
this.ng = pb.mul(this.ng, -1);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
this.TBN = pb.mat3(this.t, this.b, this.ng);
|
|
274
|
+
} else {
|
|
275
|
+
this.TBN = pb.mat3(pb.normalize(this.worldTangent), pb.normalize(this.worldBinormal), pb.normalize(this.worldNormal));
|
|
276
|
+
}
|
|
277
|
+
if (that.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type)) {
|
|
278
|
+
if (that.normalMapMode === 'object-space') {
|
|
279
|
+
const pixel = pb.sub(pb.mul(pb.textureSample(this.kkNormalTexture, this.uv).rgb, 2), pb.vec3(1));
|
|
280
|
+
const normalTex = pb.mul(pixel, pb.vec3(pb.vec3(this.kkNormalScale).xx, 1));
|
|
281
|
+
this.$return(NormalStruct(this.TBN, pb.normalize(normalTex)));
|
|
282
|
+
} else {
|
|
283
|
+
const pixel = pb.sub(pb.mul(pb.textureSample(this.kkNormalTexture, this.uv).rgb, 2), pb.vec3(1));
|
|
284
|
+
const normalTex = pb.mul(pixel, pb.vec3(pb.vec3(this.kkNormalScale).xx, 1));
|
|
285
|
+
this.$return(NormalStruct(this.TBN, pb.normalize(pb.mul(this.TBN, normalTex))));
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
this.$return(NormalStruct(this.TBN, this.TBN[2]));
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
return pb.getGlobalScope().kkCalculateNormalAndTBN(...args);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* {@inheritDoc MeshMaterial.applyUniformsValues}
|
|
295
|
+
* @override
|
|
296
|
+
*/ applyUniformValues(bindGroup, ctx) {
|
|
297
|
+
super.applyUniformValues(bindGroup, ctx);
|
|
298
|
+
if (this.needFragmentColor(ctx)) {
|
|
299
|
+
if (this.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type)) {
|
|
300
|
+
bindGroup.setValue('kkNormalScale', this._normalScale);
|
|
301
|
+
bindGroup.setTexture('kkNormalTexture', this._normalTexture, this._normalSampler);
|
|
302
|
+
if (this.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE_MATRIX, ctx.renderPass.type)) {
|
|
303
|
+
bindGroup.setValue('kkNormalTextureMatrix', this._normalTexCoordMatrix);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Check if the environment lighting should be calculated.
|
|
310
|
+
*
|
|
311
|
+
* @param ctx - Draw context
|
|
312
|
+
* @returns true Environment lighting should be calculated, otherwise false
|
|
313
|
+
*/ needCalculateEnvLight(ctx) {
|
|
314
|
+
return ctx.drawEnvLight;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get irradiance of current environment light
|
|
318
|
+
*
|
|
319
|
+
* @param scope - Shader scope
|
|
320
|
+
* @param normal - Fragment normal vector
|
|
321
|
+
* @param ctx - The drawing context
|
|
322
|
+
*
|
|
323
|
+
* @returns Irradiance of current environment light of type vec3
|
|
324
|
+
*/ getEnvLightIrradiance(scope, normal, ctx) {
|
|
325
|
+
if (!this.needCalculateEnvLight) {
|
|
326
|
+
console.warn('getEnvLightIrradiance(): No need to calculate environment lighting');
|
|
327
|
+
return scope.$builder.vec3(0);
|
|
328
|
+
}
|
|
329
|
+
return ctx.env.light.envLight.hasIrradiance() ? scope.$builder.mul(ctx.env.light.envLight.getIrradiance(scope, normal).rgb, ShaderFramework.getEnvLightStrength(scope)) : scope.$builder.vec3(0);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Get Radiance of current environment light
|
|
333
|
+
*
|
|
334
|
+
* @param scope - Shader scope
|
|
335
|
+
* @param reflectVec - The reflection vector
|
|
336
|
+
* @param roughness - Roughness value of current fragment
|
|
337
|
+
* @param ctx - The drawing context
|
|
338
|
+
*
|
|
339
|
+
* @returns Radiance of current environment light of type vec3
|
|
340
|
+
*/ getEnvLightRadiance(scope, reflectVec, roughness, ctx) {
|
|
341
|
+
if (!this.needCalculateEnvLight) {
|
|
342
|
+
console.warn('getEnvLightRadiance(): No need to calculate environment lighting');
|
|
343
|
+
return scope.$builder.vec3(0);
|
|
344
|
+
}
|
|
345
|
+
return ctx.env.light.envLight.hasRadiance() ? scope.$builder.mul(ctx.env.light.envLight.getRadiance(scope, reflectVec, roughness).rgb, ShaderFramework.getEnvLightStrength(scope)) : scope.$builder.vec3(0);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Checks if shadow should be computed
|
|
349
|
+
* @param ctx - The drawing context
|
|
350
|
+
* @returns true if shadow should be computed, other wise false
|
|
351
|
+
*/ needCalucateShadow(ctx) {
|
|
352
|
+
return !!ctx.currentShadowLight;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Calculates shadow of current fragment
|
|
356
|
+
*
|
|
357
|
+
* @param scope - Shader scope
|
|
358
|
+
* @param NoL - NdotL vector
|
|
359
|
+
* @param ctx - The drawing context
|
|
360
|
+
* @returns Shadow of current fragment, 1 means no shadow and 0 means full shadowed.
|
|
361
|
+
*/ calculateShadow(scope, NoL, ctx) {
|
|
362
|
+
const pb = scope.$builder;
|
|
363
|
+
if (!this.needCalucateShadow(ctx)) {
|
|
364
|
+
console.warn('calculateShadow(): No need to calculate shadow');
|
|
365
|
+
return pb.float(1);
|
|
366
|
+
}
|
|
367
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
368
|
+
const funcName = 'lm_calculateCSM';
|
|
369
|
+
pb.func(funcName, [
|
|
370
|
+
pb.float('NoL')
|
|
371
|
+
], function() {
|
|
372
|
+
if (shadowMapParams.numShadowCascades > 1) {
|
|
373
|
+
this.$l.shadowCascades = this.global.light.shadowCascades;
|
|
374
|
+
this.$l.shadowBound = pb.vec4(0, 0, 1, 1);
|
|
375
|
+
this.$l.linearDepth = nonLinearDepthToLinear(this, this.$builtins.fragCoord.z);
|
|
376
|
+
this.$l.splitDistances = ShaderFramework.getCascadeDistances(this);
|
|
377
|
+
this.$l.comparison = pb.vec4(pb.greaterThan(pb.vec4(this.linearDepth), this.splitDistances));
|
|
378
|
+
this.$l.cascadeFlags = pb.vec4(pb.float(pb.greaterThan(this.shadowCascades, 0)), pb.float(pb.greaterThan(this.shadowCascades, 1)), pb.float(pb.greaterThan(this.shadowCascades, 2)), pb.float(pb.greaterThan(this.shadowCascades, 3)));
|
|
379
|
+
this.$l.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));
|
|
380
|
+
if (Application.instance.device.type === 'webgl') {
|
|
381
|
+
this.$l.shadowVertex = pb.vec4();
|
|
382
|
+
this.$for(pb.int('cascade'), 0, 4, function() {
|
|
383
|
+
this.$if(pb.equal(this.cascade, this.split), function() {
|
|
384
|
+
this.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this, this.cascade);
|
|
385
|
+
this.$break();
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
} else {
|
|
389
|
+
this.$l.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this, this.split);
|
|
390
|
+
}
|
|
391
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
392
|
+
this.$l.shadow = shadowMapParams.impl.computeShadowCSM(shadowMapParams, this, this.shadowVertex, this.NoL, this.split);
|
|
393
|
+
this.$l.shadowDistance = ShaderFramework.getShadowCameraParams(scope).w;
|
|
394
|
+
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(ShaderFramework.getCameraPosition(this), ShaderFramework.getWorldPosition(this).xyz)));
|
|
395
|
+
this.$return(this.shadow);
|
|
396
|
+
} else {
|
|
397
|
+
this.$l.shadowVertex = ShaderFramework.calculateShadowSpaceVertex(this);
|
|
398
|
+
const shadowMapParams = ctx.shadowMapInfo.get(ctx.currentShadowLight);
|
|
399
|
+
this.$l.shadow = shadowMapParams.impl.computeShadow(shadowMapParams, this, this.shadowVertex, this.NoL);
|
|
400
|
+
this.$l.shadowDistance = ShaderFramework.getShadowCameraParams(scope).w;
|
|
401
|
+
this.shadow = pb.mix(this.shadow, 1, pb.smoothStep(pb.mul(this.shadowDistance, 0.8), this.shadowDistance, pb.distance(ShaderFramework.getCameraPosition(this), ShaderFramework.getWorldPosition(this).xyz)));
|
|
402
|
+
this.$return(this.shadow);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
return pb.getGlobalScope()[funcName](NoL);
|
|
406
|
+
}
|
|
407
|
+
getClusterIndex(scope, fragCoord) {
|
|
408
|
+
const pb = scope.$builder;
|
|
409
|
+
const funcName = 'lm_getClusterIndex';
|
|
410
|
+
pb.func(funcName, [
|
|
411
|
+
pb.vec3('fragCoord')
|
|
412
|
+
], function() {
|
|
413
|
+
const clusterParams = ShaderFramework.getClusterParams(this);
|
|
414
|
+
const countParams = ShaderFramework.getCountParams(this);
|
|
415
|
+
this.$l.zTile = pb.int(pb.max(pb.add(pb.mul(pb.log2(nonLinearDepthToLinear(this, this.fragCoord.z)), clusterParams.z), clusterParams.w), 0));
|
|
416
|
+
this.$l.f = pb.vec2(this.fragCoord.x, pb.sub(clusterParams.y, pb.add(this.fragCoord.y, 1)));
|
|
417
|
+
this.$l.xyTile = pb.ivec2(pb.div(this.f, pb.div(clusterParams.xy, pb.vec2(countParams.xy))));
|
|
418
|
+
this.$return(pb.ivec3(this.xyTile, this.zTile));
|
|
419
|
+
});
|
|
420
|
+
return pb.getGlobalScope()[funcName](fragCoord);
|
|
421
|
+
}
|
|
422
|
+
calculatePointLightAttenuation(scope, posRange) {
|
|
423
|
+
const pb = scope.$builder;
|
|
424
|
+
const funcName = 'lm_calculatePointLightAttenuation';
|
|
425
|
+
pb.func(funcName, [
|
|
426
|
+
pb.vec4('posRange')
|
|
427
|
+
], function() {
|
|
428
|
+
this.$l.dist = pb.distance(this.posRange.xyz, ShaderFramework.getWorldPosition(this).xyz);
|
|
429
|
+
this.$l.falloff = pb.max(0, pb.sub(1, pb.div(this.dist, this.posRange.w)));
|
|
430
|
+
this.$return(pb.mul(this.falloff, this.falloff));
|
|
431
|
+
});
|
|
432
|
+
return pb.getGlobalScope()[funcName](posRange);
|
|
433
|
+
}
|
|
434
|
+
calculateSpotLightAttenuation(scope, posRange, dirCutoff) {
|
|
435
|
+
const pb = scope.$builder;
|
|
436
|
+
const funcName = 'lm_calculateSpotLightAttenuation';
|
|
437
|
+
pb.func(funcName, [
|
|
438
|
+
pb.vec4('posRange'),
|
|
439
|
+
pb.vec4('dirCutoff')
|
|
440
|
+
], function() {
|
|
441
|
+
this.$l.dist = pb.distance(this.posRange.xyz, ShaderFramework.getWorldPosition(this).xyz);
|
|
442
|
+
this.$l.falloff = pb.max(0, pb.sub(1, pb.div(this.dist, this.posRange.w)));
|
|
443
|
+
this.$l.spotFactor = pb.dot(pb.normalize(pb.sub(ShaderFramework.getWorldPosition(this).xyz, this.posRange.xyz)), this.dirCutoff.xyz);
|
|
444
|
+
this.spotFactor = pb.smoothStep(this.dirCutoff.w, pb.mix(this.dirCutoff.w, 1, 0.5), this.spotFactor);
|
|
445
|
+
this.$return(pb.mul(this.spotFactor, this.falloff, this.falloff));
|
|
446
|
+
});
|
|
447
|
+
return pb.getGlobalScope()[funcName](posRange, dirCutoff);
|
|
448
|
+
}
|
|
449
|
+
calculateLightAttenuation(scope, type, posRange, dirCutoff) {
|
|
450
|
+
const pb = scope.$builder;
|
|
451
|
+
return scope.$choice(pb.equal(type, LIGHT_TYPE_DIRECTIONAL), pb.float(1), scope.$choice(pb.equal(type, LIGHT_TYPE_POINT), this.calculatePointLightAttenuation(scope, posRange), this.calculateSpotLightAttenuation(scope, posRange, dirCutoff)));
|
|
452
|
+
}
|
|
453
|
+
calculateLightDirection(scope, type, posRange, dirCutoff) {
|
|
454
|
+
const pb = scope.$builder;
|
|
455
|
+
return scope.$choice(pb.equal(type, LIGHT_TYPE_DIRECTIONAL), pb.neg(dirCutoff.xyz), pb.normalize(pb.sub(posRange.xyz, ShaderFramework.getWorldPosition(scope).xyz)));
|
|
456
|
+
}
|
|
457
|
+
forEachLight(scope, ctx, callback) {
|
|
458
|
+
const pb = scope.$builder;
|
|
459
|
+
const that = this;
|
|
460
|
+
if (ctx.currentShadowLight) {
|
|
461
|
+
const posRange = scope.global.light.positionAndRange;
|
|
462
|
+
const dirCutoff = scope.global.light.directionAndCutoff;
|
|
463
|
+
const colorIntensity = scope.global.light.diffuseAndIntensity;
|
|
464
|
+
scope.$scope(function() {
|
|
465
|
+
const lightType = scope.$choice(pb.lessThan(posRange.w, 0), pb.int(LIGHT_TYPE_DIRECTIONAL), scope.$choice(pb.lessThan(dirCutoff.w, 0), pb.int(LIGHT_TYPE_POINT), pb.int(LIGHT_TYPE_SPOT)));
|
|
466
|
+
callback.call(this, lightType, posRange, dirCutoff, colorIntensity, true);
|
|
467
|
+
});
|
|
468
|
+
} else {
|
|
469
|
+
scope.$scope(function() {
|
|
470
|
+
const countParams = ShaderFramework.getCountParams(this);
|
|
471
|
+
this.$l.cluster = that.getClusterIndex(this, this.$builtins.fragCoord.xyz);
|
|
472
|
+
this.$l.clusterIndex = pb.add(this.cluster.x, pb.mul(this.cluster.y, countParams.x), pb.mul(this.cluster.z, countParams.x, countParams.y));
|
|
473
|
+
this.$l.texSize = this.global.light.lightIndexTexSize;
|
|
474
|
+
if (pb.getDevice().type === 'webgl') {
|
|
475
|
+
this.$l.texCoordX = pb.div(pb.add(pb.mod(pb.float(this.clusterIndex), pb.float(this.texSize.x)), 0.5), pb.float(this.texSize.x));
|
|
476
|
+
this.$l.texCoordY = pb.div(pb.add(pb.float(pb.div(this.clusterIndex, this.texSize.x)), 0.5), pb.float(this.texSize.y));
|
|
477
|
+
this.$l.samp = pb.textureSample(ShaderFramework.getClusteredLightIndexTexture(this), pb.vec2(this.texCoordX, this.texCoordY));
|
|
478
|
+
} else {
|
|
479
|
+
this.$l.texCoordX = pb.mod(this.clusterIndex, this.texSize.x);
|
|
480
|
+
this.$l.texCoordY = pb.div(this.clusterIndex, this.texSize.x);
|
|
481
|
+
this.$l.samp = pb.textureLoad(ShaderFramework.getClusteredLightIndexTexture(this), pb.ivec2(this.texCoordX, this.texCoordY), 0);
|
|
482
|
+
}
|
|
483
|
+
if (pb.getDevice().type === 'webgl') {
|
|
484
|
+
this.$for(pb.int('i'), 0, 4, function() {
|
|
485
|
+
this.$l.k = this.samp.at(this.i);
|
|
486
|
+
this.$l.lights = pb.int[2]();
|
|
487
|
+
this.$l.lights[0] = pb.int(pb.mod(this.k, 256));
|
|
488
|
+
this.$l.lights[1] = pb.int(pb.div(this.k, 256));
|
|
489
|
+
this.$for(pb.int('k'), 0, 2, function() {
|
|
490
|
+
this.$l.li = this.lights.at(this.k);
|
|
491
|
+
this.$if(pb.greaterThan(this.li, 0), function() {
|
|
492
|
+
this.$for(pb.int('j'), 1, 256, function() {
|
|
493
|
+
this.$if(pb.equal(this.j, this.li), function() {
|
|
494
|
+
this.$l.positionRange = ShaderFramework.getLightPositionAndRange(this, this.j);
|
|
495
|
+
this.$l.directionCutoff = ShaderFramework.getLightDirectionAndCutoff(this, this.j);
|
|
496
|
+
this.$l.diffuseIntensity = ShaderFramework.getLightColorAndIntensity(this, this.j);
|
|
497
|
+
this.$l.lightType = this.$choice(pb.lessThan(this.positionRange.w, 0), pb.int(LIGHT_TYPE_DIRECTIONAL), this.$choice(pb.lessThan(this.directionCutoff.w, 0), pb.int(LIGHT_TYPE_POINT), pb.int(LIGHT_TYPE_SPOT)));
|
|
498
|
+
this.$scope(function() {
|
|
499
|
+
callback.call(this, this.lightType, this.positionRange, this.directionCutoff, this.diffuseIntensity, false);
|
|
500
|
+
});
|
|
501
|
+
this.$break();
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
} else {
|
|
508
|
+
this.$for(pb.uint('i'), 0, 4, function() {
|
|
509
|
+
this.$for(pb.uint('k'), 0, 4, function() {
|
|
510
|
+
this.$l.c = pb.compAnd(pb.sar(this.samp.at(this.i), pb.mul(this.k, 8)), 0xff);
|
|
511
|
+
this.$if(pb.greaterThan(this.c, 0), function() {
|
|
512
|
+
this.$l.positionRange = ShaderFramework.getLightPositionAndRange(this, this.c);
|
|
513
|
+
this.$l.directionCutoff = ShaderFramework.getLightDirectionAndCutoff(this, this.c);
|
|
514
|
+
this.$l.diffuseIntensity = ShaderFramework.getLightColorAndIntensity(this, this.c);
|
|
515
|
+
this.$l.lightType = this.$choice(pb.lessThan(this.positionRange.w, 0), pb.int(LIGHT_TYPE_DIRECTIONAL), this.$choice(pb.lessThan(this.directionCutoff.w, 0), pb.int(LIGHT_TYPE_POINT), pb.int(LIGHT_TYPE_SPOT)));
|
|
516
|
+
this.$scope(function() {
|
|
517
|
+
callback.call(this, this.lightType, this.positionRange, this.directionCutoff, this.diffuseIntensity, false);
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Vertex shader implementation.
|
|
528
|
+
*
|
|
529
|
+
* @param scope - Shader scope
|
|
530
|
+
* @param ctx - The drawing context
|
|
531
|
+
*/ vertexShader(scope, ctx) {
|
|
532
|
+
super.vertexShader(scope, ctx);
|
|
533
|
+
const pb = scope.$builder;
|
|
534
|
+
if (this.needFragmentColor(ctx)) {
|
|
535
|
+
if (this.vertexNormal) {
|
|
536
|
+
scope.$inputs.normal = pb.vec3().attrib('normal');
|
|
537
|
+
}
|
|
538
|
+
if (this.vertexTangent) {
|
|
539
|
+
scope.$inputs.tangent = pb.vec4().attrib('tangent');
|
|
540
|
+
}
|
|
541
|
+
if (this.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type)) {
|
|
542
|
+
const semantic = `texCoord${this.normalTexCoordIndex}`;
|
|
543
|
+
if (!scope.$getVertexAttrib(semantic)) {
|
|
544
|
+
scope.$inputs[semantic] = pb.vec2().attrib(semantic);
|
|
545
|
+
}
|
|
546
|
+
if (this.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE_MATRIX, ctx.renderPass.type)) {
|
|
547
|
+
scope.$g.kkNormalTextureMatrix = pb.mat4().uniform(2);
|
|
548
|
+
scope.$outputs.kkNormalTexCoord = pb.mul(scope.kkNormalTextureMatrix, pb.vec4(scope.$inputs[semantic], 0, 1)).xy;
|
|
549
|
+
} else {
|
|
550
|
+
scope.$outputs.kkNormalTexCoord = scope.$inputs[semantic];
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Fragment shader implementation
|
|
557
|
+
*
|
|
558
|
+
* @param scope - Shader scope
|
|
559
|
+
* @param ctx - The drawing context
|
|
560
|
+
* @returns Calucated fragment color
|
|
561
|
+
*/ fragmentShader(scope, ctx) {
|
|
562
|
+
super.fragmentShader(scope, ctx);
|
|
563
|
+
const pb = scope.$builder;
|
|
564
|
+
if (this.featureUsed(LitMaterial.FEATURE_NORMAL_TEXTURE, ctx.renderPass.type)) {
|
|
565
|
+
scope.$g.kkNormalTexture = pb.tex2D().uniform(2);
|
|
566
|
+
scope.$g.kkNormalScale = pb.float().uniform(2);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* {@inheritDoc Material.supportLighting}
|
|
571
|
+
* @override
|
|
572
|
+
*/ supportLighting() {
|
|
573
|
+
return true;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export { LitMaterial };
|
|
578
|
+
//# sourceMappingURL=lit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|