Projection and volumetric light

This is the first Unity project I’ve been working on, not counting a few tutorials that I’ve been playing around with in the past. In order to get a proper understanding of the game engine (and when I say proper, I mean basic) I started out by spending quite some time following an online course hosted by Udemy.

I started researching camera projections and the difference between a perspective projection and an orthographic one. I drew the conclusion that a orthographic projection might be easier to work with, since that would entail that I do not have to consider positions on the Z-axis for more than rendering layers. Basically perspective projection takes into account the distance of the object from the camera, and the angle offset it creates. Orthographic projection does not take into account the distance from camera to object. See picture below where the left one is perspective projection and the right one orthographic projection. Picture from stackexchange.com.

projection1

I started working on the alpha build and everything went along quite well. Until we implemented a volumetric light as a searchlight for the player avatar (which is a fishing boat). For some reason the light would not follow the camera completely. After some testing I found out that the offset from moving the player, and therefore moving the searchlight, which is a child of the player was about 1/2. That is, if the player moved 2 units on the x-axis the searchlight would only move 1. This was quite an issue since the light is supposed to be attached to the player avatar.

After some more research I found out that orthographic projection does not support volumetric light. Weird I thought, since the light was there. Almost working as it should.

Anyway. I then tried switching over to a perspective projection camera and after making sure that all my game objects were on the correct Z-position (since this now matters) I tested the prototype again. Lo and behold, the searchlight now followed the avatar as intended. This however gave me a few other issues as some scripts that worked with no issues with orthographic projection now did not. Quite easy fix and the prototype was fixed!

Added a second volumetric light as the player avatar was supposed to have a lantern lighting up the close vicinity of the boat, as well as the searchlight rotating its direction relative to the player avatar.

projection

About Emile Sohier

2017 Programming