@lijuhong1981/three.instancedsprite 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,6 +42,7 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
42
42
  const aCenterAndSize = attribute('aCenterAndSize', 'vec4');
43
43
  const aScaleAndRotationAndSizeAttenuation = attribute('aScaleAndRotationAndSizeAttenuation', 'vec3');
44
44
  const aColorAndOpacity = attribute('aColorAndOpacity', 'vec4');
45
+ const aPickColorAndEnabled = attribute('aPickColorAndEnabled', 'vec4');
45
46
 
46
47
  // ============================================================
47
48
  // Varying 变量 — 从顶点着色器传递到片元着色器
@@ -49,6 +50,7 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
49
50
  const vShow = varying(float(1));
50
51
  const vColorAndOpacity = varying(vec4(1));
51
52
  const vUv = varying(vec2(1));
53
+ const vPickColorAndEnabled = varying(vec4(1));
52
54
 
53
55
  // ============================================================
54
56
  // 顶点着色器 (vertexNode)
@@ -66,6 +68,7 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
66
68
  vShow.assign(show);
67
69
  vColorAndOpacity.assign(aColorAndOpacity);
68
70
  vUv.assign(uv());
71
+ vPickColorAndEnabled.assign(aPickColorAndEnabled);
69
72
 
70
73
  // --- 3. 计算模型视图位置 ---
71
74
  const mvPosition = modelViewMatrix.mul(vec4(aPositionAndShow.xyz, 1));
@@ -122,12 +125,24 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
122
125
  // 片元着色器 (fragmentNode)
123
126
  // ============================================================
124
127
  this.fragmentNode = Fn(() => {
125
- // 采样纹理
126
- const texColor = texture(this._textureNode, vUv);
127
- const diffuseColor = texColor.mul(vColorAndOpacity);
128
+ Discard(vShow.lessThan(0.5));
128
129
 
129
- // 丢弃完全透明或隐藏的像素
130
- Discard(diffuseColor.a.lessThan(0.005).or(vShow.lessThan(0.5)));
130
+ const enablePickColor = vPickColorAndEnabled.w.greaterThan(0.5);
131
+ const diffuseColor = vec4(0, 0, 0, 1).toVar('diffuseColor');
132
+
133
+ If(enablePickColor, () => {
134
+ // 拾取模式:直接输出拾取颜色,不受纹理/透明度影响
135
+ diffuseColor.assign(vec4(vPickColorAndEnabled.xyz, 1));
136
+ }).Else(() => {
137
+ // 采样纹理
138
+ const texColor = texture(this._textureNode, vUv);
139
+ const color = texColor.mul(vColorAndOpacity);
140
+
141
+ // 丢弃完全透明的像素
142
+ Discard(color.a.lessThan(0.005));
143
+
144
+ diffuseColor.assign(color);
145
+ });
131
146
 
132
147
  return diffuseColor;
133
148
  }).once();
@@ -142,7 +157,7 @@ class InstancedSpriteNodeMaterial extends NodeMaterial {
142
157
  set texture(value) {
143
158
  this._textureNode.value = value;
144
159
  }
145
- }
160
+ };
146
161
 
147
162
  export default InstancedSpriteNodeMaterial;
148
163
  export { InstancedSpriteNodeMaterial };
@@ -1,7 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(node --check src/InstancedSpriteNodeMaterial.js)"
5
- ]
6
- }
7
- }