Upload project file
This commit is contained in:
8
Runtime/HDRP/UTS Renderer/Debug.meta
Normal file
8
Runtime/HDRP/UTS Renderer/Debug.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac8a77c3194424846b85febc5873b5b5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Runtime/HDRP/UTS Renderer/Debug/UTSDebug.cs
Normal file
35
Runtime/HDRP/UTS Renderer/Debug/UTSDebug.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Unity.Toonshader
|
||||
{
|
||||
[GenerateHLSL]
|
||||
public enum UTS_BSDFDebug
|
||||
{
|
||||
None,
|
||||
BaseColor,
|
||||
Normal,
|
||||
Smoothness,
|
||||
Metallic,
|
||||
AmbientOcclusion,
|
||||
SpecularOcclusion,
|
||||
SpecularColor,
|
||||
Anisotropy,
|
||||
HairRoughness,
|
||||
NormalWS,
|
||||
}
|
||||
|
||||
[GenerateHLSL]
|
||||
public enum UTS_LightingDebug
|
||||
{
|
||||
None,
|
||||
DiffuseLighting,
|
||||
SpecularLighting,
|
||||
DirectDiffuseLighting,
|
||||
DirectSpecularLighting,
|
||||
IndirectDiffuseLighting,
|
||||
IndirectSpecularLighting,
|
||||
IndirectDiffuseOcclusion,
|
||||
IndirectSpecularOcclusion,
|
||||
Emission,
|
||||
}
|
||||
}
|
||||
23
Runtime/HDRP/UTS Renderer/Debug/UTSDebug.cs.hlsl
Normal file
23
Runtime/HDRP/UTS Renderer/Debug/UTSDebug.cs.hlsl
Normal file
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// This file was automatically generated. Please don't edit by hand. Execute Editor command [ Edit > Rendering > Generate Shader Includes ] instead
|
||||
//
|
||||
|
||||
#ifndef UTSDEBUG_CS_HLSL
|
||||
#define UTSDEBUG_CS_HLSL
|
||||
//
|
||||
// Unity.Toonshader.UTS_BSDFDebug: static fields
|
||||
//
|
||||
#define UTS_BSDFDEBUG_NONE (0)
|
||||
#define UTS_BSDFDEBUG_BASE_COLOR (1)
|
||||
#define UTS_BSDFDEBUG_NORMAL (2)
|
||||
#define UTS_BSDFDEBUG_SMOOTHNESS (3)
|
||||
#define UTS_BSDFDEBUG_METALLIC (4)
|
||||
#define UTS_BSDFDEBUG_AMBIENT_OCCLUSION (5)
|
||||
#define UTS_BSDFDEBUG_SPECULAR_OCCLUSION (6)
|
||||
#define UTS_BSDFDEBUG_SPECULAR_COLOR (7)
|
||||
#define UTS_BSDFDEBUG_ANISOTROPY (8)
|
||||
#define UTS_BSDFDEBUG_HAIR_ROUGHNESS (9)
|
||||
#define UTS_BSDFDEBUG_NORMAL_WS (10)
|
||||
|
||||
|
||||
#endif
|
||||
7
Runtime/HDRP/UTS Renderer/Debug/UTSDebug.cs.hlsl.meta
Normal file
7
Runtime/HDRP/UTS Renderer/Debug/UTSDebug.cs.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc640c6ba1e3c3f418daf7da8178510a
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Runtime/HDRP/UTS Renderer/Debug/UTSDebug.cs.meta
Normal file
11
Runtime/HDRP/UTS Renderer/Debug/UTSDebug.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07ff7a966a4fee6498485046a71fcce7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
Runtime/HDRP/UTS Renderer/Debug/UTSDebugPanel.cs
Normal file
71
Runtime/HDRP/UTS Renderer/Debug/UTSDebugPanel.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Unity.Toonshader
|
||||
{
|
||||
public static class UTSDebugPanel
|
||||
{
|
||||
static bool isPanelEnabled = false;
|
||||
|
||||
static UTS_BSDFDebug uTS_BSDFData = UTS_BSDFDebug.None;
|
||||
static UTS_LightingDebug uTS_LightingData = UTS_LightingDebug.None;
|
||||
|
||||
public static void OnEnable()
|
||||
{
|
||||
if (isPanelEnabled)
|
||||
return;
|
||||
|
||||
// Create a list of widgets
|
||||
List<DebugUI.Widget> widgetList = new List<DebugUI.Widget>();
|
||||
|
||||
// Add a checkbox widget to the list of widgets
|
||||
widgetList.AddRange(new DebugUI.Widget[]
|
||||
{
|
||||
new DebugUI.EnumField
|
||||
{
|
||||
displayName = "BSDF debug mode",
|
||||
tooltip = "Select a bsdf debug mode",
|
||||
getter = () => (int)uTS_BSDFData,
|
||||
setter = value => uTS_BSDFData = (UTS_BSDFDebug)value,
|
||||
getIndex = () => (int)uTS_BSDFData,
|
||||
setIndex = value => uTS_BSDFData = (UTS_BSDFDebug)value,
|
||||
autoEnum = typeof(UTS_BSDFDebug), onValueChanged = BSDFDebugChanged
|
||||
},
|
||||
new DebugUI.EnumField
|
||||
{
|
||||
displayName = "Lighting debug mode",
|
||||
tooltip = "Select a lighting debug mode",
|
||||
getter = () => (int)uTS_LightingData,
|
||||
setter = value => uTS_LightingData = (UTS_LightingDebug)value,
|
||||
getIndex = () => (int)uTS_LightingData,
|
||||
setIndex = value => uTS_LightingData = (UTS_LightingDebug)value,
|
||||
autoEnum = typeof(UTS_LightingDebug), onValueChanged = LightingDebugChanged
|
||||
},
|
||||
});
|
||||
|
||||
// Create a new panel (tab) in the Rendering Debugger
|
||||
DebugUI.Panel panel = DebugManager.instance.GetPanel("UTS", createIfNull: true);
|
||||
|
||||
// Add the widgets to the panel
|
||||
panel.children.Add(widgetList.ToArray());
|
||||
isPanelEnabled = true;
|
||||
}
|
||||
|
||||
private static void BSDFDebugChanged(DebugUI.Field<int> field, int arg2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private static void LightingDebugChanged(DebugUI.Field<int> field, int arg2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Remove the custom panel if the GameObject is disabled
|
||||
public static void OnDisable()
|
||||
{
|
||||
DebugManager.instance.RemovePanel("UTS");
|
||||
isPanelEnabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/HDRP/UTS Renderer/Debug/UTSDebugPanel.cs.meta
Normal file
11
Runtime/HDRP/UTS Renderer/Debug/UTSDebugPanel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3670f54e2c33a144ebc55e56e207d69d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
200
Runtime/HDRP/UTS Renderer/UTSRenderer.cs
Normal file
200
Runtime/HDRP/UTS Renderer/UTSRenderer.cs
Normal file
@@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
namespace Unity.Toonshader
|
||||
{
|
||||
[Serializable, VolumeComponentMenu("Rendering/Unity Toon Shader")]
|
||||
public class UTSRenderer : VolumeComponent
|
||||
{
|
||||
// flags
|
||||
bool m_initialized = false;
|
||||
bool m_srpCallbackInitialized = false;
|
||||
|
||||
const int kAdjustmentCurvePrecision = 128;
|
||||
|
||||
const string kCompensationPropName = "_ToonEvAdjustmentCompensation";
|
||||
const string kExposureAdjustmentPropName = "_ToonEvAdjustmentCurve";
|
||||
const string kExposureArrayPropName = "_ToonEvAdjustmentValueArray";
|
||||
const string kExposureMinPropName = "_ToonEvAdjustmentValueMin";
|
||||
const string kExposureMaxPropName = "_ToonEvAdjustmentValueMax";
|
||||
const string kToonLightFilterPropName = "_ToonLightHiCutFilter";
|
||||
const string kIgnoreVolumeExposurePropName = "_ToonIgnoreExposureMultiplier";
|
||||
|
||||
[SerializeField]
|
||||
internal float[] m_ExposureArray;
|
||||
[SerializeField]
|
||||
internal float m_Max, m_Min;
|
||||
|
||||
CustomPassVolume customPassVolume = new();
|
||||
UTSOutlinePass outlinePass = new();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#pragma warning restore CS0414
|
||||
bool m_isCompiling = false;
|
||||
#endif
|
||||
|
||||
public BoolParameter enable = new BoolParameter(false, BoolParameter.DisplayType.EnumPopup);
|
||||
|
||||
[Space]
|
||||
[Header("Outline")]
|
||||
public BoolParameter enableOutline = new BoolParameter(false);
|
||||
public MinFloatParameter outlineMaxWidth = new MinFloatParameter(1.0f, 0.0f);
|
||||
|
||||
[Space]
|
||||
[Header("Hair Shadow")]
|
||||
public BoolParameter enableHairShadow = new BoolParameter(false);
|
||||
public ClampedFloatParameter shadowDistance = new ClampedFloatParameter(5.0f, 0.0f, 20.0f);
|
||||
public ClampedFloatParameter shadowDistanceScale = new ClampedFloatParameter(0.5f, 0.0f, 1.0f);
|
||||
public ClampedFloatParameter shadowDepthBias = new ClampedFloatParameter(0f, 0.0f, 0.01f);
|
||||
public FloatParameter shadowFadeIn = new FloatParameter(45f);
|
||||
public FloatParameter shadowFadeOut = new FloatParameter(50f);
|
||||
|
||||
[Space]
|
||||
[Header("Exposure")]
|
||||
public BoolParameter ignoreVolumeExposure = new BoolParameter(false);
|
||||
public BoolParameter lightIntensityLimiter = new BoolParameter(false);
|
||||
public MinFloatParameter compensation = new MinFloatParameter(0.0f, 0.0f);
|
||||
public BoolParameter toonEVAdjustment = new BoolParameter(false);
|
||||
public AnimationCurveParameter adjustmentCurve = new AnimationCurveParameter(DefaultAnimationCurve());
|
||||
|
||||
UTSRenderer()
|
||||
{
|
||||
displayName = "UTS Renderer";
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
UTSDebugPanel.OnEnable();
|
||||
Initialize();
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
UTSDebugPanel.OnDisable();
|
||||
Release();
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if (!enable.value)
|
||||
{
|
||||
Release();
|
||||
return;
|
||||
}
|
||||
|
||||
Initialize();
|
||||
|
||||
if (!m_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Fail safe in case the curve is deleted / has 0 point
|
||||
var curve = adjustmentCurve.value;
|
||||
|
||||
|
||||
if (curve == null || curve.length == 0)
|
||||
{
|
||||
m_Min = 0f;
|
||||
m_Max = 0f;
|
||||
|
||||
for (var i = 0; i < kAdjustmentCurvePrecision; i++)
|
||||
m_ExposureArray[i] = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Min = curve[0].time;
|
||||
m_Max = curve[curve.length - 1].time;
|
||||
var step = (m_Max - m_Min) / (kAdjustmentCurvePrecision - 1f);
|
||||
|
||||
for (var i = 0; i < kAdjustmentCurvePrecision; i++)
|
||||
m_ExposureArray[i] = curve.Evaluate(m_Min + step * i);
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// handle script recompile
|
||||
if (EditorApplication.isCompiling && !m_isCompiling)
|
||||
{
|
||||
// on compile begin
|
||||
m_isCompiling = true;
|
||||
// Release(); no need
|
||||
return; //
|
||||
}
|
||||
else if (!EditorApplication.isCompiling && m_isCompiling)
|
||||
{
|
||||
// on compile end
|
||||
m_isCompiling = false;
|
||||
}
|
||||
#endif
|
||||
Shader.SetGlobalFloatArray(kExposureArrayPropName, m_ExposureArray);
|
||||
Shader.SetGlobalFloat(kExposureMinPropName, m_Min);
|
||||
Shader.SetGlobalFloat(kExposureMaxPropName, m_Max);
|
||||
Shader.SetGlobalInt(kExposureAdjustmentPropName, toonEVAdjustment.value ? 1 : 0);
|
||||
Shader.SetGlobalInt(kToonLightFilterPropName, lightIntensityLimiter.value ? 1 : 0);
|
||||
Shader.SetGlobalInt(kIgnoreVolumeExposurePropName, ignoreVolumeExposure.value ? 1 : 0);
|
||||
Shader.SetGlobalFloat(kCompensationPropName, compensation.value);
|
||||
}
|
||||
|
||||
internal static AnimationCurve DefaultAnimationCurve()
|
||||
{
|
||||
return AnimationCurve.Linear(-10f, -10f, -1.32f, -1.32f);
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
if (m_initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
// initializing renderer can interfere GI baking. so wait until it is completed.
|
||||
|
||||
if (EditorApplication.isCompiling)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (m_ExposureArray == null || m_ExposureArray.Length != kAdjustmentCurvePrecision)
|
||||
{
|
||||
m_ExposureArray = new float[kAdjustmentCurvePrecision];
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
Release();
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
if (m_initialized)
|
||||
{
|
||||
m_ExposureArray = null;
|
||||
Shader.SetGlobalFloat(kExposureMinPropName, 0);
|
||||
Shader.SetGlobalFloat(kExposureMaxPropName, 0);
|
||||
Shader.SetGlobalInt(kExposureAdjustmentPropName, 0);
|
||||
Shader.SetGlobalInt(kToonLightFilterPropName, 0);
|
||||
Shader.SetGlobalInt(kIgnoreVolumeExposurePropName, 0);
|
||||
Shader.SetGlobalFloat(kCompensationPropName, 0);
|
||||
}
|
||||
|
||||
m_initialized = false;
|
||||
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
OnDisable();
|
||||
OnEnable();
|
||||
DefaultAnimationCurve();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/HDRP/UTS Renderer/UTSRenderer.cs.meta
Normal file
11
Runtime/HDRP/UTS Renderer/UTSRenderer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 627ea13a5a865df4895d40d641b8bcdd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user