I have a points material defined as follows:
const material = this.material = new THREE.PointsMaterial( {
size: this.data.radius,
map: new THREE.TextureLoader().load(this.data.textureSrc),
vertexColors: THREE.VertexColors,
alphaTest: 0.5,
transparent: false,
depthTest: true,
sizeAttenuation: true,
onBeforeCompile: shader => {
shader.vertexShader = `
attribute float rotation;
varying float vRotation;
${shader.vertexShader}
`.replace(
`#include <fog_vertex>`,
`#include <fog_vertex>
vRotation = rotation;
`
);
console.log(shader.vertexShader);
shader.fragmentShader = `
varying float vRotation;
${shader.fragmentShader}
`.replace(
`#include <map_particle_fragment>`,
`
#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
vec3 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
#endif
#ifdef USE_MAP
// MODIFICATION =======================================================
float mid = 0.5;
uv = vec3(
cos(vRotation) * (uv.x - mid) + sin(vRotation) * (uv.y - mid) + mid,
cos(vRotation) * (uv.y - mid) - sin(vRotation) * (uv.x - mid) + mid
);
// ====================================================================
vec4 mapTexel = texture2D( map, uv );
diffuseColor *= mapTexelToLinear( mapTexel );
#endif
#ifdef USE_ALPHAMAP
diffuseColor.a *= texture2D( alphaMap, uv ).g;
#endif
`
);
}
//console.log(shader.fragmentShader);
});
This allows me to add rotations to the individual points like so:
this.rotations = [an array of floats]
geometry.setAttribute( 'rotation', new THREE.Float32BufferAttribute( this.rotations, 1 ))
However, I need to be able to rotate in three dimensions. Is there a way to edit the shader so that I can pass a vec3 of x, y, and z rotations instead of single float?