-
Notifications
You must be signed in to change notification settings - Fork 85
App_MatUI
This page extends on the basic application information provided on the TinyApp page. App_MatUI adds several components:
- A user interface usin AntTweakBar
- Run-time material modifications
- Storing material changes to an xml file, and restoring them
- Requesting the material and depth at the mouse position
- Adjustable depth of field
- Querying rendering statistics
These will be discussed in some detail on this page.
AntTweakBar
The user interface is defined in main_ui.h. AntTweakBar itself is beyond the scope of this wiki, but it is important to note that AntTweakBar operates directly on existing variables. For material editing we create a copy of the selected material and allow AntTweakBar to modify it:
HostMaterial currentMaterial;
A HostMaterial is the CPU-side copy of a material. The core-specific version is a CoreMaterial. Similarly, meshes, triangles, textures, lights and so on have a 'Host' and a 'Core' version. In some cases these are identical, but in other cases, including materials, the 'Core' version is specifically optimized for rendering, while the 'Host' version is optimized for maintenance. More information on this is available on the RenderSystem pages.
Modifying materials
Changes in all scene objects are automatically detected by the RenderSystem. The function HandleMaterialChange nevertheless marks the material as 'dirty', which may or may not be strictly necessary here. It also sets the 'sceneChanges' flag to true, which triggers a restart for the converging: with modified materials, the previous frame cannot be averaged with the current, even if the camera is stationary.
(De)serializing materials
All object importers attempt to convert the model material parameters to the internal format. In this case the application allows run-time editing of materials. To keep the manual adjustments, a serialization system is provided. The function SerializeMaterials stores all scene materials to an xml file. The function DeserializeMaterials restores the scene materials from this file. The xml files can also be edited outside the application.
Probing
To modify materials we need to select a material. The RenderSystem provides a simple mechanic for this: using SetProbePos (see function MousePosCallback in main_tools.h) we can ask the renderer to record primary ray intersection data for the pixel at the mouse location (if the render core supports this). The intersection data typically includes the distance of the object at the mouse position, a triangle and an instance id. The triangle and instance ids are sufficient for determining the material that we want to modify.
Depth of field
The user interface also allows modification of the aperture size. If this is non-zero, the render core is expected to produce depth of field. The position of the focal plane is determined using the probe mechanism.
Renderer statistics
The render core may also return various statistics, such as ray counts and timing information. The information is requested via the RenderSystem, using the function GetCoreStats. Actual information depends on the cooperation of the chosen render core.