This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
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

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

There are two main use cases of the Viewport class:

  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
      
      Viewport viewport;
      Texture texture;
      Camera camera;
      
      private void Init()
      {
      	viewport = new Viewport();
      
      	texture = new Texture();
      	// create 512 x 512 render target
      	texture.Create2D(512, 512, Texture.FORMAT_RGBA8, Texture.FORMAT_USAGE_RENDER);
      	camera = new Camera();
      }
      
      private void Update()
      {
      // set modelview & projection matrices to camera instance
      	// ...
      
      	// rendering
      	RenderTarget 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);
      }

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

      Source code (C#)
      // stereo rendering
      
      Viewport viewport;
      Texture left_texture;
      Texture right_texture;
      Camera left_eye;
      Camera right_eye;
      
      private void Init()
      {
      	viewport = new Viewport();
      
      	left_texture = new Texture();
      	right_texture = new Texture();
      
      	// 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 = new Camera();
      	right_eye = new Camera();
      }
      
      private void Update()
      {
      	// set modelview & projection matrices to camera instance
      	// ...
      
      	// rendering
      	RenderTarget 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);
      }
    • To render the image to the CustomSystemProxy interface, check the following 3rd party samples (e.g. Samples -> 3rd Party -> QT -> ViewportQt)
      Notice
      ViewportQt sample is available only for the Engineering and Sim editions of UNIGINE SDKs.
  2. Render a scene to the image (data will be transferred from GPU memory to CPU memory) or texture (data stays in the GPU memory).
  3. Render a node to the image (data will be transferred from GPU memory to CPU memory) or texture (data stays in the GPU memory).

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 also#

Viewport Class

Properties

int NodeLightUsage#

The type of lighting of the render node.

float StereoOffset#

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

float StereoRadius#

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

float StereoDistance#

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).

bool IsStereo#

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

bool IsPanorama#

The A value indicating if the panoramic rendering is enabled.

int RenderMode#

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

Render.VIEWPORT_MODE Mode#

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

int SkipFlags#

The skip flag set for the current viewport.

int FirstFrame#

The Value indicating if the first frame is enabled over the current frame.

bool AspectCorrection#

The Value indicating if the aspect correction enabled for current viewport.

int ID#

The viewport id.

float PanoramaFisheyeFov#

The current field of view angle used for the panorama rendering mode.

Texture EnvironmentTexture#

The Cubemap defining the environment color.

bool Paused#

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

bool UseTAAOffset#

The 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.

Members


Viewport ( ) #

Creates a new viewport with default settings.

IntPtr addCallback ( int callback, CallbackDelegate 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.
  • CallbackDelegate func - Callback function with the following signature: void CallbackDelegate(Renderer renderer)

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, IntPtr 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.
  • IntPtr id - Callback ID obtained when adding it.

Return value

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

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 ( Camera camera ) #

Renders an image from the specified camera.

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

Source code (C#)
camera = new Camera();

render_target.Enable();
{
	viewport.Render(camera);
}
render_target.Disable();

Arguments

  • Camera camera - Camera an image from which should be rendered.

void Render ( Camera camera, int width, int height ) #

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

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • int width - Image width, in pixels.
  • int height - Image height, in pixels.

void RenderEngine ( 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

  • Camera camera - Camera, an image from which should be rendered.

void RenderImage2D ( Camera camera, Image image ) #

Renders an image from the camera to the given 2D image.
Notice
This method sets the format of the 2D image to one of the following values:
  • RGBA16F - in case if initial image format was 16-bit or 32-bit per channel float
  • RGBA8 - otherwise

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Image image - Target 2D image to save the result to.

void RenderImage2D ( Camera camera, Image image, int width, int height, bool hdr = 0 ) #

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

Arguments

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

void RenderImageCube ( Camera camera, Image image, int size, bool hdr = 0, bool local_space = 0 ) #

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

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Image image - 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 image:
    • 1 - image format will be set to RGBA16F
    • 0 - image 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 RenderImageCube ( Camera camera, Image image ) #

Renders the image from the camera into the cube map.

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Image image - Target cube map to save the result to.

void RenderNode ( Camera camera, Node node ) #

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

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Node node - Node to be rendered.

void RenderNode ( Camera camera, Node node, int width, int height ) #

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

Arguments

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

void RenderNodeImage2D ( Camera camera, Node node, Image image, int width, int height, bool hdr ) #

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

Arguments

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

void RenderNodeImage2D ( Camera camera, Node node, Image image ) #

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

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Node node - Node to be rendered.
  • Image image - Target 2D image to save the result to.

void RenderNodeTexture2D ( Camera camera, Node node, Texture texture ) #

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

Arguments

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

void RenderNodes ( Camera camera, Node[] nodes ) #

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

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Node[] nodes - List of the nodes to be rendered.

void RenderNodes ( Camera camera, Node[] nodes, int width, int height ) #

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

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Node[] nodes - List of the nodes to be rendered.
  • int width - Image width, in pixels.
  • int height - Image height, in pixels.

void RenderNodesImage2D ( Camera camera, Node[] nodes, Image image ) #

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

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Node[] nodes - List of the nodes to be rendered.
  • Image image - Target 2D image to save the result to.

void RenderNodesImage2D ( Camera camera, Node[] nodes, Image image, int width, int height, int hdr ) #

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

Arguments

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

void RenderNodesTexture2D ( Camera camera, Node[] nodes, Texture texture ) #

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

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • Node[] nodes - List of the nodes to be rendered.
  • Texture texture - Target 2D texture to save the result to.

void RenderStereo ( Camera camera_left, Camera camera_right, string stereo_material ) #

Renders a stereo image in the current viewport.

Arguments

  • Camera camera_left - Camera that renders an image for the left eye.
  • Camera camera_right - Camera that renders an image for the right eye.
  • string stereo_material - List of names of stereo materials to be used.

void RenderStereoPeripheral ( Camera camera_left, Camera camera_right, Camera camera_focus_left, Camera camera_focus_right, Texture texture_left, Texture texture_right, Texture texture_focus_left, Texture texture_focus_right, string 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

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

void RenderTexture2D ( Camera camera, Texture texture ) #

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

Arguments

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

void RenderTextureCube ( Camera camera, Texture texture, bool local_space = false ) #

Renders the image from the camera to the cubemap texture.

Arguments

  • Camera camera - Camera, an image from which should be rendered.
  • 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 SetStereoHiddenAreaMesh ( Mesh hidden_area_mesh_left, Mesh hidden_area_mesh_right ) #

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

Arguments

  • Mesh hidden_area_mesh_left - Mesh representing hidden area for the left eye.
  • 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 ( string 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

  • string name - Path to the cubemap defining the environment color.

string 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 ResetEnvironmentTexture ( ) #

Resets the current environment texture to the default one.

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 ( ) #

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-04-13
Build: ()