This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Unigine::Viewport Class

Header: #include <UnigineViewport.h>

The Viewport class is used to render a scene with the specified settings.

The main use cases of the Viewport class are as follows:

  1. Integrate the engine to a 3rd party renderer (or vice versa) and render the image anywhere (via the render() method): to the external library, CustomSystemProxy interface, RenderTarget interface (a frame buffers abstraction), etc.

    • To render the image to the RenderTarget interface, do the following:

      Source code (C++)
      // mono rendering
      
      ViewportPtr viewport;
      TexturePtr texture;
      CameraPtr camera;
      
      int AppWorldLogic::init()
      {
      
      	viewport = Viewport::create();
      
      	texture = Texture::create();
      	// create 512 x 512 render target
      	texture->create2D(512, 512, Texture::FORMAT_RGBA8, Texture::FORMAT_USAGE_RENDER);
      	camera = Camera::create();
      	
      
      	return 1;
      }
      
      int AppWorldLogic::update()
      {
      
      	// set modelview & projection matrices to camera instance
      	// ...
      
      	// rendering
      	RenderTargetPtr render_target = Render::getTemporaryRenderTarget();
      	render_target->bindColorTexture(0, texture);
      	render_target->enable();
      	{
      		viewport->render(camera);
      	}
      	render_target->disable();
      	render_target->unbindAll();
      	Render::releaseTemporaryRenderTarget(render_target);
      
      	return 1;
      }

      To render the image to the RenderTarget interface in the stereo mode, do the following:

      Source code (C++)
      // stereo rendering
      
      ViewportPtr viewport;
      TexturePtr left_texture;
      TexturePtr right_texture;
      CameraPtr left_eye;
      CameraPtr right_eye;
      
      int AppWorldLogic::init()
      {
      	viewport = Viewport::create();
      
      	left_texture = Texture::create();
      	right_texture = Texture::create();
      
      	// create two 512 x 512 render target for each eye
      	left_texture->create2D(512, 512, Texture::FORMAT_RGBA8, Texture::FORMAT_USAGE_RENDER);
      	right_texture->create2D(512, 512, Texture::FORMAT_RGBA8, Texture::FORMAT_USAGE_RENDER);
      
      	left_eye = Camera::create();
      	right_eye = Camera::create();
      
      	return 1;
      }
      int AppWorldLogic::update()
      {
      	// set modelview & projection matrices to camera instance
      	// ...
      
      	// rendering
      	RenderTargetPtr render_target = Render::getTemporaryRenderTarget();
      	render_target->bindColorTexture(0, left_texture);
      	render_target->bindColorTexture(1, right_texture);
      	render_target->enable();
      	{
      		// use "post_stereo_separate" material in order to render to both textures
      		viewport->renderStereo(left_eye, right_eye, "Unigine::post_stereo_separate");
      	}
      	render_target->disable();
      	render_target->unbindAll();
      	Render::releaseTemporaryRenderTarget(render_target);
      
      	return 1;
      }
    • To render the image to the CustomSystemProxy interface, check the 3rd Party samples: source -> samples -> 3rdparty -> ViewportQt.

      Notice
      ViewportQt sample is available only for the Engineering and Sim editions of UNIGINE SDKs.
  2. Render a scene to a texture (data stays in the GPU memory).

  3. Render a node to a texture (data stays in the GPU memory).

You can set callbacks before and after any rendering pass using the addCallback() method: thus, getting access to the intermediate state of rendering buffers and matrices. Some of them are read-only, but most of them can be modified ad hoc. The callback can get a Renderer pointer.

Thanks to this feature you can get direct access to G-Buffer, SSAO, lights or any other effect. One more example: you can create a custom post-process and apply it before TAA, thus, getting correct antialiased image as a result. You can even create your own custom light sources, decals, etc. The feature can also be useful for custom sensors view.

Viewport class has different rendering modes: RENDER_DEPTH (depth only), RENDER_DEPTH_GBUFFER (depth + G-buffer), RENDER_DEPTH_GBUFFER_FINAL (depth + G-buffer + final image). This can give you extra performance boost if you need only depth info, for example.

Notice

To set any viewport as a main, use the setViewport() method of the Render class.

