这篇是自己看shadow map是的一些笔记,内容稍稍凌乱,如有错误请帮忙纠正

1.常见阴影处理方式

2. Shadow Map

参考Shadow Map WikiOpenGl Tutorial 16 : Shadow mappingOpenGL Shadow Mapping

2.1 创建Shadow Map

从光源的视角渲染整个场景,获得Shadow Map。对点光源而言,透视投影的视角应该表现效果的角度相同,聚光灯类似。对于方向光,应该使用平行投影。通过这次渲染,深度缓存数据被保存下来,鉴于只需要深度信息,可以禁止Color Buffer更新以及所有光源、贴图计算来节省时间。

深度数据一般保存在显存中。 深度数据应该随着场景中光源、物体的变动而修改,但有些情况是不需要的,如摄像机变动。如果存在多光源,可以对每个光源保存各自单独的一份。在很多实际应用中,可能只需要对场景中一部分物体进行深度采集。同时,为了解决深度接近被绘制物体表面的情况,可以尝试将深度偏移应用于这次渲染。 有些情况下,可以只渲染物体的背面。

2. 2 渲染场景

从摄像机自身的视角渲染场景,主要包含三个主要部分:

(1) 计算光源视角下物体坐标

为了测试Shadow Map和点的关系,需要将场景中做坐标转换到光源坐标系下,这个过程沟通过矩阵转换( matrix multiplication)获得。物体在屏幕上的坐标是通过做坐标转换获得,但是上面第二步需要光源坐标系下的位置信息。将物体世界坐标转换到光源空间的矩阵类似于渲染管线中的MV矩阵以及投影矩阵。

将世界坐标转换到光源空间坐标的矩阵与第一步中计算shadow map的矩阵相同(计算方式),通过齐次变换、透视除法将物体坐标转换到NDC坐标系,通过映射将[-1,1]空间转换到[0,1]空间,然后保存深度纹理中。上述转换在vertex shader中进行,通过插值传递到pixel shader中。

(2) 对比光源视角的深度数据
获取光源空间下物体的坐标之后,根据x/y即可获得深度纹理中的数据,和Z对比来判断是否为阴影。

  • 如果z大于D(x,y) , 物体是在遮挡物体之后,标记为失败,需要作为阴影来处理
  • 如果(x,y)是在深度纹理范围之外,由程序决定是否将其列入阴影范围(一般默认为在)

在shader实现中,这个判断是在pixel shader中实现。需要注意的是如果深度纹理在硬件中不能进行插值,阴影的变换会出现锯齿。 可以通过修改深度测试方式来实现产生soft edge,比如使用一组数值而不是简单通过一个数值来判断是否失败。

(3) 制物体或者阴影
绘制带有shadow的场景有几种方式。如果在shader中实现, depth map test 可以在pixel shader中进行,并根据其结果绘制物体或者阴影。如果不能再shadow中进行:

  1. Render the entire scene in shadow. For the most common lighting models (see Phong reflection model) this should technically be done using only the ambient component of the light, but this is usually adjusted to also include a dim diffuse light to prevent curved surfaces from appearing flat in shadow.

  2. Enable the depth map test, and render the scene lit. Areas where the depth map test fails will not be overwritten, and remain shadowed.

  3. An additional pass may be used for each additional light, using additive blending to combine their effect with the lights already drawn. (Each of these passes requires an additional previous pass to generate the associated shadow map.)

2.3 Shadow map real-time implementations

Shadow mapping的效果受深度纹理尺寸影响,比较常见的比如锯齿或者阴影边缘不连续等,一般情况下可以简以通过增加 shadow map的尺寸来减少锯齿,但是受限于内存和硬件情况,一般是不可能的。解决这个绕开这个问题的改进技术:Cascaded Shadow MapsTrapezoidal Shadow MapsLight Space Perspective Shadow mapsParallel-Split Shadow maps等。

1. Shadow Acne

Shadow Acne知乎

原因:浮点计算精度以及采样问题(多个点从Depth Texture同一个点获得数据,光线角度越大,越明显)

处理: shadow bias,对物体深度进行稍稍的偏移

2. Peter Panning


