Antoine Lelievre
7 年前
当前提交
c5cac258
共有 10 个文件被更改,包括 172 次插入 和 144 次删除
-
6com.unity.render-pipelines.core/CoreRP/Textures/TextureCache.cs
-
13com.unity.render-pipelines.high-definition/CHANGELOG.md
-
2com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Reflection/HDReflectionProbeEditor.Gizmos.cs
-
2com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/volumeTextureTool.cs.meta
-
18com.unity.render-pipelines.high-definition/HDRP/Lighting/Reflection/HDAdditionalReflectionData.cs
-
3com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/DensityVolume.cs
-
2com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/DensityVolumeManager.cs
-
141com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/volumeTextureTool.cs
-
129com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs
-
0/com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/volumeTextureTool.cs.meta
|
|||
using System; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering { |
|||
|
|||
public class VolumeTextureTool : EditorWindow |
|||
{ |
|||
private Texture2D sourceTexture = null; |
|||
private string assetPath; |
|||
private string assetDirectory; |
|||
|
|||
private int tileSize = 0; |
|||
|
|||
private static GUIContent windowTitle = new GUIContent("Create Volume Texture"); |
|||
private static GUIContent textureLabel = new GUIContent("Slice Texture"); |
|||
private static GUIContent tileSizeLabel = new GUIContent("Texture Slice Size", "Dimensions of the created 3D Texture in pixels. Width, Height and Depth are all the same size"); |
|||
private static GUIContent createLabel = new GUIContent("Create 3D Texture"); |
|||
|
|||
[MenuItem("Window/Render Pipeline/Create Volume Texture")] |
|||
static void Init() |
|||
{ |
|||
VolumeTextureTool window = (VolumeTextureTool)EditorWindow.GetWindow(typeof(VolumeTextureTool)); |
|||
window.titleContent = windowTitle; |
|||
window.Show(); |
|||
} |
|||
|
|||
private bool IsTileSizeValid() |
|||
{ |
|||
int textureWidth = sourceTexture.width; |
|||
int textureHeight = sourceTexture.height; |
|||
|
|||
return (tileSize > 0 && (textureWidth * textureHeight >= (tileSize*tileSize*tileSize))); |
|||
} |
|||
|
|||
void OnGUI() |
|||
{ |
|||
EditorGUILayout.LabelField(textureLabel, null); |
|||
EditorGUI.indentLevel++; |
|||
sourceTexture = ( EditorGUILayout.ObjectField((UnityEngine.Object)sourceTexture, typeof(Texture2D), false, null) as Texture2D); |
|||
EditorGUI.indentLevel--; |
|||
tileSize = EditorGUILayout.IntField(tileSizeLabel, tileSize, null); |
|||
|
|||
bool validData = (sourceTexture != null && IsTileSizeValid()); |
|||
bool create = false; |
|||
|
|||
if (!validData) |
|||
{ |
|||
if (tileSize > 0) |
|||
{ |
|||
EditorGUILayout.HelpBox(String.Format("Source Texture too small to generate a volume Texture of {0}x{0}x{0} size", tileSize), MessageType.Warning); |
|||
} |
|||
else |
|||
{ |
|||
EditorGUILayout.HelpBox("Tile size must be larger than 0", MessageType.Warning); |
|||
} |
|||
} |
|||
|
|||
using (new EditorGUI.DisabledScope(!validData)) |
|||
{ |
|||
create = GUILayout.Button(createLabel, null); |
|||
} |
|||
|
|||
if (create) |
|||
{ |
|||
assetPath = AssetDatabase.GetAssetPath(sourceTexture); |
|||
assetDirectory = System.IO.Directory.GetParent(assetPath).ToString(); |
|||
|
|||
//Check if the texture is set to read write.
|
|||
//Only need to do this since CopyTexture is currently broken on D3D11
|
|||
//So need to make sure there is a CPU copy ready to copy to the 3D Texture
|
|||
//The fix for this is coming soon. Need to revist once it's in.
|
|||
TextureImporter importer = TextureImporter.GetAtPath(assetPath) as TextureImporter; |
|||
if (importer && !importer.isReadable) |
|||
{ |
|||
importer.isReadable = true; |
|||
importer.SaveAndReimport(); |
|||
} |
|||
|
|||
BuildVolumeTexture(); |
|||
} |
|||
} |
|||
|
|||
private void BuildVolumeTexture() |
|||
{ |
|||
//Check if the object we want to create is already in the AssetDatabase
|
|||
string volumeTextureAssetPath = assetDirectory + "/" + sourceTexture.name + "_Texture3D.asset"; |
|||
bool createNewAsset = false; |
|||
|
|||
Texture3D volumeTexture = AssetDatabase.LoadAssetAtPath(volumeTextureAssetPath, typeof(Texture3D)) as Texture3D; |
|||
|
|||
//If we already have the asset then we are just updating it. make sure it's the right size.
|
|||
if (!volumeTexture || volumeTexture.width != tileSize || volumeTexture.height != tileSize || volumeTexture.depth != tileSize) |
|||
{ |
|||
volumeTexture = new Texture3D(tileSize, tileSize, tileSize, sourceTexture.format, false); |
|||
volumeTexture.filterMode = sourceTexture.filterMode; |
|||
volumeTexture.mipMapBias = 0; |
|||
volumeTexture.anisoLevel = 0; |
|||
volumeTexture.wrapMode = sourceTexture.wrapMode; |
|||
volumeTexture.wrapModeU = sourceTexture.wrapModeU; |
|||
volumeTexture.wrapModeV = sourceTexture.wrapModeV; |
|||
volumeTexture.wrapModeW = sourceTexture.wrapModeW; |
|||
|
|||
createNewAsset = true; |
|||
} |
|||
|
|||
//Only need to do this since CopyTexture is currently broken on D3D11
|
|||
//Proper fix on it's way for 18.3 or 19.1
|
|||
Color [] colorArray = new Color[0]; |
|||
|
|||
int yTiles = sourceTexture.height / tileSize; |
|||
int xTiles = sourceTexture.width / tileSize; |
|||
|
|||
for (int i = yTiles - 1; i >= 0; i--) |
|||
{ |
|||
for (int j = 0; j < xTiles; j++) |
|||
{ |
|||
Color [] sourceTile = sourceTexture.GetPixels(j * tileSize, i * tileSize, tileSize, tileSize); |
|||
Array.Resize(ref colorArray, colorArray.Length + sourceTile.Length); |
|||
Array.Copy(sourceTile, 0, colorArray, colorArray.Length - sourceTile.Length, sourceTile.Length); |
|||
} |
|||
} |
|||
|
|||
volumeTexture.SetPixels(colorArray); |
|||
volumeTexture.Apply(); |
|||
|
|||
if (createNewAsset) |
|||
{ |
|||
AssetDatabase.CreateAsset(volumeTexture, volumeTextureAssetPath); |
|||
} |
|||
else |
|||
{ |
|||
AssetDatabase.SaveAssets(); |
|||
//Asset can be currently used by Density Volume Manager so trigger refresh
|
|||
DensityVolumeManager.manager.TriggerVolumeAtlasRefresh(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|||
/// ///
|
|||
/// MIT License ///
|
|||
/// ///
|
|||
/// Copyright (c) 2016 Rapha�l Ernaelsten (@RaphErnaelsten) ///
|
|||
/// ///
|
|||
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), ///
|
|||
/// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, ///
|
|||
/// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: ///
|
|||
/// ///
|
|||
/// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. ///
|
|||
/// ///
|
|||
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ///
|
|||
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ///
|
|||
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS ///
|
|||
/// IN THE SOFTWARE. ///
|
|||
/// ///
|
|||
/// PLEASE CONSIDER CREDITING AURA IN YOUR PROJECTS. IF RELEVANT, USE THE UNMODIFIED LOGO PROVIDED IN THE "LICENSE" FOLDER. ///
|
|||
/// ///
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|||
|
|||
using System; |
|||
using UnityEngine; |
|||
using System.Collections.Generic; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
//This Editor window is a quick way to generate 3D Textures for the Volumetric system.
|
|||
//It will take a sourceTexture and slice it up into tiles that will fill a 3D Texture
|
|||
//The volumetric system has a hardcoded size of 32x32x32 volume texture atlas so this tool makes sure it fits that size.
|
|||
public class Texture3DCreationEditor : EditorWindow |
|||
{ |
|||
private Texture2D sourceTexture = null; |
|||
private string sourcePath = null; |
|||
|
|||
private int tileSize = DensityVolumeManager.volumeTextureSize; |
|||
|
|||
private int numXTiles |
|||
{ |
|||
get { return sourceTexture != null ? sourceTexture.width / tileSize : 0; } |
|||
set {} |
|||
} |
|||
|
|||
private int numYTiles |
|||
{ |
|||
get { return sourceTexture != null ? sourceTexture.height / tileSize : 0; } |
|||
set {} |
|||
} |
|||
|
|||
private bool validData |
|||
{ |
|||
get { return numXTiles * numYTiles >= tileSize; } |
|||
set {} |
|||
} |
|||
|
|||
[MenuItem("Window/Render Pipeline/Create 3D Texture")] |
|||
private static void Init() |
|||
{ |
|||
Texture3DCreationEditor window = (Texture3DCreationEditor)EditorWindow.GetWindow(typeof(Texture3DCreationEditor)); |
|||
window.titleContent.text = "Create Texture3D Asset"; |
|||
window.Show(); |
|||
} |
|||
|
|||
private void OnGUI() |
|||
{ |
|||
EditorGUILayout.BeginVertical(EditorStyles.miniButton); |
|||
GUILayout.Button(new GUIContent(" Create Texture3D Asset", ""), EditorStyles.centeredGreyMiniLabel); |
|||
|
|||
EditorGUILayout.Separator(); |
|||
|
|||
EditorGUILayout.LabelField("Source Texture"); |
|||
sourceTexture = (Texture2D)EditorGUILayout.ObjectField(sourceTexture, typeof(Texture2D), false); |
|||
EditorGUILayout.HelpBox(String.Format("Volumetric system requires textures of size {0}x{0}x{0} so please ensure the source texture is at least this many pixels.", tileSize), MessageType.Info); |
|||
|
|||
EditorGUILayout.Separator(); |
|||
|
|||
if (sourceTexture != null) |
|||
{ |
|||
sourcePath = AssetDatabase.GetAssetPath(sourceTexture); |
|||
if (validData) |
|||
{ |
|||
if (GUILayout.Button(new GUIContent("Generate 3D Texture", ""), EditorStyles.toolbarButton)) |
|||
{ |
|||
Generate3DTexture(); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
EditorGUILayout.HelpBox("Invalid Source Texture: Source texture size is not enough to create " + tileSize + " depthSlices.", MessageType.Error); |
|||
} |
|||
} |
|||
|
|||
EditorGUILayout.EndVertical(); |
|||
} |
|||
|
|||
private void Generate3DTexture() |
|||
{ |
|||
Texture3D texture = new Texture3D(tileSize, tileSize, tileSize, sourceTexture.format, false); |
|||
texture.wrapMode = sourceTexture.wrapMode; |
|||
texture.wrapModeU = sourceTexture.wrapModeU; |
|||
texture.wrapModeV = sourceTexture.wrapModeV; |
|||
texture.wrapModeW = sourceTexture.wrapModeW; |
|||
texture.filterMode = sourceTexture.filterMode; |
|||
texture.mipMapBias = 0; |
|||
texture.anisoLevel = 0; |
|||
|
|||
Color[] colorArray = new Color[0]; |
|||
|
|||
for (int i = numYTiles - 1; i >= 0; --i) |
|||
{ |
|||
for (int j = 0; j < numXTiles; ++j) |
|||
{ |
|||
Color[] texColor = sourceTexture.GetPixels(j * tileSize, i * tileSize, tileSize, tileSize); |
|||
|
|||
Array.Resize(ref colorArray, texColor.Length + colorArray.Length); |
|||
Array.Copy(texColor, 0, colorArray, colorArray.Length - texColor.Length, texColor.Length); |
|||
} |
|||
} |
|||
|
|||
|
|||
texture.SetPixels(colorArray); |
|||
texture.Apply(); |
|||
|
|||
AssetDatabase.CreateAsset(texture, System.IO.Directory.GetParent(sourcePath) + "\\" + sourceTexture.name + "_Texture3D.asset"); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue