@needle-tools/three-mesh-effects 0.3.4 → 0.3.5

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.
@@ -21,6 +21,7 @@ import {
21
21
  attribute,
22
22
  varying,
23
23
  positionLocal,
24
+ positionViewDirection,
24
25
  modelWorldMatrixInverse,
25
26
  cameraPosition,
26
27
  cameraWorldMatrix,
@@ -758,8 +759,15 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
758
759
  material.roughnessNode = surfaceOrm.g;
759
760
  material.metalnessNode = surfaceOrm.b;
760
761
  material.aoNode = surfaceOrm.r;
761
- material.emissiveNode = emission;
762
- if (transparency !== "cutout") material.opacityNode = color.a.clamp(0, 1);
762
+ material.emissiveNode = emission.mul(descriptor.emissiveStrength ?? 1);
763
+ if (transparency !== "cutout") {
764
+ let opacity = color.a.clamp(0, 1);
765
+ if (descriptor.fresnelOpacity) {
766
+ const cosine = material.normalNode.dot(positionViewDirection).abs().clamp(0, 1);
767
+ opacity = opacity.add(opacity.oneMinus().mul(cosine.oneMinus().pow(5)));
768
+ }
769
+ material.opacityNode = opacity;
770
+ }
763
771
  material.maskNode = hit.get("valid").greaterThan(0.5);
764
772
  material.maskShadowNode = material.maskNode;
765
773
  material.depthNode = capturedSurfaceDepth(hit.get("position"));
@@ -5,7 +5,7 @@ export const BOX_OCCUPANCY_RESOLUTION = 8;
5
5
  export const BOX_OCCUPANCY_WORDS = BOX_OCCUPANCY_RESOLUTION ** 3 / 32;
6
6
  export { BOX_FACE_AXES } from "./box-impostor-face-axes.js";
7
7
  /** @typedef {{center:number[],axes:number[][],halfSize:number[],views:number[][],planes?:number[],planeErrors?:number[],depthBounds?:number[],occupancy?:number[]}} ImpostorBox */
8
- /** @typedef {{version:1,depthMode?:'auto'|'projection'|'depth',alphaMode?:'opaque'|'mask'|'blend',interpolation?:'none'|'linear'|'smooth',transparency?:'auto'|'cutout'|'dithered'|'blended',mode:'basic'|'cards'|'fitted',atlasResolution:number,padding:number,raySteps:8|16|32,alphaCutoff:number,boxes:ImpostorBox[]}} BoxImpostorDescriptor */
8
+ /** @typedef {{version:1,fresnelOpacity?:boolean,emissiveStrength?:number,depthMode?:'auto'|'projection'|'depth',alphaMode?:'opaque'|'mask'|'blend',interpolation?:'none'|'linear'|'smooth',transparency?:'auto'|'cutout'|'dithered'|'blended',mode:'basic'|'cards'|'fitted',atlasResolution:number,padding:number,raySteps:8|16|32,alphaCutoff:number,boxes:ImpostorBox[]}} BoxImpostorDescriptor */
9
9
  /** @param {unknown} raw @returns {BoxImpostorDescriptor} */
10
10
  export function parseBoxImpostorDescriptor(raw) {
11
11
  const d = /** @type {BoxImpostorDescriptor} */ (raw);
@@ -38,6 +38,8 @@ export function parseBoxImpostorDescriptor(raw) {
38
38
  !["opaque", "mask", "blend"].includes(d.alphaMode)
39
39
  )
40
40
  fail();
41
+ if (d.fresnelOpacity !== undefined && typeof d.fresnelOpacity !== 'boolean') fail();
42
+ if (d.emissiveStrength !== undefined && (!Number.isFinite(d.emissiveStrength) || d.emissiveStrength < 1)) fail();
41
43
  if (d.mode === "basic" && d.boxes.length !== 1) fail();
42
44
  for (const b of d.boxes) {
43
45
  if (
@@ -116,6 +118,8 @@ export function parseBoxImpostorDescriptor(raw) {
116
118
  atlasResolution: d.atlasResolution,
117
119
  padding: d.padding,
118
120
  boxes: d.boxes,
121
+ ...(d.fresnelOpacity !== undefined ? {fresnelOpacity: d.fresnelOpacity} : {}),
122
+ ...(d.emissiveStrength !== undefined ? {emissiveStrength: d.emissiveStrength} : {}),
119
123
  ...(d.alphaMode ? { alphaMode: d.alphaMode } : {}),
120
124
  ...normalizeBoxImpostorDisplay(d),
121
125
  };