原因: shadow bias is too much.
处理:背面剔除(不是太理解)

3. Depth Map Aliasing


原因:
Because the depth map has a fixed resolution the depth frequently spans more than one fragment per texel. As a result multiple fragments sample the same depth value from the depth map and come to the same shadow conclusions, which produces these jagged blocky edges.
处理:
Percentage Closer Filtering
Smoothie
Variance Shadow maps.

3. Techniques to Improve Shadow Map

参考:Common Techniques to Improve Shadow Depth Maps

3.1 Process

3.2 Shadow Map Artifacts

1. Perspective Aliasing

It occurs when the mapping of pixels in view space to texels in the shadow map is not a one-to-one ratio. This is because pixels close to the near plane are closer together and require a higher shadow map resolution.


Perspective shadow maps (PSMs) and light space perspective shadow maps (LSPSMs) attempt to address perspective aliasing by skewing the light's projection matrix in order to place more texels near the eye where they are needed. Cascaded shadow maps (CSMs) are the most popular technique for dealing with perspective aliasing.

2. Projective Aliasing
Projective aliasing occurs when the surface normal is orthogonal to the light; these surfaces should be receiving less light based on diffuse lighting equations.

3. Shadow Acne and Erroneous Self-Shadowing

4. Peter Panning
Peter Panning is aggravated when there is insufficient precision in the depth buffer. Calculating tight near planes and far planes also helps avoid Peter Panning.

3.3 Improve Techniques

1. Slope-Scale Depth Bias

polygons with steep slopes (relative to the light) suffer more from projective aliasing than polygons with shallow slopes (relative to the light). Because of this, each depth map value may need a different offset depending on the polygon's slope relative to the light.

https://www.gamedev.net/topic/662625-slope-scale-depth-bias-shadow-map-in-hlsl/#entry5191604

2. Calculating a Tight Projection

Tightly fitting the light's projection to the view frustum increases the shadow map coverage,results in higher perspective aliasing.

3. Calculating the Near Plane and Far Plane

The more closely together the planes are, the more precise the values in the depth buffer.

  • AABB-Based Near Plane and Far Plane is test.
  • Frustum-Based Near Plane and Far Plane
  • Light Frustum Intersected with Scene to Calculate Near and Far Planes

4. Moving the Light in Texel-Sized Increments

As the camera moves, the pixels along the shadows' edges brighten and darken. This cannot be seen in still images, but it is very noticeable and distracting in real time。

For directional lights, the solution to this problem is to round the minimum/maximum value in X and Y (that make up the orthographic projection bounds) to pixel size increments. This can be done with a divide operation, a floor operation, and a multiply.

参考

OpenGL Shadow Mapping
OpenGl Tutorial 16 : Shadow mapping
Shadow Map Wiki
Shadow Acne知乎
Common Techniques to Improve Shadow Depth Maps
Cascaded Shadow Maps
Percentage Closer Filtering

