当前位置:网站首页>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 .
边栏推荐
- 1288_ Implementation analysis of vtask resume() interface and interrupt Security version interface in FreeRTOS
- Another double non reform exam 408, will it be cold? Software College of Nanchang Aviation University
- 微信小程序视频分享平台系统毕业设计毕设(8)毕业设计论文模板
- Customize a loading instruction
- Enter a valid user name and password in the Microsoft LDAP configuration page, and enter a valid user name in the Microsoft LDAP configuration page
- Leetcode 面试题 16.11. 跳水板
- 再放宽!这些应届生,可直接落户上海
- Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名
- Nvidia 显卡 Failed to initialize NVML Driver/library version mismatch 错误解决方案
- Finally detailed explanation
猜你喜欢

【西北工业大学】考研初试复试资料分享

巴比特 | 元宇宙每日必读:一千块就能买一个虚拟主播?这是小企业的直播福音还是在“割韭菜”?...

Leetcode 面试题 16.11. 跳水板

拿起相机,便是最好的艺术疗愈

再放寬!這些應届生,可直接落戶上海

Leetcode 面试题 16.15. 珠玑妙算

Please, stop painting star! This has nothing to do with patriotism!

又一所双非改考408,会爆冷么?南昌航空大学软件学院

MySQL --- 数据库的基本概念

How to download wechat payment certificate (API certificate)
随机推荐
RTE11- 中断解耦功能
MySQL --- 数据库的基本操作
MySQL --- 數據庫的基本操作
Leetcode 面试题 17.04. 消失的数字
Aptos教程-参与官方激励测试网(AIT2 激励测试网)
Editor Editor Extension add button and logo in scene view
Wechat applet video sharing platform system graduation design (2) applet function
Three methods of MySQL backup
win10 kms activator
Babbitt | metauniverse daily must read: can you buy a virtual anchor for 1000 yuan? Is this the live gospel of small businesses or "cutting leeks"
Leetcode 面试题 16.17. 连续数列
怎么可以省去大量的switch语句,省去switch语句
In Linux, MySQL sets the job task to start automatically
719. Find the distance of the number pair with the smallest K
Explain kubernetes network model in detail
微信小程序视频分享平台系统毕业设计毕设(6)开题答辩PPT
Editor编辑器扩展在Scene View添加按钮和logo
Unified interface for reading and writing data files in xml/json/ini and ubjson formats
Wasserstein slim gain with clipping penalty (wsgain-cp) introduction and code implementation -- missing data filling based on generating countermeasure network
【Golang | gRPC】使用openssl生成证书