-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
141 lines (114 loc) · 5.66 KB
/
index.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="expires" content="0">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/88/three.js"></script>
<script src="libs/three.FilterDefinitions.js"></script>
<script src="libs/filters/ColorInvert.js"></script>
<script src="libs/filters/EdgeDetect.js"></script>
<script src="libs/filters/ZoomBlur.js"></script>
<script src="libs/filters/Blends.js"></script>
<script src="libs/filters/Delay.js"></script>
<script src="libs/filters/Swirl.js"></script>
<script src="libs/filters/SphereRefraction.js"></script>
<script src="libs/filters/Pixelate.js"></script>
<script src="libs/filters/Math.js"></script>
<script src="libs/filters/BilateralBlur.js"></script>
<script src="libs/filters/Color.js"></script>
<script src="libs/filters/SobelEdgeDetection.js"></script>
<script src="libs/filters/Glitch.js"></script>
<script src="libs/filters/Pattern.js"></script>
<script src="libs/filters/Noise.js"></script>
<script src="libs/three.FilterChain.js"></script>
<script type="text/javascript">
function init() {
var canvas = document.getElementById('mainCanvas')
var renderer = new THREE.WebGLRenderer({ canvas: canvas })
var scene = new THREE.Scene();
// camera
// canvas size is 400x300
var camera = new THREE.OrthographicCamera(-2, 2, 1.5, -1.5, 1, 10);
camera.position.set(0, 0, 5);
scene.add(camera);
//
// var trippy = new THREE.Trippy( renderer, scene, camera )
// var a = trippy.createFilter( "Hue" )
// // var aa = trippy.createFilter( "Grow", {a: 0.07} )
// var b = trippy.createFilter( "Mod" )
// var c = trippy.createFilter( "Hue" )
// var d = trippy.createFilter( "Double" )
//
// a.uniforms.hueAdjust.update = (x) => x+.01309
// c.uniforms.hueAdjust.update = (x) => x-.04
// // aa.uniforms.a = 0.001
//
// trippy.addTarget( a )
// a.addTarget(b)
// // aa.addTarget(b)
// b.addTarget(c)
// c.addTarget(d)
// d.addTarget( "screen" )
var trippy = new THREE.Trippy( renderer, scene, camera )
trippy.addTarget( "screen" )
// video texture
var videoImage = document.createElement('canvas');
videoImage.width = canvas.width;
videoImage.height = canvas.height;
var videoImageContext = videoImage.getContext('2d');
videoTexture = new THREE.Texture(videoImage)
videoTexture.minFilter = THREE.LinearFilter
videoTexture.magFilter = THREE.LinearFilter
var videoMaterial = new THREE.MeshBasicMaterial({
map: videoTexture,
overdraw: true
})
var videoGeometry = new THREE.PlaneBufferGeometry(4, 3)
var videoMesh = new THREE.Mesh(videoGeometry, videoMaterial)
videoMesh.position.set(0, 0, 0)
scene.add(videoMesh)
// local video
var video = document.getElementById('video');
var facingMode = "user";
var constraints = {
audio: false,
video: { facingMode: "environment" }
}
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
video.srcObject = stream
video.onloadedmetadata = function(e) {
videoImage.width = this.videoWidth
videoImage.height = this.videoHeight
video.play()
renderFrame()
}
})
function renderFrame() {
videoImageContext.drawImage(video, 0, 0)
if (videoTexture) {
videoTexture.needsUpdate = true
}
trippy.render()
// f.uniforms.edgeStrength.value = 3+3*Math.sin( Date.now()/1000.0 )
// f3.uniforms['blurSize'].value = (10 + 10.0 * Math.sin( Date.now()/3000.0 )
// f3.uniforms['blurCenter'].value = new THREE.Vector2( 0.5+Math.sin( Date.now()/100)/2.0, 0.5+Math.cos( Date.now()/100)/2.0 )
requestAnimationFrame(renderFrame)
}
}
</script>
<style>
canvas{
position: absolute;
top: 0; left: 0;
width: 90%; height: 75%; padding-top:5%; padding-left: 5%;
}
body{ background-color: black;}
</style>
</head>
<body onload="init()">
<canvas id="mainCanvas" width="1800px" height="1350px" ></canvas>
<video style="display:none;" id="video" width="1800px" height="1350px" autoplay playsinline></video>
<!-- <script>
(function(){var script=document.createElement('script');script.onload=function(){var stats=new Stats();document.body.appendChild(stats.dom);requestAnimationFrame(function loop(){stats.update();requestAnimationFrame(loop)});};script.src='//rawgit.com/mrdoob/stats.js/master/build/stats.min.js';document.head.appendChild(script);})()
</script> -->
</body>
</html>