Jump to content

Bug? No Alpha in HDR render & can't read pixels


photo

Recommended Posts

I am trying to render into a HDR image in UnigineScript, then read the pixels out of the image. I'm using this method to set the hdr flag:

viewport.renderNodeImage2D(camera, node, img, width, height, 1);

When I then call img.get2D(float x, float y); I get the following error in the log:

Image::get(): can't get pixel from RGB16F image

Looking at the engine code, there is no case in Image.cpp where the get() method called by Image::get2D(float x,float y) handles the RGB16F image format (hence the error).

I tried working around this missing case statement first converting the image to another format that is supported before reading the pixels:

img.convertToFormat(IMAGE_FORMAT_RGBA32F);

This works, however the generated image does not have any Alpha channel!

Looking at the engine code for Viewport::renderNodeImage2D(Camera *camera,Node *node,Image &image,int width,int height,int hdr), I see this logic:

int flags = Texture::FORMAT_RGBA8;
if(hdr) flags = Texture::FORMAT_RGB16F;
Texture *texture = engine.render->getTexture(width,height,flags);

Is this a bug? Why if we enable hdr render, do we use FORMAT_RGB16F instead of FORMAT_RGBA16F? This would seem to explain the missing Alpha channel.

How can I work around this? Thanks

 

Link to comment

Hi,
"Is this a bug?" Yes.

You need to use Texture :: FORMAT_RGBA16F

if(hdr) flags = Texture::FORMAT_RGB16F;
replaced by
if(hdr) flags = Texture::FORMAT_RGBA16F;

Or use renderNodeTexture2D (only C++)
https://developer.unigine.com/en/docs/2.5/api/library/rendering/class.viewport?rlang=cpp&words=rendernodetexture2d#renderNodeTexture2D_Camera_Node_Texture_void

// create_resources
texture = Texture::create();
texture->create2D(width, height, Texture::FORMAT_RGBA16F, Texture::WRAP_CLAMP | Texture::FILTER_LINEAR | Texture::USAGE_RENDER);

// render
viewport->renderNodeTexture2D(camera, node, texture);

// copy image
image.clear();
texture->getImage(image);
if (!engine.render->isFlipped())
    image.flipY();

Link to comment
×
×
  • Create New...