浏览代码

Fix Awake issue

/main
RSlysz 6 年前
当前提交
a7c6f9bf
共有 4 个文件被更改,包括 119 次插入120 次删除
  1. 94
      com.unity.render-pipelines.core/CoreRP/Shadow/AdditionalShadowData.cs
  2. 3
      com.unity.render-pipelines.core/CoreRP/Utilities/CoreUtils.cs
  3. 6
      com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs
  4. 136
      com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs

94
com.unity.render-pipelines.core/CoreRP/Shadow/AdditionalShadowData.cs


}
[Range(0.0f, 1.0f)]
public float shadowDimmer;
public float shadowFadeDistance;
public bool contactShadows;
public float shadowDimmer = 1.0f;
public float shadowFadeDistance = 10000.0f;
public bool contactShadows = false;
public float viewBiasMin;
public float viewBiasMax;
public float viewBiasMin = 0.5f;
public float viewBiasMax = 10f;
public float viewBiasScale;
public float normalBiasMin;
public float normalBiasMax;
public float viewBiasScale = 1.0f;
public float normalBiasMin = 0.2f;
public float normalBiasMax = 4.0f;
public float normalBiasScale;
public bool sampleBiasScale;
public bool edgeLeakFixup;
public bool edgeToleranceNormal;
public float normalBiasScale = 1.0f;
public bool sampleBiasScale = true;
public bool edgeLeakFixup = false; // Causes large banding artifacts
public bool edgeToleranceNormal = true;
public float edgeTolerance;
public float edgeTolerance = 1.0f;
// shadow related parameters

};
[HideInInspector, SerializeField]
private int shadowCascadeCount;
private int shadowCascadeCount = 4;
private float[] shadowCascadeRatios;
private float[] shadowCascadeRatios = new float[3] { 0.05f, 0.2f, 0.3f };
private float[] shadowCascadeBorders;
private float[] shadowCascadeBorders = new float[4] { 0.2f, 0.2f, 0.2f, 0.2f };
private int shadowAlgorithm;
private int shadowAlgorithm = 0;
private int shadowVariant;
private int shadowVariant = 0;
private int shadowPrecision;
private int shadowPrecision = 0;
private ShadowData shadowData;
private ShadowData shadowData = new ShadowData();
[HideInInspector, SerializeField]
private ShadowData[] shadowDatas = new ShadowData[0];

return -1;
}
private void Awake()
{
Reset(); //Init
}
public void Reset()
public void CopyTo(AdditionalShadowData data)
shadowResolution = DefaultShadowResolution;
shadowDimmer = 1.0f;
shadowFadeDistance = 10000.0f;
contactShadows = false;
viewBiasMin = 0.5f;
viewBiasMax = 10.0f;
viewBiasScale = 1.0f;
normalBiasMin = 0.2f;
normalBiasMax = 4.0f;
normalBiasScale = 1.0f;
sampleBiasScale = true;
edgeLeakFixup = false; // Causes large banding artifacts
edgeToleranceNormal = true;
edgeTolerance = 1.0f;
shadowCascadeCount = 4;
shadowCascadeRatios = new float[3] { 0.05f, 0.2f, 0.3f };
shadowCascadeBorders = new float[4] { 0.2f, 0.2f, 0.2f, 0.2f };
shadowAlgorithm = 0;
shadowVariant = 0;
shadowPrecision = 0;
shadowData = new ShadowData();
shadowDatas = new ShadowData[0];
data.shadowResolution = shadowResolution;
data.shadowDimmer = shadowDimmer;
data.shadowFadeDistance = shadowFadeDistance;
data.contactShadows = contactShadows;
data.viewBiasMin = viewBiasMin;
data.viewBiasMax = viewBiasMax;
data.viewBiasScale = viewBiasScale;
data.normalBiasMin = normalBiasMin;
data.normalBiasMax = normalBiasMax;
data.normalBiasScale = normalBiasScale;
data.sampleBiasScale = sampleBiasScale;
data.edgeLeakFixup = edgeLeakFixup;
data.edgeToleranceNormal = edgeToleranceNormal;
data.edgeTolerance = edgeTolerance;
data.shadowCascadeCount = shadowCascadeCount;
data.shadowCascadeRatios = new float[shadowCascadeRatios.Length];
shadowCascadeRatios.CopyTo(data.shadowCascadeRatios, 0);
data.shadowCascadeBorders = new float[shadowCascadeBorders.Length];
shadowCascadeBorders.CopyTo(data.shadowCascadeBorders, 0);
data.shadowAlgorithm = shadowAlgorithm;
data.shadowVariant = shadowVariant;
data.shadowPrecision = shadowPrecision;
data.shadowData = shadowData;
data.shadowDatas = new ShadowData[shadowDatas.Length];
shadowDatas.CopyTo(data.shadowDatas, 0);
}
}

