当前位置:网站首页>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 .
边栏推荐
- Iframe nesting details
- 微信小程序视频分享平台系统毕业设计毕设(2)小程序功能
- Qt官方示例:Qt Quick Controls - Gallery
- Wechat applet video sharing platform system graduation design completion (4) opening report
- 567. Arrangement in string
- Vimium mapping key
- 719. Find the distance of the number pair with the smallest K
- Embedded development board ~ description
- RDK simulation experiment
- WPS inserts a picture and displays it completely
猜你喜欢

Embedded ~ introduction

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

ESP32-C3入门教程 问题篇⑩——error: implicit declaration of function ‘esp_blufi_close‘;

NM01-独立于总线协议的NM模块功能概述与API定义

Wechat applet video sharing platform system graduation design completion (5) assignment

Wechat applet video sharing platform system graduation design completion (1) development outline

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

微信小程序视频分享平台系统毕业设计毕设(6)开题答辩PPT

Détends - toi encore! Ces nouveaux étudiants peuvent s'installer directement à Shanghai

微信小程序视频分享平台系统毕业设计毕设(2)小程序功能
随机推荐
Freemaker+poi realizes dynamic generation and parsing of Excel files
面试,关于线程池的那些事
微信小程序视频分享平台系统毕业设计毕设(6)开题答辩PPT
pycharm 修改 pep8 E501 line too long > 0 characters
MySQL --- 數據庫的基本操作
Please, stop painting star! This has nothing to do with patriotism!
Wechat applet video sharing platform system graduation design completion (6) opening defense ppt
MySQL安装与配置
读写 XML/JSON/INI 和 UBJSON 等格式的数据文件的统一接口
Aloam code reading and summary
1288_ Implementation analysis of vtask resume() interface and interrupt Security version interface in FreeRTOS
MySQL --- 数据库的基本概念
win10 kms activator
再放寬!這些應届生,可直接落戶上海
Aptos tutorial - participate in the official incentive testing network (ait2 incentive testing network)
RDK仿真实验
MySQL installation and configuration
matplotlib的安装教程以及简单调用
Export Excel files using npoi
How can you omit a large number of switch statements