当前位置:网站首页>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 .
边栏推荐
- MySQL advanced - transaction and index
- Steamos 3.3 beta release, steam deck Chinese keyboard finally came
- Qt官方示例:Qt Quick Controls - Gallery
- 自定义一个loading指令
- Unified interface for reading and writing data files in xml/json/ini and ubjson formats
- MySQL -- basic operation of database
- Architecture design - ID generator "suggestions collection"
- Wechat applet video sharing platform system graduation design completion (4) opening report
- Detailed explanation of map set
- NM02-独立于总线协议的NM模块调用序列图及代码解释
猜你喜欢
Wechat applet video sharing platform system graduation design (2) applet function
Leetcode 面试题 16.15. 珠玑妙算
Détends - toi encore! Ces nouveaux étudiants peuvent s'installer directement à Shanghai
【西北工业大学】考研初试复试资料分享
Finally detailed explanation
How to download wechat payment certificate (API certificate)
微信小程序视频分享平台系统毕业设计毕设(6)开题答辩PPT
微信核酸检测预约小程序系统毕业设计毕设(3)后台功能
微信小程序视频分享平台系统毕业设计毕设(8)毕业设计论文模板
微信核酸检测预约小程序系统毕业设计毕设(4)开题报告
随机推荐
Wechat applet video sharing platform system graduation design completion (5) assignment
NM02-独立于总线协议的NM模块调用序列图及代码解释
【Golang | gRPC】使用gRPC实现简单远程调用
能解决80%故障的排查思路
Please, stop painting star! This has nothing to do with patriotism!
NVIDIA graphics card failed to initialize nvml driver/library version mismatch error solution
【Golang | gRPC】使用openssl生成证书
详解Kubernetes网络模型
MySQL advanced - transaction and index
好评率计算
Typescript
Detailed explanation of map set
No such file or directory: ‘/tmp/tmpxxx/tmpxxx. py‘
Aloam code reading and summary
微信小程序视频分享平台系统毕业设计毕设(2)小程序功能
拿起相机,便是最好的艺术疗愈
Wechat applet video sharing platform system graduation design completion (8) graduation design thesis template
Leetcode 面试题 17.04. 消失的数字
切换变换的时候记得使用三元表达式
微信小程序视频分享平台系统毕业设计毕设(5)任务书