浏览代码

GC fix (5.1KB)

/stochastic_alpha_test
Thomas 7 年前
当前提交
adfcd879
共有 4 个文件被更改,包括 68 次插入30 次删除
  1. 16
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs
  2. 41
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs
  3. 14
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  4. 27
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs

16
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
public class HDRISkySettings
: SkySettings
public class HDRISkySettings : SkySettings
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = skyHDRI != null ? hash * 23 + skyHDRI.GetHashCode() : hash;
}
return hash;
}
}
}

41
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs


{
return new ProceduralSkyRenderer(this);
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = hash * 23 + worldMieColorIntensity.GetHashCode();
hash = worldMieColorRamp != null ? hash * 23 + worldMieColorRamp.GetHashCode() : hash;
hash = hash * 23 + worldMieDensity.GetHashCode();
hash = hash * 23 + worldMieExtinctionFactor.GetHashCode();
hash = hash * 23 + worldMieNearScatterPush.GetHashCode();
hash = hash * 23 + worldMiePhaseAnisotropy.GetHashCode();
hash = hash * 23 + worldNormalDistance.GetHashCode();
hash = hash * 23 + worldRayleighColorIntensity.GetHashCode();
hash = worldRayleighColorRamp != null ? hash * 23 + worldRayleighColorRamp.GetHashCode() : hash;
hash = hash * 23 + worldRayleighDensity.GetHashCode();
hash = hash * 23 + worldRayleighExtinctionFactor.GetHashCode();
hash = hash * 23 + worldRayleighIndirectScatter.GetHashCode();
hash = hash * 23 + worldRayleighNearScatterPush.GetHashCode();
hash = hash * 23 + heightDistance.GetHashCode();
hash = hash * 23 + heightExtinctionFactor.GetHashCode();
hash = hash * 23 + heightMieDensity.GetHashCode();
hash = hash * 23 + heightMieNearScatterPush.GetHashCode();
hash = hash * 23 + heightNormalDistance.GetHashCode();
hash = hash * 23 + heightPlaneShift.GetHashCode();
hash = hash * 23 + heightRayleighColor.GetHashCode();
hash = hash * 23 + heightRayleighDensity.GetHashCode();
hash = hash * 23 + heightRayleighIntensity.GetHashCode();
hash = hash * 23 + heightRayleighNearScatterPush.GetHashCode();
hash = hash * 23 + heightSeaLevel.GetHashCode();
hash = skyHDRI != null ? hash * 23 + skyHDRI.GetHashCode() : hash;
hash = hash * 23 + worldScaleExponent.GetHashCode();
hash = hash * 23 + maxSkyDistance.GetHashCode();
hash = hash * 23 + debugMode.GetHashCode();
}
return hash;
}
}
}

14
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


m_StandardSkyboxMaterial.SetTexture("_Tex", m_SkyboxCubemapRT);
RenderSettings.skybox = IsSkyValid() ? m_StandardSkyboxMaterial : null; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.ambientMode = AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = 1.0f;
RenderSettings.customReflection = null;
DynamicGI.UpdateEnvironment();

m_BuiltinParameters.screenSize = m_CubemapScreenSize;
m_BuiltinParameters.cameraPosWS = camera.camera.transform.position;
if (
m_UpdatedFramesRequired > 0 ||
(skySettings.updateMode == EnvironementUpdateMode.OnChanged && skySettings.GetHash() != m_SkyParametersHash) ||
(skySettings.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > skySettings.updatePeriod)
)
if (m_UpdatedFramesRequired > 0 ||
(skySettings.updateMode == EnvironementUpdateMode.OnChanged && skySettings.GetHashCode() != m_SkyParametersHash) ||
(skySettings.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > skySettings.updatePeriod))
{
using (new ProfilingSample(cmd, "Sky Environment Pass"))
{

m_NeedLowLevelUpdateEnvironment = true;
m_UpdatedFramesRequired--;
m_SkyParametersHash = skySettings.GetHash();
m_SkyParametersHash = skySettings.GetHashCode();
m_SkyboxCubemapRT.imageContentsHash = new Hash128((uint)skySettings.GetHash(), 0, 0, 0);
m_SkyboxCubemapRT.imageContentsHash = new Hash128((uint)skySettings.GetHashCode(), 0, 0, 0);
#endif
}
}

27
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs


[ExecuteInEditMode]
public abstract class SkySettings : ScriptableObject
{
protected class Unhashed : Attribute {}
[Range(0,360)]
public float rotation = 0.0f;
public float exposure = 0.0f;

public float updatePeriod = 0.0f;
public Cubemap lightingOverride = null;
FieldInfo[] m_Properties;
protected void OnEnable()
{
// Enumerate properties in order to compute the hash more quickly later on.
m_Properties = GetType()
.GetFields(BindingFlags.Public | BindingFlags.Instance)
.ToArray();
}
public int GetHash()
public override int GetHashCode()
foreach (var p in m_Properties)
{
bool unhashedAttribute = p.GetCustomAttributes(typeof(Unhashed), true).Length != 0;
var obj = p.GetValue(this);
if (obj != null && !unhashedAttribute) // Sometimes it can be a null reference.
hash = hash * 23 + obj.GetHashCode();
}
hash = hash * 23 + rotation.GetHashCode();
hash = hash * 23 + exposure.GetHashCode();
hash = hash * 23 + multiplier.GetHashCode();
hash = hash * 23 + resolution.GetHashCode();
hash = hash * 23 + updateMode.GetHashCode();
hash = hash * 23 + updatePeriod.GetHashCode();
hash = lightingOverride != null ? hash * 23 + rotation.GetHashCode() : hash;
return hash;
}
}

正在加载...
取消
保存