找回密码
 立即注册
查看: 205|回复: 0

【Unity】URP源码分析(Pass篇)

[复制链接]
发表于 2022-9-21 06:51 | 显示全部楼层 |阅读模式
(基于Unity 2021.3.8、URP 12.1.7)


渲染Pass流程 (Render Pass Flow)

Forward Shading


  • MainLightShadowCasterPass ->
  • AdditionalLightsShadowCasterPass ->
  • DepthNormalPrepass / DepthPrepass ->
  • ColorGradingLutPass ->
  • CopyDepthPass (Depth Prepass On) ->
  • DrawObjectsPass (Opaque) ->
  • CopyDepthPass (Depth Prepass Off) ->
  • DrawSkyboxPass ->
  • MotionVectorPass ->
  • CopyColorPass ->
  • DrawObjectsPass (Transparent) ->
  • PostProcessPass ->
  • PostProcessPass (FinalPostProcessPass) ->
  • FinalBlitPass
Deferred Shading


  • MainLightShadowCasterPass ->
  • AdditionalLightsShadowCasterPass ->
  • DepthNormalPrepass ->
  • ColorGradingLutPass ->
  • GBufferPass ->
  • CopyDepthPass ->
  • TileDepthRangePass ->
  • TileDepthRangePass (Extra) ->
  • DeferredPass ->
  • DrawObjectsPass (Opaque ForwardOnly) ->
  • DrawSkyboxPass ->
  • MotionVectorPass ->
  • CopyColorPass ->
  • DrawObjectsPass (Transparent) ->
  • PostProcessPass ->
  • PostProcessPass (FinalPostProcessPass) ->
  • FinalBlitPass
<hr/>渲染Pass细节 (Render Pass Detail)

ScriptableRenderPass.cs

属性


  • colorAttachments、colorAttachment (颜色缓冲区)
  • depthAttachment (深度缓冲区)
  • input (Pass所需的Buffer输入)
  • clearFlag (缓冲区清除标记 (color、depth、stencil))
  • clearColor (缓冲区清除颜色)
方法


  • ConfigureInput (配置input)
  • ConfigureTarget (配置ColorAttachment、DepthAttachment)
  • ConfigureClear (配置clearFlag、clearColor)
  • OnCameraSetup (虚函数)
  • Configure (虚函数)
  • OnCameraCleanup (虚函数)
  • OnFinishCameraStackRendering (虚函数)
  • Execute (抽象函数)
  • CreateDrawingSettings (创建绘制设置)
定义


  • ScriptableRenderPassInput (Pass所需的Buffer输入)
  • RenderPassEvent (渲染Pass的执行时机事件)

MainLightShadowCasterPass.cs


  • 执行Shader中LightModeShadowCaster的Pass, 主光源空间下渲染物体深度, 生成_MainLightShadowmapTexture

AdditionalLightsShadowCasterPass.cs


  • 执行Shader中LightModeShadowCaster的Pass, 额外光源空间下渲染物体深度, 生成_AdditionalLightsShadowmapTexture
  • 需要在Render Pipeline Asset上勾选Adiitional Lights的Cast Shadows, 并且光源Shadow Type选择Hard Shadows或Soft Shadows

DepthNormalOnlyPass.cs


  • 执行Shader中LightModeDepthNormals的Pass, 生成_CameraDepthTexture、_CameraNormalsTexture, 最终传入到Shader中的_CameraDepthNormalsTexture
  • 需要有后处理用到_CameraNormalsTexture

DepthOnlyPass.cs


  • 执行Shader中LightModeDepthOnly的Pass, 生成_CameraDepthTexture
  • 需要在Renderer Data上Depth Priming Mode中设置为Forced

ColorGradingLutPass.cs


  • 根据用到的校色后处理 (ChannelMixer、ColorAdjustments、ColorCurves、LiftGammaGain、ShadowsMidtonesHighlights、SplitToning、WhiteBalance) 参数生成Lut校色RT, Shader实现可参考LutBuilderHdr.shader、LutBuilderLdr.shader

MotionVectorRenderPass.cs


  • 生成运动向量RT
  • 需要有后处理用到_MotionVectorTexture

GBufferPass.cs


  • 执行Shader中LightModeUniversalGBuffer, UniversalMaterialTypeLitSimpleLitUnlit的Pass, 生成Gbuffer0 ~ Gbuffer3四张RT

DeferredPass.cs


  • 根据Stencil Buffer的值和Pass索引光源进行渲染, Shader实现可参考StencilDeferred.shader

DrawObjectsPass.cs


  • 绘制Opaque、Transparent物体

CopyDepthPass.cs


  • 拷贝activeCameraDepthAttachment到_CameraDepthTexture (当DepthOnlyPass或DepthNormalOnlyPass存在时不执行)

DrawSkyboxPass.cs


  • DrawSkybox (绘制天空盒)

CopyColorPass.cs


  • 拷贝activeCameraColorAttachment到_CameraOpaqueTexture

PostProcessPass.cs


  • depthOfField、motionBlur、paniniProjection、bloom、lensDistortion、chromaticAberration、vignette、colorLookup、colorAdjustments、tonemapping、filmGrain等后处理的集合, Shader实现可参考UberPost.shader

PostProcessPass.cs (FinalPostProcessPass)


  • RenderFinalPass, 主要处理FXAA和Render Scale不为1.0时的Up/Down Scaling Blit, Shader实现可参考FinalPost.shader

FinalBlitPass.cs


  • 将activeCameraColorAttachment Blit到cameraData.targetTexture / BuiltinRenderTextureType.CameraTarget
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-24 10:47 , Processed in 0.113985 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表