Volumetric Lighting in Pixel Art?! | Pixel Perfect — Transcript
Full transcript
- 0:03Lighting is fundamental when rendering
- 0:05any 3D scene. Without it, the world
- 0:08simply doesn't exist. [music]
- 0:10The scene data is nothing more than a
- 0:12description of triangles and vertices.
- 0:14[music]
- 0:15And so, lighting is the bridge from the
- 0:17virtual to the visual.
- 0:20Currently in the series so far, we've
- 0:22offloaded these lighting
- 0:24responsibilities onto our material
- 0:26shaders.
- 0:26>> [music]
- 0:27>> With stylized rendering, we can take
- 0:29more liberties in how we manipulate the
- 0:31interaction of light hitting a surface.
- 0:34>> [music]
- 0:34>> Toon shading is a good candidate for our
- 0:36project because it creates clear bands
- 0:39of color, [music]
- 0:39which transpose well when quantized.
- 0:42In this episode, I want to cover
- 0:44additional lighting effects. [music]
- 0:46These are processes that contribute to
- 0:48the feeling of the environment outside
- 0:50of the values our materials return. And
- 0:53the goal of this [music] is to create a
- 0:55scene which feels more lived in and
- 0:57three-dimensional.
- 1:00If you've been enjoying the series so
- 1:02far and want to support my work,
- 1:04subscribing is the best way to help the
- 1:06channel. Thank you, and without further
- 1:08ado, let's get started.
- 1:10>> [music]
- 1:18[music]
- 1:20>> Art is difficult, especially for an
- 1:22engineer such as myself. For me, I need
- 1:24a slightly more mechanical process
- 1:26[music]
- 1:27to try and bring these ideas to life.
- 1:29And typically, those manifest in three
- 1:31clear stages. Reference, interpret, and
- 1:35action. It's about finding inspiration
- 1:37from life or other existing works.
- 1:39[music]
- 1:40Looking at how you might filter that
- 1:42through your own perception, and finally
- 1:44[music] turning it into concrete
- 1:46actionable steps.
- 1:48How that applies to this set of features
- 1:51is that we want to create spaces that
- 1:52more closely resemble nature and how
- 1:55that feels.
- 1:55>> [music]
- 1:56>> And so, we can look at environments and
- 1:58try to distill what we think is missing.
- 2:00>> [music]
- 2:01>> To me, the contrast between areas of
- 2:03light and shade that roll through the
- 2:05scene give a sense of the world being
- 2:07alive.
- 2:08>> [music]
- 2:08>> To replicate this, we'll want to look at
- 2:10adding cloud coverage into our pipeline.
- 2:15As is typical [music] with natural
- 2:17patterns, Perlin noise is a good place
- 2:19to start. Just with two parameters,
- 2:22scale [music] and threshold, we're
- 2:24already able to form something that
- 2:25could resemble clouds.
- 2:27>> [music]
- 2:27>> If we remember that Perlin noise is just
- 2:29a texture of values ranging between 0
- 2:32and 1,
- 2:33>> [music]
- 2:33>> the threshold allows us to pick a value
- 2:35and clamp any float either side of that
- 2:37to their nearest extreme. [music]
- 2:41Traditional light cookies or projective
- 2:43textures are [music] a common way to
- 2:45handle this type of task. More generally
- 2:47put, light cookies are masks which can
- 2:50[music] filter the output of a light
- 2:51source.
- 2:52An issue in our case is that they're
- 2:54often tied to the light's transform.
- 2:56[music]
- 2:57If the light moves or if the camera
- 2:58rotates, the illusion that our clouds
- 3:01exist physically above the ground
- 3:02[music] will break.
- 3:04To make clouds feel like a physical
- 3:06layer that actually exists above the
- 3:08world, we need a spatial reference in
- 3:10world space.
- 3:14We can start this by defining a virtual
- 3:17ceiling, a mathematical plane at a fixed
- 3:19height. But to figure out where a pixel
- 3:22sits in relation to this ceiling, we
- 3:24have to reconstruct its world position.
- 3:26>> [music]
- 3:29>> By sampling the depth texture and
- 3:30running it through the inverse view
- 3:32projection matrix, we can essentially
- 3:34unproject that 2D screen coordinate back
- 3:37into the 3D space it came from.
- 3:40This gives us an in-engine reference for
- 3:42where every pixel on our monitor exists
- 3:45in world space.
- 3:46>> [music]
- 3:48>> Now that we have that 3D coordinate, we
- 3:51can treat the sun's direction as a
- 3:52vector.
- 3:54We're looking for the intersection point
- 3:56where a ray, starting at our [music]
- 3:57ground position and pointing toward the
- 3:59sun, hits our cloud plane.
- 4:02The math here is a linear equation where
- 4:05we solve for the distance T along that
- 4:08light vector.
- 4:09Once we have that hit point, we can
- 4:11ignore the vertical height and just use
- 4:13the X and Z coordinates as our UVs to
- 4:17read from the Perlin generated cloud
- 4:18[music] texture.
- 4:24By adding a time-based offset to these
- 4:26UVs, we get a rolling cloud effect.
- 4:29>> [music]
- 4:31>> The result is a global shadow mask that
- 4:34we pass directly into our pipeline's
- 4:36shadow caster.
- 4:37This allows every object in the scene to
- 4:39sample [music] from the mask via default
- 4:42shadow calculations and receive the
- 4:44global cloud coverage.
- 4:49It's worth doing a quick refresher on
- 4:50how Unity and most modern engines
- 4:53actually handle shadows.
- 4:56During the shadow pass, the scene is
- 4:58rendered from the light's point of view,
- 4:59[music] writing depth values to a shadow
- 5:02map texture.
- 5:03When rendering the main camera view,
- 5:05each fragment transforms its world
- 5:07position [music]
- 5:08into light space and compares its depth
- 5:11against the stored shadow map value.
- 5:13If the fragment's depth is greater than
- 5:15the shadow map depth, it's occluded and
- 5:18receives shadow.
- 5:19>> [music]
- 5:25>> Looking at this in Unity, the main thing
- 5:27you notice is how it breaks up areas of
- 5:29flat lighting. It creates a more
- 5:31interesting composition of contrasting
- 5:33areas. And overall, it grounds the scene
- 5:36and makes the space feel more livable
- 5:39[music] for lack of a better word.
- 5:47>> [music]
- 5:48>> And because we've integrated this
- 5:50alongside our built-in shadow maps, any
- 5:53object in the scene, whether it's static
- 5:55or dynamic, is able to sample from this
- 5:57global mask.
- 6:00>> [music]
- 6:14[music]
- 6:14>> An interesting stylization tweak is to
- 6:17deviate from noise that outputs either
- 6:19cloud or not cloud and look [music] at
- 6:22partial coverage. Instead of blurring
- 6:24the edges of our noise, as that might
- 6:26break the pixel art look, we can apply a
- 6:29stepped banding effect to values [music]
- 6:31within the threshold.
- 6:36This consists of simply rounding the
- 6:38noise to fixed intervals when the Perlin
- 6:40values are read.
- 6:42>> [music]
- 6:42>> And we can add some additional
- 6:44parameters in our pixel art settings
- 6:46class to really round out the
- 6:48flexibility of this system.
- 6:50Back over in Unity, clouds now cover the
- 6:52scene with different levels of coverage.
- 6:55And as we adjust the threshold,
- 6:57different regions of banding are able to
- 6:59coalesce.
- 6:59>> [music]
- 7:04>> Now that we know the regions that are
- 7:06directly cast upon by the sun, we can
- 7:08start to look at simulating the light to
- 7:10pour down into the scene by looking at
- 7:13volumetric lighting.
- 7:22Shadows are half the story. They tell us
- 7:25where the light doesn't reach the floor.
- 7:27But god rays are about conveying a sense
- 7:29of the light interacting with the
- 7:31atmosphere. To simulate this, we need to
- 7:34look at the path the light takes through
- 7:36the air between the camera and the
- 7:37object.
- 7:39Some of you may be familiar with the
- 7:41concept of ray marching. [music]
- 7:43We take the vector from our camera to
- 7:45the world position and divide it into a
- 7:47fixed number of steps. At each step, we
- 7:50can query the information at that point.
- 7:52And if we do this for every pixel, we're
- 7:55able to form an understanding of the
- 7:56volume in front of the camera.
- 7:59Now for our process, we deploy this ray
- 8:01marching approach, but at each fixed
- 8:04interval, we do the same upward
- 8:06projection we did for our cloud
- 8:08coverage. And so, with each step through
- 8:10the air, we build a representation of
- 8:12the space that has a clear view of the
- 8:14sun.
- 8:17>> [music]
- 8:17>> Now typically, to avoid the cost of
- 8:19these such calculations, a card-based
- 8:22approach can be taken to give a
- 8:23convincing approximation. But I wanted
- 8:26to go with a physically grounded method
- 8:28which utilizes our low-resolution grid.
- 8:38Now you'll see in the engine that this
- 8:39generates beams of light. These are
- 8:42areas of the screen that when projected
- 8:44back up through the sky, are not
- 8:46occluded by our cloud texture. And
- 8:48unlike our cloud coverage shadows, which
- 8:50is only a projection of the ground via
- 8:52the depth map, this data is
- 8:54representational of the cloud coverage
- 8:56for the space between the ground and the
- 8:58sky.
- 9:10>> [music]
- 9:10>> A clear issue with this type of method
- 9:12is noise.
- 9:15When we step through the scene, we need
- 9:16to define how many samples our ray march
- 9:19will process. If we set this to a high
- 9:21number, we'll take a hefty performance
- 9:24hit. If this number is too low, we won't
- 9:26have enough samples to capture the scene
- 9:28coherently. A common approach to hiding
- 9:31these types of flaws is smoothing or
- 9:33blurring. [music]
- 9:34If we sort of mix together neighboring
- 9:36pixels, we can hide some of the sampling
- 9:38issues.
- 9:48It results in a more homogeneous light
- 9:50flooding result, [music]
- 9:51but it does deviate significantly from
- 9:53the pixel art aesthetic. I'm still
- 9:55uncertain on the best way to go ahead
- 9:57here. I personally have more of an
- 9:59affinity to combining pixel art [music]
- 10:01with modern rendering techniques, but
- 10:03I'm keen to hear what you think. So, let
- 10:05me know in the comments.
- 10:08>> [music]
- 10:09>> And as always, we've implemented way too
- 10:11many parameters in this episode, [music]
- 10:13but it does give us a lot of control
- 10:15over how each element renders. From
- 10:18changing how the clouds form, [music]
- 10:19how dense they are, and how they move to
- 10:22aspects of the light transport through
- 10:24the air. We get a lot of flexibility in
- 10:26what we want to create, and I think it
- 10:27succeeds in our goal to add more
- 10:29atmosphere.
- 10:32>> [music]
- 10:34>> I hope you enjoyed this installment of
- 10:35Pixel Perfect. If you made it this far
- 10:38in the video, [music] a like and
- 10:39subscribe goes a long way to help out
- 10:41the channel. Let me know what you'd like
- 10:43to see me cover in the next episodes,
- 10:46and I greatly appreciate all the support
- 10:48over [music] on Patreon.
- 10:50I'll catch you in the next one. Thanks
- 10:51for watching.
- 10:54>> [music]
- 10:59[music]
About this transcript
This page contains the full transcript of Volumetric Lighting in Pixel Art?! | Pixel Perfect by Red Giraffe, generated from the public captions YouTube serves with the video. The transcript has 1,652 words across 287 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.