I’m using the code below.
I can’t touch depthwrite and depthTest because of other rendering issues.
I used a shader to make my one tubegeometry transparent in the front and not transparent in the back, but I want to have a line projected from the transparent part to the back…
How do I do this.
const lineMaterial = new THREE.ShaderMaterial({
uniforms: {
color: { value: new THREE.Color("red") },
maxZ: { value: 0.0 },
minZ: { value: 0.0 }
},
vertexShader: `
uniform float maxZ;
uniform float minZ;
varying float alpha;
void main() {
float range = maxZ - minZ;
alpha = smoothstep(0.5, 1.0, (abs(position.z - minZ) / range));
alpha = min(alpha, 0.8); // 최대 0.7까지 제한
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
uniform vec3 color;
varying float alpha;
void main() {
gl_FragColor = vec4(color, 1.0 - alpha); // 처음이 밝고 뒷부분이 어둡게
}
`,
transparent: true,
depthTest: true, // 선이 다른 객체를 가리지 않도록 depthTest를 비활성화
depthWrite: true,
});