浏览代码

Merge pull request #1294 from Unity-Technologies/volumetric-lighting-updates

Adding 3D Texture support to the local fog volumes.
/main
GitHub 6 年前
当前提交
6b174809
共有 17 个文件被更改,包括 578 次插入58 次删除
  1. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  2. 83
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolumeManager.cs
  3. 38
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
  4. 52
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  5. 15
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs.hlsl
  6. 100
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs
  7. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/AtmosphericScattering/VolumetricFog.cs
  8. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric.meta
  9. 128
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs
  10. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs.meta
  11. 108
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs
  12. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs.meta
  13. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs.meta
  14. 63
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs
  15. 0
      /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs.meta
  16. 0
      /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _VolumeBounds = Shader.PropertyToID("_VolumeBounds");
public static readonly int _VolumeData = Shader.PropertyToID("_VolumeData");
public static readonly int _NumVisibleDensityVolumes = Shader.PropertyToID("_NumVisibleDensityVolumes");
public static readonly int _VolumeMaskAtlas = Shader.PropertyToID("_VolumeMaskAtlas");
public static readonly int _VolumeMaskDimensions = Shader.PropertyToID("_VolumeMaskDimensions");
}
}

83
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolumeManager.cs


using System.Collections.Generic;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

private DensityVolumeManager()
{
volumes = new List<HomogeneousDensityVolume>();
}
public static DensityVolumeManager manager
{

}
}
private List<HomogeneousDensityVolume> volumes = null;
public VolumeTextureAtlas volumeAtlas = null;
private bool atlasNeedsRefresh = false;
//TODO: hardcoded size....:-(
public static int volumeTextureSize = 32;
public void RegisterVolume(HomogeneousDensityVolume volume)
private DensityVolumeManager()
{
volumes = new List<DensityVolume>();
volumeAtlas = new VolumeTextureAtlas(TextureFormat.Alpha8, volumeTextureSize);
volumeAtlas.OnAtlasUpdated += AtlasUpdated;
}
private List<DensityVolume> volumes = null;
public void RegisterVolume(DensityVolume volume)
volume.OnTextureUpdated += TriggerVolumeAtlasRefresh;
if (volume.parameters.volumeMask != null)
{
volumeAtlas.AddTexture(volume.parameters.volumeMask);
}
public void DeRegisterVolume(HomogeneousDensityVolume volume)
public void DeRegisterVolume(DensityVolume volume)
volume.OnTextureUpdated -= TriggerVolumeAtlasRefresh;
if (volume.parameters.volumeMask != null)
{
volumeAtlas.RemoveTexture(volume.parameters.volumeMask);
}
public DensityVolume[] PrepareDensityVolumeData(CommandBuffer cmd)
{
//Update volumes
foreach (DensityVolume volume in volumes )
{
volume.PrepareParameters();
}
public HomogeneousDensityVolume[] GetAllVolumes()
if (atlasNeedsRefresh)
{
atlasNeedsRefresh = false;
VolumeAtlasRefresh();
}
volumeAtlas.GenerateVolumeAtlas(cmd);
return volumes.ToArray();
}
private void VolumeAtlasRefresh()
{
volumeAtlas.ClearTextures();
foreach (DensityVolume volume in volumes )
{
if (volume.parameters.volumeMask != null)
{
volumeAtlas.AddTexture(volume.parameters.volumeMask);
}
}
}
private void TriggerVolumeAtlasRefresh()
return volumes.ToArray();
atlasNeedsRefresh = true;
}
private void AtlasUpdated()
{
foreach(DensityVolume volume in volumes )
{
volume.parameters.textureIndex = volumeAtlas.GetTextureIndex(volume.parameters.volumeMask);
}
}
}
}

38
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute


// Inputs & outputs
//--------------------------------------------------------------------------------------------------
StructuredBuffer<OrientedBBox> _VolumeBounds;
StructuredBuffer<DensityVolumeData> _VolumeData;
StructuredBuffer<OrientedBBox> _VolumeBounds;
StructuredBuffer<DensityVolumeData> _VolumeData;
TEXTURE3D(_VolumeMaskAtlas);
RW_TEXTURE3D(float4, _VBufferDensity); // RGB = sqrt(scattering), A = sqrt(extinction)

