feat: threads
This commit is contained in:
parent
6fb46573da
commit
46e7070b6b
18 changed files with 878 additions and 125 deletions
|
|
@ -64,8 +64,9 @@ export namespace Sky {
|
|||
* block and is copied across it. The sky is low-frequency, so 2 is nearly free
|
||||
* visually and quarters the cloud cost; 1 is full resolution.
|
||||
*/
|
||||
export function render(fb: Framebuffer, camera: Camera, sky: SkyConfig, time: number, step = 1): void {
|
||||
export function render(fb: Framebuffer, camera: Camera, sky: SkyConfig, time: number, step = 1, y0 = 0, y1 = -1): void {
|
||||
const { width, height, color, depth } = fb
|
||||
const bottom = y1 < 0 ? height : y1
|
||||
const forward = Camera.forward(camera)
|
||||
const right = Vec3.normalize(Vec3.cross(forward, UP))
|
||||
const up = Vec3.cross(right, forward)
|
||||
|
|
@ -76,11 +77,13 @@ export namespace Sky {
|
|||
const clouds = sky.clouds
|
||||
const cloud: CloudSample = { cover: 0, shade: 1 }
|
||||
const s = Math.max(1, step | 0)
|
||||
for (let by = 0; by < height; by += s) {
|
||||
// Band `y0`..`bottom` must be step-aligned (callers ensure it) so the block
|
||||
// grid stays global and neighboring bands don't seam.
|
||||
for (let by = y0; by < bottom; by += s) {
|
||||
// Shade at the block center, then flood the whole block with that color.
|
||||
const sampleY = Math.min(height - 1, by + (s >> 1))
|
||||
const ndcY = 1 - ((sampleY + 0.5) / height) * 2
|
||||
const yEnd = Math.min(height, by + s)
|
||||
const yEnd = Math.min(bottom, by + s)
|
||||
for (let bx = 0; bx < width; bx += s) {
|
||||
const sampleX = Math.min(width - 1, bx + (s >> 1))
|
||||
const ndcX = ((sampleX + 0.5) / width) * 2 - 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue