当前位置:网站首页>Implementation shadow introduction
Implementation shadow introduction
2022-07-02 18:23:00 【Jelly Xizhilang】
Plane shadow
According to the direction of light , Project each vertex of the object onto the plane ground . On .、
Principles of Mathematics : Similar triangles
shortcoming : It can only be projected to the plane , The projected object must be between the light and the plane 
Shadow casting
Set one for each shadow projector A camera , Render shadow shadows into shadow textures , Render shadow receiver , And blend with shadow texture

stay Unity To realize :
Projector Components : Its parameters can be set to generate a visual vertebral body ,Projector Will use the material provided to it , Draw all the objects in its visual vertebra , Use Render Texture Generate shadow maps , Paint the shadow shadow volume to the shadow texture , to Project Sets the material for blending objects and shadow maps

Shadow mapping


No depth map on the right , Record the depth value of each pixel , The darker the color, the closer it is to the camera , The white area represents the sky box .

The core idea of shadow mapping : Pixels in the shadow are not visible , That is to say, the depth value of the pixel in the shadow is greater than the depth value of the pixel in the shadow map .
technological process : First, generate shadow mapping from the perspective of care , Then generate the whole scene object from the camera's perspective , After converting the camera coordinate system to the shadow mapping coordinate system , Guessing the depth of two textures is , If the pixel depth value in the camera perspective is greater than the pixel depth value in the shadow map , Then the pixel belongs to shadow .
Unity Screen space shadow mapping in
1. Render the depth map of screen space ;
2. Render shadow mapping from the direction of the light source ;
3. Do a shadow collection calculation in screen space (Shadows Collector), This calculation will get a - Screen space shadow texture ;
4. When drawing objects , Use the screen coordinates of the object uv, sampling 3 Screen space shadow map generated in .

Optimization of shadow mapping
Self shadowing problem
Due to the limited resolution of shadow mapping , Discrete sampling points and values . The deviation on may cause incorrect self shadowing , Also known as Z- Fighting Or Shadow Pink (Surface Acne)
When comparing depth , To avoid surface self shadowing , The fault tolerance threshold needs to be set
● Depth migration (Depth Bias)
● Normal offset (Normal Bias)
But when the depth offset is set too large , Will cause light leakage . That is, there is a disconnection between the shadow and the projector , It's also called Peter Panning problem .



Depth migration : Increasing the depth offset brings the pixel closer to the light source ;
Normal offset : Offset outward in the direction of the surface normal ;
The offset unit is the texture element of shadow mapping ;
stay Shadow Receive The calculation phase , Pixel by pixel ;
Only use in shadow depth test , Will not affect the real scene .
Unity Offset optimization in
Do offset in lift Wenli stage , Let the shelter reverse offset , That is, subtract the offset , That's better performance


Aliasing problem
Look at shadow mapping in the process of signal reconstruction :
● Initial sampling : Render shadow mapping ;
● Resampling : Sample the signal from the perspective of the camera ( Shadow mapping ) Resampling .
Perspective aliasing
● Shadow mapping is evenly distributed in world space .
● After the object in the visual cone passes through the perspective projection , Near and far away , The pixels in the near plane and the far plane are the same ;
● There are significantly fewer sampling points for elements close to the observer .
Solution : Cascade shadow mapping
Divide the visual cone into several sub visual cones ; Calculate independent shadow maps of equal size for each sub view cone ;

Resampling error
Shadow mapping is a dynamically generated texture ; wave filtering —— Solution of texture sampling error
wave filtering
● Image processing , Filter to emphasize some features or remove some unnecessary parts of the image ;
● Filtering is a neighborhood operator , The final output value of a given pixel is determined by the value of the pixel around the pixel .
Shadow filtering
● Use a portion of the shadow map sample points to calculate a specified value View The method of sampling the final shadow result of the point .
PCF wave filtering
1. Generate shadow mapping from light direction ;
2. from view Perspective rendering scene , Use shadow mapping for depth testing ;
3. When the coloring point passes the depth test , Take the specified size around the pixel ( Filter core ) The scope of the . Calculate their visible average as output .

PCF Different implementations of filtering
Number of samples K
● Regular filtering ,3*3 or 5*5;
● use Poisson Disk To distribute a certain number of sampling points .
Filter kernel function
● Gaussian function as filter function .
Unity Shadow mapping optimization summary
● Use depth offset and normal offset to solve the problem of self shadow ;
● Use cascaded shadow mapping to solve the problem of perspective projection ;
● Use PCF Solve the problem of resampling , And produce the effect of soft shadow .
边栏推荐
- Steamos 3.3 beta release, steam deck Chinese keyboard finally came
- paddlepaddle 28 搭建基于卷积的自动编码机
- Wechat nucleic acid detection and appointment applet system graduation design (3) background function
- Wechat nucleic acid detection appointment applet system graduation design completion (4) opening report
- wait_ for_ Gap -- restore archive from primary archive to secondary Archive
- Three methods of MySQL backup
- MySQL进阶-事务及索引
- Graduation summary
- vi/vim 删除:一行, 一个字符, 单词, 每行第一个字符 命令
- Remember to use ternary expressions when switching transformations
猜你喜欢

微信小程序视频分享平台系统毕业设计毕设(2)小程序功能

Intelligent hydropower meter energy consumption monitoring cloud platform

微信小程序视频分享平台系统毕业设计毕设(5)任务书

Use Zadig to build a continuous delivery platform from 0 to 1

Explain kubernetes network model in detail

微信核酸检测预约小程序系统毕业设计毕设(5)任务书

Wechat applet video sharing platform system graduation design completion (8) graduation design thesis template

Detailed explanation of map set

【愚公系列】2022年07月 Go教学课程 001-Go语言前提简介

MySQL进阶-事务及索引
随机推荐
2020互联网行业术语
RDK simulation experiment
vimium映射键
【西北工业大学】考研初试复试资料分享
Web chat tool
MySQL安装与配置
Picking up the camera is the best artistic healing
拿起相机,便是最好的艺术疗愈
Deep understanding of ThreadLocal
切换变换的时候记得使用三元表达式
Qt官方示例:Qt Quick Controls - Gallery
Aptos tutorial - participate in the official incentive testing network (ait2 incentive testing network)
Design of the multi live architecture in different places of the king glory mall
SteamOS 3.3 Beta 发布,Steam Deck 中文键盘终于来了
A4988 and 42 stepper motors
Embedded development board ~ description
Steamos 3.3 beta release, steam deck Chinese keyboard finally came
Web聊天工具
使用NPOI导出Excel文件
Aptos教程-参与官方激励测试网(AIT2 激励测试网)