-
Notifications
You must be signed in to change notification settings - Fork 0
/
rumination.ts
59 lines (48 loc) · 1.42 KB
/
rumination.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { TRIANGLE_STRIP } from 'luma.gl/constants'
import { $, Cell, Seed, ReadObject } from './loop'
import { Shader } from './shader'
import { Swapper } from './framebuffer'
import { Stage, GLContext } from './contexts'
export interface Props {
shader: Shader
uniforms?: object
opacity?: number
width?: number
height?: number
}
export default function Rumination(props: Props, cell?: Cell) {
if (!cell) return Seed(Rumination, props)
const gl = $(GLContext)
if (!gl) return
const { width=gl.drawingBufferWidth,
height=gl.drawingBufferHeight } = props
const framebuffers = cell.readChild(Swapper({ width, height }))
const shader = cell.read(props.shader)
const uniforms = cell.read(ReadObject(props.uniforms || {}))
const aPosition = cell.read(Stage.aPosition)
const vertexCount = cell.read(Stage.uCount)
if (!framebuffers || !shader || !uniforms || !aPosition) return
const { src, dst } = framebuffers
if (!src || !dst) return
uniforms.uInput = src.color
shader.vertexArray.setAttributes({ aPosition })
gl.viewport(0, 0, width, height);
shader.program.draw({
vertexArray: shader.vertexArray,
vertexCount,
drawMode: TRIANGLE_STRIP,
framebuffer: dst,
uniforms: {
...uniforms,
uInput: src.color,
uStep: Float32Array.from([1 / width, 1 / height]),
}
})
return {
input: src,
output: dst.color,
src,
dst,
opacity: props.opacity
}
}