您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
67 行
2.8 KiB
67 行
2.8 KiB
using UnityEngine.Rendering;
|
|
|
|
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
|
|
{
|
|
public class CreateLightweightRenderTexturesPass : ScriptableRenderPass
|
|
{
|
|
const string k_CreateRenderTexturesTag = "Create Render Textures";
|
|
const int k_DepthStencilBufferBits = 32;
|
|
private RenderTargetHandle colorAttachmentHandle { get; set; }
|
|
private RenderTargetHandle depthAttachmentHandle { get; set; }
|
|
private RenderTextureDescriptor descriptor { get; set; }
|
|
private SampleCount samples { get; set; }
|
|
|
|
public void Setup(
|
|
RenderTextureDescriptor baseDescriptor,
|
|
RenderTargetHandle colorAttachmentHandle,
|
|
RenderTargetHandle depthAttachmentHandle,
|
|
SampleCount samples)
|
|
{
|
|
this.colorAttachmentHandle = colorAttachmentHandle;
|
|
this.depthAttachmentHandle = depthAttachmentHandle;
|
|
this.samples = samples;
|
|
descriptor = baseDescriptor;
|
|
}
|
|
|
|
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
|
|
{
|
|
CommandBuffer cmd = CommandBufferPool.Get(k_CreateRenderTexturesTag);
|
|
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
|
|
{
|
|
var colorDescriptor = descriptor;
|
|
colorDescriptor.depthBufferBits = 0;
|
|
colorDescriptor.sRGB = true;
|
|
colorDescriptor.msaaSamples = (int)samples;
|
|
cmd.GetTemporaryRT(colorAttachmentHandle.id, colorDescriptor, FilterMode.Bilinear);
|
|
}
|
|
|
|
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
|
|
{
|
|
var depthDescriptor = descriptor;
|
|
depthDescriptor.colorFormat = RenderTextureFormat.Depth;
|
|
depthDescriptor.depthBufferBits = k_DepthStencilBufferBits;
|
|
depthDescriptor.msaaSamples = (int)samples;
|
|
depthDescriptor.bindMS = (int)samples > 1;
|
|
cmd.GetTemporaryRT(depthAttachmentHandle.id, depthDescriptor, FilterMode.Point);
|
|
}
|
|
|
|
context.ExecuteCommandBuffer(cmd);
|
|
CommandBufferPool.Release(cmd);
|
|
}
|
|
|
|
public override void FrameCleanup(CommandBuffer cmd)
|
|
{
|
|
if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
|
|
{
|
|
cmd.ReleaseTemporaryRT(colorAttachmentHandle.id);
|
|
colorAttachmentHandle = RenderTargetHandle.CameraTarget;
|
|
}
|
|
|
|
if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
|
|
{
|
|
cmd.ReleaseTemporaryRT(depthAttachmentHandle.id);
|
|
depthAttachmentHandle = RenderTargetHandle.CameraTarget;
|
|
}
|
|
}
|
|
}
|
|
}
|