A single viewport should be used with a single camera, otherwise it may cause visual artefacts. To avoid artefacts, when using several cameras with a single viewport, all post effects must be disabled using the setSkipFlags() method with the SKIP_POSTEFFECTS flag. See the usage example below.

See also#

Viewport Class

Members


static ViewportPtr create ( ) #

Creates a new viewport with default settings.

void setAspectCorrection ( bool correction ) #

Sets the aspect correction for current viewport. true enables correction, false disables it.

Arguments

  • bool correction - true to enable aspect correction, false to disable.

bool isAspectCorrection ( ) const#

Return the value indicating if the aspect correction enabled for the current viewport.

Return value

true if the aspect correction enabled, otherwise false.

void * addCallback ( int callback, Unigine::CallbackBase1< Unigine::Renderer * > * func ) #

Adds a callback for the specified stage of the rendering sequence. Callback functions can be used to get access to buffers and matrices at intermediate stages of the rendering sequence. Some of them are read-only, but most of them can be modified ad hoc.Callback function must be as follows:
Source code (C++)
void callback_name(Renderer *renderer){

	/* .. */
	
}

Arguments

  • int callback - Stage of the rendering sequence for which a callback is to be added. One of the Render::CALLBACK_* variables.
    Notice
    The _BEGIN prefix corresponds to the beginning of the rendering pass, _END - to its completion.
  • Unigine::CallbackBase1< Unigine::Renderer * > * func - Callback pointer.

Return value

ID of the last added callback of the specified type, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

void clearCallbacks ( int callback ) #

Clears all added callbacks for the specified stage of the rendering sequence. Callback functions can be used to get access to buffers and matrices at intermediate stages of the rendering sequence. Some of them are read-only, but most of them can be modified ad hoc.

Arguments

  • int callback - Stage of the rendering sequence for which the callbacks are to be cleared. One of the Render::CALLBACK_* variables.
    Notice
    The _BEGIN prefix corresponds to the beginning of the rendering pass, _END - to its completion.

bool removeCallback ( int callback, void * id ) #

Removes the specified callback from the list of callbacks for the specified stage of the rendering sequence. Callback functions can be used to get access to buffers and matrices at intermediate stages of the rendering sequence. Some of them are read-only, but most of them can be modified ad hoc.

Arguments

  • int callback - Stage of the rendering sequence for which the callback is to be removed. One of the Render::CALLBACK_* variables.
    Notice
    The _BEGIN prefix corresponds to the beginning of the rendering pass, _END - to its completion.
  • void * id - Callback ID obtained when adding it.

Return value

True if the callback with the given ID was removed successfully; otherwise false.

void setFirstFrame ( int frame ) #

Sets a value indicating if the first frame should be enabled over the current frame.

Arguments

  • int frame - 1 to set the first frame flag; otherwise, 0.

int getFirstFrame ( ) const#

Returns a value indicating if the first frame is enabled over the current frame.

Return value

1 if the first frame flag is set; otherwise, 0.

int getID ( ) const#

Returns the viewport ID.

Return value

Viewport ID.

void setMode ( Render::VIEWPORT_MODE mode ) #

Sets the rendering mode for the current viewport. It can be one of the stereo or panoramic modes or the default mode.

Arguments

Render::VIEWPORT_MODE getMode ( ) const#

Returns the rendering mode set for the current viewport. It can be one of the stereo or panoramic modes or the default mode.

Return value

The current rendering mode.

int getNodeLightUsage ( ) const#

Returns the type of lighting of the render node.

Return value

The lighting type. Can be one of the following:

bool isPanorama ( ) const#

Returns a value indicating if the panoramic rendering is enabled.

Return value

true if the panoramic rendering is enabled; otherwise, false.

void setPanoramaFisheyeFov ( float fov ) #

Sets a new Field of View angle to be used for the panorama rendering mode.

Arguments

  • float fov - New Field of View angle to be set for the panorama rendering mode, in degrees

float getPanoramaFisheyeFov ( ) const#

Returns the current Field of View angle used for the panorama rendering mode.

Return value

Current Field of View angle for the panorama rendering mode, in degrees

void setRenderMode ( int mode ) #

Sets the specified render mode. The mode determines the set of buffers to be rendered.

