浏览代码

Merge pull request #1609 from EvgeniiG/volumetrics_probe_dimmer

Add "Global Light Probe Dimmer" and tooltips for volumetrics
/main
GitHub 7 年前
当前提交
87e8a616
共有 5 个文件被更改,包括 57 次插入27 次删除
  1. 24
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs
  2. 20
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/AtmosphericScattering/VolumetricFogEditor.cs
  3. 13
      com.unity.render-pipelines.high-definition/HDRP/Lighting/SphericalHarmonics.cs
  4. 5
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  5. 22
      com.unity.render-pipelines.high-definition/HDRP/Sky/AtmosphericScattering/VolumetricFog.cs

24
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/Volumetric/DensityVolumeEditor.cs


[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");
static GUIContent s_AlbedoLabel = new GUIContent("Single Scattering Albedo", "Hue and saturation control the color of the fog (the wavelength of in-scattered light). Value controls scattering (0 = max absorption & no scattering, 1 = no absorption & max scattering).");
static GUIContent s_MeanFreePathLabel = new GUIContent("Mean Free Path", "Controls the density, which determines how far you can seen through the fog. It's the distance in meters at which 50% of background light is lost in the fog (due to absorption and out-scattering).");
static GUIContent s_VolumeTextureLabel = new GUIContent("Density Mask Texture");
static GUIContent s_TextureScrollLabel = new GUIContent("Texture Scroll Speed");
static GUIContent s_TextureTileLabel = new GUIContent("Texture Tiling Amount");
static GUIContent s_TextureSettingsTitle = new GUIContent("Volume Texture Settings");
private bool showTextureParams = false;

public override void OnInspectorGUI()
{
albedo.colorValue = EditorGUILayout.ColorField(albedoLabel, albedo.colorValue, true, false, false);
EditorGUILayout.PropertyField(meanFreePath, meanFreePathLabel);
albedo.colorValue = EditorGUILayout.ColorField(s_AlbedoLabel, albedo.colorValue, true, false, false);
EditorGUILayout.PropertyField(meanFreePath, s_MeanFreePathLabel);
showTextureParams = EditorGUILayout.Foldout(showTextureParams, textureSettingsTitle, true);
showTextureParams = EditorGUILayout.Foldout(showTextureParams, s_TextureSettingsTitle, true);
EditorGUILayout.PropertyField(volumeTexture, volumeTextureLabel);
EditorGUILayout.PropertyField(textureScroll, textureScrollLabel);
EditorGUILayout.PropertyField(textureTile, textureTileLabel);
EditorGUILayout.PropertyField(volumeTexture, s_VolumeTextureLabel);
EditorGUILayout.PropertyField(textureScroll, s_TextureScrollLabel);
EditorGUILayout.PropertyField(textureTile, s_TextureTileLabel);
EditorGUI.indentLevel--;
}

20
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/AtmosphericScattering/VolumetricFogEditor.cs


private SerializedDataParameter m_Albedo;
private SerializedDataParameter m_MeanFreePath;
private SerializedDataParameter m_Anisotropy;
private SerializedDataParameter m_GlobalLightProbeDimmer;
static GUIContent s_AlbedoLabel = new GUIContent("Single Scattering Albedo", "Hue and saturation control the color of the fog (the wavelength of in-scattered light). Value controls scattering (0 = max absorption & no scattering, 1 = no absorption & max scattering).");
static GUIContent s_MeanFreePathLabel = new GUIContent("Mean Free Path", "Controls the density, which determines how far you can seen through the fog. It's the distance in meters at which 50% of background light is lost in the fog (due to absorption and out-scattering).");
static GUIContent s_AnisotropyLabel = new GUIContent("Anisotropy", "Controls the angular distribution of scattered light. 0 is isotropic, 1 is forward scattering, -1 is backward scattering.");
static GUIContent s_GlobalLightProbeDimmerLabel = new GUIContent("Global Light Probe Dimmer", "Reduces the intensity of the global light probe.");
public override void OnEnable()
{

m_Albedo = Unpack(o.Find(x => x.albedo));
m_MeanFreePath = Unpack(o.Find(x => x.meanFreePath));
m_Anisotropy = Unpack(o.Find(x => x.anisotropy));
m_Albedo = Unpack(o.Find(x => x.albedo));
m_MeanFreePath = Unpack(o.Find(x => x.meanFreePath));
m_Anisotropy = Unpack(o.Find(x => x.anisotropy));
m_GlobalLightProbeDimmer = Unpack(o.Find(x => x.globalLightProbeDimmer));
PropertyField(m_Albedo);
PropertyField(m_MeanFreePath);
PropertyField(m_Anisotropy);
PropertyField(m_Albedo, s_AlbedoLabel);
PropertyField(m_MeanFreePath, s_MeanFreePathLabel);
PropertyField(m_Anisotropy, s_AnisotropyLabel);
PropertyField(m_GlobalLightProbeDimmer, s_GlobalLightProbeDimmerLabel);
}
}
}

