使用WebRTC并应用着色器的Three.js
我不知道如何将着色器应用于具有视频纹理的three.js对象 我一直在使用webRTC和three.js,并使用标准材质成功地将视频纹理映射到网格上:使用WebRTC并应用着色器的Three.js,three.js,webgl,shader,webrtc,Three.js,Webgl,Shader,Webrtc,我不知道如何将着色器应用于具有视频纹理的three.js对象 我一直在使用webRTC和three.js,并使用标准材质成功地将视频纹理映射到网格上: var material = new THREE.MeshBasicMaterial({ color : 0xffffff, map : videoTexture }); 我想通过将着色器(本例中为sobel着色器)应用于此纹理来进一步了解它。我的尝试是:
var material = new THREE.MeshBasicMaterial({
color : 0xffffff,
map : videoTexture
});
我想通过将着色器(本例中为sobel着色器)应用于此纹理来进一步了解它。我的尝试是:
我收到了一堆无效的_操作警告,但在理解如何调试问题时遇到了困难。我也没有看到其他人这样做,因此我认为将这一知识公开是有益的:)
任何帮助都将不胜感激。你很接近。这是:。它至少在OSX上的Chrome下工作 您有一些着色器格式错误,需要将uv作为变量传递
var sobelShader = {
uniforms: {
'texture': {
type: 't',
value: videoTexture
},
'width': {
type: 'f',
value: 320.0
},
'height': {
type: 'f',
value: 240.0
}
},
vertexShader: [
'varying vec2 vUv;',
'void main() {',
'vUv = uv;',
'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
'}'
].join('\n'),
fragmentShader: [
'uniform sampler2D texture;',
'uniform float width;',
'uniform float height;',
'varying vec2 vUv;',
'void main(void) {',
'float w = 1.0/width;',
'float h = 1.0/height;',
'vec2 texCoord = vUv;',
'vec4 n[9];',
'n[0] = texture2D(texture, texCoord + vec2( -w, -h));',
'n[1] = texture2D(texture, texCoord + vec2(0.0, -h));',
'n[2] = texture2D(texture, texCoord + vec2( w, -h));',
'n[3] = texture2D(texture, texCoord + vec2( -w, 0.0));',
'n[4] = texture2D(texture, texCoord);',
'n[5] = texture2D(texture, texCoord + vec2( w, 0.0));',
'n[6] = texture2D(texture, texCoord + vec2( -w, h));',
'n[7] = texture2D(texture, texCoord + vec2(0.0, h));',
'n[8] = texture2D(texture, texCoord + vec2( w, h));',
'vec4 sobel_horizEdge = n[2] + (2.0*n[5]) + n[8] - (n[0] + (2.0*n[3]) + n[6]);',
'vec4 sobel_vertEdge = n[0] + (2.0*n[1]) + n[2] - (n[6] + (2.0*n[7]) + n[8]);',
'vec3 sobel = sqrt((sobel_horizEdge.rgb * sobel_horizEdge.rgb) + (sobel_vertEdge.rgb * sobel_vertEdge.rgb));',
'gl_FragColor = vec4( sobel, 1.0 );',
'}'
].join('\n')
}
three.js r.53非常有效。感谢您帮助@WestLangley更新以使用当前版本的three.js和当前标准
getUserMedia()
API:(使用Firefox 55进行测试)+1获得酷炫演示:-)(在Chrome中工作)