{"id":2481,"date":"2022-08-04T18:41:52","date_gmt":"2022-08-04T18:41:52","guid":{"rendered":"https:\/\/salarydistribution.com\/machine-learning\/2022\/08\/04\/what-is-direct-and-indirect-lighting\/"},"modified":"2022-08-04T18:41:52","modified_gmt":"2022-08-04T18:41:52","slug":"what-is-direct-and-indirect-lighting","status":"publish","type":"post","link":"https:\/\/salarydistribution.com\/machine-learning\/2022\/08\/04\/what-is-direct-and-indirect-lighting\/","title":{"rendered":"What Is Direct and Indirect Lighting?"},"content":{"rendered":"<div data-url=\"https:\/\/blogs.nvidia.com\/blog\/2022\/08\/04\/direct-indirect-lighting\/\" data-title=\"What Is Direct and Indirect Lighting?\" data-hashtags=\"\">\n<p>Imagine hiking to a lake on a summer day \u2014 sitting under a shady tree and watching the water gleam under the sun.<\/p>\n<p>In this scene, the differences between light and shadow are examples of direct and indirect lighting.<\/p>\n<p>The sun shines onto the lake and the trees, making the water look like it\u2019s shimmering and the leaves appear bright green. That\u2019s direct lighting. And though the trees cast shadows, sunlight still bounces off the ground and other trees, casting light on the shady area around you. That\u2019s indirect lighting.<\/p>\n<p>For computer graphics to immerse viewers in photorealistic environments, it\u2019s important to accurately simulate the behavior of light to achieve the proper balance of direct and indirect lighting.<\/p>\n<h2><b>What Is Direct and Indirect Lighting?<\/b><\/h2>\n<p>Light shining onto an object is called <i>direct lighting<\/i>.<\/p>\n<p>It determines the color and quantity of light that reaches a surface from a light source, but ignores all light that may arrive at the surface from any other sources, such as after reflection or refraction. Direct lighting also determines the amount of the light that\u2019s absorbed and reflected by the surface itself.<\/p>\n<figure id=\"attachment_58717\" aria-describedby=\"caption-attachment-58717\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-1.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-1-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58717\" class=\"wp-caption-text\">Direct lighting from the sun and sky.<\/figcaption><\/figure>\n<p>Light bouncing off a surface, illuminating other objects is called <i>indirect lighting<\/i>. It arrives at surfaces from everything <i>except <\/i>light sources. In other words, indirect lighting determines the color and quantity of all other light that arrives at a surface. Most commonly, indirect light is reflected from one surface onto other surfaces.<\/p>\n<p>Indirect lighting generally tends to be more difficult and expensive to compute than direct lighting. This is because there is a substantially larger number of paths that light can take between the light emitter and the observer.<\/p>\n<figure id=\"attachment_58720\" aria-describedby=\"caption-attachment-58720\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-2.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-2-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58720\" class=\"wp-caption-text\">Direct and indirect lighting in the same setting.<\/figcaption><\/figure>\n<h2><b>What Is Global Illumination?<\/b><\/h2>\n<p>Global illumination is the process of computing the color and quantity of <i>all light<\/i> \u2014 both direct and indirect \u2014 that is on visible surfaces in a scene.<\/p>\n<p>Accurately simulating all types of indirect light is extremely difficult, especially if the scene includes complex materials such as glass, water and shiny metals \u2014 or if the scene has scattering in clouds, smoke, fog or other elements known as volumetric media.<\/p>\n<p>As a result, real-time graphics solutions for global illumination are typically limited to computing a subset of the indirect light \u2014 commonly for surfaces with diffuse (aka matte) materials.<\/p>\n<h2><b>How Are Direct and Indirect Lighting Computed?\u00a0<\/b><\/h2>\n<p>Many algorithms can be used for computing direct lighting, all of which have strengths and weaknesses. For example, if the scene has a single light and no shadows, direct illumination is trivial to compute, but it won\u2019t look very realistic. On the other hand, when a scene has multiple light sources, processing them all for each surface can become expensive.<\/p>\n<p>To tackle these issues, optimized algorithms and shading techniques were developed, such as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Deferred_shading\">deferred<\/a> or <a href=\"https:\/\/www.cse.chalmers.se\/~uffe\/clustered_shading_preprint.pdf\">clustered<\/a> shading. These algorithms reduce the number of surface and light interactions to be computed.<\/p>\n<p>Shadows can be added through a number of techniques, including shadow maps, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Shadow_volume\">stencil shadow volumes<\/a> and <a href=\"https:\/\/developer.nvidia.com\/rtx\/ray-tracing\">ray tracing<\/a>.<\/p>\n<p>Shadow mapping has two steps. First, the scene is rendered from the light\u2019s point of view into a special texture called the shadow map. Then, the shadow map is used to test whether surfaces visible on the screen are also visible from the light\u2019s point of view. Shadow maps come with many limitations and artifacts, and quickly become expensive as the number of lights in the scene increases.<\/p>\n<figure id=\"attachment_58723\" aria-describedby=\"caption-attachment-58723\" class=\"wp-caption alignright\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-3.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-3-400x213.jpg\" alt=\"\" width=\"400\" height=\"213\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58723\" class=\"wp-caption-text\">Stencil shadows in \u2018Doom 3\u2019 (2004). Image source: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Shadow_volume\">Wikipedia<\/a>.<\/figcaption><\/figure>\n<p>Stencil shadow volumes are based on extruding scene geometry away from the light, and rendering that extruded geometry into the stencil buffer. The contents of the stencil buffer are then used to determine if a given surface on the screen is in shadow or not. Stencil shadows are always sharp, unnaturally so, but they don\u2019t suffer from common shadow map problems.<\/p>\n<p>Until the introduction of <a href=\"https:\/\/www.nvidia.com\/en-us\/design-visualization\/technologies\/rtx\/\">NVIDIA RTX technology<\/a>, ray tracing was too costly to use when computing shadows. Ray tracing is a method of rendering in graphics that simulates the physical behavior of light. Tracing the rays from a surface on the screen to a light allows for the computation of shadows, but this can be challenging if the light comes from one point. And ray-traced shadows can quickly get expensive if there are many lights in the scene.<\/p>\n<p>More efficient sampling methods were developed to reduce the number of rays required to compute soft shadows from multiple lights. One example is an algorithm called<a href=\"https:\/\/research.nvidia.com\/sites\/default\/files\/pubs\/2020-07_Spatiotemporal-reservoir-resampling\/ReSTIR.pdf\"> ReSTIR<\/a>, which calculates direct lighting from millions of lights and shadows with ray tracing at interactive frame rates.<\/p>\n<figure id=\"attachment_58726\" aria-describedby=\"caption-attachment-58726\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-4.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-4-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58726\" class=\"wp-caption-text\">Direct illumination and ray-traced shadows created with ReSTIR, compared to a previous algorithm.<\/figcaption><\/figure>\n<h2>What Is Path Tracing?<\/h2>\n<p>For indirect lighting and global illumination, even more methods exist. The most straightforward is called <a href=\"https:\/\/blogs.nvidia.com\/blog\/2022\/03\/23\/what-is-path-tracing\/\">path tracing<\/a>, where random light paths are simulated for each visible surface. Some of these paths reach lights and contribute to the finished scene, while others do not.<\/p>\n<p>Path tracing is the most accurate method capable of producing results that fully represent lighting in a scene, matching the accuracy of mathematical models for materials and lights. Path tracing can be very expensive to compute, but it\u2019s considered the \u201choly grail\u201d of real-time graphics.<\/p>\n<figure id=\"attachment_58729\" aria-describedby=\"caption-attachment-58729\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-5.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-5-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58729\" class=\"wp-caption-text\">Comparison of path tracing with a less complete ray-tracing algorithm and rasterization.<\/figcaption><\/figure>\n<h2><b>How Does Direct and Indirect Lighting Affect Graphics?<\/b><\/h2>\n<figure id=\"attachment_58732\" aria-describedby=\"caption-attachment-58732\" class=\"wp-caption alignright\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-6.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-6-400x213.jpg\" alt=\"\" width=\"400\" height=\"213\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58732\" class=\"wp-caption-text\">Light map applied to a scene. Image courtesy of <a href=\"https:\/\/www.reddit.com\/r\/Unity3D\/comments\/ccdte9\/externally_baked_lightmap_from_blender_into_unity\/\">Reddit.<\/a><\/figcaption><\/figure>\n<p>Direct lighting provides the basic appearance of realism, and indirect lighting makes scenes look richer and more natural.<\/p>\n<p>One way indirect lighting has been used in many video games is through omnipresent ambient light. This type of light can be constant, or vary spatially over light probes arranged in a grid pattern. It can also be rendered into a texture that is wrapped around static objects in a scene \u2014 this method is known as a \u201clight map.\u201d<\/p>\n<p>In most cases, ambient light is shadowed by a function of geometry around the surface called ambient occlusion, which helps increase the image realism.<\/p>\n<figure id=\"attachment_58735\" aria-describedby=\"caption-attachment-58735\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-7.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-7-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58735\" class=\"wp-caption-text\">Direct lighting only vs. global illumination in a forest scene.<\/figcaption><\/figure>\n<h2><b>Examples of Direct Lighting, Indirect Lighting and Global Illumination<\/b><\/h2>\n<p>Direct and indirect lighting has been present, in some form, in almost every 3D game since the 1990s. Below are some milestones of how lighting has been implemented in popular titles:<\/p>\n<ul>\n<li>1993: <i>Doom<\/i> showcased one of the first examples of dynamic lighting. The game could vary the light intensity per sector, which made textures lighter or darker, and was used to simulate dim and bright areas or flickering lights.<\/li>\n<\/ul>\n<figure id=\"attachment_58738\" aria-describedby=\"caption-attachment-58738\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-8.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-8-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58738\" class=\"wp-caption-text\">Map sectors with varying light intensities in <em>Doom.<\/em><\/figcaption><\/figure>\n<ul>\n<li>1995: <i>Quake<\/i> introduced light maps, which were pre-computed for each level in the game. The light maps could modulate the ambient light intensity.<\/li>\n<li>1997: <i>Quake II<\/i> added color to the light maps, as well as dynamic lighting from projectiles and explosions.<\/li>\n<li>2001: <i>Silent Hill 2<\/i> showcased per-pixel lighting and shadow mapping. <i>Shrek<\/i> used deferred lighting and stencil shadows.<\/li>\n<li>2007: <i>Crysis<\/i> showed dynamic screen-space ambient occlusion, which uses pixel depth to give a sense of changes in lighting.<\/li>\n<\/ul>\n<figure id=\"attachment_58741\" aria-describedby=\"caption-attachment-58741\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-9.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-9-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58741\" class=\"wp-caption-text\"><em>Crysis<\/em> (2007). Image courtesy of <a href=\"https:\/\/www.mobygames.com\/game\/windows\/crysis\/screenshots\/gameShotId,339892\/\">MobyGames.com<\/a>.<\/figcaption><\/figure>\n<ul>\n<li>2008: <a href=\"https:\/\/www.qwrt.de\/\"><i>Quake Wars<\/i>:<i> Ray Traced<\/i><\/a> became the first game tech demo to use ray-traced reflections.<\/li>\n<li>2011: <i>Crysis 2<\/i> became the first game to include screen-space reflections, which is a popular technique for reusing screen-space data to calculate reflections.<\/li>\n<li>2016: <i>Rise of the Tomb Raider <\/i>became the first game to use <a href=\"https:\/\/developer.nvidia.com\/vxgi\">voxel-based ambient occlusion<\/a>.<\/li>\n<li>2018: <i>Battlefield V<\/i> became the first commercial game to use ray-traced reflections.<\/li>\n<li>2019: <i>Q2VKPT<\/i> became the first game to implement path tracing, which was later refined in <i>Quake II RTX<\/i>.<\/li>\n<li>2020: <i>Minecraft with RTX <\/i>used path tracing with RTX.<\/li>\n<\/ul>\n<figure id=\"attachment_58744\" aria-describedby=\"caption-attachment-58744\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-10.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Copy-10-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58744\" class=\"wp-caption-text\"><em>Minecraft with RTX.<\/em><\/figcaption><\/figure>\n<h2><b>What\u2019s Next for Lighting in Real-Time Graphics?<\/b><\/h2>\n<p>Real-time graphics are moving toward a more complete simulation of light in scenes with increasing complexity.<\/p>\n<p><a href=\"https:\/\/research.nvidia.com\/sites\/default\/files\/pubs\/2020-07_Spatiotemporal-reservoir-resampling\/ReSTIR.pdf\">ReSTIR<\/a> dramatically expands the possibilities of artists to use multiple lights in games. Its newer variant, <a href=\"https:\/\/d1qx31qr3h6wln.cloudfront.net\/publications\/ReSTIR%20GI.pdf\">ReSTIR GI<\/a>, applies the same ideas toward global illumination, enabling path tracing with more bounces and fewer approximations. It can also render less noisy images faster. And more algorithms are being developed to make path tracing faster and more accessible.<\/p>\n<p>Using a complete simulation of lighting effects with ray tracing also means that the rendered images can contain some noise. Clearing that noise, or \u201cdenoising,\u201d is another area of active research.<\/p>\n<p>More technologies are being developed to help games effectively denoise lighting in complex, highly detailed scenes with lots of motion at real-time frame rates. This challenge is being approached from two ends: advanced sampling algorithms that generate less noise and advanced denoisers that can handle increasingly difficult situations.<\/p>\n<figure id=\"attachment_58747\" aria-describedby=\"caption-attachment-58747\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Last-Two-Before-After.jpg\"><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/blogs.nvidia.com\/wp-content\/uploads\/2022\/08\/Lighting-Explainer-Last-Two-Before-After-672x357.jpg\" alt=\"\" width=\"672\" height=\"357\"><\/p>\n<p><\/a><figcaption id=\"caption-attachment-58747\" class=\"wp-caption-text\">Denoising with NRD in <em>Cyberpunk 2077<\/em>.<\/figcaption><\/figure>\n<p>Check out NVIDIA\u2019s solutions for <a href=\"https:\/\/developer.nvidia.com\/rtx\/ray-tracing\/rtxdi\">direct lighting<\/a> and <a href=\"https:\/\/developer.nvidia.com\/rtx\/ray-tracing\/rtxgi\">indirect lighting<\/a>, and access <a href=\"https:\/\/developer.nvidia.com\/industries\/game-development\">NVIDIA resources for game development<\/a>.<\/p>\n<p>Learn more about graphics with <a href=\"https:\/\/www.nvidia.com\/en-us\/events\/siggraph\/\">NVIDIA at SIGGRAPH \u201822<\/a> and watch the <a href=\"https:\/\/www.addevent.com\/event\/Ex14445230\">NVIDIA\u2019s special address<\/a>, presented by NVIDIA CEO and senior leaders, to hear the latest graphics announcements.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/blogs.nvidia.com\/blog\/2022\/08\/04\/direct-indirect-lighting\/<\/p>\n","protected":false},"author":0,"featured_media":2482,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/2481"}],"collection":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/comments?post=2481"}],"version-history":[{"count":0,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/posts\/2481\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media\/2482"}],"wp:attachment":[{"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/media?parent=2481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/categories?post=2481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salarydistribution.com\/machine-learning\/wp-json\/wp\/v2\/tags?post=2481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}