Several ways to color a mesh

Blitz3D Forums/Blitz3D Programming/Several ways to color a mesh

RemiD(Posted 2016) [#1]
double post


RemiD(Posted 2016) [#2]
Hello, :)

As you may know, there are several methods to color a mesh :

-You can use different materials/brushes to color the triangles of the mesh, but in this case there will be one surface for each material, and this is bad (will increase rendering time)

-You can unwrap/texelsfill/uvmap some vertices/triangles of the mesh and then color the texels of the texture, in this case there will be one surface for all "materials", and this is good (will decrease rendering time)

-You can use vertex color to color the triangles of the mesh, in this case there will be one surface for all "materials", and this is good (will decrease rendering time)

But there is also another method,n which i have never seen used by anybody (except by me ;) ) so i will try to explain :
-the idea is to color the triangles of the mesh with different materials, and then, when you load it inside Blitz3d, to analyze the mesh and the number of surfaces, then to create a texture of 8w*surfacescount,8h, then to create a small rectangle on the texture (of 8w,8h, of the same color than the color of the material), then to set the uv coords of all vertices of this surface to the center of the small rectangle (depending on how it is positionned on the texture), then to add the surface to a final surface, then to apply the final texture on the final surface.
So, at the end there will be only one surface but with its triangles colored with different colors by one texture. So one surface, one texture, and this is good (will decrease rendering time)

And of course all is done automatically (except the texture width which is defined manually to be a power of 2 (this power of 2 rule thing is sooo annoying !)

This is a good alternative to color meshes and it is fast to render...


Bobysait(Posted 2016) [#3]

-You can unwrap/texelsfill/uvmap some vertices/triangles of the mesh and then color the texels of the texture, in this case there will be one surface for all "materials", and this is good (will decrease rendering time)



It's actually the same technique.
What you're speaking of is just a baking method to recreate the technique via a loaded scene, but in the end, you'll have a texture with some colored pixels and triangles UVs set to fit the pixels of the corresponding color. So it's not another technique, but only a workaround to get this technique working from an external file. (which is still a very good thing)

ps : BTW, your baking process can't be done in native blitz3D, you'll have to use one or the other method to get brush colors (by a dll or memory hack or the blitz3d "add-ons" version) - You probably already know this, but I mention it for anyone who could read this.


RemiD(Posted 2016) [#4]
method4 uses a mix of method1 and method2 but the uvmapping is done automatically by a routine.

the idea is to make a higher details mesh and to color the triangles instead of having to unwrap/texelsfill/uvmap/texelscolor which can be time consuming and annoying to do...

if i remmember correctly i have managed to get the texture filename associated to a material (and coloring all triangles of a surface with a small 8x8 texture is not complicated and takes little time)

also not tested but to get the material color : http://www.blitzbasic.com/Community/posts.php?topic=75711


RemiD(Posted 2016) [#5]

also not tested but to get the material color : http://www.blitzbasic.com/Community/posts.php?topic=75711


tested and it works well, i manage to get the brush color (red, green, blue) and alpha, properties


RemiD(Posted 2016) [#6]
What i wrote in post #2 is not true because if you use a texture (texels colors) + a material/brush with a 255,255,255 color, 2 blends are happening : a blend between the texture (texels colors) and the material/brush (material/brush color), and a blend between the material/brush and the environment.
Whereas if you only use vertices colors, only one blend is happening, and if you use only materials/brushes colors, only 1 blend is happening.

So to keep a consistent appearance, the best approach (imo) is to use a texture (texels colors) + a material/brush with a 255,255,255 color and you can either unwrap/texelsfill/uvmap the faces of each part to keep a consistent texel size, or unwrap/texelsfill/uvmap each part and scale it down on the uvmap to color it with one color. (for example all vertices of each part positionned at the center of a small 4x4 colored rectangle, with several small 4x4 colored rectangles on the same texture, one for each "material").

The second approach i suggest here is fast to do since you only have to model your mesh and then the coloring is per "material" using several small 4x4 colored rectangles (on the same texture).

And you can also mix a detailed unwrap/texelsfill/uvmap/coloring and a quick unwrap/texelsfill/uvmap/coloring (with several small 4x4 colored rectangles)


K(Posted 2017) [#7]
I have actually used the same technique at times RemiD. I wld say yeah it's just a proceduralized method 2 in your above post. I've also combined it with greyscale vertex coloring for artificial shadowing.