To achieve the lighting effect, I used a Material Parameter Collection that stored a bunch of vector and scalar parameters. Each would represent a "light sphere" with a location and radius info, combined with a Sphere mask and applied on the opacity of a Masked material.
The collision was the challenge though. In my first try I made collision to be overlap instead of blocking and was rolling with a custom hit detection for the player character as you can see from the raytraces, but it wasn't controlling great, and I wasn't confident in implementing a custom collision system in UE4.
I tried another method, where I'd turn off and on the player's collision, depending on its location. If the player's feet was outside of the light sphere, the collision for the player would be turned off. Problem with that: if the lights went away, the player would still stand in place and get stuck. I tried another approach, where I'd turn off the collision of the platforms instead, and quickly discovered that I just needed to turn off the collision of all in-game platform objects at the same time to achieve the effect. Only issue was that by doing so, all physics-based objects would fall off the screen - so I made a mental note to always constrain physics objects.
Here's another gif with the revised approach. I also added a "void" MPC that was basically a negative light sphere, and here you see some colorful disintegrate/burn effects on the edges - that really took longer to achieve.
Now I had a choice between first and third person - with third person you basically play it as a platformer and it's a bit easier to make the jumps if you can see the feet, whereas first person platforming is always a hassle to control and time your jumps right. I didn't want to repeat a Mario Galaxy level though, and first person was going to be more atmospheric and moody. Plus - I realized with work and all that I didn't have much time to create and rig my custom character - so I eventually decided to go with first person.
It was time to create the game proper. But I immediately stumbled onto these gotchas:
- The material was to be applied to all objects in-game. But upon applying it, objects were basically transparent in the editor. It was going to be a pain editing transparent objects, and so I had the transparency partially disabled when building the game by basically half-shading the material outside the light sphere. The same effect was going to be applied to multiple objects with various materials, so I used a material function.
- A bigger issue was that the complexity of the material was giving UE4 a bit of a pain - the shader complexity was a somewhat worrying dark brown, but the worst bit was having UE4 crash on me multiple times. Fortunately I was frequently saving but I must have sent my crash note to Epic multiple times. I tried upgrading from 4.16 to 4.18, but it still crashed occasionally, which was frustrating to work with. That made me concerned about the actual game (which fortunately didn't crash often), and I avoided adding additional complexity to the materials.
- The number of concurrent light spheres was an issue - I didn't want to bloat up the material complexity too much so I limited it to 12 light spheres and 4 dark spheres, but needed to find a way to juggle between using each of the light spheres. To do that, I made it such that multiple in game light sources would be juggling the same use of a single light sphere - however that introduced a host of problems.
- More of an aesthetic issue: the disintegrate effect looked good with normal meshes but looked meh on the BSP brushes as they were obviously tiled. Wasn't sure how to avoid that.
- Collision was less than ideal as you'd get caught with your feet just within the light sphere and that would block a wall
To sum it up, a cool idea but it was really pushing on the boundaries of what's possible in UE4. There might be a more performant solution, but I'm glad that it was still possible though.
Get Void City
Leave a comment
Log in with itch.io to leave a comment.