How to get raw data of texture being loaded from file texture node

How to get raw data of texture being loaded from file texture node

vanessa.schueller
Observer Observer
295 Views
0 Replies
Message 1 of 1

How to get raw data of texture being loaded from file texture node

vanessa.schueller
Observer
Observer

Hi,

 

I am currently working on a rendering plugin for maya. I am facing some issues, while adding our custom material to Hypershade. We don't have a node material system, so our way to workaround that is to bake node graphs into a texture and load them in our different channels. This is working great for the most scenarios.

The code we use, is the following:

 

if (const auto texture = texture_manager->acquireTexture("", connected_plug, baking_resolution,
baking_resolution, false))
{
MHWRender::MTextureDescription desc = {};
texture->textureDescription(desc);

size_t slice_pitch = 0;
int row_pitch = 0;

if (const auto pixel_data = texture->rawData(row_pitch, slice_pitch))
{
/*

* copy pixel_data to our custom image format

*/
texture->freeRawData(pixel_data);
}

texture_manager->releaseTexture(texture);
}

 

vanessaschueller_0-1658839657392.png

 

The problem now comes when trying to "bake" a file texture node to a texture, a scenario as scene in the above image (I am using our material, instead of the standard surface of course). Of course I could directly load the image from disk, but then I lose the uv information that is in the place2Dtexture node. So right now, my preferred way would be to load the file and bake it into a new texture. 

The acquisition of the texture is possible the same way as seen in the above code. The texture description also contains the right information (e.g. width and height being the actual size of the texture file). Where it fails is line 10. For some reason I cannot get a pointer to the raw data of the MTexture being created. I also tried other "acquireTexture" functions already. But I am never able to get a pointer to the texture data for copying the mtexture to our image format. 

 

I would appreciate any tips about what I am missing here. 

 

Thanks a lot!

 

V

 

296 Views
0 Replies
Replies (0)