浏览代码
Merge pull request #1294 from Unity-Technologies/volumetric-lighting-updates
Merge pull request #1294 from Unity-Technologies/volumetric-lighting-updates
Adding 3D Texture support to the local fog volumes./main
GitHub
7 年前
当前提交
6b174809
共有 17 个文件被更改,包括 578 次插入 和 58 次删除
-
2ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
-
83ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolumeManager.cs
-
38ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
-
52ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
-
15ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs.hlsl
-
100ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs
-
6ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/AtmosphericScattering/VolumetricFog.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric.meta
-
128ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs.meta
-
108ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs.meta
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs.meta
-
63ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs
-
0/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs.meta
-
0/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs
|
|||
fileFormatVersion: 2 |
|||
guid: fd873482d8bcf8049b02cd828184e831 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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); |
|||
|
|||
foreach (Texture3D tex in textures) |
|||
{ |
|||
//TODO: Need to have copy texture and convert texture working for Tex3D in order for this to be
|
|||
//more robust
|
|||
Color[] texColor = tex.GetPixels(); |
|||
Array.Resize(ref colorArray, texColor.Length + colorArray.Length); |
|||
Array.Copy(texColor, 0, colorArray, colorArray.Length - texColor.Length, texColor.Length); |
|||
} |
|||
|
|||
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: |
|
|||
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"); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9723a65f374db464a8a4f39c94ca7f54 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7ffb0e1717cab7a40ad62507bc855683 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CanEditMultipleObjects] |
|||
[CustomEditor(typeof(DensityVolume))] |
|||
class DensityVolumeEditor : Editor |
|||
{ |
|||
private static GUIContent albedoLabel = new GUIContent("Scattering Color"); |
|||
private static GUIContent meanFreePathLabel = new GUIContent("Mean Free Path"); |
|||
private static GUIContent volumeTextureLabel = new GUIContent("Volume Texture Mask"); |
|||
private static GUIContent textureScrollLabel = new GUIContent("Texture Scroll Speed"); |
|||
private static GUIContent textureTileLabel = new GUIContent("Texture Tiling Amount"); |
|||
private static GUIContent textureSettingsTitle = new GUIContent("Volume Texture Settings"); |
|||
|
|||
private bool showTextureParams = false; |
|||
|
|||
SerializedProperty densityParams; |
|||
SerializedProperty albedo; |
|||
SerializedProperty meanFreePath; |
|||
|
|||
SerializedProperty volumeTexture; |
|||
SerializedProperty textureScroll; |
|||
SerializedProperty textureTile; |
|||
|
|||
void OnEnable() |
|||
{ |
|||
densityParams = serializedObject.FindProperty("parameters"); |
|||
albedo = densityParams.FindPropertyRelative("albedo"); |
|||
meanFreePath = densityParams.FindPropertyRelative("meanFreePath"); |
|||
|
|||
volumeTexture = densityParams.FindPropertyRelative("volumeMask"); |
|||
textureScroll = densityParams.FindPropertyRelative("textureScrollingSpeed"); |
|||
textureTile = densityParams.FindPropertyRelative("textureTiling"); |
|||
|
|||
if (volumeTexture != null && volumeTexture.objectReferenceValue != null) |
|||
{ |
|||
showTextureParams = true; |
|||
} |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
albedo.colorValue = EditorGUILayout.ColorField(albedoLabel, albedo.colorValue, true, false, false); |
|||
EditorGUILayout.PropertyField(meanFreePath, meanFreePathLabel); |
|||
EditorGUILayout.Space(); |
|||
|
|||
showTextureParams = EditorGUILayout.Foldout(showTextureParams, textureSettingsTitle, true); |
|||
if (showTextureParams) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
EditorGUILayout.PropertyField(volumeTexture, volumeTextureLabel); |
|||
EditorGUILayout.PropertyField(textureScroll, textureScrollLabel); |
|||
EditorGUILayout.PropertyField(textureTile, textureTileLabel); |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
serializedObject.ApplyModifiedProperties (); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue