mata api c++ writeToFile not working for float

mata api c++ writeToFile not working for float

ryan.lewis8N66A
Observer Observer
613 Views
3 Replies
Message 1 of 4

mata api c++ writeToFile not working for float

ryan.lewis8N66A
Observer
Observer

trying to write out data to a texture ( exr would be awsome).

the code snippit should work form the examples in the api .

it does not and i get no errors.

if i change the type to char its fine. why wont it work for float.?

 

is there another /better way to do this?

better solution to write out exr textures?

 

MImage animationImage;

int fWidth = 800;
int fHeight = 800;
int fChannels = 4;

animationImage.create( fWidth, fHeight, fChannels, MImage::kFloat);
float *dest = animationImage.floatPixels();

for (int y=0; y < fHeight; y++)
  {
    for (int x=0; x < fWidth; x++)
    {
      *dest++ = 0.5;
      *dest++ = 0.5;
      *dest++ = 0.5;
      if (fChannels ==4)
      {
        *dest++ = 0.0;
      }
    }
}
animationImage.writeToFile ("D:/myTestiff.iff", "iff") ;

0 Likes
614 Views
3 Replies
Replies (3)
Message 2 of 4

cheng_xi_li
Autodesk Support
Autodesk Support

Hi Ryan,

 

MImage is a little bit outdated now, if you want to write exr float images, you can use MTextureManager.

 

Here is an updated version of your code:

 

const int fWidth = 800;
	const int fHeight = 800;
	const int fChannels = 4;
	float *floatPixels = new float[fWidth*fHeight*fChannels];

	float *dest = floatPixels;

	for (int y=0; y < fHeight; y++)
	{
		for (int x=0; x < fWidth; x++)
		{
			*dest++ = 0.5f;
			*dest++ = 0.5f;
			*dest++ = 0.5f;
			if (fChannels ==4)
			{
				*dest++ = 1.0f;
			}
		}
	}
	
	auto render = MHWRender::MRenderer::theRenderer();
	auto textureManager = render->getTextureManager();
	MHWRender::MTextureDescription texDesc;
	texDesc.setToDefault2DTexture();
	texDesc.fWidth = fWidth;
	texDesc.fHeight = fHeight;
	texDesc.fDepth = 1;
	texDesc.fTextureType = MHWRender::MTextureType::kImage2D;
	texDesc.fFormat = MHWRender::MRasterFormat::kR32G32B32A32_FLOAT;
	texDesc.fBytesPerRow = fWidth * fChannels * sizeof(float);
	texDesc.fBytesPerSlice = fWidth * fHeight * fChannels * sizeof(float);
	texDesc.fArraySlices = 1;
	texDesc.fEnvMapType = MHWRender::MEnvironmentMapType::kEnvNone;
	auto myTex = textureManager->acquireTexture("myexrfile",texDesc,floatPixels,false);
	textureManager->saveTexture(myTex,"D:/test.exr");
	textureManager->releaseTexture(myTex);
	delete floatPixels;
	floatPixels = NULL;
	dest = NULL;
	return MS::kSuccess;

Yours,

Li

0 Likes
Message 3 of 4

ryan.lewis8N66A
Observer
Observer

that's great. thanks!

did not even see that in the sdk.

 

i tried the code. the exr opens in maya but not photoshop ( or unreal4).

i tried a couple different  MrasterFormats,- kR16G16B16A16_SNORM no luck.

any thoughts about why that happens?

something else in the headers or compression?

 

i am using maya2014 and vs2012.

 

ryan

 

0 Likes
Message 4 of 4

ryan.lewis8N66A
Observer
Observer

looking at again..

 if i save out and exr or tga as kR32G32B32A32_FLOAT

then read them back in to maya (in fcheck) -still can not open in photoshop.

as an exr the rg channels are black. ie only have blue

as a tga the gb channels are black. ie only have red

 

so even as an image it seems the data is wrong.

 

what am i missing?

 

ryan

0 Likes