Passing UVs to shader

Hi everyone!

I’m working on an application that uses Cycles to do pretty renders for my realtime scenes.
Based on code snooping and the standalone application, I’ve got the basics working, like geometry and I believe shaders as well.
Now I’m having some issues using UVs on the geometry. On the image below (1), the small window is Cycles, the larger viewport is a realtime visualization of the scene. As it is clear, the UV mapping is not working. I know it is the UV map because if I change the texture to a block color of some sort, the Cycles rendered image changes accordingly (for example, if the cube uses a full red texture, it becomes red in both the realtime and the Cycles viewport, which leads me to assume that all the UVs are being set to zero).
I created a shader graph with Blender that does what I want (2):
And I translated that into code (3):
This seems to be correct, as far as I can understand the API.
So the problem is probably related to the geometry itself, but that also seems to be correct (4).
I create an extra attribute in the mesh, of type ATTR_STD_UV, with name “UVMap”, and I fill it with for every triangle in the geometry.

(sorry about the big image, you’ll have to open in new tab to be able to read it, can only upload one image per post)

I’m a bit out of ideas, so if anybody has any idea on what I’m doing wrong, or even just a suggestion on how to look for the issue, I’d appreciate it!

Best regards,
Diogo

I’ve tried to get a sample with simple texture mapping working with the standalone Cycles application, and I also got nowhere with that, if someone wants to take a look.

XML: Dropbox - scene_cube_surface2.xml - Simplify your life
Object: Dropbox - cube2.xml - Simplify your life

Just add any image with the name texture.png on the same path as the XML. The texture is being used (if I change it to some solid color, it behaves as expected), the UVs are just not being loaded…

Thanks in advance!
Diogo

Continuing my tests, I can’t seem to make any attributes working, so I’m probably missing something there…
Just tried to get some vertex colors working on my mesh, but no luck:

    Attribute*  attr = mesh->attributes.add(ATTR_STD_VERTEX_COLOR, ustring(""));
    uchar4*     fdata = attr->data_uchar4();
    for (int i = 0; i < vertex.size(); i++)
    {
        uchar r = (uchar)(255 * ((float)(rand() % 1000) / 1000.0f));
        uchar g = (uchar)(255 * ((float)(rand() % 1000) / 1000.0f));
        uchar b = (uchar)(255 * ((float)(rand() % 1000) / 1000.0f));
        *fdata = make_uchar4(r, g, b, 255);
        fdata++;
    }

For future reference, I managed to make this work by not using the UVMapNode node. Now I don’t supply anything to the “Vector” input of the image node it defaults to my UV channel with no issues…

Since I only have one UV channel, this works for me.