zhengwenxin Posted August 2, 2017 Share Posted August 2, 2017 Hi, I render a node by the function renderNodeImage2D , but the generated image has the background. The result image is in the attachment. Is there any ways to only render the node image without the background. Kind regards Link to comment
silent Posted August 2, 2017 Share Posted August 2, 2017 Hi Zheng, You can remove default cubemap for veiwport by calling setNodeEnvironmentTextureName() method and passing to it texture from this forum post: How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
zhengwenxin Posted August 4, 2017 Author Share Posted August 4, 2017 Hi, I use the method that you recommend, but the result is not I want. I want a three dimension cube image , but the result give me a two dimension image. How to get the three dimension image? Kind regards Link to comment
fox Posted August 7, 2017 Share Posted August 7, 2017 Hi Zheng, You can try the code below to generate an image of the node without the background (see the picture below) Insert the following code to the AppWorldLogic.h file of Your project: /*...*/ #include <UnigineViewport.h> #include <UnigineApp.h> #include <UnigineGame.h> #include <UnigineEditor.h> class AppWorldLogic : public Unigine::WorldLogic { public: /*...*/ // pointers to viewport, image, camera and node Unigine::ViewportPtr viewport; Unigine::ImagePtr image; Unigine::CameraPtr camera; Unigine::NodePtr node; }; Insert the following code to the AppWorldLogic.cpp file of Your project: /* ... */ int AppWorldLogic::init() { // getting the pointer to the node we want to render node = Editor::get()->getNodeByName("material_ball"); // creating a viewport and an image to render the node to, and setting necessary parameters viewport = Viewport::create(); image = Image::create(); image->create2D(App::get()->getWidth(), App::get()->getHeight(), Image::FORMAT_RGB8); viewport->appendSkipFlags(Viewport::SKIP_POSTEFFECTS); // setting environment texture (you can use your own texture if necessary) viewport->setNodeEnvironmentTextureName("core/textures/common/environment_white.dds"); // getting current player's camera camera = Game::get()->getPlayer()->getCamera(); viewport->renderNode(camera, node); return 1; } int AppWorldLogic::update() { // checking if "backspace" key was pressed if (App::get()->clearKeyState(App::KEY_BACKSPACE)){ // render the node to the image using the camera viewport->renderNodeImage2D(camera, node, image, image->getWidth(), image->getHeight(), 0); // saving the image to a file in the application data folder image->save("node_image.png"); } return 1; } /* ... */ Hope this helps! Thanks! Link to comment
Scott.McNab Posted August 11, 2017 Share Posted August 11, 2017 I'm trying to do the same thing, except I would like a black transparent background (i.e. RGBA = 0,0,0,0). I followed the strategy described here Using a similar black transparent environment texture results in an alpha background which is close, but the RGB components of the default environment cube are still present in the rendered image. i.e. the transparent RGBA pixels in the background contain [R,G,B,0] values, but what I need is background pixels to be [0,0,0,0]. Is it possible to disable rendering the environment cube entirely? I'm using UnigineScript to create a WidgetSpriteNode: sprite = new WidgetSpriteNode(engine.getGui(),x,y); sprite.setBlendFunc(GUI_BLEND_SRC_ALPHA,GUI_BLEND_ONE_MINUS_SRC_ALPHA); sprite.setEnvironmentTextureName("blank.dds"); sprite.setSkipFlags(VIEWPORT_SKIP_SHADOWS | VIEWPORT_SKIP_VISUALIZER | VIEWPORT_SKIP_POSTEFFECTS | VIEWPORT_SKIP_DYNAMIC_REFLECTIONS | VIEWPORT_SKIP_VELOCITY_BUFFER | VIEWPORT_SKIP_SRGB | VIEWPORT_SKIP_FORMAT_RG11B10); sprite.renderImage(img); How do I set a black transparent background on the image and render the objects without any environment cube? Thanks Link to comment
silent Posted August 11, 2017 Share Posted August 11, 2017 Hi Scott, You can try to disable environment via render_environment 0 and setup background color in Rendering Settings inside editor. That in theory should do the trick. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Scott.McNab Posted August 15, 2017 Share Posted August 15, 2017 Hi @silent Is it possible to disable render_environment and setup background colour programmatically just for a single Viewport? I need to leave environment enabled for the main view, so can't disable it globally. Thanks Link to comment
silent Posted August 15, 2017 Share Posted August 15, 2017 Hi Scott, There is no per-viewport environment setting available, I'm afraid. You have to set own cubemap manually via setNodeEnvironmentTextureName() and use together with renderNodeImage2D(). Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts