当前位置:网站首页>Shadowcaster shadowmask map of 0 basic unityurp rendering pipeline is indistinct (code direction)
Shadowcaster shadowmask map of 0 basic unityurp rendering pipeline is indistinct (code direction)
2022-04-22 22:38:00 【avi9111】
This is not to say that graphics theory , Is not to say that URP The difference between this branch ( in addition 2 Branches :built-in,HDRP), Finally, I want to talk about custom programming pipeline ( Custom becomes equivalent to , Implement a whole rendering engine ), Then I'll say , But now is not the time to say custom programming
In fact, the following is still HLSL Programming ,Shader Code ( Just put on a URP Skin of formwork )
Catalog
Various names , The concept is confused
actual combat Shader shadow ” Magic reform “....??
Unity Of ShadowMask principle
Many new to graphics rendering Renderer, In particular, the entry tool is Unity Classmate ,
It's easy to confuse all kinds of Shadow Concept ;
The first time I saw such code :Pass{ “ShadowCaster", It's preconceived that this is rendering Shadow Code for
The basic principle of projection is
1. The light source
2. Occluder ( Projection source )
3. Shadow painting (Object Render)

Actually ShadowCaster Pass, Is the projection source ( Mainly to tell the engine , How to locate , The granularity of shadows , Whether to offset , Then the engine will bake the corresponding shadow map at some time ); The shadow drawing and color drawing are the same , It's all in ForwardPass( perhaps DefferPass, This next article will talk about )
void InitializeInputData(Varyings input, half3 normalTS, out InputData inputData)
{
//...........
inputData.shadowMask = SAMPLE_SHADOWMASK(input.lightmapUV);
Because the code above , We know ,.shadowMask Store in inputData
therefore ,
half4 UniversalFragmentPBR(InputData inputData, SurfaceData surfaceData)
{
//.......
// To ensure backward compatibility we have to avoid using shadowMask input, as it is not present in older shaders
#if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON)
half4 shadowMask = inputData.shadowMask;
#elif !defined (LIGHTMAP_ON)
half4 shadowMask = unity_ProbesOcclusion;
#else
half4 shadowMask = half4(1, 1, 1, 1);
#endif
Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, shadowMask);
From this code , We know shadowMask It's actually mixed with the main light ( Parallel light ) Calculated together , In fact, light ==1, shadow ==0, light ++, shadow --; It's not that hard to understand
however , Doesn't a point light need shadows ?
#ifdef _ADDITIONAL_LIGHTS
uint pixelLightCount = GetAdditionalLightsCount();
for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)
{
Light light = GetAdditionalLight(lightIndex, inputData.positionWS, shadowMask);
Because of this code , We also know , The shadow of a point light source is the same as that of a moving light
// Parallel light ( Other tools have similar names :Main Lit, The main light source , Direct light sources )
light.shadowAttenuation = MainLightShadow(shadowCoord, positionWS, shadowMask, _MainLightOcclusionProbes);
// Point source , Spotlights ( Other tools have similar names :Other Lit, Auxiliary light , Indirect light sources )
light.shadowAttenuation = AdditionalLightShadow(perObjectLightIndex, positionWS, shadowMask, occlusionProbeChannels);
Let's look at another piece of code :
#ifdef CALCULATE_BAKED_SHADOWS
half bakedShadow = BakedShadow(shadowMask, occlusionProbeChannels);
#else
half bakedShadow = 1.0h;
#endif
So we know shadowMask Only again Baked It works in mode , By the way, I also know the keywords to be given :occlusionProbeChannels
Various names , The concept is confused
< make a concrete analysis , Then add >
The conclusion is the conclusion of the previous article :
Better believe than have no book
In fact, there are not so many profound reasons
Master the theory of the world ( In fact, it is impossible to master all ), It's not as good as a sentence of code
actual combat Shader shadow ” Magic reform “....??
1. No shadow
According to the code of the previous article ( Realize point light source and spotlight ), A shadow ??

At first I thought , It's this question

It turned out , Or code ( official ) setting
#if !defined(ADDITIONAL_LIGHT_CALCULATE_SHADOWS)
return 1.0h;
#endif
< Because I've been cheated by the authorities many times , So it's not a waste of time , Just look at the code , Can find a solution from the code >
2. There is a shadow

// The official recommended way to open macros ,_ADDITIONAL_LIGHT_SHADOWS_CASCADE I don't know what the effect is
//#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
//#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
//#define _ADDITIONAL_LIGHT_SHADOWS_CASCADE
//#define _ADDITIONAL_LIGHT_SHADOWS;
// Visual measurement ,_ADDITIONAL_LIGHT_SHADOWS opened , It will ADDITIONAL_LIGHT_CALCULATE_SHADOWS open
// So just ADDITIONAL_LIGHT_CALCULATE_SHADOWS That's it ,_ADDITIONAL_LIGHT_SHADOWS_CASCADE The temporary effect is unknown
#define ADDITIONAL_LIGHT_CALCULATE_SHADOWS 0;
// Test whether the macro is open , Need someone to pay IDE Support
#if !defined(ADDITIONAL_LIGHT_CALCULATE_SHADOWS)
abc = 1 //ADDITIONAL_LIGHT_CALCULATE_SHADOWS Defined , So even if this line of error is incomplete code , No errors reported
#endif
//Light light = GetAdditionalLight(lightIndex, positionWS);
float4 shadowMask = SAMPLE_SHADOWMASK(i.uv.zw);//lightmapUV
Light light = GetAdditionalLight(lightIndex,positionWS,shadowMask);
// Now this light The structure will carry shadow information
3. The shadow is gone again
Let's change it , period ( What we want ?)


4. EH , Have a

< Last , You still find that the character's video doesn't >
here , The difference between shadow and no shadow is : Whether static objects are checked , whether MeshRenderer

However SkinnedMeshRenderer There is no such option ,《Unity2020》
Reference resources
Unity Real time shadow implementation ——Shadow Mapping - You know
Shadowmask vs DistanceShadowmask - Unity Forum
How to be in unity Of URP Under the shadow _ Huang Lang's blog -CSDN Blog _unity urp shadow
Unity SRP To make things ( Four ) shadow - You know

版权声明
本文为[avi9111]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204222146082307.html
边栏推荐
- repeat_map mp.find() + mp.erase()
- Svg series - 3, powerful path
- [*CTF2022]oh_ my_ lotto_ revenge
- Characteristics of Vickers Vickers proportional valve
- Typical application scenarios of alicloud log service SLS
- 阿里云日志服务sls的典型应用场景
- How to make a successful open source project
- Redux devtools installation
- JS intercept file suffix
- Reference policy example explanation
猜你喜欢

Transport layer - overview of transport layer (1)
![[untitled]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[untitled]

对象大小与指针压缩--JVM

人称小HomeKit的智汀,如何连接天猫精灵音箱?

Vulnerability utilization in 2021: 95% of traditional vulnerabilities have been disclosed

What is the working nature of Italian ATOS solenoid valve?
![[*CTF2022]oh_ my_ lotto_ revenge](/img/48/d67ef80f95363e69552b1d6573eb16.png)
[*CTF2022]oh_ my_ lotto_ revenge

Is it necessary to read the history of mathematics? We have neglected too much about mathematics education

Mathematics - Bezier curve
![[intranet penetration] - vulnstack (I)](/img/d4/b7267b8306b353ea6a8ac22d64f9f6.png)
[intranet penetration] - vulnstack (I)
随机推荐
Preprocessing is the process of a program
MySql--数据库基础
396. 旋转函数 / 剑指 Offer II 013. 二维子矩阵的和
100 billion level im independent development guide! Global instant messaging full set of codes 4 hours quick (II)
不能再简单的意向锁
企业应如何制定云计算使用中的灾难恢复计划?
初学单片机点亮第一个外设--LED灯
优化点
kubeflow创建新用户用户密码
Vulnerability utilization in 2021: 95% of traditional vulnerabilities have been disclosed
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
Reference policy example explanation
Want to day browser: recommend several easy-to-use desktop browsers
SSM框架
MySql--库的操作
报名开启|QKE 容器引擎托管版暨容器生态发布会!
TS classic type gymnastics: how to turn the joint type into the cross type? We need to know three points: distribution law, inversion position, inversion and covariance
2.60-假设我们将一个w位的字中的字节从0(最低位)到w/8- 1(最高位)编号。写出下面C函数的代码,它会返回一个无符号值,其中参数x的字节i被替换成字节b。
Metawork: please, this remote pairing programming is cool!