Hello! I need to take a screenshot and also save the depthmap for that capture in a separate file, what would be the easiest way to do that in 2.2? I can imagine some ways to do it alla 2.1, but I am guessing en 2.2 there is a more straightforward way to do it?
thanks in advance!!
[2.2] Save depth texture to file
-
- OGRE Expert User
- Posts: 1148
- Joined: Sat Jul 06, 2013 10:59 pm
- Location: Chile
- x 168
-
- OGRE Expert User
- Posts: 1148
- Joined: Sat Jul 06, 2013 10:59 pm
- Location: Chile
- x 168
Re: [2.2] Save depth texture to file
I see that its recommended to copy the depth buffer in to another texture, even in 2.2 (due to hw limitations/performance) that's the "2.1 way" I knew, so I implemented it and it works!
buuuuuuuuuuut!!! it onIy works when I use 8 bit pixel format... and I really need to store the image as 16 or 32 bit... I tried lots of combinations of pixel formats and save extensions and always get a 0 bit size file
which pixel format should I use and in what extensions should I save? os its not supported? should I use the library mantioned here (DirectXTex) viewtopic.php?f=25&t=94913? sounds like it wont work with opengl
buuuuuuuuuuut!!! it onIy works when I use 8 bit pixel format... and I really need to store the image as 16 or 32 bit... I tried lots of combinations of pixel formats and save extensions and always get a 0 bit size file
which pixel format should I use and in what extensions should I save? os its not supported? should I use the library mantioned here (DirectXTex) viewtopic.php?f=25&t=94913? sounds like it wont work with opengl
- dark_sylinc
- OGRE Team Member
- Posts: 5296
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1278
- Contact:
Re: [2.2] Save depth texture to file
I can't try anything right now, I'm away.
Copying TextureGpu -> StagingTexture should work, but there may be minor GL caveats (I haven't tried).
Since all our download code uses (requires) StagingTexture, then copying to another texture shouldn't be needed. If copying to another texture works for you and workarounds those untested caveats, then great.
As for the pixel format thingy, that's a codec thing. I know OITD codec (our internal format) will work, but that is not readable by any useable tool.
FreeImageCodec2 only supports up to 16 bits per channel
DDSCodec2::encode hasn't been ported yet but should support it.
EXR codec hasn't been ported but perhaps it's easy to port to 2.2? I don't know if it ever supported encoding
KTX (ETCCodec) also supports float32 but we haven't written the encode() functionality
Copying TextureGpu -> StagingTexture should work, but there may be minor GL caveats (I haven't tried).
Since all our download code uses (requires) StagingTexture, then copying to another texture shouldn't be needed. If copying to another texture works for you and workarounds those untested caveats, then great.
As for the pixel format thingy, that's a codec thing. I know OITD codec (our internal format) will work, but that is not readable by any useable tool.
FreeImageCodec2 only supports up to 16 bits per channel
DDSCodec2::encode hasn't been ported yet but should support it.
EXR codec hasn't been ported but perhaps it's easy to port to 2.2? I don't know if it ever supported encoding
KTX (ETCCodec) also supports float32 but we haven't written the encode() functionality
-
- OGRE Expert User
- Posts: 1148
- Joined: Sat Jul 06, 2013 10:59 pm
- Location: Chile
- x 168
Re: [2.2] Save depth texture to file
yes, for time sake I am going to leave it like this, I just need it for taking captures so I don't care it there's a better waydark_sylinc wrote: ↑Sun May 19, 2019 1:19 am If copying to another texture works for you and workarounds those untested caveats, then great.
that's enough for my needs!! do you mean this is implemented/integrated in to ogre? how do I use it?dark_sylinc wrote: ↑Sun May 19, 2019 1:19 am FreeImageCodec2 only supports up to 16 bits per channel
-
- OGRE Expert User
- Posts: 1148
- Joined: Sat Jul 06, 2013 10:59 pm
- Location: Chile
- x 168
Re: [2.2] Save depth texture to file
ok, turns out it wasnt that difficult to integrate DirectXtex library and its working!
this is how I save a PFG_R16_FLOAT texture:
still would be nicer to have ogre do it so I don' t have to include another dependency, but not a real problem
thanks!!
this is how I save a PFG_R16_FLOAT texture:
Code: Select all
Ogre::Image2 image;
image.convertFromTexture( mScreenShotTextureDepth, 0, 0 );
DirectX::Image dxImage;
dxImage.width = mScreenShotTextureDepth->getWidth();
dxImage.height = mScreenShotTextureDepth->getHeight();
dxImage.format = DXGI_FORMAT_R16_FLOAT;
dxImage.pixels = static_cast<uint8_t*>( image.getData( 0 ).atFromOffsettedOrigin( 0, 0, 0 ) );
size_t rowPitch;
size_t slicePitch;
DirectX::ComputePitch( dxImage.format, dxImage.width, dxImage.height,
rowPitch, slicePitch, DirectX::CP_FLAGS_NONE );
dxImage.rowPitch = rowPitch;
dxImage.slicePitch = slicePitch;
std::string fileName = "./Captures/" + yUtils::getDateInStandardString() + "_Depth.png";
wchar_t* wide_string = new wchar_t[ fileName.length() + 1 ];
std::copy( fileName.begin(), fileName.end(), wide_string );
wide_string[ fileName.length() ] = 0;
DirectX::SaveToWICFile( dxImage, DirectX::WIC_FLAGS_NONE, DirectX::GetWICCodec(DirectX::WIC_CODEC_PNG), wide_string );
delete [] wide_string;
thanks!!