浏览代码

Updates based on feedback. VolumeTextureAtlas now a Alpha8 texture. DensityVolume renamed.

/main
Raymond Graham 7 年前
当前提交
2952dd59
共有 11 个文件被更改,包括 38 次插入57 次删除
  1. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs
  2. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolumeManager.cs
  3. 12
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeTextureAtlas.cs
  4. 26
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumeVoxelization.compute
  5. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  6. 10
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs.hlsl
  7. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs
  8. 0
      /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs.meta
  9. 0
      /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs
  10. 0
      /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs.meta
  11. 0
      /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/DensityVolume.cs

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


namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[CanEditMultipleObjects]
[CustomEditor(typeof(HomogeneousDensityVolume))]
class HomogeneousDensityVolumeEditor : Editor
[CustomEditor(typeof(DensityVolume))]
class DensityVolumeEditor : Editor
private static GUIContent asymmetryLabel = new GUIContent("Asymmetry");
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");

SerializedProperty densityParams;
SerializedProperty albedo;
SerializedProperty meanFreePath;
SerializedProperty asymmetry;
SerializedProperty volumeTexture;
SerializedProperty textureScroll;

densityParams = serializedObject.FindProperty("parameters");
albedo = densityParams.FindPropertyRelative("albedo");
meanFreePath = densityParams.FindPropertyRelative("meanFreePath");
asymmetry = densityParams.FindPropertyRelative("asymmetry");
volumeTexture = densityParams.FindPropertyRelative("volumeMask");
textureScroll = densityParams.FindPropertyRelative("textureScrollingSpeed");

