Raymond Graham
7 年前
当前提交
29eb0f1f
共有 10 个文件被更改,包括 338 次插入 和 47 次删除
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
-
75ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolumeManager.cs
-
63ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousDensityVolume.cs
-
33ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
-
44ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
-
15ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs.hlsl
-
4ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/StackLit/StackLit.cs.hlsl
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/AtmosphericScattering/VolumetricFog.cs
-
136ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Collections.LowLevel.Unsafe; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class VolumeTextureAtlas |
|||
{ |
|||
private List<Texture3D> textures = null; |
|||
|
|||
//Assuming every volume texture is square and number of depth slices equal to 2D dimensions
|
|||
private int requiredTextureSize; |
|||
private TextureFormat requiredTextureFormat; |
|||
|
|||
public bool needTextureUpdate |
|||
{ |
|||
get; |
|||
private set; |
|||
} |
|||
|
|||
|
|||
public Texture3D volumeAtlas |
|||
{ |
|||
get; |
|||
private set; |
|||
} |
|||
|
|||
public event Action OnAtlasUpdated; |
|||
|
|||
private void NotifyAtlasUpdated() |
|||
{ |
|||
if (OnAtlasUpdated != null) |
|||
{ |
|||
OnAtlasUpdated(); |
|||
} |
|||
} |
|||
|
|||
public VolumeTextureAtlas(TextureFormat atlasFormat, int atlasSize ) |
|||
{ |
|||
requiredTextureSize = atlasSize; |
|||
|
|||
requiredTextureFormat = atlasFormat; |
|||
|
|||
textures = new List<Texture3D>(); |
|||
|
|||
needTextureUpdate = false; |
|||
} |
|||
|
|||
public void ClearTextures() |
|||
{ |
|||
textures.Clear(); |
|||
needTextureUpdate = true; |
|||
} |
|||
|
|||
public void AddTexture(Texture3D volumeTexture) |
|||
{ |
|||
//TODO: we should really just convert the texture to the right size and format...HOWEVER, we dont' support 3D textures at the moment in the ConvertTexture call
|
|||
if (volumeTexture.width != requiredTextureSize || volumeTexture.height != requiredTextureSize || volumeTexture.depth != requiredTextureSize) |
|||
{ |
|||
Debug.LogError(string.Format("VolumeTextureAtlas: Dimensions of texture {0} does not match expected dimensions of {1}", volumeTexture, requiredTextureSize)); |
|||
return; |
|||
} |
|||
|
|||
if (volumeTexture.format != requiredTextureFormat) |
|||
{ |
|||
Debug.LogError(string.Format("VolumeTextureAtlas: Texture format of texture {0} : {1} does not match expected format of {2}", volumeTexture, volumeTexture.format, requiredTextureSize)); |
|||
return; |
|||
} |
|||
|
|||
if (!textures.Contains(volumeTexture)) |
|||
{ |
|||
textures.Add(volumeTexture); |
|||
|
|||
needTextureUpdate = true; |
|||
} |
|||
} |
|||
|
|||
public void RemoveTexture(Texture3D volumeTexture) |
|||
{ |
|||
if (textures.Contains(volumeTexture)) |
|||
{ |
|||
textures.Add(volumeTexture); |
|||
|
|||
needTextureUpdate = true; |
|||
} |
|||
} |
|||
|
|||
//Generates the volume atlas by converting (if needed) and then copying the textures into one big volume texture.
|
|||
public void GenerateVolumeAtlas(CommandBuffer cmd) |
|||
{ |
|||
if (needTextureUpdate) |
|||
{ |
|||
if (textures.Count > 0) |
|||
{ |
|||
Color[] colorArray = new Color[0]; |
|||
volumeAtlas = new Texture3D(requiredTextureSize, requiredTextureSize, requiredTextureSize * textures.Count, requiredTextureFormat, false); |
|||
|
|||
// int volumeDepthOffset = 0;
|
|||
|
|||
foreach (Texture3D tex in textures) |
|||
{ |
|||
//UGGG this is awful...why you no working CopyTexture???
|
|||
Color[] texColor = tex.GetPixels(); |
|||
Array.Resize(ref colorArray, texColor.Length + colorArray.Length); |
|||
Array.Copy(texColor, 0, colorArray, colorArray.Length - texColor.Length, texColor.Length); |
|||
for (int i = 0; i < requiredTextureSize; i++) |
|||
{ |
|||
/* |
|||
cmd.CopyTexture(tex, i, volumeAtlas, volumeDepthOffset); |
|||
|
|||
volumeDepthOffset++;*/ |
|||
} |
|||
} |
|||
|
|||
volumeAtlas.SetPixels(colorArray); |
|||
volumeAtlas.Apply(); |
|||
} |
|||
else |
|||
{ |
|||
volumeAtlas = null; |
|||
} |
|||
|
|||
needTextureUpdate = false; |
|||
|
|||
NotifyAtlasUpdated(); |
|||
} |
|||
} |
|||
|
|||
public int GetTextureIndex(Texture3D tex) |
|||
{ |
|||
return textures.IndexOf(tex); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dec15692e6345454297042562cea930a |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue