Unity基础(5) Shadow Map 概述
这篇是自己看shadow map是的一些笔记,内容稍稍凌乱,如有错误请帮忙纠正
1.常见阴影处理方式
- Shadow Map : using Z-Buffer
Shadow Mapping 的原理与实践 - Shadow Volume : using stecil Z-Buffer
Shadow Volume Wiki
2. Shadow Map
参考Shadow Map Wiki、OpenGl Tutorial 16 : Shadow mapping、OpenGL 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中进行:
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.
Enable the depth map test, and render the scene lit. Areas where the depth map test fails will not be overwritten, and remain shadowed.
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 Maps、Trapezoidal Shadow Maps 、Light Space Perspective Shadow maps、 Parallel-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 概述的更多相关文章
- Unity基础6 Shadow Map 阴影实现
这篇实现来的有点墨迹,前前后后折腾零碎的时间折腾了半个月才才实现一个基本的shadow map流程,只能说是对原理理解更深刻一些,但离实际应用估计还需要做很多优化.这篇文章大致分析下shadow ma ...
- Shadow Map 原理和改进 【转】
http://blog.csdn.net/ronintao/article/details/51649664 参考 1.Common Techniques to Improve Shadow Dept ...
- Shadow Map阴影贴图技术之探 【转】
这两天勉勉强强把一个shadowmap的demo做出来了.参考资料多,苦头可不少.Shadow Map技术是目前与Shadow Volume技术并行的传统阴影渲染技术,而且在游戏领域可谓占很大优势.本 ...
- GraphicsLab Project之再谈Shadow Map
作者:i_dovelemon 日期:2019-06-07 主题:Shadow Map(SM), Percentage Closer Filtering(PCF), Variance Shadow Ma ...
- Shadow Map -- 点阴影(全方位)
昨晚终于把点阴影(深度CubeMap)程序调通了,思想不难,基本就是在上节定向光阴影基础上稍作修改,但是CG程序不太方便Debug,需要输出中间效果图进行判断,耽搁了一会儿. 过程如下: 1.将深度渲 ...
- Java同步数据结构之Map概述及ConcurrentSkipListMap原理
引言 前面介绍了CopyOnWriteArraySet,本来接着是打算介绍ConcurrentSkipListSet,无耐ConcurrentSkipListSet的内部实现其实是依赖一个Concur ...
- (转)Shadow Map & Shadow Volume
转自:http://blog.csdn.net/hippig/article/details/7858574 shadow volume 这个术语几乎是随着 DOOM3 的发布而成为FPS 玩家和图形 ...
- [ZZ] Shadow Map
Shadow Map 如何能够高效的产生更接近真实的阴影一直是视频游戏的一个很有挑战的工作,本文介绍目前所为人熟知的两种阴影技术之一的ShadowMap(阴影图)技术. ShadowMap技术 ...
- OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务
OpenVAS漏洞扫描基础教程之OpenVAS概述及安装及配置OpenVAS服务 1. OpenVAS基础知识 OpenVAS(Open Vulnerability Assessment Sys ...
随机推荐
- [转]Angular4 数据请求 POST、GET
本文转自:https://blog.csdn.net/dailuwen/article/details/79375980 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...
- 【转载】阿里云Windows服务器快速部署PHP运行环境
PHP也是一种常用的网站脚本语言,时常用于网站应用程序的编写,PHP运行环境包含几个要素:PHP.Apache服务器.MySql数据库,此3个要素是Php网站运行的必要条件.在阿里云的Windows服 ...
- 应用TortoiseGit为github账号添加SSH keys,解决pull总是提示输入密码的问题
每次同步或者上传代码到githun上的代码库时,需要每次都输入用户名和密码,这时我们设置一下SSH key就可以省去这些麻烦了.若果使用TortoiseGit作为github本地管理工具,Tortoi ...
- sqlserver 操作数据表语句模板
从网上搜的,一点一点加吧. -----------设置事务全部回滚----------------- SET XACT_ABORT ON BEGIN BEGIN TRY BEGIN TRANSACTI ...
- VB.NET 使用ADODB連接資料庫滙出到EXCEL
'導入命名空間 Imports ADODB Imports Microsoft.Office.Interop Private Sub A1() Dim Sql As StringDim Cnn As ...
- Netty实战四之传输
流经网络的数据总是具有相同的类型:字节(网络传输——一个帮助我们抽象底层数据传输机制的概念) Netty为它所有的传输实现提供了一个通用的API,即我们可以将时间花在其他更有成效的事情上. 我们将通过 ...
- Reactor模式理解
Reactor模式 也可以叫反应器模式或者应答者模式 reactor模式简介 让我们先了解一下阻塞I/O与非阻塞I/O I/O 是非常缓慢的 I/O绝对是计算机操作中最慢的.访问RAM的事件为ns级别 ...
- Python3 系列之 基础语法篇
基础数据类型 整数 python 可以处理任意大小的整数 浮点数 python 可以处理任意大小的浮点数,但是需要注意的一点是:整数运算永远是精确的(除法也是精确的),而浮点数运算则可能会有四舍五入的 ...
- javascript 里面 with 关键字
1.with的基本概念 with语句的作用是将代码的作用域设置到一个特定的作用域中,目的是为了简化多次编写访问同一对象的工作.基本语法如下: with (expression) statement 下 ...
- blfs(systemd版本)学习笔记-构建google-chrome浏览器
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 一.google-chrome浏览器官网下载地址 我只找到了deb包和rpm包的下载地址 1.https://dl.google ...