I don't want to use the depth map externally. I'd like to save it so that I can have a look at it later on (for some kind of debugging).
Ok, if I create the depth texture as ECF_G32R32F, I'll have to decode depth in the shader via
Code: Select all
vec4 texDepth = texture2D(DepthMapSampler, coords);
float depth = (texDepth.r + (texDepth.g / 255.0));
right?
BTW: does anyone know, where the ENCODING of the depth happens in the XEffects project? Or does Irrlicht do this internally when an object is rendered to a depth render target of format ECF_G32R32F?
However, I still don't know, how I can save this texture to a file on HD...?
In combination with a depth texture of format ECF_R32F, I already tried the following code, which stores only a completely black image:
Code: Select all
u32 col = 0;
unsigned int texWidth = texture->getSize().Width;
unsigned int texHeight = texture->getSize().Height;
IImage* im = driver->createImage(ECF_R8G8B8, texture->getSize());
float* imageData = (float*)texture->lock(true);
if (imageData)
{
for (unsigned int y=0; y < texHeight; y++)
{
for (unsigned int x=0; x < texWidth; x++)
{
col = clamp<u32>(255.0 * imageData[y * texWidth + x], 0, 255);
im->setPixel(x, y, SColor(255, col, col, col));
}
}
driver->writeImageToFile(im, filename);
texture->unlock();
im->drop();
}
else
std::cout << "ERROR: could not lock texture data" << std::endl;