GAMEDEV.NET
generate vertex colors for a mesh
Author I have mesh and would like to generate vertex colors for the mesh, but have found no solutions, atleast for C++. The mesh looks like this://Vector3F is float[3], Vector2F is float[2] and Triangle is unsigned short[3] class Mesh{ Vector3F* positions; Vector3F* normals; Vector2F* uvMap1; Triangle* triangles; unsigned int numVertex unsigned int numTriangles; }; Just add per ver vertex color as you do with positions, normals, etc. The problem is not on the C++ side, but about the graphics API. You need to tell it which components a vertex has, e.g. additional color, or a second channel of texture coords. Advertisement Author JoeJ said:Just add per ver vertex color as you do with positions, normals, etc.The problem is not on the C++ side, but about the graphics API. You need to tell it which components a vertex has, e.g. additional color, or a second channel of texture coords.Sorry looks like I was completly misunderstood. Let say I have read a mesh from an obj file into my mesh structure. Unfortunatelly obj files store only positions, normals and texture coords, but no vertex colors. This has nothing to do with the graphics API. Just need to generate for the mesh the vertex colors, which were not present.So what I am asking, is some kind of algorithm, which creates for every vertex a coresponding color. Ah ok. But what gives you the ‘coresponding color’?I assume you want to paint the color in some modeling tool like Blender? If so, you could export using a file format which supports vertex colors, and you would also need a new importer for that file format. (Not sure about file formats, but i can confirm the AssImp library, which supports many formats, also supports up to 8 color channels per vertex.)If you instead want to generate the colors using some algorithm, you probably want to learn about ‘procedural texturing’, for example perlin noise, voronoi cells, or similar patterns.Related resources are the old but good book ‘Texturing and Modeling: A Procedural Approach’,or Inigo Quilez website, for example: https://iquilezles.org/articles/voronoilines/or the many examples on ShaderToyThose procedural techniques can be used to generate texture colors but also vertex colors. Well, you can go with 3-D binary Perlin noise, to make cow colouring:https://github.com/AnthonyNystrom/Julia-4D/blob/f1d743be8bd619c3f2d70d8d6514f5bc0bb98759/utilities.cpp#L285You can also do dot product based colouring:https://github.com/AnthonyNystrom/Julia-4D/blob/f1d743be8bd619c3f2d70d8d6514f5bc0bb98759/utilities.cpp#L196Also, there is rainbow colouring based on the distance from the origin:https://github.com/AnthonyNystrom/Julia-4D/blob/f1d743be8bd619c3f2d70d8d6514f5bc0bb98759/utilities.cpp#L79 Author I assume you want to paint the color in some modeling tool like Blender? I would like to do it like in some modeling tool, but in my own code. Importing every single model into modeling tool then manualy paint the color and reexporting the model in some new format suporting vertex colors is a big pain in the as. Advertisement convert said:I would like to do it like in some modeling tool, but in my own code. Importing every single model into modeling tool then manualy paint the color and reexporting the model in some new format suporting vertex colors is a big pain in the as.A warning from my personal experience: You can spend lots of time on your own tools, but chances are you will still end up using Blender & co, because overall those professional tools still offer more.Import / export can be automated, requiring a fraction of work compared to making your own mesh editing / painting.The real problem is probably the painting itself. No matter how good tools and asset pipeline is, you still need to do that manually.Eventually for a huge amount of models or levels. And because you didn't tell which kind of content you want to make, we can only give very broad proposals about procedural content generation methods aiming to replace manual work.Beside procedural patterns already mentioned, here are some other things which might help:Wavefunction collapse algorithm (can do procedural textures, but also procedural placement of modular geoemtry, up to entire levels.)Baking global illumination (place few lights and get beautiful color gardients everywhere without painting)Terrain simulation (erosion can give natural mountains and rivers)Maybe there is some magic algorithm which would generate good colors for your specific content, but there surely is no such algorithm working for anything (charaxcters, architecture, terrain, …). So you may want to tell more about your actual goals. Author JoeJ said:convert said:I would like to do it like in some modeling tool, but in my own code. Importing every single model into modeling tool then manualy paint the color and reexporting the model in some new format suporting vertex colors is a big pain in the as.A warning from my personal experience: You can spend lots of time on your own tools, but chances are you will still end up using Blender & co, because overall those professional tools still offer more.Import / export can be automated, requiring a fraction of work compared to making your own mesh editing / painting.The real problem is probably the painting itself. No matter how good tools and asset pipeline is, you still need to do that manually.Eventually for a huge amount of models or levels. And because you didn't tell which kind of content you want to make, we can only give very broad proposals about procedural content generation methods aiming to replace manual work.Beside procedural patterns already mentioned, here are some other things which might help:Wavefunction collapse algorithm (can do procedural textures, but also procedural placement of modular geoemtry, up to entire levels.)Baking global illumination (place few lights and get beautiful color gardients everywhere without painting)Terrain simulation (erosion can give natural mountains and rivers)Maybe there is some magic algorithm which would generate good colors for your specific content, but there surely is no such algorithm working for anything (charaxcters, architecture, terrain, …).So you may want to tell more about your actual goals.Some time ago, about 10 years, have read somewhere that in a modeling tool it is posible to place light(s) and then the tool wil generate colors afected by that light(s). In this case all I need to do is to play with some lights, but posibly I remember it wrong. convert said:Some time ago, about 10 years, have read somewhere that in a modeling tool it is posible to place light(s) and then the tool wil generate colors afected by that light(s). In this case all I need to do is to play with some lights, but posibly I remember it wrong.Yeah, that's possible. But there are potential issues, since you're baking lighting whioch the observer will identify as such:If you bake lighting this way, it is static. We would assume the lighting to change if objects move. Shadows should move with them, but they won't. Also, if you also bake lighting to dynamic models like characters, and then place them into a level with baked lighting as well, they may not fit together, looking wrong.The usual solution to this problem is:Bake only to the static level geometry, and only indirect lighting (indirect = light reflected from walls, but not directly from the light source itself).Then at runtime we calculate the direct lighting in realtime, adding it to both the static and the dynamic models. Eventually with shadows.The baked light is usually stored in textures ('lightmaps'), not vertices. This enables details also on large triangles. But baking per vertex is possible as well. (Usually any 3D modeling tool can be used to bake lighting to geometry.)So if you want to do this, you probably need to learn more about lighting as well. Or you ignore all the errors of incorrect lighting, which can be acceptable if your light palecement aims to add colors everwhere instead achieving realistic lighting. Maybe you even want to disable shadows to avoid the problematic realism. But maybe using only direct lights in realtime is an option too. Can look like this:No textures, no vertex colors, and only one shadowed spotlight is used.
0 Σχόλια 0 Μοιράστηκε 65 Views