3
com.unity.render-pipelines.core/CoreRP/Utilities/CoreUtils.cs


public static class CoreUtils
{
// Keep a reference to default values for Reset purpose
static public AdditionalShadowData s_DefaultAdditionalShadowData { get { return ComponentSingleton<AdditionalShadowData>.instance; } }
// Data useful for various cubemap processes.
// Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/bb204881(v=vs.85).aspx
static public readonly Vector3[] lookAtList =

6
com.unity.render-pipelines.high-definition/HDRP/Editor/Lighting/HDLightEditor.cs


Undo.RecordObjects(new UnityEngine.Object[] { light, lightAdditionalData, shadowAdditionalData }, "Reset HD Light");
light.Reset();
lightAdditionalData.Reset();
shadowAdditionalData.Reset();
// To avoid duplicating init code we copy default settings to Reset additional data
// Note: we can't call this code inside the HDAdditionalLightData, thus why we don't wrap it in a Reset() function
HDUtils.s_DefaultHDAdditionalLightData.CopyTo(lightAdditionalData);
CoreUtils.s_DefaultAdditionalShadowData.CopyTo(shadowAdditionalData);
}
sealed class SerializedLightData

136
com.unity.render-pipelines.high-definition/HDRP/Lighting/Light/HDAdditionalLightData.cs


// To be able to have correct default values for our lights and to also control the conversion of intensity from the light editor (so it is compatible with GI)
// we add intensity (for each type of light we want to manage).
[System.Obsolete("directionalIntensity is deprecated, use intensity and lightUnit instead")]
public float directionalIntensity;
public float directionalIntensity = k_DefaultDirectionalLightIntensity;
public float punctualIntensity;
public float punctualIntensity = k_DefaultPunctualLightIntensity;
public float areaIntensity;
public float areaIntensity = k_DefaultAreaLightIntensity;
public const float k_DefaultDirectionalLightIntensity = Mathf.PI; // In lux
public const float k_DefaultPunctualLightIntensity = 600.0f; // Light default to 600 lumen, i.e ~48 candela

}
// Only for Spotlight, should be hide for other light
public bool enableSpotReflector;
public bool enableSpotReflector = false;
[Range(0.0f, 100.0f)]
public float m_InnerSpotPercent; // To display this field in the UI this need to be public

}
[Range(0.0f, 1.0f)]
public float lightDimmer;
public float lightDimmer = 1.0f;
public float volumetricDimmer;
public float volumetricDimmer = 1.0f;
public LightUnit lightUnit;
public LightUnit lightUnit = LightUnit.Lumen;
public float fadeDistance;
public float fadeDistance = 10000.0f;
public bool affectDiffuse;
public bool affectSpecular;
public bool affectDiffuse = true;
public bool affectSpecular = true;
public bool nonLightmappedOnly;
public bool nonLightmappedOnly = false;
public LightTypeExtent lightTypeExtent;
public LightTypeExtent lightTypeExtent = LightTypeExtent.Punctual;
public SpotLightShape spotLightShape;
public SpotLightShape spotLightShape = SpotLightShape.Cone;
public float shapeWidth;
public float shapeWidth = 0.5f;
public float shapeHeight;
public float shapeHeight = 0.5f;
public float aspectRatio;
public float aspectRatio = 1.0f;
// Only for Sphere/Disc
public float shapeRadius;

public float maxSmoothness;
public float maxSmoothness = 1.0f;
public bool applyRangeAttenuation;
public bool applyRangeAttenuation = true;
public bool useOldInspector;
public bool featuresFoldout;
public bool showAdditionalSettings;
public bool useOldInspector = false;
public bool featuresFoldout = true;
public bool showAdditionalSettings = false;
public bool displayAreaLightEmissiveMesh;
public bool displayAreaLightEmissiveMesh = false;
// Duplication of HDLightEditor.k_MinAreaWidth, maybe do something about that
const float k_MinAreaWidth = 0.01f; // Provide a small size of 1cm for line light

