浏览代码

Update code with last merge changes and fixed some formatting issues.

/main
Julien Ignace 7 年前
当前提交
b782a332
共有 7 个文件被更改,包括 66 次插入65 次删除
  1. 28
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  2. 42
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  3. 13
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.cs
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/ExponentialFog.cs
  5. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/LinearFog.cs
  6. 34
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  7. 6
      ScriptableRenderPipeline/HDRenderPipeline/Sky/VisualEnvironment.cs

28
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


if (!m_IBLFilterGGX.IsInitialized())
m_IBLFilterGGX.Initialize(cmd);
foreach (var material in m_MaterialList)
material.RenderInit(cmd);
foreach (var material in m_MaterialList)
material.RenderInit(cmd);
using (new ProfilingSample(cmd, "HDRenderPipeline::Render", GetSampler(CustomSamplerId.HDRenderPipelineRender)))
{

renderContext.ExecuteCommandBuffer(cmd);
cmd.Clear();
buildGPULightListsCompleteFence = m_LightLoop.BuildGPULightListsAsyncBegin(camera, renderContext, m_CameraDepthStencilBufferRT, m_CameraStencilBufferCopyRT, startFence, m_SkyManager.IsSkyValid());
buildGPULightListsCompleteFence = m_LightLoop.BuildGPULightListsAsyncBegin(camera, renderContext, m_CameraDepthStencilBufferRT, m_CameraStencilBufferCopyRT, startFence, m_SkyManager.IsSkyValid());
}
using (new ProfilingSample(cmd, "Render shadows", GetSampler(CustomSamplerId.RenderShadows)))

{
using (new ProfilingSample(cmd, "Build Light list", GetSampler(CustomSamplerId.BuildLightList)))
{
m_LightLoop.BuildGPULightLists(camera, cmd, m_CameraDepthStencilBufferRT, m_CameraStencilBufferCopyRT, m_SkyManager.IsSkyValid());
m_LightLoop.BuildGPULightLists(camera, cmd, m_CameraDepthStencilBufferRT, m_CameraStencilBufferCopyRT, m_SkyManager.IsSkyValid());
}
}

if (m_FrameSettings.enableTransparentPrePass)
{
// Render transparent depth prepass after opaque one
using (new ProfilingSample(cmd, "Transparent Depth Prepass", GetSampler(CustomSamplerId.TransparentDepthPrepass)))
{
RenderTransparentRenderList(cull, camera, renderContext, cmd, m_TransparentDepthPrePassNames);
// Render transparent depth prepass after opaque one
using (new ProfilingSample(cmd, "Transparent Depth Prepass", GetSampler(CustomSamplerId.TransparentDepthPrepass)))
{
RenderTransparentRenderList(cull, camera, renderContext, cmd, m_TransparentDepthPrePassNames);
}
}
}
// RenderGBuffer do the gbuffer pass. This is solely call with deferred. If we use a depth prepass, then the depth prepass will perform the alpha testing for opaque apha tested and we don't need to do it anymore

void RenderDBuffer(Vector3 cameraPos, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
if (!m_FrameSettings.enableDBuffer)
return ;
return;
using (new ProfilingSample(cmd, "DBuffer", GetSampler(CustomSamplerId.DBuffer)))
{

{
// Rendering the sky is the first time in the frame where we need fog parameters so we push them here for the whole frame.
var visualEnv = VolumeManager.instance.stack.GetComponent<VisualEnvironment>();
visualEnv.PushFogShaderParameters(cmd, m_DebugDisplaySettings.renderingDebugSettings);
visualEnv.PushFogShaderParameters(cmd, m_FrameSettings);
if(visualEnv.fogType != FogType.None)
m_SkyManager.RenderOpaqueAtmosphericScattering(cmd);
if (visualEnv.fogType != FogType.None)
m_SkyManager.RenderOpaqueAtmosphericScattering(cmd);
}
public Texture2D ExportSkyToTexture()

if (debugMode == FullScreenDebugMode.PreRefractionColorPyramid)
{
if (!m_FrameSettings.enableRoughRefraction)
return;
return;
}
else if (debugMode == FullScreenDebugMode.FinalColorPyramid)
{

42
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


var varianceInit3 = varianceInit;
varianceInit3.baseInit.shadowmapFormat = ShadowVariance.GetFormat( true, false, true );
m_Shadowmaps = new ShadowmapBase[] { new ShadowVariance( ref varianceInit ), new ShadowVariance( ref varianceInit2 ), new ShadowVariance( ref varianceInit3 ), new ShadowAtlas( ref atlasInit ) };
m_Shadowmaps = new ShadowmapBase[] { new ShadowVariance(ref varianceInit), new ShadowVariance(ref varianceInit2), new ShadowVariance(ref varianceInit3), new ShadowAtlas(ref atlasInit) };
ShadowContext.SyncDel syncer = (ShadowContext sc) =>
{

RenderTargetIdentifier[] tex;
sc.GetTex2DArrays(out tex, out offset, out count);
// bind buffers
cb.SetGlobalBuffer(HDShaderIDs._ShadowDatasExp, s_ShadowDataBuffer);
cb.SetGlobalBuffer(HDShaderIDs._ShadowPayloads, s_ShadowPayloadBuffer);
// bind textures
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_0, tex[0]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_1, tex[1]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_2, tex[2]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_PCF, tex[3]);
// bind buffers
cb.SetGlobalBuffer(HDShaderIDs._ShadowDatasExp, s_ShadowDataBuffer);
cb.SetGlobalBuffer(HDShaderIDs._ShadowPayloads, s_ShadowPayloadBuffer);
// bind textures
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_0, tex[0]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_1, tex[1]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_VSM_2, tex[2]);
cb.SetGlobalTexture(HDShaderIDs._ShadowmapExp_PCF, tex[3]);
// TODO: Currently samplers are hard coded in ShadowContext.hlsl, so we can't really set them here
};

s_GlobalLightListAtomic = new ComputeBuffer(1, sizeof(uint));
}
s_GenListPerBigTileKernel = buildPerBigTileLightListShader.FindKernel("BigTileLightListGen");
s_GenListPerBigTileKernel = buildPerBigTileLightListShader.FindKernel("BigTileLightListGen");
s_BuildDispatchIndirectKernel = buildDispatchIndirectShader.FindKernel("BuildDispatchIndirect");
s_ClearDispatchIndirectKernel = clearDispatchIndirectShader.FindKernel("ClearDispatchIndirect");

{
for (int shadowMask = 0; shadowMask < 2; ++shadowMask)
{
for (int debugDisplay = 0; debugDisplay < 2; ++debugDisplay)
{
for (int debugDisplay = 0; debugDisplay < 2; ++debugDisplay)
{
}
}
CoreUtils.Destroy(m_DebugViewTilesMaterial);
}

s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? "TileLightListGen_SrcBigTile_FeatureFlags" : "TileLightListGen_FeatureFlags");
}
else
{
{
s_GenListPerTileKernel = buildPerTileLightListShader.FindKernel(m_FrameSettings.lightLoopSettings.enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen");
}

public bool PrepareLightsForGPU(CommandBuffer cmd, ShadowSettings shadowSettings, CullResults cullResults, Camera camera)
{
using (new ProfilingSample(cmd, "Prepare Lights For GPU"))
{
{
// If any light require it, we need to enabled bake shadow mask feature
m_enableBakeShadowMask = false;

s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes);
}
void PushGlobalParams(Camera camera, CommandBuffer cmd)
void PushGlobalParams(Camera camera, CommandBuffer cmd)
{
using (new ProfilingSample(cmd, "Push Global Parameters", HDRenderPipeline.GetSampler(CustomSamplerId.TPPushGlobalParameters)))
{

cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, s_BigTileLightList);
// Cluster
{
{
cmd.SetGlobalFloat(HDShaderIDs.g_fClustScale, m_ClustScale);
cmd.SetGlobalFloat(HDShaderIDs.g_fClustBase, k_ClustLogBase);
cmd.SetGlobalFloat(HDShaderIDs.g_fNearPlane, camera.nearClipPlane);

cmd.SetGlobalBuffer(HDShaderIDs.g_vLayeredOffsetsBuffer, s_PerVoxelOffset);
if (k_UseDepthBuffer)
{
if (k_UseDepthBuffer)
{
}
}
}
}
}
}

13
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.cs


{
// 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");

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 );
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 abstract void PushShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug);
public abstract void PushShaderParameters(CommandBuffer cmd, FrameSettings frameSettings);
public static void PushNeutralShaderParameters(CommandBuffer cmd)
{

public void PushShaderParametersCommon(CommandBuffer cmd, FrameSettings frameSettings)
public void PushShaderParametersCommon(CommandBuffer cmd, FogType type, FrameSettings frameSettings)
if(frameSettings.enableAtmosphericScattering)
if (frameSettings.enableAtmosphericScattering)
cmd.SetGlobalFloat(m_TypeParam, (float)type);
else
cmd.SetGlobalFloat(m_TypeParam, (float)FogType.None);

Linear,
Exponential
}
[Serializable]
public sealed class FogTypeParameter : VolumeParameter<FogType>
{

}
}
[GenerateHLSL]
public enum FogColorMode
{

[Serializable]
public sealed class FogColorParameter : VolumeParameter<FogColorMode> { }
}

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/ExponentialFog.cs


