修复轮廓渲染特性BUG

This commit is contained in:
MuHua-123
2025-05-12 17:17:47 +08:00
parent d3b75a4e58
commit 264c0df234
2 changed files with 26 additions and 15 deletions
@@ -4,11 +4,13 @@ using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace MuHua {
namespace MuHua
{
/// <summary>
/// 轮廓渲染设置
/// </summary>
public class SRFOutlineSettings {
public class SRFOutlineSettings
{
/// <summary> 辅助材质 </summary>
public Material unlit;
/// <summary> 轮廓材质 </summary>
@@ -23,7 +25,8 @@ namespace MuHua {
/// <summary>
/// 轮廓渲染通道
/// </summary>
public class SRFOutlinePass : ScriptableRenderPass {
public class SRFOutlinePass : ScriptableRenderPass
{
public const string ProfilerTag = "Outline";
/// <summary> 渲染设置 </summary>
@@ -35,7 +38,8 @@ namespace MuHua {
public RTHandle outlineRTHandle;
/// <summary> 渲染前设置 </summary>
public void Setup(SRFOutlineSettings settings, in RenderingData renderingData) {
public void Setup(SRFOutlineSettings settings, in RenderingData renderingData)
{
this.settings = settings;
renderPassEvent = settings.renderPassEvent;
RenderTextureDescriptor descriptor = renderingData.cameraData.cameraTargetDescriptor;
@@ -44,7 +48,8 @@ namespace MuHua {
RenderingUtils.ReAllocateIfNeeded(ref tempRTHandle, descriptor, name: "TempRT");
}
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) {
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if (renderingData.cameraData.cameraType == CameraType.SceneView || renderingData.cameraData.cameraType == CameraType.Preview) return;
CommandBuffer command = CommandBufferPool.Get(ProfilerTag);
@@ -73,11 +78,18 @@ namespace MuHua {
outlineRTHandle?.Release();
}
public void DrawRenderer(CommandBuffer command, Material material) {
for (int i = 0; i < settings.renderObjs.Length; i++) {
public void DrawRenderer(CommandBuffer command, Material material)
{
for (int i = 0; i < settings.renderObjs.Length; i++)
{
Renderer renderer = settings.renderObjs[i];
if (renderer == null) { continue; }
command.DrawRenderer(renderer, material, 0, 0);
// 遍历所有的子网格
for (int subMeshIndex = 0; subMeshIndex < renderer.sharedMaterials.Length; subMeshIndex++)
{
command.DrawRenderer(renderer, material, subMeshIndex, 0);
}
}
}