GPU Instancer:GettingStarted

From GurBu Wiki
Revision as of 00:04, 7 December 2018 by GurBu Admin (talk | contribs) (The Detail Manager)
Jump to: navigation, search

About | Features | Getting Started | Terminology | Best Practices | F.A.Q.


Getting Started


GPU Instancer consists of three main Monobehavior classes. These are the Prefab Manager, Detail Manager and Tree Manager. The managers are designed with mainly ease of use in mind, and adding them to your scene is as easy as clicking a menu item. On this page, you will find information about these managers that will quickly get you started using GPUI.


HelpButton.png  All the GPU Instancer Managers also have a question mark icon on their top right corners. Clicking this icon will make the managers show descriptions on their settings. You can always click this button to get information about a manager setting.



The Prefab Manager


By adding your prefabs to the GPU Instancer Prefab Manager, the prefab instances you add to your scenes are automatically rendered by GPU Instancer. It also provides additional functionality such as adding/removing/updating instances at runtime, changing material properties per instance, choosing an LOD level to render the shadows from, and much more. Note that the Prefab Manager only accepts user created prefabs. It will not accept prefabs that are generated when importing your 3D model assets.


Adding a Prefab Manager
The Prefab Manager


You can add a Prefab Manager from:

Tools -> GPU Instancer -> Add Prefab Manager

HelpButton.png   You can click the question mark icon at the top-right corner of the Prefab Manager at any time to get detailed information about these settings.


Below are the sections you will find in the Prefab Manager.


Scene Settings



The Scene Settings section contains scene specific settings like camera selection and global culling settings that effect all the prototypes in this manager.


Auto Select Camera: When this checkbox is active, GPU Instancer will use the first camera with the MainCamera tag at startup. If the checkbox is inactive, the desired camera can be set manually. GPU Instancer uses this camera for various calculations including culling operations.


Use Selected Camera Only: If enabled, instances will only be rendered with the selected camera. They will not be rendered in other active cameras (including the Scene View camera). This may improve performance if there are other cameras in the scene that are mainly used for camera effects, weather/water effects, reflections, etc. Using this option will make them ignore GPUI, increasing performance. Please note that the scene view during play mode will no longer show GPUI instances if this is selected.


Use Frustum Culling: Toggles frustum culling globally for all the prototypes in this manager. By turning frustum culling off, you can have view GPUI prototypes in all active cameras since they will not be culled. However, please note that turning frustum culling off may result in a lower FPS than having it on. If turned on, you can still turn frustum culling off for individual prototypes.


Use Occlusion Culling: toggles occlusion culling globally for all the prototypes in this manager. By using occlusion culling, the prototypes that are not actually visible at runtime will not be rendered. This will increase rendering performance depending on the amount of occluded geometry. Please note that occlusion culling may lag if the FPS falls to extremely low levels. If this is a possibility, it could be better to turn it off. Please also check the Best Practices section on occlusion culling.


Min. Culling Distance: You can use this slider to define the minimum distance that any kind of culling will occur. If it is a value higher than 0, the instances with a distance less than the specified value to the Camera will never be culled.


Registered Prefabs



Registered Prefabs shows the list of registered prefab instances that are currently in the scene. These instances will be rendered with GPU Instancer.


Register Prefabs in Scene: This button can be used to register the prefab instances that are currently in the scene, so that they can be used by GPU Instancer. When you add new instances to the scene using the Unity editor, you need to register them to GPUI again using this button to update the current instance counts. For adding new instances at runtime, you can check the API documentation.

Prototypes



Prototypes show the list of objects that will be rendered by GPU Instancer. To modify the settings of a prototype, you can click on its image.


Add: Click on this button to select a prefab from your project and add it as a prototype to the manager. You can also drag and drop a prefab, a prefab instance or a GPUI prototype scriptable object on this button; in all these cases the referenced prefab is added to the manager. You can take a look at this section of the Best Practices Page to see how you can add multiple prefabs like this. Please note that you can also use the Scene Prefab Importer tool to create a Prefab Manager with the selected prefab instances in your scene.


The following settings can be edited for each individual prototype.


Shadows



Settings related to shadows can be accessed from this section. GPU Instancer allows you to use shadows selectively on your prototypes. Shadow casting requires extra shadow passes in shaders - resulting in additional rendering operations. GPUI uses various techniques that boost the performance of these operations, but turning shadow casting off completely will increase performance a lot more. If your prefab for the selected prototype is an LOD Group, you can also choose which LOD level to render the shadows from. Rendering shadows from LOD levels with lower triangle counts will help a lot with performance.


Is Shadow Casting: This option specifies whether the object will cast shadows or not. Turning shadows off hides the rest of the shadow options in the menu as well.


Shadow with Original Shader: By default, GPUI uses a custom, lightweight "shadows only" shader to render the shadows of the prototypes that are defined on a Prefab Manager. Using this shader helps increase the shadow performance slightly more; especially if the original shader is using a shadow pass generated by a surface shader (using the addshadow directive). In most cases this shader is enough to render the prototype flawlessly; however, if the original shader uses vertex animation and/or alpha cutoff, then the shadows might not look right. Typical cases of this are when adding tree prefabs. In these cases you can enable this option to use the shadow pass of the original shaders of the prefab and the shadows should then look right.


Use Custom Shadow Distance: If this option is enabled, you can set a custom shadow distance for this prototype. This is particularly helpful since shadows can have the hugest impact on performance. If, for example, your scene fog is blurring objects further away from the camera, then using using a smaller shadow distance can increase the performance while not changing much of visual quality. If this option is not enabled, then GPUI will use the shadow distance defined in Unity's quality settings.


LOD N Shadow: These options appear if the registered prefab has an LOD Group on it. There will be as many options showing here as there are LOD levels on the LOD Group. Using the dropdowns, you can select which LOD level to render the shadows from for each LOD individual level; or choose "None" if you don't wish to render shadows for a specific LOD Group. Managing these options correctly can increase the scene performance greatly.


Use Culling for Shadows: By default GPUI does not use frustum and occlusion culling for prototype shadows that are in the shadow distance. This prevents issues with shadows (e.g. shadow popping) especially if the camera is dynamic and scene lighting changes a lot. If this option is selected, culling results will also be applied to the prototype shadows. This will result in more performance but might also lead to less consistency in shadows.


Culling



These are the culling settings you can define on a prototype basis. Changing settings here will override the general settings in the manager for the selected prototype. You can check the Terminology Page for more information on culling.


Max Distance: Defines the maximum distance from the selected camera within which this prototype will be rendered.


Is Frustum Culling: Specifies whether the objects that are not in the selected camera's view frustum will be rendered or not. If enabled, GPU Instancer will not render the objects that are outside the selected camera's view frustum. This will increase performance. It is recommended to turn frustum culling on unless there are multiple cameras rendering the scene at the same time.


Frustum Offset: Defines the size of the area around the camera frustum planes within which objects will be rendered while frustum culling is enabled. GPU Instancer does frustum culling on the GPU which provides a performance boost. However, if there is a performance hit (usually while rendering an extreme amount of objects in the frustum; or because of some game script), and if the camera is moving very fast at the same time, rendering can lag behind the camera movement. This could result in some objects not being rendered around the frustum edges. This offset expands the calculated frustum area so that the renderer can keep up with the camera movement in those cases.


LOD



Using LODs (Level of Detail) are a great way to improve performance. GPUI supports LOD groups on your prefabs and automatically renders them with indirect instancing while managing the necessary GPU buffer automatically. The LOD settings of the prototype will only be visible if there is an LOD Group on the prefab.


LOD Cross-Fade: Enables cross-fade style blending between the LOD levels of this prototype. This can have a minor impact on performance since during cross-fading, both LOD levels will be rendering.


Animate Cross-Fading: If this option is selected, GPUI animates cross-fading instead of it being distance based. The animation starts with the first occurrence of the changed LOD. During the animation, both LOD levels will be rendered.


LOD Fade Transition Width: You can use this value to define the cross-fading zone between LOD Levels. This zone is the distance in which the prototype LODs are cross-faded. Higher numbers result in wider transition zones. In the transition zone, both LOD levels will be rendered. This option only becomes visible if cross-fade animation is disabled.


LOD Bias Adjustment: This value effects the LOD level distances per prototype. When it is set to a value less than 1, it favors less detail. A value of more than 1 favors greater detail. You can use this to manipulate the instance LOD distances without changing LOD Group on the original prefab.


Runtime Settings



The runtime settings that you can find here can be used to change the runtime behavior of the prototype instances. If you enable runtime modifications, the instances can be added, removed and/or updated during runtime. These modifications can either be done through the GPU Instancer API, or automatically from the manager.


Enable Runtime Modifications: If this option is enabled, transform data (position, rotation, scale) for the prefab instances can be modified at runtime. This can be done either automatically (see below) or through scripting with API calls. The options below become visible only when this option is enabled.


Start With RigidBody: When using this option, the prefab instances that have a RigidBody component on them will start with an active RigidBody.


Add/Remove Instances At Runtime: Enabling this option allows you to add new prefab instances or remove existing ones at runtime. This can be done either automatically (see below) or through scripting with API calls.


Extra Buffer Size: This option specifies the amount of prefab instances that can be added without re-initializing compute buffers at runtime. This is relevant when scripting the add/remove operations and not while GPUI is automatically managing the buffers (see below).


Auto. Add/Remove Instances: If this option is enabled, new prefab instances will be added or existing ones will be removed automatically at runtime without using any API calls. This is the easiest way to use this feature; however, if you have an extreme number of objects (e.g. tens or hundreds of thousands) it is recommended to use the API and manage these operations through code. The reason for this is, each time an instance is added/removed, GPU buffers will be re-initialized. Even though these operations are optimized for efficiency and are quite fast, in extreme numbers there will be a slight difference in performance.


