浏览代码

Fixed "Baked sky" behavior in new sky volume system.

/main
Julien Ignace 7 年前
当前提交
dd1baa91
共有 4 个文件被更改,包括 81 次插入23 次删除
  1. 51
      ScriptableRenderPipeline/Core/CoreUtils.cs
  2. 41
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  3. 10
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyRenderingContext.cs
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs

51
ScriptableRenderPipeline/Core/CoreUtils.cs


public const int assetCreateMenuPriority1 = 230;
public const int assetCreateMenuPriority2 = 241;
static Cubemap m_BlackCubeTexture;
public static Cubemap blackCubeTexture
{
get
{
if (m_BlackCubeTexture == null)
{
m_BlackCubeTexture = new Cubemap(1, TextureFormat.ARGB32, false);
for (int i = 0; i < 6; ++i)
m_BlackCubeTexture.SetPixel((CubemapFace)i, 0, 0, Color.black);
m_BlackCubeTexture.Apply();
}
return m_BlackCubeTexture;
}
}
static Cubemap m_MagentaCubeTexture;
public static Cubemap magentaCubeTexture
{
get
{
if (m_MagentaCubeTexture == null)
{
m_MagentaCubeTexture = new Cubemap(1, TextureFormat.ARGB32, false);
for (int i = 0; i < 6; ++i)
m_MagentaCubeTexture.SetPixel((CubemapFace)i, 0, 0, Color.magenta);
m_MagentaCubeTexture.Apply();
}
return m_MagentaCubeTexture;
}
}
static Cubemap m_WhiteCubeTexture;
public static Cubemap whiteCubeTexture
{
get
{
if (m_WhiteCubeTexture == null)
{
m_WhiteCubeTexture = new Cubemap(1, TextureFormat.ARGB32, false);
for (int i = 0; i < 6; ++i)
m_WhiteCubeTexture.SetPixel((CubemapFace)i, 0, 0, Color.white);
m_WhiteCubeTexture.Apply();
}
return m_WhiteCubeTexture;
}
}
// Render Target Management.
public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier buffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = 0)
{

41
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


int m_LastFrameUpdated = -1;
bool m_UpdateRequired =false;
bool m_NeedUpdateSkyMaterialFromBaking = false;
bool m_NeedUpdateBakingSky = false;
// This is the sky used for rendering in the main view. It will also be used for lighting if no lighting override sky is setup.
// Ambient Probe: Only for real time GI (otherwise we use the baked one)

public void UpdateEnvironment(HDCamera camera, Light sunLight, CommandBuffer cmd)
{
// WORKAROUND for building the player.
// When building the player, for some reason we end up in a state where frameCount is not updated but all currently setup shader texture are reset to null
// resulting in a rendering error (compute shader property not bound) that makes the player building fails...
// So we just check if the texture is bound here so that we can setup a pink one to avoid the error without breaking half the world.
if(Shader.GetGlobalTexture(HDShaderIDs._SkyTexture) == null)
cmd.SetGlobalTexture(HDShaderIDs._SkyTexture, CoreUtils.magentaCubeTexture);
// Both m_NeedUpdateSkyMaterialFromBaking and m_NeedUpdateRealtimeEnv are done here because we need to wait for one frame that the command buffer is executed before using the resulting textures.
if(m_NeedUpdateSkyMaterialFromBaking)
// This is done here because we need to wait for one frame that the command buffer is executed before using the resulting textures.
if (m_NeedUpdateBakingSky)
using (new ProfilingSample(cmd, "DynamicGI.UpdateEnvironment"))
{
// Here we update the global SkyMaterial so that it uses our baking sky cubemap. This way, next time the GI is baked, the right sky will be present.
float intensity = m_BakingSky.IsValid() ? 1.0f : 0.0f; // Eliminate all diffuse if we don't have a skybox (meaning for now the background is black in HDRP)
m_StandardSkyboxMaterial.SetTexture("_Tex", m_BakingSky.cubemapRT);
RenderSettings.skybox = m_StandardSkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = intensity;
RenderSettings.ambientMode = AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = intensity;
RenderSettings.customReflection = null;
DynamicGI.UpdateEnvironment();
// Here we update the global SkyMaterial so that it uses our baking sky cubemap. This way, next time the GI is baked, the right sky will be present.
float intensity = m_BakingSky.IsValid() ? 1.0f : 0.0f; // Eliminate all diffuse if we don't have a skybox (meaning for now the background is black in HDRP)
m_StandardSkyboxMaterial.SetTexture("_Tex", m_BakingSky.cubemapRT);
RenderSettings.skybox = m_StandardSkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = intensity;
RenderSettings.ambientMode = AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = intensity;
RenderSettings.customReflection = null;
// Strictly speaking, this should not be necessary, but it helps avoiding inconsistent behavior in the editor
// where the GI system sometimes update the ambient probe and sometime does not...
DynamicGI.UpdateEnvironment();
m_NeedUpdateSkyMaterialFromBaking = false;
}
m_NeedUpdateBakingSky = false;
}
if(m_NeedUpdateRealtimeEnv)

UpdateCurrentSkySettings();
m_NeedUpdateSkyMaterialFromBaking = m_BakingSky.UpdateEnvironment(camera, sunLight, m_UpdateRequired, cmd);
m_NeedUpdateBakingSky = m_BakingSky.UpdateEnvironment(camera, sunLight, m_UpdateRequired, cmd);
if(m_LightingOverrideSky.IsValid())
{
m_NeedUpdateRealtimeEnv = m_LightingOverrideSky.UpdateEnvironment(camera, sunLight, m_UpdateRequired, cmd);

10
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyRenderingContext.cs


}
else
{
if (m_SkyParametersHash != 0 && m_SupportsConvolution)
if (m_SkyParametersHash != 0)
using (new ProfilingSample(cmd, "Reset Sky Environment"))
if(m_SupportsConvolution)
m_SkyParametersHash = 0;
result = true;
m_SkyParametersHash = 0;
result = true;
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs


protected override void OnDisable()
{
m_BakingSkySettings.Remove(this);
OnValidate();
}
public void OnValidate()

正在加载...
取消
保存