User Problem
Overload doesn't have any support for in-game user interface
Proposed Solution
We should add everything required to build in-game user interfaces.
To-Do List
PRs should target feature/in_game_ui
Feature Design
Canvas system (OvCore::ECS::Components::UI::Canvas)
Introduce a 2D render pass that will render elements on a flat surface. The canvas size should be customizable, and should be able to adapt itself to the screen. The CCanvas component will mimic Unity's canvas component, as well as the canvas scaler. We should support modes like "Constant Pixel Size" and "Scale With Screen Size".
Instead of rendering the canvas and its directly in the 3D world, like Unity does, we should render the UI in 2D directly on top of the scene (and game) views. A button should be added in the toolbar to toggle this behaviour.
2D Transforms
When a canvas is added, transform information should be interpreted based on the canvas, and not world units. Additional width/height parameters should be introduced for 2D transforms.
2D transform-specific properties should be made optional, and should not bloat the default 3D transform (CTransform). To allow for dynamic addition/removal of such properties, the Describable design pattern can be used. Inheritance should be avoided to allow the transform to mutate from one type to another (2D <--> 3D).
Anchor presets
For UI elements to be actually usable, an anchor system will need to be added. Anchor settings will only be available to 2D transforms.
For reference see Unity's anchor presets.
These presets should be made available through the transform inspector, and position should be locked/unlocked based on the currently used preset.
Layouts
The following components will need to be added:
OvCore::ECS::Components::UI::CHorizontalLayout
OvCore::ECS::Components::UI::CVerticalLayout
UI elements can have their position and width/height modified if their parent has a horizontal or vertical layout. Settings like "padding", "control children width", "control children height" will need to be introduced to the layout components.
Font backend
Overload doesn't have any backend to load font (outside of ImGui, which isn't appropriate for our purpose). OvRendering will need to be extended to support loading fonts (TTF, OTF for now) into static glyph atlases. Custom shaders will need to be added to the engine resources to support rendering fonts using a given glyph atlas. Dependencies like freetype will need to be added, and used for font loading. Fonts when loaded should follow the Model "embedded asset" principle, by having their glyph atlas as an embedded texture, and a material using this embedded texture and the appropriate default text shader will need to be embedded as well.
Text rendering (OvCore::ECS::Components::UI::CText)
This component would behave similarly to a CModelRenderer + CMaterialRenderer, as it would contain text settings, and a font to use. The material to use when rendering would be found inside the embedded assets of the font. Text settings should at least include font size, alignment, and extents. Extents should be drawn as a debug overlay in the scene view.
Image rendering (OvCore::ECS::Components::UI::CImage)
This component would also behave similarly to a CModelRenderer + CMaterialRenderer. For the initial implementation, it would mostly contain a reference to an image, and would use a default "Image" material. A custom shader will need to be implemented.
SceneRenderer composition
This new UI pass will need to be composited on top of the scene rendering. It should apply after post-processing effects. If multiple canvas are found, they should (at least for now) be layered/stacked on top of each other based on their position in the hierarchy. Individual UI components (text, image...) placed under a canvas will need to be drawn in order, from top to bottom, following their placement in the hierarchy.
Lua bindings
All these components will need to be exposed to developers through the Lua API.
User Problem
Overload doesn't have any support for in-game user interface
Proposed Solution
We should add everything required to build in-game user interfaces.
To-Do List
PRs should target
feature/in_game_uiFeature Design
Canvas system (
OvCore::ECS::Components::UI::Canvas)Introduce a 2D render pass that will render elements on a flat surface. The canvas size should be customizable, and should be able to adapt itself to the screen. The
CCanvascomponent will mimic Unity's canvas component, as well as the canvas scaler. We should support modes like "Constant Pixel Size" and "Scale With Screen Size".Instead of rendering the canvas and its directly in the 3D world, like Unity does, we should render the UI in 2D directly on top of the scene (and game) views. A button should be added in the toolbar to toggle this behaviour.
2D Transforms
When a canvas is added, transform information should be interpreted based on the canvas, and not world units. Additional width/height parameters should be introduced for 2D transforms.
2D transform-specific properties should be made optional, and should not bloat the default 3D transform (
CTransform). To allow for dynamic addition/removal of such properties, theDescribabledesign pattern can be used. Inheritance should be avoided to allow the transform to mutate from one type to another (2D <--> 3D).Anchor presets
For UI elements to be actually usable, an anchor system will need to be added. Anchor settings will only be available to 2D transforms.
For reference see Unity's anchor presets.
These presets should be made available through the transform inspector, and position should be locked/unlocked based on the currently used preset.
Layouts
The following components will need to be added:
OvCore::ECS::Components::UI::CHorizontalLayoutOvCore::ECS::Components::UI::CVerticalLayoutUI elements can have their position and width/height modified if their parent has a horizontal or vertical layout. Settings like "padding", "control children width", "control children height" will need to be introduced to the layout components.
Font backend
Overload doesn't have any backend to load font (outside of ImGui, which isn't appropriate for our purpose).
OvRenderingwill need to be extended to support loading fonts (TTF, OTF for now) into static glyph atlases. Custom shaders will need to be added to the engine resources to support rendering fonts using a given glyph atlas. Dependencies like freetype will need to be added, and used for font loading. Fonts when loaded should follow the Model "embedded asset" principle, by having their glyph atlas as an embedded texture, and a material using this embedded texture and the appropriate default text shader will need to be embedded as well.Text rendering (
OvCore::ECS::Components::UI::CText)This component would behave similarly to a
CModelRenderer+CMaterialRenderer, as it would contain text settings, and a font to use. The material to use when rendering would be found inside the embedded assets of the font. Text settings should at least include font size, alignment, and extents. Extents should be drawn as a debug overlay in the scene view.Image rendering (
OvCore::ECS::Components::UI::CImage)This component would also behave similarly to a
CModelRenderer+CMaterialRenderer. For the initial implementation, it would mostly contain a reference to an image, and would use a default "Image" material. A custom shader will need to be implemented.SceneRenderer composition
This new UI pass will need to be composited on top of the scene rendering. It should apply after post-processing effects. If multiple canvas are found, they should (at least for now) be layered/stacked on top of each other based on their position in the hierarchy. Individual UI components (text, image...) placed under a canvas will need to be drawn in order, from top to bottom, following their placement in the hierarchy.
Lua bindings
All these components will need to be exposed to developers through the Lua API.