Jump to content

renderNodeTexture2D method in class Viewport can't render texture with transparent background, it always black background


photo

Recommended Posts

renderNodeTexture2D method in class Viewport can't render texture with transparent background, it always black background. I need a texture, not a image. here is my code, ask for help:

Unigine::ViewportPtr pViewport = Unigine::Viewport::create();

Unigine::TexturePtr pTexturePtr = Unigine::Texture::create();

pTexturePtr->create2D(iWidth, iHeight, Unigine::Texture::FORMAT_RGBA8, Unigine::Texture::USAGE_RENDER);

pViewport->renderNodeTexture2D(pOrthoCameraPtr, m_pRootNodePtr, pTexturePtr );

Link to comment

Dear @hongya,

You render viewport to texture, what is your next step? Are you using it or blend this texture with something else?

As I see the transparency will be retained. But if you use this texture to save as Image then it will be black. 

For a quick test. Save this as .png image and check it with other image editor.

I use the same technique to render the camera.

    RenderState::saveState();
	RenderState::clearStates();
	RenderState::flushStates();

	texturerender->bindColorTexture(0, texture);

	texturerender->enable();

	viewport->renderEngine(m_CameraOutputUnit.player->getCamera());

	texturerender->flush();

	texturerender->disable();

	texturerender->unbindColorTexture(0);

	RenderState::restoreState();

If I directly put this to texture the result is

image.thumb.png.211fa2330063ef35caf3310e23cf8300.png

From my product if I play Video and just overlay this texture on to it. then it is..

 

image.thumb.png.db39122180e33b77397d3f9e43c8e9f5.png

It works.

Rohit

  • Like 1
Link to comment

Dear @rohit.gonsalves,

Thanks for your reply, my demond is render a texture real time, and then use this texture to change a decal's albeo texture every frame. I've saved it in PNG format, and I've tried your code. It's background is black, and if 

pViewport->setNodeEnvironmentTextureName("core/textures/common/environment_white.dds");

the background is white. no transparent background.

Here is my final effect(black background):

1748113741_youdu20201223120147.thumb.png.61e6be9c38d989b889b8ee76a8d5b472.png

white background:

1279598431_youdu20201223120340.thumb.png.18105289e4d7db5475f87409e8854081.png

It's not transparent!

Link to comment

Dear @hongya,

The png image you have retrieved from the rendernodetoTexture2D.  If you take it in any image editor do you see Transparency?

I think the code is ok and if you use that texture real time with decals and Alpha blend, everything should work as you need.

Now the question is why the renderNodeTexture2D giving you that non transparent image?

Which Node you are rendering to have that image? Does the material used on that node has Alpha Blend State On?

Regards,

Rohit

Link to comment
×
×
  • Create New...