-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathworker.js
39 lines (36 loc) · 960 Bytes
/
worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { renderRegion } from './src/render.js'
import { iterative } from './src/pathTrace.js'
import { cast } from './src/rayCast.js'
import { load } from './loader.js'
let renderRegion_ = () => {}
// const trace = cast
const trace = iterative
onmessage = ({ data: msg }) => {
switch (msg.type) {
case 'loadScene':
{
const {
camera: cameraRayThrough,
geometry: intersectRay,
maxDepth = 8
} = load(msg.data)
renderRegion_ = renderRegion(
trace({ maxDepth })(intersectRay),
cameraRayThrough
)
}
break
case 'renderRegion':
{
const { spp, x0, y0, x1, y1, width, height } = msg.data
const samples = renderRegion_(spp, x0, y0, x1, y1, width, height)
postMessage({ spp, x0, y0, x1, y1, width, height, samples }, [
samples.buffer
])
}
break
case 'terminate':
close()
break
}
}