YouTube2Text

Volumetric Lighting in Pixel Art?! | Pixel Perfect — Transcript

by Red Giraffe · 1,652 words · 287 segments · language en · Watch on YouTube

Full transcript

  1. 0:03Lighting is fundamental when rendering
  2. 0:05any 3D scene. Without it, the world
  3. 0:08simply doesn't exist. [music]
  4. 0:10The scene data is nothing more than a
  5. 0:12description of triangles and vertices.
  6. 0:14[music]
  7. 0:15And so, lighting is the bridge from the
  8. 0:17virtual to the visual.
  9. 0:20Currently in the series so far, we've
  10. 0:22offloaded these lighting
  11. 0:24responsibilities onto our material
  12. 0:26shaders.
  13. 0:26>> [music]
  14. 0:27>> With stylized rendering, we can take
  15. 0:29more liberties in how we manipulate the
  16. 0:31interaction of light hitting a surface.
  17. 0:34>> [music]
  18. 0:34>> Toon shading is a good candidate for our
  19. 0:36project because it creates clear bands
  20. 0:39of color, [music]
  21. 0:39which transpose well when quantized.
  22. 0:42In this episode, I want to cover
  23. 0:44additional lighting effects. [music]
  24. 0:46These are processes that contribute to
  25. 0:48the feeling of the environment outside
  26. 0:50of the values our materials return. And
  27. 0:53the goal of this [music] is to create a
  28. 0:55scene which feels more lived in and
  29. 0:57three-dimensional.
  30. 1:00If you've been enjoying the series so
  31. 1:02far and want to support my work,
  32. 1:04subscribing is the best way to help the
  33. 1:06channel. Thank you, and without further
  34. 1:08ado, let's get started.
  35. 1:10>> [music]
  36. 1:18[music]
  37. 1:20>> Art is difficult, especially for an
  38. 1:22engineer such as myself. For me, I need
  39. 1:24a slightly more mechanical process
  40. 1:26[music]
  41. 1:27to try and bring these ideas to life.
  42. 1:29And typically, those manifest in three
  43. 1:31clear stages. Reference, interpret, and
  44. 1:35action. It's about finding inspiration
  45. 1:37from life or other existing works.
  46. 1:39[music]
  47. 1:40Looking at how you might filter that
  48. 1:42through your own perception, and finally
  49. 1:44[music] turning it into concrete
  50. 1:46actionable steps.
  51. 1:48How that applies to this set of features
  52. 1:51is that we want to create spaces that
  53. 1:52more closely resemble nature and how
  54. 1:55that feels.
  55. 1:55>> [music]
  56. 1:56>> And so, we can look at environments and
  57. 1:58try to distill what we think is missing.
  58. 2:00>> [music]
  59. 2:01>> To me, the contrast between areas of
  60. 2:03light and shade that roll through the
  61. 2:05scene give a sense of the world being
  62. 2:07alive.
  63. 2:08>> [music]
  64. 2:08>> To replicate this, we'll want to look at
  65. 2:10adding cloud coverage into our pipeline.
  66. 2:15As is typical [music] with natural
  67. 2:17patterns, Perlin noise is a good place
  68. 2:19to start. Just with two parameters,
  69. 2:22scale [music] and threshold, we're
  70. 2:24already able to form something that
  71. 2:25could resemble clouds.
  72. 2:27>> [music]
  73. 2:27>> If we remember that Perlin noise is just
  74. 2:29a texture of values ranging between 0
  75. 2:32and 1,
  76. 2:33>> [music]
  77. 2:33>> the threshold allows us to pick a value
  78. 2:35and clamp any float either side of that
  79. 2:37to their nearest extreme. [music]
  80. 2:41Traditional light cookies or projective
  81. 2:43textures are [music] a common way to
  82. 2:45handle this type of task. More generally
  83. 2:47put, light cookies are masks which can
  84. 2:50[music] filter the output of a light
  85. 2:51source.
  86. 2:52An issue in our case is that they're
  87. 2:54often tied to the light's transform.
  88. 2:56[music]
  89. 2:57If the light moves or if the camera
  90. 2:58rotates, the illusion that our clouds
  91. 3:01exist physically above the ground
  92. 3:02[music] will break.
  93. 3:04To make clouds feel like a physical
  94. 3:06layer that actually exists above the
  95. 3:08world, we need a spatial reference in
  96. 3:10world space.
  97. 3:14We can start this by defining a virtual
  98. 3:17ceiling, a mathematical plane at a fixed
  99. 3:19height. But to figure out where a pixel
  100. 3:22sits in relation to this ceiling, we
  101. 3:24have to reconstruct its world position.
  102. 3:26>> [music]
  103. 3:29>> By sampling the depth texture and
  104. 3:30running it through the inverse view
  105. 3:32projection matrix, we can essentially
  106. 3:34unproject that 2D screen coordinate back
  107. 3:37into the 3D space it came from.
  108. 3:40This gives us an in-engine reference for
  109. 3:42where every pixel on our monitor exists
  110. 3:45in world space.
  111. 3:46>> [music]
  112. 3:48>> Now that we have that 3D coordinate, we
  113. 3:51can treat the sun's direction as a
  114. 3:52vector.
  115. 3:54We're looking for the intersection point
  116. 3:56where a ray, starting at our [music]
  117. 3:57ground position and pointing toward the
  118. 3:59sun, hits our cloud plane.
  119. 4:02The math here is a linear equation where
  120. 4:05we solve for the distance T along that
  121. 4:08light vector.
  122. 4:09Once we have that hit point, we can
  123. 4:11ignore the vertical height and just use
  124. 4:13the X and Z coordinates as our UVs to
  125. 4:17read from the Perlin generated cloud
  126. 4:18[music] texture.
  127. 4:24By adding a time-based offset to these
  128. 4:26UVs, we get a rolling cloud effect.
  129. 4:29>> [music]
  130. 4:31>> The result is a global shadow mask that
  131. 4:34we pass directly into our pipeline's
  132. 4:36shadow caster.
  133. 4:37This allows every object in the scene to
  134. 4:39sample [music] from the mask via default
  135. 4:42shadow calculations and receive the
  136. 4:44global cloud coverage.
  137. 4:49It's worth doing a quick refresher on
  138. 4:50how Unity and most modern engines
  139. 4:53actually handle shadows.
  140. 4:56During the shadow pass, the scene is
  141. 4:58rendered from the light's point of view,
  142. 4:59[music] writing depth values to a shadow
  143. 5:02map texture.
  144. 5:03When rendering the main camera view,
  145. 5:05each fragment transforms its world
  146. 5:07position [music]
  147. 5:08into light space and compares its depth
  148. 5:11against the stored shadow map value.
  149. 5:13If the fragment's depth is greater than
  150. 5:15the shadow map depth, it's occluded and
  151. 5:18receives shadow.
  152. 5:19>> [music]
  153. 5:25>> Looking at this in Unity, the main thing
  154. 5:27you notice is how it breaks up areas of
  155. 5:29flat lighting. It creates a more
  156. 5:31interesting composition of contrasting
  157. 5:33areas. And overall, it grounds the scene
  158. 5:36and makes the space feel more livable
  159. 5:39[music] for lack of a better word.
  160. 5:47>> [music]
  161. 5:48>> And because we've integrated this
  162. 5:50alongside our built-in shadow maps, any
  163. 5:53object in the scene, whether it's static
  164. 5:55or dynamic, is able to sample from this
  165. 5:57global mask.
  166. 6:00>> [music]
  167. 6:14[music]
  168. 6:14>> An interesting stylization tweak is to
  169. 6:17deviate from noise that outputs either
  170. 6:19cloud or not cloud and look [music] at
  171. 6:22partial coverage. Instead of blurring
  172. 6:24the edges of our noise, as that might
  173. 6:26break the pixel art look, we can apply a
  174. 6:29stepped banding effect to values [music]
  175. 6:31within the threshold.
  176. 6:36This consists of simply rounding the
  177. 6:38noise to fixed intervals when the Perlin
  178. 6:40values are read.
  179. 6:42>> [music]
  180. 6:42>> And we can add some additional
  181. 6:44parameters in our pixel art settings
  182. 6:46class to really round out the
  183. 6:48flexibility of this system.
  184. 6:50Back over in Unity, clouds now cover the
  185. 6:52scene with different levels of coverage.
  186. 6:55And as we adjust the threshold,
  187. 6:57different regions of banding are able to
  188. 6:59coalesce.
  189. 6:59>> [music]
  190. 7:04>> Now that we know the regions that are
  191. 7:06directly cast upon by the sun, we can
  192. 7:08start to look at simulating the light to
  193. 7:10pour down into the scene by looking at
  194. 7:13volumetric lighting.
  195. 7:22Shadows are half the story. They tell us
  196. 7:25where the light doesn't reach the floor.
  197. 7:27But god rays are about conveying a sense
  198. 7:29of the light interacting with the
  199. 7:31atmosphere. To simulate this, we need to
  200. 7:34look at the path the light takes through
  201. 7:36the air between the camera and the
  202. 7:37object.
  203. 7:39Some of you may be familiar with the
  204. 7:41concept of ray marching. [music]
  205. 7:43We take the vector from our camera to
  206. 7:45the world position and divide it into a
  207. 7:47fixed number of steps. At each step, we
  208. 7:50can query the information at that point.
  209. 7:52And if we do this for every pixel, we're
  210. 7:55able to form an understanding of the
  211. 7:56volume in front of the camera.
  212. 7:59Now for our process, we deploy this ray
  213. 8:01marching approach, but at each fixed
  214. 8:04interval, we do the same upward
  215. 8:06projection we did for our cloud
  216. 8:08coverage. And so, with each step through
  217. 8:10the air, we build a representation of
  218. 8:12the space that has a clear view of the
  219. 8:14sun.
  220. 8:17>> [music]
  221. 8:17>> Now typically, to avoid the cost of
  222. 8:19these such calculations, a card-based
  223. 8:22approach can be taken to give a
  224. 8:23convincing approximation. But I wanted
  225. 8:26to go with a physically grounded method
  226. 8:28which utilizes our low-resolution grid.
  227. 8:38Now you'll see in the engine that this
  228. 8:39generates beams of light. These are
  229. 8:42areas of the screen that when projected
  230. 8:44back up through the sky, are not
  231. 8:46occluded by our cloud texture. And
  232. 8:48unlike our cloud coverage shadows, which
  233. 8:50is only a projection of the ground via
  234. 8:52the depth map, this data is
  235. 8:54representational of the cloud coverage
  236. 8:56for the space between the ground and the
  237. 8:58sky.
  238. 9:10>> [music]
  239. 9:10>> A clear issue with this type of method
  240. 9:12is noise.
  241. 9:15When we step through the scene, we need
  242. 9:16to define how many samples our ray march
  243. 9:19will process. If we set this to a high
  244. 9:21number, we'll take a hefty performance
  245. 9:24hit. If this number is too low, we won't
  246. 9:26have enough samples to capture the scene
  247. 9:28coherently. A common approach to hiding
  248. 9:31these types of flaws is smoothing or
  249. 9:33blurring. [music]
  250. 9:34If we sort of mix together neighboring
  251. 9:36pixels, we can hide some of the sampling
  252. 9:38issues.
  253. 9:48It results in a more homogeneous light
  254. 9:50flooding result, [music]
  255. 9:51but it does deviate significantly from
  256. 9:53the pixel art aesthetic. I'm still
  257. 9:55uncertain on the best way to go ahead
  258. 9:57here. I personally have more of an
  259. 9:59affinity to combining pixel art [music]
  260. 10:01with modern rendering techniques, but
  261. 10:03I'm keen to hear what you think. So, let
  262. 10:05me know in the comments.
  263. 10:08>> [music]
  264. 10:09>> And as always, we've implemented way too
  265. 10:11many parameters in this episode, [music]
  266. 10:13but it does give us a lot of control
  267. 10:15over how each element renders. From
  268. 10:18changing how the clouds form, [music]
  269. 10:19how dense they are, and how they move to
  270. 10:22aspects of the light transport through
  271. 10:24the air. We get a lot of flexibility in
  272. 10:26what we want to create, and I think it
  273. 10:27succeeds in our goal to add more
  274. 10:29atmosphere.
  275. 10:32>> [music]
  276. 10:34>> I hope you enjoyed this installment of
  277. 10:35Pixel Perfect. If you made it this far
  278. 10:38in the video, [music] a like and
  279. 10:39subscribe goes a long way to help out
  280. 10:41the channel. Let me know what you'd like
  281. 10:43to see me cover in the next episodes,
  282. 10:46and I greatly appreciate all the support
  283. 10:48over [music] on Patreon.
  284. 10:50I'll catch you in the next one. Thanks
  285. 10:51for watching.
  286. 10:54>> [music]
  287. 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.