float4 _VBufferSampleOffset; // Not used by this shader
float _CornetteShanksConstant; // Not used by this shader
uint _NumVisibleDensityVolumes;
float2 _VolumeMaskDimensions; //x = 1/totalTextures , y = 1/textureSize
float SampleVolumeMask(DensityVolumeData volumeData, float3 voxelCenterUV)
{
float offset = volumeData.textureIndex * _VolumeMaskDimensions.x;
float clampBorder = 0.5f * _VolumeMaskDimensions.y;
//scale and bias the UVs and then take fractional part, will be in [0,1] range
voxelCenterUV = frac(voxelCenterUV * volumeData.textureTiling + volumeData.textureScroll);
voxelCenterUV.z = voxelCenterUV.z * _VolumeMaskDimensions.x;
voxelCenterUV.z += offset;
voxelCenterUV.z = clamp(voxelCenterUV.z, offset + clampBorder, offset + _VolumeMaskDimensions.x - clampBorder);
float maskValue = SAMPLE_TEXTURE3D_LOD(_VolumeMaskAtlas, s_linear_clamp_sampler, voxelCenterUV, 0).a;
return maskValue;
}
void FillVolumetricDensityBuffer(PositionInputs posInput, float3 rayOriginWS, float3 rayUnDirWS,
float3 voxelAxisRight, float3 voxelAxisUp, float3 voxelAxisForward)

// Express the voxel center in the local coordinate system of the box.
float3 voxelCenterBS = mul(voxelCenterWS - obb.center, transpose(obbFrame));
float3 voxelCenterUV = voxelCenterBS / obbExtents;
float3 voxelCenterUV = (voxelCenterBS / obbExtents) * 0.5 + 0.5;
#if SOFT_VOXELIZATION
// We need to determine which is the face closest to 'voxelCenterBS'.

if (overlapFraction > 0)
{
float scatteringAndExtinctionMask = 1.0f;
//Sample the volumeMask
if (_VolumeData[volumeIndex].textureIndex != -1)
{
scatteringAndExtinctionMask = SampleVolumeMask(_VolumeData[volumeIndex], voxelCenterUV);
}
voxelScattering += overlapFraction * _VolumeData[volumeIndex].scattering;
voxelExtinction += overlapFraction * _VolumeData[volumeIndex].extinction;
voxelScattering += overlapFraction * _VolumeData[volumeIndex].scattering * scatteringAndExtinctionMask;
voxelExtinction += overlapFraction * _VolumeData[volumeIndex].extinction * scatteringAndExtinctionMask;
}
#ifndef USE_CLUSTERED_LIGHTLIST

52
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


