Skip to content

Commit 51e3147

Browse files
committed
Restrict sun source to only directional lights and display warning message if user changes the sun light type.
1 parent 6650434 commit 51e3147

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineLightEditor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Styles
2525

2626
public readonly GUIContent BakingWarning = EditorGUIUtility.TrTextContent("Light mode is currently overridden to Realtime mode. Enable Baked Global Illumination to use Mixed or Baked light modes.");
2727
public readonly GUIContent DisabledLightWarning = EditorGUIUtility.TrTextContent("Lighting has been disabled in at least one Scene view. Any changes applied to lights in the Scene will not be updated in these views until Lighting has been enabled again.");
28+
public readonly GUIContent SunSourceWarning = EditorGUIUtility.TrTextContent("This light is set as the current Sun Source, which requires a directional light. Go to the Lighting Environment settings to edit the Sun Source.");
2829

2930
public readonly GUIContent ShadowsNotSupportedWarning = EditorGUIUtility.TrTextContent("Realtime shadows for point lights are not supported. Either disable shadows or set the light mode to Baked.");
3031
public static readonly GUIContent ShadowRealtimeSettings = EditorGUIUtility.TrTextContent("Realtime Shadows", "Settings for realtime direct shadows.");
@@ -111,6 +112,12 @@ public override void OnInspectorGUI()
111112

112113
settings.DrawLightType();
113114

115+
Light light = target as Light;
116+
if (LightType.Directional != light.type && light == RenderSettings.sun)
117+
{
118+
EditorGUILayout.HelpBox(s_Styles.SunSourceWarning.text, MessageType.Warning);
119+
}
120+
114121
EditorGUILayout.Space();
115122

116123
// When we are switching between two light types that don't show the range (directional and area lights)
@@ -141,7 +148,6 @@ public override void OnInspectorGUI()
141148
using (var group = new EditorGUILayout.FadeGroupScope(1.0f - m_AnimAreaOptions.faded))
142149
if (group.visible)
143150
{
144-
Light light = target as Light;
145151
if (light.type != LightType.Disc)
146152
{
147153
settings.DrawLightmapping();

com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -861,14 +861,18 @@ static int GetMainLightIndex(UniversalRenderPipelineAsset settings, NativeArray<
861861
if (currLight == null)
862862
break;
863863

864-
if (currLight == sunLight)
865-
return i;
866-
867-
// In case no shadow light is present we will return the brightest directional light
868-
if (currVisibleLight.lightType == LightType.Directional && currLight.intensity > brightestLightIntensity)
864+
if (currVisibleLight.lightType == LightType.Directional)
869865
{
870-
brightestLightIntensity = currLight.intensity;
871-
brightestDirectionalLightIndex = i;
866+
// Sun source needs be a directional light
867+
if (currLight == sunLight)
868+
return i;
869+
870+
// In case no shadow light is present we will return the brightest directional light
871+
if (currLight.intensity > brightestLightIntensity)
872+
{
873+
brightestLightIntensity = currLight.intensity;
874+
brightestDirectionalLightIndex = i;
875+
}
872876
}
873877
}
874878

0 commit comments

Comments
 (0)