Changed the outline layer and hair shadow caster layer from LayerMask to RenderingLayerMask;
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using System.Linq;
|
||||
|
||||
#if HDRP_IS_INSTALLED_FOR_UTS
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using Unity.Properties;
|
||||
|
||||
namespace Unity.Rendering.HighDefinition.Toon
|
||||
{
|
||||
@@ -18,24 +17,60 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
private bool _initialized = false;
|
||||
private bool _srpCallbackInitialized = false;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject[] _gameObjects;
|
||||
private HDAdditionalLightData _bindingSourceLightData;
|
||||
private HDAdditionalLightData _targetBoxLightData;
|
||||
|
||||
[SerializeField]
|
||||
private Renderer[] _renderers;
|
||||
private uint _layerMask;
|
||||
private Light _bindingSourceLight;
|
||||
private Light _targetBoxLight;
|
||||
|
||||
[SerializeField]
|
||||
internal HDAdditionalLightData targetBoxLight;
|
||||
public Transform trackedTransform;
|
||||
public bool followGameObjectPosition = false;
|
||||
public bool followGameObjectRotation = false;
|
||||
|
||||
[SerializeField]
|
||||
internal bool followGameObjectPosition = false;
|
||||
public Vector3 positionOffset;
|
||||
public Quaternion rotationOffset;
|
||||
|
||||
[CreateProperty]
|
||||
public Light BindingSourceLight
|
||||
{
|
||||
get => _bindingSourceLight;
|
||||
set
|
||||
{
|
||||
_bindingSourceLight = value;
|
||||
_bindingSourceLightData = _bindingSourceLight.GetComponent<HDAdditionalLightData>();
|
||||
}
|
||||
}
|
||||
|
||||
[CreateProperty]
|
||||
public Light TargetBoxLight
|
||||
{
|
||||
get => _targetBoxLight;
|
||||
set
|
||||
{
|
||||
_targetBoxLight = value;
|
||||
_targetBoxLightData = _targetBoxLight.GetComponent<HDAdditionalLightData>();
|
||||
}
|
||||
}
|
||||
|
||||
[CreateProperty]
|
||||
public uint LayerMask
|
||||
{
|
||||
get => _layerMask;
|
||||
set
|
||||
{
|
||||
if (_targetBoxLight == null || _bindingSourceLight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateShadowLayer(_bindingSourceLightData, _layerMask, value);
|
||||
UpdateShadowLayer(_targetBoxLightData, _layerMask, value);
|
||||
|
||||
_layerMask = value;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
internal bool followGameObjectRotation = false;
|
||||
[SerializeField]
|
||||
internal Vector3 positionOffset;
|
||||
[SerializeField]
|
||||
internal Quaternion rotationOffset;
|
||||
#if UNITY_EDITOR
|
||||
#pragma warning restore CS0414
|
||||
private bool _isCompiling = false;
|
||||
@@ -56,16 +91,14 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
private void Awake()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
private void LateUpdate()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
@@ -84,31 +117,23 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
_isCompiling = false;
|
||||
}
|
||||
#endif
|
||||
if (_renderers == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (targetBoxLight == null)
|
||||
if (_targetBoxLight == null || _bindingSourceLight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Set rendering layer mask when property changed.
|
||||
for (var ii = 0; ii < _renderers.Length; ii++)
|
||||
{
|
||||
_renderers[ii].renderingLayerMask &= 0xffffff00;
|
||||
_renderers[ii].renderingLayerMask |= (uint)targetBoxLight.lightlayersMask;
|
||||
}
|
||||
_targetBoxLight.enabled = _bindingSourceLight.enabled;
|
||||
_targetBoxLight.intensity = _bindingSourceLight.intensity;
|
||||
|
||||
if (_gameObjects != null && _gameObjects.Length > 0 && _gameObjects[0] != null)
|
||||
if (trackedTransform != null)
|
||||
{
|
||||
if (followGameObjectPosition)
|
||||
{
|
||||
targetBoxLight.transform.position = _gameObjects[0].transform.position + positionOffset;
|
||||
_targetBoxLight.transform.position = trackedTransform.transform.position + positionOffset;
|
||||
}
|
||||
if (followGameObjectRotation)
|
||||
{
|
||||
targetBoxLight.transform.rotation = _gameObjects[0].transform.rotation * rotationOffset;
|
||||
_targetBoxLight.transform.rotation = trackedTransform.transform.rotation * rotationOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,14 +175,14 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
Initialize();
|
||||
}
|
||||
|
||||
internal static GameObject CreateBoxLight(GameObject[] gameObjects)
|
||||
internal static GameObject CreateBoxLight(Transform transform)
|
||||
{
|
||||
if (gameObjects == null || gameObjects[0] == null)
|
||||
if (transform == null)
|
||||
{
|
||||
Debug.LogError("Please, select a GameObject you want a Box Light to follow.");
|
||||
return null;
|
||||
}
|
||||
var gameObjectName = "Box Light for " + gameObjects[0].name;
|
||||
var gameObjectName = "Box Light for " + transform.name;
|
||||
var lightGameObject = new GameObject(gameObjectName);
|
||||
#if UNITY_EDITOR
|
||||
Undo.RegisterCreatedObjectUndo(lightGameObject, "Created Boxlight adjustment");
|
||||
@@ -180,7 +205,7 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
#if UNITY_EDITOR
|
||||
Undo.RecordObject(boxLightAdjustment, "target " + boxLightAdjustment.name);
|
||||
#endif
|
||||
boxLightAdjustment.targetBoxLight = hdLightData;
|
||||
boxLightAdjustment._targetBoxLight = hdLightData.GetComponent<Light>();
|
||||
#if UNITY_EDITOR
|
||||
Undo.RecordObject(lightGameObject.transform, "Position " + lightGameObject.transform.name);
|
||||
#endif
|
||||
@@ -197,12 +222,20 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
hdLightData.gameObject.transform.rotation = goRot;
|
||||
|
||||
// must be put to gameObject model chain.
|
||||
boxLightAdjustment._gameObjects = gameObjects;
|
||||
boxLightAdjustment.trackedTransform = transform;
|
||||
|
||||
|
||||
return lightGameObject;
|
||||
}
|
||||
|
||||
private void UpdateShadowLayer(HDAdditionalLightData lightData, uint oldValue, uint newValue)
|
||||
{
|
||||
lightData.linkShadowLayers = false;
|
||||
var oldShadowLayer = lightData.GetShadowLayers();
|
||||
oldShadowLayer &= ~oldValue;
|
||||
var newShadowLayer = oldShadowLayer | newValue;
|
||||
lightData.SetShadowLightLayer((UnityEngine.Rendering.HighDefinition.RenderingLayerMask)newShadowLayer);
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
@@ -216,62 +249,15 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
if (EditorApplication.isCompiling)
|
||||
return;
|
||||
#endif
|
||||
if (_gameObjects == null)
|
||||
if (trackedTransform == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var objCount = _gameObjects.Length;
|
||||
var rendererCount = 0;
|
||||
|
||||
var rendererList = new List<Renderer>();
|
||||
for (var ii = 0; ii < objCount; ii++)
|
||||
if (_targetBoxLight != null)
|
||||
{
|
||||
if (_gameObjects[ii] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
var renderer = _gameObjects[ii].GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
rendererCount++;
|
||||
rendererList.Add(renderer);
|
||||
}
|
||||
|
||||
var childGameObjects = _gameObjects[ii].GetComponentsInChildren<Transform>().Select(t => t.gameObject).ToArray();
|
||||
var childCount = childGameObjects.Length;
|
||||
for (var jj = 0; jj < childCount; jj++)
|
||||
{
|
||||
if (_gameObjects[ii] == childGameObjects[jj])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var modelToonEvAdjustment = childGameObjects[jj].GetComponent<BoxLightAdjustment>();
|
||||
if (modelToonEvAdjustment != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
renderer = childGameObjects[jj].GetComponent<Renderer>();
|
||||
if (renderer == null)
|
||||
{
|
||||
continue;
|
||||
};
|
||||
|
||||
rendererList.Add(renderer);
|
||||
rendererCount++;
|
||||
}
|
||||
if (rendererCount != 0)
|
||||
{
|
||||
_renderers = rendererList.ToArray();
|
||||
}
|
||||
}
|
||||
if (targetBoxLight != null && objCount > 0)
|
||||
{
|
||||
positionOffset = targetBoxLight.transform.position - _gameObjects[0].transform.position;
|
||||
rotationOffset = Quaternion.Inverse(_gameObjects[0].transform.rotation) * targetBoxLight.transform.rotation;
|
||||
positionOffset = _targetBoxLight.transform.position - trackedTransform.transform.position;
|
||||
rotationOffset = Quaternion.Inverse(trackedTransform.transform.rotation) * _targetBoxLight.transform.rotation;
|
||||
}
|
||||
|
||||
_initialized = true;
|
||||
@@ -279,13 +265,7 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
|
||||
private void Release()
|
||||
{
|
||||
if (_initialized)
|
||||
{
|
||||
_renderers = null;
|
||||
}
|
||||
|
||||
_initialized = false;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user