Arguments

int getRenderMode ( ) const#

Returns the current render mode. The mode determines the set of buffers to be rendered.

Return value

Current render mode. Can be one of the following:

void setSkipFlags ( int flags ) #

Sets the skip flag for the current viewport.

Arguments

int getSkipFlags ( ) const#

Returns the skip flag set for the current viewport.

Return value

A skip flag.

bool isStereo ( ) const#

Returns a value indicating if the stereo rendering is enabled for the current viewport (one of the stereo modes is set).

Return value

1 if the stereo rendering is enabled; otherwise, 0.

void setStereoDistance ( float distance ) #

Sets the focal distance for stereo rendering (distance in the world space to the point where two views line up, i.e. to the zero parallax plane).

Arguments

  • float distance - A focal distance in units.

float getStereoDistance ( ) const#

Returns the focal distance for stereo rendering (distance in the world space to the point where two views line up, i.e. to the zero parallax plane).

Return value

A focal distance in units.

void setStereoOffset ( float offset ) #

Updates the virtual camera offset (an offset after the perspective projection).

Arguments

  • float offset - A virtual camera offset in units.

float getStereoOffset ( ) const#

Returns the virtual camera offset (an offset after the perspective projection).

Return value

A virtual camera offset in units.

void setStereoRadius ( float radius ) #

Updates the radius for stereo - the half of the separation distance between the cameras (i.e. between eyes).

Arguments

  • float radius - A stereo radius in units. If a negative value is provided, 0 will be used instead.

float getStereoRadius ( ) const#

Returns the current radius for stereo - the half of the separation distance between the cameras (i.e. between eyes).

Return value

Stereo radius in units.

void appendSkipFlags ( int flags ) #

Appends specified skip flags to the list of currently used ones.

Arguments

int checkSkipFlags ( int flags ) #

Returns a value indicating if the specified skip flags are set for the current viewport.

Arguments

Return value

1 if the skip flags are set; otherwise, 0.

void removeSkipFlags ( int flags ) #

Removes specified skip flags from the list of currently used ones.

Arguments

void render ( const Ptr<Camera> & camera ) #

Renders an image from the specified camera. This method is used to integrate the engine to a 3rd party renderer.

To render an image from the camera to the RenderTarget interface, do the following:

Source code (C++)
camera = Camera::create();

render_target->enable();
{
	viewport->render(camera);
}
render_target->disable();

Arguments

  • const Ptr<Camera> & camera - Camera an image from which should be rendered.

void render ( const Ptr<Camera> & camera, int width, int height ) #

Renders an image of the specified size from the specified camera to the current rendering target.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • int width - Image width, in pixels.
  • int height - Image height, in pixels.

void renderEngine ( const Ptr<Camera> & camera ) #

Renders an Engine viewport for the specified camera to the current rendering target. This method renders a splash screen and provides an image in accordance with panoramic and stereo rendering settings.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.

void renderTexture2D ( const Ptr<Camera> & camera, const Ptr<Texture> & texture ) #

Renders an image from the camera to the specified 2D texture.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<Texture> & texture - Target 2D texture to save the result to.

void renderTexture2D ( const Ptr<Camera> & camera, const Ptr<Texture> & texture, int width, int height, bool hdr = 0 ) #

Renders an image of the specified size from the camera to a 2D texture.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<Texture> & texture - Target 2D texture to save the result to.
  • int width - Texture width, in pixels.
  • int height - Texture height, in pixels.
  • bool hdr - HDR flag.
    Notice
    This parameter determines the format of the 2D texture:
    • 1 - texture format will be set to RGBA16F
    • 0 - texture format will be set to RGBA8

void renderTextureCube ( const Ptr<Camera> & camera, const Ptr<Texture> & texture, bool local_space = false ) #

Renders the image from the camera to the cubemap texture.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<Texture> & texture - Target Cube texture to save the result to.
  • bool local_space - A flag indicating if the camera angle should be used for the cube map rendering.

void renderTextureCube ( const Ptr<Camera> & camera, const Ptr<Texture> & texture, int size, bool hdr = 0, bool local_space = 0 ) #

