您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
78 行
3.1 KiB
78 行
3.1 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
namespace UnityEngine.Experimental.Rendering.HDPipeline
|
|
{
|
|
// Keep this class first in the file. Otherwise it seems that the script type is not registered properly.
|
|
public abstract class AtmosphericScattering : VolumeComponent
|
|
{
|
|
private readonly static int m_TypeParam = Shader.PropertyToID("_AtmosphericScatteringType");
|
|
// Fog Color
|
|
private readonly static int m_ColorModeParam = Shader.PropertyToID("_FogColorMode");
|
|
private readonly static int m_FogColorDensityParam = Shader.PropertyToID("_FogColorDensity");
|
|
private readonly static int m_MipFogParam = Shader.PropertyToID("_MipFogParameters");
|
|
|
|
|
|
// Fog Color
|
|
public FogColorParameter colorMode = new FogColorParameter { value = FogColorMode.SkyColor };
|
|
[Tooltip("Constant Fog Color")]
|
|
public ColorParameter color = new ColorParameter(Color.grey);
|
|
public ClampedFloatParameter density = new ClampedFloatParameter(1.0f, 0.0f, 1.0f);
|
|
[Tooltip("Maximum mip map used for mip fog (0 being lowest and 1 highest mip).")]
|
|
public ClampedFloatParameter mipFogMaxMip = new ClampedFloatParameter(1.0f, 0.0f, 1.0f);
|
|
[Tooltip("Distance at which minimum mip of blurred sky texture is used as fog color.")]
|
|
public MinFloatParameter mipFogNear = new MinFloatParameter(0.0f, 0.0f);
|
|
[Tooltip("Distance at which maximum mip of blurred sky texture is used as fog color.")]
|
|
public MinFloatParameter mipFogFar = new MinFloatParameter(1000.0f, 0.0f);
|
|
|
|
public abstract void PushShaderParameters(CommandBuffer cmd, FrameSettings frameSettings);
|
|
|
|
public static void PushNeutralShaderParameters(CommandBuffer cmd)
|
|
{
|
|
cmd.SetGlobalFloat(m_TypeParam, (float)FogType.None);
|
|
}
|
|
|
|
public void PushShaderParametersCommon(CommandBuffer cmd, FogType type, FrameSettings frameSettings)
|
|
{
|
|
if (frameSettings.enableAtmosphericScattering)
|
|
cmd.SetGlobalFloat(m_TypeParam, (float)type);
|
|
else
|
|
cmd.SetGlobalFloat(m_TypeParam, (float)FogType.None);
|
|
|
|
// Fog Color
|
|
cmd.SetGlobalFloat(m_ColorModeParam, (float)colorMode.value);
|
|
cmd.SetGlobalColor(m_FogColorDensityParam, new Color(color.value.r, color.value.g, color.value.b, density));
|
|
cmd.SetGlobalVector(m_MipFogParam, new Vector4(mipFogNear, mipFogFar, mipFogMaxMip, 0.0f));
|
|
}
|
|
}
|
|
|
|
[GenerateHLSL]
|
|
public enum FogType
|
|
{
|
|
None,
|
|
Linear,
|
|
Exponential
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class FogTypeParameter : VolumeParameter<FogType>
|
|
{
|
|
public FogTypeParameter(FogType value, bool overrideState = false)
|
|
: base(value, overrideState)
|
|
{
|
|
}
|
|
}
|
|
|
|
[GenerateHLSL]
|
|
public enum FogColorMode
|
|
{
|
|
ConstantColor,
|
|
SkyColor,
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class FogColorParameter : VolumeParameter<FogColorMode> { }
|
|
}
|