Sprint 3 Unlit Renderer - UQdeco2800/2021-studio-6 GitHub Wiki
Overview
After the lighting engine was introduced into the game, a new problem was found with rendering entities separate to the lighting system. With how the render update is structured, the lighting is rendered last over the top of the previously rendered elements, hence giving the appearance of dynamic lighting. However, this meant that any asset registered in the render service, apart from the UI which is rendered separately, would be effected by the lighting.
RenderService and MainGameScreen
To allow assets to be rendered separately from the lighting engine, a new RenderService named renderUnlitService was created and registered in the ServiceLocator. This RenderService stores and registers the relevant assets separately from the normal renderService, thus allowing a separate render function to be run after the lighting is rendered, as evident in the render function of MainGameScreen.
Renderer
To properly register assets in the new unlit service, the Renderer was adjusted to take in a boolean value that designates if the service is for lit (true) or unlit (false) assets. This creates the appropriate service so that assets can be registered with it later on for rendering.
RenderFactory
createUnlitRenderer(CameraComponent camComponent, Stage stage)
This function is used to create the new unlitRenderService. The only noteworthy difference against the normal renderService constructor is that it needs to be passed the CameraComponent and Stage created in the normal renderService constructor so that both renderers refer to the same environmental entities. As such, createUnlitRenderer should only be called after the normal renderService is constructed. It also sets the lighting to false when creating the Renderer.
RenderComponent
The RenderComponent was changed to automatically register new assets within the lit render service for simplicity sake. However, two new functions were created to properly assign and registers the asset to the correct RenderService for use later in the render update.
setLit()
Registers the asset to the lit renderService.
setUnlit()
Registers the asset to the unlitRenderService and unregisters it from the normal, lit renderService.
IndependentAnimator
As it stands, IndependentAnimator is the only Renderable asset that is implemented with the unlitRenderService. This was for the sake of efficieny, as the only assets that required the unlitRenderService were IndependentAnimations. The only change made was to add a boolean variable to the constructor that specifies if the object is lit (true) or not (false), which calls the necessary function in RenderComponent.
While this is the only class that has this feature, changing the other classes (AnimationRenderComponent and TextureRenderComponent) should be as simple as changing the constructor in a similar manner so that they take in a boolean variable dictating if it is lit or not. The only thing after this is to call the appropriate function from RenderComponent to assign it correctly.