-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[models] Display problem of vertex colors in the Raylib library for M3D models #3109
Comments
have you checked vertex colours are being loaded? how are you rendering the model, from memory I'm not sure the default shader uses vertex colours, if not you'll need to use a shader that uses these... |
@chriscamacho Effectively, the vertex colors are just not loading, so I will have to write a solution myself, thanks for your answer. |
I am back to the problem I presented here, and it turns out that you simply needed to add the following to
And the rest of the code was already implemented here: L2655 And the model displays its beautiful vertex colors! :D |
@Bigfoot71 Feel free to send a PR |
@raysan5 Well, I think if /* vertex entry */
typedef struct {
M3D_FLOAT x; /* 3D coordinates and weight */
M3D_FLOAT y;
M3D_FLOAT z;
M3D_FLOAT w;
uint32_t color; /* default vertex color */
M3D_INDEX skinid; /* skin index */
#ifdef M3D_VERTEXTYPE
uint8_t type;
#endif
} m3dv_t;
typedef struct {
/* [...] */
M3D_INDEX numvertex;
m3dv_t *vertex; /* vertex data */
/* [...] */
} m3d_t; In the m3d model, I might be mistaken, and someone more knowledgeable about this file format could correct me, but the only solution I can think of would be to allocate The solution I proposed above is correct for me in the sense that I'm sure there will be vertex colors for all my models. The current method used in LoadM3D is to check if you have allocated If we allocate |
@bztsrc please, could you take a look to this issue? |
Sure!
No, because M3D can store both vertex colors and materials (with textures). You can have a model with colors, that's only used by loaders that do not load materials; and never be shown by loaders that support materials and textures.
Of course, because color is a 32-bit packed pixel with separate RGBA channels.
You don't need mesh.colors at all. Even if the model uses a color-map, the SDK automatically converts that into 32-bit RGBA packed pixels, so all you can see is a consistent, true-color compatible code. And this is intended. You shouldn't know if the compression algorithm optimized the colors into a palette or not; you should get the same RGBA pixels for the vertex colors no matter how those were stored in the file.
Now this is a different thing. This relates to the VertexBuffer that the GPU uses. Yes, you could always allocate the colors array if you want, that won't hurt.
No. It would fill up mesh.colors with black pixels in worst case, this isn't problematic at all. BTW, even if the allocation fails and mesh.colors indeed becomes 0x0000000, there are checks to avoid NULL dereference, so that wouldn't be a problem either. To sum it up, I believe adding #3109 (comment) would waste some memory for vertex color-less models, but otherwise I see no harm at all. I think it should be merged. Cheers, |
I think this is a key point, most models nowaday do not use vertex colors, allocating vertex colors for every loaded model would be, in most cases, a waste of memory. |
Yes, you're right, it's not common. Here's a proper solution: rmodels.c.zip In this, when the number of vertices counted for a material, I've added an extra check to see if all vertex colors are fully transparent black or not. The mesh.colors array is only allocated if no materials is defined or there's at least one non fully transparent black color. I've tested this, it works perfectly with normal models (material only), models without materials (which supposed to use colors), and models with both materials and colors (in this case raylib's shader seems to mix the vertex color and the texture's color). NOTE: I've also added the materialCount fix from #3177 to this version. Cheers, ps: I'm terribly sorry for creating an attachment instead of a PR, but I have troubles with github ever since it changed to this JS heavy interface. Sorry about this! |
I believe there was a misunderstanding with my previous message, I must have expressed myself poorly. It's not a big deal though.
I had not seen that the loop used to browse the faces was already present, it looks perfect! |
@bztsrc thank you very much for the review! just merged your changes!
No problem! I agree this new interface is really slow! |
Issue description
I'm having a problem using raylib to display M3D models with vertex colors. The vertex colors are not displayed correctly in my scene, while the official m3dview viewer manages to display the vertex colors correctly.
Environment
Desktop, Windows 10, OpenGL 3.3:
Issue Screenshot
Code Example
test-m3d.zip
The text was updated successfully, but these errors were encountered: