Shadows 阴影

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.3版本
参考链接:https://docs.unity3d.com/Manual/Shadows.html

Unity’s lights can cast Shadows from an object onto other parts of itself or onto other nearby objects. Shadows add a degree of depth and realism to a scene since they bring out the scale and position of objects that can otherwise look “flat”.
Unity的灯光可以将物体的阴影投射到自身的其他部分或者附近的物体上。阴影给场景增加了深度感和真实感,因为它们突出了物体的比例和位置,否则会看起来“单调”。


Scene with objects casting shadows

How do shadows work?

Consider the simplest case of a scene with a single light source. Light rays travel in straight lines from that source and may eventually hit objects in the scene. Once a ray has hit an object, it can’t travel any further to illuminate anything else (ie, it “bounces” off the first object and doesn’t pass through). The shadows cast by the object are simply the areas that are not illuminated because the light couldn’t reach them.
考虑使用单一光源的场景的最简单情况。光线从那个光源以直线传播,最终可能击中场景中的物体。一旦光线击中一个物体,它就不能再移动到更远的地方去照亮其他任何物体(也就是说,它从第一个物体上“反弹”而不穿过)。物体投下的阴影只是因为光线无法到达而没有被照亮的区域。

Another way to look at this is to imagine a camera at the same position as the light. The areas of the scene that are in shadow are precisely those areas that the camera can’t see.
另一种看这个的方法是想象一个相机在与灯光相同的位置。处于阴影中的场景区域正是摄像机无法看到的区域。

A “light’s eye view” of the same scene

In fact, this is exactly how Unity determines the positions of shadows from a light. The light uses the same principle as a camera to “render” the scene internally from its point of view. A depth buffer system, as used by scene cameras, keeps track of the surfaces that are closest to the light; surfaces in a direct line of sight receive illumination but all the others are in shadow. The depth map in this case is known as a Shadow Map (you may find the Wikipedia Page on shadow mapping useful for further information).
事实上,这正是Unity如何决定光的阴影的位置。光线使用与摄像机相同的原理从内部“渲染”场景。场景摄影机使用深度缓冲系统,能追踪离光线最近的表面;直线视野内的物体表面接受光照,但其他物体都处于阴影中。在本例中,深度映射被称为阴影图(Shadow Map)(您可能会发现关于阴影映射的Wikipedia页面对进一步的信息有用)。

The sections below give details on casting shadows from Unity’s Light objects.
下面的部分给出了关于从Unity的光物体投射阴影的细节。

Enabling Shadows 启用阴影

Use the Shadow Type property in the Inspector to enable and define shadows for an individual light.
使用检查器中的阴影类型属性来启用和定义单个灯光的阴影。

Each Mesh Renderer in the Scene also has a Cast Shadows and a Receive Shadows property, which must be enabled as appropriate.
场景中的每个网格渲染器也有一个投射阴影和一个接收阴影属性,这必须在适当的时候启用。

Enable Cast Shadows by selecting On from the drop-down menu to enable or disable shadow casting for the mesh. Alternatively, select Two Sided to allow shadows to be cast by either side of the surface (so backface culling is ignored for shadow casting purposes), or Shadows Only to allow shadows to be cast by an invisible GameObject.
通过从下拉菜单中选择启用或禁用网格的阴影投射来启用投射阴影。或者,选择“双面”,允许阴影从表面的任何一边投射(因此为了投射阴影的目的,背面剔除将被忽略),或者允许由不可见的GameObject(游戏物体)投射阴影。

Shadow mapping and the Bias property 阴影贴图和偏差属性

The shadows for a given Light are determined during the final Scene rendering. When the Scene is rendered to the main Camera view, each pixel position in the view is transformed into the coordinate system of the Light. The distance of a pixel from the Light is then compared to the corresponding pixel in the shadow map. If the pixel is more distant than the shadow map pixel, then it is presumably obscured from the Light by another GameObject and it obtains no illumination.
给定光线的阴影是在最后的场景渲染中确定的。当场景被渲染到主摄像机视图时,视图中的每个像素位置都被转换为光照的坐标系统。然后将一个像素到光照的距离与阴影贴图中的相应像素进行比较。如果像素比阴影贴图像素更远,那么它可能会被另一个游戏物体遮挡而无法获得光照。

Correct shadowing

A surface directly illuminated by a Light sometimes appears to be partly in shadow. This is because pixels that should be exactly at the distance specified in the shadow map are sometimes calculated as being further away (this is a consequence of using shadow filtering, or a low-resolution image for the shadow map). The result is arbitrary patterns of pixels in shadow when they should really be lit, giving a visual effect known as “shadow acne”.
被光直接照射的表面有时会出现部分阴影。这是因为像素应该精确地位于阴影贴图中指定的距离,有时计算为距离更远(这是使用阴影过滤的结果,或者是阴影贴图的低分辨率图像)。其结果是,当它们真正应该被照亮时却呈现像素的任意性,这种视觉效果被称为“阴影粉刺”。

Shadow acne in the form of false self-shadowing artifacts
阴影粉刺的形式的假自阴影

To prevent shadow acne, a Bias value can be added to the distance in the shadow map to ensure that pixels on the borderline definitely pass the comparison as they should, or to ensure that while rendering into the shadow map, GameObjects can be inset a little bit along their normals. These values are set by the Bias and Normal Bias properties in the Light Inspector window when shadows are enabled.
为了防止影子粉刺,偏差值可以添加阴影贴图的距离到绝对确保像素边界通过比较功能,或确保渲染阴影贴图时,GameObjects可以沿着法线插一点值。当启用阴影时,这些值由偏差和法线偏差属性在Light Inspector窗口中设置。

Do not set the Bias value too high, because areas around a shadow near the GameObject casting it are sometimes falsely illuminated. This results in a disconnected shadow, making the GameObject look as if it is flying above the ground.
不要设置过高的偏差值,因为在游戏对象附近投射阴影的区域有时会被错误地照亮。这导致了一个不连贯的阴影,使游戏对象看起来就像在地面上飞行。

A high Bias value makes the shadow appear “disconnected” from the GameObject

Likewise, setting the Normal Bias value too high makes the shadow appear too narrow for the GameObject:
同样,设置过高的法线偏差值会使阴影对于GameObject(游戏物体)显得太窄:

A high Normal Bias value makes the shadow shape too narrow

In some situations, Normal Bias can cause an unwanted effect called “light bleeding”, where light bleeds through from nearby geometry into areas that should be shadowed. A potential solution is to open the GameObject’s Mesh Renderer and change the Cast Shadows property to Two Sided. This can sometimes help, although it can be more resource-instensive and increase performance overhead when rendering the Scene.
在某些情况下,法线偏差会导致一种不受欢迎的效应,称为“光照渗出”,即光线从几何图形附近中渗出,进入应该被遮挡的区域。一个潜在的解决方案是打开GameObject的网格渲染器,并将Cast Shadows属性更改为双面。这有时是有帮助的,尽管它占用更多资源,并在渲染场景时增加性能开销。

The bias values for a Light may need tweaking to make sure that unwanted effects occur. It is generally easier to gauge the right value by eye rather than attempting to calculate it.
灯光的偏差值可能需要调整,以确保产生不需要的效果。一般来说,用眼睛测量正确的值比试图计算它更容易。

To further prevent shadow acne we are using a technique known as Shadow pancaking (see Directional light shadows: Shadow pancaking). This generally works well, but can create visual artifacts for very large triangles.
为了进一步预防粉刺,我们使用了一种被称为“阴影平坠”的技术(参见方向光影:阴影平坠)。这通常工作得很好,但是可以为非常大的三角形创建可视化人为调整。

A low Shadow near plane offset value create the appearance of holes in shadows
一个低的近平面偏移值会在阴影中产生孔洞

Tweak the Shadow Near Plane Offset property to troubleshoot this problem. Setting this value too high introduces shadow acne.
调整阴影近平面偏移属性,以排除这个问题。设置这个值过高会导致粉刺。

Correct shadowing

Shadows 阴影 光照系列8相关推荐

  1. Types of light 光照类型 光照系列4

    Types of light 光源类型 本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>) 仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处. 文章中涉及到的 ...

  2. Lighting Window 光照设置界面 光照系列2

    Lighting Window 光照设置界面 本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>) 仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处. 文章中涉 ...

  3. Cookies 剪影 光照系列7

    Cookies 剪影 本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>) 仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处. 文章中涉及到的操作都是基于Uni ...

  4. three.js学习笔记(五)——Shadows阴影

    阴影一直是实时三维渲染的挑战,开发人员必须在合理的情况下找到显示真实阴影的技巧. Three.js 有一个内置的解决方案,虽然其并不完美,但用起来很方便. 阴影是怎么工作的? 当你进行一次渲染时,Th ...

  5. OpenGL学习: 光照系列3-光源类型和使用多个光源

    写在前面  上一节光照中使用材质和lighting maps介绍了使用材质属性和lighting maps使物体的光照效果能反映物体的材料特性,看起来更逼真.在前面的章节中使用的实际上都是一个点光源, ...

  6. The simplest way to get started with Stable Diffusion on Ubuntu

    link1 link2 Stable Diffusion is a machine learning model that can generate images from natural langu ...

  7. 阴影Shadows(笔记)

    文章目录 前言 ∞.阴影(Shadows) 阴影映射(Shadows Mapping) 阴影映射的实现步骤 阴影映射的问题 课程的最后 前言 讲一下之前没讲的阴影(Shadows) ∞.阴影(Shad ...

  8. 【GPU精粹与Shader编程】(一) 全系列核心知识点总览

    系列文章前言 <GPU Gems>1~3 .<GPU Pro>1~7 以及<GEM Zen>组成的GPU精粹系列书籍,是游戏开发.计算机图形学和渲染领域的业界大牛们 ...

  9. 【GPU精粹与Shader编程】(一) 开篇 全系列11本书核心知识点总览

    本文由@浅墨_毛星云 出品,首发于知乎专栏,转载请注明出处   文章链接: https://zhuanlan.zhihu.com/p/34917895 系列文章前言 <GPU Gems>1 ...

最新文章

  1. databricks使用
  2. Android第二十五期 - 猜歌小游戏
  3. 求根节点到叶节点数字之和Python解法
  4. CMOS图像传感器——SmartSens
  5. Oracle v$session/v$sql 表
  6. asterisk php agi,asterisk AMI入门
  7. 北京地铁挤,最挤昌平线
  8. oracle jde优势介绍,JDE 的扫盲知识介绍。。。
  9. 蝗虫优化算法(GOA)优化深度置信网络DBN【matlab源码】
  10. Android APP微信第三方登录踩坑 - 微信开放平台修改应用包名后微信第三方登录失败
  11. Kaggle 入门 Crime
  12. iOS开发之制作越狱ios设备ipa包
  13. Python 学生管理系统+mysql+Flask
  14. java古诗词打印_java古诗词自动生成程序.doc
  15. c语言改错题字符串a放在b后面,C语言程序改错题汇总.doc
  16. 论语 季氏篇(笔记)
  17. 碎片化学习Java(十六)Java for得出年份生肖
  18. 旅游指南之五----途登山装备清单
  19. Go语言中的包你知道吗
  20. matlab2021b软件下载+crack

热门文章

  1. 详解加法与减法对CPU标志位的影响
  2. GitHub上收集的最全的前端资源汇总(包括前端学习、求职、开发资源)
  3. Map比较containsKey()
  4. 用python从日期中获取年、月、日、星期等30种信息
  5. 计算机主机与显示屏如何接线,电脑怎么一次连接显示器和电视
  6. python之逗号的用法
  7. 去掉Warning: Using a password on the command line interface can be insecure.
  8. Ubuntu22.04 USB转串口驱动
  9. [IOS APP]从唐诗到元曲-蒋勋说中国文学
  10. 智能优化算法-蚁狮优化器Ant Lion Optimizer(附Matlab代码)