浏览代码

added texture2d atlas

/main
Paul Melamed 7 年前
当前提交
22cfa928
共有 5 个文件被更改,包括 86 次插入3 次删除
  1. 24
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/Blit.shader
  4. 50
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Texture2DAtlas.cs
  5. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Texture2DAtlas.cs.meta

24
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Decal/DecalSystem.cs


static public int m_DecalsVisibleThisFrame = 0;
private Texture2DAtlas m_Atlas = null;
public Texture2DAtlas Atlas
{
get
{
if (m_Atlas == null)
{
m_Atlas = new Texture2DAtlas(4096, 4096, RenderTextureFormat.ARGB32);
}
return m_Atlas;
}
}
private class DecalSet
{
private void InitializeMaterialValues()

{
m_DiffuseTexIndex = (m_DiffuseTexture != null) ? instance.TextureAtlas.FetchSlice(cmd, m_DiffuseTexture) : -1;
m_NormalTexIndex = (m_NormalTexture != null) ? instance.TextureAtlas.FetchSlice(cmd, m_NormalTexture) : -1;
m_MaskTexIndex = (m_MaskTexture != null) ? instance.TextureAtlas.FetchSlice(cmd, m_MaskTexture) : -1;
m_MaskTexIndex = (m_MaskTexture != null) ? instance.TextureAtlas.FetchSlice(cmd, m_MaskTexture) : -1;
if (m_DiffuseTexture != null)
{
instance.Atlas.AddTexture(cmd, m_DiffuseTexture);
}
}
public void RemoveFromTextureCache()

{
if (m_DecalAtlas != null)
m_DecalAtlas.Release();
if (m_Atlas != null)
m_Atlas.Release();
m_Atlas = null;
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDUtils.cs


}
}
public static void BlitTexture(CommandBuffer cmd, RTHandle source, RTHandle destination, Vector4 scaleBiasSrc, Vector4 scaleBiasDst, float srcMipLevel, int dstMipLevel, bool bilinear)
public static void BlitTexture(CommandBuffer cmd, Texture source, RTHandle destination, Vector4 scaleBiasSrc, Vector4 scaleBiasDst, float srcMipLevel, int dstMipLevel, bool bilinear)
{
s_PropertyBlock.SetTexture(HDShaderIDs._BlitTexture, source);
s_PropertyBlock.SetVector(HDShaderIDs._BlitScaleBiasSrc, scaleBiasSrc);

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/RenderPipelineResources/Blit.shader


{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID) * float4(_BlitScaleBiasDst.xy, 1, 1) + float4(_BlitScaleBiasDst.zw, 0, 0);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID) * float4(_BlitScaleBiasSrc.xy, 1, 1) + float4(_BlitScaleBiasSrc.zw, 0, 0);
output.texcoord = GetFullScreenTriangleTexCoord(input.vertexID) * _BlitScaleBiasSrc.xy + _BlitScaleBiasSrc.zw;
return output;
}

50
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Texture2DAtlas.cs


using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.Experimental.Rendering
{
public class Texture2DAtlas
{
private RTHandle m_AtlasTexture = null;
private int m_Width;
private int m_Height;
private RenderTextureFormat m_Format;
public Texture2DAtlas(int width, int height, RenderTextureFormat format)
{
m_Width = width;
m_Height = height;
m_Format = format;
m_AtlasTexture = RTHandle.Alloc(m_Width,
m_Height,
1,
DepthBits.None,
RenderTextureFormat.ARGB32,
FilterMode.Point,
TextureWrapMode.Clamp,
TextureDimension.Tex2D,
false,
false,
true,
false);
}
public void Release()
{
RTHandle.Release(m_AtlasTexture);
}
public void AddTexture(CommandBuffer cmd, Texture texture)
{
float scaleW = (float)texture.width / m_Width;
float scaleH = (float) texture.height / m_Height;
HDUtils.BlitTexture(cmd, texture, m_AtlasTexture, new Vector4(1,1,0,0), new Vector4(scaleW, scaleH, 0, 0), 0, 0, false);
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Texture2DAtlas.cs.meta


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