Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates from ShaderMaterial to PointsMaterial in Particles.js #217

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 5 additions & 47 deletions src/sensors/Particles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,67 +26,25 @@ ROS3D.Particles = function(options) {
var that = this;
THREE.Object3D.call(this);

this.vertex_shader = [
'attribute vec3 customColor;',
'attribute float alpha;',
'varying vec3 vColor;',
'varying float falpha;',
'void main() ',
'{',
' vColor = customColor; // set color associated to vertex; use later in fragment shader',
' vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );',
' falpha = alpha; ',
'',
' // option (1): draw particles at constant size on screen',
' // gl_PointSize = size;',
' // option (2): scale particles as objects in 3D space',
' gl_PointSize = ', size, '* ( 300.0 / length( mvPosition.xyz ) );',
' gl_Position = projectionMatrix * mvPosition;',
'}'
].join('\n');

this.fragment_shader = [
'uniform sampler2D texture;',
'varying vec3 vColor; // colors associated to vertices; assigned by vertex shader',
'varying float falpha;',
'void main() ',
'{',
' // THREE.Material.alphaTest is not evaluated for ShaderMaterial, so we',
' // have to take care of this ourselves.',
' if (falpha < 0.5) discard;',
' // calculates a color for the particle',
' gl_FragColor = vec4( vColor, falpha );',
' // sets particle texture to desired color',
' gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );',
'}'
].join('\n');

this.geom = new THREE.Geometry();
for(var i=0;i<this.max_pts;i++){
this.geom.vertices.push(new THREE.Vector3( ));
this.geom.colors.push( new THREE.Color( options.color ) );
}

var customUniforms =
{
texture: { type: 't', value: THREE.ImageUtils.loadTexture( texture ) },
};

this.attribs =
{
customColor: { type: 'c', value: [] },
alpha: { type: 'f', value: [] }
};

this.shaderMaterial = new THREE.ShaderMaterial(
this.pointsMaterial = new THREE.PointsMaterial(
{
uniforms: customUniforms,
attributes: this.attribs,
vertexShader: this.vertex_shader,
fragmentShader: this.fragment_shader,
transparent: true,
size : size,
vertexColors : THREE.VertexColors
});

this.ps = new THREE.ParticleSystem( this.geom, this.shaderMaterial );
this.ps = new THREE.Points( this.geom, this.pointsMaterial );
this.sn = null;

this.points = this.geom.vertices;
Expand Down