浏览代码

Rename: "_GlobalFog" -> "_Global", "HomogeneousFog" -> "HomogeneousMediumVolume"

/main
Evgenii Golubev 7 年前
当前提交
1df1dda7
共有 9 个文件被更改,包括 118 次插入106 次删除
  1. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightEvaluation.hlsl
  3. 8
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/Resources/VolumetricLighting.compute
  4. 60
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/VolumetricLighting.cs
  5. 6
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl
  6. 59
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousMediumVolume.cs
  7. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousMediumVolume.cs.meta
  8. 13
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousFog.cs.meta
  9. 59
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousFog.cs

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDStringConstants.cs


public static readonly int _Result1 = Shader.PropertyToID("_Result1");
public static readonly int _AmbientProbeCoeffs = Shader.PropertyToID("_AmbientProbeCoeffs");
public static readonly int _GlobalFog_Extinction = Shader.PropertyToID("_GlobalFog_Extinction");
public static readonly int _GlobalFog_Scattering = Shader.PropertyToID("_GlobalFog_Scattering");
public static readonly int _GlobalFog_Asymmetry = Shader.PropertyToID("_GlobalFog_Asymmetry");
public static readonly int _Global_Extinction = Shader.PropertyToID("_Global_Extinction");
public static readonly int _Global_Scattering = Shader.PropertyToID("_Global_Scattering");
public static readonly int _Global_Asymmetry = Shader.PropertyToID("_Global_Asymmetry");
public static readonly int _CornetteShanksConstant = Shader.PropertyToID("_CornetteShanksConstant");
public static readonly int _VBufferResolution = Shader.PropertyToID("_VBufferResolution");
public static readonly int _VBufferScaleAndSliceCount = Shader.PropertyToID("_VBufferScaleAndSliceCount");

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightEvaluation.hlsl


#if (SHADEROPTIONS_VOLUMETRIC_LIGHTING_PRESET != 0)
float distVol = (lightData.lightType == GPULIGHTTYPE_PROJECTOR_BOX) ? distances.w : distances.x;
attenuation *= TransmittanceHomogeneousMedium(_GlobalFog_Extinction, distVol);
attenuation *= TransmittanceHomogeneousMedium(_Global_Extinction, distVol);
#endif
// Projector lights always have cookies, so we can perform clipping inside the if().

8
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/Resources/VolumetricLighting.compute


CBUFFER_START(UnityVolumetricLighting)
float4 _VBufferSampleOffset; // {x, y, z}, w = rendered frame count
float4x4 _VBufferCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float _CornetteShanksConstant; // CornetteShanksPhasePartConstant(_GlobalFog_Asymmetry)
float _CornetteShanksConstant; // CornetteShanksPhasePartConstant(_Global_Asymmetry)
CBUFFER_END
//--------------------------------------------------------------------------------------------------

// Sample the participating medium at 'tc' (or 'centerWS').
// We consider it to be constant along the interval [t0, t1] (within the voxel).
// TODO: piecewise linear.
float3 scattering = _GlobalFog_Scattering;
float extinction = max(_GlobalFog_Extinction, FLT_MIN); // Avoid NaNs
float asymmetry = _GlobalFog_Asymmetry;
float3 scattering = _Global_Scattering;
float extinction = max(_Global_Extinction, FLT_MIN); // Avoid NaNs
float asymmetry = _Global_Asymmetry;
// TODO: define a function ComputeGlobalFogCoefficients(float3 centerWS),
// which allows procedural definition of extinction and scattering.

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


ComputeShader m_VolumetricLightingCS = null;
List<VBuffer> m_VBuffers = null;
float m_VBufferNearPlane = 0.5f; // Distance in meters; dynamic modifications not handled by reprojection
float m_VBufferFarPlane = 64.0f; // Distance in meters; dynamic modifications not handled by reprojection
const float k_LogScale = 0.5f;
List<VBuffer> m_VBuffers = null;
List<OrientedBBox> m_VisibleVolumes = null;
List<VolumeProperties> m_VisibleVolumeProperties = null;
float m_VBufferNearPlane = 0.5f; // Distance in meters; dynamic modifications not handled by reprojection
float m_VBufferFarPlane = 64.0f; // Distance in meters; dynamic modifications not handled by reprojection
const float k_LogScale = 0.5f;
m_VolumetricLightingCS = asset.renderPipelineResources.volumetricLightingCS;
m_VBuffers = new List<VBuffer>(0);
m_VolumetricLightingCS = asset.renderPipelineResources.volumetricLightingCS;
m_VBuffers = new List<VBuffer>();
m_VisibleVolumes = new List<OrientedBBox>();
m_VisibleVolumeProperties = new List<VolumeProperties>();
}
public void Cleanup()

m_VBuffers[i].Destroy();
}
m_VBuffers = null;
m_VBuffers = null;
m_VisibleVolumes = null;
m_VisibleVolumeProperties = null;
}
public void ResizeVBuffer(HDCamera camera, int screenWidth, int screenHeight)

{
if (preset == VolumetricLightingPreset.Off) return;
HomogeneousFog globalFogComponent = HomogeneousFog.GetGlobalFogComponent();
HomogeneousMediumVolume globalVolume = HomogeneousMediumVolume.GetGlobalHomogeneousMediumVolume();
VolumeProperties globalFogProperties = (globalFogComponent != null) ? globalFogComponent.volumeParameters.GetProperties()
VolumeProperties globalVolumeProperties = (globalVolume != null) ? globalVolume.volumeParameters.GetProperties()
float asymmetry = globalFogComponent != null ? globalFogComponent.volumeParameters.asymmetry : 0;
cmd.SetGlobalVector(HDShaderIDs._GlobalFog_Scattering, globalFogProperties.scattering);
cmd.SetGlobalFloat( HDShaderIDs._GlobalFog_Extinction, globalFogProperties.extinction);
cmd.SetGlobalFloat( HDShaderIDs._GlobalFog_Asymmetry, asymmetry);
float asymmetry = globalVolume != null ? globalVolume.volumeParameters.asymmetry : 0;
cmd.SetGlobalVector(HDShaderIDs._Global_Scattering, globalVolumeProperties.scattering);
cmd.SetGlobalFloat( HDShaderIDs._Global_Extinction, globalVolumeProperties.extinction);
cmd.SetGlobalFloat( HDShaderIDs._Global_Asymmetry, asymmetry);
int w = 0, h = 0, d = 0;
Vector2 scale = ComputeVBufferResolutionAndScale(preset, (int)camera.screenSize.x, (int)camera.screenSize.y, ref w, ref h, ref d);

camOffset = -camPosition; // Camera-relative
}
HomogeneousFog[] fogComponents = Object.FindObjectsOfType(typeof(HomogeneousFog)) as HomogeneousFog[];
m_VisibleVolumes.Clear();
m_VisibleVolumeProperties.Clear();
foreach (HomogeneousFog fogComponent in fogComponents)
// Collect all the visible volume data, and upload it to the GPU.
HomogeneousMediumVolume[] volumes = Object.FindObjectsOfType(typeof(HomogeneousMediumVolume)) as HomogeneousMediumVolume[];
foreach (HomogeneousMediumVolume volume in volumes)
if (fogComponent.enabled && fogComponent.volumeParameters.IsLocalVolume())
if (volume.enabled && volume.volumeParameters.IsLocalVolume())
// Convert to the camera-relative coordinates if necessary.
var obb = OrientedBBox.Create(fogComponent.transform);
var obb = OrientedBBox.Create(volume.transform);
if (!GeometryUtils.Overlap(obb, camOffset, camera.frustum, 6, 8))
if (GeometryUtils.Overlap(obb, camOffset, camera.frustum, 6, 8))
Debug.Log("Culled.");
// TODO: cache these?
var properties = volume.volumeParameters.GetProperties();
m_VisibleVolumes.Add(obb);
m_VisibleVolumeProperties.Add(properties);
}
}
}

VBuffer vBuffer = FindVBuffer(camera.GetViewID());
Debug.Assert(vBuffer != null);
HomogeneousFog globalFogComponent = HomogeneousFog.GetGlobalFogComponent();
float asymmetry = globalFogComponent != null ? globalFogComponent.volumeParameters.asymmetry : 0;
HomogeneousMediumVolume globalVolume = HomogeneousMediumVolume.GetGlobalHomogeneousMediumVolume();
float asymmetry = globalVolume != null ? globalVolume.volumeParameters.asymmetry : 0;
if (globalFogComponent == null)
if (globalVolume == null)
{
// Clear the render target instead of running the shader.
// CoreUtils.SetRenderTarget(cmd, GetVBufferLightingIntegral(viewOffset), ClearFlag.Color, CoreUtils.clearColorAllBlack);

6
ScriptableRenderPipeline/HDRenderPipeline/HDRP/ShaderVariables.hlsl


uint _TaaFrameIndex; // [0, 7]
// Volumetric lighting.
float4 _AmbientProbeCoeffs[7]; // 3 bands of SH, packed, rescaled and convolved with the phase function
float _GlobalFog_Asymmetry;
float3 _GlobalFog_Scattering;
float _GlobalFog_Extinction;
float _Global_Asymmetry;
float3 _Global_Scattering;
float _Global_Extinction;
float4 _VBufferResolution; // { w, h, 1/w, 1/h }
float4 _VBufferScaleAndSliceCount; // { fracVisW, fracVisH, count, 1/count }
float4 _VBufferDepthEncodingParams; // See the call site for description

59
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousMediumVolume.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
[AddComponentMenu("RenderPipeline/High Definition/Homogeneous Medium Volume", -1)]
public class HomogeneousMediumVolume : MonoBehaviour
{
public VolumeParameters volumeParameters = new VolumeParameters();
private void Awake()
{
}
private void OnEnable()
{
}
private void OnDisable()
{
}
private void Update()
{
}
private void OnValidate()
{
volumeParameters.Constrain();
}
void OnDrawGizmos()
{
if (volumeParameters.IsLocalVolume())
{
Gizmos.color = volumeParameters.albedo;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
}
}
// Returns NULL if a global fog component does not exist, or is not enabled.
public static HomogeneousMediumVolume GetGlobalHomogeneousMediumVolume()
{
HomogeneousMediumVolume globalVolume = null;
HomogeneousMediumVolume[] volumes = FindObjectsOfType(typeof(HomogeneousMediumVolume)) as HomogeneousMediumVolume[];
foreach (HomogeneousMediumVolume volume in volumes)
{
if (volume.enabled && !volume.volumeParameters.IsLocalVolume())
{
globalVolume = volume;
break;
}
}
return globalVolume;
}
}
} // UnityEngine.Experimental.Rendering.HDPipeline

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


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

13
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousFog.cs.meta


fileFormatVersion: 2
guid: 8f608e240d5376341bcef2478d231457
timeCreated: 1503411233
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

59
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Volumetrics/HomogeneousFog.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
[AddComponentMenu("RenderPipeline/High Definition/Homogenous Fog", -1)]
public class HomogeneousFog : MonoBehaviour
{
public VolumeParameters volumeParameters = new VolumeParameters();
private void Awake()
{
}
private void OnEnable()
{
}
private void OnDisable()
{
}
private void Update()
{
}
private void OnValidate()
{
volumeParameters.Constrain();
}
void OnDrawGizmos()
{
if (volumeParameters.IsLocalVolume())
{
Gizmos.color = volumeParameters.albedo;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
}
}
// Returns NULL if a global fog component does not exist, or is not enabled.
public static HomogeneousFog GetGlobalFogComponent()
{
HomogeneousFog globalFogComponent = null;
HomogeneousFog[] fogComponents = FindObjectsOfType(typeof(HomogeneousFog)) as HomogeneousFog[];
foreach (HomogeneousFog fogComponent in fogComponents)
{
if (fogComponent.enabled && !fogComponent.volumeParameters.IsLocalVolume())
{
globalFogComponent = fogComponent;
break;
}
}
return globalFogComponent;
}
}
} // UnityEngine.Experimental.Rendering.HDPipeline
正在加载...
取消
保存