This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
编程
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
应用程序接口
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Unigine::Viewport Class

Header:#include <UnigineViewport.h>

A 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, App interface, TextureRender interface (a frame buffers abstraction), etc.

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

      Source code (C++)
      // mono rendering
      // initialization
      ViewportPtr viewport = Viewport::create();
      
      TextureRenderPtr texturerender = TextureRender::create();
      TexturePtr texture = Texture::create();
      texture->create2D(512,512,Texture::FORMAT_RGBA8,Texture::USAGE_RENDER); // create 512 x 512 render target
      
      CameraPtr camera = Camera::create();
      // set modelview & projection matrices to camera instance
      
      // rendering
      texturerender->enable();
      	texturerender->setColorTexture(0,texture);
      	viewport->render(camera);
      texturerender->disable();

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

      Source code (C++)
      // stereo rendering
      // initialization
      ViewportPtr viewport = Viewport::create();
      
      TextureRenderPtr texturerender = TextureRender::create();
      TexturePtr left_texture = Texture::create();
      TexturePtr right_texture = Texture::create();
      
      // create two 512 x 512 render target for each eye
      left_texture->create2D(512,512,Texture::FORMAT_RGBA8,Texture::USAGE_RENDER);
      right_texture->create2D(512,512,Texture::FORMAT_RGBA8,Texture::USAGE_RENDER);
      
      CameraPtr left_eye = Camera::create();
      CameraPtr right_eye = Camera::create();
      // set modelview & projection matrices for each eyes
      
      // rendering
      texturerender->enable();
      	texturerender->setColorTexture(0,left_texture);
      	texturerender->setColorTexture(0,right_texture);
      	viewport->renderStereo(left_eye,right_eye,"post_stereo_separate"); // use "post_stereo_separate" material in order to render to both textures
      texturerender->disable();
    • To render the image to the App interface, check the following 3rdparty samples (e.g. source -> samples -> 3rdparty -> ViewportQt)
      Notice
      Qml and ViewportQt samples are available only for the Engineering and Sim editions of UNIGINE SDKs.
  2. Render a scene to the image (data will be transfered from GPU memory to CPU memory) or texture (data stays in the GPU memory).
  3. Render a node to the image (data will be transfered from GPU memory to CPU memory) or 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(int correction)

Sets the aspect correction for current viewport. 1 enables correction, 0 disables.

Arguments

  • int correction - 1 to enable aspect correction, 0 to disable.

int getAspectCorrection()

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

Return value

1 if the aspect correction enabled, otherwise 0.

