[英]three.js transparent texture and shader material
I'm using a circle texture to render particles: 我正在使用圆形纹理渲染粒子:
The circle has transparent pixels. 圆圈具有透明像素。 I'm using
ShaderMaterial
and BufferGeometry
to provide custom size, color for each node. 我正在使用
ShaderMaterial
和BufferGeometry
为每个节点提供自定义大小,颜色。 However I'm stuck with proper z-index rendering. 但是我坚持正确的z-index渲染。 In the image below:
在下图中:
The white particle is the nearest to the camera, the cyan ( 0x00ffff
) is the second, and hibiscus color on the top right ( 0xC3206F
looks pinkish) is the farthest. 白色粒子距离相机最近,蓝色(
0x00ffff
)是第二个,右上角的芙蓉色( 0xC3206F
看起来是粉红色)最远。
As you can see the order is not correct. 如您所见,顺序不正确。 Ideally white circle should fully override cyan, and partially cover hibiscus.
理想情况下,白色圆圈应完全覆盖青色,并部分覆盖芙蓉。 If I set
depthTest: true
for ShaderMaterial
, the transparent regions of the texture become solid: 如果为
ShaderMaterial
设置depthTest: true
,则纹理的透明区域将变为实心:
Here is the full source code: http://jsbin.com/mikimifipi/edit?js,output 这是完整的源代码: http : //jsbin.com/mikimifipi/edit?js,输出
I'm probably missing something with blending or messed up with the shaders. 我可能会缺少一些混合功能,或者将着色器弄乱了。 Can you please help?
你能帮忙吗?
The particles are rendered in the order specified by BufferGeometry
. 以
BufferGeometry
指定的顺序渲染粒子。
If depthTest = true
, the material is not becoming solid, as you claim -- the particles behind it (and rendered later) are simply not being rendered at all. 如果
depthTest = true
,则该材料不会像您所声称的那样变成固体-它后面的粒子(以及稍后渲染)根本就不会渲染。
You can improve some artifacts by setting if ( tColor.a < 0.5 ) discard;
您可以通过设置
if ( tColor.a < 0.5 ) discard;
来改善一些伪像if ( tColor.a < 0.5 ) discard;
. 。
You likely should not be premultiplying your fragment shader output RGB by alpha. 您可能不应该将片段着色器输出RGB预乘以alpha。 That is not the correct thing to do when using the default alpha-blending in three.js.
在three.js中使用默认的alpha混合时,这不是正确的选择。 It is also is what is causing the ring to appear around the white disk.
这也是导致环出现在白色磁盘周围的原因。
three.js r.71 three.js r.71
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.