hongya Posted December 22, 2020 Share Posted December 22, 2020 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
hongya Posted December 23, 2020 Author Share Posted December 23, 2020 or is there a way render a node into texture with transparent background? waiting online Link to comment
rohit.gonsalves Posted December 23, 2020 Share Posted December 23, 2020 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 From my product if I play Video and just overlay this texture on to it. then it is.. It works. Rohit 1 Link to comment
hongya Posted December 23, 2020 Author Share Posted December 23, 2020 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): white background: It's not transparent! Link to comment
rohit.gonsalves Posted December 23, 2020 Share Posted December 23, 2020 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
Recommended Posts