Unity基础(5) Shadow Map 概述的更多相关文章

  1. Unity基础6 Shadow Map 阴影实现

    这篇实现来的有点墨迹,前前后后折腾零碎的时间折腾了半个月才才实现一个基本的shadow map流程,只能说是对原理理解更深刻一些,但离实际应用估计还需要做很多优化.这篇文章大致分析下shadow ma ...

  2. Shadow Map 原理和改进 【转】

    http://blog.csdn.net/ronintao/article/details/51649664 参考 1.Common Techniques to Improve Shadow Dept ...

  3. Shadow Map阴影贴图技术之探 【转】

    这两天勉勉强强把一个shadowmap的demo做出来了.参考资料多,苦头可不少.Shadow Map技术是目前与Shadow Volume技术并行的传统阴影渲染技术,而且在游戏领域可谓占很大优势.本 ...

  4. GraphicsLab Project之再谈Shadow Map

    作者:i_dovelemon 日期:2019-06-07 主题:Shadow Map(SM), Percentage Closer Filtering(PCF), Variance Shadow Ma ...

  5. Shadow Map -- 点阴影(全方位)

    昨晚终于把点阴影(深度CubeMap)程序调通了,思想不难,基本就是在上节定向光阴影基础上稍作修改,但是CG程序不太方便Debug,需要输出中间效果图进行判断,耽搁了一会儿. 过程如下: 1.将深度渲 ...

  6. Java同步数据结构之Map概述及ConcurrentSkipListMap原理

    引言 前面介绍了CopyOnWriteArraySet,本来接着是打算介绍ConcurrentSkipListSet,无耐ConcurrentSkipListSet的内部实现其实是依赖一个Concur ...

  7. (转)Shadow Map & Shadow Volume

    转自:http://blog.csdn.net/hippig/article/details/7858574 shadow volume 这个术语几乎是随着 DOOM3 的发布而成为FPS 玩家和图形 ...

  8. [ZZ] Shadow Map

    Shadow Map 如何能够高效的产生更接近真实的阴影一直是视频游戏的一个很有挑战的工作,本文介绍目前所为人熟知的两种阴影技术之一的ShadowMap(阴影图)技术.     ShadowMap技术 ...

  9. OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务

    OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务   1.  OpenVAS基础知识 OpenVAS(Open Vulnerability Assessment Sys ...

随机推荐

  1. 解读经典-《C#高级编程》第七版-Chapter1-.Net体系结构-Page13-20

    01 程序集 程序集是包含编译好的.基于.Net Framework的代码逻辑单元.一般来说,在Visual Studio中的一个项目即一个程序集,而一个项目中包含多种不同的代码文件.程序集分为可执行 ...

  2. vmware vcsa-6.5 网络架构之虚拟机的标准交换机

    一.配置虚拟机网络 1.概述(esxi 比workstation,vmware server,网络功能更强大) workstation和vmware server每块物理网卡可以给多个虚拟机使用,多个 ...

  3. golang使用chrome headless获取网页内容

    如今动态渲染的页面越来越多,爬虫们或多或少都需要用到headless browser来渲染待爬取的页面. 而最近广泛使用的headless browser解决方案PhantomJS已经宣布不再继续维护 ...

  4. 基础篇:8.如何定义变量?js变量有什么特点?

    书接上文,废话不多说,直接进入正题,下面我们一起来讨论js中的变量那些事! 那什么是变量? 变量是存储信息的容器,可以存储任何类型的数据. 如何定义变量呢? 变量可以使用短名称,如x,y:也可以是长名 ...

  5. RNN入门(4)利用LSTM实现整数加法运算

      本文将介绍LSTM模型在实现整数加法方面的应用.   我们以0-255之间的整数加法为例,生成的结果在0到510之间.为了能利用深度学习模型模拟整数的加法运算,我们需要将输入的两个加数和输出的结果 ...

  6. c# 接口的协变和逆变

    如果派生类只是用于输出值,那么这种结构化的委托有效性之间的常数关系叫做协变 就是创建一个派生类委托对象 让派生类赋值给基类对象 协变关键字out 对期望传入基类时允许传入派生对象的特性叫逆变  逆变关 ...

  7. [android] 开启新的activity获取他的返回值

    应用场景:打开一个新的activity,在这个activity上获取数据,返回给打开它的界面 短信发送时,可以直接选择系统联系人 界面布局是一个线性布局,里面右侧选择联系人在EditText的右上,因 ...

  8. 洛谷P4577 [FJOI2018]领导集团问题(dp 线段树合并)

    题意 题目链接 Sol 首先不难想到一个dp,设\(f[i][j]\)表示\(i\)的子树内选择的最小值至少为\(j\)的最大个数 转移的时候维护一个后缀\(mx\)然后直接加 因为后缀max是单调不 ...

  9. C#基础(202)--类定义,字段与属性,自动属性,方法及常见错误

    c#类的定义规范 字段与属性的比较: 字段: 字段主要是为类的内部做数据交换交互使用,字段一般是private 字段可以赋值,也可以取值 当字段需要为外部数据提供数据的时候,请将字段封装为属性,而不是 ...

  10. python 标准类库-并行执行之subprocess-子进程管理

    标准类库-并行执行之subprocess-子进程管理 by:授客QQ:1033553122 1.使用subprocess模块 以下函数是调用子进程的推荐方法,所有使用场景它们都能处理.也可用Popen ...