Three.js, custom shader and png texture with transparency -


i have extremely simple png texture: grey circle transparent background.

png image transparency

i use uniform map three.shadermaterial:

var uniforms = three.uniformsutils.merge( [basicshader.uniforms] ); uniforms['map'].value = three.imageutils.loadtexture( "img/particle.png" ); uniforms['size'].value = 100; uniforms['opacity'].value = 0.5; uniforms['pscolor'].value = new three.color( 0xffffff ); 

here fragment shader (just part of it):

gl_fragcolor = vec4( pscolor, vopacity ); gl_fragcolor = gl_fragcolor * texture2d( map,vec2( gl_pointcoord.x, 1.0 - gl_pointcoord.y ) ); gl_fragcolor = gl_fragcolor * vec4( vcolor, 1.0 ); 

i applied material particles (three.pointcloud mesh) , works quite well:

particles texture transparency: ok!

but if turn camera of more 180 degrees see this:

particles texture without transparency

i understand fragment shader not correctly taking account alpha value of png texture.

what best approach in case, right color , opacity (from custom attributes) , still alpha right png?

and why behaving correctly on 1 side?

transparent objects must rendered front -- furthest closest. because of depth buffer.

but pointcloud particles not sorted based on distance camera. inefficient. particles rendered in same order, regardless of camera position.

you have several work-arounds.

the first discard fragments alpha low. can use pattern so:

if ( texturecolor.a < 0.5 ) discard; 

another option set material.depthtest = false or material.depthwrite = false. might not side effects, however, if have other objects in scene.

three.js r.71


Comments

Popular posts from this blog

c# - Where does the .ToList() go in LINQ query result -

Listeners to visualise results of load test in JMeter -