Animating the x,y,z coordinates of vertices in a sphere-like manner with horizontal rings around the center using attributes on a THREE.Points() object has been quite intriguing. Initially, with a MeshStandardMaterial(), tilting the Points object along the z-axis by setting points.rotation.z = 0.2 worked perfectly :
https://i.sstatic.net/SEubx.jpg
However, upon switching to ShaderMaterial() and transferring the animation logic into a shader, I noticed that the z-tilt disappeared. Despite confirming through an axis helper that the Points object was indeed still tilted, it seemed like the shader animation was now affecting the vertices based on the x, y, z coordinates of the scene rather than the tilted Points object.
https://i.sstatic.net/QEVOF.jpg
The image clearly shows that the sphere and outer ring of particles are no longer tilted at the same angle as indicated by the axis helpers.
I'm wondering if there's a simple solution to rectify this issue or if I need to adjust the shader animation to accommodate an overall rotation?
Thank you.
Below is the requested shader script, but after experimenting with similar shader animations from various tutorials, it seems like they all exhibit the same behavior. Hence, I suspect this might be an inherent problem or expected functionality with shaders:
#define PI 3.1415926535897932384626433832795
uniform float uSize;
attribute float aScale;
attribute vec4 aParticle;
uniform float uTime;
varying vec3 vColor;
void main()
{
/**
* Position
*/
vec4 modelPosition = modelMatrix * vec4(position, 1.0);
/**
* Particle
*/
float moveT = aParticle.g;
float moveS = aParticle.r + uTime * aParticle.b;
float fullRotate = step(360.0, moveS);
moveS = moveS - (fullRotate * 360.0);
float radMoveS = moveS * (PI / 180.0);
float radMoveT = moveT * (PI / 180.0);
modelPosition.x = aParticle.a * cos(radMoveS) * sin(radMoveT); //x
modelPosition.y = aParticle.a * cos(radMoveT); //y
modelPosition.z = aParticle.a * sin(radMoveS) * sin(radMoveT); //z
vec4 viewPosition = viewMatrix * modelPosition;
vec4 projectedPosition = projectionMatrix * viewPosition;
gl_Position = projectedPosition;
/**
* Size
*/
gl_PointSize = uSize * aScale;
//Attenuation
gl_PointSize *= ( 1.0 / - viewPosition.z );
/**
* Color
*/
vColor = color;
}