13
com.unity.render-pipelines.high-definition/HDRP/Lighting/SphericalHarmonics.cs


return sh;
}
public static SphericalHarmonicsL2 RescaleCoefficients(SphericalHarmonicsL2 sh, float scalar)
{
for (int c = 0; c < 3; c++)
{
for (int i = 0; i < 9; i++)
{
sh[c, i] *= scalar;
}
}
return sh;
}
// Packs coefficients so that we can use Peter-Pike Sloan's shader code.
// Does not perform premultiplication with coefficients of SH basis functions.
// See SetSHEMapConstants() in "Stupid Spherical Harmonics Tricks".

5
com.unity.render-pipelines.high-definition/HDRP/Lighting/Volumetrics/VolumetricLighting.cs


return depthParams;
}
void SetPreconvolvedAmbientLightProbe(CommandBuffer cmd, float anisotropy)
void SetPreconvolvedAmbientLightProbe(CommandBuffer cmd, float dimmer, float anisotropy)
probeSH = SphericalHarmonicMath.RescaleCoefficients(probeSH, dimmer);
ZonalHarmonicsL2 phaseZH = ZonalHarmonicsL2.GetCornetteShanksPhaseFunction(anisotropy);
SphericalHarmonicsL2 finalSH = SphericalHarmonicMath.PremultiplyCoefficients(SphericalHarmonicMath.Convolve(probeSH, phaseZH));

// Get the interpolated anisotropy value.
var fog = VolumeManager.instance.stack.GetComponent<VolumetricFog>();
SetPreconvolvedAmbientLightProbe(cmd, fog.anisotropy);
SetPreconvolvedAmbientLightProbe(cmd, fog.globalLightProbeDimmer, fog.anisotropy);
var currFrameParams = hdCamera.vBufferParams[0];
var prevFrameParams = hdCamera.vBufferParams[1];

22
com.unity.render-pipelines.high-definition/HDRP/Sky/AtmosphericScattering/VolumetricFog.cs


{
public class VolumetricFog : AtmosphericScattering
{
public ColorParameter albedo = new ColorParameter(Color.white);
public MinFloatParameter meanFreePath = new MinFloatParameter(1000000.0f, 1.0f);
public ClampedFloatParameter anisotropy = new ClampedFloatParameter(0.0f, -1.0f, 1.0f);
public ColorParameter albedo = new ColorParameter(Color.white);
public MinFloatParameter meanFreePath = new MinFloatParameter(1000000.0f, 1.0f);
public ClampedFloatParameter anisotropy = new ClampedFloatParameter(0.0f, -1.0f, 1.0f);
public ClampedFloatParameter globalLightProbeDimmer = new ClampedFloatParameter(1.0f, 0.0f, 1.0f);
public override void Override(VolumeComponent state, float interpFactor)
public override void Override(VolumeComponent state, float lerpFactor)
{
VolumetricFog other = state as VolumetricFog;

float otherExtinction = VolumeRenderingUtils.ExtinctionFromMeanFreePath(other.meanFreePath);
Vector3 otherScattering = VolumeRenderingUtils.ScatteringFromExtinctionAndAlbedo(otherExtinction, (Vector3)(Vector4)other.albedo.value);
float blendExtinction = Mathf.Lerp(otherExtinction, thisExtinction, interpFactor);
Vector3 blendScattering = Vector3.Lerp(otherScattering, thisScattering, interpFactor);
float blendAsymmetry = Mathf.Lerp(other.anisotropy, anisotropy, interpFactor);
float blendExtinction = Mathf.Lerp(otherExtinction, thisExtinction, lerpFactor);
Vector3 blendScattering = Vector3.Lerp(otherScattering, thisScattering, lerpFactor);
float blendAsymmetry = Mathf.Lerp(other.anisotropy, anisotropy, lerpFactor);
float blendDimmer = Mathf.Lerp(other.globalLightProbeDimmer, globalLightProbeDimmer, lerpFactor);
blendAlbedo.a = 1.0f;
if (meanFreePath.overrideState)

if (anisotropy.overrideState)
{
other.anisotropy.value = blendAsymmetry;
}
if (globalLightProbeDimmer.overrideState)
{
other.globalLightProbeDimmer.value = blendDimmer;
}
}

正在加载...
取消
保存