Skip to content

Commit 8b4192c

Browse files
committed
Merge branch 'migrate-three-types'
2 parents 33c8098 + 90d2210 commit 8b4192c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+375
-475
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@types/react-dom": "19.0.0",
5353
"@types/shallowequal": "^1.1.5",
5454
"@types/string-template": "^1.0.7",
55-
"@types/three": "0.180.0",
55+
"@types/three": "0.181.0",
5656
"@vitejs/plugin-react": "^4.7.0",
5757
"@vitest/coverage-v8": "^3.2.4",
5858
"@vitest/ui": "^3.2.4",

packages/atmosphere/WEBGPU.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ const aerialPerspective: (
358358
colorNode: Node,
359359
depthNode: Node,
360360
normalNode?: Node | null
361-
) => NodeObject<AerialPerspectiveNode>
361+
) => AerialPerspectiveNode
362362
```
363363
364364
### Dependencies
@@ -459,8 +459,8 @@ scene.backgroundNode = skyBackground(context)
459459

460460
<!-- prettier-ignore -->
461461
```ts
462-
const sky: (atmosphereContext: AtmosphereContext) => NodeObject<SkyNode>
463-
const skyBackground: (atmosphereContext: AtmosphereContext) => NodeObject<SkyNode>
462+
const sky: (atmosphereContext: AtmosphereContext) => SkyNode
463+
const skyBackground: (atmosphereContext: AtmosphereContext) => SkyNode
464464
```
465465
466466
### Dependencies
@@ -597,7 +597,7 @@ scene.environmentNode = skyEnvironment(context)
597597
const skyEnvironment: (
598598
atmosphereContext: AtmosphereContext,
599599
size?: number
600-
) => NodeObject<SkyEnvironmentNode>
600+
) => SkyEnvironmentNode
601601
```
602602
603603
### Dependencies

packages/atmosphere/src/PrecomputedTexturesLoader.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
HalfFloatType,
66
LinearFilter,
77
Loader,
8+
type DataTextureImageData,
89
type LoadingManager,
910
type Texture,
1011
type WebGLRenderer
@@ -18,6 +19,7 @@ import {
1819
Float16Array,
1920
isFloatLinearSupported,
2021
parseFloat16Array,
22+
reinterpretType,
2123
type AnyFloatType
2224
} from '@takram/three-geospatial'
2325

