Unigine.Viewport Class
A Viewport class is used to render a scene with the specified settings.
There are two main use cases of the Viewport class:
-
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, RenderTarget interface (a frame buffers abstraction), etc.
-
To render the image to the RenderTarget interface, do the following:
// mono rendering // initialization Viewport viewport = new Viewport(); RenderTarget rendertarget = new RenderTarget(); Texture texture = new Texture(); texture.Create2D(512,512,Texture.FORMAT_RGBA8,Texture.USAGE_RENDER); // create 512 x 512 render target Camera camera = new Camera(); // set modelview & projection matrices to camera instance // rendering rendertarget.BindColorTexture(0,texture); rendertarget.Enable(); viewport.Render(camera); rendertarget.Disable(); rendertarget.UnbindAll();
To render the image to the RenderTarget interface in the stereo mode, do the following:
// stereo rendering // initialization Viewport viewport = new Viewport(); RenderTarget rendertarget = new RenderTarget(); Texture left_texture = new Texture(); Texture right_texture = new Texture(); // 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); Camera left_eye = new Camera(); Camera right_eye = new Camera(); // set modelview & projection matrices for each eyes // rendering rendertarget.BindColorTexture(0,left_texture); rendertarget.BindColorTexture(1,right_texture); rendertarget.Enable(); viewport.RenderStereo(left_eye,right_eye,"post_stereo_separate"); // use "post_stereo_separate" material in order to render to both textures rendertarget.Disable(); rendertarget.UnbindAll();
- To render the image to the App interface, check the following 3rdparty samples (e.g. source -> samples -> 3rdparty -> ViewportQt)
Qml and ViewportQt samples are available only for the Engineering and Sim editions of UNIGINE SDKs.
-
- Render a scene to the image (data will be transferred from GPU memory to CPU memory) or texture (data stays in the GPU memory).
- To render the scene to the Texture interface, use the renderTexture2D(camera,texture) method.
// initialization Viewport viewport = new Viewport(); Texture texture = new Texture(); texture.Create2D(512,512,Texture.FORMAT_RGBA8,Texture.USAGE_RENDER); // create 512 x 512 render target Camera camera = new Camera(); // set modelview & projection matrices to camera instance // rendering // saving current render state and clearing it RenderState.SaveState(); RenderState.ClearStates(); // rendering an image from the camera to the texture viewport.RenderTexture2D(camera, texture); // restoring back render state RenderState.RestoreState();
- To render the scene to the Image interface, use the following methods:
- To render the scene to the Texture interface, use the renderTexture2D(camera,texture) method.
- Render a node to the image (data will be transferred from GPU memory to CPU memory) or texture (data stays in the GPU memory).
- To render the node to the Texture interface, use the renderNodeTexture2D(camera,node,texture) method.
- To render the node to the Image interface, use the following methods:
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.
Viewport Class
Properties
int NodeLightUsage#
float StereoOffset#
float StereoRadius#
float StereoDistance#
bool IsPanorama360#
bool IsPanorama180#
bool IsStereo#
int RenderMode#
int Mode#
int SkipFlags#
int FirstFrame#
int AspectCorrection#
int ID#
Members
static Viewport ( ) #
Creates a new viewport with default settings.IntPtr addCallback ( Render.CALLBACK_INDEX 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:void callback_name(Renderer renderer){
/* .. */
}
Arguments
- Render.CALLBACK_INDEX callback - Stage of the rendering sequence for which a callback is to be added. One of the Render.CALLBACK_* variables.
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 ( Render.CALLBACK_INDEX 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
- Render.CALLBACK_INDEX callback - Stage of the rendering sequence for which the callbacks are to be cleared. One of the Render.CALLBACK_* variables.
The _BEGIN prefix corresponds to the beginning of the rendering pass, _END - to its completion.
bool removeCallback ( Render.CALLBACK_INDEX 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
- Render.CALLBACK_INDEX callback - Stage of the rendering sequence for which the callback is to be removed. One of the Render.CALLBACK_* variables.
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 SetNodeEnvironmentTextureName ( string name ) #
Sets a name for the environment texture.Arguments
- string name - A texture name.
void AppendSkipFlags ( int flags ) #
Appends specified skip flags to the list of currently used ones.Arguments
- int flags - Skip flags to append.
int CheckSkipFlags ( int flags ) #
Returns a value indicating if the specified skip flags are set for the current viewport.Arguments
- int flags - Skip flags to check.
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
- int flags - Skip flags to remove.
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:
camera = new Camera();
rendertarget->enable();
viewport->render(camera);
rendertarget->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.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, int 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.
- int hdr - HDR flag.
void RenderImageCube ( Camera camera, 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
- 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.
- int hdr - HDR flag.
- int 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, int 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.
- int hdr - HDR flag.
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.
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 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 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.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.