@zephyr3d/scene 0.8.1 → 0.9.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/animationset.js +563 -128
- 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 +1907 -3
- 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 +157 -146
- 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 +11701 -8506
- 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 +222 -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 +125 -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,9 +1,9 @@
|
|
|
1
1
|
import { PBShaderExp } from '@zephyr3d/device';
|
|
2
2
|
import { ConstantScalarNode, ConstantVec2Node, ConstantVec3Node, ConstantVec4Node, ConstantBooleanNode, ConstantBVec2Node, ConstantBVec3Node, ConstantBVec4Node } from '../common/constants.js';
|
|
3
3
|
import { ASSERT } from '@zephyr3d/base';
|
|
4
|
-
import { BaseTextureNode, TextureSampleNode } from './texture.js';
|
|
5
|
-
import { MakeVectorNode, SwizzleNode, CompComparisonNode, AnyConditionNode, AllConditionNode, SelectionNode, Hash1Node, Hash2Node, Hash3Node, SimplexNoise2DNode, PerlinNoise2DNode, GenericMathNode, TransformNode } from '../common/math.js';
|
|
6
|
-
import { ResolveVertexPositionNode, ResolveVertexNormalNode, ResolveVertexTangentNode, VertexColorNode, VertexUVNode, VertexPositionNode, VertexNormalNode, VertexTangentNode, VertexBinormalNode, ViewMatrixNode, ProjectionMatrixNode, ViewProjMatrixNode, InvProjMatrixNode, InvViewProjMatrixNode, BillboardMatrixNode, CameraPositionNode, CameraNearFarNode, SkyEnvTextureNode, ElapsedTimeNode } from './inputs.js';
|
|
4
|
+
import { BaseTextureNode, TextureSampleNode, PannerNode } from './texture.js';
|
|
5
|
+
import { MakeVectorNode, SwizzleNode, CompComparisonNode, AnyConditionNode, AllConditionNode, SelectionNode, Hash1Node, Hash2Node, Hash3Node, SimplexNoise2DNode, PerlinNoise2DNode, GenericMathNode, TransformNode, RotateAboutAxisNode } from '../common/math.js';
|
|
6
|
+
import { ResolveVertexPositionNode, ResolveVertexNormalNode, ResolveVertexTangentNode, VertexColorNode, VertexUVNode, VertexPositionNode, PixelWorldPositionNode, VertexNormalNode, PixelNormalNode, VertexTangentNode, VertexBinormalNode, ViewMatrixNode, ProjectionMatrixNode, ViewProjMatrixNode, InvProjMatrixNode, InvViewProjMatrixNode, BillboardMatrixNode, CameraPositionNode, CameraVectorNode, CameraNearFarNode, SkyEnvTextureNode, ElapsedTimeNode } from './inputs.js';
|
|
7
7
|
import { ShaderHelper } from '../../../material/shader/helper.js';
|
|
8
8
|
import { FunctionCallNode, FunctionInputNode, FunctionOutputNode } from './func.js';
|
|
9
9
|
import { hash11, hash21, hash31, hash12, hash22, hash32, hash13, hash23, hash33, valueNoise } from '../../../shaders/noise.js';
|
|
@@ -330,8 +330,11 @@ import { VertexBlockNode } from './pbr.js';
|
|
|
330
330
|
*/ create(pb) {
|
|
331
331
|
if (this.tmpName) {
|
|
332
332
|
const exp = pb.getCurrentScope()[this.tmpName];
|
|
333
|
-
|
|
334
|
-
|
|
333
|
+
if (exp) {
|
|
334
|
+
return exp;
|
|
335
|
+
}
|
|
336
|
+
// Scope changed, recompute in current scope
|
|
337
|
+
this.tmpName = '';
|
|
335
338
|
}
|
|
336
339
|
const params = this.params.map((param)=>param instanceof IRExpression ? param.create(pb) : param);
|
|
337
340
|
// @ts-ignore
|
|
@@ -723,7 +726,7 @@ class IRComparison extends IRExpression {
|
|
|
723
726
|
*
|
|
724
727
|
* @public
|
|
725
728
|
*/ class IRSampleTexture extends IRExpression {
|
|
726
|
-
/** The texture
|
|
729
|
+
/** The texture expression */ tex;
|
|
727
730
|
/** The texture coordinate expression */ coord;
|
|
728
731
|
/** The sampler type determining how to interpret the sampled value */ samplerType;
|
|
729
732
|
/** Cached temporary variable name if result is referenced multiple times */ tmpName;
|
|
@@ -762,6 +765,12 @@ class IRComparison extends IRExpression {
|
|
|
762
765
|
const tex = this.tex.create(pb);
|
|
763
766
|
const coord = this.coord.create(pb);
|
|
764
767
|
let coordExp;
|
|
768
|
+
let texExp;
|
|
769
|
+
if (tex instanceof PBShaderExp) {
|
|
770
|
+
texExp = tex;
|
|
771
|
+
} else {
|
|
772
|
+
throw new Error('Invalid texture expression');
|
|
773
|
+
}
|
|
765
774
|
if (coord instanceof PBShaderExp) {
|
|
766
775
|
coordExp = coord;
|
|
767
776
|
} else if (Array.isArray(coord)) {
|
|
@@ -770,7 +779,7 @@ class IRComparison extends IRExpression {
|
|
|
770
779
|
} else {
|
|
771
780
|
throw new Error('Invalid texture coordinate');
|
|
772
781
|
}
|
|
773
|
-
let exp = pb.textureSample(
|
|
782
|
+
let exp = pb.textureSample(texExp, coordExp);
|
|
774
783
|
if (this.samplerType === 'Normal') {
|
|
775
784
|
exp = pb.sub(pb.mul(exp, pb.vec4(2, 2, 2, 1)), pb.vec4(1, 1, 1, 0));
|
|
776
785
|
}
|
|
@@ -900,6 +909,7 @@ class IRComparison extends IRExpression {
|
|
|
900
909
|
/** Map from graph node to IR expression index */ _expressionMap;
|
|
901
910
|
/** Array of uniform scalar/vector values to be set at runtime */ _uniformValues;
|
|
902
911
|
/** Array of uniform textures to be bound at runtime */ _uniformTextures;
|
|
912
|
+
/** Fallback texture uniforms generated for TextureSample nodes without texture input */ _textureSampleFallbackMap;
|
|
903
913
|
/** Flags indicating which shader features are used */ _behaviors;
|
|
904
914
|
/** Array of named output expressions (e.g., baseColor, normal, metallic) */ _outputs;
|
|
905
915
|
/**
|
|
@@ -1049,6 +1059,7 @@ class IRComparison extends IRExpression {
|
|
|
1049
1059
|
this._expressionMap = new Map();
|
|
1050
1060
|
this._uniformTextures = [];
|
|
1051
1061
|
this._uniformValues = [];
|
|
1062
|
+
this._textureSampleFallbackMap = new Map();
|
|
1052
1063
|
this._outputs = null;
|
|
1053
1064
|
this._behaviors = {
|
|
1054
1065
|
useVertexColor: false,
|
|
@@ -1086,6 +1097,8 @@ class IRComparison extends IRExpression {
|
|
|
1086
1097
|
expr = this.constantTexture(node, output);
|
|
1087
1098
|
} else if (node instanceof TextureSampleNode) {
|
|
1088
1099
|
expr = this.textureSample(node, output);
|
|
1100
|
+
} else if (node instanceof PannerNode) {
|
|
1101
|
+
expr = this.panner(node, output);
|
|
1089
1102
|
} else if (node instanceof MakeVectorNode) {
|
|
1090
1103
|
expr = this.makeVector(node, output);
|
|
1091
1104
|
} else if (node instanceof SwizzleNode) {
|
|
@@ -1118,14 +1131,20 @@ class IRComparison extends IRExpression {
|
|
|
1118
1131
|
expr = this.func(node, output);
|
|
1119
1132
|
} else if (node instanceof TransformNode) {
|
|
1120
1133
|
expr = this.transform(node, output);
|
|
1134
|
+
} else if (node instanceof RotateAboutAxisNode) {
|
|
1135
|
+
expr = this.rotateAboutAxis(node, output);
|
|
1121
1136
|
} else if (node instanceof VertexColorNode) {
|
|
1122
1137
|
expr = this.vertexColor(node, output);
|
|
1123
1138
|
} else if (node instanceof VertexUVNode) {
|
|
1124
1139
|
expr = this.vertexUV(node, output);
|
|
1125
1140
|
} else if (node instanceof VertexPositionNode) {
|
|
1126
1141
|
expr = this.vertexPosition(node, output);
|
|
1142
|
+
} else if (node instanceof PixelWorldPositionNode) {
|
|
1143
|
+
expr = this.pixelWorldPosition(node, output);
|
|
1127
1144
|
} else if (node instanceof VertexNormalNode) {
|
|
1128
1145
|
expr = this.vertexNormal(node, output);
|
|
1146
|
+
} else if (node instanceof PixelNormalNode) {
|
|
1147
|
+
expr = this.pixelNormal(node, output);
|
|
1129
1148
|
} else if (node instanceof VertexTangentNode) {
|
|
1130
1149
|
expr = this.vertexTangent(node, output);
|
|
1131
1150
|
} else if (node instanceof VertexBinormalNode) {
|
|
@@ -1144,6 +1163,8 @@ class IRComparison extends IRExpression {
|
|
|
1144
1163
|
expr = this.billboardMatrix(node, output);
|
|
1145
1164
|
} else if (node instanceof CameraPositionNode) {
|
|
1146
1165
|
expr = this.cameraPosition(node, output);
|
|
1166
|
+
} else if (node instanceof CameraVectorNode) {
|
|
1167
|
+
expr = this.cameraVector(node, output);
|
|
1147
1168
|
} else if (node instanceof CameraNearFarNode) {
|
|
1148
1169
|
expr = this.cameraNearFar(node, output);
|
|
1149
1170
|
} else if (node instanceof SkyEnvTextureNode) {
|
|
@@ -1272,6 +1293,86 @@ class IRComparison extends IRExpression {
|
|
|
1272
1293
|
const input = this.ir(node.inputs[0]);
|
|
1273
1294
|
return this.getOrCreateIRExpression(node, output, IRFunctionOutput, input);
|
|
1274
1295
|
}
|
|
1296
|
+
/** Converts a rotate-about-axis node to IR */ rotateAboutAxis(node, output) {
|
|
1297
|
+
const axis = this.ir(node.inputs[0]);
|
|
1298
|
+
const angleTurns = node.inputs[1].inputNode ? this.ir(node.inputs[1]) : new IRConstantf(node.inputs[1].defaultValue?.[0] ?? 0, '');
|
|
1299
|
+
const pivot = node.inputs[2].inputNode ? this.ir(node.inputs[2]) : new IRConstantfv(node.inputs[2].defaultValue ?? [
|
|
1300
|
+
0,
|
|
1301
|
+
0,
|
|
1302
|
+
0
|
|
1303
|
+
], '', 'vec3');
|
|
1304
|
+
const position = this.ir(node.inputs[3]);
|
|
1305
|
+
const angleRad = new IRFunc([
|
|
1306
|
+
angleTurns,
|
|
1307
|
+
6.283185307179586
|
|
1308
|
+
], 'mul'); // turns -> radians
|
|
1309
|
+
const cosA = new IRFunc([
|
|
1310
|
+
angleRad
|
|
1311
|
+
], 'cos');
|
|
1312
|
+
const sinA = new IRFunc([
|
|
1313
|
+
angleRad
|
|
1314
|
+
], 'sin');
|
|
1315
|
+
const p = new IRFunc([
|
|
1316
|
+
position,
|
|
1317
|
+
pivot
|
|
1318
|
+
], 'sub');
|
|
1319
|
+
const term1 = new IRFunc([
|
|
1320
|
+
p,
|
|
1321
|
+
cosA
|
|
1322
|
+
], 'mul');
|
|
1323
|
+
const term2 = new IRFunc([
|
|
1324
|
+
new IRFunc([
|
|
1325
|
+
axis,
|
|
1326
|
+
p
|
|
1327
|
+
], 'cross'),
|
|
1328
|
+
sinA
|
|
1329
|
+
], 'mul');
|
|
1330
|
+
const term3 = new IRFunc([
|
|
1331
|
+
axis,
|
|
1332
|
+
new IRFunc([
|
|
1333
|
+
new IRFunc([
|
|
1334
|
+
axis,
|
|
1335
|
+
p
|
|
1336
|
+
], 'dot'),
|
|
1337
|
+
new IRFunc([
|
|
1338
|
+
1,
|
|
1339
|
+
cosA
|
|
1340
|
+
], 'sub')
|
|
1341
|
+
], 'mul')
|
|
1342
|
+
], 'mul');
|
|
1343
|
+
const rotated = new IRFunc([
|
|
1344
|
+
new IRFunc([
|
|
1345
|
+
term1,
|
|
1346
|
+
term2
|
|
1347
|
+
], 'add'),
|
|
1348
|
+
term3
|
|
1349
|
+
], 'add');
|
|
1350
|
+
return this.getOrCreateIRExpression(node, output, IRFunc, [
|
|
1351
|
+
rotated,
|
|
1352
|
+
pivot
|
|
1353
|
+
], 'add');
|
|
1354
|
+
}
|
|
1355
|
+
/** Converts a panner node to IR */ panner(node, output) {
|
|
1356
|
+
const coordInput = node.inputs[0];
|
|
1357
|
+
const timeInput = node.inputs[1];
|
|
1358
|
+
const speedInput = node.inputs[2];
|
|
1359
|
+
const coord = coordInput.inputNode ? this.ir(coordInput) : (()=>{
|
|
1360
|
+
this._behaviors.useVertexUV = true;
|
|
1361
|
+
return new IRInput((scope)=>scope.zVertexUV);
|
|
1362
|
+
})();
|
|
1363
|
+
const time = timeInput.inputNode ? this.ir(timeInput) : new IRInput((scope)=>ShaderHelper.getElapsedTime(scope));
|
|
1364
|
+
const speed = speedInput.inputNode ? this.ir(speedInput) : new IRConstantfv(speedInput.defaultValue ?? [
|
|
1365
|
+
0,
|
|
1366
|
+
0
|
|
1367
|
+
], '', 'vec2');
|
|
1368
|
+
return this.getOrCreateIRExpression(node, output, IRFunc, [
|
|
1369
|
+
coord,
|
|
1370
|
+
new IRFunc([
|
|
1371
|
+
time,
|
|
1372
|
+
speed
|
|
1373
|
+
], 'mul')
|
|
1374
|
+
], 'add');
|
|
1375
|
+
}
|
|
1275
1376
|
/** Converts a vertex color input node to IR */ vertexColor(node, output) {
|
|
1276
1377
|
this._behaviors.useVertexColor = true;
|
|
1277
1378
|
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>scope.zVertexColor);
|
|
@@ -1285,6 +1386,9 @@ class IRComparison extends IRExpression {
|
|
|
1285
1386
|
/** Converts a vertex normal input node to IR */ vertexNormal(node, output) {
|
|
1286
1387
|
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>scope.$builder.getDevice().type === 'vertex' ? scope.$getVertexAttrib('normal') ?? ShaderHelper.resolveVertexNormal(scope) : scope.zVertexNormal);
|
|
1287
1388
|
}
|
|
1389
|
+
/** Converts a pixel normal input node to IR */ pixelNormal(node, output) {
|
|
1390
|
+
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>scope.$builder.getDevice().type === 'vertex' ? scope.$getVertexAttrib('normal') ?? ShaderHelper.resolveVertexNormal(scope) : scope.zVertexNormal);
|
|
1391
|
+
}
|
|
1288
1392
|
/** Converts a vertex tangent input node to IR */ vertexTangent(node, output) {
|
|
1289
1393
|
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>scope.$builder.getDevice().type === 'vertex' ? scope.$getVertexAttrib('tangent') ?? ShaderHelper.resolveVertexTangent(scope) : scope.zVertexTangent);
|
|
1290
1394
|
}
|
|
@@ -1292,7 +1396,24 @@ class IRComparison extends IRExpression {
|
|
|
1292
1396
|
return this.getOrCreateIRExpression(node, output, IRInput, 'zVertexBinormal');
|
|
1293
1397
|
}
|
|
1294
1398
|
/** Converts a vertex position input node to IR */ vertexPosition(node, output) {
|
|
1295
|
-
return this.getOrCreateIRExpression(node, output, IRInput,
|
|
1399
|
+
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>{
|
|
1400
|
+
if (scope.$builder.getDevice().type === 'vertex') {
|
|
1401
|
+
const worldMatrix = ShaderHelper.getWorldMatrix(scope);
|
|
1402
|
+
const basePos = ShaderHelper.resolveVertexPosition(scope);
|
|
1403
|
+
return scope.$builder.mul(worldMatrix, scope.$builder.vec4(basePos, 1)).xyz;
|
|
1404
|
+
}
|
|
1405
|
+
return scope.zWorldPos;
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
/** Converts a pixel world position input node to IR */ pixelWorldPosition(node, output) {
|
|
1409
|
+
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>{
|
|
1410
|
+
if (scope.$builder.getDevice().type === 'vertex') {
|
|
1411
|
+
const worldMatrix = ShaderHelper.getWorldMatrix(scope);
|
|
1412
|
+
const basePos = ShaderHelper.resolveVertexPosition(scope);
|
|
1413
|
+
return scope.$builder.mul(worldMatrix, scope.$builder.vec4(basePos, 1)).xyz;
|
|
1414
|
+
}
|
|
1415
|
+
return scope.zWorldPos;
|
|
1416
|
+
});
|
|
1296
1417
|
}
|
|
1297
1418
|
/** Converts a view matrix input node to IR */ viewMatrix(node, output) {
|
|
1298
1419
|
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>ShaderHelper.getViewMatrix(scope));
|
|
@@ -1312,6 +1433,13 @@ class IRComparison extends IRExpression {
|
|
|
1312
1433
|
/** Converts a camera position input node to IR */ cameraPosition(node, output) {
|
|
1313
1434
|
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>ShaderHelper.getCameraPosition(scope));
|
|
1314
1435
|
}
|
|
1436
|
+
/** Converts a camera vector input node to IR */ cameraVector(node, output) {
|
|
1437
|
+
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>{
|
|
1438
|
+
const pb = scope.$builder;
|
|
1439
|
+
const worldPos = pb.getDevice().type === 'vertex' ? pb.mul(ShaderHelper.getWorldMatrix(scope), pb.vec4(ShaderHelper.resolveVertexPosition(scope), 1)).xyz : scope.zWorldPos;
|
|
1440
|
+
return pb.normalize(pb.sub(ShaderHelper.getCameraPosition(scope), worldPos));
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1315
1443
|
/** Converts a camera near/far input node to IR */ cameraNearFar(node, output) {
|
|
1316
1444
|
return this.getOrCreateIRExpression(node, output, IRInput, (scope)=>ShaderHelper.getCameraParams(scope).xy);
|
|
1317
1445
|
}
|
|
@@ -1509,10 +1637,26 @@ class IRComparison extends IRExpression {
|
|
|
1509
1637
|
return this.getOrCreateIRExpression(node, output, IRConstantTexture, node.paramName, node.textureId, node.getOutputType(1), node.sRGB, node.addressU, node.addressV, node.filterMin, node.filterMag, node.filterMip);
|
|
1510
1638
|
}
|
|
1511
1639
|
/** Converts a texture sample node to IR */ textureSample(node, output) {
|
|
1512
|
-
const tex = this.ir(node.inputs[0]);
|
|
1513
|
-
const coord = this.ir(node.inputs[1])
|
|
1640
|
+
const tex = node.inputs[0].inputNode ? this.ir(node.inputs[0]) : this.textureSampleFallbackTexture(node);
|
|
1641
|
+
const coord = node.inputs[1].inputNode ? this.ir(node.inputs[1]) : (()=>{
|
|
1642
|
+
this._behaviors.useVertexUV = true;
|
|
1643
|
+
return new IRInput((scope)=>scope.zVertexUV);
|
|
1644
|
+
})();
|
|
1514
1645
|
return this.getOrCreateIRExpression(node, output, IRSampleTexture, tex, coord, node.samplerType);
|
|
1515
1646
|
}
|
|
1647
|
+
/** Gets or creates fallback texture uniform expression for texture sample nodes */ textureSampleFallbackTexture(node) {
|
|
1648
|
+
let ir = this._textureSampleFallbackMap.get(node);
|
|
1649
|
+
if (!ir) {
|
|
1650
|
+
ir = new IRConstantTexture(node.paramName, node.textureId, 'tex2D', node.sRGB, node.addressU, node.addressV, node.filterMin, node.filterMag, node.filterMip);
|
|
1651
|
+
this._expressions.push(ir);
|
|
1652
|
+
this._textureSampleFallbackMap.set(node, ir);
|
|
1653
|
+
const uniformTexture = ir.asUniformTexture();
|
|
1654
|
+
if (uniformTexture) {
|
|
1655
|
+
this._uniformTextures.push(uniformTexture);
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
return ir;
|
|
1659
|
+
}
|
|
1516
1660
|
}
|
|
1517
1661
|
|
|
1518
1662
|
export { MaterialBlueprintIR };
|