저는 비디오를 크로 마키하기 위해 this shader을 사용하고 있습니다. 내가 좋아하는 것 불투명도를 추가 동일한 비디오에. 불투명도 구성 요소를 셰이더에 추가하려고 시도했지만 더 많은 것이 누락되어 있어야합니다 (모름).프래임의 chromakey 쉐이더에 불투명도를 추가하십시오.
opacity: {type: 'number', is: 'uniform', default: 0.5}
그리고 업데이트 기능에 : 내가 스키마에서 불투명도를 추가 한
다음this.material.uniforms.opacity = data.opacity
의 모든 쉐이더 코드 :
AFRAME.registerShader('chromakey', {
schema: {
src: {type: 'map'},
color: {default: {x: 0.1, y: 0.9, z: 0.2}, type: 'vec3', is: 'uniform'},
transparent: {default: true, is: 'uniform'},
opacity: {type: 'number', is: 'uniform', default: 0.5}
},
init: function (data) {
var videoTexture = new THREE.VideoTexture(data.src)
videoTexture.minFilter = THREE.LinearFilter
this.material = new THREE.ShaderMaterial({
uniforms: {
color: {
type: 'c',
value: data.color
},
texture: {
type: 't',
value: videoTexture
}
},
vertexShader: this.vertexShader,
fragmentShader: this.fragmentShader
})
},
update: function (data) {
this.material.color = data.color
this.material.src = data.src
this.material.transparent = data.transparent
this.material.uniforms.opacity = data.opacity
},
vertexShader: [
'varying vec2 vUv;',
'void main(void)',
'{',
'vUv = uv;',
'vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);',
'gl_Position = projectionMatrix * mvPosition;',
'}'
].join('\n'),
fragmentShader: [
'uniform sampler2D texture;',
'uniform vec3 color;',
'varying vec2 vUv;',
'void main(void)',
'{',
'vec3 tColor = texture2D(texture, vUv).rgb;',
'float a = (length(tColor - color) - 0.5) * 7.0;',
'gl_FragColor = vec4(tColor, a);',
'}'
].join('\n')
})
'a = 0.3'을 설정하면 어떻게됩니까? – gaitat
나는 프래그먼트 쉐이더에서 'a'를 언급하고 있다고 가정합니다. 그렇다면 불투명하지만 크로 마키 효과를 잃어 버리게됩니다. – dianadfonseca
상수 알파를 설정하면 불투명도가 생성되는지 여부를 확인하기 만하면됩니다. 불투명도를 얻으므로 문제는 'a'에 사용하는 수식과 관련이 있습니다. [0,1]에 가깝기 때문에 그 기능의 한계는 무엇입니까? 즉, 가능한 최소값은 무엇이고 가능한 최대 값은 무엇입니까? 음의 값이나 값이 1보다 훨씬 높으면 드라이버가 클램핑하여 대부분의 시간에 원하는 효과를 잃어 버리게됩니다. – gaitat