{
public Vector3 scattering; // [0, 1], prefer sRGB
public float extinction; // [0, 1], prefer sRGB
public Vector3 textureTiling;
public int textureIndex; //
public Vector3 textureScroll;
public static DensityVolumeData GetNeutralValues()
{

data.extinction = 0;
data.textureIndex = -1;
data.textureTiling = Vector3.one;
data.textureScroll = Vector3.zero;
return data;
}

return meanFreePath * scattering;
}
}
[Serializable]
public struct DensityVolumeParameters
{
public Color albedo; // Single scattering albedo: [0, 1]. Alpha is ignored
public float meanFreePath; // In meters: [1, 1000000]. Should be chromatic - this is an optimization!
public float asymmetry; // Controls the phase function: [-1, 1]
public void Constrain()
{
albedo.r = Mathf.Clamp01(albedo.r);
albedo.g = Mathf.Clamp01(albedo.g);
albedo.b = Mathf.Clamp01(albedo.b);
albedo.a = 1.0f;
meanFreePath = Mathf.Clamp(meanFreePath, 1.0f, float.MaxValue);
asymmetry = Mathf.Clamp(asymmetry, -1.0f, 1.0f);
}
public DensityVolumeData GetData()
{
DensityVolumeData data = new DensityVolumeData();
data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector3)(Vector4)albedo);
return data;
}
} // class VolumeParameters
public struct DensityVolumeList
{

m_VisibleVolumeData.Clear();
// Collect all visible finite volume data, and upload it to the GPU.
HomogeneousDensityVolume[] volumes = DensityVolumeManager.manager.GetAllVolumes();
DensityVolume[] volumes = DensityVolumeManager.manager.PrepareDensityVolumeData(cmd);
HomogeneousDensityVolume volume = volumes[i];
DensityVolume volume = volumes[i];
// TODO: cache these?
var obb = OrientedBBox.Create(volume.transform);

// Compose the matrix which allows us to compute the world space view direction.
Matrix4x4 transform = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(vFoV, resolution, camera.viewMatrix, false);
Texture3D volumeAtlas = DensityVolumeManager.manager.volumeAtlas.volumeAtlas;
Vector2 volumeAtlasDimensions = new Vector2(0.0f, 0.0f);
if (volumeAtlas != null)
{
volumeAtlasDimensions.x = volumeAtlas.width / volumeAtlas.depth; // 1 / number of textures
volumeAtlasDimensions.y = 1.0f / volumeAtlas.width;
}
cmd.SetComputeTextureParam(m_VolumeVoxelizationCS, kernel, HDShaderIDs._VolumeMaskAtlas, volumeAtlas);
cmd.SetComputeVectorParam(m_VolumeVoxelizationCS, HDShaderIDs._VolumeMaskDimensions, volumeAtlasDimensions);
int w = (int)resolution.x;
int h = (int)resolution.y;

15
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs.hlsl


{
float3 scattering;
float extinction;
float3 textureTiling;
int textureIndex;
float3 textureScroll;
};
//

float GetExtinction(DensityVolumeData value)
{
return value.extinction;
}
float3 GetTextureTiling(DensityVolumeData value)
{
return value.textureTiling;
}
int GetTextureIndex(DensityVolumeData value)
{
return value.textureIndex;
}
float3 GetTextureScroll(DensityVolumeData value)
{
return value.textureScroll;
}

100
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs


using System;
using UnityEngine.Rendering;
[Serializable]
public struct DensityVolumeParameters
{
public Color albedo; // Single scattering albedo [0, 1]. Alpha is ignored
public float meanFreePath; // In meters [1, inf]. Should be chromatic - this is an optimization!
public float asymmetry; // Only used if (isLocal == false)
public Texture3D volumeMask;
public int textureIndex;
public Vector3 textureScrollingSpeed;
public Vector3 textureTiling;
private Vector3 volumeScrollingAmount;
public DensityVolumeParameters(Color color, float _meanFreePath, float _asymmetry)
{
albedo = color;
meanFreePath = _meanFreePath;
asymmetry = _asymmetry;
volumeMask = null;
textureIndex = -1;
textureScrollingSpeed = Vector3.zero;
textureTiling = Vector3.one;
volumeScrollingAmount = textureScrollingSpeed;
}
public void Update()
{
//Update scrolling based on deltaTime
if (volumeMask != null)
{
volumeScrollingAmount = volumeScrollingAmount + (textureScrollingSpeed * Time.deltaTime);
}
}
public void Constrain()
{
albedo.r = Mathf.Clamp01(albedo.r);
albedo.g = Mathf.Clamp01(albedo.g);
albedo.b = Mathf.Clamp01(albedo.b);
albedo.a = 1.0f;
meanFreePath = Mathf.Clamp(meanFreePath, 1.0f, float.MaxValue);
asymmetry = Mathf.Clamp(asymmetry, -1.0f, 1.0f);
volumeScrollingAmount = Vector3.zero;
}
public DensityVolumeData GetData()
{
DensityVolumeData data = new DensityVolumeData();
data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector3)(Vector4)albedo);
data.textureIndex = textureIndex;
data.textureScroll = volumeScrollingAmount;
data.textureTiling = textureTiling;
return data;
}
} // class DensityVolumeParameters
[AddComponentMenu("Rendering/Homogeneous Density Volume", 1100)]
public class HomogeneousDensityVolume : MonoBehaviour
[AddComponentMenu("Rendering/Density Volume", 1100)]
public class DensityVolume : MonoBehaviour
public DensityVolumeParameters parameters;
public DensityVolumeParameters parameters = new DensityVolumeParameters(Color.grey, 10.0f, 0.0f);
public HomogeneousDensityVolume()
private Texture3D previousVolumeMask = null;
public Action OnTextureUpdated;
//Gather and Update any parameters that may have changed
public void PrepareParameters()
parameters.albedo = new Color(0.5f, 0.5f, 0.5f);
parameters.meanFreePath = 10.0f;
parameters.asymmetry = 0.0f;
//Texture has been updated notify the manager
if (previousVolumeMask != parameters.volumeMask)
{
NotifyUpdatedTexure();
previousVolumeMask = parameters.volumeMask;
}
parameters.Update();
}
private void NotifyUpdatedTexure()
{
if (OnTextureUpdated != null)
{
OnTextureUpdated();
}
}
private void Awake()

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/AtmosphericScattering/VolumetricFog.cs


public override void PushShaderParameters(CommandBuffer cmd, FrameSettings frameSettings)
{
DensityVolumeParameters param;
param.albedo = albedo;
param.meanFreePath = meanFreePath;
param.asymmetry = asymmetry;
DensityVolumeParameters param = new DensityVolumeParameters(albedo, meanFreePath, asymmetry);
DensityVolumeData data = param.GetData();

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric.meta


fileFormatVersion: 2
guid: fd873482d8bcf8049b02cd828184e831
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

128
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs


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);
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs.meta


fileFormatVersion: 2
guid: dec15692e6345454297042562cea930a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

108
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs


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");
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/Texture3DCreationEditor.cs.meta


fileFormatVersion: 2
guid: 9723a65f374db464a8a4f39c94ca7f54
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs.meta


fileFormatVersion: 2
guid: 7ffb0e1717cab7a40ad62507bc855683
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

63
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs


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 ();
}
}
}

/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousDensityVolume.cs.meta → /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs.meta

/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousDensityVolume.cs → /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs

正在加载...
取消
保存