저는 Three.js
을 사용하고 있으며 모든 입자가 다른 투명도와 색상을 가질 수있는 ParticleSystem
을 가지고 있습니다.Three.js ParticleSystem 투명도 문제
코드 :
var shaderMaterial = new THREE.ShaderMaterial({
uniforms: customUniforms,
attributes: customAttributes,
vertexShader: document.getElementById('vertexshader').textContent,
fragmentShader: document.getElementById('fragmentshader').textContent,
transparent: true,
alphaTest: 0.5
});
particles = new THREE.ParticleSystem(geometry, shaderMaterial);
particles.dynamic = true;
버텍스 쉐이더 :
attribute float size;
attribute vec3 color;
varying vec3 vColor;
void main() {
vColor = color;
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
//gl_PointSize = size;
gl_PointSize = size * (300.0/length(mvPosition.xyz));
gl_Position = projectionMatrix * mvPosition;
}
조각 쉐이더 :
uniform sampler2D texture;
uniform float alpha;
varying vec3 vColor;
void main() {
gl_FragColor = vec4(vColor, 100);
vec4 textureColor = texture2D(texture, gl_PointCoord);
gl_FragColor = gl_FragColor * textureColor;
gl_FragColor.a = alpha;
}
텍스처가 원하지만 난 알파를 설정,이 같은 : gl_FragColor.a = alpha
, 내 텍스처 검은 색 사각형의 원이 되려면 알파 수준은 괜찮지 만 사각형이 필요없고 원만이 필요합니다. 알파를 설정하지 않으면 사각형이 나타나지 않습니다. 제공된 텍스처에 대해 알파를 올바르게 설정하는 방법은 무엇입니까?
고맙습니다. 예를 들자면 내가 원하는 것입니다. 그리고 코드를 단순화하여 vertexshader에서만 알파를 설정했습니다. – Sergey