I am currently in the process of converting a project over to use TheeJS, and an initial implementation made use of PointsMaterial
to help render a collection of points orbiting a planet, but now I am trying to use ShaderMaterial
in its place, so that I can make these points more circular and add the glow effect in the original. The problem is now I don’t see any points being rendered, and being a newbie with shaders I am a little confused as to what I am doing wrong?
I am using one of the ThreeJS example projects as reference, but I not sure where I am going wrong.
The code using PointsMaterial
:
const geometry = new BufferGeometry();
geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
const material= new PointsMaterial({
color: 'grey',
size: 3,
sizeAttenuation: false,
vertexColors: true,
blending: AdditiveBlending,
});
this.geometry = geometry;
this.particles = new Points( geometry, material );
if (this.scene) {
this.scene.add( this.particles );
}
Then I swapped out the PointsMaterial
for the ShaderMaterial
:
const shader = this.shaderStore.getShader('dot');
const material = new ShaderMaterial({
uniforms: {
color: { value: new Color( 0xffffff ) },
pointTexture: { value: new TextureLoader().load( '/StuffInSpace/images/spark1.png' ) }
},
vertexShader: shader.vertex,
fragmentShader: shader.fragment,
blending: AdditiveBlending,
depthTest: false,
transparent: true
});
Then shaders code, for the fragement:
uniform vec3 color;
uniform sampler2D pointTexture;
varying vec3 vColor;
void main() {
gl_FragColor = vec4( color * vColor, 1.0 );
gl_FragColor = gl_FragColor * texture2D( pointTexture, gl_PointCoord );
}
and for the vertex:
attribute float size;
attribute vec3 color;
varying vec3 vColor;
void main() {
vColor = color;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_PointSize = size * ( 300.0 / -mvPosition.z );
gl_Position = projectionMatrix * mvPosition;
}
Can anyone point me int the right direction?
BTW the project source, with the draft branch is available at: GitHub - ajmas/StuffInSpace at issue-1-threejs