Jump to content

renderNodeImage has background


photo

Recommended Posts

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

 

node.png

Link to comment

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

11.png

12.png

Link to comment

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!

node.jpg

Link to comment

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

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
×
×
  • Create New...