Unigine::CallbackBase * addCallback(int callback, Unigine::CallbackBase * 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::CallbackBase * func - Callback pointer.

Return value

Pointer to the last added callback of the specified type, if the callback was added successsfully; otherwise, nullptr.

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.

void removeCallback(int callback, Unigine::CallbackBase * func)

Removes a callback with a given number 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.
  • Unigine::CallbackBase * func - Callback pointer.

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

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

Returns the viewport ID.

Return value

Viewport ID.

void setMode(int mode)

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

Arguments

  • int mode - A rendering mode.

int getMode()

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.

void setNodeEnvironmentTextureName(const char * name)

Sets a name for the environment texture.

Arguments

  • const char * name - A texture name.

void setNodeLightUsage(int usage)

Sets the type of lighting for the render node.

Arguments

int getNodeLightUsage()

Returns the type of lighting of the render node.

Return value

The lighting type. Can be one of the following:

int isPanorama180()

Returns a value indicating if a 180-degree panoramic rendering is enabled.

Return value

1 if a 180-degree panoramic rendering is enabled; otherwise, 0.

int isPanorama360()

Returns a value indicating if a 360-degree panoramic rendering is enabled.

Return value

1 if a 360-degree panoramic rendering is enabled; otherwise, 0.

void setRenderMode(int mode)

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

Arguments

int getRenderMode()

Returns the current render mode. The mode determines the set 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()

Returns the skip flag set for the current viewport.

Return value

A skip flag.

int isStereo()

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

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

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

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 TextureRender interface, do the following:

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

texturerender->enable();
	viewport->render(camera);
texturerender->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 renderImage2D(const Ptr<Camera> & camera, const Ptr<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

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

void renderImage2D(const Ptr<Camera> & camera, const Ptr<Image> & image, int width, int height, int hdr = 0)

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

Arguments

  • const Ptr<Camera> & camera - Camera, an image from which should be rendered.
  • const Ptr<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 renderImageCube(const Ptr<Camera> & camera, const Ptr<Image> & image, int size, int hdr = 0, int 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<Image> & image - Target cube map to save the result to.
  • int size - Cube map edge size.
  • 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
  • int local_space - A flag indicating if the camera angle should be used for the cube map rendering.

void renderImageCube(const Ptr<Camera> & camera, const Ptr<Image> & image)

Renders the image from the camera into the cube map.

Arguments

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

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 renderNodeImage2D(const Ptr<Camera> & camera, const Ptr<Node> & node, const Ptr<Image> & image, int width, int height, int hdr)

Renders the given node with all children to the 2D image 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<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 renderNodeImage2D(const Ptr<Camera> & camera, const Ptr<Node> & node, const Ptr<Image> & image)

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

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<Image> & image - Target 2D image to save the result to.

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 renderNodesImage2D(const Ptr<Camera> & camera, const Vector< Ptr<Node> > & nodes, const Ptr<Image> & image)

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

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> & image - Target 2D image to save the result to.

void renderNodesImage2D(const Ptr<Camera> & camera, const Vector< Ptr<Node> > & nodes, const Ptr<Image> & image, int width, int height, int hdr)

Renders given nodes with all their children to the 2D image 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> & 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(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 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.

int MODE_DEFAULT

Description

Enables the default stereo mode - no stereo and panoramic rendering in the current viewport is available. This mode is set by default for a new viewport.

int MODE_PANORAMA_180_CURVED

Description

Enables rendering of the viewport as a 180-degree panorama with curved edges.

int MODE_PANORAMA_180_FISHEYE

Description

Enables rendering of the viewport as a 180-degree spherical panorama (fisheye).

int MODE_PANORAMA_180_LINEAR

Description

Enables rendering of the viewport as a 180-degree linear panorama without distortion at the edges.

int MODE_PANORAMA_360_CURVED

Description

Enables rendering of the viewport as a 360-degree panorama with curved edges.

int MODE_PANORAMA_360_FISHEYE

Description

Enables rendering of the viewport as a 360-degree spherical panorama (fisheye).

int MODE_PANORAMA_360_LINEAR

Description

Enables rendering of the viewport as a 360-degree linear panorama without distortion at the edges.

int MODE_STEREO_ANAGLYPH

Description

Enables the anaglyph stereo mode that is viewed with red-cyan anaglyph glasses.

int MODE_STEREO_HORIZONTAL

Description

Enables the horizontal stereo mode that is supported on mobile devices.

int MODE_STEREO_INTERLACED

Description

Enables the interlaced stereo mode that is used with interlaced stereo monitors and polarized 3D glasses.

int MODE_STEREO_REPLICATE

Description

Enables the separate images stereo mode. This mode serves to output two separate images for each of the eye. It can be used with any VR/AR output devices that support separate images output, e.g. for 3D video glasses or helmets (HMD).

int MODE_STEREO_SEPARATE

Description

Enables the replicate images stereo mode.

int MODE_STEREO_VERTICAL

Description

Enables the vertical stereo mode that is supported on mobile devices.

int SKIP_DYNAMIC_REFLECTIONS

Description

Skip rendering of dynamic reflections in the viewport.

int SKIP_FORMAT_RG11B10

Description

Skip rendering of RG11B10 formats in the viewport.

int SKIP_POSTEFFECTS

Description

Skip rendering of post effects in the viewport.

int SKIP_SHADOWS

Description

Skip shadows rendering in the viewport.

int SKIP_SRGB

Description

Skip rendering of the srgb color space.

int SKIP_STREAMING

Description

Disables data streaming in the process of rendering.

int SKIP_TRANSPARENT

Description

Skip rendering of transparent objects in the viewport.

int SKIP_VELOCITY_BUFFER

Description

Skip rendering to the velocity buffer for the viewport.

int SKIP_VISUALIZER

Description

Skip rendering of the visualizer in the viewport. This flag is set by default for a new viewport.

int USAGE_AUX_LIGHT

Description

Use lighting from the auxiliary virtual scene containing one LightWorld (with 45, 45 and 45 degrees slope angles), scattering is not used.

int USAGE_NODE_LIGHT

Description

Use the node lighting.

int USAGE_WORLD_LIGHT

Description

Use lighting from the LightWorld set in the current loaded world.

int RENDER_DEPTH

Description

Render only depth.

int RENDER_DEPTH_GBUFFER

Description

Render only depth and Gbuffer.

int RENDER_DEPTH_GBUFFER_FINAL

Description

Render depth, Gbuffer and final image.
Last update: 2018-08-10
Build: ()