[System.NonSerialized]
TimelineWorkaround timelineWorkaround;
TimelineWorkaround timelineWorkaround = new TimelineWorkaround();
bool needsIntensityUpdate_1_0;
bool needsIntensityUpdate_1_0 = false;
Light _light;
Light m_Light
Light _light;
Light m_Light
{
get
{

SetLightIntensityPunctual(intensity);
break;
case LightTypeExtent.Line:
m_Light.intensity = LightUtils.CalculateLineLightLumenToLuminance(intensity, shapeWidth);
m_Light.intensity = LightUtils.CalculateLineLightLumenToLuminance(intensity, shapeWidth);
break;
case LightTypeExtent.Rectangle:
m_Light.intensity = LightUtils.ConvertRectLightLumenToLuminance(intensity, shapeWidth, shapeHeight);

else
m_Light.intensity = intensity;
#if UNITY_EDITOR
#if UNITY_EDITOR
#endif
#endif
}
void SetLightIntensityPunctual(float intensity)

}
if (m_Light.color != timelineWorkaround.oldLightColor
|| transform.localScale !=timelineWorkaround.oldLocalScale
|| transform.localScale != timelineWorkaround.oldLocalScale
|| lightTypeExtent !=timelineWorkaround.oldLightTypeExtent
|| lightTypeExtent != timelineWorkaround.oldLightTypeExtent
|| m_Light.colorTemperature != timelineWorkaround.oldLightColorTemperature)
{
UpdateAreaLightEmissiveMesh();

public void UpdateAreaLightEmissiveMesh()
{
MeshRenderer emissiveMeshRenderer = GetComponent<MeshRenderer>();
MeshFilter emissiveMeshFilter = GetComponent<MeshFilter>();
MeshRenderer emissiveMeshRenderer = GetComponent<MeshRenderer>();
MeshFilter emissiveMeshFilter = GetComponent<MeshFilter>();
bool displayEmissiveMesh = IsAreaLight(lightTypeExtent) && lightTypeExtent != LightTypeExtent.Line && displayAreaLightEmissiveMesh;

DestroyImmediate(emissiveMeshFilter);
// We don't have anything to do left if the dislay emissive mesh option is disabled
return ;
return;
}
Vector3 lightSize;

}
#endif
private void Awake()
{
Reset(); //init
}
public void Reset()
public void CopyTo(HDAdditionalLightData data)
directionalIntensity = k_DefaultDirectionalLightIntensity;
punctualIntensity = k_DefaultPunctualLightIntensity;
areaIntensity = k_DefaultAreaLightIntensity;
enableSpotReflector = false;
m_InnerSpotPercent = 0.0f;
lightDimmer = 1.0f;
volumetricDimmer = 1.0f;
lightUnit = LightUnit.Lumen;
fadeDistance = 10000.0f;
affectDiffuse = true;
affectSpecular = true;
nonLightmappedOnly = false;
lightTypeExtent = LightTypeExtent.Punctual;
spotLightShape = SpotLightShape.Cone;
shapeWidth = 0.5f;
shapeHeight = 0.5f;
aspectRatio = 1.0f;
shapeRadius = 0.0f;
maxSmoothness = 1.0f;
applyRangeAttenuation = true;
useOldInspector = false;
featuresFoldout = true;
showAdditionalSettings = false;
displayLightIntensity = 0f;
displayAreaLightEmissiveMesh = false;
needsIntensityUpdate_1_0 = false;
#pragma warning disable 0618
data.directionalIntensity = directionalIntensity;
data.punctualIntensity = punctualIntensity;
data.areaIntensity = areaIntensity;
#pragma warning restore 0618
data.enableSpotReflector = enableSpotReflector;
data.m_InnerSpotPercent = m_InnerSpotPercent;
data.lightDimmer = lightDimmer;
data.volumetricDimmer = volumetricDimmer;
data.lightUnit = lightUnit;
data.fadeDistance = fadeDistance;
data.affectDiffuse = affectDiffuse;
data.affectSpecular = affectSpecular;
data.nonLightmappedOnly = nonLightmappedOnly;
data.lightTypeExtent = lightTypeExtent;
data.spotLightShape = spotLightShape;
data.shapeWidth = shapeWidth;
data.shapeHeight = shapeHeight;
data.aspectRatio = aspectRatio;
data.shapeRadius = shapeRadius;
data.maxSmoothness = maxSmoothness;
data.applyRangeAttenuation = applyRangeAttenuation;
data.useOldInspector = useOldInspector;
data.featuresFoldout = featuresFoldout;
data.showAdditionalSettings = showAdditionalSettings;
data.displayLightIntensity = displayLightIntensity;
data.displayAreaLightEmissiveMesh = displayAreaLightEmissiveMesh;
data.needsIntensityUpdate_1_0 = needsIntensityUpdate_1_0;
timelineWorkaround = new TimelineWorkaround();
data.timelineWorkaround = timelineWorkaround;
InitDefaultHDAdditionalLightData(this);
}
// As we have our own default value, we need to initialize the light intensity correctly

light.lightShadowCasterMode = LightShadowCasterMode.Everything;
}
public void OnBeforeSerialize() {}
public void OnBeforeSerialize() { }
public void OnAfterDeserialize()
{

{
if (needsIntensityUpdate_1_0)
{
// Pragma to disable the warning got by using deprecated properties (areaIntensity, directionalIntensity, ...)
// Pragma to disable the warning got by using deprecated properties (areaIntensity, directionalIntensity, ...)
#pragma warning disable 0618
switch (lightTypeExtent)
{

正在加载...
取消
保存