Alvaro Posted November 20, 2014 Share Posted November 20, 2014 Hi guys, I have read some tutorials about ShaderMaterial, but I don't see in any of then if it is possible to add custom attributes apart from position, uv and normal. What I would like is create a list of floats (one for each position) and keep it in the mesh (so far so good).When creating the ShaderMaterial, I want to add this list as another attribute so I can take the right value for each position when rendering the material and work with it. Any ideas? Cheers. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 21, 2014 Share Posted November 21, 2014 Hello, this is perfectly feasible using ShaderMaterial constructor:)var myShaderMaterial = new BABYLON.ShaderMaterial("cloud", scene, { vertexElement: "vertexShaderCode", fragmentElement: "fragmentShaderCode", }, { needAlphaBlending: true, attributes: ["position", "uv", "listOfStuff"], uniforms: ["worldViewProjection"], samplers: ["textureSampler"] });You have then to use mesh.setVerticesData("listOfStuff", data) to fill your data Quote Link to comment Share on other sites More sharing options...
Alvaro Posted November 21, 2014 Author Share Posted November 21, 2014 Thank you Deltakosh! Quote Link to comment Share on other sites More sharing options...
Alvaro Posted November 22, 2014 Author Share Posted November 22, 2014 Hi Deltakosh, I did exactly was you told me, but when I define and try to use the new attribute "listOfStuff" in the vertex and fragment files I am getting this error: [.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 3 I have checked the mesh and I can see my new list of floats when doing the getVerticesDataKinds, it is looking good. The way I have defined the attribute in the shader is like this: attribute float listOfStuff; It looks like the new attribute is not properly set at the moment the vertex files is executing. I was expecting the same behavior we have with normal, uv and position. Do I have to manually set the attribute values using the "setFloats"? If that is the case, I have to create a new material for each mesh and I was using the same material for several meshes. ideas? Cheers. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 22, 2014 Share Posted November 22, 2014 This *should* work Could you reproduce it on the playground? Will be easier to help you then Quote Link to comment Share on other sites More sharing options...
Alvaro Posted November 22, 2014 Author Share Posted November 22, 2014 ok, I will try, sometime has to be the first time I use the playground. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Alvaro Posted November 22, 2014 Author Share Posted November 22, 2014 Sorry Deltakosh, but how can I add shaders to the play ground? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 24, 2014 Share Posted November 24, 2014 Arf yes this is not convenient. Please send me your project then Quote Link to comment Share on other sites More sharing options...
Alvaro Posted November 26, 2014 Author Share Posted November 26, 2014 Not sure if this is the right way of sharing this, so let me know about it. I have the proof of concept ready and failing as expected. I am trying to replicated as much as possible what I am doing, so it should give you an idea. I have created a dummy html file (it should work just clicking, well, fail as expected):https://dl.dropboxusercontent.com/u/63244599/CustomAttributes/CustomAttributes.html It also include a simple js file and two images. Thank you! Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 26, 2014 Share Posted November 26, 2014 Maybe putting all your files in a .zip would have been more convenient. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 27, 2014 Share Posted November 27, 2014 Gotcha! I fixed the issue by adding a new parameter to setVerticesData(kind, data, updatable, stride) In you case stride is 1 (size in float of your data) Quote Link to comment Share on other sites More sharing options...
Alvaro Posted November 28, 2014 Author Share Posted November 28, 2014 Yes! it works, So depending of the type of the new attribute I have to use a different stride? what about if I have two custom attributes floats? It is 1 + 1. I don't really understand why is 1 but I will try to dig into the code. cheers! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 28, 2014 Share Posted November 28, 2014 number of float usedin your case only one float for a vec2: 2 floats and so on Quote Link to comment Share on other sites More sharing options...
Alvaro Posted November 29, 2014 Author Share Posted November 29, 2014 understood, thank you Deltakosh! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.