当前位置:网站首页>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

Wechat applet video sharing platform system graduation design (3) background function

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

MySQL安装与配置

Remember to use ternary expressions when switching transformations

Wechat nucleic acid detection appointment applet system graduation design (2) applet function

Mysql - opérations de base de la base de données

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

Microsoft LDAP 配置页中输入有效的用户名及密码,microsoft ldap 配置页中输入有效的用户名

Steamos 3.3 beta release, steam deck Chinese keyboard finally came
随机推荐
D构造函数问题
MySQL -- basic concept of database
MySQL installation and configuration
Embedded development board ~ description
Web聊天工具
Wechat nucleic acid detection appointment applet system graduation design completion (1) development outline
初夏,开源魔改一个带击杀音效的电蚊拍!
自定义一个loading指令
Web chat tool
Leetcode 面试题 16.15. 珠玑妙算
利用DOSBox运行汇编超详细步骤「建议收藏」
Pychar modify pep8 e501 line too long > 0 characters
Qt Official examples: Qt Quick Controls - Gallery
Typescript
微信小程序视频分享平台系统毕业设计毕设(8)毕业设计论文模板
Chrome 正式支持 MathML,默认在 Chromium Dev 105 中启用
面试,关于线程池的那些事
Win10 uninstall CUDA
Qt官方示例:Qt Quick Controls - Gallery
vimium映射鍵