Updated UTSRenderPass
This commit is contained in:
@@ -15,41 +15,36 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
[RequireComponent(typeof(Light))]
|
||||
internal class BoxLightAdjustment : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
// flags
|
||||
bool m_initialized = false;
|
||||
bool m_srpCallbackInitialized = false;
|
||||
private bool _initialized = false;
|
||||
private bool _srpCallbackInitialized = false;
|
||||
|
||||
[SerializeField]
|
||||
GameObject[] m_GameObjects;
|
||||
private GameObject[] _gameObjects;
|
||||
|
||||
[SerializeField]
|
||||
Renderer[] m_Renderers;
|
||||
|
||||
private Renderer[] _renderers;
|
||||
|
||||
[SerializeField]
|
||||
internal HDAdditionalLightData m_targetBoxLight;
|
||||
internal HDAdditionalLightData targetBoxLight;
|
||||
|
||||
[SerializeField]
|
||||
internal bool m_FollowGameObjectPosition = false;
|
||||
internal bool followGameObjectPosition = false;
|
||||
|
||||
[SerializeField]
|
||||
internal bool m_FollowGameObjectRotation = false;
|
||||
internal bool followGameObjectRotation = false;
|
||||
[SerializeField]
|
||||
internal Vector3 m_PositionOffset;
|
||||
internal Vector3 positionOffset;
|
||||
[SerializeField]
|
||||
internal Quaternion m_RotationOffset;
|
||||
internal Quaternion rotationOffset;
|
||||
#if UNITY_EDITOR
|
||||
#pragma warning restore CS0414
|
||||
bool m_isCompiling = false;
|
||||
private bool _isCompiling = false;
|
||||
#endif
|
||||
|
||||
void Reset()
|
||||
private void Reset()
|
||||
{
|
||||
OnDisable();
|
||||
OnEnable();
|
||||
|
||||
}
|
||||
|
||||
internal void OnValidate()
|
||||
@@ -64,100 +59,95 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
|
||||
|
||||
Initialize();
|
||||
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// handle script recompile
|
||||
if (EditorApplication.isCompiling && !m_isCompiling)
|
||||
if (EditorApplication.isCompiling && !_isCompiling)
|
||||
{
|
||||
// on compile begin
|
||||
m_isCompiling = true;
|
||||
_isCompiling = true;
|
||||
// Release(); no need
|
||||
return; //
|
||||
}
|
||||
else if (!EditorApplication.isCompiling && m_isCompiling)
|
||||
else if (!EditorApplication.isCompiling && _isCompiling)
|
||||
{
|
||||
// on compile end
|
||||
m_isCompiling = false;
|
||||
_isCompiling = false;
|
||||
}
|
||||
#endif
|
||||
if (m_Renderers == null)
|
||||
if (_renderers == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (m_targetBoxLight == null)
|
||||
if (targetBoxLight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Set rendering layer mask when property changed.
|
||||
for (var ii = 0; ii < m_Renderers.Length; ii++)
|
||||
for (var ii = 0; ii < _renderers.Length; ii++)
|
||||
{
|
||||
m_Renderers[ii].renderingLayerMask &= 0xffffff00;
|
||||
m_Renderers[ii].renderingLayerMask |= (uint)m_targetBoxLight.lightlayersMask;
|
||||
_renderers[ii].renderingLayerMask &= 0xffffff00;
|
||||
_renderers[ii].renderingLayerMask |= (uint)targetBoxLight.lightlayersMask;
|
||||
}
|
||||
if ( /* m_targetBoxLight != null && */ m_GameObjects != null && m_GameObjects.Length > 0 && m_GameObjects[0] != null)
|
||||
|
||||
if (_gameObjects != null && _gameObjects.Length > 0 && _gameObjects[0] != null)
|
||||
{
|
||||
if (m_FollowGameObjectPosition)
|
||||
if (followGameObjectPosition)
|
||||
{
|
||||
m_targetBoxLight.transform.position = m_GameObjects[0].transform.position + m_PositionOffset;
|
||||
targetBoxLight.transform.position = _gameObjects[0].transform.position + positionOffset;
|
||||
}
|
||||
if (m_FollowGameObjectRotation)
|
||||
if (followGameObjectRotation)
|
||||
{
|
||||
m_targetBoxLight.transform.rotation = m_GameObjects[0].transform.rotation * m_RotationOffset;
|
||||
targetBoxLight.transform.rotation = _gameObjects[0].transform.rotation * rotationOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EnableSrpCallbacks()
|
||||
private void EnableSrpCallbacks()
|
||||
{
|
||||
|
||||
if (!m_srpCallbackInitialized)
|
||||
if (!_srpCallbackInitialized)
|
||||
{
|
||||
m_srpCallbackInitialized = true;
|
||||
}
|
||||
}
|
||||
void DisableSrpCallbacks()
|
||||
{
|
||||
if (m_srpCallbackInitialized)
|
||||
{
|
||||
m_srpCallbackInitialized = false;
|
||||
_srpCallbackInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
private void DisableSrpCallbacks()
|
||||
{
|
||||
if (_srpCallbackInitialized)
|
||||
{
|
||||
_srpCallbackInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
EnableSrpCallbacks();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OnDisable()
|
||||
private void OnDisable()
|
||||
{
|
||||
DisableSrpCallbacks();
|
||||
|
||||
Release();
|
||||
}
|
||||
|
||||
void UpdateObjectLightLayers()
|
||||
private void UpdateObjectLightLayers()
|
||||
{
|
||||
Initialize();
|
||||
|
||||
}
|
||||
|
||||
internal static GameObject CreateBoxLight(GameObject[] gameObjects)
|
||||
@@ -190,7 +180,7 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
#if UNITY_EDITOR
|
||||
Undo.RecordObject(boxLightAdjustment, "target " + boxLightAdjustment.name);
|
||||
#endif
|
||||
boxLightAdjustment.m_targetBoxLight = hdLightData;
|
||||
boxLightAdjustment.targetBoxLight = hdLightData;
|
||||
#if UNITY_EDITOR
|
||||
Undo.RecordObject(lightGameObject.transform, "Position " + lightGameObject.transform.name);
|
||||
#endif
|
||||
@@ -207,16 +197,16 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
hdLightData.gameObject.transform.rotation = goRot;
|
||||
|
||||
// must be put to gameObject model chain.
|
||||
boxLightAdjustment.m_GameObjects = gameObjects;
|
||||
boxLightAdjustment._gameObjects = gameObjects;
|
||||
|
||||
|
||||
return lightGameObject;
|
||||
}
|
||||
|
||||
|
||||
void Initialize()
|
||||
private void Initialize()
|
||||
{
|
||||
if (m_initialized)
|
||||
if (_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -226,76 +216,77 @@ namespace Unity.Rendering.HighDefinition.Toon
|
||||
if (EditorApplication.isCompiling)
|
||||
return;
|
||||
#endif
|
||||
if (m_GameObjects == null)
|
||||
if (_gameObjects == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var objCount = m_GameObjects.Length;
|
||||
var objCount = _gameObjects.Length;
|
||||
var rendererCount = 0;
|
||||
|
||||
var rendererList = new List<Renderer>();
|
||||
for (var ii = 0; ii < objCount; ii++)
|
||||
{
|
||||
if (m_GameObjects[ii] == null)
|
||||
if (_gameObjects[ii] == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
var renderer = m_GameObjects[ii].GetComponent<Renderer>();
|
||||
var renderer = _gameObjects[ii].GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
rendererCount++;
|
||||
rendererList.Add(renderer);
|
||||
}
|
||||
var childGameObjects = m_GameObjects[ii].GetComponentsInChildren<Transform>().Select(t => t.gameObject).ToArray();
|
||||
|
||||
var childGameObjects = _gameObjects[ii].GetComponentsInChildren<Transform>().Select(t => t.gameObject).ToArray();
|
||||
var childCount = childGameObjects.Length;
|
||||
for (var jj = 0; jj < childCount; jj++)
|
||||
{
|
||||
if (m_GameObjects[ii] == childGameObjects[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)
|
||||
if (renderer == null)
|
||||
{
|
||||
rendererList.Add(renderer);
|
||||
rendererCount++;
|
||||
}
|
||||
continue;
|
||||
};
|
||||
|
||||
rendererList.Add(renderer);
|
||||
rendererCount++;
|
||||
}
|
||||
if (rendererCount != 0)
|
||||
{
|
||||
|
||||
|
||||
m_Renderers = rendererList.ToArray();
|
||||
|
||||
_renderers = rendererList.ToArray();
|
||||
}
|
||||
}
|
||||
if (m_targetBoxLight != null && objCount > 0)
|
||||
if (targetBoxLight != null && objCount > 0)
|
||||
{
|
||||
m_PositionOffset = m_targetBoxLight.transform.position - m_GameObjects[0].transform.position;
|
||||
m_RotationOffset = Quaternion.Inverse(m_GameObjects[0].transform.rotation) * m_targetBoxLight.transform.rotation;
|
||||
positionOffset = targetBoxLight.transform.position - _gameObjects[0].transform.position;
|
||||
rotationOffset = Quaternion.Inverse(_gameObjects[0].transform.rotation) * targetBoxLight.transform.rotation;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
|
||||
void Release()
|
||||
private void Release()
|
||||
{
|
||||
if (m_initialized)
|
||||
if (_initialized)
|
||||
{
|
||||
m_Renderers = null;
|
||||
_renderers = null;
|
||||
}
|
||||
|
||||
m_initialized = false;
|
||||
_initialized = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif // HDRP_IS_INSTALLED_FOR_UTS
|
||||
@@ -430,7 +430,6 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
}
|
||||
|
||||
context.shadowValue = lerp(1, context.shadowValue, lightData.shadowDimmer);
|
||||
|
||||
customMainLight.shadowValue = context.shadowValue;
|
||||
}
|
||||
|
||||
@@ -1000,4 +999,7 @@ void Frag(PackedVaryingsToPS packedInput,
|
||||
|
||||
outVTFeedback = builtinData.vtPackedFeedback;
|
||||
#endif
|
||||
|
||||
//outColor.rgb = customMainLight.shadowValue;
|
||||
|
||||
}
|
||||
@@ -44,8 +44,8 @@ namespace Unity.Toonshader
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
public static void RegisterCustomPasses()
|
||||
{
|
||||
CustomPassVolume.RegisterGlobalCustomPass(CustomPassInjectionPoint.AfterOpaqueAndSky, _outlinePass);
|
||||
CustomPassVolume.RegisterGlobalCustomPass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, _hairShadowPass);
|
||||
CustomPassVolume.RegisterUniqueGlobalCustomPass(CustomPassInjectionPoint.AfterOpaqueAndSky, _outlinePass);
|
||||
CustomPassVolume.RegisterUniqueGlobalCustomPass(CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, _hairShadowPass);
|
||||
|
||||
_outlinePass.enabled = _renderSetting.outlineSetting.enable;
|
||||
_hairShadowPass.SetEnable(_renderSetting.hairShadowSetting.enable);
|
||||
|
||||
Reference in New Issue
Block a user