This is a test for a more complex 2D data visualisation. I am trying to place 200 particles/points on the screen with a shader (there will be many more in the real application). My data contains 200 values between 9000$ and 11000$, with 10$ increments. I simply need to centre the particles on the X axis (simply 0!) and scale them on the Y axis in order to show a certain range within the viewport (1000$).
const RANGE = 1000; // visible $ within viewport height
const MID_VALUE = 10000; // center of the screen
const PARTICLES_COUNT = 200;
const SIZE = 16; // texture size
const FRUSTUM = 2;
So i have a DataTexture with all the values that i will send to the shader:
array = new Float32Array(SIZE * SIZE * 4);
for (var i = 0; i < PARTICLES_COUNT * 4; i += 4) {
array[i + 1] = 9000 + (i / 4) * 10
}
dataTexture = new THREE.DataTexture(
array,
SIZE,
SIZE,
THREE.RGBAFormat,
THREE.FloatType
)
dataTexture.needsUpdate = true;
And an orthographic camera:
const aspect = window.innerWidth / window.innerHeight;
camera = new THREE.OrthographicCamera(
FRUSTUM * aspect / -2,
FRUSTUM * aspect / 2,
FRUSTUM / 2,
FRUSTUM / -2,
1,
1000
);
camera.position.z = 500;
And this is the way i calculate the scale to be applied to the data inside the vertex shader:
scale = FRUSTUM / RANGE;
The particles are correctly scaled and centred but they are not evenly spaced on the Y axis, as they are supposed to be according to the data. Could this be a precision issue? Or what is wrong?
You can see the code here: http://jsfiddle.net/bze7sgmy/4/