Viewport Class
The Viewport class is used to render a scene with the specified settings.
The main use cases of the Viewport class are as follows:
-
Render a scene to the texture interface (data stays in the GPU memory), using the following methods:
- renderTexture2D(camera,texture)
- renderTexture2D(camera,texture,width,height,hdr)
- renderTextureCube(camera,texture,local_space)
- renderTextureCube(camera,texture,size,hdr,local_space)
// initialization Viewport viewport = new Viewport(); Texture texture = new Texture(); texture.create2D(512, 512, TEXTURE_FORMAT_RGBA8);// create 512 x 512 render target CameraPtr camera = new Camera(); // set modelview & projection matrices to camera instance // rendering an image from the camera to the texture viewport.renderTexture2D(camera, texture);
-
Render a node to a texture (data stays in the GPU memory).
-
To render a node (or nodes) to a Texture 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.
See also#
-
See the following C++/C# samples:
- source/samples/Api/Render/GBufferWrite
- source/samples/Api/Render/GBufferRead
- Render to Texture sample in CPP Samples suite
- Weapon Clipping sample in C# Component Samples suite
-
See the following C++/C# usage example:
Viewport Class
Members
void setNodeLightUsage ( int usage ) #
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).
int getNodeLightUsage() const#
Return value
Current 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 setStereoOffset ( float offset ) #
Arguments
- float offset - The virtual camera offset in units.
float getStereoOffset() const#
Return value
Current virtual camera offset in units.void setStereoRadius ( float radius ) #
Arguments
- float radius - The stereo radius in units. If a negative value is provided, 0 will be used instead.
float getStereoRadius() const#
Return value
Current stereo radius in units. If a negative value is provided, 0 will be used instead.void setStereoDistance ( float distance ) #
Arguments
- float distance - The focal distance in units.
float getStereoDistance() const#
Return value
Current focal distance in units.isStereo() const#
Return value
Current stereo rendering for the current viewport (one of the stereo modes)isPanorama() const#
Return value
Current panoramic renderingvoid setRenderMode ( int mode ) #
Arguments
- int mode - The render mode, one of the following:
int getRenderMode() const#
Return value
Current render mode, one of the following:void setMode ( ) #
Arguments
- mode - The rendering mode set for the current viewport. It can be one of the stereo or panoramic modes or the default mode.
getMode() const#
Return value
Current rendering mode set for the current viewport. It can be one of the stereo or panoramic modes or the default mode.void setSkipFlags ( int flags ) #
Arguments
- int flags - The skip flag set for the current viewport.
int getSkipFlags() const#
Return value
Current skip flag set for the current viewport.void setFirstFrame ( int frame ) #
Arguments
- int frame - The value indicating if the first frame is enabled over the current frame: 1 for the first frame flag; otherwise, 0.
int getFirstFrame() const#
Return value
Current value indicating if the first frame is enabled over the current frame: 1 for the first frame flag; otherwise, 0.void setAspectCorrection ( bool correction ) #
Arguments
- bool correction - Set true to enable the aspect correction; false - to disable it.
bool isAspectCorrection() const#
Return value
true if the aspect correction is enabled; otherwise false.int getID() const#
Return value
Current Viewport ID.void setPanoramaFisheyeFov ( float fov ) #
Arguments
- float fov - The field of view angle used for the panorama rendering mode, in degrees.
float getPanoramaFisheyeFov() const#
Return value
Current field of view angle used for the panorama rendering mode, in degrees.void setEnvironmentTexture ( ) #
Arguments
- texture - The cubemap defining the environment color.
getEnvironmentTexture() const#
Return value
Current cubemap defining the environment color.void setPaused ( bool paused ) #
Arguments
- bool paused - Set true to enable the viewport paused state; false - to disable it.
bool isPaused() const#
Return value
true if the viewport paused state is enabled; otherwise false.void setUseTAAOffset ( bool taaoffset ) #
Arguments
- bool taaoffset - Set true to enable skipping render mode check when using TAA; false - to disable it.
bool isUseTAAOffset() const#
Return value
true if skipping render mode check when using TAA is enabled; otherwise false.void setLifetime ( int lifetime ) #
Arguments
- int lifetime - The number of frames during which temporary viewport resources are available after the viewport stops rendering
int getLifetime() const#
Return value
Current number of frames during which temporary viewport resources are available after the viewport stops renderinggetEventEnd() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndScreen() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndVisualizer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginVisualizer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndDebugMaterials() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginDebugMaterials() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndPostMaterials() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginPostMaterials() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndCameraEffects() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginCameraEffects() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndTAA() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginTAA() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndAdaptationColor() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginAdaptationColor() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndAdaptationColorAverage() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginAdaptationColorAverage() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndSrgbCorrection() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginSrgbCorrection() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndTransparent() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndWater() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndWaterPlanarProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginWaterPlanarProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndWaterEnvironmentProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginWaterEnvironmentProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndWaterVoxelProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginWaterVoxelProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndWaterLights() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginWaterLights() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndWaterDecals() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginWaterDecals() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginWater() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndClouds() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginClouds() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginTransparent() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndCompositeDeferred() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginCompositeDeferred() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndSky() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginSky() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndSSGI() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginSSGI() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndSSAO() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginSSAO() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndSSR() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginSSR() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndSSSS() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginSSSS() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndTransparentBlurBuffer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginTransparentBlurBuffer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndRefractionBuffer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginRefractionBuffer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndAuxiliaryBuffer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginAuxiliaryBuffer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndOpacityPlanarProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginOpacityPlanarProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndOpacityEnvironmentProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginOpacityEnvironmentProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndOpacityVoxelProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginOpacityVoxelProbes() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndOpacityLights() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginOpacityLights() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndSSRTGI() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginSSRTGI() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndCurvatureComposite() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginCurvatureComposite() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndCurvature() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginCurvature() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndOpacityDecals() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginOpacityDecals() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndOpacityGBuffer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginOpacityGBuffer() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndMixedRealityBlendMaskColor() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginMixedRealityBlendMaskColor() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginScreen() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndShadows() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndOmniShadow() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginOmniShadow() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndProjShadow() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginProjShadow() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndWorldShadow() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginWorldShadow() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginShadows() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventEndEnvironment() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBeginEnvironment() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.getEventBegin() const#
The event handler signature is as follows: myhandler()Usage Example
Return value
Event reference.static Viewport ( ) #
Creates a new viewport with default settings.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 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 renderTexture2D ( Camera camera, Texture texture, int width, int height, int hdr = 0 ) #
Renders an image of the specified size from the camera to a 2D texture.Arguments
- Camera camera - Camera, an image from which should be rendered.
- Texture 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.
void renderTextureCube ( Camera camera, Texture texture, int 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.
- int local_space - A flag indicating if the camera angle should be used for the cube map rendering.
void renderTextureCube ( Camera camera, Texture texture, 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.
- Texture texture - 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 renderNode ( Camera camera, Node node ) #
Renders the given node with all children to the current rendering target.Arguments
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 renderNodeTexture2D ( Camera camera, Node node, Texture texture, int width, int height, int hdr ) #
Renders the given node with all children to the 2D texture of the specified size.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.
- int width - Texture width, in pixels.
- int height - Texture height, in pixels.
- int hdr - HDR flag.
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 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 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.
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 VRvoid 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.