@zephyr3d/scene 0.8.2 → 0.9.1
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/animationset.js +473 -60
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/cloth/gpu_cloth_system.js +2516 -0
- package/dist/animation/cloth/gpu_cloth_system.js.map +1 -0
- package/dist/animation/fixed_geometry_cache_track.js +138 -0
- package/dist/animation/fixed_geometry_cache_track.js.map +1 -0
- package/dist/animation/geometry_cache_utils.js +120 -0
- package/dist/animation/geometry_cache_utils.js.map +1 -0
- package/dist/animation/ik_modifier.js +9 -1
- package/dist/animation/ik_modifier.js.map +1 -1
- package/dist/animation/joint_dynamics/collision.js +469 -0
- package/dist/animation/joint_dynamics/collision.js.map +1 -0
- package/dist/animation/joint_dynamics/constraints.js +329 -0
- package/dist/animation/joint_dynamics/constraints.js.map +1 -0
- package/dist/animation/joint_dynamics/controller.js +699 -0
- package/dist/animation/joint_dynamics/controller.js.map +1 -0
- package/dist/animation/joint_dynamics/joint_dynamics_system.js +393 -0
- package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -0
- package/dist/animation/joint_dynamics/solver.js +794 -0
- package/dist/animation/joint_dynamics/solver.js.map +1 -0
- package/dist/animation/joint_dynamics/types.js +19 -0
- package/dist/animation/joint_dynamics/types.js.map +1 -0
- package/dist/animation/joint_dynamics/vrm_spring_bone.js +46 -0
- package/dist/animation/joint_dynamics/vrm_spring_bone.js.map +1 -0
- package/dist/animation/joint_dynamics_modifier.js +51 -0
- package/dist/animation/joint_dynamics_modifier.js.map +1 -0
- package/dist/animation/pca_geometry_cache_track.js +222 -0
- package/dist/animation/pca_geometry_cache_track.js.map +1 -0
- package/dist/animation/skeleton.js +2011 -139
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/skeleton_modifier.js +3 -5
- package/dist/animation/skeleton_modifier.js.map +1 -1
- package/dist/animation/spring/multi_chain_spring_system.js +2 -0
- package/dist/animation/spring/multi_chain_spring_system.js.map +1 -1
- package/dist/animation/spring/spring_chain.js +3 -2
- package/dist/animation/spring/spring_chain.js.map +1 -1
- package/dist/animation/spring/spring_collider.js +35 -5
- package/dist/animation/spring/spring_collider.js.map +1 -1
- package/dist/animation/spring/spring_particle.js +1 -0
- package/dist/animation/spring/spring_particle.js.map +1 -1
- package/dist/animation/spring/spring_system.js +325 -28
- package/dist/animation/spring/spring_system.js.map +1 -1
- package/dist/animation/spring2/collision.js +469 -0
- package/dist/animation/spring2/collision.js.map +1 -0
- package/dist/animation/spring2/constraints.js +329 -0
- package/dist/animation/spring2/constraints.js.map +1 -0
- package/dist/animation/spring2/controller.js +434 -0
- package/dist/animation/spring2/controller.js.map +1 -0
- package/dist/animation/spring2/math.js +16 -0
- package/dist/animation/spring2/math.js.map +1 -0
- package/dist/animation/spring2/solver.js +624 -0
- package/dist/animation/spring2/solver.js.map +1 -0
- package/dist/animation/spring2/spring_system.js +118 -0
- package/dist/animation/spring2/spring_system.js.map +1 -0
- package/dist/animation/spring2/types.js +19 -0
- package/dist/animation/spring2/types.js.map +1 -0
- package/dist/animation/spring_modifier.js +17 -1
- package/dist/animation/spring_modifier.js.map +1 -1
- package/dist/app/engine.js +42 -15
- package/dist/app/engine.js.map +1 -1
- package/dist/app/runtimescript.js +132 -1
- package/dist/app/runtimescript.js.map +1 -1
- package/dist/app/screen.js +3 -3
- package/dist/app/screen.js.map +1 -1
- package/dist/app/scriptingsystem.js +69 -37
- package/dist/app/scriptingsystem.js.map +1 -1
- package/dist/app/scriptregistry.js +14 -3
- package/dist/app/scriptregistry.js.map +1 -1
- package/dist/asset/assetmanager.js +2 -1
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/asset/loaders/zabc/zabc_loader.js +570 -0
- package/dist/asset/loaders/zabc/zabc_loader.js.map +1 -0
- package/dist/asset/model.js +192 -0
- package/dist/asset/model.js.map +1 -1
- package/dist/camera/base.js +26 -7
- package/dist/camera/base.js.map +1 -1
- package/dist/camera/camera.js +146 -24
- package/dist/camera/camera.js.map +1 -1
- package/dist/camera/fps.js +2 -2
- package/dist/camera/fps.js.map +1 -1
- package/dist/camera/orbit.js +2 -2
- package/dist/camera/orbit.js.map +1 -1
- package/dist/index.d.ts +11728 -8535
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/dist/material/lambert.js +1 -1
- package/dist/material/lambert.js.map +1 -1
- package/dist/material/material.js +9 -3
- package/dist/material/material.js.map +1 -1
- package/dist/material/meshmaterial.js +54 -7
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/mixins/lightmodel/blinnphong.js +17 -7
- package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
- package/dist/material/mixins/lightmodel/lambert.js +7 -2
- package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +108 -16
- package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +209 -14
- package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js +24 -12
- package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
- package/dist/material/mixins/lit.js +11 -8
- package/dist/material/mixins/lit.js.map +1 -1
- package/dist/material/mixins/pbr/common.js +72 -5
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/material/pbrblueprint.js +148 -1
- package/dist/material/pbrblueprint.js.map +1 -1
- package/dist/material/pbrmr.js +115 -2
- package/dist/material/pbrmr.js.map +1 -1
- package/dist/material/shader/helper.js +10 -4
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/water.js +2 -2
- package/dist/material/water.js.map +1 -1
- package/dist/posteffect/coloradjust.js +145 -0
- package/dist/posteffect/coloradjust.js.map +1 -0
- package/dist/posteffect/taa.js +68 -32
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/cluster_light.js +17 -12
- package/dist/render/cluster_light.js.map +1 -1
- package/dist/render/deferredlightpass.js +510 -0
- package/dist/render/deferredlightpass.js.map +1 -0
- package/dist/render/deferredshadowlightpass.js +428 -0
- package/dist/render/deferredshadowlightpass.js.map +1 -0
- package/dist/render/drawable.js.map +1 -1
- package/dist/render/drawable_mixin.js +21 -12
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/envlight.js +20 -22
- package/dist/render/envlight.js.map +1 -1
- package/dist/render/gbufferpass.js +50 -0
- package/dist/render/gbufferpass.js.map +1 -0
- package/dist/render/lightpass.js +1 -2
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/primitive.js +1 -1
- package/dist/render/primitive.js.map +1 -1
- package/dist/render/render_queue.js +3 -2
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +5 -358
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/executor.js +15 -12
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +144 -88
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/history_resource_manager.js +178 -0
- package/dist/render/rendergraph/history_resource_manager.js.map +1 -0
- package/dist/render/rendergraph/rendergraph.js +12 -1
- package/dist/render/rendergraph/rendergraph.js.map +1 -1
- package/dist/render/rendergraph/types.js +2 -2
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/render/sky.js +26 -9
- package/dist/render/sky.js.map +1 -1
- package/dist/scene/basesprite.js +4 -3
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +4 -4
- package/dist/scene/environment.js +7 -4
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +184 -18
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +30 -0
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/particlesys.js +3 -2
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/raycast_visitor.js +29 -3
- package/dist/scene/raycast_visitor.js.map +1 -1
- package/dist/scene/scene.js +86 -19
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/scene_node.js +87 -31
- package/dist/scene/scene_node.js.map +1 -1
- package/dist/scene/script_attachment.js +59 -0
- package/dist/scene/script_attachment.js.map +1 -0
- package/dist/scene/terrain-cm/grass.js +3 -2
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +4 -3
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +3 -2
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +2 -2
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/shadowmapper.js +74 -4
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shapes/box.js +163 -0
- package/dist/shapes/box.js.map +1 -1
- package/dist/shapes/capsule.js +216 -0
- package/dist/shapes/capsule.js.map +1 -0
- package/dist/shapes/cylinder.js +91 -0
- package/dist/shapes/cylinder.js.map +1 -1
- package/dist/shapes/plane.js +32 -0
- package/dist/shapes/plane.js.map +1 -1
- package/dist/shapes/tetrahedron.js +211 -0
- package/dist/shapes/tetrahedron.js.map +1 -1
- package/dist/shapes/torus.js +173 -0
- package/dist/shapes/torus.js.map +1 -1
- package/dist/utility/blueprint/common/math.js +111 -1
- package/dist/utility/blueprint/common/math.js.map +1 -1
- package/dist/utility/blueprint/material/inputs.js +235 -1
- package/dist/utility/blueprint/material/inputs.js.map +1 -1
- package/dist/utility/blueprint/material/ir.js +154 -10
- package/dist/utility/blueprint/material/ir.js.map +1 -1
- package/dist/utility/blueprint/material/texture.js +273 -19
- package/dist/utility/blueprint/material/texture.js.map +1 -1
- package/dist/utility/serialization/json.js +12 -2
- package/dist/utility/serialization/json.js.map +1 -1
- package/dist/utility/serialization/manager.js +30 -11
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +250 -7
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +4 -2
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +154 -2
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/cloth_script.js +834 -0
- package/dist/utility/serialization/scene/cloth_script.js.map +1 -0
- package/dist/utility/serialization/scene/common.js +7 -0
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +120 -4
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +453 -1
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +4 -2
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +298 -10
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +4 -2
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +100 -3
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/scene.js +130 -3
- package/dist/utility/serialization/scene/scene.js.map +1 -1
- package/dist/utility/serialization/scene/script.js +66 -0
- package/dist/utility/serialization/scene/script.js.map +1 -0
- package/dist/utility/serialization/scene/spring_script.js +596 -0
- package/dist/utility/serialization/scene/spring_script.js.map +1 -0
- package/dist/utility/serialization/scene/sprite.js +5 -3
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +4 -2
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +4 -2
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/utility/serialization/types.js.map +1 -1
- package/dist/values.js +5 -1
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { applyMaterialMixins } from '../../meshmaterial.js';
|
|
2
2
|
import { mixinTextureProps } from '../texture.js';
|
|
3
3
|
import { mixinPBRCommon } from '../pbr/common.js';
|
|
4
|
-
import { Vector4 } from '@zephyr3d/base';
|
|
4
|
+
import { Vector4, Vector2 } from '@zephyr3d/base';
|
|
5
5
|
import { mixinLight } from '../lit.js';
|
|
6
6
|
import { ShaderHelper } from '../../shader/helper.js';
|
|
7
|
-
import { MaterialVaryingFlags } from '../../../values.js';
|
|
7
|
+
import { RENDER_PASS_TYPE_LIGHT, LIGHT_TYPE_RECT, LIGHT_TYPE_POINT, MaterialVaryingFlags } from '../../../values.js';
|
|
8
8
|
|
|
9
|
+
const PBR_REFLECTION_MODE = {
|
|
10
|
+
none: 0,
|
|
11
|
+
ggx: 1,
|
|
12
|
+
anisotropic: 2,
|
|
13
|
+
glint: 3
|
|
14
|
+
};
|
|
9
15
|
/**
|
|
10
16
|
* PBRMetallicRoughness lighting model mixin
|
|
11
17
|
* @param BaseCls - Class to mix in
|
|
@@ -15,7 +21,7 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
15
21
|
if (BaseCls.pbrMetallicRoughnessMixed) {
|
|
16
22
|
return BaseCls;
|
|
17
23
|
}
|
|
18
|
-
const S = applyMaterialMixins(BaseCls, mixinPBRCommon, mixinLight, mixinTextureProps('metallicRoughness'), mixinTextureProps('specular'), mixinTextureProps('specularColor'));
|
|
24
|
+
const S = applyMaterialMixins(BaseCls, mixinPBRCommon, mixinLight, mixinTextureProps('metallicRoughness'), mixinTextureProps('specular'), mixinTextureProps('specularColor'), mixinTextureProps('anisotropyDirection'));
|
|
19
25
|
const METALLIC_UNIFORM = S.defineInstanceUniform('metallic', 'float', 'Metallic');
|
|
20
26
|
const ROUGHNESS_UNIFORM = S.defineInstanceUniform('roughness', 'float', 'Roughness');
|
|
21
27
|
const SPECULAR_FACTOR_UNFORM = S.defineInstanceUniform('specularFactor', 'rgba', 'SpecularFactor');
|
|
@@ -24,17 +30,29 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
24
30
|
_metallic;
|
|
25
31
|
_roughness;
|
|
26
32
|
_specularFactor;
|
|
33
|
+
_reflectionMode;
|
|
34
|
+
_anisotropy;
|
|
35
|
+
_anisotropyDirection;
|
|
36
|
+
_anisotropyDirectionScaleBias;
|
|
27
37
|
constructor(){
|
|
28
38
|
super();
|
|
29
39
|
this._metallic = 1;
|
|
30
40
|
this._roughness = 1;
|
|
31
41
|
this._specularFactor = Vector4.one();
|
|
42
|
+
this._reflectionMode = 'ggx';
|
|
43
|
+
this._anisotropy = 0.75;
|
|
44
|
+
this._anisotropyDirection = 0;
|
|
45
|
+
this._anisotropyDirectionScaleBias = new Vector2(1, 0);
|
|
32
46
|
}
|
|
33
47
|
copyFrom(other) {
|
|
34
48
|
super.copyFrom(other);
|
|
35
49
|
this.metallic = other.metallic;
|
|
36
50
|
this.roughness = other.roughness;
|
|
37
51
|
this.specularFactor = other.specularFactor;
|
|
52
|
+
this.reflectionMode = other.reflectionMode;
|
|
53
|
+
this.anisotropy = other.anisotropy;
|
|
54
|
+
this.anisotropyDirection = other.anisotropyDirection;
|
|
55
|
+
this.anisotropyDirectionScaleBias = other.anisotropyDirectionScaleBias;
|
|
38
56
|
}
|
|
39
57
|
get metallic() {
|
|
40
58
|
return this._metallic;
|
|
@@ -63,6 +81,152 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
63
81
|
this.uniformChanged();
|
|
64
82
|
}
|
|
65
83
|
}
|
|
84
|
+
directLighting(scope, lightDir, lightColor, normal, viewVec, commonData, diffuseScale, specularScale, sourceRadiusFactor, outColor) {
|
|
85
|
+
const pb = scope.$builder;
|
|
86
|
+
const that = this;
|
|
87
|
+
const funcName = 'Z_PBRMR_DirectLighting';
|
|
88
|
+
pb.func(funcName, [
|
|
89
|
+
pb.vec3('L'),
|
|
90
|
+
pb.vec3('lightColor'),
|
|
91
|
+
pb.vec3('normal'),
|
|
92
|
+
pb.vec3('viewVec'),
|
|
93
|
+
that.getCommonDatasStruct(scope)('data'),
|
|
94
|
+
pb.float('diffuseScale'),
|
|
95
|
+
pb.float('specularScale'),
|
|
96
|
+
pb.float('sourceRadiusFactor'),
|
|
97
|
+
pb.vec3('outColor').inout()
|
|
98
|
+
], function() {
|
|
99
|
+
this.$l.reflectionMode = this.zReflectionMode;
|
|
100
|
+
this.$l.anisotropy = this.zAnisotropy;
|
|
101
|
+
this.$l.anisotropyDirection = this.zAnisotropyDirection;
|
|
102
|
+
this.$l.anisotropyDirectionScaleBias = this.zAnisotropyDirectionScaleBias;
|
|
103
|
+
this.$l.H = pb.normalize(pb.add(this.viewVec, this.L));
|
|
104
|
+
this.$l.NoH = pb.clamp(pb.dot(this.normal, this.H), 0, 1);
|
|
105
|
+
this.$l.NoL = pb.clamp(pb.dot(this.normal, this.L), 0, 1);
|
|
106
|
+
this.$l.NoV = pb.clamp(pb.dot(this.normal, this.viewVec), 0, 1);
|
|
107
|
+
this.$if(pb.greaterThan(this.NoL, 0), function() {
|
|
108
|
+
this.$l.VoH = pb.clamp(pb.dot(this.viewVec, this.H), 0, 1);
|
|
109
|
+
this.$l.schlickFresnel = that.fresnelSchlick(this, this.VoH, this.data.f0.rgb, this.data.f90);
|
|
110
|
+
if (that.iridescence) {
|
|
111
|
+
this.$l.F = pb.mix(this.schlickFresnel, this.data.iridescenceFresnel, this.data.iridescenceFactor.x);
|
|
112
|
+
} else {
|
|
113
|
+
this.$l.F = this.schlickFresnel;
|
|
114
|
+
}
|
|
115
|
+
this.$l.specularRoughness = pb.clamp(pb.add(this.data.roughness, this.sourceRadiusFactor), 0, 1);
|
|
116
|
+
this.$l.alphaRoughness = pb.mul(this.specularRoughness, this.specularRoughness);
|
|
117
|
+
this.$l.Dggx = that.distributionGGX(this, this.NoH, this.alphaRoughness);
|
|
118
|
+
this.$l.D = this.Dggx;
|
|
119
|
+
this.$if(pb.equal(this.reflectionMode, PBR_REFLECTION_MODE.anisotropic), function() {
|
|
120
|
+
this.$l.dirAngle = pb.mul(this.anisotropyDirection, Math.PI / 180);
|
|
121
|
+
if (that.anisotropyDirectionTexture) {
|
|
122
|
+
this.$l.dirSample = that.sampleAnisotropyDirectionTexture(this);
|
|
123
|
+
this.$l.dirAngle = pb.mul(pb.add(pb.mul(this.dirSample.r, this.anisotropyDirectionScaleBias.x), this.anisotropyDirectionScaleBias.y), Math.PI / 180);
|
|
124
|
+
}
|
|
125
|
+
this.$l.anisoAngle = this.dirAngle;
|
|
126
|
+
this.$l.up = pb.vec3(0, 1, 0);
|
|
127
|
+
this.$l.t0 = pb.normalize(pb.cross(this.up, this.normal));
|
|
128
|
+
this.$if(pb.lessThan(pb.length(this.t0), 0.001), function() {
|
|
129
|
+
this.t0 = pb.normalize(pb.cross(pb.vec3(1, 0, 0), this.normal));
|
|
130
|
+
});
|
|
131
|
+
this.$l.b0 = pb.normalize(pb.cross(this.normal, this.t0));
|
|
132
|
+
this.$l.tangent = pb.normalize(pb.add(pb.mul(this.t0, pb.cos(this.anisoAngle)), pb.mul(this.b0, pb.sin(this.anisoAngle))));
|
|
133
|
+
this.$l.bitangent = pb.normalize(pb.cross(this.normal, this.tangent));
|
|
134
|
+
this.$l.ToH = pb.dot(this.tangent, this.H);
|
|
135
|
+
this.$l.BoH = pb.dot(this.bitangent, this.H);
|
|
136
|
+
this.$l.at = pb.max(pb.mul(this.alphaRoughness, pb.add(1, this.anisotropy)), 0.0001);
|
|
137
|
+
this.$l.ab = pb.max(pb.mul(this.alphaRoughness, pb.sub(1, this.anisotropy)), 0.0001);
|
|
138
|
+
this.$l.anisoDenom = pb.mul(Math.PI, this.at, this.ab, pb.pow(pb.add(pb.div(pb.mul(this.ToH, this.ToH), pb.mul(this.at, this.at)), pb.div(pb.mul(this.BoH, this.BoH), pb.mul(this.ab, this.ab)), pb.mul(this.NoH, this.NoH)), 2));
|
|
139
|
+
this.D = pb.div(1, pb.max(this.anisoDenom, 0.0001));
|
|
140
|
+
}).$elseif(pb.equal(this.reflectionMode, PBR_REFLECTION_MODE.glint), function() {
|
|
141
|
+
this.$l.glintNoise = pb.fract(pb.mul(pb.sin(pb.add(pb.dot(this.H, pb.vec3(127.1, 311.7, 74.7)), pb.mul(this.NoH, 43.1))), 43758.5453));
|
|
142
|
+
this.$l.glintMask = pb.smoothStep(0.97, 1, this.glintNoise);
|
|
143
|
+
this.D = pb.mul(this.Dggx, pb.add(1, pb.mul(this.glintMask, 8)));
|
|
144
|
+
});
|
|
145
|
+
this.$l.V = that.visGGX(this, this.NoV, this.NoL, this.alphaRoughness);
|
|
146
|
+
this.$l.specular = pb.mul(this.lightColor, this.D, this.V, this.F, this.data.specularWeight, this.specularScale);
|
|
147
|
+
if (that.sheen) {
|
|
148
|
+
this.specular = pb.mul(this.specular, this.data.sheenAlbedoScaling);
|
|
149
|
+
}
|
|
150
|
+
this.$if(pb.equal(this.reflectionMode, PBR_REFLECTION_MODE.none), function() {
|
|
151
|
+
this.specular = pb.vec3(0);
|
|
152
|
+
});
|
|
153
|
+
this.outColor = pb.add(this.outColor, this.specular);
|
|
154
|
+
if (that.iridescence) {
|
|
155
|
+
this.$l.iridescenceFresnelMax = pb.vec3(pb.max(pb.max(this.data.iridescenceFresnel.r, this.data.iridescenceFresnel.g), this.data.iridescenceFresnel.b));
|
|
156
|
+
this.F = pb.mix(this.schlickFresnel, this.iridescenceFresnelMax, this.data.iridescenceFactor.x);
|
|
157
|
+
}
|
|
158
|
+
this.$l.diffuseBRDF = pb.mul(pb.sub(pb.vec3(1), pb.mul(this.F, this.data.specularWeight)), pb.div(this.data.diffuse.rgb, Math.PI));
|
|
159
|
+
this.$l.diffuse = pb.mul(this.lightColor, pb.max(this.diffuseBRDF, pb.vec3(0)), this.diffuseScale);
|
|
160
|
+
if (that.transmission && that.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
|
|
161
|
+
this.$l.transmissionRay = that.getVolumeTransmissionRay(this, this.normal, this.viewVec, this.data.thicknessFactor, this.data.f0.a);
|
|
162
|
+
this.$l.pointToLight = pb.normalize(pb.sub(this.L, this.transmissionRay));
|
|
163
|
+
this.$l.transmittedLight = pb.mul(this.lightColor, that.getPunctualRadianceTransmission(this, this.normal, this.viewVec, this.pointToLight, this.alphaRoughness, this.data.f0.rgb, this.data.f90.rgb, this.data.diffuse.rgb, this.data.f0.a));
|
|
164
|
+
this.transmittedLight = that.applyVolumeAttenuation(this, this.transmittedLight, pb.length(this.transmissionRay), this.data.attenuationColor, this.data.attenuationDistance);
|
|
165
|
+
this.diffuse = pb.mix(this.diffuse, this.transmittedLight, this.data.transmissionFactor);
|
|
166
|
+
}
|
|
167
|
+
if (that.sheen) {
|
|
168
|
+
this.diffuse = pb.mul(this.diffuse, this.data.sheenAlbedoScaling);
|
|
169
|
+
}
|
|
170
|
+
this.outColor = pb.add(this.outColor, this.diffuse);
|
|
171
|
+
if (that.sheen) {
|
|
172
|
+
this.$l.sheenD = that.D_Charlie(this, this.NoH, this.data.sheenRoughness);
|
|
173
|
+
this.$l.sheenV = that.V_Ashikhmin(this, this.NoL, this.NoV);
|
|
174
|
+
this.outColor = pb.add(this.outColor, pb.mul(this.lightColor, this.data.sheenColor, this.sheenD, this.sheenV));
|
|
175
|
+
}
|
|
176
|
+
if (that.clearcoat) {
|
|
177
|
+
this.alphaRoughness = pb.mul(this.data.ccFactor.y, this.data.ccFactor.y);
|
|
178
|
+
this.NoH = pb.clamp(pb.dot(this.data.ccNormal, this.H), 0, 1);
|
|
179
|
+
this.NoL = pb.clamp(pb.dot(this.data.ccNormal, this.L), 0, 1);
|
|
180
|
+
this.ccF0 = pb.vec3(pb.pow(pb.div(pb.sub(this.data.f0.a, 1), pb.add(this.data.f0.a, 1)), 2));
|
|
181
|
+
this.F = that.fresnelSchlick(this, this.VoH, this.ccF0, pb.vec3(1));
|
|
182
|
+
this.D = that.distributionGGX(this, this.NoH, this.alphaRoughness);
|
|
183
|
+
this.V = that.visGGX(this, this.data.ccNoV, this.NoL, this.alphaRoughness);
|
|
184
|
+
this.outColor = pb.add(this.outColor, pb.mul(this.D, this.V, this.F, this.data.ccFactor.x));
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
scope.$g[funcName](lightDir, lightColor, normal, viewVec, commonData, diffuseScale, specularScale, sourceRadiusFactor, outColor);
|
|
189
|
+
}
|
|
190
|
+
get reflectionMode() {
|
|
191
|
+
return this._reflectionMode;
|
|
192
|
+
}
|
|
193
|
+
set reflectionMode(val) {
|
|
194
|
+
if (val !== this._reflectionMode) {
|
|
195
|
+
this._reflectionMode = val;
|
|
196
|
+
this.uniformChanged();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
get anisotropy() {
|
|
200
|
+
return this._anisotropy;
|
|
201
|
+
}
|
|
202
|
+
set anisotropy(val) {
|
|
203
|
+
const clamped = Math.max(-0.95, Math.min(0.95, val));
|
|
204
|
+
if (clamped !== this._anisotropy) {
|
|
205
|
+
this._anisotropy = clamped;
|
|
206
|
+
this.uniformChanged();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
get anisotropyDirection() {
|
|
210
|
+
return this._anisotropyDirection;
|
|
211
|
+
}
|
|
212
|
+
set anisotropyDirection(val) {
|
|
213
|
+
if (val !== this._anisotropyDirection) {
|
|
214
|
+
this._anisotropyDirection = val;
|
|
215
|
+
this.uniformChanged();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
get anisotropyDirectionScaleBias() {
|
|
219
|
+
return this._anisotropyDirectionScaleBias;
|
|
220
|
+
}
|
|
221
|
+
set anisotropyDirectionScaleBias(val) {
|
|
222
|
+
if (!val.equalsTo(this._anisotropyDirectionScaleBias)) {
|
|
223
|
+
this._anisotropyDirectionScaleBias.set(val);
|
|
224
|
+
this.uniformChanged();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
calculateAnisotropyDirectionScaleBias(scope) {
|
|
228
|
+
return scope.zAnisotropyDirectionScaleBias;
|
|
229
|
+
}
|
|
66
230
|
PBRLight(scope, worldPos, normal, viewVec, albedo, TBN, outRoughness) {
|
|
67
231
|
const pb = scope.$builder;
|
|
68
232
|
const funcName = 'Z_PBRMetallicRoughnessLight';
|
|
@@ -85,17 +249,29 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
85
249
|
} else {
|
|
86
250
|
that.indirectLighting(this, this.normal, this.viewVec, this.pbrData, this.lightingColor);
|
|
87
251
|
}
|
|
88
|
-
that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, shadow) {
|
|
89
|
-
this.$
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
|
|
98
|
-
|
|
252
|
+
that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, extra, shadow) {
|
|
253
|
+
this.$if(pb.equal(type, LIGHT_TYPE_RECT), function() {
|
|
254
|
+
that.directRectLight(this, this.worldPos, this.normal, this.viewVec, this.pbrData, posRange, dirCutoff, extra, colorIntensity, this.lightingColor);
|
|
255
|
+
}).$else(function() {
|
|
256
|
+
this.$l.diffuse = pb.vec3();
|
|
257
|
+
this.$l.specular = pb.vec3();
|
|
258
|
+
this.$l.diffuseScale = pb.float(1);
|
|
259
|
+
this.$l.specularScale = pb.float(1);
|
|
260
|
+
this.$l.sourceRadiusFactor = pb.float(0);
|
|
261
|
+
this.$if(pb.equal(type, LIGHT_TYPE_POINT), function() {
|
|
262
|
+
this.diffuseScale = extra.x;
|
|
263
|
+
this.specularScale = extra.y;
|
|
264
|
+
this.sourceRadiusFactor = pb.div(extra.z, pb.max(pb.distance(posRange.xyz, this.worldPos), 0.0001));
|
|
265
|
+
});
|
|
266
|
+
this.$l.lightAtten = that.calculateLightAttenuation(this, type, this.worldPos, posRange, dirCutoff);
|
|
267
|
+
this.$l.lightDir = that.calculateLightDirection(this, type, this.worldPos, posRange, dirCutoff);
|
|
268
|
+
this.$l.NoL = pb.clamp(pb.dot(this.normal, this.lightDir), 0, 1);
|
|
269
|
+
this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten, this.NoL);
|
|
270
|
+
if (shadow) {
|
|
271
|
+
this.lightColor = pb.mul(this.lightColor, that.calculateShadow(this, this.worldPos, this.NoL));
|
|
272
|
+
}
|
|
273
|
+
that.directLighting(this, this.lightDir, this.lightColor, this.normal, this.viewVec, this.pbrData, this.diffuseScale, this.specularScale, this.sourceRadiusFactor, this.lightingColor);
|
|
274
|
+
});
|
|
99
275
|
});
|
|
100
276
|
this.$return(pb.add(this.lightingColor, this.emissiveColor));
|
|
101
277
|
});
|
|
@@ -118,6 +294,10 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
118
294
|
scope.zRoughness = pb.float().uniform(2);
|
|
119
295
|
scope.zSpecularFactor = pb.vec4().uniform(2);
|
|
120
296
|
}
|
|
297
|
+
scope.zReflectionMode = pb.float().uniform(2);
|
|
298
|
+
scope.zAnisotropy = pb.float().uniform(2);
|
|
299
|
+
scope.zAnisotropyDirection = pb.float().uniform(2);
|
|
300
|
+
scope.zAnisotropyDirectionScaleBias = pb.vec2().uniform(2);
|
|
121
301
|
}
|
|
122
302
|
}
|
|
123
303
|
applyUniformValues(bindGroup, ctx, pass) {
|
|
@@ -127,6 +307,10 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
127
307
|
bindGroup.setValue('zMetallic', this._metallic);
|
|
128
308
|
bindGroup.setValue('zRoughness', this._roughness);
|
|
129
309
|
bindGroup.setValue('zSpecularFactor', this._specularFactor);
|
|
310
|
+
bindGroup.setValue('zReflectionMode', PBR_REFLECTION_MODE[this._reflectionMode]);
|
|
311
|
+
bindGroup.setValue('zAnisotropy', this._anisotropy);
|
|
312
|
+
bindGroup.setValue('zAnisotropyDirection', this._anisotropyDirection);
|
|
313
|
+
bindGroup.setValue('zAnisotropyDirectionScaleBias', this._anisotropyDirectionScaleBias);
|
|
130
314
|
}
|
|
131
315
|
}
|
|
132
316
|
}
|
|
@@ -147,6 +331,7 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
147
331
|
const metallic = this.calculateMetallic(scope, albedo, normal);
|
|
148
332
|
const roughness = this.calculateRoughness(scope, albedo, normal);
|
|
149
333
|
const specularFactor = this.calculateSpecularFactor(scope, albedo, normal);
|
|
334
|
+
const reflectionMode = this.calculateReflectionMode(scope);
|
|
150
335
|
if (this.metallicRoughnessTexture) {
|
|
151
336
|
scope.$l.metallicRoughnessSample = this.sampleMetallicRoughnessTexture(scope);
|
|
152
337
|
data.metallic = pb.mul(metallic, scope.metallicRoughnessSample.z);
|
|
@@ -166,11 +351,21 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
166
351
|
} else {
|
|
167
352
|
data.specularWeight = specularFactor.a;
|
|
168
353
|
}
|
|
354
|
+
data.specularWeight = pb.mul(data.specularWeight, pb.float(pb.notEqual(reflectionMode, PBR_REFLECTION_MODE.none)));
|
|
169
355
|
data.f0 = pb.vec4(pb.mix(pb.min(pb.mul(this.getF0(scope).rgb, scope.specularColor), pb.vec3(1)), albedo.rgb, data.metallic), this.getF0(scope).a);
|
|
170
356
|
data.f90 = pb.vec3(1);
|
|
171
357
|
data.diffuse = pb.vec4(pb.mix(albedo.rgb, pb.vec3(0), data.metallic), albedo.a);
|
|
172
358
|
super.calculateCommonData(scope, albedo, normal, viewVec, TBN, data);
|
|
173
359
|
}
|
|
360
|
+
calculateReflectionMode(scope) {
|
|
361
|
+
return scope.zReflectionMode;
|
|
362
|
+
}
|
|
363
|
+
calculateAnisotropy(scope) {
|
|
364
|
+
return scope.zAnisotropy;
|
|
365
|
+
}
|
|
366
|
+
calculateAnisotropyDirection(scope) {
|
|
367
|
+
return scope.zAnisotropyDirection;
|
|
368
|
+
}
|
|
174
369
|
};
|
|
175
370
|
}
|
|
176
371
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbrmetallicroughness.js","sources":["../../../../src/material/mixins/lightmodel/pbrmetallicroughness.ts"],"sourcesContent":["import type { BindGroup, PBFunctionScope, PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport type { MeshMaterial } from '../../meshmaterial';\r\nimport { applyMaterialMixins } from '../../meshmaterial';\r\nimport type { TextureMixinInstanceTypes } from '../texture';\r\nimport { mixinTextureProps } from '../texture';\r\nimport type { IMixinPBRCommon } from '../pbr/common';\r\nimport { mixinPBRCommon } from '../pbr/common';\r\nimport type { DrawContext } from '../../../render';\r\nimport type { Immutable } from '@zephyr3d/base';\r\nimport { Vector4 } from '@zephyr3d/base';\r\nimport type { IMixinLight } from '../lit';\r\nimport { mixinLight } from '../lit';\r\nimport { ShaderHelper } from '../../shader/helper';\r\nimport { MaterialVaryingFlags } from '../../../values';\r\n\r\n/**\r\n * Interface for PBRMetallicRoughness lighting model mixin\r\n * @public\r\n */\r\nexport type IMixinPBRMetallicRoughness = {\r\n metallic: number;\r\n roughness: number;\r\n specularFactor: Vector4;\r\n PBRLight(\r\n scope: PBInsideFunctionScope,\r\n worldPos: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n albedo: PBShaderExp,\r\n TBN: PBShaderExp,\r\n outRoughness?: PBShaderExp\r\n ): PBShaderExp;\r\n calculateMetallic(scope: PBInsideFunctionScope, albedo: PBShaderExp, normal: PBShaderExp): PBShaderExp;\r\n calculateRoughness(scope: PBInsideFunctionScope, albedo: PBShaderExp, normal: PBShaderExp): PBShaderExp;\r\n calculateSpecularFactor(\r\n scope: PBInsideFunctionScope,\r\n albedo: PBShaderExp,\r\n normal: PBShaderExp\r\n ): PBShaderExp;\r\n calculateCommonData(\r\n scope: PBInsideFunctionScope,\r\n albedo: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n TBN: PBShaderExp,\r\n data: PBShaderExp\r\n ): void;\r\n} & IMixinPBRCommon &\r\n IMixinLight &\r\n TextureMixinInstanceTypes<['metallicRoughness', 'occlusion', 'specular', 'specularColor']>;\r\n\r\n/**\r\n * PBRMetallicRoughness lighting model mixin\r\n * @param BaseCls - Class to mix in\r\n * @returns Mixed class\r\n * @public\r\n */\r\nexport function mixinPBRMetallicRoughness<T extends typeof MeshMaterial>(BaseCls: T) {\r\n if ((BaseCls as any).pbrMetallicRoughnessMixed) {\r\n return BaseCls as T & { new (...args: any[]): IMixinPBRMetallicRoughness };\r\n }\r\n const S = applyMaterialMixins(\r\n BaseCls,\r\n mixinPBRCommon,\r\n mixinLight,\r\n mixinTextureProps('metallicRoughness'),\r\n mixinTextureProps('specular'),\r\n mixinTextureProps('specularColor')\r\n );\r\n const METALLIC_UNIFORM = S.defineInstanceUniform('metallic', 'float', 'Metallic');\r\n const ROUGHNESS_UNIFORM = S.defineInstanceUniform('roughness', 'float', 'Roughness');\r\n const SPECULAR_FACTOR_UNFORM = S.defineInstanceUniform('specularFactor', 'rgba', 'SpecularFactor');\r\n\r\n return class extends S {\r\n static readonly pbrMetallicRoughnessMixed = true;\r\n private _metallic: number;\r\n private _roughness: number;\r\n private readonly _specularFactor: Vector4;\r\n constructor() {\r\n super();\r\n this._metallic = 1;\r\n this._roughness = 1;\r\n this._specularFactor = Vector4.one();\r\n }\r\n copyFrom(other: this) {\r\n super.copyFrom(other);\r\n this.metallic = other.metallic;\r\n this.roughness = other.roughness;\r\n this.specularFactor = other.specularFactor;\r\n }\r\n get metallic() {\r\n return this._metallic;\r\n }\r\n set metallic(val) {\r\n if (val !== this._metallic) {\r\n this._metallic = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get roughness() {\r\n return this._roughness;\r\n }\r\n set roughness(val) {\r\n if (val !== this._roughness) {\r\n this._roughness = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get specularFactor(): Immutable<Vector4> {\r\n return this._specularFactor;\r\n }\r\n set specularFactor(val: Immutable<Vector4>) {\r\n if (!val.equalsTo(this._specularFactor)) {\r\n this._specularFactor.set(val);\r\n this.uniformChanged();\r\n }\r\n }\r\n PBRLight(\r\n scope: PBInsideFunctionScope,\r\n worldPos: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n albedo: PBShaderExp,\r\n TBN: PBShaderExp,\r\n outRoughness?: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_PBRMetallicRoughnessLight';\r\n const that = this;\r\n pb.func(\r\n funcName,\r\n [\r\n pb.vec3('worldPos'),\r\n pb.vec3('normal'),\r\n pb.mat3('TBN'),\r\n pb.vec3('viewVec'),\r\n pb.vec4('albedo'),\r\n ...(outRoughness ? [pb.vec4('outRoughness').out()] : [])\r\n ],\r\n function () {\r\n this.$l.pbrData = that.getCommonData(this, this.albedo, this.normal, this.viewVec, this.TBN);\r\n this.$l.lightingColor = pb.vec3(0);\r\n this.$l.emissiveColor = that.calculateEmissiveColor(this);\r\n if (outRoughness) {\r\n that.indirectLighting(\r\n this,\r\n this.normal,\r\n this.viewVec,\r\n this.pbrData,\r\n this.lightingColor,\r\n this.outRoughness\r\n );\r\n } else {\r\n that.indirectLighting(this, this.normal, this.viewVec, this.pbrData, this.lightingColor);\r\n }\r\n that.forEachLight(this, function (type, posRange, dirCutoff, colorIntensity, shadow) {\r\n this.$l.diffuse = pb.vec3();\r\n this.$l.specular = pb.vec3();\r\n this.$l.lightAtten = that.calculateLightAttenuation(\r\n this,\r\n type,\r\n this.worldPos,\r\n posRange,\r\n dirCutoff\r\n );\r\n this.$l.lightDir = that.calculateLightDirection(this, type, this.worldPos, posRange, dirCutoff);\r\n this.$l.NoL = pb.clamp(pb.dot(this.normal, this.lightDir), 0, 1);\r\n this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten, this.NoL);\r\n if (shadow) {\r\n this.lightColor = pb.mul(this.lightColor, that.calculateShadow(this, this.worldPos, this.NoL));\r\n }\r\n that.directLighting(\r\n this,\r\n this.lightDir,\r\n this.lightColor,\r\n this.normal,\r\n this.viewVec,\r\n this.pbrData,\r\n this.lightingColor\r\n );\r\n });\r\n this.$return(pb.add(this.lightingColor, this.emissiveColor));\r\n }\r\n );\r\n return (\r\n outRoughness\r\n ? pb.getGlobalScope()[funcName](worldPos, normal, TBN, viewVec, albedo, outRoughness)\r\n : pb.getGlobalScope()[funcName](worldPos, normal, TBN, viewVec, albedo)\r\n ) as PBShaderExp;\r\n }\r\n vertexShader(scope: PBFunctionScope) {\r\n super.vertexShader(scope);\r\n if (this.needFragmentColor() && this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING) {\r\n scope.$outputs.zMetallic = this.getInstancedUniform(scope, METALLIC_UNIFORM);\r\n scope.$outputs.zRoughness = this.getInstancedUniform(scope, ROUGHNESS_UNIFORM);\r\n scope.$outputs.zSpecularFactor = this.getInstancedUniform(scope, SPECULAR_FACTOR_UNFORM);\r\n }\r\n }\r\n fragmentShader(scope: PBFunctionScope) {\r\n super.fragmentShader(scope);\r\n if (this.needFragmentColor()) {\r\n const pb = scope.$builder;\r\n if (!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING)) {\r\n scope.zMetallic = pb.float().uniform(2);\r\n scope.zRoughness = pb.float().uniform(2);\r\n scope.zSpecularFactor = pb.vec4().uniform(2);\r\n }\r\n }\r\n }\r\n applyUniformValues(bindGroup: BindGroup, ctx: DrawContext, pass: number) {\r\n super.applyUniformValues(bindGroup, ctx, pass);\r\n if (this.needFragmentColor(ctx)) {\r\n if (!(ctx.materialFlags & MaterialVaryingFlags.INSTANCING)) {\r\n bindGroup.setValue('zMetallic', this._metallic);\r\n bindGroup.setValue('zRoughness', this._roughness);\r\n bindGroup.setValue('zSpecularFactor', this._specularFactor);\r\n }\r\n }\r\n }\r\n calculateMetallic(scope: PBInsideFunctionScope, _albedo: PBShaderExp, _normal: PBShaderExp) {\r\n const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);\r\n return (instancing ? scope.$inputs.zMetallic : scope.zMetallic) as PBShaderExp;\r\n }\r\n calculateRoughness(scope: PBInsideFunctionScope, _albedo: PBShaderExp, _normal: PBShaderExp) {\r\n const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);\r\n return (instancing ? scope.$inputs.zRoughness : scope.zRoughness) as PBShaderExp;\r\n }\r\n calculateSpecularFactor(scope: PBInsideFunctionScope, _albedo: PBShaderExp, _normal: PBShaderExp) {\r\n const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);\r\n return (instancing ? scope.$inputs.zSpecularFactor : scope.zSpecularFactor) as PBShaderExp;\r\n }\r\n calculateCommonData(\r\n scope: PBInsideFunctionScope,\r\n albedo: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n TBN: PBShaderExp,\r\n data: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n const metallic = this.calculateMetallic(scope, albedo, normal);\r\n const roughness = this.calculateRoughness(scope, albedo, normal);\r\n const specularFactor = this.calculateSpecularFactor(scope, albedo, normal);\r\n if (this.metallicRoughnessTexture) {\r\n scope.$l.metallicRoughnessSample = this.sampleMetallicRoughnessTexture(scope);\r\n data.metallic = pb.mul(metallic, scope.metallicRoughnessSample.z);\r\n data.roughness = pb.mul(roughness, scope.metallicRoughnessSample.y);\r\n } else {\r\n data.metallic = metallic;\r\n data.roughness = roughness;\r\n }\r\n data.roughness = pb.mul(data.roughness, ShaderHelper.getCameraRoughnessFactor(scope));\r\n if (this.specularColorTexture) {\r\n scope.$l.specularColor = pb.mul(specularFactor.rgb, this.sampleSpecularColorTexture(scope).rgb);\r\n } else {\r\n scope.$l.specularColor = specularFactor.rgb;\r\n }\r\n if (this.specularTexture) {\r\n data.specularWeight = pb.mul(specularFactor.a, this.sampleSpecularTexture(scope).a);\r\n } else {\r\n data.specularWeight = specularFactor.a;\r\n }\r\n data.f0 = pb.vec4(\r\n pb.mix(\r\n pb.min(pb.mul(this.getF0(scope).rgb, scope.specularColor), pb.vec3(1)),\r\n albedo.rgb,\r\n data.metallic\r\n ),\r\n this.getF0(scope).a\r\n );\r\n data.f90 = pb.vec3(1);\r\n data.diffuse = pb.vec4(pb.mix(albedo.rgb, pb.vec3(0), data.metallic), albedo.a);\r\n super.calculateCommonData(scope, albedo, normal, viewVec, TBN, data);\r\n }\r\n } as unknown as T & { new (...args: any[]): IMixinPBRMetallicRoughness };\r\n}\r\n"],"names":["mixinPBRMetallicRoughness","BaseCls","pbrMetallicRoughnessMixed","S","applyMaterialMixins","mixinPBRCommon","mixinLight","mixinTextureProps","METALLIC_UNIFORM","defineInstanceUniform","ROUGHNESS_UNIFORM","SPECULAR_FACTOR_UNFORM","_metallic","_roughness","_specularFactor","Vector4","one","copyFrom","other","metallic","roughness","specularFactor","val","uniformChanged","equalsTo","set","PBRLight","scope","worldPos","normal","viewVec","albedo","TBN","outRoughness","pb","$builder","funcName","that","func","vec3","mat3","vec4","out","$l","pbrData","getCommonData","lightingColor","emissiveColor","calculateEmissiveColor","indirectLighting","forEachLight","type","posRange","dirCutoff","colorIntensity","shadow","diffuse","specular","lightAtten","calculateLightAttenuation","lightDir","calculateLightDirection","NoL","clamp","dot","lightColor","mul","rgb","a","calculateShadow","directLighting","$return","add","getGlobalScope","vertexShader","needFragmentColor","drawContext","materialFlags","MaterialVaryingFlags","INSTANCING","$outputs","zMetallic","getInstancedUniform","zRoughness","zSpecularFactor","fragmentShader","float","uniform","applyUniformValues","bindGroup","ctx","pass","setValue","calculateMetallic","_albedo","_normal","instancing","$inputs","calculateRoughness","calculateSpecularFactor","calculateCommonData","data","metallicRoughnessTexture","metallicRoughnessSample","sampleMetallicRoughnessTexture","z","y","ShaderHelper","getCameraRoughnessFactor","specularColorTexture","specularColor","sampleSpecularColorTexture","specularTexture","specularWeight","sampleSpecularTexture","f0","mix","min","getF0","f90"],"mappings":";;;;;;;;AAmDA;;;;;IAMO,SAASA,yBAAAA,CAAyDC,OAAU,EAAA;IACjF,IAAKA,OAAgBC,CAAAA,yBAAyB,EAAE;QAC9C,OAAOD,OAAAA;AACT;IACA,MAAME,CAAAA,GAAIC,oBACRH,OACAI,EAAAA,cAAAA,EACAC,YACAC,iBAAkB,CAAA,mBAAA,CAAA,EAClBA,iBAAkB,CA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AA,KAAK,CAACgC,mBAAoBzE,CAAAA,KAAAA,EAAOI,MAAQF,EAAAA,MAAAA,EAAQC,SAASE,GAAKqE,EAAAA,IAAAA,CAAAA;AACjE;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"pbrmetallicroughness.js","sources":["../../../../src/material/mixins/lightmodel/pbrmetallicroughness.ts"],"sourcesContent":["import type { BindGroup, PBFunctionScope, PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport type { MeshMaterial } from '../../meshmaterial';\r\nimport { applyMaterialMixins } from '../../meshmaterial';\r\nimport type { TextureMixinInstanceTypes } from '../texture';\r\nimport { mixinTextureProps } from '../texture';\r\nimport type { IMixinPBRCommon } from '../pbr/common';\r\nimport { mixinPBRCommon } from '../pbr/common';\r\nimport type { DrawContext } from '../../../render';\r\nimport type { Immutable } from '@zephyr3d/base';\r\nimport { Vector2, Vector4 } from '@zephyr3d/base';\r\nimport type { IMixinLight } from '../lit';\r\nimport { mixinLight } from '../lit';\r\nimport { ShaderHelper } from '../../shader/helper';\r\nimport {\r\n LIGHT_TYPE_POINT,\r\n LIGHT_TYPE_RECT,\r\n MaterialVaryingFlags,\r\n RENDER_PASS_TYPE_LIGHT\r\n} from '../../../values';\r\n\r\nexport type PBRReflectionMode = 'none' | 'ggx' | 'anisotropic' | 'glint';\r\n\r\nconst PBR_REFLECTION_MODE: Record<PBRReflectionMode, number> = {\r\n none: 0,\r\n ggx: 1,\r\n anisotropic: 2,\r\n glint: 3\r\n};\r\n\r\n/**\r\n * Interface for PBRMetallicRoughness lighting model mixin\r\n * @public\r\n */\r\nexport type IMixinPBRMetallicRoughness = {\r\n metallic: number;\r\n roughness: number;\r\n specularFactor: Vector4;\r\n reflectionMode: PBRReflectionMode;\r\n anisotropy: number;\r\n anisotropyDirection: number;\r\n anisotropyDirectionScaleBias: Vector2;\r\n PBRLight(\r\n scope: PBInsideFunctionScope,\r\n worldPos: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n albedo: PBShaderExp,\r\n TBN: PBShaderExp,\r\n outRoughness?: PBShaderExp\r\n ): PBShaderExp;\r\n calculateMetallic(scope: PBInsideFunctionScope, albedo: PBShaderExp, normal: PBShaderExp): PBShaderExp;\r\n calculateRoughness(scope: PBInsideFunctionScope, albedo: PBShaderExp, normal: PBShaderExp): PBShaderExp;\r\n calculateSpecularFactor(\r\n scope: PBInsideFunctionScope,\r\n albedo: PBShaderExp,\r\n normal: PBShaderExp\r\n ): PBShaderExp;\r\n calculateCommonData(\r\n scope: PBInsideFunctionScope,\r\n albedo: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n TBN: PBShaderExp,\r\n data: PBShaderExp\r\n ): void;\r\n} & IMixinPBRCommon &\r\n IMixinLight &\r\n TextureMixinInstanceTypes<\r\n ['metallicRoughness', 'occlusion', 'specular', 'specularColor', 'anisotropyDirection']\r\n >;\r\n\r\n/**\r\n * PBRMetallicRoughness lighting model mixin\r\n * @param BaseCls - Class to mix in\r\n * @returns Mixed class\r\n * @public\r\n */\r\nexport function mixinPBRMetallicRoughness<T extends typeof MeshMaterial>(BaseCls: T) {\r\n if ((BaseCls as any).pbrMetallicRoughnessMixed) {\r\n return BaseCls as T & { new (...args: any[]): IMixinPBRMetallicRoughness };\r\n }\r\n const S = applyMaterialMixins(\r\n BaseCls,\r\n mixinPBRCommon,\r\n mixinLight,\r\n mixinTextureProps('metallicRoughness'),\r\n mixinTextureProps('specular'),\r\n mixinTextureProps('specularColor'),\r\n mixinTextureProps('anisotropyDirection')\r\n );\r\n const METALLIC_UNIFORM = S.defineInstanceUniform('metallic', 'float', 'Metallic');\r\n const ROUGHNESS_UNIFORM = S.defineInstanceUniform('roughness', 'float', 'Roughness');\r\n const SPECULAR_FACTOR_UNFORM = S.defineInstanceUniform('specularFactor', 'rgba', 'SpecularFactor');\r\n\r\n return class extends S {\r\n static readonly pbrMetallicRoughnessMixed = true;\r\n private _metallic: number;\r\n private _roughness: number;\r\n private readonly _specularFactor: Vector4;\r\n private _reflectionMode: PBRReflectionMode;\r\n private _anisotropy: number;\r\n private _anisotropyDirection: number;\r\n private readonly _anisotropyDirectionScaleBias: Vector2;\r\n constructor() {\r\n super();\r\n this._metallic = 1;\r\n this._roughness = 1;\r\n this._specularFactor = Vector4.one();\r\n this._reflectionMode = 'ggx';\r\n this._anisotropy = 0.75;\r\n this._anisotropyDirection = 0;\r\n this._anisotropyDirectionScaleBias = new Vector2(1, 0);\r\n }\r\n copyFrom(other: this) {\r\n super.copyFrom(other);\r\n this.metallic = other.metallic;\r\n this.roughness = other.roughness;\r\n this.specularFactor = other.specularFactor;\r\n this.reflectionMode = other.reflectionMode;\r\n this.anisotropy = other.anisotropy;\r\n this.anisotropyDirection = other.anisotropyDirection;\r\n this.anisotropyDirectionScaleBias = other.anisotropyDirectionScaleBias;\r\n }\r\n get metallic() {\r\n return this._metallic;\r\n }\r\n set metallic(val) {\r\n if (val !== this._metallic) {\r\n this._metallic = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get roughness() {\r\n return this._roughness;\r\n }\r\n set roughness(val) {\r\n if (val !== this._roughness) {\r\n this._roughness = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get specularFactor(): Immutable<Vector4> {\r\n return this._specularFactor;\r\n }\r\n set specularFactor(val: Immutable<Vector4>) {\r\n if (!val.equalsTo(this._specularFactor)) {\r\n this._specularFactor.set(val);\r\n this.uniformChanged();\r\n }\r\n }\r\n directLighting(\r\n scope: PBInsideFunctionScope,\r\n lightDir: PBShaderExp,\r\n lightColor: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n commonData: PBShaderExp,\r\n diffuseScale: PBShaderExp,\r\n specularScale: PBShaderExp,\r\n sourceRadiusFactor: PBShaderExp,\r\n outColor: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n const that = this as any;\r\n const funcName = 'Z_PBRMR_DirectLighting';\r\n pb.func(\r\n funcName,\r\n [\r\n pb.vec3('L'),\r\n pb.vec3('lightColor'),\r\n pb.vec3('normal'),\r\n pb.vec3('viewVec'),\r\n that.getCommonDatasStruct(scope)('data'),\r\n pb.float('diffuseScale'),\r\n pb.float('specularScale'),\r\n pb.float('sourceRadiusFactor'),\r\n pb.vec3('outColor').inout()\r\n ],\r\n function () {\r\n this.$l.reflectionMode = this.zReflectionMode;\r\n this.$l.anisotropy = this.zAnisotropy;\r\n this.$l.anisotropyDirection = this.zAnisotropyDirection;\r\n this.$l.anisotropyDirectionScaleBias = this.zAnisotropyDirectionScaleBias;\r\n this.$l.H = pb.normalize(pb.add(this.viewVec, this.L));\r\n this.$l.NoH = pb.clamp(pb.dot(this.normal, this.H), 0, 1);\r\n this.$l.NoL = pb.clamp(pb.dot(this.normal, this.L), 0, 1);\r\n this.$l.NoV = pb.clamp(pb.dot(this.normal, this.viewVec), 0, 1);\r\n this.$if(pb.greaterThan(this.NoL, 0), function () {\r\n this.$l.VoH = pb.clamp(pb.dot(this.viewVec, this.H), 0, 1);\r\n this.$l.schlickFresnel = that.fresnelSchlick(this, this.VoH, this.data.f0.rgb, this.data.f90);\r\n if (that.iridescence) {\r\n this.$l.F = pb.mix(\r\n this.schlickFresnel,\r\n this.data.iridescenceFresnel,\r\n this.data.iridescenceFactor.x\r\n );\r\n } else {\r\n this.$l.F = this.schlickFresnel;\r\n }\r\n this.$l.specularRoughness = pb.clamp(pb.add(this.data.roughness, this.sourceRadiusFactor), 0, 1);\r\n this.$l.alphaRoughness = pb.mul(this.specularRoughness, this.specularRoughness);\r\n this.$l.Dggx = that.distributionGGX(this, this.NoH, this.alphaRoughness);\r\n this.$l.D = this.Dggx;\r\n this.$if(pb.equal(this.reflectionMode, PBR_REFLECTION_MODE.anisotropic), function () {\r\n this.$l.dirAngle = pb.mul(this.anisotropyDirection, Math.PI / 180);\r\n if (that.anisotropyDirectionTexture) {\r\n this.$l.dirSample = that.sampleAnisotropyDirectionTexture(this);\r\n this.$l.dirAngle = pb.mul(\r\n pb.add(\r\n pb.mul(this.dirSample.r, this.anisotropyDirectionScaleBias.x),\r\n this.anisotropyDirectionScaleBias.y\r\n ),\r\n Math.PI / 180\r\n );\r\n }\r\n this.$l.anisoAngle = this.dirAngle;\r\n this.$l.up = pb.vec3(0, 1, 0);\r\n this.$l.t0 = pb.normalize(pb.cross(this.up, this.normal));\r\n this.$if(pb.lessThan(pb.length(this.t0), 0.001), function () {\r\n this.t0 = pb.normalize(pb.cross(pb.vec3(1, 0, 0), this.normal));\r\n });\r\n this.$l.b0 = pb.normalize(pb.cross(this.normal, this.t0));\r\n this.$l.tangent = pb.normalize(\r\n pb.add(pb.mul(this.t0, pb.cos(this.anisoAngle)), pb.mul(this.b0, pb.sin(this.anisoAngle)))\r\n );\r\n this.$l.bitangent = pb.normalize(pb.cross(this.normal, this.tangent));\r\n this.$l.ToH = pb.dot(this.tangent, this.H);\r\n this.$l.BoH = pb.dot(this.bitangent, this.H);\r\n this.$l.at = pb.max(pb.mul(this.alphaRoughness, pb.add(1, this.anisotropy)), 0.0001);\r\n this.$l.ab = pb.max(pb.mul(this.alphaRoughness, pb.sub(1, this.anisotropy)), 0.0001);\r\n this.$l.anisoDenom = pb.mul(\r\n Math.PI,\r\n this.at,\r\n this.ab,\r\n pb.pow(\r\n pb.add(\r\n pb.div(pb.mul(this.ToH, this.ToH), pb.mul(this.at, this.at)),\r\n pb.div(pb.mul(this.BoH, this.BoH), pb.mul(this.ab, this.ab)),\r\n pb.mul(this.NoH, this.NoH)\r\n ),\r\n 2\r\n )\r\n );\r\n this.D = pb.div(1, pb.max(this.anisoDenom, 0.0001));\r\n }).$elseif(pb.equal(this.reflectionMode, PBR_REFLECTION_MODE.glint), function () {\r\n this.$l.glintNoise = pb.fract(\r\n pb.mul(\r\n pb.sin(pb.add(pb.dot(this.H, pb.vec3(127.1, 311.7, 74.7)), pb.mul(this.NoH, 43.1))),\r\n 43758.5453\r\n )\r\n );\r\n this.$l.glintMask = pb.smoothStep(0.97, 1, this.glintNoise);\r\n this.D = pb.mul(this.Dggx, pb.add(1, pb.mul(this.glintMask, 8)));\r\n });\r\n this.$l.V = that.visGGX(this, this.NoV, this.NoL, this.alphaRoughness);\r\n this.$l.specular = pb.mul(\r\n this.lightColor,\r\n this.D,\r\n this.V,\r\n this.F,\r\n this.data.specularWeight,\r\n this.specularScale\r\n );\r\n if (that.sheen) {\r\n this.specular = pb.mul(this.specular, this.data.sheenAlbedoScaling);\r\n }\r\n this.$if(pb.equal(this.reflectionMode, PBR_REFLECTION_MODE.none), function () {\r\n this.specular = pb.vec3(0);\r\n });\r\n this.outColor = pb.add(this.outColor, this.specular);\r\n if (that.iridescence) {\r\n this.$l.iridescenceFresnelMax = pb.vec3(\r\n pb.max(\r\n pb.max(this.data.iridescenceFresnel.r, this.data.iridescenceFresnel.g),\r\n this.data.iridescenceFresnel.b\r\n )\r\n );\r\n this.F = pb.mix(this.schlickFresnel, this.iridescenceFresnelMax, this.data.iridescenceFactor.x);\r\n }\r\n this.$l.diffuseBRDF = pb.mul(\r\n pb.sub(pb.vec3(1), pb.mul(this.F, this.data.specularWeight)),\r\n pb.div(this.data.diffuse.rgb, Math.PI)\r\n );\r\n this.$l.diffuse = pb.mul(\r\n this.lightColor,\r\n pb.max(this.diffuseBRDF, pb.vec3(0)),\r\n this.diffuseScale\r\n );\r\n if (that.transmission && that.drawContext.renderPass!.type === RENDER_PASS_TYPE_LIGHT) {\r\n this.$l.transmissionRay = that.getVolumeTransmissionRay(\r\n this,\r\n this.normal,\r\n this.viewVec,\r\n this.data.thicknessFactor,\r\n this.data.f0.a\r\n );\r\n this.$l.pointToLight = pb.normalize(pb.sub(this.L, this.transmissionRay));\r\n this.$l.transmittedLight = pb.mul(\r\n this.lightColor,\r\n that.getPunctualRadianceTransmission(\r\n this,\r\n this.normal,\r\n this.viewVec,\r\n this.pointToLight,\r\n this.alphaRoughness,\r\n this.data.f0.rgb,\r\n this.data.f90.rgb,\r\n this.data.diffuse.rgb,\r\n this.data.f0.a\r\n )\r\n );\r\n this.transmittedLight = that.applyVolumeAttenuation(\r\n this,\r\n this.transmittedLight,\r\n pb.length(this.transmissionRay),\r\n this.data.attenuationColor,\r\n this.data.attenuationDistance\r\n );\r\n this.diffuse = pb.mix(this.diffuse, this.transmittedLight, this.data.transmissionFactor);\r\n }\r\n if (that.sheen) {\r\n this.diffuse = pb.mul(this.diffuse, this.data.sheenAlbedoScaling);\r\n }\r\n this.outColor = pb.add(this.outColor, this.diffuse);\r\n if (that.sheen) {\r\n this.$l.sheenD = that.D_Charlie(this, this.NoH, this.data.sheenRoughness);\r\n this.$l.sheenV = that.V_Ashikhmin(this, this.NoL, this.NoV);\r\n this.outColor = pb.add(\r\n this.outColor,\r\n pb.mul(this.lightColor, this.data.sheenColor, this.sheenD, this.sheenV)\r\n );\r\n }\r\n if (that.clearcoat) {\r\n this.alphaRoughness = pb.mul(this.data.ccFactor.y, this.data.ccFactor.y);\r\n this.NoH = pb.clamp(pb.dot(this.data.ccNormal, this.H), 0, 1);\r\n this.NoL = pb.clamp(pb.dot(this.data.ccNormal, this.L), 0, 1);\r\n this.ccF0 = pb.vec3(pb.pow(pb.div(pb.sub(this.data.f0.a, 1), pb.add(this.data.f0.a, 1)), 2));\r\n this.F = that.fresnelSchlick(this, this.VoH, this.ccF0, pb.vec3(1));\r\n this.D = that.distributionGGX(this, this.NoH, this.alphaRoughness);\r\n this.V = that.visGGX(this, this.data.ccNoV, this.NoL, this.alphaRoughness);\r\n this.outColor = pb.add(this.outColor, pb.mul(this.D, this.V, this.F, this.data.ccFactor.x));\r\n }\r\n });\r\n }\r\n );\r\n scope.$g[funcName](\r\n lightDir,\r\n lightColor,\r\n normal,\r\n viewVec,\r\n commonData,\r\n diffuseScale,\r\n specularScale,\r\n sourceRadiusFactor,\r\n outColor\r\n );\r\n }\r\n get reflectionMode() {\r\n return this._reflectionMode;\r\n }\r\n set reflectionMode(val: PBRReflectionMode) {\r\n if (val !== this._reflectionMode) {\r\n this._reflectionMode = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get anisotropy() {\r\n return this._anisotropy;\r\n }\r\n set anisotropy(val) {\r\n const clamped = Math.max(-0.95, Math.min(0.95, val));\r\n if (clamped !== this._anisotropy) {\r\n this._anisotropy = clamped;\r\n this.uniformChanged();\r\n }\r\n }\r\n get anisotropyDirection() {\r\n return this._anisotropyDirection;\r\n }\r\n set anisotropyDirection(val) {\r\n if (val !== this._anisotropyDirection) {\r\n this._anisotropyDirection = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get anisotropyDirectionScaleBias(): Immutable<Vector2> {\r\n return this._anisotropyDirectionScaleBias;\r\n }\r\n set anisotropyDirectionScaleBias(val: Immutable<Vector2>) {\r\n if (!val.equalsTo(this._anisotropyDirectionScaleBias)) {\r\n this._anisotropyDirectionScaleBias.set(val);\r\n this.uniformChanged();\r\n }\r\n }\r\n calculateAnisotropyDirectionScaleBias(scope: PBInsideFunctionScope) {\r\n return scope.zAnisotropyDirectionScaleBias as PBShaderExp;\r\n }\r\n PBRLight(\r\n scope: PBInsideFunctionScope,\r\n worldPos: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n albedo: PBShaderExp,\r\n TBN: PBShaderExp,\r\n outRoughness?: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n const funcName = 'Z_PBRMetallicRoughnessLight';\r\n const that = this;\r\n pb.func(\r\n funcName,\r\n [\r\n pb.vec3('worldPos'),\r\n pb.vec3('normal'),\r\n pb.mat3('TBN'),\r\n pb.vec3('viewVec'),\r\n pb.vec4('albedo'),\r\n ...(outRoughness ? [pb.vec4('outRoughness').out()] : [])\r\n ],\r\n function () {\r\n this.$l.pbrData = that.getCommonData(this, this.albedo, this.normal, this.viewVec, this.TBN);\r\n this.$l.lightingColor = pb.vec3(0);\r\n this.$l.emissiveColor = that.calculateEmissiveColor(this);\r\n if (outRoughness) {\r\n that.indirectLighting(\r\n this,\r\n this.normal,\r\n this.viewVec,\r\n this.pbrData,\r\n this.lightingColor,\r\n this.outRoughness\r\n );\r\n } else {\r\n that.indirectLighting(this, this.normal, this.viewVec, this.pbrData, this.lightingColor);\r\n }\r\n that.forEachLight(this, function (type, posRange, dirCutoff, colorIntensity, extra, shadow) {\r\n this.$if(pb.equal(type, LIGHT_TYPE_RECT), function () {\r\n that.directRectLight(\r\n this,\r\n this.worldPos,\r\n this.normal,\r\n this.viewVec,\r\n this.pbrData,\r\n posRange,\r\n dirCutoff,\r\n extra,\r\n colorIntensity,\r\n this.lightingColor\r\n );\r\n }).$else(function () {\r\n this.$l.diffuse = pb.vec3();\r\n this.$l.specular = pb.vec3();\r\n this.$l.diffuseScale = pb.float(1);\r\n this.$l.specularScale = pb.float(1);\r\n this.$l.sourceRadiusFactor = pb.float(0);\r\n this.$if(pb.equal(type, LIGHT_TYPE_POINT), function () {\r\n this.diffuseScale = extra.x;\r\n this.specularScale = extra.y;\r\n this.sourceRadiusFactor = pb.div(\r\n extra.z,\r\n pb.max(pb.distance(posRange.xyz, this.worldPos), 0.0001)\r\n );\r\n });\r\n this.$l.lightAtten = that.calculateLightAttenuation(\r\n this,\r\n type,\r\n this.worldPos,\r\n posRange,\r\n dirCutoff\r\n );\r\n this.$l.lightDir = that.calculateLightDirection(this, type, this.worldPos, posRange, dirCutoff);\r\n this.$l.NoL = pb.clamp(pb.dot(this.normal, this.lightDir), 0, 1);\r\n this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten, this.NoL);\r\n if (shadow) {\r\n this.lightColor = pb.mul(\r\n this.lightColor,\r\n that.calculateShadow(this, this.worldPos, this.NoL)\r\n );\r\n }\r\n that.directLighting(\r\n this,\r\n this.lightDir,\r\n this.lightColor,\r\n this.normal,\r\n this.viewVec,\r\n this.pbrData,\r\n this.diffuseScale,\r\n this.specularScale,\r\n this.sourceRadiusFactor,\r\n this.lightingColor\r\n );\r\n });\r\n });\r\n this.$return(pb.add(this.lightingColor, this.emissiveColor));\r\n }\r\n );\r\n return (\r\n outRoughness\r\n ? pb.getGlobalScope()[funcName](worldPos, normal, TBN, viewVec, albedo, outRoughness)\r\n : pb.getGlobalScope()[funcName](worldPos, normal, TBN, viewVec, albedo)\r\n ) as PBShaderExp;\r\n }\r\n vertexShader(scope: PBFunctionScope) {\r\n super.vertexShader(scope);\r\n if (this.needFragmentColor() && this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING) {\r\n scope.$outputs.zMetallic = this.getInstancedUniform(scope, METALLIC_UNIFORM);\r\n scope.$outputs.zRoughness = this.getInstancedUniform(scope, ROUGHNESS_UNIFORM);\r\n scope.$outputs.zSpecularFactor = this.getInstancedUniform(scope, SPECULAR_FACTOR_UNFORM);\r\n }\r\n }\r\n fragmentShader(scope: PBFunctionScope) {\r\n super.fragmentShader(scope);\r\n if (this.needFragmentColor()) {\r\n const pb = scope.$builder;\r\n if (!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING)) {\r\n scope.zMetallic = pb.float().uniform(2);\r\n scope.zRoughness = pb.float().uniform(2);\r\n scope.zSpecularFactor = pb.vec4().uniform(2);\r\n }\r\n scope.zReflectionMode = pb.float().uniform(2);\r\n scope.zAnisotropy = pb.float().uniform(2);\r\n scope.zAnisotropyDirection = pb.float().uniform(2);\r\n scope.zAnisotropyDirectionScaleBias = pb.vec2().uniform(2);\r\n }\r\n }\r\n applyUniformValues(bindGroup: BindGroup, ctx: DrawContext, pass: number) {\r\n super.applyUniformValues(bindGroup, ctx, pass);\r\n if (this.needFragmentColor(ctx)) {\r\n if (!(ctx.materialFlags & MaterialVaryingFlags.INSTANCING)) {\r\n bindGroup.setValue('zMetallic', this._metallic);\r\n bindGroup.setValue('zRoughness', this._roughness);\r\n bindGroup.setValue('zSpecularFactor', this._specularFactor);\r\n bindGroup.setValue('zReflectionMode', PBR_REFLECTION_MODE[this._reflectionMode]);\r\n bindGroup.setValue('zAnisotropy', this._anisotropy);\r\n bindGroup.setValue('zAnisotropyDirection', this._anisotropyDirection);\r\n bindGroup.setValue('zAnisotropyDirectionScaleBias', this._anisotropyDirectionScaleBias);\r\n }\r\n }\r\n }\r\n calculateMetallic(scope: PBInsideFunctionScope, _albedo: PBShaderExp, _normal: PBShaderExp) {\r\n const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);\r\n return (instancing ? scope.$inputs.zMetallic : scope.zMetallic) as PBShaderExp;\r\n }\r\n calculateRoughness(scope: PBInsideFunctionScope, _albedo: PBShaderExp, _normal: PBShaderExp) {\r\n const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);\r\n return (instancing ? scope.$inputs.zRoughness : scope.zRoughness) as PBShaderExp;\r\n }\r\n calculateSpecularFactor(scope: PBInsideFunctionScope, _albedo: PBShaderExp, _normal: PBShaderExp) {\r\n const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);\r\n return (instancing ? scope.$inputs.zSpecularFactor : scope.zSpecularFactor) as PBShaderExp;\r\n }\r\n calculateCommonData(\r\n scope: PBInsideFunctionScope,\r\n albedo: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp,\r\n TBN: PBShaderExp,\r\n data: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n const metallic = this.calculateMetallic(scope, albedo, normal);\r\n const roughness = this.calculateRoughness(scope, albedo, normal);\r\n const specularFactor = this.calculateSpecularFactor(scope, albedo, normal);\r\n const reflectionMode = this.calculateReflectionMode(scope) as PBShaderExp;\r\n if (this.metallicRoughnessTexture) {\r\n scope.$l.metallicRoughnessSample = this.sampleMetallicRoughnessTexture(scope);\r\n data.metallic = pb.mul(metallic, scope.metallicRoughnessSample.z);\r\n data.roughness = pb.mul(roughness, scope.metallicRoughnessSample.y);\r\n } else {\r\n data.metallic = metallic;\r\n data.roughness = roughness;\r\n }\r\n data.roughness = pb.mul(data.roughness, ShaderHelper.getCameraRoughnessFactor(scope));\r\n if (this.specularColorTexture) {\r\n scope.$l.specularColor = pb.mul(specularFactor.rgb, this.sampleSpecularColorTexture(scope).rgb);\r\n } else {\r\n scope.$l.specularColor = specularFactor.rgb;\r\n }\r\n if (this.specularTexture) {\r\n data.specularWeight = pb.mul(specularFactor.a, this.sampleSpecularTexture(scope).a);\r\n } else {\r\n data.specularWeight = specularFactor.a;\r\n }\r\n data.specularWeight = pb.mul(\r\n data.specularWeight,\r\n pb.float(pb.notEqual(reflectionMode, PBR_REFLECTION_MODE.none))\r\n );\r\n data.f0 = pb.vec4(\r\n pb.mix(\r\n pb.min(pb.mul(this.getF0(scope).rgb, scope.specularColor), pb.vec3(1)),\r\n albedo.rgb,\r\n data.metallic\r\n ),\r\n this.getF0(scope).a\r\n );\r\n data.f90 = pb.vec3(1);\r\n data.diffuse = pb.vec4(pb.mix(albedo.rgb, pb.vec3(0), data.metallic), albedo.a);\r\n super.calculateCommonData(scope, albedo, normal, viewVec, TBN, data);\r\n }\r\n calculateReflectionMode(scope: PBInsideFunctionScope) {\r\n return scope.zReflectionMode as PBShaderExp;\r\n }\r\n calculateAnisotropy(scope: PBInsideFunctionScope) {\r\n return scope.zAnisotropy as PBShaderExp;\r\n }\r\n calculateAnisotropyDirection(scope: PBInsideFunctionScope) {\r\n return scope.zAnisotropyDirection as PBShaderExp;\r\n }\r\n } as unknown as T & { new (...args: any[]): IMixinPBRMetallicRoughness };\r\n}\r\n"],"names":["PBR_REFLECTION_MODE","none","ggx","anisotropic","glint","mixinPBRMetallicRoughness","BaseCls","pbrMetallicRoughnessMixed","S","applyMaterialMixins","mixinPBRCommon","mixinLight","mixinTextureProps","METALLIC_UNIFORM","defineInstanceUniform","ROUGHNESS_UNIFORM","SPECULAR_FACTOR_UNFORM","_metallic","_roughness","_specularFactor","_reflectionMode","_anisotropy","_anisotropyDirection","_anisotropyDirectionScaleBias","Vector4","one","Vector2","copyFrom","other","metallic","roughness","specularFactor","reflectionMode","anisotropy","anisotropyDirection","anisotropyDirectionScaleBias","val","uniformChanged","equalsTo","set","directLighting","scope","lightDir","lightColor","normal","viewVec","commonData","diffuseScale","specularScale","sourceRadiusFactor","outColor","pb","$builder","that","funcName","func","vec3","getCommonDatasStruct","float","inout","$l","zReflectionMode","zAnisotropy","zAnisotropyDirection","zAnisotropyDirectionScaleBias","H","normalize","add","L","NoH","clamp","dot","NoL","NoV","$if","greaterThan","VoH","schlickFresnel","fresnelSchlick","data","f0","rgb","f90","iridescence","F","mix","iridescenceFresnel","iridescenceFactor","x","specularRoughness","alphaRoughness","mul","Dggx","distributionGGX","D","equal","dirAngle","Math","PI","anisotropyDirectionTexture","dirSample","sampleAnisotropyDirectionTexture","r","y","anisoAngle","up","t0","cross","lessThan","length","b0","tangent","cos","sin","bitangent","ToH","BoH","at","max","ab","sub","anisoDenom","pow","div","$elseif","glintNoise","fract","glintMask","smoothStep","V","visGGX","specular","specularWeight","sheen","sheenAlbedoScaling","iridescenceFresnelMax","g","b","diffuseBRDF","diffuse","transmission","drawContext","renderPass","type","RENDER_PASS_TYPE_LIGHT","transmissionRay","getVolumeTransmissionRay","thicknessFactor","a","pointToLight","transmittedLight","getPunctualRadianceTransmission","applyVolumeAttenuation","attenuationColor","attenuationDistance","transmissionFactor","sheenD","D_Charlie","sheenRoughness","sheenV","V_Ashikhmin","sheenColor","clearcoat","ccFactor","ccNormal","ccF0","ccNoV","$g","clamped","min","calculateAnisotropyDirectionScaleBias","PBRLight","worldPos","albedo","TBN","outRoughness","mat3","vec4","out","pbrData","getCommonData","lightingColor","emissiveColor","calculateEmissiveColor","indirectLighting","forEachLight","posRange","dirCutoff","colorIntensity","extra","shadow","LIGHT_TYPE_RECT","directRectLight","$else","LIGHT_TYPE_POINT","z","distance","xyz","lightAtten","calculateLightAttenuation","calculateLightDirection","calculateShadow","$return","getGlobalScope","vertexShader","needFragmentColor","materialFlags","MaterialVaryingFlags","INSTANCING","$outputs","zMetallic","getInstancedUniform","zRoughness","zSpecularFactor","fragmentShader","uniform","vec2","applyUniformValues","bindGroup","ctx","pass","setValue","calculateMetallic","_albedo","_normal","instancing","$inputs","calculateRoughness","calculateSpecularFactor","calculateCommonData","calculateReflectionMode","metallicRoughnessTexture","metallicRoughnessSample","sampleMetallicRoughnessTexture","ShaderHelper","getCameraRoughnessFactor","specularColorTexture","specularColor","sampleSpecularColorTexture","specularTexture","sampleSpecularTexture","notEqual","getF0","calculateAnisotropy","calculateAnisotropyDirection"],"mappings":";;;;;;;;AAsBA,MAAMA,mBAAyD,GAAA;IAC7DC,IAAM,EAAA,CAAA;IACNC,GAAK,EAAA,CAAA;IACLC,WAAa,EAAA,CAAA;IACbC,KAAO,EAAA;AACT,CAAA;AA4CA;;;;;IAMO,SAASC,yBAAAA,CAAyDC,OAAU,EAAA;IACjF,IAAKA,OAAgBC,CAAAA,yBAAyB,EAAE;QAC9C,OAAOD,OAAAA;AACT;IACA,MAAME,CAAAA,GAAIC,mBACRH,CAAAA,OAAAA,EACAI,cACAC,EAAAA,UAAAA,EACAC,iBAAkB,CAAA,mBAAA,CAAA,EAClBA,iBAAkB,CAAA,UAAA,CAAA,EAClBA,iBAAkB,CAAA,eAAA,CAAA,EAClBA,iBAAkB,CAAA,qBAAA,CAAA,CAAA;AAEpB,IAAA,MAAMC,gBAAmBL,GAAAA,CAAAA,CAAEM,qBAAqB,CAAC,YAAY,OAAS,EAAA,UAAA,CAAA;AACtE,IAAA,MAAMC,iBAAoBP,GAAAA,CAAAA,CAAEM,qBAAqB,CAAC,aAAa,OAAS,EAAA,WAAA,CAAA;AACxE,IAAA,MAAME,sBAAyBR,GAAAA,CAAAA,CAAEM,qBAAqB,CAAC,kBAAkB,MAAQ,EAAA,gBAAA,CAAA;AAEjF,IAAA,OAAO,cAAcN,CAAAA,CAAAA;AACnB,QAAA,OAAgBD,4BAA4B,IAAK;QACzCU,SAAkB;QAClBC,UAAmB;QACVC,eAAyB;QAClCC,eAAmC;QACnCC,WAAoB;QACpBC,oBAA6B;QACpBC,6BAAuC;QACxD,WAAc,EAAA;YACZ,KAAK,EAAA;YACL,IAAI,CAACN,SAAS,G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IAAAA,CAAKG,GAAG,GAAG/B,EAAGK,CAAAA,IAAI,CAAC,CAAA,CAAA;AACnBuB,YAAAA,IAAAA,CAAK4D,OAAO,GAAGxF,EAAAA,CAAG8H,IAAI,CAAC9H,EAAAA,CAAGkC,GAAG,CAACwF,MAAAA,CAAO5F,GAAG,EAAE9B,EAAAA,CAAGK,IAAI,CAAC,CAAA,CAAA,EAAIuB,KAAKlD,QAAQ,CAAA,EAAGgJ,OAAOzB,CAAC,CAAA;AAC9E,YAAA,KAAK,CAACiF,mBAAoB5L,CAAAA,KAAAA,EAAOoI,MAAQjI,EAAAA,MAAAA,EAAQC,SAASiI,GAAK/F,EAAAA,IAAAA,CAAAA;AACjE;AACAuJ,QAAAA,uBAAAA,CAAwB7L,KAA4B,EAAE;AACpD,YAAA,OAAOA,MAAMoB,eAAe;AAC9B;AACAsL,QAAAA,mBAAAA,CAAoB1M,KAA4B,EAAE;AAChD,YAAA,OAAOA,MAAMqB,WAAW;AAC1B;AACAsL,QAAAA,4BAAAA,CAA6B3M,KAA4B,EAAE;AACzD,YAAA,OAAOA,MAAMsB,oBAAoB;AACnC;AACF,KAAA;AACF;;;;"}
|
|
@@ -4,7 +4,7 @@ import { mixinPBRCommon } from '../pbr/common.js';
|
|
|
4
4
|
import { Vector3 } from '@zephyr3d/base';
|
|
5
5
|
import { mixinLight } from '../lit.js';
|
|
6
6
|
import { ShaderHelper } from '../../shader/helper.js';
|
|
7
|
-
import { MaterialVaryingFlags } from '../../../values.js';
|
|
7
|
+
import { MaterialVaryingFlags, LIGHT_TYPE_RECT, LIGHT_TYPE_POINT } from '../../../values.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* PBRSpecularGlossiness mixin
|
|
@@ -96,17 +96,29 @@ import { MaterialVaryingFlags } from '../../../values.js';
|
|
|
96
96
|
} else {
|
|
97
97
|
that.indirectLighting(this, this.normal, this.viewVec, this.pbrData, this.lightingColor);
|
|
98
98
|
}
|
|
99
|
-
that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, shadow) {
|
|
100
|
-
this.$
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.
|
|
108
|
-
|
|
109
|
-
|
|
99
|
+
that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, extra, shadow) {
|
|
100
|
+
this.$if(pb.equal(type, LIGHT_TYPE_RECT), function() {
|
|
101
|
+
that.directRectLight(this, this.worldPos, this.normal, this.viewVec, this.pbrData, posRange, dirCutoff, extra, colorIntensity, this.lightingColor);
|
|
102
|
+
}).$else(function() {
|
|
103
|
+
this.$l.diffuse = pb.vec3();
|
|
104
|
+
this.$l.specular = pb.vec3();
|
|
105
|
+
this.$l.diffuseScale = pb.float(1);
|
|
106
|
+
this.$l.specularScale = pb.float(1);
|
|
107
|
+
this.$l.sourceRadiusFactor = pb.float(0);
|
|
108
|
+
this.$if(pb.equal(type, LIGHT_TYPE_POINT), function() {
|
|
109
|
+
this.diffuseScale = extra.x;
|
|
110
|
+
this.specularScale = extra.y;
|
|
111
|
+
this.sourceRadiusFactor = pb.div(extra.z, pb.max(pb.distance(posRange.xyz, this.worldPos), 0.0001));
|
|
112
|
+
});
|
|
113
|
+
this.$l.lightAtten = that.calculateLightAttenuation(this, type, this.worldPos, posRange, dirCutoff);
|
|
114
|
+
this.$l.lightDir = that.calculateLightDirection(this, type, this.worldPos, posRange, dirCutoff);
|
|
115
|
+
this.$l.NoL = pb.clamp(pb.dot(this.normal, this.lightDir), 0, 1);
|
|
116
|
+
this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten, this.NoL);
|
|
117
|
+
if (shadow) {
|
|
118
|
+
this.lightColor = pb.mul(this.lightColor, that.calculateShadow(this, this.worldPos, this.NoL));
|
|
119
|
+
}
|
|
120
|
+
that.directLighting(this, this.lightDir, this.lightColor, this.normal, this.viewVec, this.pbrData, this.diffuseScale, this.specularScale, this.sourceRadiusFactor, this.lightingColor);
|
|
121
|
+
});
|
|
110
122
|
});
|
|
111
123
|
this.$return(pb.add(this.lightingColor, this.emissiveColor));
|
|
112
124
|
});
|