I use ShaderMaterial to create point cloud with attribute based size and opacity. I also need to texture map. The problem is that texture is rendered without transparency. Looks like each texture pixel color is blended somehow with background color (white in this case); How to avoid this this?
I use svg texture:
<div id="circle-texture" style="width: 0; height: 0; display: none">
<svg width="32" height="32" xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="16" cy="16" r="13" stroke="none" fill="white" fill-opacity="1" />
</svg>
</div>
Here is my fragment shader:
<script type="x-shader/x-fragment" id="point-cloud-fragment-shader">
...
uniform sampler2D texture;
varying vec3 vColor;
varying float vOpacity;
#include <clipping_planes_pars_fragment>
void main() {
#include <clipping_planes_fragment>
vec3 outgoingLight = vec3( 0.0 );
vec4 diffuseColor = vec4( diffuse, vOpacity );
if (enableTexture) {
vec4 mapTexel = texture2D( texture, gl_PointCoord );
diffuseColor *= mapTexelToLinear( mapTexel );
}
diffuseColor.rgb *= vColor;
outgoingLight = diffuseColor.rgb;
gl_FragColor = vec4( outgoingLight, diffuseColor.a );
}
Discarding fixes if:
if ( gl_FragColor.a < 0.001 ) discard;
But is it possible without discarding? (with custom blending or something else) I've played with custom blending but without success so far.
three.js
does when configuring Material.alphaTest. Can you please demonstrate your progress of work as a live example that shows your custom blending? – Mugen87transparent
property of your shader material totrue
? – Mugen87material.depthWrite = false
andpoints.renderOrder = 999;
– WestLangley