public MinFloatParameter fogDistance = new MinFloatParameter(200.0f, 0.0f);
public override void PushShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug)
public override void PushShaderParameters(CommandBuffer cmd, FrameSettings frameSettings)
PushShaderParametersCommon(cmd, FogType.Exponential, renderingDebug);
PushShaderParametersCommon(cmd, FogType.Exponential, frameSettings);
cmd.SetGlobalVector(m_ExpFogParam, new Vector4(Mathf.Max(0.0f, fogDistance), 0.0f, 0.0f, 0.0f));
}
}

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/LinearFog.cs


public MinFloatParameter fogStart = new MinFloatParameter(500.0f, 0.0f);
public MinFloatParameter fogEnd = new MinFloatParameter(1000.0f, 0.0f);
public override void PushShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug)
public override void PushShaderParameters(CommandBuffer cmd, FrameSettings frameSettings)
PushShaderParametersCommon(cmd, FogType.Linear, renderingDebug);
PushShaderParametersCommon(cmd, FogType.Linear, frameSettings);
cmd.SetGlobalVector(m_LinearFogParam, new Vector4(fogStart, fogEnd, 1.0f / (fogEnd - fogStart), 0.0f));
}
}

34
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


else
return m_VisualSky.reflectionTexture;
}
}
}
{
{
{
{
{
{
}
}
{
{
}
}
m_VisualSky.skySettings = newSkySettings;
m_BakingSky.skySettings = SkySettings.GetBakingSkySettings();

public bool IsSkyValid()
{
return m_VisualSky.IsValid();
}
}
void BlitCubemap(CommandBuffer cmd, Cubemap source, RenderTexture dest)

// where the GI system sometimes update the ambient probe and sometime does not...
DynamicGI.UpdateEnvironment();
m_NeedUpdateBakingSky = false;
m_NeedUpdateBakingSky = false;
}
if (m_NeedUpdateRealtimeEnv)

m_NeedUpdateBakingSky = m_BakingSky.UpdateEnvironment(camera, sunLight, m_UpdateRequired, cmd);
if (m_LightingOverrideSky.IsValid())
{
{
{
{
}
}
m_UpdateRequired = false;

if (IsSkyValid())
{
cmd.SetGlobalInt(HDShaderIDs._EnvLightSkyEnabled, 1);
}
}
}
}
}
}
CoreUtils.DrawFullScreen(cmd, m_OpaqueAtmScatteringMaterial);
}
CoreUtils.DrawFullScreen(cmd, m_OpaqueAtmScatteringMaterial);
}
public Texture2D ExportSkyToTexture()
{

6
ScriptableRenderPipeline/HDRenderPipeline/Sky/VisualEnvironment.cs


public SkyTypeParameter skyType = new SkyTypeParameter(SkyType.None);
public FogTypeParameter fogType = new FogTypeParameter(FogType.None);
public void PushFogShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug)
public void PushFogShaderParameters(CommandBuffer cmd, FrameSettings frameSettings)
{
switch (fogType.value)
{

case FogType.Linear:
{
var fogSettings = VolumeManager.instance.stack.GetComponent<LinearFog>();
fogSettings.PushShaderParameters(cmd, renderingDebug);
fogSettings.PushShaderParameters(cmd, frameSettings);
fogSettings.PushShaderParameters(cmd, renderingDebug);
fogSettings.PushShaderParameters(cmd, frameSettings);
break;
}
}

正在加载...
取消
保存