0

I have a PointCloud in which I am using to visualize some time-related data points. For each vertex in the PointCloud.Geometry, I'd like to assign an attribute which is an array of epoch times.

These epoch times are ints, an example would be:
epochTimes = [1432314839, 1432314840, 1432314841];

the custom attributes would look like this:

attributes = {

    epochTimes: {   type: 'f', value: [] }

};

Will 'f' actually work?

I saw some interesting uniform types in the wiki, specifically uIntArray, which is iv1. I get an error when using that data type as an attribute. It may be reserved for only uniforms.

Is there any way I can assign an array of values as an attribute to a vertex?

Jared
  • 607
  • 1
  • 6
  • 28

1 Answers1

0

These kind of attribute assignment is Three.js specific. If you always have by three times in your array, you could use vec3 type.

attributes = {
     epochTimes: {   type: 'iv3', value: null } // 'iv3' specifies that attribute type is ivec3, like as 'f' specifies that it would be float type in the shader
};

For more code and complete example take a look at http://threejs.org/examples/webgl_buffergeometry_custom_attributes_particles.html.

You could try and bind a texture whose data is actually encoded epoch times, and use that in fragment shader.

To answer you question, can you send an array of data to a vertex shader - no. (related topic - Is it possible for a vertex attribute to be an array in GLSL-ES 2.0?)

Community
  • 1
  • 1
Dragan Okanovic
  • 7,509
  • 3
  • 32
  • 48
  • thanks for the reply. The idea about binding the data into a texture sounds interesting. Going to give it a try. Thanks a bunch. – Jared May 22 '15 at 20:55
  • It would be great if you could sample the texture within vertex shader, but you can't, not with current webGL. If reply helped you, please accept it. Thanks. – Dragan Okanovic May 22 '15 at 21:03
  • 1
    @AbstractAlgorithm That's not correct. `texture2D` and related functions are available in vertex shaders. For example, [acko.net's banner](http://acko.net/blog/zero-to-sixty-in-one-second/) is built on storing vertex positions in textures. – Kevin Reid May 23 '15 at 02:48
  • @KevinReid I thought that sampling wasn't possible in vertex shader, but indeed, newer versions of broth FF and Chrome support it. Sorry for misinformation. – Dragan Okanovic May 23 '15 at 10:37