Renders the image from the camera to the cube map of the specified size.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<Texture> & texture - Target cube map to save the result to.
  • int size - Cube map edge size.
  • bool hdr - HDR flag.
    Notice
    This parameter determines the format of the 2D texture:
    • 1 - texture format will be set to RGBA16F
    • 0 - texture format will be set to RGBA8
  • bool local_space - A flag indicating if the camera angle should be used for the cube map rendering.

void renderNode ( const Ptr<Camera> & camera, const Ptr<Node> & node ) #

Renders the given node with all children to the current rendering target.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<Node> & node - Node to be rendered.

void renderNode ( const Ptr<Camera> & camera, const Ptr<Node> & node, int width, int height ) #

Renders the given node with all children to the current rendering target.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<Node> & node - Node to be rendered.
  • int width - Image width, in pixels.
  • int height - Image height, in pixels.

void renderNodeTexture2D ( const Ptr<Camera> & camera, const Ptr<Node> & node, const Ptr<Texture> & texture, int width, int height, bool hdr ) #

Renders the given node with all children to the 2D texture of the specified size.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<Node> & node - Pointer to the node to be rendered.
  • const Ptr<Texture> & texture - Target 2D texture to save the result to.
  • int width - Texture width, in pixels.
  • int height - Texture height, in pixels.
  • bool hdr - HDR flag.
    Notice
    This parameter determines the format of the 2D texture:
    • 1 - texture format will be set to RGBA16F
    • 0 - texture format will be set to RGBA8

void renderNodeTexture2D ( const Ptr<Camera> & camera, const Ptr<Node> & node, const Ptr<Texture> & texture ) #

Renders the given node with all children to the specified 2D texture.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<Node> & node - Pointer to the node to be rendered.
  • const Ptr<Texture> & texture - Target 2D texture to save the result to.

void renderNodes ( const Ptr<Camera> & camera, const Vector< Ptr<Node> > & nodes ) #

Renders given nodes with all their children to the current rendering target.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Vector< Ptr<Node> > & nodes - List of the nodes to be rendered.

void renderNodes ( const Ptr<Camera> & camera, const Vector< Ptr<Node> > & nodes, int width, int height ) #

Renders given nodes with all their children to the current rendering target of the specified size.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Vector< Ptr<Node> > & nodes - List of the nodes to be rendered.
  • int width - Image width, in pixels.
  • int height - Image height, in pixels.

void renderNodesTexture2D ( const Ptr<Camera> & camera, const Vector< Ptr<Node> > & nodes, const Ptr<Image> & texture, int width, int height, int hdr ) #

Renders given nodes with all their children to the 2D texture of the specified size.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Vector< Ptr<Node> > & nodes - List of the nodes to be rendered.
  • const Ptr<Image> & texture - Target 2D texture to save the result to.
  • int width - Texture width, in pixels.
  • int height - Texture height, in pixels.
  • int hdr - HDR flag.
    Notice
    This parameter determines the format of the 2D image:
    • 1 - texture format will be set to RGBA16F
    • 0 - texture format will be set to RGBA8

void renderNodesTexture2D ( const Ptr<Camera> & camera, const Vector< Ptr<Node> > & nodes, const Ptr<Texture> & texture ) #

Renders given nodes with all their children to the specified 2D texture.

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Vector< Ptr<Node> > & nodes - List of the nodes to be rendered.
  • const Ptr<Texture> & texture - Target 2D texture to save the result to.

void renderStereo ( const Ptr<Camera> & camera_left, const Ptr<Camera> & camera_right, const char * stereo_material ) #

Renders a stereo image in the current viewport.

Arguments

  • const Ptr<Camera> & camera_left - Camera that renders an image for the left eye.
  • const Ptr<Camera> & camera_right - Camera that renders an image for the right eye.
  • const char * stereo_material - List of names of stereo materials to be used.

void renderStereoPeripheral ( const Ptr<Camera> & camera_left, const Ptr<Camera> & camera_right, const Ptr<Camera> & camera_focus_left, const Ptr<Camera> & camera_focus_right, const Ptr<Texture> & texture_left, const Ptr<Texture> & texture_right, const Ptr<Texture> & texture_focus_left, const Ptr<Texture> & texture_focus_right, const char * stereo_material ) #

