GitHub
7 年前
当前提交
2e9e7be4
共有 12 个文件被更改,包括 1382 次插入 和 238 次删除
-
476SampleScenes/HDTest/HDRenderLoopTest.unity
-
1ScriptableRenderPipeline/Core/Shadow/AdditionalShadowData.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalCameraData.cs
-
109ScriptableRenderPipeline/HDRenderPipeline/AdditionalData/HDAdditionalLightData.cs
-
14ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightDefinition.cs
-
89ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs
-
10ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor.meta
-
265ScriptableRenderPipeline/HDRenderPipeline/Lighting/EditorLightUtilities.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/Lighting/EditorLightUtilities.cs.meta
-
13ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.cs.meta
-
628ScriptableRenderPipeline/HDRenderPipeline/Lighting/Editor/HDLightEditor.cs
|
|||
fileFormatVersion: 2 |
|||
guid: 636a5a3ca5205984e90e86aec12f7eb2 |
|||
folderAsset: yes |
|||
timeCreated: 1505218693 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Rendering; |
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
public static class EditorLightUtilities |
|||
{ |
|||
public static void DrawSpotlightGizmo(Light spotlight, bool selected) |
|||
{ |
|||
var flatRadiusAtRange = spotlight.range * Mathf.Tan(spotlight.spotAngle * Mathf.Deg2Rad * 0.5f); |
|||
|
|||
var vectorLineUp = Vector3.Normalize(spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * spotlight.range + spotlight.gameObject.transform.up * flatRadiusAtRange - spotlight.gameObject.transform.position); |
|||
var vectorLineDown = Vector3.Normalize(spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * spotlight.range + spotlight.gameObject.transform.up * -flatRadiusAtRange - spotlight.gameObject.transform.position); |
|||
var vectorLineRight = Vector3.Normalize(spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * spotlight.range + spotlight.gameObject.transform.right * flatRadiusAtRange - spotlight.gameObject.transform.position); |
|||
var vectorLineLeft = Vector3.Normalize(spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * spotlight.range + spotlight.gameObject.transform.right * -flatRadiusAtRange - spotlight.gameObject.transform.position); |
|||
|
|||
var rangeDiscDistance = Mathf.Cos(Mathf.Deg2Rad * spotlight.spotAngle / 2) * spotlight.range; |
|||
var rangeDiscRadius = spotlight.range * Mathf.Sin(spotlight.spotAngle * Mathf.Deg2Rad * 0.5f); |
|||
var nearDiscDistance = Mathf.Cos(Mathf.Deg2Rad * spotlight.spotAngle / 2) * spotlight.shadowNearPlane; |
|||
var nearDiscRadius = spotlight.shadowNearPlane * Mathf.Sin(spotlight.spotAngle * Mathf.Deg2Rad * 0.5f); |
|||
|
|||
|
|||
//Draw Range disc
|
|||
Handles.Disc(spotlight.gameObject.transform.rotation, spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * rangeDiscDistance, spotlight.gameObject.transform.forward, rangeDiscRadius, false, 1); |
|||
//Draw Lines
|
|||
|
|||
Gizmos.DrawLine(spotlight.gameObject.transform.position, spotlight.gameObject.transform.position + vectorLineUp * spotlight.range); |
|||
Gizmos.DrawLine(spotlight.gameObject.transform.position, spotlight.gameObject.transform.position + vectorLineDown * spotlight.range); |
|||
Gizmos.DrawLine(spotlight.gameObject.transform.position, spotlight.gameObject.transform.position + vectorLineRight * spotlight.range); |
|||
Gizmos.DrawLine(spotlight.gameObject.transform.position, spotlight.gameObject.transform.position + vectorLineLeft * spotlight.range); |
|||
|
|||
if (selected) |
|||
{ |
|||
//Draw Range Arcs
|
|||
Handles.DrawWireArc(spotlight.gameObject.transform.position, spotlight.gameObject.transform.right, vectorLineUp, spotlight.spotAngle, spotlight.range); |
|||
Handles.DrawWireArc(spotlight.gameObject.transform.position, spotlight.gameObject.transform.up, vectorLineLeft, spotlight.spotAngle, spotlight.range); |
|||
//Draw Near Plane Disc
|
|||
if (spotlight.shadows != LightShadows.None) Handles.Disc(spotlight.gameObject.transform.rotation, spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * nearDiscDistance, spotlight.gameObject.transform.forward, nearDiscRadius, false, 1); |
|||
|
|||
//Inner Cone
|
|||
var additionalLightData = spotlight.GetComponent<HDAdditionalLightData>(); |
|||
DrawInnerCone(spotlight,additionalLightData); |
|||
} |
|||
} |
|||
|
|||
public static void DrawInnerCone(Light spotlight, HDAdditionalLightData additionalLightData) |
|||
{ |
|||
if (additionalLightData == null) return; |
|||
|
|||
var flatRadiusAtRange = spotlight.range * Mathf.Tan(spotlight.spotAngle * additionalLightData.m_InnerSpotPercent * 0.01f * Mathf.Deg2Rad * 0.5f); |
|||
|
|||
var vectorLineUp = Vector3.Normalize(spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * spotlight.range + spotlight.gameObject.transform.up * flatRadiusAtRange - spotlight.gameObject.transform.position); |
|||
var vectorLineDown = Vector3.Normalize(spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * spotlight.range + spotlight.gameObject.transform.up * -flatRadiusAtRange - spotlight.gameObject.transform.position); |
|||
var vectorLineRight = Vector3.Normalize(spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * spotlight.range + spotlight.gameObject.transform.right * flatRadiusAtRange - spotlight.gameObject.transform.position); |
|||
var vectorLineLeft = Vector3.Normalize(spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * spotlight.range + spotlight.gameObject.transform.right * -flatRadiusAtRange - spotlight.gameObject.transform.position); |
|||
|
|||
//Draw Lines
|
|||
|
|||
Gizmos.DrawLine(spotlight.gameObject.transform.position, spotlight.gameObject.transform.position + vectorLineUp * spotlight.range); |
|||
Gizmos.DrawLine(spotlight.gameObject.transform.position, spotlight.gameObject.transform.position + vectorLineDown * spotlight.range); |
|||
Gizmos.DrawLine(spotlight.gameObject.transform.position, spotlight.gameObject.transform.position + vectorLineRight * spotlight.range); |
|||
Gizmos.DrawLine(spotlight.gameObject.transform.position, spotlight.gameObject.transform.position + vectorLineLeft * spotlight.range); |
|||
|
|||
var innerAngle = spotlight.spotAngle * additionalLightData.GetInnerSpotPercent01(); |
|||
if (innerAngle > 0) |
|||
{ |
|||
var innerDiscDistance = Mathf.Cos(Mathf.Deg2Rad * innerAngle * 0.5f) * spotlight.range; |
|||
var innerDiscRadius = spotlight.range * Mathf.Sin(innerAngle * Mathf.Deg2Rad * 0.5f); |
|||
//Draw Range disc
|
|||
Handles.Disc(spotlight.gameObject.transform.rotation, spotlight.gameObject.transform.position + spotlight.gameObject.transform.forward * innerDiscDistance, spotlight.gameObject.transform.forward, innerDiscRadius, false, 1); |
|||
} |
|||
} |
|||
|
|||
public static void DrawArealightGizmo(Light arealight) |
|||
{ |
|||
|
|||
var RectangleSize = new Vector3(arealight.areaSize.x, arealight.areaSize.y, 0); |
|||
Gizmos.matrix = arealight.transform.localToWorldMatrix; |
|||
Gizmos.DrawWireCube(Vector3.zero, RectangleSize); |
|||
Gizmos.matrix = Matrix4x4.identity; |
|||
Gizmos.DrawWireSphere(arealight.transform.position, arealight.range); |
|||
} |
|||
|
|||
public static void DrawPointlightGizmo(Light pointlight, bool selected) |
|||
{ |
|||
if (pointlight.shadows != LightShadows.None && selected) Gizmos.DrawWireSphere(pointlight.transform.position, pointlight.shadowNearPlane); |
|||
Gizmos.DrawWireSphere(pointlight.transform.position, pointlight.range); |
|||
} |
|||
|
|||
public static void DrawSpherelightGizmo(Light spherelight) |
|||
{ |
|||
var additionalLightData = spherelight.GetComponent<HDAdditionalLightData>(); |
|||
if (additionalLightData == null) return; |
|||
Gizmos.DrawSphere(spherelight.transform.position, additionalLightData.shapeLength); |
|||
if (spherelight.shadows != LightShadows.None) Gizmos.DrawWireSphere(spherelight.transform.position, spherelight.shadowNearPlane); |
|||
Gizmos.DrawWireSphere(spherelight.transform.position, spherelight.range); |
|||
} |
|||
|
|||
public static void DrawFrustumlightGizmo(Light frustumlight) |
|||
{ |
|||
var additionalLightData = frustumlight.GetComponent<HDAdditionalLightData>(); |
|||
if (additionalLightData == null) return; |
|||
var frustumSize = new Vector3(additionalLightData.shapeLength / frustumlight.gameObject.transform.localScale.x, additionalLightData.shapeWidth / frustumlight.gameObject.transform.localScale.y, frustumlight.range - frustumlight.shadowNearPlane / frustumlight.gameObject.transform.localScale.z); |
|||
Gizmos.matrix = frustumlight.transform.localToWorldMatrix; |
|||
Gizmos.DrawWireCube(Vector3.forward * (frustumSize.z * 0.5f + frustumlight.shadowNearPlane), frustumSize); |
|||
Gizmos.matrix = Matrix4x4.identity; |
|||
} |
|||
|
|||
public static void DrawDirectionalLightGizmo(Light directionalLight) |
|||
{ |
|||
var gizmoSize = 0.2f; |
|||
Handles.Disc(directionalLight.transform.rotation, directionalLight.transform.position, directionalLight.gameObject.transform.forward, gizmoSize, false, 1); |
|||
Gizmos.DrawLine(directionalLight.transform.position, directionalLight.transform.position + directionalLight.transform.forward); |
|||
Gizmos.DrawLine(directionalLight.transform.position + directionalLight.transform.up * gizmoSize, directionalLight.transform.position + directionalLight.transform.up * gizmoSize + directionalLight.transform.forward); |
|||
Gizmos.DrawLine(directionalLight.transform.position + directionalLight.transform.up * -gizmoSize, directionalLight.transform.position + directionalLight.transform.up * -gizmoSize + directionalLight.transform.forward); |
|||
Gizmos.DrawLine(directionalLight.transform.position + directionalLight.transform.right * gizmoSize, directionalLight.transform.position + directionalLight.transform.right * gizmoSize + directionalLight.transform.forward); |
|||
Gizmos.DrawLine(directionalLight.transform.position + directionalLight.transform.right * -gizmoSize, directionalLight.transform.position + directionalLight.transform.right * -gizmoSize + directionalLight.transform.forward); |
|||
} |
|||
|
|||
public static void DrawCross(Transform m_transform) |
|||
{ |
|||
var gizmoSize = 0.25f; |
|||
Gizmos.DrawLine(m_transform.position, m_transform.position + m_transform.TransformVector(m_transform.root.forward * gizmoSize / m_transform.localScale.z)); |
|||
Gizmos.DrawLine(m_transform.position, m_transform.position + m_transform.TransformVector(m_transform.root.forward * -gizmoSize / m_transform.localScale.z)); |
|||
Gizmos.DrawLine(m_transform.position, m_transform.position + m_transform.TransformVector(m_transform.root.up * gizmoSize / m_transform.localScale.y)); |
|||
Gizmos.DrawLine(m_transform.position, m_transform.position + m_transform.TransformVector(m_transform.root.up * -gizmoSize / m_transform.localScale.y)); |
|||
Gizmos.DrawLine(m_transform.position, m_transform.position + m_transform.TransformVector(m_transform.root.right * gizmoSize / m_transform.localScale.x)); |
|||
Gizmos.DrawLine(m_transform.position, m_transform.position + m_transform.TransformVector(m_transform.root.right * -gizmoSize / m_transform.localScale.x)); |
|||
} |
|||
|
|||
public static bool DrawHeader(string title, bool activeField) |
|||
{ |
|||
var backgroundRect = GUILayoutUtility.GetRect(1f, 17f); |
|||
|
|||
var labelRect = backgroundRect; |
|||
labelRect.xMin += 16f; |
|||
labelRect.xMax -= 20f; |
|||
|
|||
var toggleRect = backgroundRect; |
|||
toggleRect.y += 2f; |
|||
toggleRect.width = 13f; |
|||
toggleRect.height = 13f; |
|||
|
|||
var menuIcon = EditorGUIUtility.isProSkin |
|||
? (Texture2D)EditorGUIUtility.Load("Builtin Skins/DarkSkin/Images/pane options.png") |
|||
: (Texture2D)EditorGUIUtility.Load("Builtin Skins/LightSkin/Images/pane options.png"); |
|||
|
|||
var menuRect = new Rect(labelRect.xMax + 4f, labelRect.y + 4f, menuIcon.width, menuIcon.height); |
|||
|
|||
// Background rect should be full-width
|
|||
backgroundRect.xMin = 0f; |
|||
backgroundRect.width += 4f; |
|||
|
|||
// Background
|
|||
float backgroundTint = EditorGUIUtility.isProSkin ? 0.1f : 1f; |
|||
EditorGUI.DrawRect(backgroundRect, new Color(backgroundTint, backgroundTint, backgroundTint, 0.2f)); |
|||
|
|||
// Title
|
|||
using (new EditorGUI.DisabledScope(!activeField)) |
|||
EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel); |
|||
|
|||
// Active checkbox
|
|||
activeField = GUI.Toggle(toggleRect, activeField, GUIContent.none, new GUIStyle("ShurikenCheckMark")); |
|||
|
|||
var e = Event.current; |
|||
if (e.type == EventType.MouseDown && backgroundRect.Contains(e.mousePosition) && e.button == 0) |
|||
{ |
|||
activeField = !activeField; |
|||
e.Use(); |
|||
} |
|||
|
|||
EditorGUILayout.Space(); |
|||
|
|||
return activeField; |
|||
} |
|||
|
|||
public static void DrawHeader(string title) |
|||
{ |
|||
var backgroundRect = GUILayoutUtility.GetRect(1f, 17f); |
|||
|
|||
var labelRect = backgroundRect; |
|||
labelRect.xMin += 16f; |
|||
labelRect.xMax -= 20f; |
|||
|
|||
var foldoutRect = backgroundRect; |
|||
foldoutRect.y += 1f; |
|||
foldoutRect.width = 13f; |
|||
foldoutRect.height = 13f; |
|||
|
|||
// Background rect should be full-width
|
|||
backgroundRect.xMin = 0f; |
|||
backgroundRect.width += 4f; |
|||
|
|||
// Background
|
|||
float backgroundTint = EditorGUIUtility.isProSkin ? 0.1f : 1f; |
|||
EditorGUI.DrawRect(backgroundRect, new Color(backgroundTint, backgroundTint, backgroundTint, 0.2f)); |
|||
|
|||
// Title
|
|||
EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel); |
|||
EditorGUILayout.Space(); |
|||
} |
|||
|
|||
public static void DrawSplitter() |
|||
{ |
|||
EditorGUILayout.Space(); |
|||
var rect = GUILayoutUtility.GetRect(1f, 1f); |
|||
|
|||
// Splitter rect should be full-width
|
|||
rect.xMin = 0f; |
|||
rect.width += 4f; |
|||
|
|||
if (Event.current.type != EventType.Repaint) |
|||
return; |
|||
|
|||
EditorGUI.DrawRect(rect, !EditorGUIUtility.isProSkin |
|||
? new Color(0.6f, 0.6f, 0.6f, 1.333f) |
|||
: new Color(0.12f, 0.12f, 0.12f, 1.333f)); |
|||
} |
|||
|
|||
public static bool DrawHeaderFoldout(string title, bool state) |
|||
{ |
|||
var backgroundRect = GUILayoutUtility.GetRect(1f, 17f); |
|||
|
|||
var labelRect = backgroundRect; |
|||
labelRect.xMin += 16f; |
|||
labelRect.xMax -= 20f; |
|||
|
|||
var foldoutRect = backgroundRect; |
|||
foldoutRect.y += 1f; |
|||
foldoutRect.width = 13f; |
|||
foldoutRect.height = 13f; |
|||
|
|||
// Background rect should be full-width
|
|||
backgroundRect.xMin = 0f; |
|||
backgroundRect.width += 4f; |
|||
|
|||
// Background
|
|||
float backgroundTint = EditorGUIUtility.isProSkin ? 0.1f : 1f; |
|||
EditorGUI.DrawRect(backgroundRect, new Color(backgroundTint, backgroundTint, backgroundTint, 0.2f)); |
|||
|
|||
// Title
|
|||
EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel); |
|||
|
|||
// Active checkbox
|
|||
state = GUI.Toggle(foldoutRect, state, GUIContent.none, EditorStyles.foldout); |
|||
|
|||
var e = Event.current; |
|||
if (e.type == EventType.MouseDown && backgroundRect.Contains(e.mousePosition) && e.button == 0) |
|||
{ |
|||
state = !state; |
|||
e.Use(); |
|||
} |
|||
|
|||
return state; |
|||
} |
|||
} |
|||
#endif
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f38354ca887c51245a6780e4cd3e6609 |
|||
timeCreated: 1505227267 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: f2cd83e80bf0aee45b3de08f571be4ac |
|||
timeCreated: 1505208164 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEngine.Rendering; |
|||
using System.Linq; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
[CustomEditor(typeof(Light))] |
|||
[CanEditMultipleObjects] |
|||
public class HDLightEditor : Editor |
|||
{ |
|||
// Original light editor
|
|||
SerializedProperty m_Type; |
|||
SerializedProperty m_Range; |
|||
SerializedProperty m_SpotAngle; |
|||
SerializedProperty m_CookieSize; |
|||
SerializedProperty m_Color; |
|||
SerializedProperty m_Intensity; |
|||
SerializedProperty m_BounceIntensity; |
|||
SerializedProperty m_ColorTemperature; |
|||
SerializedProperty m_UseColorTemperature; |
|||
SerializedProperty m_Cookie; |
|||
SerializedProperty m_ShadowsType; |
|||
SerializedProperty m_ShadowsStrength; |
|||
SerializedProperty m_ShadowsResolution; |
|||
SerializedProperty m_ShadowsBias; |
|||
SerializedProperty m_ShadowsNormalBias; |
|||
SerializedProperty m_ShadowsNearPlane; |
|||
SerializedProperty m_Flare; |
|||
SerializedProperty m_RenderMode; |
|||
SerializedProperty m_CullingMask; |
|||
SerializedProperty m_Lightmapping; |
|||
SerializedProperty m_AreaSizeX; |
|||
SerializedProperty m_AreaSizeY; |
|||
SerializedProperty m_BakedShadowRadius; |
|||
SerializedProperty m_BakedShadowAngle; |
|||
|
|||
// HD Light editor part
|
|||
SerializedObject additionalDataSerializedObject; |
|||
SerializedObject shadowDataSerializedObject; |
|||
|
|||
SerializedProperty m_SpotInnerAngle; |
|||
SerializedProperty m_LightDimmer; |
|||
SerializedProperty m_FadeDistance; |
|||
SerializedProperty m_AffectDiffuse; |
|||
SerializedProperty m_AffectSpecular; |
|||
SerializedProperty m_LightTypeExtent; |
|||
SerializedProperty m_SpotLightShape; |
|||
SerializedProperty m_ShapeLength; |
|||
SerializedProperty m_ShapeWidth; |
|||
SerializedProperty m_ShapeRadius; |
|||
SerializedProperty m_MaxSmoothness; |
|||
SerializedProperty m_ApplyRangeAttenuation; |
|||
|
|||
// Extra data for GUI only
|
|||
SerializedProperty m_UseOldInspector; |
|||
SerializedProperty m_ShowAdditionalSettings; |
|||
|
|||
SerializedProperty m_ShadowDimmer; |
|||
SerializedProperty m_ShadowFadeDistance; |
|||
SerializedProperty m_ShadowCascadeCount; |
|||
SerializedProperty m_ShadowCascadeRatios; |
|||
SerializedProperty m_ShadowCascadeBorders; |
|||
SerializedProperty m_ShadowResolution; |
|||
|
|||
// This enum below is LightType enum + LightTypeExtent enum
|
|||
public enum LightShape |
|||
{ |
|||
Spot, |
|||
Directional, |
|||
Point, |
|||
//Area, <= offline type of Unity not dispay in our case but reuse for GI of our area light
|
|||
Rectangle, |
|||
Line, |
|||
// Sphere,
|
|||
// Disc,
|
|||
} |
|||
|
|||
// LightShape is use for displaying UI only. The processing code must use LightTypeExtent and LightType
|
|||
LightShape m_LightShape; |
|||
|
|||
private Light light { get { return target as Light; } } |
|||
|
|||
// Note: There is no Lightmapping enum, the code C# side must use int
|
|||
// Light.h file: int m_Lightmapping; ///< enum { Dynamic=4, Stationary=1, Static=2 }
|
|||
// Lighting.h file:
|
|||
// enum LightmapBakeType (not accessible in C#)
|
|||
//{
|
|||
// kLightRealtime = 1 << 2, // Light is realtime
|
|||
// kLightBaked = 1 << 1, // light will always be fully baked
|
|||
// kLightMixed = 1 << 0, // depends on selected LightmapMixedBakeMode
|
|||
//};
|
|||
// This mean that m_Lightmapping.enumValueIndex is enum { Stationary=0, Static=1, Dynamic=2 }
|
|||
enum LightMappingType |
|||
{ |
|||
Stationary = 0, |
|||
Static=1, |
|||
Dynamic=2 |
|||
} |
|||
|
|||
protected class Styles |
|||
{ |
|||
public static GUIContent CookieSizeX = new GUIContent("CookieSizeX", ""); |
|||
public static GUIContent CookieSizeY = new GUIContent("CookieSizeY", ""); |
|||
|
|||
public static GUIContent ShapeLengthLine = new GUIContent("Length", "Length of the line light"); |
|||
public static GUIContent ShapeLengthRect = new GUIContent("SizeX", "SizeX of the rectangle light"); |
|||
public static GUIContent ShapeWidthRect = new GUIContent("SizeY", "SizeY of the rectangle light"); |
|||
|
|||
public static GUIContent ShapeLengthPyramid = new GUIContent("SizeX", ""); |
|||
public static GUIContent ShapeWidthPyramid = new GUIContent("SizeY", ""); |
|||
|
|||
public static GUIContent ShapeLengthBox = new GUIContent("SizeX", ""); |
|||
public static GUIContent ShapeWidthBox = new GUIContent("SizeY", ""); |
|||
|
|||
public static GUIContent MaxSmoothness = new GUIContent("MaxSmoothness", "Very low cost way of faking spherical area lighting. This will modifying the roughness of the material lit. This is use when the highlight point is not visible enough."); |
|||
public static GUIContent SpotLightShape = new GUIContent("SpotLightShape", "The shape use for the spotlight. Have impact on cookie transformation and light angular attenuation."); |
|||
|
|||
public static GUIContent SpotAngle = new GUIContent("Spot Angle", "Controls the angle in degrees at the base of a Spot light's cone."); |
|||
public static GUIContent SpotInnerAngle = new GUIContent("Spot Inner Angle", "Controls the inner angle in percent of the base angle of a Spot light's cone."); |
|||
|
|||
public static GUIContent Color = new GUIContent("Color", "Controls the color being emitted by the light."); |
|||
public static GUIContent Intensity = new GUIContent("Intensity", "Controls the brightness of the light. Light color is multiplied by this value."); |
|||
|
|||
public static GUIContent Range = new GUIContent("Range", "Controls how far the light is emitted from the center of the object."); |
|||
public static GUIContent LightmappingMode = new GUIContent("Mode", "Specifies the light mode used to determine if and how a light will be baked. Possible modes are Baked, Mixed, and Realtime."); |
|||
public static GUIContent BounceIntensity = new GUIContent("Indirect Multiplier", "Controls the intensity of indirect light being contributed to the scene. A value of 0 will cause Realtime lights to be removed from realtime global illumination and Baked and Mixed lights to no longer emit indirect lighting. Has no effect when both Realtime and Baked Global Illumination are disabled."); |
|||
public static GUIContent Cookie = new GUIContent("Cookie", "Specifies the Texture mask to cast shadows, create silhouettes, or patterned illumination for the light."); |
|||
|
|||
public static GUIContent BakedShadowRadius = new GUIContent("Baked Shadow Radius", "Controls the amount of artificial softening applied to the edges of shadows cast by the Point or Spot light."); |
|||
public static GUIContent BakedShadowAngle = new GUIContent("Baked Shadow Angle", "Controls the amount of artificial softening applied to the edges of shadows cast by directional lights."); |
|||
|
|||
public static GUIContent ShadowResolution = new GUIContent("Resolution", "Controls the rendered resolution of the shadow maps. A higher resolution will increase the fidelity of shadows at the cost of GPU performance and memory usage."); |
|||
public static GUIContent ShadowBias = new GUIContent("Bias", "Controls the distance at which the shadows will be pushed away from the light. Useful for avoiding false self-shadowing artifacts."); |
|||
public static GUIContent ShadowNormalBias = new GUIContent("Normal Bias", "Controls distance at which the shadow casting surfaces will be shrunk along the surface normal. Useful for avoiding false self-shadowing artifacts."); |
|||
public static GUIContent ShadowNearPlane = new GUIContent("Near Plane", "Controls the value for the near clip plane when rendering shadows. Currently clamped to 0.1 units or 1% of the lights range property, whichever is lower."); |
|||
|
|||
|
|||
public static GUIContent ShadowCascadeCount = new GUIContent("ShadowCascadeCount", ""); |
|||
public static GUIContent[] ShadowCascadeRatios = new GUIContent[6] { new GUIContent("Cascade 1"), new GUIContent("Cascade 2"), new GUIContent("Cascade 3"), new GUIContent("Cascade 4"), new GUIContent("Cascade 5"), new GUIContent("Cascade 6") }; |
|||
|
|||
public static GUIContent AffectDiffuse = new GUIContent("AffectDiffuse", "This will disable diffuse lighting for this light. Don't save performance, diffuse lighting is still."); |
|||
public static GUIContent AffectSpecular = new GUIContent("AffectSpecular", "This will disable specular lighting for this light. Don't save performance, specular lighting is still."); |
|||
public static GUIContent FadeDistance = new GUIContent("FadeDistance", "The light color will fade at distance FadeDistance before being culled to minimize popping."); |
|||
public static GUIContent LightDimmer = new GUIContent("LightDimmer", "Aim to be use with script, timeline or animation. It allow to dim one or multiple lights of heterogeneous intensity easily (Else you need to know the intensity of each light)"); |
|||
public static GUIContent ApplyRangeAttenuation = new GUIContent("ApplyRangeAttenuation", "Allow to disable range attenuation. This aim to be use indoor (like a room) to avoid to have to setup a large range for a light to get correct inverse square attenuation that may leak out of the indoor"); |
|||
public static GUIContent ShadowFadeDistance = new GUIContent("ShadowFadeDistance", "The shadow will fade at distance ShadowFadeDistance before being culled to minimize popping."); |
|||
public static GUIContent ShadowDimmer = new GUIContent("ShadowDimmer", "Aim to be use with script, timeline or animation. It allow to dim one or multiple shadows. this can also be use to fit in shadow budget manually and minimize popping."); |
|||
|
|||
public static GUIContent DisabledLightWarning = new GUIContent("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."); |
|||
public static GUIContent CookieWarning = new GUIContent("Cookie textures for spot lights must be set to clamp. Repeat is not supported."); |
|||
public static GUIContent IndirectBounceShadowWarning = new GUIContent("Realtime indirect bounce shadowing is not supported for Spot and Point lights."); |
|||
public static GUIContent BakingWarning = new GUIContent("Light mode is currently overridden to Realtime mode. Enable Baked Global Illumination to use Mixed or Baked light modes."); |
|||
|
|||
public static string lightShapeText = "LightShape"; |
|||
public static readonly string[] lightShapeNames = Enum.GetNames(typeof(LightShape)); |
|||
} |
|||
|
|||
static Styles s_Styles; |
|||
|
|||
// Should match same colors in GizmoDrawers.cpp!
|
|||
static Color kGizmoLight = new Color(254 / 255f, 253 / 255f, 136 / 255f, 128 / 255f); |
|||
static Color kGizmoDisabledLight = new Color(135 / 255f, 116 / 255f, 50 / 255f, 128 / 255f); |
|||
|
|||
private bool typeIsSame { get { return !m_Type.hasMultipleDifferentValues; } } |
|||
private Texture cookie { get { return m_Cookie.objectReferenceValue as Texture; } } |
|||
|
|||
private bool lightmappingTypeIsSame { get { return !m_Lightmapping.hasMultipleDifferentValues; } } |
|||
|
|||
private bool isRealtime { get { return m_Lightmapping.enumValueIndex == (int)LightMappingType.Dynamic; } } |
|||
|
|||
private bool isBakedOrMixed { get { return !isRealtime; } } |
|||
|
|||
private bool bakingWarningValue { get { return !Lightmapping.bakedGI && lightmappingTypeIsSame && isBakedOrMixed; } } |
|||
|
|||
private bool cookieWarningValue |
|||
{ |
|||
get |
|||
{ |
|||
return typeIsSame && light.type == LightType.Spot && |
|||
!m_Cookie.hasMultipleDifferentValues && cookie && cookie.wrapMode != TextureWrapMode.Clamp; |
|||
} |
|||
} |
|||
private bool bounceWarningValue |
|||
{ |
|||
get |
|||
{ |
|||
return typeIsSame && (light.type == LightType.Point || light.type == LightType.Spot) && |
|||
lightmappingTypeIsSame && isRealtime && !m_BounceIntensity.hasMultipleDifferentValues && m_BounceIntensity.floatValue > 0.0f && m_ShadowsType.enumValueIndex != (int)LightShadows.None; |
|||
} |
|||
} |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
m_Type = serializedObject.FindProperty("m_Type"); |
|||
m_Range = serializedObject.FindProperty("m_Range"); |
|||
m_SpotAngle = serializedObject.FindProperty("m_SpotAngle"); |
|||
m_CookieSize = serializedObject.FindProperty("m_CookieSize"); |
|||
m_Color = serializedObject.FindProperty("m_Color"); |
|||
m_Intensity = serializedObject.FindProperty("m_Intensity"); |
|||
m_BounceIntensity = serializedObject.FindProperty("m_BounceIntensity"); |
|||
m_ColorTemperature = serializedObject.FindProperty("m_ColorTemperature"); |
|||
m_UseColorTemperature = serializedObject.FindProperty("m_UseColorTemperature"); |
|||
m_Cookie = serializedObject.FindProperty("m_Cookie"); |
|||
m_ShadowsType = serializedObject.FindProperty("m_Shadows.m_Type"); |
|||
m_ShadowsStrength = serializedObject.FindProperty("m_Shadows.m_Strength"); |
|||
m_ShadowsResolution = serializedObject.FindProperty("m_Shadows.m_Resolution"); |
|||
m_ShadowsBias = serializedObject.FindProperty("m_Shadows.m_Bias"); |
|||
m_ShadowsNormalBias = serializedObject.FindProperty("m_Shadows.m_NormalBias"); |
|||
m_ShadowsNearPlane = serializedObject.FindProperty("m_Shadows.m_NearPlane"); |
|||
m_Flare = serializedObject.FindProperty("m_Flare"); |
|||
m_RenderMode = serializedObject.FindProperty("m_RenderMode"); |
|||
m_CullingMask = serializedObject.FindProperty("m_CullingMask"); |
|||
m_Lightmapping = serializedObject.FindProperty("m_Lightmapping"); |
|||
m_AreaSizeX = serializedObject.FindProperty("m_AreaSize.x"); |
|||
m_AreaSizeY = serializedObject.FindProperty("m_AreaSize.y"); |
|||
m_BakedShadowRadius = serializedObject.FindProperty("m_ShadowRadius"); |
|||
m_BakedShadowAngle = serializedObject.FindProperty("m_ShadowAngle"); |
|||
|
|||
// Automatically add HD data if not present
|
|||
// We need to handle multiSelection. To do this we need to get the array of selection and assign it to additionalDataSerializedObject
|
|||
// additionalDataSerializedObject must be see as an array of selection in all following operation (this is transparent)
|
|||
|
|||
var additionalDatas = this.targets.Select(t => (t as Component).GetComponent<HDAdditionalLightData>()).ToArray(); |
|||
var shadowDatas = this.targets.Select(t => (t as Component).GetComponent<AdditionalShadowData>()).ToArray(); |
|||
|
|||
for (int i = 0; i < additionalDatas.Length; ++i) |
|||
{ |
|||
if (additionalDatas[i] == null) |
|||
{ |
|||
additionalDatas[i] = Undo.AddComponent<HDAdditionalLightData>((targets[i] as Component).gameObject); |
|||
} |
|||
} |
|||
|
|||
for (int i = 0; i < shadowDatas.Length; ++i) |
|||
{ |
|||
if (shadowDatas[i] == null) |
|||
{ |
|||
shadowDatas[i] = Undo.AddComponent<AdditionalShadowData>((targets[i] as Component).gameObject); |
|||
} |
|||
} |
|||
|
|||
additionalDataSerializedObject = new SerializedObject(additionalDatas); |
|||
shadowDataSerializedObject = new SerializedObject(shadowDatas); |
|||
|
|||
// Additional data
|
|||
m_SpotInnerAngle = additionalDataSerializedObject.FindProperty("m_InnerSpotPercent"); |
|||
m_LightDimmer = additionalDataSerializedObject.FindProperty("lightDimmer"); |
|||
m_FadeDistance = additionalDataSerializedObject.FindProperty("fadeDistance"); |
|||
m_AffectDiffuse = additionalDataSerializedObject.FindProperty("affectDiffuse"); |
|||
m_AffectSpecular = additionalDataSerializedObject.FindProperty("affectSpecular"); |
|||
m_LightTypeExtent = additionalDataSerializedObject.FindProperty("lightTypeExtent"); |
|||
m_SpotLightShape = additionalDataSerializedObject.FindProperty("spotLightShape"); |
|||
m_ShapeLength = additionalDataSerializedObject.FindProperty("shapeLength"); |
|||
m_ShapeWidth = additionalDataSerializedObject.FindProperty("shapeWidth"); |
|||
m_ShapeRadius = additionalDataSerializedObject.FindProperty("shapeRadius"); |
|||
m_MaxSmoothness = additionalDataSerializedObject.FindProperty("maxSmoothness"); |
|||
m_ApplyRangeAttenuation = additionalDataSerializedObject.FindProperty("applyRangeAttenuation"); |
|||
|
|||
// Editor only
|
|||
m_UseOldInspector = additionalDataSerializedObject.FindProperty("useOldInspector"); |
|||
m_ShowAdditionalSettings = additionalDataSerializedObject.FindProperty("showAdditionalSettings"); |
|||
|
|||
// Shadow data
|
|||
m_ShadowDimmer = shadowDataSerializedObject.FindProperty("shadowDimmer"); |
|||
m_ShadowFadeDistance = shadowDataSerializedObject.FindProperty("shadowFadeDistance"); |
|||
m_ShadowCascadeCount = shadowDataSerializedObject.FindProperty("shadowCascadeCount"); |
|||
m_ShadowCascadeRatios = shadowDataSerializedObject.FindProperty("shadowCascadeRatios"); |
|||
m_ShadowCascadeBorders = serializedObject.FindProperty("shadowCascadeBorders"); |
|||
m_ShadowResolution = shadowDataSerializedObject.FindProperty("shadowResolution"); |
|||
} |
|||
|
|||
void ResolveLightShape() |
|||
{ |
|||
// When we do multiple selection we must not avoid to chose a type, else it may corrupt light
|
|||
if (m_Type.hasMultipleDifferentValues) |
|||
{ |
|||
m_LightShape = (LightShape)(-1); |
|||
|
|||
return; |
|||
} |
|||
|
|||
if (m_LightTypeExtent.enumValueIndex == (int)LightTypeExtent.Punctual) |
|||
{ |
|||
switch ((LightType)m_Type.enumValueIndex) |
|||
{ |
|||
case LightType.Directional: |
|||
m_LightShape = LightShape.Directional; |
|||
break; |
|||
case LightType.Point: |
|||
m_LightShape = LightShape.Point; |
|||
break; |
|||
case LightType.Spot: |
|||
m_LightShape = LightShape.Spot; |
|||
break; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
switch ((LightTypeExtent)m_LightTypeExtent.enumValueIndex) |
|||
{ |
|||
case LightTypeExtent.Rectangle: |
|||
m_LightShape = LightShape.Rectangle; |
|||
break; |
|||
case LightTypeExtent.Line: |
|||
m_LightShape = LightShape.Line; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void LigthShapeGUI() |
|||
{ |
|||
m_LightShape = (LightShape)EditorGUILayout.Popup(Styles.lightShapeText, (int)m_LightShape, Styles.lightShapeNames); |
|||
|
|||
// LightShape is HD specific, it need to drive LightType from the original LightType when it make sense, so the GI is still in sync with the light shape
|
|||
switch (m_LightShape) |
|||
{ |
|||
case LightShape.Directional: |
|||
m_Type.enumValueIndex = (int)LightType.Directional; |
|||
m_LightTypeExtent.enumValueIndex = (int)LightTypeExtent.Punctual; |
|||
break; |
|||
|
|||
case LightShape.Point: |
|||
m_Type.enumValueIndex = (int)LightType.Point; |
|||
m_LightTypeExtent.enumValueIndex = (int)LightTypeExtent.Punctual; |
|||
EditorGUILayout.PropertyField(m_MaxSmoothness, Styles.MaxSmoothness); |
|||
break; |
|||
|
|||
case LightShape.Spot: |
|||
m_Type.enumValueIndex = (int)LightType.Spot; |
|||
m_LightTypeExtent.enumValueIndex = (int)LightTypeExtent.Punctual; |
|||
EditorGUILayout.PropertyField(m_SpotLightShape, Styles.SpotLightShape); |
|||
//Cone Spot
|
|||
if (m_SpotLightShape.enumValueIndex == (int)SpotLightShape.Cone) |
|||
{ |
|||
EditorGUILayout.Slider(m_SpotAngle, 1f, 179f, Styles.SpotAngle); |
|||
EditorGUILayout.Slider(m_SpotInnerAngle, 0f, 100f, Styles.SpotInnerAngle); |
|||
} |
|||
// TODO : replace with angle and ratio
|
|||
if (m_SpotLightShape.enumValueIndex == (int)SpotLightShape.Pyramid) |
|||
{ |
|||
EditorGUILayout.Slider(m_ShapeLength, 0.01f, 10, Styles.ShapeLengthPyramid); |
|||
EditorGUILayout.Slider(m_ShapeWidth, 0.01f, 10, Styles.ShapeWidthPyramid); |
|||
} |
|||
if (m_SpotLightShape.enumValueIndex == (int)SpotLightShape.Box) |
|||
{ |
|||
EditorGUILayout.PropertyField(m_ShapeLength, Styles.ShapeLengthBox); |
|||
EditorGUILayout.PropertyField(m_ShapeWidth, Styles.ShapeWidthBox); |
|||
} |
|||
EditorGUILayout.PropertyField(m_MaxSmoothness, Styles.MaxSmoothness); |
|||
break; |
|||
|
|||
case LightShape.Rectangle: |
|||
// TODO: Currently if we use Area type as it is offline light in legacy, the light will not exist at runtime
|
|||
//m_Type.enumValueIndex = (int)LightType.Area;
|
|||
m_Type.enumValueIndex = (int)LightType.Point; |
|||
m_LightTypeExtent.enumValueIndex = (int)LightTypeExtent.Rectangle; |
|||
EditorGUILayout.PropertyField(m_ShapeLength, Styles.ShapeLengthRect); |
|||
EditorGUILayout.PropertyField(m_ShapeWidth, Styles.ShapeWidthRect); |
|||
m_AreaSizeX.floatValue = m_ShapeLength.floatValue; |
|||
m_AreaSizeY.floatValue = m_ShapeWidth.floatValue; |
|||
m_ShadowsType.enumValueIndex = (int)LightShadows.None; |
|||
break; |
|||
|
|||
case LightShape.Line: |
|||
// TODO: Currently if we use Area type as it is offline light in legacy, the light will not exist at runtime
|
|||
//m_Type.enumValueIndex = (int)LightType.Area;
|
|||
m_Type.enumValueIndex = (int)LightType.Point; |
|||
m_LightTypeExtent.enumValueIndex = (int)LightTypeExtent.Line; |
|||
EditorGUILayout.PropertyField(m_ShapeLength, Styles.ShapeLengthLine); |
|||
// Fake line with a small rectangle in vanilla unity for GI
|
|||
m_AreaSizeX.floatValue = m_ShapeLength.floatValue; |
|||
m_AreaSizeY.floatValue = 0.01f; |
|||
break; |
|||
|
|||
case (LightShape)(-1): |
|||
// don't do anything, this is just to handle multi selection
|
|||
break; |
|||
|
|||
default: |
|||
Debug.Assert(false, "Not implemented light type"); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void LightGUI() |
|||
{ |
|||
EditorGUILayout.PropertyField(m_Color, Styles.Color); |
|||
EditorGUILayout.PropertyField(m_Intensity, Styles.Intensity); |
|||
EditorGUILayout.PropertyField(m_BounceIntensity, Styles.BounceIntensity); |
|||
// Indirect shadows warning (Should be removed when we support realtime indirect shadows)
|
|||
if (bounceWarningValue) |
|||
{ |
|||
EditorGUILayout.HelpBox(Styles.IndirectBounceShadowWarning.text, MessageType.Info); |
|||
} |
|||
EditorGUILayout.PropertyField(m_Range, Styles.Range); |
|||
EditorGUILayout.PropertyField(m_Lightmapping, Styles.LightmappingMode); |
|||
|
|||
// Warning if GI Baking disabled and m_Lightmapping isn't realtime
|
|||
if (bakingWarningValue) |
|||
{ |
|||
EditorGUILayout.HelpBox(Styles.BakingWarning.text, MessageType.Info); |
|||
} |
|||
|
|||
// no cookie with area light (maybe in future textured area light ?)
|
|||
if (!(m_LightShape == LightShape.Rectangle) && !(m_LightShape == LightShape.Line)) |
|||
{ |
|||
EditorGUILayout.PropertyField(m_Cookie, Styles.Cookie); |
|||
|
|||
// When directional light use a cookie, it can control the size
|
|||
if (m_LightShape == LightShape.Directional) |
|||
{ |
|||
EditorGUILayout.Slider(m_ShapeLength, 0.01f, 10, Styles.CookieSizeX); |
|||
EditorGUILayout.Slider(m_ShapeWidth, 0.01f, 10, Styles.CookieSizeY); |
|||
} |
|||
|
|||
if (cookieWarningValue) |
|||
{ |
|||
// warn on spotlights if the cookie is set to repeat
|
|||
EditorGUILayout.HelpBox(Styles.CookieWarning.text, MessageType.Warning); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ShadowsGUI() |
|||
{ |
|||
if (m_ShadowsType.enumValueIndex != (int)LightShadows.None) |
|||
{ |
|||
if (m_Lightmapping.enumValueIndex == (int)LightMappingType.Static) |
|||
{ |
|||
switch ((LightType)m_Type.enumValueIndex) |
|||
{ |
|||
case LightType.Directional: |
|||
EditorGUILayout.PropertyField(m_BakedShadowAngle, Styles.BakedShadowAngle); |
|||
break; |
|||
case LightType.Spot: |
|||
case LightType.Point: |
|||
EditorGUILayout.PropertyField(m_BakedShadowRadius, Styles.BakedShadowRadius); |
|||
break; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
EditorGUILayout.PropertyField(m_ShadowResolution, Styles.ShadowResolution); |
|||
EditorGUILayout.Slider(m_ShadowsBias, 0.001f, 1, Styles.ShadowBias); |
|||
EditorGUILayout.Slider(m_ShadowsNormalBias, 0.001f, 1, Styles.ShadowNormalBias); |
|||
EditorGUILayout.Slider(m_ShadowsNearPlane, 0.01f, 10, Styles.ShadowNearPlane); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ShadowsCascadeGUI() |
|||
{ |
|||
UnityEditor.EditorGUI.BeginChangeCheck(); |
|||
EditorGUILayout.IntSlider(m_ShadowCascadeCount, 1, 4, Styles.ShadowCascadeCount); |
|||
if (UnityEditor.EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_ShadowCascadeRatios.arraySize = m_ShadowCascadeCount.intValue - 1; |
|||
m_ShadowCascadeBorders.arraySize = m_ShadowCascadeCount.intValue; |
|||
} |
|||
|
|||
for (int i = 0; i < m_ShadowCascadeRatios.arraySize; i++) |
|||
{ |
|||
UnityEditor.EditorGUILayout.Slider(m_ShadowCascadeRatios.GetArrayElementAtIndex(i), 0.0f, 1.0f, Styles.ShadowCascadeRatios[i]); |
|||
} |
|||
} |
|||
|
|||
void AdditionalSettingsGUI() |
|||
{ |
|||
// Currently culling mask is not working with HD
|
|||
// EditorGUILayout.LabelField(new GUIContent("General"), EditorStyles.boldLabel);
|
|||
// EditorGUILayout.PropertyField(m_CullingMask);
|
|||
|
|||
EditorGUILayout.LabelField(new GUIContent("Light"), EditorStyles.boldLabel); |
|||
EditorGUILayout.PropertyField(m_AffectDiffuse, Styles.AffectDiffuse); |
|||
EditorGUILayout.PropertyField(m_AffectSpecular, Styles.AffectSpecular); |
|||
EditorGUILayout.PropertyField(m_FadeDistance, Styles.FadeDistance); |
|||
EditorGUILayout.PropertyField(m_LightDimmer, Styles.LightDimmer); |
|||
EditorGUILayout.PropertyField(m_ApplyRangeAttenuation, Styles.ApplyRangeAttenuation); |
|||
|
|||
if (m_ShadowsType.enumValueIndex != (int)LightShadows.None && m_Lightmapping.enumValueIndex != (int)LightMappingType.Static) |
|||
{ |
|||
EditorGUILayout.LabelField(new GUIContent("Shadows"), EditorStyles.boldLabel); |
|||
EditorGUILayout.PropertyField(m_ShadowFadeDistance, Styles.ShadowFadeDistance); |
|||
EditorGUILayout.PropertyField(m_ShadowDimmer, Styles.ShadowDimmer); |
|||
} |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
|
|||
// Sanity check
|
|||
if (additionalDataSerializedObject == null || shadowDataSerializedObject == null) |
|||
return; |
|||
|
|||
additionalDataSerializedObject.Update(); |
|||
shadowDataSerializedObject.Update(); |
|||
|
|||
ResolveLightShape(); |
|||
|
|||
var additionalData = light.GetComponent<HDAdditionalLightData>(); |
|||
var shadowData = light.GetComponent<AdditionalShadowData>(); |
|||
|
|||
if (GUILayout.Button("Toggle light editor")) |
|||
{ |
|||
m_UseOldInspector.boolValue = !m_UseOldInspector.boolValue; |
|||
} |
|||
|
|||
EditorGUILayout.Space(); |
|||
|
|||
if (m_UseOldInspector.boolValue) |
|||
{ |
|||
base.DrawDefaultInspector(); |
|||
ApplyAdditionalComponentsVisibility(false); |
|||
serializedObject.ApplyModifiedProperties(); |
|||
// It is required to save m_UseOldInspector value
|
|||
additionalDataSerializedObject.ApplyModifiedProperties(); |
|||
shadowDataSerializedObject.ApplyModifiedProperties(); // Should not be needed but if we do some change, could be, so let it here.
|
|||
return; |
|||
} |
|||
|
|||
ApplyAdditionalComponentsVisibility(true); |
|||
|
|||
// Light features
|
|||
EditorGUI.indentLevel++; |
|||
EditorGUILayout.LabelField(new GUIContent("Light features"), EditorStyles.boldLabel); |
|||
|
|||
// Do not display option for shadow if we are fully bake
|
|||
if (m_Lightmapping.enumValueIndex != (int)LightMappingType.Static) |
|||
{ |
|||
if (EditorGUILayout.Toggle(new GUIContent("Enable Shadow"), m_ShadowsType.enumValueIndex != 0)) |
|||
m_ShadowsType.enumValueIndex = (int)LightShadows.Hard; |
|||
else |
|||
m_ShadowsType.enumValueIndex = (int)LightShadows.None; |
|||
} |
|||
|
|||
EditorGUI.indentLevel--; |
|||
|
|||
// Allow to display the arrow for reduce/expand correctly
|
|||
EditorGUI.indentLevel = 1; |
|||
|
|||
// LightShape
|
|||
EditorGUI.indentLevel--; |
|||
EditorLightUtilities.DrawSplitter(); |
|||
m_Type.isExpanded = EditorLightUtilities.DrawHeaderFoldout("Shape", m_Type.isExpanded); |
|||
EditorGUI.indentLevel++; |
|||
|
|||
if (m_Type.isExpanded) |
|||
{ |
|||
LigthShapeGUI(); |
|||
} |
|||
|
|||
// Light
|
|||
EditorGUI.indentLevel--; |
|||
EditorLightUtilities.DrawSplitter(); |
|||
m_Intensity.isExpanded = EditorLightUtilities.DrawHeaderFoldout("Light", m_Intensity.isExpanded); |
|||
EditorGUI.indentLevel++; |
|||
|
|||
if (m_Intensity.isExpanded) |
|||
{ |
|||
LightGUI(); |
|||
} |
|||
|
|||
// Shadows
|
|||
if (m_ShadowsType.enumValueIndex != (int)LightShadows.None) |
|||
{ |
|||
EditorGUI.indentLevel--; |
|||
EditorLightUtilities.DrawSplitter(); |
|||
m_ShadowsType.isExpanded = EditorLightUtilities.DrawHeaderFoldout("Shadow", m_ShadowsType.isExpanded); |
|||
EditorGUI.indentLevel++; |
|||
|
|||
if (m_ShadowsType.isExpanded) |
|||
{ |
|||
ShadowsGUI(); |
|||
} |
|||
|
|||
// shadow cascade
|
|||
if (m_Type.enumValueIndex == (int)LightType.Directional && m_Lightmapping.enumValueIndex != (int)LightMappingType.Static) |
|||
{ |
|||
EditorGUI.indentLevel--; |
|||
EditorLightUtilities.DrawSplitter(); |
|||
m_ShadowCascadeCount.isExpanded = EditorLightUtilities.DrawHeaderFoldout("ShadowCascades", m_ShadowCascadeCount.isExpanded); |
|||
EditorGUI.indentLevel++; |
|||
|
|||
if (m_ShadowCascadeCount.isExpanded) |
|||
{ |
|||
ShadowsCascadeGUI(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// AdditionalSettings
|
|||
EditorGUI.indentLevel--; |
|||
EditorLightUtilities.DrawSplitter(); |
|||
m_ShowAdditionalSettings.boolValue = EditorLightUtilities.DrawHeaderFoldout("Additional Settings", m_ShowAdditionalSettings.boolValue); |
|||
EditorGUI.indentLevel++; |
|||
|
|||
if (m_ShowAdditionalSettings.boolValue) |
|||
{ |
|||
AdditionalSettingsGUI(); |
|||
} |
|||
|
|||
EditorGUI.indentLevel = 0; // Reset the value that we have init to 1
|
|||
|
|||
if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.m_SceneLighting == false) |
|||
{ |
|||
EditorGUILayout.HelpBox(Styles.DisabledLightWarning.text, MessageType.Warning); |
|||
} |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
additionalDataSerializedObject.ApplyModifiedProperties(); |
|||
shadowDataSerializedObject.ApplyModifiedProperties(); |
|||
} |
|||
|
|||
void ApplyAdditionalComponentsVisibility(bool hide) |
|||
{ |
|||
var additionalData = light.GetComponent<HDAdditionalLightData>(); |
|||
var shadowData = light.GetComponent<AdditionalShadowData>(); |
|||
|
|||
additionalData.hideFlags = hide ? HideFlags.HideInInspector : HideFlags.None; |
|||
shadowData.hideFlags = hide ? HideFlags.HideInInspector : HideFlags.None; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue