“Shadow” Mesh Generator
Unreleased Project in Unreal Engine
For this project, I wanted to create environments that represented 2D photographs in 3D space. In other words, everything the camera could see at the time of the photo would be visible in the 3D space, and everything outside of the camera’s view would be culled. One approach to creating this mechanic would have been for each model to be created bespoke, but I wanted to preserve the ability to change a scene’s setup later on without causing a large amount of wake.
I considered multiple approaches, and ultimately I determined that the most feasible and scalable option was to create a tool that would generate “shadow” meshes for each object in the scene. These shadow meshes encompass the entire area behind an object that that object obscures from the camera’s view, basically acting as a silhouette that extends away from the camera (while also scaling as it gets farther away). I would then be able to use these shadow meshes to cut out chunks from the meshes of any objects they overlap with, essentially cutting a shadow-shaped tunnel through the scene.
Shadow tool results
Using Unreal Engine’s Editor Utility Widget system and Blueprint Scripts, I created a tool that allows me to generate and then use these shadow meshes as cutouts.
The basic steps of generating an object shadow mesh are as follows: first, a 1920×1080 texture is created using the capture camera. The camera is set to only see the target object, which it renders in all-white. The result is a black and white silhouette of the object from the camera’s perspective.
Next, that texture is used as a displacement map on a plane mesh that is 1920×1080 units in size. Depending on the target object’s distance from the capture camera, the mesh is scaled to the correct size. Then, the mesh has to be warped so that it grows in scale as it get farther away from the camera. And finally, the shadow mesh is saved in a specified folder and placed in the level.
After generating the object shadow meshes, the Shadow Cutter tool is used to remove the sections of other object’s meshes that overlap with the object shadow. I included options to replace the original object’s static mesh asset with the newly created cut mesh asset, or to add the cut mesh to the level as a separate Actor.
Similarly to the Object Shadow Generator, I also added a tab to the tool that creates a mesh that encompasses the camera’s entire field of view to a specified distance. The camera bounds shadows are much simpler to create, since they’re all the same shape (a sideways pyramid), so they only need to be scaled correctly before they’re placed in level. The camera bounds shadow is then used by the cutter tool to remove the portions of objects that fall outside of the camera’s frame.