Renders a stereo image for HMDs having context (peripheral) and focus displays. This method saves performance on shadows and reflections along with other optimizations reducing rendering load, such as reduced resolutions for textures.

Arguments

  • const Ptr<Camera> & camera_left - Camera that renders an image for the left context (low-res) display.
  • const Ptr<Camera> & camera_right - Camera that renders an image for the right context (low-res) display.
  • const Ptr<Camera> & camera_focus_left - Camera that renders an image for the left focus (high-res) display.
  • const Ptr<Camera> & camera_focus_right - Camera that renders an image for the right focus (high-res) display.
  • const Ptr<Texture> & texture_left - Texture to save the image rendered for the left context (low-res) display.
  • const Ptr<Texture> & texture_right - Texture to save the image rendered for the right context (low-res) display.
  • const Ptr<Texture> & texture_focus_left - Texture to save the image rendered for the left focus (high-res) display.
  • const Ptr<Texture> & texture_focus_right - Texture to save the image rendered for the right focus (high-res) display.
  • const char * stereo_material - List of names of stereo materials to be used.

void setStereoHiddenAreaMesh ( const Ptr<Mesh> & hidden_area_mesh_left, const Ptr<Mesh> & hidden_area_mesh_right ) #

Sets custom meshes to be used for culling pixels, that are not visible in VR.
Notice

Arguments

  • const Ptr<Mesh> & hidden_area_mesh_left - Mesh representing hidden area for the left eye.
  • const Ptr<Mesh> & hidden_area_mesh_right - Mesh representing hidden area for the right eye.

void clearStereoHiddenAreaMesh ( ) #

Clears meshes that represent hidden areas for both, left and right eye. Hidden areas are used for culling pixels, that are not visible in VR

void setEnvironmentTexturePath ( const char * name ) #

Sets the path to the cubemap defining the environment color for the viewport. This texture is used for imitating landscape reflections and lighting in accordance with the ground mask.

Arguments

  • const char * name - Path to the cubemap defining the environment color.

const char * getEnvironmentTexturePath ( ) #

Returns the path to the cubemap defining the environment color set for the viewport. This texture is used for imitating landscape reflections and lighting in accordance with the ground mask.

Return value

Path to the cubemap defining the environment color.

void setEnvironmentTexture ( const Ptr<Texture> & texture ) #

Sets the specified environment texture.

Arguments

  • const Ptr<Texture> & texture - Cubemap defining the environment color.

Ptr<Texture> getEnvironmentTexture ( ) const#

Returns the current environment texture.

Return value

Cubemap defining the environment color.

void resetEnvironmentTexture ( ) #

Resets the current environment texture to the default one.

void setPaused ( bool paused ) #

Sets the viewport rendering to the paused mode.

Arguments

  • bool paused - A flag indicating if the current viewport should be paused or not.

bool isPaused ( ) const#

Returns a value indicating if the rendering in the current viewport is paused or not.

Return value

1 if the viewport is paused; otherwise, 0.

void setNodeLightUsage ( int usage ) #

Sets the type of lighting for the render of a node (used for impostor grabbing, node preview rendering, etc.).

Arguments

  • int usage - The lighting type. Can be one of the following:
    • 0 - USAGE_WORLD_LIGHT (use lighting from the LightWorld set in the current loaded world).
    • 1 - USAGE_AUX_LIGHT (use lighting from the auxiliary virtual scene containing one LightWorld with 45 degrees slope angles along all axes, scattering is not used).
    • 2 - USAGE_NODE_LIGHT (use the node lighting).

void setUseTAAOffset ( bool offset ) #

Sets a value indicating if skipping render mode check is enabled for using TAA. Can be used to ensure proper TAA calculation when rendering mode for the Viewport is set to RENDER_DEPTH.

Arguments

  • bool offset - true to enable skipping render mode check and use TAA; otherwise false.

bool isUseTAAOffset ( ) const#

Returns a value indicating if skipping render mode check is enabled for using TAA. Can be used to ensure proper TAA calculation when rendering mode for the Viewport is set to RENDER_DEPTH.

Return value

true if skipping render mode check is enabled for using TAA; otherwise false.
Last update: 2023-06-23
Build: ()