{
albedo.colorValue = EditorGUILayout.ColorField(albedoLabel, albedo.colorValue, true, false, false);
EditorGUILayout.PropertyField(meanFreePath, meanFreePathLabel);
EditorGUILayout.PropertyField(asymmetry, asymmetryLabel);
EditorGUILayout.Space();
showTextureParams = EditorGUILayout.Foldout(showTextureParams, textureSettingsTitle, true);

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


private DensityVolumeManager()
{
volumes = new List<HomogeneousDensityVolume>();
volumes = new List<DensityVolume>();
volumeAtlas = new VolumeTextureAtlas(TextureFormat.RGBA32, volumeTextureSize);
volumeAtlas = new VolumeTextureAtlas(TextureFormat.Alpha8, volumeTextureSize);
private List<HomogeneousDensityVolume> volumes = null;
private List<DensityVolume> volumes = null;
public void RegisterVolume(HomogeneousDensityVolume volume)
public void RegisterVolume(DensityVolume volume)
{
volumes.Add(volume);

}
}
public void DeRegisterVolume(HomogeneousDensityVolume volume)
public void DeRegisterVolume(DensityVolume volume)
{
if (volumes.Contains(volume))
{

}
}
public HomogeneousDensityVolume[] PrepareDensityVolumeData(CommandBuffer cmd)
public DensityVolume[] PrepareDensityVolumeData(CommandBuffer cmd)
foreach (HomogeneousDensityVolume volume in volumes )
foreach (DensityVolume volume in volumes )
{
volume.PrepareParameters();
}

private void VolumeAtlasRefresh()
{
volumeAtlas.ClearTextures();
foreach (HomogeneousDensityVolume volume in volumes )
foreach (DensityVolume volume in volumes )
{
if (volume.parameters.volumeMask != null)
{

private void AtlasUpdated()
{
foreach(HomogeneousDensityVolume volume in volumes )
foreach(DensityVolume volume in volumes )
{
volume.parameters.textureIndex = volumeAtlas.GetTextureIndex(volume.parameters.volumeMask);
}

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


Color[] colorArray = new Color[0];
volumeAtlas = new Texture3D(requiredTextureSize, requiredTextureSize, requiredTextureSize * textures.Count, requiredTextureFormat, false);
// int volumeDepthOffset = 0;
//UGGG this is awful...why you no working CopyTexture???
//TODO: Need to have copy texture and convert texture working for Tex3D in order for this to be
//more robust
for (int i = 0; i < requiredTextureSize; i++)
{
/*
cmd.CopyTexture(tex, i, volumeAtlas, volumeDepthOffset);
volumeDepthOffset++;*/
}
}
volumeAtlas.SetPixels(colorArray);

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


float4 _VBufferSampleOffset; // Not used by this shader
float _CornetteShanksConstant; // Not used by this shader
uint _NumVisibleDensityVolumes;
float2 _VolumeMaskDimensions; //x = width , y = depth
float2 _VolumeMaskDimensions; //x = 1/totalTextures , y = 1/textureSize
float4 SampleVolumeMask(DensityVolumeData volumeData, float3 voxelCenterUV)
float SampleVolumeMask(DensityVolumeData volumeData, float3 voxelCenterUV)
float totalTextures = _VolumeMaskDimensions.y / _VolumeMaskDimensions.x;
float offset = volumeData.textureIndex / totalTextures;
float clampBorder = 0.5f / _VolumeMaskDimensions.x;
float offset = volumeData.textureIndex * _VolumeMaskDimensions.x;
float clampBorder = 0.5f * _VolumeMaskDimensions.y;
voxelCenterUV.z /= totalTextures;
voxelCenterUV.z = voxelCenterUV.z * _VolumeMaskDimensions.x;
voxelCenterUV.z = clamp(voxelCenterUV.z, offset + clampBorder, offset + (1.0f / totalTextures) - clampBorder);
float4 maskValue = SAMPLE_TEXTURE3D_LOD(_VolumeMaskAtlas, s_linear_clamp_sampler, voxelCenterUV, 0);
voxelCenterUV.z = clamp(voxelCenterUV.z, offset + clampBorder, offset + _VolumeMaskDimensions.x - clampBorder);
//Scattering is albedo * extinction
maskValue.rgb *= maskValue.a;
float maskValue = SAMPLE_TEXTURE3D_LOD(_VolumeMaskAtlas, s_linear_clamp_sampler, voxelCenterUV, 0).a;
return maskValue;
}

// 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)
{
float4 scatteringAndExtinctionMask = float4(1.0f, 1.0f, 1.0f, 1.0f);
float scatteringAndExtinctionMask = 1.0f;
//Sample the volumeMask
if (_VolumeData[volumeIndex].textureIndex != -1)
{

// There is an overlap. Sample the 3D texture, or load the constant value.
voxelScattering += overlapFraction * _VolumeData[volumeIndex].scattering * scatteringAndExtinctionMask.rgb;
voxelExtinction += overlapFraction * _VolumeData[volumeIndex].extinction * scatteringAndExtinctionMask.a;
voxelScattering += overlapFraction * _VolumeData[volumeIndex].scattering * scatteringAndExtinctionMask;
voxelExtinction += overlapFraction * _VolumeData[volumeIndex].extinction * scatteringAndExtinctionMask;
}
#ifndef USE_CLUSTERED_LIGHTLIST

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


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

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

if (volumeAtlas != null)
{
volumeAtlasDimensions.x = volumeAtlas.width;
volumeAtlasDimensions.y = volumeAtlas.depth;
volumeAtlasDimensions.x = volumeAtlas.width / volumeAtlas.depth; // 1 / number of textures
volumeAtlasDimensions.y = 1.0f / volumeAtlas.width;
}
cmd.SetComputeTextureParam(m_VolumeVoxelizationCS, kernel, HDShaderIDs._VBufferDensity, vBuffer.GetDensityBuffer());

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


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

{
return value.extinction;
}
int GetTextureIndex(DensityVolumeData value)
{
return value.textureIndex;
}
}
int GetTextureIndex(DensityVolumeData value)
{
return value.textureIndex;
}
float3 GetTextureScroll(DensityVolumeData value)
{

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


data.extinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(meanFreePath);
data.scattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(data.extinction, (Vector3)(Vector4)albedo);
//The UV coordinates are in -1,1 space so have to convert to 0,1 space before applying texture scrolling and tiling.
// uv = ((uv * 0.5) + 0.5) * tiling + scroll
// uv = (uv * 0.5 * tiling + (0.5 * tiling + scroll))
data.textureScroll = volumeScrollingAmount + new Vector3(0.5f * textureTiling.x, 0.5f * textureTiling.y, 0.5f * textureTiling.z);
data.textureTiling = textureTiling * 0.5f;
data.textureScroll = volumeScrollingAmount;
data.textureTiling = textureTiling;
return data;
}

[AddComponentMenu("Rendering/Homogeneous Density Volume", 1100)]
public class HomogeneousDensityVolume : MonoBehaviour
[AddComponentMenu("Rendering/Density Volume", 1100)]
public class DensityVolume : MonoBehaviour
{
public DensityVolumeParameters parameters = new DensityVolumeParameters(Color.grey, 10.0f, 0.0f);

/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/HomogeneousDensityVolumeEditor.cs.meta → /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs.meta

/ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/HomogeneousDensityVolumeEditor.cs → /ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs

/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

正在加载...
取消
保存