Dynamic Shadow Projector库的各个主要组件属性详解

DrawTargetObject组件原文地址

DrawSceneObject组件属性原文地址

ShadowTextureRenderer组件属性原文地址

MipmappedShadowFallback组件属性原文地址

DrawTargetObject组件属性详解

DrawTargetObject组件是用于在运行时,将对象及其子对象的阴影,渲染到render texture上的组件。使用时,将此组件和ProjectorForLWRP组件一齐添加到同一个game object上。

属性 描述
Target 指定要产生并渲染阴影的那个game object
Render Children 如果为true,还会对Target下的子game object进行阴影渲染
Layer Mask 指明待渲染的Target object下的子object所从属的Layer,不在指定的Layer中的子object是不进行阴影渲染的
Auto Detect Hierarchy Changes 如果启用此选项,组件将会每帧检查Target object的子object的层次结构,如果这些子game object的Renderer组件发生了增加删除启用禁用等操作的话,本组件的command buffer将会发生更新。除了启用此选项之外,可以直接调用SetCommandBufferDirty() 函数来达成同样的更新操作。
Texture Alignment 使用此属性,可以旋转Projector的变换矩阵,使得沿着Target object的特定轴(specified axis of target object) 渲染出来的阴影贴图,能够与承纳这些阴影贴图信息的render texture的Y轴对齐
Follow Target 如果为true,projector object将会跟随Target Object的 移动而移动
Update Function 选择一个函数,用来指明在哪里更新projector的transform。您无需太在意此领域。您始终可以使用OnPreCull作为这个函数。如果要在脚本的UpdateLateUpdate函数中引用projector的transform,则在使用projector的transform之前,需要将此组件的UpdateTransform()函数,或调用SendMessage(“ UpdateTransform”)向projector object发送消息。在这种情况下,最好选择UpdateTransform,否则projector的transform将每帧更新两次。Fast Shadow Receiver组件也将引用projector的transform。这些组件将在LateUpdate函数中向projector object发送 “UpdateTransform” 消息。如果需要在LateUpdate函数中更新projector的transform,请确保在Update函数中更新了Target object的transform。

DrawSceneObject组件属性详解

DrawSceneObject组件可用于聚光灯阴影(spotlight shadows)。将此组件添加light projector object,并设置culling mask以渲染可产生阴影的object(shadow caster object) 产生的阴影。

属性 描述
Replacement Shader 设置一个replacement shader用来绘制阴影。缺省默认的shader是Hidden/DynamicShadowProjector/Shadow/Replacement
Culling Mask 设置可产生阴影的object(shadow caster object) 所在的层

MipmappedShadowFallback组件属性

MipmappedShadowFallback组件是一个起着后备作用的组件。专门准备了一个后备着色器。要使用它的话,将此组件添加light projector object。

属性 描述
Fallback/Material 设置Project的后备着色器/材质
Blur Level 设置后备材质的模糊级别。ShadowTextureRenderer组件的模糊级别将替换为此值。
Blur Size 设置后备效果的模糊大小。ShadowTextureRenderer组件的模糊大小将替换为此值。
Modify Texture Size 如果要更改后备材质的render texture纹理大小,请设置true。
Texture Width 使用此纹理大小作为后备材质的纹理宽。如果Modify Texture Size 选项为true,则适用。
Texture Height 使用此纹理大小作为后备材质的纹理高。如果Modify Texture Size选项为true,则适用。
Multi Sampling 使用此多重采样作为后备材质的多重采样级别。如果Modify Texture Size选项为true,则适用。
Super Sampling 使用此超级采样作为后备材质的超采样级别。如果Modify Texture Size选项为true,则适用。
Test Fallback 选中此字段以测试后备材质。您可以在“scene”视图中看到后备材质的样子。

Shadow Texture Renderer is a component for controlling the quality of a shadow render texture. You don’t need to add this component explicitly. It will be added together with Draw Target Object component or Draw Scene Object component.

Field Description Shadow Color Set a shadow color. If projector material can adjust shadow color or shadow intensity, leave this field black for better performance. Texture Width Choose a render texture width Texture Height Choose a render texture height Multi Sampling Choose a multisampling level for antialiasing. Multisampling requires hardware support. Super Sampling Choose a supersampling level for antialiasing. Supersampling uses larger internal render texture. Use multisampling for better performance, especially on mobile devices. Blur Level Choose a blur level. Usually, choose 0 for hard shadows, and choose 1 for soft shadows. Higher blur level can make the shadow more blurry, but not recommended. Please consider to use smaller texture size. Blur Size Adjust blur filter size. Applicable if bluer level is greater than 0. Mip Level Set max mip level of the render texture. It should be zero if you don’t use Mipmapped Shadow shader. See also Projector Shaders.

  • Version 1.0 had a memory leak bug. If mip level was greater than 0, a temporary render texture had not been released every frame. Version 1.0.1 will be released soon. Please don’t forget to update this asset. Single Pass Mipmap Blur Use a single pass blur shader for generating mipmap. It cannot have a large blur size, but it can be faster than the normal blur shader. Mipmap Blur Size Blur filter size for each mip level. Don’t update while out of view You can set false if you are sure that the projector is always visible. If this field is true and the projection frustum of the projector does not intersect with a view frustum of a camera, the render texture will not be updated. Cameras For View Clip Test Set an array of cameras used for view clip test of the projector. If this array is empty, main camera will be used. Blur Filter Choose a blur filter type, Uniform or Gaussian. Uniform filter might be better for soft shadows, and Gaussian is suitable for blob shadows. Mipmap Falloff Choose a falloff type for Mipmapped Shadow shader. If you choose custom, you need to set Custom Mipmap Falloff as well. Custom Mipmap Falloff Set a falloff value for each mip level Near Clip Plane The near clip plane of the camera which is used for rendering the render texture. It can be different from the near clip plane of the projector. Default value is 0.01. Show Camera in Inspector This is only for debug purpose. The camera for the render texture is fully controlled by Shadow Texture Renderer component, and it is usually hidden in Inspector view. You can see the camera status by checking this field. Blur Shader A shader internally used in this component. Usually, you don’t need to change this field. Downsample Shader A shader internally used in this component. Usually, you don’t need to change this field. Copy Mipmap Shader A shader internally used in this component. Usually, you don’t need to change this field. Preferred Texture Formats By default, ARGB32 format is used for the render texture. If you want to use another format, you can set it here. In case that GPU does not support the render texture format, you can set multiple formats. If none of them are supported, ARGB32 will be used.