@@ -127,9 +129,12 @@ export class PrecomputedTexturesLoader extends Loader<PrecomputedTextures> {
127129
// EXR and binary data are parsed to Uint16Array, which must be
128130
// converted to Float32Array when FloatType is used.
129131
if (this.type === FloatType) {
130-
texture.image.data = new Float32Array(
131-
new Float16Array(texture.image.data.buffer)
132-
)
132+
reinterpretType<DataTextureImageData>(texture.image)
133+
if (texture.image.data != null) {
134+
texture.image.data = new Float32Array(
135+
new Float16Array(texture.image.data?.buffer)
136+
)
137+
}
133138
}
134139
texture.minFilter = LinearFilter
135140
texture.magFilter = LinearFilter

packages/atmosphere/src/helpers/sampleTexture.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
import { HalfFloatType, Vector3, type Texture, type Vector2 } from 'three'
1+
import {
2+
HalfFloatType,
3+
Vector3,
4+
type DataTextureImageData,
5+
type Texture,
6+
type Vector2
7+
} from 'three'
28

39
import {
410
clamp,
511
Float16Array,
612
isTypedArray,
13+
reinterpretType,
714
type TypedArray
815
} from '@takram/three-geospatial'
916

@@ -19,6 +26,7 @@ const float16ArrayCache = /*#__PURE__*/ new WeakMap<
1926
function getImageData(texture: Texture): TypedArray | undefined {
2027
// Image data is stored in the userData in case of normal texture.
2128
// See PrecomputedTexturesGenerator.
29+
reinterpretType<DataTextureImageData>(texture.image)
2230
let data: TypedArray | undefined = isTypedArray(texture.image.data)
2331
? texture.image.data
2432
: isTypedArray(texture.userData.imageData)
@@ -56,6 +64,7 @@ export function sampleTexture(
5664
if (data == null) {
5765
return result.setScalar(0)
5866
}
67+
reinterpretType<DataTextureImageData>(texture.image)
5968
const { width, height } = texture.image
6069
const x = clamp(uv.x, 0, 1) * (width - 1)
6170
const y = clamp(uv.y, 0, 1) * (height - 1)

packages/atmosphere/src/webgpu/AerialPerspectiveNode.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
Fn,
44
If,
55
mix,
6-
nodeObject,
76
positionGeometry,
87
remapClamp,
98
select,
@@ -22,8 +21,7 @@ import {
2221
projectionMatrix,
2322
rayEllipsoidIntersection,
2423
screenToPositionView,
25-
type Node,
26-
type NodeObject
24+
type Node
2725
} from '@takram/three-geospatial/webgpu'
2826

2927
import type { AtmosphereContextNode } from './AtmosphereContextNode'
@@ -91,11 +89,10 @@ export class AerialPerspectiveNode extends TempNode {
9189
altitudeCorrectionUnit
9290
} = this.atmosphereContext
9391

94-
const colorNode = nodeObject(this.colorNode)
95-
const depthNode = nodeObject(this.depthNode)
92+
const { colorNode, depthNode, normalNode } = this
9693
const depth = depthNode.r.toVar()
9794

98-
const getSurfacePositionECEF = (): NodeObject<'vec3'> => {
95+
const getSurfacePositionECEF = (): Node<'vec3'> => {
9996
const viewZ = depthToViewZ(depth, cameraNear(camera), cameraFar(camera), {
10097
perspective: camera.isPerspectiveCamera,
10198
logarithmic: builder.renderer.logarithmicDepthBuffer
@@ -113,7 +110,7 @@ export class AerialPerspectiveNode extends TempNode {
113110
return matrixWorldToECEF.mul(vec4(positionWorld, 1)).xyz
114111
}
115112

116-
const getRayDirectionECEF = (): NodeObject<'vec3'> => {
113+
const getRayDirectionECEF = (): Node<'vec3'> => {
117114
const positionView = inverseProjectionMatrix(camera).mul(
118115
vec4(positionGeometry, 1)
119116
).xyz
@@ -161,14 +158,13 @@ export class AerialPerspectiveNode extends TempNode {
161158
}
162159

163160
const illuminance = Fn(() => {
164-
if (this.normalNode == null) {
161+
if (normalNode == null) {
165162
throw new Error(
166163
'The "normalNode" is required when the "light" is set.'
167164
)
168165
}
169166

170167
// Normal vector of the surface:
171-
const normalNode = nodeObject(this.normalNode)
172168
const normalView = normalNode.xyz
173169
const normalWorld = inverseViewMatrix(camera).mul(
174170
vec4(normalView, 0)
@@ -239,5 +235,4 @@ export class AerialPerspectiveNode extends TempNode {
239235

240236
export const aerialPerspective = (
241237
...args: ConstructorParameters<typeof AerialPerspectiveNode>
242-
): NodeObject<AerialPerspectiveNode> =>
243-
nodeObject(new AerialPerspectiveNode(...args))
238+
): AerialPerspectiveNode => new AerialPerspectiveNode(...args)

packages/atmosphere/src/webgpu/AtmosphereContextBaseNode.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { float, vec3 } from 'three/tsl'
2-
import { Node, type NodeBuilder } from 'three/webgpu'
2+
import type { NodeBuilder } from 'three/webgpu'
33

4-
import type { NodeObject } from '@takram/three-geospatial/webgpu'
4+
import { Node } from '@takram/three-geospatial/webgpu'
55

66
import {
77
AtmosphereParameters,
@@ -19,11 +19,11 @@ import type {
1919
} from './dimensional'
2020

2121
export interface DensityProfileLayerNodes {
22-
width: NodeObject<Length>
23-
expTerm: NodeObject<Dimensionless>
24-
expScale: NodeObject<InverseLength>
25-
linearTerm: NodeObject<InverseLength>
26-
constantTerm: NodeObject<Dimensionless>
22+
width: Node<Length>
23+
expTerm: Node<Dimensionless>
24+
expScale: Node<InverseLength>
25+
linearTerm: Node<InverseLength>
26+
constantTerm: Node<Dimensionless>
2727
}
2828

2929
function densityProfileLayerNodes(
@@ -65,24 +65,24 @@ export class AtmosphereContextBaseNode extends Node {
6565

6666
readonly parameters: AtmosphereParameters
6767

68-
worldToUnit: NodeObject<Dimensionless>
69-
solarIrradiance: NodeObject<IrradianceSpectrum>
70-
sunAngularRadius: NodeObject<Angle>
71-
bottomRadius: NodeObject<Length>
72-
topRadius: NodeObject<Length>
68+
worldToUnit: Node<Dimensionless>
69+
solarIrradiance: Node<IrradianceSpectrum>
70+
sunAngularRadius: Node<Angle>
71+
bottomRadius: Node<Length>
72+
topRadius: Node<Length>
7373
rayleighDensity: DensityProfileNodes
74-
rayleighScattering: NodeObject<ScatteringSpectrum>
74+
rayleighScattering: Node<ScatteringSpectrum>
7575
mieDensity: DensityProfileNodes
76-
mieScattering: NodeObject<ScatteringSpectrum>
77-
mieExtinction: NodeObject<ScatteringSpectrum>
78-
miePhaseFunctionG: NodeObject<Dimensionless>
76+
mieScattering: Node<ScatteringSpectrum>
77+
mieExtinction: Node<ScatteringSpectrum>
78+
miePhaseFunctionG: Node<Dimensionless>
7979
absorptionDensity: DensityProfileNodes
80-
absorptionExtinction: NodeObject<ScatteringSpectrum>
81-
groundAlbedo: NodeObject<DimensionlessSpectrum>
82-
minCosSun: NodeObject<Dimensionless>
83-
sunRadianceToLuminance: NodeObject<DimensionlessSpectrum>
84-
skyRadianceToLuminance: NodeObject<DimensionlessSpectrum>
85-
luminanceScale: NodeObject<Dimensionless>
80+
absorptionExtinction: Node<ScatteringSpectrum>
81+
groundAlbedo: Node<DimensionlessSpectrum>
82+
minCosSun: Node<Dimensionless>
83+
sunRadianceToLuminance: Node<DimensionlessSpectrum>
84+
skyRadianceToLuminance: Node<DimensionlessSpectrum>
85+
luminanceScale: Node<Dimensionless>
8686

8787
constructor(parameters = new AtmosphereParameters()) {
8888
super(null)

packages/atmosphere/src/webgpu/AtmosphereLUTNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class AtmosphereLUTNode extends Node {
112112
return this.textureNodes[name]
113113
}
114114

115-
private *compute(
115+
private *performCompute(
116116
renderer: Renderer,
117117
context: AtmosphereLUTTexturesContext
118118
): Iterable<boolean> {
@@ -165,7 +165,7 @@ export class AtmosphereLUTNode extends Node {
165165
const context = this.textures.createContext()
166166
this.updating = true
167167
try {
168-
await timeSlice(this.compute(renderer, context))
168+
await timeSlice(this.performCompute(renderer, context))
169169
} finally {
170170
this.updating = false
171171
context.dispose()

packages/atmosphere/src/webgpu/AtmosphereLUTTexturesWebGL.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ function clearRenderTarget(
113113
if (renderTarget instanceof RenderTarget3D) {
114114
for (let i = 0; i < renderTarget.depth; ++i) {
115115
renderer.setRenderTarget(renderTarget, i)
116-
void renderer.clearColor()
116+
renderer.clearColor()
117117
}
118118
} else {
119119
renderer.setRenderTarget(renderTarget)
120-
void renderer.clearColor()
120+
renderer.clearColor()
121121
}
122122
}
123123
}

packages/atmosphere/src/webgpu/AtmosphereLUTTexturesWebGPU.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
Box3,
33
LinearFilter,
44
NoColorSpace,
5+
type Data3DTextureImageData,
6+
type DataTextureImageData,
57
type Texture,
68
type Vector2,
79
type Vector3
@@ -31,8 +33,7 @@ import {
3133
} from 'three/webgpu'
3234
import invariant from 'tiny-invariant'
3335

34-
import type { AnyFloatType } from '@takram/three-geospatial'
35-
import type { NodeObject } from '@takram/three-geospatial/webgpu'
36+
import { reinterpretType, type AnyFloatType } from '@takram/three-geospatial'
3637

3738
import type {
3839
AtmosphereLUTTexture3DName,
@@ -79,6 +80,7 @@ export function setupStorageTexture(
7980
size: Vector2
8081
): void {
8182
texture.type = textureType
83+
reinterpretType<DataTextureImageData>(texture.image)
8284
texture.image.width = size.x
8385
texture.image.height = size.y
8486
}
@@ -89,6 +91,7 @@ export function setupStorage3DTexture(
8991
size: Vector3
9092
): void {
9193
texture.type = textureType
94+
reinterpretType<Data3DTextureImageData>(texture.image)
9295
texture.image.width = size.x
9396
texture.image.height = size.y
9497
texture.image.depth = size.z
@@ -188,12 +191,12 @@ export class AtmosphereLUTTexturesWebGPU extends AtmosphereLUTTextures {
188191
'higherOrderScattering'
189192
)
190193

191-
private transmittanceNode?: NodeObject<ComputeNode>
192-
private directIrradianceNode?: NodeObject<ComputeNode>
193-
private singleScatteringNode?: NodeObject<ComputeNode>
194-
private scatteringDensityNode?: NodeObject<ComputeNode>
195-
private indirectIrradianceNode?: NodeObject<ComputeNode>
196-
private multipleScatteringNode?: NodeObject<ComputeNode>
194+
private transmittanceNode?: ComputeNode
195+
private directIrradianceNode?: ComputeNode
196+
private singleScatteringNode?: ComputeNode
197+
private scatteringDensityNode?: ComputeNode
198+
private indirectIrradianceNode?: ComputeNode
199+
private multipleScatteringNode?: ComputeNode
197200

198201
private readonly scatteringOrder = uniform(0)
199202

packages/atmosphere/src/webgpu/AtmosphereLightNode.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,10 @@ import {
99
} from 'three/tsl'
1010
import { AnalyticLightNode, type NodeBuilder } from 'three/webgpu'
1111

12-
import type { Node, NodeObject } from '@takram/three-geospatial/webgpu'
13-
1412
import type { AtmosphereLight } from './AtmosphereLight'
1513
import { getTransmittanceToSun } from './common'
1614
import { getSkyIlluminance } from './runtime'
1715

18-
type CorrectLightingContext = {
19-
[K in keyof LightingContext]: LightingContext[K] extends Node
20-
? NodeObject<LightingContext[K]>
21-
: LightingContext[K]
22-
}
23-
2416
export class AtmosphereLightNode extends AnalyticLightNode<AtmosphereLight> {
2517
static override get type(): string {
2618
return 'AtmosphereLightNode'
@@ -67,7 +59,7 @@ export class AtmosphereLightNode extends AnalyticLightNode<AtmosphereLight> {
6759
})()
6860

6961
// Yes, it's an indirect but should be fine to update it here.
70-
const lightingContext = builder.getContext() as CorrectLightingContext
62+
const lightingContext = builder.getContext() as unknown as LightingContext
7163
lightingContext.irradiance.addAssign(skyIlluminance)
7264

7365
// Derive the view-space sun direction.

0 commit comments

Comments
 (0)