In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use screen space in unity3d to improve shadowmap light leakage, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.
Antecedent
Since the development of real-time shadow into the era of shadowmap, light leakage and Shadow Acne have been inseparable. This common problem will not be solved unless you can greatly improve shadowmap accuracy or achieve real-time shadows over very short distances. The figure below is as follows
The light leaks when bias is turned up, and the self-shadow error occurs when bias is adjusted low.
Dynamic bias scheme
The boss of the director asked me this question when I was interviewing in NetEase's engine department in my early years. I was very proud to tell him that I created and realized the practice of demo, calculating shadowmap not only writes the depth but also writes the world normal of the projection surface (or the SV_PrimitiveID of the projection surface), so that when you draw shadows, you can judge whether you project yourself according to whether the world normal of your surface is close to the projection surface. If the calculation of bias is larger, otherwise it is smaller. Because since bias doesn't work with fixed values, implement dynamic bias, which is logically true. Boss calmly said that the accuracy of shadowmap itself is not enough for you to improve the data of the same size too much. (the actual test really didn't improve much.) he then asked cautiously: can't you do something in the screen space? At that time, in addition to the implementation of ssao imitation, I did not have the flexibility to master a variety of other SS skills and had no experience, so I could not answer. But I could see that his caution seemed to reveal the practice if he asked again, so I was impressed to write it down: it might be easy to figure out and try it when you have time. Now is the right time.
Improvement of light leakage in screen space
I think that a pixel in the screen space can be checked according to the depth map to see if there is an occlusion in a short distance in the direction of the light, and if so, there should be shadows. So I chose to increase the bias, such as the left picture above, and then try to find a way to make up for the missing light. Do not choose from the shadow error and then remove the shadow because the projector is not necessarily nearby, so you can't simply remove the shadow. But if there is a projection in the leak, it must be nearby, so it's easier to query. First look, the effect is very good.
The optimized screen space is better than the best combination of two bias.
Such a large amount of code to improve the amount of only 6 sentences of sampling is also the existing depth map performance is basically no problem. The code is directly described in detail. The simple test function is written in LightingMyStandard_GI, and the shader can be calculated according to the screen shadow of the actual project, as long as the world coordinates can be obtained anywhere.
Void LightingMyStandard_GI (SurfaceOutputStandard s, UnityGIInput data,inout UnityGI gi) {/ / the current position moves 0.1m to the light direction to locate the virtual projection to see if there is a real object there. If there is an object there, float4 casterWpos = float4 (data.worldPos + data.light.dir * 0.1fpen1); / / go to the cropping space float4 casterNdc = mul (UNITY_MATRIX_VP, casterWpos) / / go to the ndc space casterNdc / = casterNdc.w; / / go to the sampling coordinates to see the actual screen depth here float2 samplePos = casterNdc.xy * 0.5 + 0.5; / / get the actual depth of the virtual projection position float depth = SAMPLE_DEPTH_TEXTURE (_ CameraDepthTexture, samplePos) / / if the virtual projection is obscured, even if the shadow is black / / the actual project had better go to Linear01Depth (depth) * _ ProjectionParams.z within the real distance and effective range before occlusion if (depth > casterNdc.z) data.atten = 0 / / the following is the original content of the function # if defined (UNITY_PASS_DEFERRED) & & UNITY_ENABLE_REFLECTION_BUFFERS gi = UnityGlobalIllumination (data, s.Occlusion, s.Normal); # else Unity_GlossyEnvironmentData g = UnityGlossyEnvironmentSetup (s.Smoothness, data.worldViewDir, s.Normal, lerp (unity_ColorSpaceDielectricSpec.rgb, s.Albedo, s.Metallic)) Gi = UnityGlobalIllumination (data, s.Occlusion, s.Normal, g); # endif}
If the virtual projection is obscured, even if the shadow is black, the actual project had better go to Linear01Depth (depth) * _ ProjectionParams.z within the real distance and effective range.
Thank you for reading this article carefully. I hope the article "how to use screen space in unity3d to improve shadowmap light leakage" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.