-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
66 lines (54 loc) · 1.73 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
AFRAME.registerShader('transparent-video', {
schema: {
src: { type: 'map' },
},
applyWebmShader: function(videoEl) {
const videoTexture = new THREE.VideoTexture(videoEl);
videoTexture.format = THREE.RGBAFormat;
this.material = new THREE.MeshBasicMaterial({
map: videoTexture, transparent: true,
});
},
applyHEVCShader: function(videoEl) {
const videoTexture = new THREE.VideoTexture(videoEl);
const alphaTexture = new THREE.VideoTexture(videoEl);
videoTexture.format = THREE.RGBAFormat;
alphaTexture.format = THREE.AlphaFormat;
this.material = new THREE.ShaderMaterial({
vertexShader: `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
varying vec2 vUv;
uniform sampler2D videoTexture;
uniform sampler2D alphaTexture;
void main() {
vec4 videoColor = texture2D(videoTexture, vUv);
vec4 alphaColor = texture2D(alphaTexture, vUv);
gl_FragColor = vec4(videoColor.rgb, alphaColor.a);
}
`,
uniforms: {
videoTexture: { type: 't', value: videoTexture },
alphaTexture: { type: 't', value: alphaTexture }
},
transparent: true
});
},
init: function (data) {
const videoEl = data.src;
const videoUrl = new URL(videoEl.currentSrc);
const splitedUrl = videoUrl.pathname.split('.');
const videoType = splitedUrl[splitedUrl.length - 1]?.toLowerCase();
data.transparent = true;
if (videoType === 'webm') {
this.applyWebmShader(videoEl);
} else {
this.applyHEVCShader(videoEl);
}
},
});