1

I was reading on ThreeJS custom attributes and got confused about how to set them up.

So i've seen that we add an attribute to the geometry attribute list and then the same to the ShaderMaterial attributes list ?

My question is how to add custom attributes in 3js ?

3
  • Can you share some source code or a JSFiddle to let us know what you've tried already? It's a little hard to tell what you need without more context. Commented Apr 24, 2014 at 21:36
  • Search the three.js examples: threejs.org/examples/webgl_custom_attributes.html Commented Apr 24, 2014 at 22:02
  • I think i go it. So first i add an attribute to the geometry attribute list, call it Attrib1 Then on the the shader attributes, i've added that specific attribute to the list geometry.attributes = { Attrib1: { ... } } then in the material attributes: { Attrib1: { type: "f", value: null } } it seems to work. I came here because examples online were a bit confusing Commented Apr 24, 2014 at 22:52

1 Answer 1

3

The new version (r67) features RawShaderMaterial which allows full control of attributes/shaders. Here's an example:

http://threejs.org/examples/webgl_buffergeometry_rawshader.html

If you want something less "raw" but still performant, here's an example using BufferGeometry and ShaderMaterial:

http://threejs.org/examples/webgl_buffergeometry_custom_attributes_particles.html

And, if you want to use Geometry here's an example of that too:

http://threejs.org/examples/webgl_custom_attributes.html

Sign up to request clarification or add additional context in comments.

2 Comments

Cool, RawShaderMaterial sounds much better to me. Thanks
That last example uses buffergeometry.. From what I see there isn't a way to pass custom attributes to the shaders using a normal geometry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.