Auto. Update Transform Data: If this option is enabled, transform updates (position, rotation and scale changes) on prefab instances will be reflected automatically on the prototype instances at runtime without the need for API calls. GPUI will track transform changes and physics movements through rigidbodies and apply them to its rendered instances automatically. Please have in mind, however, that even though GPUI efficiently keeps track of the transform changes (i.e. transform data is cached as opposed to being queried each frame), this still adds a further operation to each update. The impact of this on performance should usually not be noticeable, but if you know that your instances transforms will not be updated (that they won't move, rotate or resize) then you should not enable this option.


Billboard Settings



GPU Instancer comes with a billboard generator system. A billboard is a simple quad that shows snapshots of the object from different angles depending on the camera viewing angle. GPUI's billboard generator is mainly designed for use with trees so it generates snapshots of view angles around the world y axis. This means that the billboards do not have view perspectives from up or down. For detailed information on GPUI's billboard generator, you can take a look at its section in the Features Page. Bilboards are a great way to increase performance while having vast viewing distances. GPUI adds the generated billboard automatically as the final LOD level (even if the prefab does not have an LOD Group on it). You can also use a custom mesh and material for the billboard if you do not wish to use the billboard that GPUI generates. All the billboard settings here can be edited for each individual prototype.


Generate Billboard: If enabled, GPU Instancer will automatically generate a camera facing billboard of this prototype to use as its final LOD level. This billboard is made of a single quad mesh, and as such it can increase the performance for distant instances greatly. The remaining billboard options will not be visible if this option is disabled.


Use Custom Billboard: You can use a custom mesh and material with GPUIs billboard system instead of the generated billboard. When you enable this option, you will see two fields where you can assign your mesh and material. Billboard generation settings will disappear since GPUI will not be generating the billboard anymore.


Billboard Quality: Defines the resolution of the billboard textures. Higher resolutions result in better looking billboards, but use more memory. Texture atlases are not square for 2D billboards; so for example "2048" option results in a 2048x256 texture resolution.


Billboard Frame Count: Defines the total amount of snapshots that are taken from different angles for this billboard. Higher frame counts result in more accurate view differences in different view angles, but result in lower resolution frames since they are all packed in the same atlas.


Replace LOD Culled With Billboard: If this option is enabled, GPU Instancer will use the generated billboard instead of the "Culled" distance defined in this prototype's LOD Group. Deselect this option if you want to use a custom billboard distance.


Billboard Distance: Defines the distance to the camera in which the prototype will render as the billboard. Increase this if you want the prototypes to switch to billboards further away from the camera.


Generate Billboard: If you see this option then the billboard has not been generated yet. This button generates the billboard atlases for this prototype and creates the current textures with the current billboard settings.


Regenerate Billboard: This button regenerates the billboard atlases for this prototype and updates the current textures with the changed settings.


Show Billboard: This button instantiates a quad mesh at (0,0,0) position and shows the generated billboard on it. You can use this to inspect how the billboards will look like at runtime. You can also safely delete the generated game object from your scene once you are done inspecting.



By adding your prefabs to the GPU Instancer Prefab Manager, the prefab instances you add to your scenes are automatically rendered by GPU Instancer. It also provides additional functionality such as adding/removing/updating instances at runtime, changing material properties per instance, choosing an LOD level to render the shadows from, and much more. Note that the Prefab Manager only accepts user created prefabs. It will not accept prefabs that are generated when importing your 3D model assets.


The Detail Manager


GPUI-DetailInstancing002.png

The main purpose of the Detail Manager is increasing visual quality over that of the default Unity terrain details while backing this up with the indirect instancing core of GPUI for performance. You also don't have to do any extra work for this visual upgrade - GPUI simply takes your Unity terrain and makes it better looking just by adding the Detail Manager. The default settings on the manager introduce shadows for your details and turn the texture prototypes into cross-quads. The foliage shader also introduces further quality upgrades by adding ambient occlusion, color gradienting, wind wave tints, and much more to the detail instances. The Detail Manager also allows you to use custom shaders for your Unity terrain details while still using cross quads for texture details, shadows, etc.


GPUI uses instancing techniques for backing this up performance-wise, and the result is always a stable FPS with no spikes. The occlusion and frustum culling solutions apply to the detail prototypes as well; further increasing performance. However, please note that in some cases, the FPS would result in a number that is lower than the default Unity terrain especially if you are using features that don't exist in the Unity terrain details. The expected result when increasing visual quality in the Detail Manager, therefore, is not that it would always be faster than the Unity terrain, but that it is fast while still using these features. For more information and best practices on using the Detail Manager, you can check the relevant section of the Best Practices Page.


When you add a Detail Manager for your terrain, the manager automatically creates GPUI prototypes from the detail prototypes that are defined in your terrain. The settings that match the Unity terrain are also transferred to the Manager (e.g. max detail distance, density, colors, etc.)


The prototype types on the terrain result in different kinds of GPUI prototypes depending on whether they are detail textures or detail meshes. Detail textures will be handled by the manager with the GPUI foliage shader, while the prefab references of the detail meshes will be directly referenced as prefab instances. What this latter point means is that even though the Unity terrain applies its own shader and does not always correctly handle prefabs for detail prototypes, you can add them to the terrain anyway and GPUI will render them with their own materials and shaders. Furthermore, you can also add prefabs with LOD Groups on them if you add the prototypes form the Detail Manager. GPUI will add the first LOD to the terrain so that it is visible in the editor; but will use the prefab with all its LOD levels when rendering. We recommend to use LODed prefabs on your terrains as details for performance.


Please also note that you can use the GPUI foliage shader on your prefab materials and make use of this shaders features when using prefab prototypes. You can check the DetailInstancingDemo scene to investigate how we used the detail manager settings and LODs on the detail prefabs (that also use the foliage shader).


Adding Detail Managers
The Detail Manager

You can add a Detail Manager from:

Tools -> GPU Instancer -> Add Detail Manager For Terrains

HelpButton.png   You can click the question mark icon at the top-right corner of the Detail Manager at any time to get detailed information about these settings.


When you click this menu item, GPU Instancer will create a Detail Manager for each Unity terrain that you have in the scene. Below are the sections you will find in the Detail Manager.


Scene Settings



The Scene Settings section contains scene specific settings like camera selection and global culling settings that effect all the prototypes in this manager. You can also easily switch to the Unity terrain that this manager is responsible for to paint details on the terrain. You can also set and unset the terrain connection with this manager from here.


Please note that after you add the Detail Manager, it is recommended to add/remove/update detail prototypes on the terrain from the manager rather than directly on the terrain object.


Paint on Terrain: This button can be used to navigate to the Unity terrain component that this manager is referencing. Details should be painted on the terrain using Unity's native tools as usual. Detail data on the terrain will be automatically detected by GPU Instancer. GPUI also adds a script on your terrain which will show you a button to go back to the manager that is responsible for that terrain. When you are done painting, you can use the Go to GPUI Detail Manager button to come back to the manager.


Unset Terrain: This button will severe the connection between the Unity terrain and this manager. You can use this to effectively disable GPUI's rendering of the terrain. It can later be enabled again by using the Set Terrain button.


Auto Select Camera: When this checkbox is active, GPU Instancer will use the first camera with the MainCamera tag at startup. If the checkbox is inactive, the desired camera can be set manually. GPU Instancer uses this camera for various calculations including culling operations.


Use Selected Camera Only: If enabled, instances will only be rendered with the selected camera. They will not be rendered in other active cameras (including the Scene View camera). This may improve performance if there are other cameras in the scene that are mainly used for camera effects, weather/water effects, reflections, etc. Using this option will make them ignore GPUI, increasing performance. Please note that the scene view during play mode will no longer show GPUI instances if this is selected.


Use Frustum Culling: Toggles frustum culling globally for all the prototypes in this manager. By turning frustum culling off, you can have view GPUI prototypes in all active cameras since they will not be culled. However, please note that turning frustum culling off may result in a lower FPS than having it on. If turned on, you can still turn frustum culling off for individual prototypes.


Use Occlusion Culling: toggles occlusion culling globally for all the prototypes in this manager. By using occlusion culling, the prototypes that are not actually visible at runtime will not be rendered. This will increase rendering performance depending on the amount of occluded geometry. Please note that occlusion culling may lag if the FPS falls to extremely low levels. If this is a possibility, it could be better to turn it off. Please also check the Best Practices section on occlusion culling.


Min. Culling Distance: You can use this slider to define the minimum distance that any kind of culling will occur. If it is a value higher than 0, the instances with a distance less than the specified value to the Camera will never be culled.


Debug



The debug section is intended to show edit-time specific features. It is mainly used to simulate GPUI's rendering of terrain details without entering play mode. Since GPUI uses the data from the instances on the Unity terrain, it does not take over scene rendering and you can enable and disable GPUI in your project without loosing the terrain detail data.


Simulate at Scene Camera: This button can be used to render the terrain details on the scene camera using the current GPU Instancer setup. This simulation is designed to provide a fast sneak peak of the GPU Instanced terrain details without having to enter play mode.


Global Detail Values



These settings are applied to all the detail prototypes defined in the manager.


Max Detail Distance: defines the maximum distance from the camera within which the terrain details will be rendered. Details that are farther than the specified distance will not be visible. This setting also provides the upper limit for the maximum view distance of each detail prototype.


Detail Density: goes from 0.0 to 1.0, with 1.0 being the original density, and lower numbers resulting in less detail objects being rendered.


Wind Vector: specifies the [X, Z] vector (world axis) of the wind for all the prototypes (in this terrain) that use the "GPUInstancer/Foliage" shader (which is also the default shader for the texture type grass details). This vector supplies both direction and magnitude information for wind.


Healthy / Dry Noise Texture: can be used to specify the Healthy Color / Dry Color variation for all the prototypes that use the "GPUInstancer/Foliage" shader in this terrain (which is also the default shader for the texture type grass details). Texture type detail prototypes are also scaled by this noise. This image must be a greyscale noise texture.


Wind Wave Normal Texture: can be used to specify the vectors of all wind animations and coloring for all the prototypes that use the "GPUInstancer/Foliage" shader in this terrain (which is also the default shader for the texture type grass details). This image must be a normal map noise texture.


Auto SP Cell Size: Detail Manager uses spatial partitioning for loading and unloading detail instances from GPU memory according to camera position. Detail instances are grouped in cells with a calculated size. By selecting "Auto SP Cell Size", you can let the manager decide which cell size to use. If you deselect "Auto SP Cell Size", you can determine a "Prefered SP Cell Size".


Prototypes



Prototypes show the list of objects that will be used in GPU Instancer. To modify a prototype, click on its image.


Render Settings



Render Settings can be edited individualy for each prototype.


Detail Properties



Detail Properties can be edited individualy for each prototype.


Cross Quads



Cross Quads can be edited individualy for each prototype.


Foliage Shader Properties



Foliage Shader Properties can be edited individualy for each prototype.


The Tree Manager

Scene Settings

Scene Settings contains scene specific settings like camera selection.

Global Tree Values

Global Tree Values settings that are applied to all tree prototypes.

Prototypes

Prototypes show the list of objects that will be used in GPU Instancer. To modify a prototype, click on its image.

Render Settings

Render Settings can be edited individualy for each prototype.

Billboard Settings

Billboard Settings can be edited individualy for each prototype.