Unity渲染路径 Rendering Paths_1_Deferred Lighting 延时光照

Deferred Lighting 延时光照
       延时光照是有着最高保真度的光照和阴影的渲染路径。如果你有很多实时灯光,最好是使用延时光照。它需要一定水平的硬件支持,仅在 Unity Pro可用,移动设备上不支持。
       延迟光照是一种当前最高级的能实现光线和阴影保真的渲染路径
  • 对于能影响任何物体的光线数量没有上限 
  • 完全采用以每像素的方式评估光线,这等于意味着全部将以正常贴图的方式正确的和物体交互
  • 所有光线都能拥有信息缓存
  • 所有的光线都能产生阴影
延迟光照的优点:
  • 光照的开销与屏幕的光线尺寸成正比,不用担心光线所照射的物品的数量,少量光线 等价于 廉价的花费
  • 一致性,所有的光线的光照采用按像素为计算分割单位来计算。比如,不会有在大规模三角形情况下光照计算使计算性能发生崩溃的情况发生。
缺点:
  • 没有实时抗锯齿支持
  • 延迟光照不能处理半透明物体,也不能用在哪些使用前向渲染的物体之上
  • 有限的光照模式支持(Blinn-Phong)。所有光照以同样的方式计算,你不能够在不同的物体上采用完全不同的光照模式
  • 没有对接收阴影特征的支持和对光线遮罩剔除有限的支持
延时光照的需求:
  • 需要Unity专业版
  • 显示卡支持Shader Model 3.0(或更高),深度纹理渲染和双面模板缓冲特性。许多2004年后的显卡都支持:如Geforce Fx或更高,Radeon X1300或更高 Intel 965/ GMA X3100 或更高
  • 目前在移动平台不支持。
性能注意事项:
  • 延迟光照中实时光线的开销和光线照亮的像素值的数量成正比。而不取决于场景的复杂性。微小的点光源和聚光灯光源非常容易渲染。点光源或者完全或者部分被场景物体遮挡的聚光灯光源所照射的像素则被GPU所跳过,因此更加廉价。
  • 当然,拥有阴影的光源比没有阴影的光源要昂贵许多。使用延迟光照,光影投射器仍然需要为每个阴影投射渲染一次或者多次。而且产生阴影的光线着色器也比不产生阴影的光线着色器要昂贵许多。
实现细节:
当延迟光照生效时,在Unity中发生的渲染过程如下:
  • 基本渲染:被渲染的对象产生带有深度,法线,和反射量的屏幕空间缓冲
  • 光照渲染:使用上一步的缓冲计算出光照。结果放入另一个屏幕空间缓存
  • 最后渲染:物体再次渲染。取来已经计算好的光线和颜色纹理混合在一起,然后再加上环境光以及散射光照。
不能采用延迟光照技术的带阴影的物体在延迟光照渲染完后使用前向渲染路径处理。
Base Pass 基本渲染阶段
  • 基本渲染将每个物体都渲染一次。视图空间法线和高光强度被渲染进单一的ARGB32渲染纹理(法线在RGB通道,高光强度在A通道)中。如果平台和硬件支持将Z缓冲按纹理读取,那么深度不会被明确的渲染。如果Z缓冲不能被以纹理的方式访问,那么深度将在额外的渲染处理中被使用着色器替代技术渲染。
  • 基本渲染的结果是被屏幕内容填满的Z缓冲和带有法线和高光强度的渲染纹理。
Lighting Pass 光照渲染阶段
  • 光照渲染基于深度,法线和高光强度计算光照。光照是被屏幕空间被计算的,因此和屏幕复杂性无关。光照缓冲是一个单一的ARGGB32渲染纹理,纹理的RGB通道带有漫反射的光照信息,在A通道带有单一特定颜色的光照。光照值采用对数值编码以产生比通常ARGB32纹理所能达到的动态扩展范围。
  • 光照模式固定为Blinn-Phong。
  • 不能跨越临近平面的点光源和聚光灯光源被作为带有开启测试场景的Z缓冲3D形状渲染,这部分和完全屏蔽的点光源和聚光灯光源可以非常廉价的渲染。 跨越临近区域的平行光或者点光源能作为全屏四边形。
  • 如果一个带有阴影的光源生效,在这个处理过程中会被很好的渲染。注意阴影并不免费,阴影投射器需要开销来渲染,同时一个更加复杂的光线着色器需要应用。
Final Pass 最后渲染阶段
  • 最终渲染阶段产生最后渲染后的图像,到这一步,所有的对象都将被再次渲染,其中着色器将混合前一步生成的光源和纹理以及所有自发光照明。
  • 在最后渲染阶段光照贴图也被应用。靠近相机,使用实时光照,并仅烘焙间接光照。
### Unity URP Lightmap Parameters Configuration and Usage In the context of configuring and using lightmaps within Unity's Universal Render Pipeline (URP), several key aspects must be considered to ensure optimal performance and visual fidelity. #### Configuring Lighting Settings The lighting settings play a crucial role in preparing scenes for baking lightmaps. Within the `Lighting` window, one can adjust various parameters that influence how lightmaps are generated[^2]. For instance: - **Baked GI**: Enables or disables baked global illumination. - **Realtime GI**: Controls whether real-time global illumination should be used alongside baked lightmaps. - **Indirect Intensity**: Adjusts the intensity multiplier applied to indirect lighting contributions captured by the lightmap. These configurations help tailor the behavior of both direct and indirect lighting components stored inside the lightmaps. #### Setting Up Materials Materials intended to receive lightmapped data need specific properties configured properly. Typically, shaders utilized under URP require inclusion of `_MainTex`, which serves as albedo input, along with additional textures like emission maps if applicable. Moreover, materials should reference shaders compatible with deferred rendering paths since most implementations supporting lightmapping operate efficiently through this pipeline[^4]. For example, when defining custom HLSL code within Shader Graph nodes or hand-coded shaders, incorporating necessary functions from `Lighting.hlsl` becomes essential. This allows access to main lights' directions via constructs such as: ```csharp float3 lightDir = normalize(light.direction); ``` This line retrieves normalized direction vectors pointing towards primary sources illuminating objects rendered using these materials. #### Handling Shadow Artifacts When working with URP and its associated shadow casting mechanisms, certain artifacts may arise due to limitations inherent in rasterization techniques employed during render passes. To mitigate issues related to aliasing around shadow edges, adjusting MSAA levels found under Quality settings proves beneficial: ```python // Example Python snippet demonstrating adjustment logic qualitySettings.msaaSamples = 4; // Set Multi-Sample Anti-Aliasing sample count ``` Increasing multisampling rates helps smooth out jagged lines appearing at silhouette boundaries where shadows meet surfaces receiving them. --- --related questions-- 1. How does altering Indirect Intensity affect final scene appearance? 2. What considerations exist while choosing between Realtime vs Baked Global Illumination modes? 3. Can you provide examples illustrating differences among available shading models suitable for lightmapped geometries? 4. Are there any best practices regarding material setup specifically aimed at optimizing lightmap usage efficiency?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值