浏览代码

Added TexturePadding utility

/main
Frédéric Vauchelles 7 年前
当前提交
a939e5aa
共有 4 个文件被更改,包括 109 次插入0 次删除
  1. 44
      ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.compute
  2. 8
      ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.compute.meta
  3. 46
      ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.cs
  4. 11
      ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.cs.meta

44
ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.compute


#include "CoreRP/ShaderLibrary/Common.hlsl"
#define DIRECTION_TOPRIGHT 0
#define DIRECTION_TOP 1
#define DIRECTION_RIGHT 2
#pragma kernel KMainTopRight KERNEL_NAME=KMainTopRight DIRECTION=DIRECTION_TOPRIGHT
#pragma kernel KMainTop KERNEL_NAME=KMainTop DIRECTION=DIRECTION_TOP
#pragma kernel KMainRight KERNEL_NAME=KMainRight DIRECTION=DIRECTION_RIGHT
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
// ------------------------------------------------
// Texture buffers
// ------------------------------------------------
RW_TEXTURE2D(float4, _Source);
// ------------------------------------------------
// Constant buffers
// ------------------------------------------------
CBUFFER_START(cb)
int2 _RectOffset;
CBUFFER_END
// ------------------------------------------------
// Kernel
// ------------------------------------------------
[numthreads(1, 1, 1)]
void KERNEL_NAME(uint2 dispatchThreadId : SV_DispatchThreadID)
{
const int2 targetId = _RectOffset + dispatchThreadId;
#if DIRECTION == DIRECTION_TOPRIGHT
const int2 loadId = targetId - int2(1 + dispatchThreadId.x, 1 + dispatchThreadId.y);
#elif DIRECTION == DIRECTION_TOP
const int2 loadId = targetId - int2(0, 1 + dispatchThreadId.y);
#elif DIRECTION == DIRECTION_RIGHT
const int2 loadId = targetId - int2(1 + dispatchThreadId.x, 0);
#endif
_Source[targetId] = LOAD_TEXTURE2D_LOD(_Source, loadId, 0);
}

8
ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.compute.meta


fileFormatVersion: 2
guid: 6736f53014c69f84aa2130aeae99730b
ComputeShaderImporter:
externalObjects: {}
currentAPIMask: 262148
userData:
assetBundleName:
assetBundleVariant:

46
ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.cs


using System;
using System.Collections.Generic;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering
{
public class TexturePadding
{
static readonly int _RectOffset = Shader.PropertyToID("_RectOffset");
static readonly int _Source = Shader.PropertyToID("_Source");
ComputeShader m_CS;
int m_KMainTopRight;
int m_KMainTop;
int m_KMainRight;
public TexturePadding(ComputeShader cs)
{
m_CS = cs;
m_KMainTopRight = m_CS.FindKernel("KMainTopRight");
m_KMainTop = m_CS.FindKernel("KMainTop");
m_KMainRight = m_CS.FindKernel("KMainRight");
}
public void Pad(CommandBuffer cmd, RTHandle source, RectInt from, RectInt to)
{
if (from.width < to.width)
{
cmd.SetComputeIntParams(m_CS, _RectOffset, from.width, 0);
cmd.SetComputeTextureParam(m_CS, m_KMainRight, _Source, source);
cmd.DispatchCompute(m_CS, m_KMainRight, to.width - from.width, from.height, 1);
}
if (from.height < to.height)
{
cmd.SetComputeIntParams(m_CS, _RectOffset, 0, from.height);
cmd.SetComputeTextureParam(m_CS, m_KMainTop, _Source, source);
cmd.DispatchCompute(m_CS, m_KMainTop, from.width, to.height - from.height, 1);
}
if (from.width < to.width && from.height < to.height)
{
cmd.SetComputeIntParams(m_CS, _RectOffset, from.width, from.height);
cmd.SetComputeTextureParam(m_CS, m_KMainTopRight, _Source, source);
cmd.DispatchCompute(m_CS, m_KMainTopRight, to.width - from.width, to.height - from.height, 1);
}
}
}
}

11
ScriptableRenderPipeline/Core/CoreRP/CoreResources/TexturePadding.cs.meta


fileFormatVersion: 2
guid: 51c4121b1f8d7e142931a35917400cb1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存