35 Commits

Author SHA1 Message Date
ea3e83157c Added UtsSingleLightLoop 2025-03-23 17:53:36 +09:00
ee0b720b6d Added new Shadow SSS Lut;
Fixed the issue that SSGI and SSAO weight not works properly;
2025-03-17 00:02:46 +09:00
b2136e1ff4 Organized folder structure;
Added new SSS Lut Baker;
Removed old SubsurfaceLookupTextureIntegrator;
2025-03-16 15:13:06 +09:00
4ce84572d0 Shader code cleanupand bug fix. 2025-02-17 22:15:27 +09:00
eacbbc9b8b Organize folder structure;
Update RimLighting;
2025-02-04 21:21:44 +09:00
d44ff7d58c Merge branch 'release/3.0.0' of https://git.personalnas.com/Misaki/com.misaki.hdrp-toon into release/3.0.0 2025-02-03 23:02:10 +09:00
de370f845e Changing UI style;
Updating RImeLight;
2025-02-03 23:01:57 +09:00
3d06bb8129 Merge pull request 'Added UtsGetSurfaceAndBuiltinData to change metallic and smothness when PBR mode off;' (#2) from feature/custom-gbuffer into release/3.0.0
Reviewed-on: #2
Reviewed-by: Misaki <misaki_39@outlook.com>
2025-02-03 11:38:17 +00:00
680ebb72e5 Remove BOM; 2025-02-03 19:35:38 +08:00
74263900ac Added UtsGetSurfaceAndBuiltinData to change metallic and smothness when PBR mode off; 2025-02-03 19:17:25 +08:00
886432db7b Updated OutlineScope;
Reorgnize shader code;
2025-02-03 13:46:31 +09:00
281dfbc4f0 Improve AmbientScope and OutlineScope 2025-02-02 17:04:05 +09:00
ecd0cfdb9f Added AmbientScope; 2025-02-01 23:34:34 +08:00
3273812902 Added ShadowScope;
Renamed PBRScope to SurfaceInputsScope;
2025-02-01 20:51:22 +09:00
Misaki
458afd880f Update dependency 2025-02-01 14:45:04 +09:00
Misaki
a9b989fb19 Update ShadingColorScope; 2025-02-01 14:44:23 +09:00
Misaki
27e743755d Finish the ShadingColorScope; 2025-02-01 00:32:02 +09:00
780b3f9f13 Added PBRScope; 2025-01-31 22:28:21 +08:00
68870fe818 Update ShadingColorScope tooltips; 2025-01-31 20:01:49 +08:00
9822fa61ca Implement ShowSection for RimLightScope; 2025-01-31 19:19:46 +08:00
d92a103be2 Added RimLightScope; 2025-01-31 19:15:11 +08:00
Misaki
068e501fad Rename ShadingColorSettingsScope to ShadingColorScope 2025-01-31 17:27:44 +09:00
Misaki
e8d1d5923a Optmize shader structure 2025-01-31 17:25:19 +09:00
f41c6c9b34 Optimize ShadingColorSettingsScope toggle style; 2025-01-31 16:17:29 +08:00
5d23bd906b Added ShadingColorScope; 2025-01-30 22:36:37 +08:00
Misaki
181a53a3b2 Added UtsEvaluateAngelRing;
Added UTSTonemapping;
2025-01-30 22:54:43 +09:00
Misaki
d8b12a0ca9 Added SurfaceFeatureFlags;
Added OutlineScope;
Added AngelRingScope;

Change up Outline pass
2025-01-29 21:54:17 +09:00
Misaki
018300e046 Folder clean up;
Added Emissive;
2025-01-29 12:27:09 +09:00
Misaki
1a82022a6f Shader code cleanup;
Added punctual light evaluation in light loop;
2025-01-27 17:54:19 +09:00
Misaki
fac66d8694 Added UtsEvaluateBSDF_MatCapDiffuse;
Added UtsEvaluateBSDF_MatCapSpecular;
2025-01-24 17:59:40 +09:00
Misaki
476fdc3774 Updated dependency 2025-01-24 11:55:44 +09:00
Misaki
6a8095d7e0 Code Cleanup; 2025-01-23 23:56:32 +09:00
Misaki
e6b58cb321 Added UtsAreaLight.hlsl;
Fixed the problem that the appearence of direct diffuse is incorrect when area light intensity is low.

Changed the file name of PBR.hlsl to UtsPBR.hlsl
Changed the file name of EnvLighting.hlsl to UtsEnvLighting.hlsl
2025-01-18 14:14:00 +09:00
Misaki
12a03e9c3c Added UTSPolygonFormFactor and UTSComputeEdgeFactor 2025-01-17 18:47:37 +09:00
Misaki
b838223551 Changed area light calculation, need feature clean up 2025-01-17 18:45:41 +09:00
169 changed files with 5724 additions and 5232 deletions

74
.gitignore vendored
View File

@@ -1,74 +0,0 @@
# ---> Unity
# This .gitignore file should be placed at the root of your Unity project directory
#
# Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore
#
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/[Ll]ogs/
/[Uu]ser[Ss]ettings/
# MemoryCaptures can get excessive in size.
# They also could contain extremely sensitive data
/[Mm]emoryCaptures/
# Recordings can get excessive in size
/[Rr]ecordings/
# Uncomment this line if you wish to ignore the asset store tools plugin
# /[Aa]ssets/AssetStoreTools*
# Autogenerated Jetbrains Rider plugin
/[Aa]ssets/Plugins/Editor/JetBrains*
# Visual Studio cache directory
.vs/
# Gradle cache directory
.gradle/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
# Unity3D generated meta files
*.pidb.meta
*.pdb.meta
*.mdb.meta
# Unity3D generated file on crash reports
sysinfo.txt
# Builds
*.apk
*.aab
*.unitypackage
*.app
# Crashlytics generated file
crashlytics-build.properties
# Packed Addressables
/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
# Temporary auto-generated Android Assets
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*

View File

@@ -9,6 +9,11 @@ namespace Misaki.HdrpToon.Editor
{
SerializedObject m_SerializedObject;
public static AnimationCurve DefaultAnimationCurve()
{
return AnimationCurve.Linear(-10f, -10f, -1.32f, -1.32f);
}
public override void OnInspectorGUI()
{
@@ -93,7 +98,7 @@ namespace Misaki.HdrpToon.Editor
var curve2 = obj.m_AnimationCurve;
if (buttonIsPressed)
{
curve2 = SceneToonEvAdjustment.DefaultAnimationCurve();
curve2 = DefaultAnimationCurve();
}
if (EditorGUI.EndChangeCheck())
{

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 29660dd543a3ad04ea860b6366d28b54
guid: bcc6ebf595772354fbb5631c8e4cac04
folderAsset: yes
DefaultImporter:
externalObjects: {}

View File

@@ -99,16 +99,16 @@ namespace UnityEditor.Rendering.Toon
internal const string ShaderProp_Set_RimLightMask = "_Set_RimLightMask";
internal const string ShaderProp_HighColor_Tex = "_HighColor_Tex";
internal const string ShaderProp_Set_HighColorMask = "_Set_HighColorMask";
internal const string ShaderProp_MatCap_Sampler = "_MatCap_Sampler";
internal const string ShaderProp_MatCapMap = "_MatCapMap";
internal const string ShaderProp_Set_MatcapMask = "_Set_MatcapMask";
internal const string ShaderProp_OutlineTex = "_OutlineTex";
internal const string ShaderProp_Outline_Sampler = "_Outline_Sampler";
internal const string ShaderPropCastHairShadow = "_Is_CastHairShadow";
internal const string ShaderPropReceiveHairShadow = "_Is_ReceiveHairShadow";
internal const string ShaderPropReceiveHairShadow = "_Receive_Hair_Shadow";
internal const string ShaderPropEyeParallax = "_Is_EyeParallax";
internal const string ShaderPropHairBlendingTarget = "_Is_HairBlendingTarget";
internal const string ShaderPropHairBlendingTarget = "_HairBlendingTarget";
internal const string ShaderPropSimpleUI = "_simpleUI";
internal const string ShaderPropAutoRenderQueue = "_AutoRenderQueue";
@@ -130,6 +130,8 @@ namespace UnityEditor.Rendering.Toon
internal const string ShaderPropShadowMode = "_Shadow_Mode";
internal const string ShaderPropMaterialType = "_Material_Type";
internal const string ShaderPropPBR = "_PBR_Mode";
internal const string ShaderPropIDMode = "_Indirect_Diffuse_Mode";
internal const string ShaderPropISMode = "_Indirect_Specular_Mode";
internal const string ShaderPropOutline = "_OUTLINE";
internal const string ShaderPropNormalMapToHighColor = "_Is_NormalMapToHighColor";
internal const string ShaderPropIsNormalMapToRimLight = "_Is_NormalMapToRimLight";
@@ -156,7 +158,6 @@ namespace UnityEditor.Rendering.Toon
internal const string ShaderPropInvert_MatcapMask = "_Inverse_MatcapMask";
internal const string ShaderPropUse_BaseAs1st = "_Use_BaseAs1st";
internal const string ShaderPropUse_1stAs2nd = "_Use_1stAs2nd";
internal const string ShaderPropIs_NormalMapToBase = "_Is_NormalMapToBase";
internal const string ShaderPropIs_ColorShift = "_Is_ColorShift";
internal const string ShaderPropRimLight = "_RimLight";
internal const string ShaderPropRimLight_FeatherOff = "_RimLight_FeatherOff";
@@ -213,8 +214,10 @@ namespace UnityEditor.Rendering.Toon
protected readonly string[] StencilModeNames = { "Off", "Draw If Not Equal to", "Replace Stencil Buffer with" };
protected readonly string[] ZTestModeNames = { "Disabled", "Never", "Less", "Equal", "LessEqual", "Greater", "NotEqual", "GreaterEqual", "Always" };
protected readonly string[] materialTypeDefines = { "MATERIAL_TYPE_STANDARD", "MATERIAL_TYPE_FRONT_HAIR", "MATERIAL_TYPE_FACE", "MATERIAL_TYPE_EYE" };
protected readonly string[] PbrModeDefines = { "_PBR_Mode_OFF", "_PBR_Mode_ST", "_PBR_Mode_ANISO", "_PBR_Mode_KK", "_PBR_Mode_TOON" };
protected readonly string[] materialTypeDefines = { "_MATERIAL_TYPE_STANDARD", "_MATERIAL_TYPE_FRONTHAIR", "_MATERIAL_TYPE_FACE", "_MATERIAL_TYPE_EYE" };
protected readonly string[] PbrModeDefines = { "_PBR_MODE_OFF", "_PBR_MODE_STANDARD", "_PBR_MODE_ANISOTROPY", "_PBR_MODE_HAIR", "_PBR_MODE_TOON" };
protected readonly string[] IndirectDiffuseModeDefines = { "_INDIRECT_DIFFUSE_OFF", "_INDIRECT_DIFFUSE_IBL", "_INDIRECT_DIFFUSE_MATCAP", "_INDIRECT_DIFFUSE_RAMP" };
protected readonly string[] IndirectSpecularModeDefines = { "_INDIRECT_SPECULAR_OFF", "_INDIRECT_SPECULAR_IBL", "_INDIRECT_SPECULAR_MATCAP" };
public enum UTS_ClippingMode
{
@@ -295,6 +298,17 @@ namespace UnityEditor.Rendering.Toon
Off, Standard, Anisotropy, KKHair, Toon
}
public enum IndirectDiffuseMode
{
Off, IBL, Matcap, Ramp
}
public enum IndirectSpecularMode
{
Off, IBL, Matcap
}
public enum OutlineMode
{
NormalDirection, PositionScaling
@@ -320,24 +334,25 @@ namespace UnityEditor.Rendering.Toon
#if UNITY_2021_1_OR_NEWER
[UTS3InspectorHelpURL("instruction")]
#endif // UNITY_2021_1_OR_NEWER
protected enum Expandable
protected enum Expandable : uint
{
Shader = 1 << 0,
Basic = 1 << 1,
ShadingStepAndFeather = 1 << 2,
MaterialFeature = 1 << 3,
PBR = 1 << 4,
Highlight = 1 << 5,
Rimlight = 1 << 6,
MatCap = 1 << 7,
AngelRing = 1 << 8,
Emission = 1 << 9,
Outline = 1 << 10,
TessellationLegacy = 1 << 11,
TessellationHDRP = 1 << 12,
SceneLight = 1 << 13,
EnvironmentalLightEffectiveness = 1 << 14,
MetaverseSettings = 1 << 15,
AmbientMode = 1 << 5,
Highlight = 1 << 6,
Rimlight = 1 << 7,
MatCap = 1 << 8,
AngelRing = 1 << 9,
Emission = 1 << 10,
Outline = 1 << 11,
TessellationLegacy = 1 << 12,
TessellationHDRP = 1 << 13,
SceneLight = 1 << 14,
EnvironmentalLightEffectiveness = 1 << 15,
MetaverseSettings = 1 << 16,
}
// variables which must be gotten from shader at the beggning of GUI
@@ -347,6 +362,8 @@ namespace UnityEditor.Rendering.Toon
internal ShadowMode m_shadowMode;
internal MaterialType m_materialType;
internal PBRMode m_pbrMode;
internal IndirectDiffuseMode m_IndirectDiffuseMode;
internal IndirectSpecularMode m_IndirectSpecularMode;
internal OutlineMode m_outlineMode;
internal CullingMode m_cullingMode;
internal EmissionMode m_emissionMode;
@@ -422,7 +439,7 @@ namespace UnityEditor.Rendering.Toon
protected MaterialProperty ap_RimLight_Power = null;
protected MaterialProperty set_RimLightMask = null;
protected MaterialProperty matCap_Sampler = null;
protected MaterialProperty matCapMap = null;
protected MaterialProperty matCapColor = null;
protected MaterialProperty normalMapForMatCap = null;
protected MaterialProperty bumpScaleMatcap = null;
@@ -515,7 +532,7 @@ namespace UnityEditor.Rendering.Toon
set_RimLightMask = FindProperty(ShaderProp_Set_RimLightMask, props);
matCap_Sampler = FindProperty(ShaderProp_MatCap_Sampler, props);
matCapMap = FindProperty(ShaderProp_MatCapMap, props);
matCapColor = FindProperty("_MatCapColor", props);
normalMapForMatCap = FindProperty("_NormalMapForMatCap", props);
@@ -527,8 +544,8 @@ namespace UnityEditor.Rendering.Toon
angelRing_Sampler = FindProperty("_AngelRing_Sampler", props, false);
angelRing_Color = FindProperty("_AngelRing_Color", props, false);
emissive_Tex = FindProperty("_Emissive_Tex", props);
emissive_Color = FindProperty("_Emissive_Color", props);
emissive_Tex = FindProperty("_EmissiveColorMap", props);
emissive_Color = FindProperty("_EmissiveColor", props);
outline_Sampler = FindProperty(ShaderProp_Outline_Sampler, props, false);
@@ -631,6 +648,7 @@ namespace UnityEditor.Rendering.Toon
public static readonly GUIContent shadingStepAndFeatherFoldout = EditorGUIUtility.TrTextContent("Shading Step and Feather Settings", "Basic 3 color step and feather settings.");
public static readonly GUIContent materialFeatureFoldout = EditorGUIUtility.TrTextContent("Material Feature", "Material Feature Setting. The settings for special material feature like hair shadow, hair blending, etc");
public static readonly GUIContent pbrFoldout = EditorGUIUtility.TrTextContent("PBR Settings", "PBR settings. The settings for PBR effect, such as specular and IBL.");
public static readonly GUIContent ambientModeFoldout = EditorGUIUtility.TrTextContent("Ambient Settings", "Ambient settings. The settings for ambient lighting like IBL, Matcap, etc.");
public static readonly GUIContent highlightFoldout = EditorGUIUtility.TrTextContent("Highlight Settings", "Highlight settings. Such as power, show or hide, light shape and so on.");
public static readonly GUIContent rimLightFoldout = EditorGUIUtility.TrTextContent("Rim Light Settings", "Rim Light Settings. Such as color, direction, inverted rim light and so on.");
public static readonly GUIContent matCapFoldout = EditorGUIUtility.TrTextContent("Material Capture (MatCap) Settings", "MatCap settings. Sphere maps for metallic or unusual expressions.");
@@ -654,8 +672,10 @@ namespace UnityEditor.Rendering.Toon
public static readonly GUIContent hairBlendingTargetMapText = new GUIContent("Blending Map", "Specifies the texture to blend with hair.");
public static readonly GUIContent normalMapText = new GUIContent("Normal Map", "A texture that dictates the bumpiness of the material.");
public static readonly GUIContent pbrModeText = new GUIContent("PBR Mode", "Specifies PBR model mode.");
public static readonly GUIContent indirectDiffuseModeText = new GUIContent("Indirect Diffuse Mode", "Specifies indirect diffuse mode.");
public static readonly GUIContent indirectSpecularText = new GUIContent("Indirect Specular Mode", "Specifies indirect specular mode.");
public static readonly GUIContent highColorText = new GUIContent("Highlight", "Highlight : Texture(sRGB) x Color(RGB) Default:White");
public static readonly GUIContent highColorMaskText = new GUIContent("Highlight Mask", "A grayscale texture which utilises its brightness to control intensity.");
public static readonly GUIContent highColorMaskText = new GUIContent("Highlight Mask", "A grayscale texture which utilizes its brightness to control intensity.");
public static readonly GUIContent rimLightMaskText = new GUIContent("Rim Light Mask", "Rim Light Mask : Texture(linear). The white part of the texture is displayed as Rim Light, and the black part is masked and not displayed.");
public static readonly GUIContent matCapSamplerText = new GUIContent("MatCap Map", "MatCap Color : Texture(sRGB) x Color(RGB) Default:White");
public static readonly GUIContent matCapMaskText = new GUIContent("MatCap Mask", "The MatCap mask is positioned with respect to the UV coordinates of the mesh onto which the MatCap is projected, and the pixels on black areas are hidden.");
@@ -667,7 +687,7 @@ namespace UnityEditor.Rendering.Toon
public static readonly GUIContent outlineSamplerText = new GUIContent("Outline Width Map", "Outline Width Map as Grayscale Texture : Texture(linear). In the case of white, the Outline Width is displayed as it is. In black, the width is 0.");
public static readonly GUIContent outlineTexText = new GUIContent("Outline Color Map", "Outline texture : Texture(sRGB) Default:White");
public static readonly GUIContent bakedNormalOutlineText = new GUIContent("Baked Normal Map for Outline", "Unpacked Normal Map : Texture(linear) .Note that this is not a standard NORMAL MAP.");
public static readonly GUIContent clippingMaskText = new GUIContent("Clipping Mask", "A grayscale texture which utilises its brightness to control transparency.");
public static readonly GUIContent clippingMaskText = new GUIContent("Clipping Mask", "A grayscale texture which utilizes its brightness to control transparency.");
public static readonly GUIContent specularModeText = new GUIContent("Specular Mode", "Specular light mode. Hard or Soft.");
public static readonly GUIContent specularBlendModeText = new GUIContent("Color Blending Mode", "Specular color blending mode. Multiply or Add.");
@@ -947,12 +967,12 @@ namespace UnityEditor.Rendering.Toon
propName: "_RimLight_InsideMask", defaultValue: 0.0001f, min: 0.0001f, max: 1);
public static readonly RangeProperty SSAOFactorText = new RangeProperty(
label: "SSAO Minimum", "The minimum value of SSAO.",
propName: "_AOMin", defaultValue: 0.0f, min: 0, max: 1);
label: "SSAO Factor", "The weight of SSAO.",
propName: "_AO_Factor", defaultValue: 0.0f, min: 0, max: 1);
public static readonly RangeProperty SSGIFactorText = new RangeProperty(
label: "SSGI Factor", "The multiplier of SSGI.",
propName: "_GIMultiplier", defaultValue: 1.0f, min: 1, max: 10);
label: "SSGI Factor", "The weight of SSGI.",
propName: "_GI_Factor", defaultValue: 1.0f, min: 1, max: 10);
public static readonly RangeProperty BSDFContribution = new RangeProperty(
label: "BSDF Contribution", "BSDF smoothness contribution, 1 means KK Hair smoothness will fully contribute bsdf calculation",
@@ -1022,6 +1042,7 @@ namespace UnityEditor.Rendering.Toon
m_MaterialScopeList.RegisterHeaderScope(Styles.shadingStepAndFeatherFoldout, Expandable.ShadingStepAndFeather, GUI_StepAndFeather, (uint)UTS_TransparentMode.Off, isTessellation: 0);
m_MaterialScopeList.RegisterHeaderScope(Styles.materialFeatureFoldout, Expandable.MaterialFeature, GUI_MaterialFeature, (uint)UTS_TransparentMode.Off, isTessellation: 0);
m_MaterialScopeList.RegisterHeaderScope(Styles.pbrFoldout, Expandable.PBR, GUI_PBRSettings, (uint)UTS_TransparentMode.Off, isTessellation: 0);
m_MaterialScopeList.RegisterHeaderScope(Styles.ambientModeFoldout, Expandable.AmbientMode, GUI_AmbientMode, (uint)UTS_TransparentMode.Off, isTessellation: 0);
m_MaterialScopeList.RegisterHeaderScope(Styles.highlightFoldout, Expandable.Highlight, GUI_HighlightSettings, (uint)UTS_TransparentMode.Off, isTessellation: 0);
m_MaterialScopeList.RegisterHeaderScope(Styles.rimLightFoldout, Expandable.Rimlight, GUI_RimLight, (uint)UTS_TransparentMode.Off, isTessellation: 0);
m_MaterialScopeList.RegisterHeaderScope(Styles.matCapFoldout, Expandable.MatCap, GUI_MatCap, (uint)UTS_TransparentMode.Off, isTessellation: 0);
@@ -1529,6 +1550,71 @@ namespace UnityEditor.Rendering.Toon
EditorGUI.EndDisabledGroup();
}
void GUI_ShadingStepAndFeatherSettings(Material material)
{
var shadowMode_Setting = MaterialGetInt(material, ShaderPropShadowMode);
//Convert it to Enum format and store it in the offlineMode variable.
switch (shadowMode_Setting)
{
case (int)ShadowMode.Normal:
m_shadowMode = ShadowMode.Normal;
break;
case (int)ShadowMode.SDF:
m_shadowMode = ShadowMode.SDF;
break;
}
m_shadowMode = (ShadowMode)EditorGUILayout.EnumPopup(Styles.shadowModeText, m_shadowMode);
EditorGUILayout.Space();
switch (m_shadowMode)
{
case ShadowMode.Normal:
{
material.SetFloat(ShaderPropShadowMode, (int)ShadowMode.Normal);
material.DisableKeyword(new LocalKeyword(material.shader, "_SHADOW_MODE_SDF"));
GUI_RangeProperty(material, Styles.shaderProp1st_ShadeColor_StepText);
GUI_RangeProperty(material, Styles.shaderProp1st_ShadeColor_FeatherText);
GUI_RangeProperty(material, Styles.shaderProp2nd_ShadeColor_StepText);
GUI_RangeProperty(material, Styles.shaderProp2nd_ShadeColor_FeatherText);
//Share variables with DoubleWithFeather method.
material.SetFloat(ShaderPropBaseColor_Step, material.GetFloat(ShaderProp1st_ShadeColor_Step));
material.SetFloat(ShaderPropBaseShade_Feather, material.GetFloat(ShaderProp1st_ShadeColor_Feather));
material.SetFloat(ShaderPropShadeColor_Step, material.GetFloat(ShaderProp2nd_ShadeColor_Step));
material.SetFloat(ShaderProp1st2nd_Shades_Feather, material.GetFloat(ShaderProp2nd_ShadeColor_Feather));
}
break;
case ShadowMode.SDF:
{
material.SetFloat(ShaderPropShadowMode, (int)ShadowMode.SDF);
material.EnableKeyword(new LocalKeyword(material.shader, "_SHADOW_MODE_SDF"));
m_MaterialEditor.TexturePropertySingleLine(Styles.SDFShadowText, SDFShadowMap);
GUI_RangeProperty(material, Styles.SDFShadowLevelText);
GUI_RangeProperty(material, Styles.SDFSmoothGammaText);
GUI_RangeProperty(material, Styles.SDFNoseHighlightCoefText);
GUI_RangeProperty(material, Styles.SDFNoseHighlightSmoothRange);
}
break;
}
EditorGUILayout.Space();
}
void GUI_AdditionalLookdevs(Material material)
{
EditorGUI.indentLevel++;
GUI_RangeProperty(material, Styles.shaderPropStepOffsetText);
GUI_Toggle(material, Styles.filterPointLightText, ShaderPropIsFilterHiCutPointLightColor, MaterialGetInt(material, ShaderPropIsFilterHiCutPointLightColor) != 0);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
void GUI_MaterialFeature(Material material)
{
var materialTypeSetting = MaterialGetInt(material, ShaderPropMaterialType);
@@ -1553,7 +1639,7 @@ namespace UnityEditor.Rendering.Toon
var isReceiveHairShadowEnabled = GUI_Toggle(material, Styles.receiveHairShadowText, ShaderPropReceiveHairShadow,
MaterialGetInt(material, ShaderPropReceiveHairShadow) != 0);
material.SetKeyword(new LocalKeyword(material.shader, "_RECEIVE_HAIR_SHADOW"), isReceiveHairShadowEnabled);
material.SetKeyword(new LocalKeyword(material.shader, "_RECEIVE_HAIR_SHADOW_ON"), isReceiveHairShadowEnabled);
var isHairBlendingTargetEnabled = GUI_Toggle(material, Styles.hairBlendingTargetShadowText, ShaderPropHairBlendingTarget,
MaterialGetInt(material, ShaderPropHairBlendingTarget) != 0);
@@ -1596,125 +1682,39 @@ namespace UnityEditor.Rendering.Toon
GUI_RangeProperty(material, Styles.eyeParallaxAmount);
}
void GUI_ShadingStepAndFeatherSettings(Material material)
void SwitchKeywrod(Material material, string targetKeywrod, string[] sources)
{
var shadowMode_Setting = MaterialGetInt(material, ShaderPropShadowMode);
//Convert it to Enum format and store it in the offlineMode variable.
switch (shadowMode_Setting)
foreach (var keywrod in sources)
{
case (int)ShadowMode.Normal:
m_shadowMode = ShadowMode.Normal;
break;
case (int)ShadowMode.SDF:
m_shadowMode = ShadowMode.SDF;
break;
if (targetKeywrod == keywrod)
{
material.EnableKeyword(keywrod);
}
m_shadowMode = (ShadowMode)EditorGUILayout.EnumPopup(Styles.shadowModeText, m_shadowMode);
EditorGUILayout.Space();
switch (m_shadowMode)
else
{
case ShadowMode.Normal:
{
material.SetFloat(ShaderPropShadowMode, (int)ShadowMode.Normal);
material.DisableKeyword(new LocalKeyword(material.shader, "_SDFShadow"));
GUI_RangeProperty(material, Styles.shaderProp1st_ShadeColor_StepText);
GUI_RangeProperty(material, Styles.shaderProp1st_ShadeColor_FeatherText);
GUI_RangeProperty(material, Styles.shaderProp2nd_ShadeColor_StepText);
GUI_RangeProperty(material, Styles.shaderProp2nd_ShadeColor_FeatherText);
//Share variables with DoubleWithFeather method.
material.SetFloat(ShaderPropBaseColor_Step, material.GetFloat(ShaderProp1st_ShadeColor_Step));
material.SetFloat(ShaderPropBaseShade_Feather, material.GetFloat(ShaderProp1st_ShadeColor_Feather));
material.SetFloat(ShaderPropShadeColor_Step, material.GetFloat(ShaderProp2nd_ShadeColor_Step));
material.SetFloat(ShaderProp1st2nd_Shades_Feather, material.GetFloat(ShaderProp2nd_ShadeColor_Feather));
material.DisableKeyword(keywrod);
}
break;
case ShadowMode.SDF:
{
material.SetFloat(ShaderPropShadowMode, (int)ShadowMode.SDF);
material.EnableKeyword(new LocalKeyword(material.shader, "_SDFShadow"));
m_MaterialEditor.TexturePropertySingleLine(Styles.SDFShadowText, SDFShadowMap);
GUI_RangeProperty(material, Styles.SDFShadowLevelText);
GUI_RangeProperty(material, Styles.SDFSmoothGammaText);
GUI_RangeProperty(material, Styles.SDFNoseHighlightCoefText);
GUI_RangeProperty(material, Styles.SDFNoseHighlightSmoothRange);
}
break;
}
EditorGUILayout.Space();
}
void GUI_AdditionalLookdevs(Material material)
{
EditorGUI.indentLevel++;
GUI_RangeProperty(material, Styles.shaderPropStepOffsetText);
GUI_Toggle(material, Styles.filterPointLightText, ShaderPropIsFilterHiCutPointLightColor, MaterialGetInt(material, ShaderPropIsFilterHiCutPointLightColor) != 0);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
}
void GUI_PBRSettings(Material material)
{
var PBRMode_Setting = MaterialGetInt(material, ShaderPropPBR);
//Convert it to Enum format and store it in the offlineMode variable.
switch (PBRMode_Setting)
{
case (int)PBRMode.Off:
m_pbrMode = PBRMode.Off;
break;
case (int)PBRMode.Standard:
m_pbrMode = PBRMode.Standard;
break;
case (int)PBRMode.Anisotropy:
m_pbrMode = PBRMode.Anisotropy;
break;
case (int)PBRMode.KKHair:
m_pbrMode = PBRMode.KKHair;
break;
case (int)PBRMode.Toon:
m_pbrMode = PBRMode.Toon;
break;
}
//GUI description with EnumPopup.
m_pbrMode = (PBRMode)MaterialGetInt(material, ShaderPropPBR);
m_pbrMode = (PBRMode)EditorGUILayout.EnumPopup(Styles.pbrModeText, m_pbrMode);
EditorGUILayout.Space();
void SwitchPbrMode(string targetMode)
{
foreach (var pbrMode in PbrModeDefines)
{
if (targetMode == pbrMode)
{
material.EnableKeyword(pbrMode);
}
else
{
material.DisableKeyword(pbrMode);
}
}
}
material.SetFloat(ShaderPropPBR, (int)m_pbrMode);
SwitchPbrMode(PbrModeDefines[(int)m_pbrMode]);
SwitchKeywrod(material, PbrModeDefines[(int)m_pbrMode], PbrModeDefines);
m_MaterialEditor.TexturePropertySingleLine(Styles.normalMapText, normalMap, normalScale);
material.SetKeyword(new LocalKeyword(material.shader, "_NORMAL_MAP"), normalMap.textureValue != null);
if (m_pbrMode != PBRMode.Off)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.MaskMapText, Mask);
if (Mask.textureValue == null)
{
material.DisableKeyword(new LocalKeyword(material.shader, "_MASKMAP"));
material.DisableKeyword(new LocalKeyword(material.shader, "_MASK_MAP"));
if (m_pbrMode != PBRMode.KKHair)
{
GUI_RangeProperty(material, Styles.MetallicText);
@@ -1723,7 +1723,7 @@ namespace UnityEditor.Rendering.Toon
}
else
{
material.EnableKeyword(new LocalKeyword(material.shader, "_MASKMAP"));
material.EnableKeyword(new LocalKeyword(material.shader, "_MASK_MAP"));
m_MaterialEditor.MinMaxShaderProperty(MetallicRemapMin, MetallicRemapMax, minLimit: 0, 1, Styles.MetallicRemap);
m_MaterialEditor.MinMaxShaderProperty(AORemapMin, AORemapMax, 0, 1, Styles.AORemap);
m_MaterialEditor.MinMaxShaderProperty(RoughnessRemapMin, RoughnessRemapMax, 0, 1, Styles.RoughnessRemap);
@@ -1731,9 +1731,9 @@ namespace UnityEditor.Rendering.Toon
}
else
{
material.DisableKeyword(new LocalKeyword(material.shader, "_MASKMAP"));
material.DisableKeyword(new LocalKeyword(material.shader, "_ANISOTROPYMAP"));
material.DisableKeyword(new LocalKeyword(material.shader, "_SPECULARCOLORMAP"));
material.DisableKeyword(new LocalKeyword(material.shader, "_MASK_MAP"));
material.DisableKeyword(new LocalKeyword(material.shader, "_ANISOTROPY_MAP"));
material.DisableKeyword(new LocalKeyword(material.shader, "_SPECULAR_COLOR_MAP"));
}
@@ -1752,11 +1752,11 @@ namespace UnityEditor.Rendering.Toon
if (AnisotropyMap.textureValue == null)
{
material.DisableKeyword(new LocalKeyword(material.shader, "_ANISOTROPYMAP"));
material.DisableKeyword(new LocalKeyword(material.shader, "_ANISOTROPY_MAP"));
}
else
{
material.EnableKeyword(new LocalKeyword(material.shader, "_ANISOTROPYMAP"));
material.EnableKeyword(new LocalKeyword(material.shader, "_ANISOTROPY_MAP"));
}
}
@@ -1765,11 +1765,11 @@ namespace UnityEditor.Rendering.Toon
m_MaterialEditor.TexturePropertySingleLine(new GUIContent("Specular Color Map"), SpecColorMap, SpecColor);
if (SpecColorMap.textureValue == null)
{
material.DisableKeyword(new LocalKeyword(material.shader, "_SPECULARCOLORMAP"));
material.DisableKeyword(new LocalKeyword(material.shader, "_SPECULAR_COLOR_MAP"));
}
else
{
material.EnableKeyword(new LocalKeyword(material.shader, "_SPECULARCOLORMAP"));
material.EnableKeyword(new LocalKeyword(material.shader, "_SPECULAR_COLOR_MAP"));
}
m_MaterialEditor.MinMaxShaderProperty(SpecFeather, SpecStep, 0, 1, Styles.SpecRemap);
}
@@ -1815,6 +1815,22 @@ namespace UnityEditor.Rendering.Toon
MaterialSetInt(material, "_Use_SSSLut", 0);
}
}
void GUI_AmbientMode(Material material)
{
m_IndirectDiffuseMode = (IndirectDiffuseMode)MaterialGetInt(material, ShaderPropIDMode);
m_IndirectDiffuseMode = (IndirectDiffuseMode)EditorGUILayout.EnumPopup(Styles.indirectDiffuseModeText, m_IndirectDiffuseMode);
material.SetFloat(ShaderPropIDMode, (int)m_IndirectDiffuseMode);
SwitchKeywrod(material, IndirectDiffuseModeDefines[(int)m_IndirectDiffuseMode], IndirectDiffuseModeDefines);
m_IndirectSpecularMode = (IndirectSpecularMode)MaterialGetInt(material, ShaderPropISMode);
m_IndirectSpecularMode = (IndirectSpecularMode)EditorGUILayout.EnumPopup(Styles.indirectSpecularText, m_IndirectSpecularMode);
material.SetFloat(ShaderPropISMode, (int)m_IndirectSpecularMode);
SwitchKeywrod(material, IndirectSpecularModeDefines[(int)m_IndirectSpecularMode], IndirectSpecularModeDefines);
}
void GUI_HighlightSettings(Material material)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.highColorText, highColor_Tex, highColor);
@@ -1893,7 +1909,6 @@ namespace UnityEditor.Rendering.Toon
void GUI_RimLight(Material material)
{
EditorGUILayout.BeginHorizontal();
var rimLightEnabled = GUI_Toggle(material, Styles.rimlightText, ShaderPropRimLight, MaterialGetInt(material, ShaderPropRimLight) != 0);
EditorGUILayout.EndHorizontal();
@@ -1973,10 +1988,6 @@ namespace UnityEditor.Rendering.Toon
EditorGUILayout.Space();
EditorGUI.EndDisabledGroup();
}
void GUI_MatCap(Material material)
@@ -1986,9 +1997,9 @@ namespace UnityEditor.Rendering.Toon
EditorGUILayout.EndHorizontal();
EditorGUI.BeginDisabledGroup(!matcapEnabled);
m_MaterialEditor.TexturePropertySingleLine(Styles.matCapSamplerText, matCap_Sampler, matCapColor);
m_MaterialEditor.TexturePropertySingleLine(Styles.matCapSamplerText, matCapMap, matCapColor);
EditorGUI.indentLevel++;
m_MaterialEditor.TextureScaleOffsetProperty(matCap_Sampler);
m_MaterialEditor.TextureScaleOffsetProperty(matCapMap);
if (!_SimpleUI)
{
@@ -2232,9 +2243,9 @@ namespace UnityEditor.Rendering.Toon
void GUI_Emissive(Material material)
{
m_MaterialEditor.TexturePropertySingleLine(Styles.emissiveTexText, emissive_Tex, emissive_Color);
m_MaterialEditor.TextureScaleOffsetProperty(emissive_Tex);
material.SetKeyword(new LocalKeyword(material.shader, "_EMISSIVE_COLOR_MAP"), emissive_Tex.textureValue != null);
var _EmissiveMode_Setting = MaterialGetInt(material, "_EMISSIVE");
if ((int)EmissionMode.SimpleEmissive == _EmissiveMode_Setting)
@@ -2402,14 +2413,14 @@ namespace UnityEditor.Rendering.Toon
{
material.SetFloat(ShaderPropOutline, 0);
//The keywords on the UTCS_Outline.cginc side are also toggled around.
material.EnableKeyword("_OUTLINE_NML");
material.DisableKeyword("_OUTLINE_POS");
material.EnableKeyword("_OUTLINE_MODE_NML");
material.DisableKeyword("_OUTLINE_MODE_POS");
}
else if (m_outlineMode == OutlineMode.PositionScaling)
{
material.SetFloat(ShaderPropOutline, 1);
material.EnableKeyword("_OUTLINE_POS");
material.DisableKeyword("_OUTLINE_NML");
material.EnableKeyword("_OUTLINE_MODE_POS");
material.DisableKeyword("_OUTLINE_MODE_NML");
}
GUI_FloatProperty(material, Styles.outlineWidthText);

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f00671385fbbb674495b9f0b3d6dbe07
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using UnityEngine;
using static Misaki.HdrpToon.UtsShaderPropertyName;
namespace Misaki.HdrpToon.Editor
{
internal static class MaterialHelpers
{
public static ShadingMode GetShadingMode(this Material material)
{
if (!material.HasProperty(SurfaceOptions.SHADING_MODE))
{
return ShadingMode.Standard;
}
return (ShadingMode)material.GetInteger(SurfaceOptions.SHADING_MODE);
}
public static PBRMode GetPBRMode(this Material material)
{
if (!material.HasProperty(SurfaceOptions.PBR_MODE))
{
return PBRMode.Off;
}
return (PBRMode)material.GetInteger(SurfaceOptions.PBR_MODE);
}
public static bool HasFeature(this Material material, SurfaceFeature feature)
{
if (!material.HasProperty(SurfaceOptions.SURFACE_FEATURE))
{
return false;
}
var value = (SurfaceFeature)material.GetInteger(SurfaceOptions.SURFACE_FEATURE);
return (value & feature) != 0;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b32ea10056de246488796e50f7160a4a

View File

@@ -0,0 +1,23 @@
namespace Misaki.HdrpToon.Editor
{
public enum ShaderGUIExpandable : uint
{
SurfaceOptions = 1 << 0,
ShadingColor = 1 << 1,
Shadow = 1 << 2,
MaterialFeature = 1 << 3,
SurfaceInputs = 1 << 4,
Ambient = 1 << 5,
Highlight = 1 << 6,
Rimlight = 1 << 7,
MatCap = 1 << 8,
AngelRing = 1 << 9,
Emission = 1 << 10,
Outline = 1 << 11,
TessellationLegacy = 1 << 12,
TessellationHDRP = 1 << 13,
SceneLight = 1 << 14,
EnvironmentalLightEffectiveness = 1 << 15,
MetaverseSettings = 1 << 16,
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 63067f176ae106c459bcb9cc105f626d

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bc8d991d265341a4598574f90fc0e21c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,115 @@
using Misaki.ShaderGUI;
using UnityEditor;
using UnityEngine;
namespace Misaki.HdrpToon.Editor
{
public class AmbientScope : MaterialUIScope<ShaderGUIExpandable>
{
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Ambient;
protected override GUIContent Header => new("Ambient Settings");
private static class Properties
{
public static MaterialProperty indirectDiffuseMode;
public static MaterialProperty indirectSpecularMode;
public static MaterialProperty indirectDiffuseMatCapMap;
public static MaterialProperty indirectDiffuseMatCapLod;
public static MaterialProperty indirectDiffuseIntensity;
public static MaterialProperty ssaoWeight;
public static MaterialProperty ssgiWeight;
public static MaterialProperty indirectSpecularMatCapMap;
public static MaterialProperty indirectSpecularMatCapLod;
public static MaterialProperty indirectReflectionIntensity;
public static MaterialProperty ssrWeight;
}
private static class Styles
{
public static readonly GUIContent indirectDiffuseModeText = new("Indirect Diffuse Mode", "Specifies indirect diffuse mode.");
public static readonly GUIContent indirectSpecularModeText = new("Indirect Specular Mode", "Specifies indirect specular mode.");
public static readonly GUIContent indirectDiffuseMatCapMapText = new("MatCap Map", "The material capture map for indirect diffuse evaluation, with the additional setting for controlling the LOD offset when sampling the indirect diffuse material capture map.");
public static readonly GUIContent indirectDiffuseIntensityText = new("Intensity", "The indirect diffuse color is added to the material color according to the intensity value.");
public static readonly GUIContent ssaoWeightText = new("SSAO Weight", "The weight of SSAO.");
public static readonly GUIContent ssgiWeightText = new("SSGI Weight", "The weight of SSGI.");
public static readonly GUIContent indirectSpecularMatCapMapText = new("MatCap Map", "The material capture map for indirect specular evaluation, with the additional setting for controlling the LOD offset when sampling the indirect specular material capture map.");
public static readonly GUIContent indirectReflectionIntensityText = new("Intensity", "The indirect reflection color is added to the material color according to the intensity value.");
public static readonly GUIContent ssrWeightText = new("SSR Weight", "SSR Weight");
}
public override void LoadMaterialProperties()
{
Properties.indirectDiffuseMode = FindProperty("_Indirect_Diffuse_Mode");
Properties.indirectSpecularMode = FindProperty("_Indirect_Specular_Mode");
Properties.indirectDiffuseMatCapMap = FindProperty("_IndirectDiffuseMatCapMap");
Properties.indirectDiffuseMatCapLod = FindProperty("_IndirectDiffuseMatCapLod");
Properties.indirectDiffuseIntensity = FindProperty("_IndirectDiffuseIntensity");
Properties.ssaoWeight = FindProperty("_SSAOWeight");
Properties.ssgiWeight = FindProperty("_SSGIWeight");
Properties.indirectSpecularMatCapMap = FindProperty("_IndirectSpecularMatCapMap");
Properties.indirectSpecularMatCapLod = FindProperty("_IndirectSpecularMatCapLod");
Properties.indirectReflectionIntensity = FindProperty("_IndirectSpecularIntensity");
Properties.ssrWeight = FindProperty("_SSRWeight");
}
protected override void DrawContent()
{
editor.ShaderProperty(Properties.indirectDiffuseMode, Styles.indirectDiffuseModeText);
editor.ShaderProperty(Properties.indirectSpecularMode, Styles.indirectSpecularModeText);
var indirectDiffuseMode = Properties.indirectDiffuseMode.GetEnumValue<IndirectDiffuseMode>();
var indirectSpecularMode = Properties.indirectSpecularMode.GetEnumValue<IndirectSpecularMode>();
if (indirectDiffuseMode != IndirectDiffuseMode.Off)
{
EditorGUILayout.Space();
using (var indentLevelScope = new EditorGUI.IndentLevelScope(-1))
{
EditorGUILayout.LabelField("Indirect Diffuse", EditorStyles.boldLabel);
}
if (indirectDiffuseMode == IndirectDiffuseMode.Matcap)
{
editor.TexturePropertySingleLine(Styles.indirectDiffuseMatCapMapText, Properties.indirectDiffuseMatCapMap, Properties.indirectDiffuseMatCapLod);
}
editor.ShaderProperty(Properties.indirectDiffuseIntensity, Styles.indirectDiffuseIntensityText);
editor.ShaderProperty(Properties.ssaoWeight, Styles.ssaoWeightText);
if (indirectDiffuseMode == IndirectDiffuseMode.IBL)
{
editor.ShaderProperty(Properties.ssgiWeight, Styles.ssgiWeightText);
}
}
if (indirectSpecularMode != (int)IndirectSpecularMode.Off)
{
EditorGUILayout.Space();
using (var indentLevelScope = new EditorGUI.IndentLevelScope(-1))
{
EditorGUILayout.LabelField("Indirect Specular", EditorStyles.boldLabel);
}
if (indirectSpecularMode == IndirectSpecularMode.Matcap)
{
editor.TexturePropertySingleLine(Styles.indirectSpecularMatCapMapText, Properties.indirectSpecularMatCapMap, Properties.indirectSpecularMatCapLod);
}
editor.ShaderProperty(Properties.indirectReflectionIntensity, Styles.indirectReflectionIntensityText);
editor.ShaderProperty(Properties.ssrWeight, Styles.ssrWeightText);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0f3997bcef824e5a9bd3728830006bd1
timeCreated: 1738419718

View File

@@ -0,0 +1,55 @@
using Misaki.ShaderGUI;
using System.Linq;
using UnityEditor;
using UnityEngine;
using static Misaki.HdrpToon.UtsShaderPropertyName.AngelRing;
namespace Misaki.HdrpToon.Editor
{
internal class AngelRingScope : MaterialUIScope<ShaderGUIExpandable>
{
private static class Properties
{
public static MaterialProperty angelRingColor;
public static MaterialProperty angelRingColorMap;
public static MaterialProperty angelRingIntensity;
public static MaterialProperty angelRingOffsetU;
public static MaterialProperty angelRingOffsetV;
}
private static class Styles
{
public static readonly GUIContent angelRingColorText = new("Angel Ring Color", "Specifies the color of the angel ring.");
public static readonly GUIContent angelRingIntensityText = new("Angel Ring Intensity", "Specifies the intensity of the angel ring.");
public static readonly GUIContent angelRingOffsetUText = new("Angel Ring Offset U", "Specifies the offset of the angel ring in the U direction.");
public static readonly GUIContent angelRingOffsetVText = new("Angel Ring Offset V", "Specifies the offset of the angel ring in the V direction.");
}
protected override bool ShowSection => materials.All(mat => mat.HasFeature(SurfaceFeature.AngelRing));
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.AngelRing;
protected override GUIContent Header => EditorGUIUtility.TrTextContent("Angel Ring Settings");
public override void LoadMaterialProperties()
{
Properties.angelRingColor = FindProperty(ANGEL_RING_COLOR);
Properties.angelRingColorMap = FindProperty(ANGEL_RING_COLOR_MAP);
Properties.angelRingIntensity = FindProperty(ANGEL_RING_INTENSITY);
Properties.angelRingOffsetU = FindProperty(ANGEL_RING_OFFSET_U);
Properties.angelRingOffsetV = FindProperty(ANGEL_RING_OFFSET_V);
}
protected override void DrawContent()
{
editor.TexturePropertySingleLine(Styles.angelRingColorText, Properties.angelRingColorMap, Properties.angelRingColor);
editor.ShaderProperty(Properties.angelRingIntensity, Styles.angelRingIntensityText);
editor.ShaderProperty(Properties.angelRingOffsetU, Styles.angelRingOffsetUText);
editor.ShaderProperty(Properties.angelRingOffsetV, Styles.angelRingOffsetVText);
EditorGUILayout.Space();
editor.TextureScaleOffsetProperty(Properties.angelRingColorMap);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f21124eb2f73ac14e8cda9a0340191cd

View File

@@ -0,0 +1,92 @@
using Misaki.ShaderGUI;
using UnityEditor;
using UnityEngine;
using static Misaki.HdrpToon.UtsShaderPropertyName.Outline;
namespace Misaki.HdrpToon.Editor
{
internal class OutlineScope : MaterialUIScope<ShaderGUIExpandable>
{
private static class Properties
{
public static MaterialProperty outlineState;
public static MaterialProperty outlineWidth;
public static MaterialProperty outlineWidthMap;
public static MaterialProperty outlineColor;
public static MaterialProperty outlineColorMap;
public static MaterialProperty albedoAffectOutline;
public static MaterialProperty skyColorAffectOutline;
public static MaterialProperty skyColorIntensity;
public static MaterialProperty fadeIn;
public static MaterialProperty fadeOut;
public static MaterialProperty useSmoothedNormal;
}
private static class Styles
{
public static readonly GUIContent outlineStateText = new("Outline State", "Enable the outline pass for this material instance.");
public static readonly GUIContent outlineWidthText = new("Outline Width", "Specifies the width of the outline.");
public static readonly GUIContent outlineColorText = new("Outline Color", "Specifies the color of the outline.");
public static readonly GUIContent albedoAffectOutlineText = new("Albedo Affect Outline", "Enable to affect the outline color with the albedo color.");
public static readonly GUIContent skyColorAffectOutlineText = new("Sky Color Affect Outline", "Enable to affect the outline color with the sky color.");
public static readonly GUIContent skyColorIntensityText = new("Sky Color Intensity", "The intensity of the sky color when add to the outline color.");
public static readonly GUIContent fadeInText = new("Fade In Distance", "Specify the nearest distance, where the outline width changes with the distance between the camera and the object. The outline will be the maximum width at this distance.");
public static readonly GUIContent fadeOutText = new("Fade Out Distance", "Specify the furthest distance, where the outline width changes with the distance between the camera and the object. The outline will be zero at this distance.");
public static readonly GUIContent useSmoothedNormalText = new("Use Smoothed Normal", "Enable to use smoothed normal(that packed in uv2) for outline calculation.");
}
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Outline;
protected override GUIContent Header => EditorGUIUtility.TrTextContent("Outline Settings");
public override void LoadMaterialProperties()
{
Properties.outlineState = FindProperty(OUTLINE_STATE);
Properties.outlineWidth = FindProperty(OUTLINE_WIDTH);
Properties.outlineWidthMap = FindProperty(OUTLINE_WIDTH_MAP);
Properties.outlineColor = FindProperty(OUTLINE_COLOR);
Properties.outlineColorMap = FindProperty(OUTLINE_COLOR_MAP);
Properties.albedoAffectOutline = FindProperty(ALBEDO_AFFECT_OUTLINE);
Properties.skyColorAffectOutline = FindProperty(SKY_COLOR_AFFECT_OUTLINE);
Properties.skyColorIntensity = FindProperty(SKY_COLOR_INTENSITY);
Properties.fadeIn = FindProperty(OUTLINE_FADE_IN);
Properties.fadeOut = FindProperty(OUTLINE_FADE_OUT);
Properties.useSmoothedNormal = FindProperty(USE_SMOOTHED_NORMAL);
}
protected override void DrawContent()
{
editor.ShaderProperty(Properties.outlineState, Styles.outlineStateText);
if (Properties.outlineState.GetBooleanValue())
{
EditorGUILayout.Space();
editor.TexturePropertySingleLine(Styles.outlineWidthText, Properties.outlineWidthMap, Properties.outlineWidth);
editor.TexturePropertySingleLine(Styles.outlineColorText, Properties.outlineColorMap, Properties.outlineColor);
editor.ShaderProperty(Properties.albedoAffectOutline, Styles.albedoAffectOutlineText);
editor.ShaderProperty(Properties.skyColorAffectOutline, Styles.skyColorAffectOutlineText);
if (Properties.skyColorAffectOutline.GetBooleanValue())
{
using var skyColorIndentLevelScope = new EditorGUI.IndentLevelScope();
editor.ShaderProperty(Properties.skyColorIntensity, Styles.skyColorIntensityText);
}
EditorGUILayout.Space();
editor.ShaderProperty(Properties.fadeIn, Styles.fadeInText);
editor.ShaderProperty(Properties.fadeOut, Styles.fadeOutText);
editor.ShaderProperty(Properties.useSmoothedNormal, Styles.useSmoothedNormalText);
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ac42903bc14e05f41a9a06d1e6cf5cd9

View File

@@ -0,0 +1,84 @@
using Misaki.ShaderGUI;
using System.Linq;
using UnityEditor;
using UnityEngine;
using static Misaki.HdrpToon.UtsShaderPropertyName.RimLight;
namespace Misaki.HdrpToon.Editor
{
public class RimLightScope : MaterialUIScope<ShaderGUIExpandable>
{
private static class Properties
{
public static MaterialProperty rimLightColor;
public static MaterialProperty rimLightIntensity;
public static MaterialProperty screenSpaceRimLight;
public static MaterialProperty rimLightLevel;
public static MaterialProperty rimLightClipping;
public static MaterialProperty rimLightClippingLevel;
public static MaterialProperty lightBaseRimLight;
public static MaterialProperty lightDirectionRimLightLevel;
}
private static class Styles
{
public static readonly GUIContent rimLightColorText = new("Rim Light Color", "Specifies the color of rim light.");
public static readonly GUIContent rimLightIntensityText = new("Rim Light Strength", "Specifies Rim Light strength.");
public static readonly GUIContent screenSpaceRimLightText = new("Screen Space Rim Light", "Enable to make the rim light width constant in screen space.");
public static readonly GUIContent rimLightLevelText = new("Rim Light Level", "Specifies Rim Light power intensity.");
public static readonly GUIContent rimLightClippingText = new("Rim Light Clipping", "Enable to Clip the rim light at specific level");
public static readonly GUIContent rimLightClippingLevelText = new("Clipping Level", "The Clipping value of the rim light.");
public static readonly GUIContent lightBaseRimLightText = new("Light Base Rim Light", "Enable to let rim light calculate per light.");
public static readonly GUIContent lightDirectionRimLightLevelText = new("Light Direction Level", "Specifies intensity of Rim Light in the light source direction,");
}
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Rimlight;
protected override GUIContent Header => EditorGUIUtility.TrTextContent("Rim Light Settings");
protected override bool ShowSection => materials.All(mat => mat.HasFeature(SurfaceFeature.RimLight));
public override void LoadMaterialProperties()
{
Properties.rimLightColor = FindProperty(RIM_LIGHT_COLOR);
Properties.rimLightIntensity = FindProperty(RIM_LIGHT_INTENSITY);
Properties.screenSpaceRimLight = FindProperty(SCREEN_SPACE_RIM_LIGHT);
Properties.rimLightLevel = FindProperty(RIM_LIGHT_LEVEL);
Properties.rimLightClipping = FindProperty(RIM_LIGHT_CLIPPING);
Properties.rimLightClippingLevel = FindProperty(RIM_LIGHT_CLIPPING_LEVEL);
Properties.lightBaseRimLight = FindProperty(LIGHT_BASE_RIM_LIGHT);
Properties.lightDirectionRimLightLevel = FindProperty(LIGHT_DIRECTION_RIM_LIGHT_LEVEL);
}
protected override void DrawContent()
{
editor.ShaderProperty(Properties.rimLightColor, Styles.rimLightColorText);
editor.ShaderProperty(Properties.rimLightIntensity, Styles.rimLightIntensityText);
editor.ShaderProperty(Properties.screenSpaceRimLight, Styles.screenSpaceRimLightText);
editor.ShaderProperty(Properties.rimLightLevel, Styles.rimLightLevelText);
if (!Properties.screenSpaceRimLight.GetBooleanValue())
{
editor.ShaderProperty(Properties.rimLightClipping, Styles.rimLightClippingText);
if (Properties.rimLightClipping.GetBooleanValue())
{
using var clippingLevelIndentLevelScope = new EditorGUI.IndentLevelScope();
editor.ShaderProperty(Properties.rimLightClippingLevel, Styles.rimLightClippingLevelText);
}
}
EditorGUILayout.Space();
editor.ShaderProperty(Properties.lightBaseRimLight, Styles.lightBaseRimLightText);
if (Properties.lightBaseRimLight.GetBooleanValue())
{
editor.ShaderProperty(Properties.lightDirectionRimLightLevel, Styles.lightDirectionRimLightLevelText);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c18934f763fe4f3cb5e6f02599209764
timeCreated: 1738311777

View File

@@ -0,0 +1,151 @@
using Misaki.ShaderGUI;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace Misaki.HdrpToon.Editor
{
public class ShadingColorScope : MaterialUIScope<ShaderGUIExpandable>
{
private static class Properties
{
public static MaterialProperty shadingRampMapState;
public static MaterialProperty baseColor;
public static MaterialProperty baseColorMap;
public static MaterialProperty applyTo1stShadingMapEnable;
public static MaterialProperty firstShadingColor;
public static MaterialProperty firstShadingMap;
public static MaterialProperty applyTo2ndShadingMapEnable;
public static MaterialProperty secondShadingColor;
public static MaterialProperty secondShadingMap;
public static MaterialProperty firstShadeColorStep;
public static MaterialProperty firstShadeColorFeather;
public static MaterialProperty secondShadeColorStep;
public static MaterialProperty secondShadeColorFeather;
public static MaterialProperty shadingRampMap;
public static MaterialProperty shadingIndex;
public static MaterialProperty shadingRampMaskMap;
public static MaterialProperty shadingRampMask;
public static MaterialProperty sdfShadingMap;
public static MaterialProperty sdfShadowLevel;
public static MaterialProperty sdfSmoothLevel;
public static MaterialProperty sdfHighlightStrength;
}
private static class Styles
{
public static readonly GUIContent shadingRampMapStateText = new("Shading Ramp Map State", "Use Shading Ramp Map to control the shading color instead of manually setting the shading color.");
public static readonly GUIContent baseColorText = new("Base Map", "Base Color : Texture(sRGB) x Color(RGB) Default:White");
public static readonly GUIContent applyTo1stShadingMapText = new("Apply to 1st shading map", "Apply Base map to the 1st shading map.");
public static readonly GUIContent firstShadingMapText = new("1st Shading Map", "The map used for the brighter portions of the shadow.");
public static readonly GUIContent applyTo2ndShadingMapText = new("Apply to 2nd shading map", "Apply Base map or the 1st shading map to the 2st shading map.");
public static readonly GUIContent secondShadingMapText = new("2nd Shading Map", "The map used for the darker portions of the shadow.");
public static readonly GUIContent firstShadeColorStepText = new("1st Shade Color Step", "Sets the step between the Base color and 1st Shade Color, the same as the BaseColor_Step property.");
public static readonly GUIContent firstShadeColorFeatherText = new("1st Shade Color Feather", "Sets the feather between the Base color and 1st Shade Color, the same as the BaseColor_Feather property.");
public static readonly GUIContent secondShadeColorStepText = new("2nd Shade Color Step", "Sets the step between the 1st Shade color and 2nd Shade Color, the same as the 1stShadeColorStep property.");
public static readonly GUIContent secondShadeColorFeatherText = new("2nd Shade Color Feather", "Sets the feather between the 1st Shade color and 2nd Shade Color, the same as the 1stShadeColorFeather property.");
public static readonly GUIContent sdfShadingMapText = new("SDF Shading Map", "The map used for the SDF shading. R channel for SDF shadow, G channel for highlight, B channel for fixed shadow.");
public static readonly GUIContent sdfShadowLevelText = new("SDF Shadow Level", "Control the sampling position of the shadow in the SDF shading map.");
public static readonly GUIContent sdfSmoothLevelText = new("SDF Smooth Level", "Control the smoothness of the shadow edge.");
public static readonly GUIContent shadingRampMapText = new("Shading Ramp Map", "A texture 2D array that contains a ramp color in each slice, and the index to choose when sampling the shading ramp map.");
public static readonly GUIContent shadingRampMaskMapText = new("Shading Ramp Mask Map", "A texture that contains the mask for the shading ramp map.");
public static readonly GUIContent sdfHighlightStrengthText = new("SDF Highlight Strength", "Control the strength of the highlight in the SDF shading map.");
}
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.ShadingColor;
protected override GUIContent Header => EditorGUIUtility.TrTextContent("Shading Color Settings");
private void DrawShadingProperties(MaterialProperty inheritProperty, MaterialProperty colorProperty, MaterialProperty colorMapProperty, GUIContent inheritText, GUIContent colorText)
{
EditorGUI.indentLevel += 2;
editor.ShaderProperty(inheritProperty, inheritText);
EditorGUI.indentLevel -= 2;
if (Mathf.Approximately(inheritProperty.floatValue, 1))
{
EditorGUI.indentLevel += 2;
editor.ShaderProperty(colorProperty, colorText);
EditorGUI.indentLevel -= 2;
}
else
{
editor.TexturePropertySingleLine(colorText, colorMapProperty, colorProperty);
}
}
public override void LoadMaterialProperties()
{
Properties.shadingRampMapState = FindProperty("_Use_Shading_Ramp_Map");
Properties.baseColor = FindProperty("_BaseColor");
Properties.baseColorMap = FindProperty("_BaseColorMap");
Properties.applyTo1stShadingMapEnable = FindProperty("_UseBaseAs1st");
Properties.firstShadingColor = FindProperty("_1stShadeColor");
Properties.firstShadingMap = FindProperty("_1stShadeColorMap");
Properties.applyTo2ndShadingMapEnable = FindProperty("_Use1stAs2nd");
Properties.secondShadingColor = FindProperty("_2ndShadeColor");
Properties.secondShadingMap = FindProperty("_2ndShadeColorMap");
Properties.firstShadeColorStep = FindProperty("_1stShadeColorStep");
Properties.firstShadeColorFeather = FindProperty("_1stShadeColorFeather");
Properties.secondShadeColorStep = FindProperty("_2ndShadeColorStep");
Properties.secondShadeColorFeather = FindProperty("_2ndShadeColorFeather");
Properties.shadingRampMap = FindProperty("_ShadingRampMap");
Properties.shadingIndex = FindProperty("_ShadingIndex");
Properties.shadingRampMaskMap = FindProperty("_ShadingRampMaskMap");
Properties.shadingRampMask = FindProperty("_ShadingRampMask");
Properties.sdfShadingMap = FindProperty("_SDFShadingMap");
Properties.sdfShadowLevel = FindProperty("_SDFShadowLevel");
Properties.sdfSmoothLevel = FindProperty("_SDFShadowSmoothLevel");
Properties.sdfHighlightStrength = FindProperty("_SDFHighlightStrength");
}
protected override void DrawContent()
{
editor.ShaderProperty(Properties.shadingRampMapState, Styles.shadingRampMapStateText);
editor.TexturePropertySingleLine(Styles.baseColorText, Properties.baseColorMap, Properties.baseColor);
if (Properties.shadingRampMapState.GetBooleanValue())
{
editor.TexturePropertySingleLine(Styles.shadingRampMapText, Properties.shadingRampMap, Properties.shadingIndex);
editor.KeywordTexturePropertySingleLine(Styles.shadingRampMaskMapText, Properties.shadingRampMaskMap, Properties.shadingRampMask, "_SHADING_RAMP_MASK_MAP");
}
else
{
DrawShadingProperties(Properties.applyTo1stShadingMapEnable, Properties.firstShadingColor, Properties.firstShadingMap, Styles.applyTo1stShadingMapText, Styles.firstShadingMapText);
if (materials.All(material => material.GetShadingMode() == ShadingMode.Standard))
{
DrawShadingProperties(Properties.applyTo2ndShadingMapEnable, Properties.secondShadingColor, Properties.secondShadingMap, Styles.applyTo2ndShadingMapText, Styles.secondShadingMapText);
EditorGUILayout.Space();
editor.ShaderProperty(Properties.firstShadeColorStep, Styles.firstShadeColorStepText);
editor.ShaderProperty(Properties.firstShadeColorFeather, Styles.firstShadeColorFeatherText);
editor.ShaderProperty(Properties.secondShadeColorStep, Styles.secondShadeColorStepText);
editor.ShaderProperty(Properties.secondShadeColorFeather, Styles.secondShadeColorFeatherText);
}
}
if (materials.All(material => material.GetShadingMode() == ShadingMode.SDF))
{
EditorGUILayout.Space();
editor.TexturePropertySingleLine(Styles.sdfShadingMapText, Properties.sdfShadingMap);
editor.ShaderProperty(Properties.sdfShadowLevel, Styles.sdfShadowLevelText);
editor.ShaderProperty(Properties.sdfSmoothLevel, Styles.sdfSmoothLevelText);
editor.ShaderProperty(Properties.sdfHighlightStrength, Styles.sdfHighlightStrengthText);
}
EditorGUILayout.Space();
editor.TextureScaleOffsetProperty(Properties.baseColorMap);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 35d7c7fd9279ea64199f1aa61c24fbcd

View File

@@ -0,0 +1,57 @@
using Misaki.ShaderGUI;
using UnityEditor;
using UnityEngine;
namespace Misaki.HdrpToon.Editor
{
internal class ShadowScope : MaterialUIScope<ShaderGUIExpandable>
{
private static class Properties
{
public static MaterialProperty receiveLightShadow;
public static MaterialProperty receiveScreenSpaceShadow;
public static MaterialProperty receiveHairShadow;
public static MaterialProperty shadowDistanceBias;
public static MaterialProperty shadowNormalBias;
}
private static class Styles
{
public static readonly GUIContent receiveLightShadowText = new("Receive Light Shadow", "Enable to receive shadow from light.");
public static readonly GUIContent receiveHairShadowText = new("Receive Hair Shadow", "Enable to receive shadow from hair shadow caster");
public static readonly GUIContent receiveScreenSpaceShadowText = new("Receive Screen Space Shadow", "Enable to receive screen space shadow.");
public static readonly GUIContent lightShadowBiasText = new("Light Shadow Bias", "Specifies the bias of the light shadow.");
public static readonly GUIContent lightShadowNormalBiasText = new("Light Shadow Normal Bias", "Specifies the normal bias of the light shadow.");
}
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Shadow;
protected override GUIContent Header => EditorGUIUtility.TrTextContent("Shadow Settings");
public override void LoadMaterialProperties()
{
Properties.receiveLightShadow = FindProperty("_Receive_Light_Shadow");
Properties.receiveScreenSpaceShadow = FindProperty("_Receive_Screen_Space_Shadow");
Properties.receiveHairShadow = FindProperty("_Receive_Hair_Shadow");
Properties.shadowDistanceBias = FindProperty("_ShadowDistanceBias");
Properties.shadowNormalBias = FindProperty("_ShadowNormalBias");
}
protected override void DrawContent()
{
editor.ShaderProperty(Properties.receiveLightShadow, Styles.receiveLightShadowText);
if (Properties.receiveLightShadow.GetBooleanValue())
{
editor.ShaderProperty(Properties.receiveScreenSpaceShadow, Styles.receiveScreenSpaceShadowText);
}
editor.ShaderProperty(Properties.receiveHairShadow, Styles.receiveHairShadowText);
EditorGUILayout.Space();
editor.ShaderProperty(Properties.shadowDistanceBias, Styles.lightShadowBiasText);
editor.ShaderProperty(Properties.shadowNormalBias, Styles.lightShadowNormalBiasText);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8f9bb5393aec4e648a1c3b2ba0d566c3

View File

@@ -0,0 +1,178 @@
using Misaki.ShaderGUI;
using System.Linq;
using UnityEditor;
using UnityEditor.Rendering;
using UnityEngine;
using static Misaki.HdrpToon.UtsShaderPropertyName.SurfaceInputs;
namespace Misaki.HdrpToon.Editor
{
public class SurfaceInputsScope : MaterialUIScope<ShaderGUIExpandable>
{
private static class Properties
{
public static MaterialProperty NormalMap;
public static MaterialProperty NormalMapScale;
public static MaterialProperty MaskMap;
public static MaterialProperty Metallic;
public static MaterialProperty MetallicRemapMin;
public static MaterialProperty MetallicRemapMax;
public static MaterialProperty AORemapMin;
public static MaterialProperty AORemapMax;
public static MaterialProperty Smoothness;
public static MaterialProperty SmoothnessRemapMin;
public static MaterialProperty SmoothnessRemapMax;
public static MaterialProperty AnisotropyMap;
public static MaterialProperty Anisotropy;
public static MaterialProperty KKColor;
public static MaterialProperty BSDFContribution;
public static MaterialProperty SpecularColorMap;
public static MaterialProperty SpecularColor;
public static MaterialProperty SpecularFeather;
public static MaterialProperty SpecularStep;
public static MaterialProperty emissiveColorLDR;
public static MaterialProperty emissiveColorMap;
public static MaterialProperty emissiveIntensity;
public static MaterialProperty albedoAffectEmissive;
public static MaterialProperty emissiveExposureWeight;
}
private static class Styles
{
public static readonly GUIContent NormalMapText = new("Normal Map", "A texture that dictates the bumpiness of the material.");
public static readonly GUIContent MaskMapText = new("Mask Map", "A texture that dictates the physical properties of the material. R channel for metallic, G channel for ambient occlusion, A channel for smoothness");
public static readonly GUIContent MetallicText = new("Metallic", "Specifies the metallic value of the material.");
public static readonly GUIContent MetallicRemap = new("Metallic Remap", "Remap the max and min value of metallic");
public static readonly GUIContent AORemap = new("AO Remap", "Remap the max and min value of ambient occlusion");
public static readonly GUIContent SmoothnessText = new("Smoothness", "Specifies the smoothness of the material.");
public static readonly GUIContent SmoothnessRemapText = new("Smoothness Remap", "Remap the max and min value of smoothness");
public static readonly GUIContent AnisotropyMapText = new("Anisotropy Map", "Specifies the anisotropy map of the material.");
public static readonly GUIContent KKColorText = new("KK specular Color", "Specifies the color of KK specular.");
public static readonly GUIContent BSDFContributionText = new("BSDF Contribution", "BSDF smoothness contribution, 1 means KK Hair smoothness will fully contribute bsdf calculation");
public static readonly GUIContent SpecularColorMapText = new("Specular Color Map", "Specifies the specular color map of the material.");
public static readonly GUIContent SpecRemap = new("Specular Remap", "Feather and step value of Toon Specular");
public static readonly GUIContent emissiveColorText = new("Emissive Color", "The color and color map to set for emissive effect.");
public static readonly GUIContent albedoAffectEmissiveText = new("Albedo Affect Emissive", "Enable to affect emissive color with base color");
public static readonly GUIContent emissiveIntensityText = new("Emissive Intensity", "Set the intensity of the emissive color,in Nits");
public static readonly GUIContent emissiveExposureWeightText = new("Exposure Weight", "Controls how the camera exposure influences the perceived intensity of the emissivity. A weight of 0 means that the emissive intensity is calculated ignoring the exposure; increasing this weight progressively increases the influence of exposure on the final emissive value.");
}
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.SurfaceInputs;
protected override GUIContent Header => new("Surface Inputs");
public override void LoadMaterialProperties()
{
Properties.NormalMap = FindProperty("_NormalMap");
Properties.NormalMapScale = FindProperty("_NormalScale");
Properties.MaskMap = FindProperty("_MaskMap");
Properties.Metallic = FindProperty("_Metallic");
Properties.MetallicRemapMin = FindProperty("_MetallicRemapMin");
Properties.MetallicRemapMax = FindProperty("_MetallicRemapMax");
Properties.AORemapMin = FindProperty("_AORemapMin");
Properties.AORemapMax = FindProperty("_AORemapMax");
Properties.SmoothnessRemapMin = FindProperty("_SmoothnessRemapMin");
Properties.SmoothnessRemapMax = FindProperty("_SmoothnessRemapMax");
Properties.Smoothness = FindProperty("_Smoothness");
Properties.AnisotropyMap = FindProperty("_AnisotropyMap");
Properties.Anisotropy = FindProperty("_Anisotropy");
Properties.KKColor = FindProperty("_KKColor");
Properties.BSDFContribution = FindProperty("_BSDFContribution");
Properties.SpecularColorMap = FindProperty("_SpecularColorMap");
Properties.SpecularColor = FindProperty("_SpecularColor");
Properties.SpecularFeather = FindProperty("_ToonSpecularFeather");
Properties.SpecularStep = FindProperty("_ToonSpecularStep");
Properties.emissiveColorLDR = FindProperty(EMISSIVE_COLOR_LDR);
Properties.emissiveColorMap = FindProperty(EMISSIVE_COLOR_MAP);
Properties.albedoAffectEmissive = FindProperty(ALBEDO_AFFECT_EMISSIVE);
Properties.emissiveIntensity = FindProperty(EMISSIVE_INTENSITY);
Properties.emissiveExposureWeight = FindProperty(EMISSIVE_EXPOSURE_WEIGHT);
}
protected override void DrawContent()
{
editor.KeywordTexturePropertySingleLine(Styles.NormalMapText, Properties.NormalMap, Properties.NormalMapScale);
if (materials.All(mat => mat.GetPBRMode() != PBRMode.Off))
{
if (editor.KeywordTexturePropertySingleLine(Styles.MaskMapText, Properties.MaskMap))
{
editor.MinMaxShaderProperty(Properties.MetallicRemapMin, Properties.MetallicRemapMax, 0, 1, Styles.MetallicRemap);
editor.MinMaxShaderProperty(Properties.AORemapMin, Properties.AORemapMax, 0, 1, Styles.AORemap);
editor.MinMaxShaderProperty(Properties.SmoothnessRemapMin, Properties.SmoothnessRemapMax, 0, 1, Styles.SmoothnessRemapText);
}
else
{
if (materials.All(mat => mat.GetPBRMode() != PBRMode.KKHair))
{
editor.ShaderProperty(Properties.Metallic, Styles.MetallicText);
}
editor.ShaderProperty(Properties.Smoothness, Styles.SmoothnessText);
}
}
if (materials.All(mat => mat.GetPBRMode() == PBRMode.Anisotropy || mat.GetPBRMode() == PBRMode.KKHair))
{
editor.KeywordTexturePropertySingleLine(Styles.AnisotropyMapText, Properties.AnisotropyMap, Properties.Anisotropy);
if (materials.All(mat => mat.GetPBRMode() == PBRMode.KKHair))
{
editor.ShaderProperty(Properties.KKColor, Styles.KKColorText);
editor.ShaderProperty(Properties.BSDFContribution, Styles.BSDFContributionText);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Anisotropy Map only ST");
editor.TextureScaleOffsetProperty(Properties.AnisotropyMap);
}
else if (materials.All(mat => mat.GetPBRMode() == PBRMode.Toon))
{
editor.KeywordTexturePropertySingleLine(Styles.SpecularColorMapText, Properties.SpecularColorMap, Properties.SpecularColor);
editor.MinMaxShaderProperty(Properties.SpecularFeather, Properties.SpecularStep, 0, 1, Styles.SpecRemap);
}
EditorGUILayout.Space();
using (var EmissiveIntentLevel = new EditorGUI.IndentLevelScope(-1))
{
EditorGUILayout.LabelField("Emissive", EditorStyles.boldLabel);
}
EditorGUI.BeginChangeCheck();
editor.KeywordTexturePropertySingleLine(Styles.emissiveColorText, Properties.emissiveColorMap, Properties.emissiveColorLDR, "_EMISSIVE_COLOR_MAP");
editor.ShaderProperty(Properties.emissiveIntensity, Styles.emissiveIntensityText);
if (EditorGUI.EndChangeCheck())
{
foreach (var material in materials)
{
if (material.HasProperty(EMISSIVE_COLOR_LDR) && material.HasProperty(EMISSIVE_INTENSITY) && material.HasProperty(EMISSIVE_COLOR))
{
// Important: The color picker for kEmissiveColorLDR is LDR and in sRGB color space but Unity don't perform any color space conversion in the color
// picker BUT only when sending the color data to the shader... So as we are doing our own calculation here in C#, we must do the conversion ourselves.
var emissiveColorLDR = material.GetColor(EMISSIVE_COLOR_LDR);
var emissiveColorLDRLinear = new Color(Mathf.GammaToLinearSpace(emissiveColorLDR.r), Mathf.GammaToLinearSpace(emissiveColorLDR.g), Mathf.GammaToLinearSpace(emissiveColorLDR.b));
material.SetColor(EMISSIVE_COLOR, emissiveColorLDRLinear * material.GetFloat(EMISSIVE_INTENSITY));
}
}
}
EditorGUILayout.Space();
editor.ShaderProperty(Properties.albedoAffectEmissive, Styles.albedoAffectEmissiveText);
editor.ShaderProperty(Properties.emissiveExposureWeight, Styles.emissiveExposureWeightText);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 184fb730617fcf24592d8e6c49e2029a

View File

@@ -0,0 +1,100 @@
using Misaki.ShaderGUI;
using UnityEditor;
using UnityEngine;
namespace Misaki.HdrpToon.Editor
{
internal class SurfaceOptionsScope : MaterialUIScope<ShaderGUIExpandable>
{
private static class Properties
{
public static MaterialProperty transparentMode;
public static MaterialProperty alphaClipEnable;
public static MaterialProperty alphaClip;
public static MaterialProperty cullMode;
public static MaterialProperty shadingMode;
public static MaterialProperty materialType;
public static MaterialProperty pbrMode;
public static MaterialProperty hairBlendingTarget;
public static MaterialProperty surfaceFeatures;
}
private static class Styles
{
public static readonly GUIContent transparentModeText = new("Transparent Mode", "Enable different modes that allow the simulation of a variety of transparent objects.");
public static readonly GUIContent alphaClipEnableText = new("Alpha Clipping", "Enable alpha clipping.");
public static readonly GUIContent alphaClipText = new("Alpha Clipping Threshold", "Threshold for alpha clipping.");
public static readonly GUIContent cullingModeText = new("Culling Mode", "Controls the sides of polygons that should not be drawn (culled).");
public static readonly GUIContent shadingModeText = new("Shading Color Mode", "Specifies the shading grade mode.");
public static readonly GUIContent materialTypeText = new("Material Type", "Specifies the material type.");
public static readonly GUIContent pbrModeText = new("PBR Mode", "Specifies PBR model mode.");
public static readonly GUIContent hairBlendingTargetText = new("Hair Blending Target", "Enable to be blended with hair");
public static readonly GUIContent surfaceFeaturesText = new("Surface Features", "Specifies the surface features.");
}
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.SurfaceOptions;
protected override GUIContent Header => EditorGUIUtility.TrTextContent("Surface Options");
public override void LoadMaterialProperties()
{
Properties.transparentMode = FindProperty("_TransparentEnabled");
Properties.alphaClipEnable = FindProperty("_AlphaCutoffEnable");
Properties.alphaClip = FindProperty("_AlphaCutoff");
Properties.cullMode = FindProperty("_CullMode");
Properties.shadingMode = FindProperty("_Shading_Mode");
Properties.materialType = FindProperty("_Material_Type");
Properties.pbrMode = FindProperty("_PBR_Mode");
Properties.hairBlendingTarget = FindProperty("_HairBlendingTarget");
Properties.surfaceFeatures = FindProperty("_SurfaceFeatures");
}
protected override void DrawContent()
{
editor.ShaderProperty(Properties.transparentMode, Styles.transparentModeText);
editor.ShaderProperty(Properties.alphaClipEnable, Styles.alphaClipEnableText);
if (Properties.alphaClipEnable.floatValue == 1.0f)
{
EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.alphaClip, Styles.alphaClipText);
EditorGUI.indentLevel--;
}
editor.ShaderProperty(Properties.cullMode, Styles.cullingModeText);
editor.ShaderProperty(Properties.shadingMode, Styles.shadingModeText);
EditorGUI.BeginChangeCheck();
editor.ShaderProperty(Properties.materialType, Styles.materialTypeText);
if (EditorGUI.EndChangeCheck())
{
foreach (var material in materials)
{
material.SetShaderPassEnabled(UtsShaderPassName.HAIR_SHADOW_CASTER_PASS_NAME, Properties.materialType.GetEnumValue<MaterialType>() == MaterialType.FrontHair);
}
}
editor.ShaderProperty(Properties.pbrMode, Styles.pbrModeText);
EditorGUI.BeginChangeCheck();
editor.ShaderProperty(Properties.hairBlendingTarget, Styles.hairBlendingTargetText);
if (EditorGUI.EndChangeCheck())
{
foreach (var material in materials)
{
material.SetShaderPassEnabled(UtsShaderPassName.HAIR_BLENDING_TARGET_PASS_NAME, Properties.hairBlendingTarget.floatValue == 1.0f);
}
}
editor.ShaderProperty(Properties.surfaceFeatures, Styles.surfaceFeaturesText);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f62b264626a3bbd42a7b45b899084983

View File

@@ -0,0 +1,50 @@
using Misaki.ShaderGUI;
using UnityEditor;
using UnityEngine;
namespace Misaki.HdrpToon.Editor
{
public class UTSShaderGUI : ScopedShaderGUI
{
private GUIStyle _headerStyle;
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
if (!initialized)
{
OnInitialize(materialEditor, properties);
}
EditorGUILayout.Space(10);
EditorGUILayout.LabelField("HDRP Toon Shader", _headerStyle);
EditorGUILayout.Space(20);
DrawShaderGUI(properties);
}
private void OnInitialize(MaterialEditor materialEditor, MaterialProperty[] properties)
{
AddUIScope(new SurfaceOptionsScope());
AddUIScope(new ShadingColorScope());
AddUIScope(new ShadowScope());
AddUIScope(new SurfaceInputsScope());
AddUIScope(new AmbientScope());
AddUIScope(new RimLightScope());
AddUIScope(new AngelRingScope());
AddUIScope(new OutlineScope());
Initialize(materialEditor, properties);
_headerStyle = new GUIStyle()
{
fontSize = 25,
fontStyle = FontStyle.Bold,
alignment = TextAnchor.MiddleCenter,
normal =
{
textColor = GUI.skin.label.normal.textColor
}
};
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 41e8a43d8ee32f04cbf2ac4d1db45948

View File

@@ -7,7 +7,9 @@
"Unity.RenderPipelines.Core.Editor",
"Unity.RenderPipelines.HighDefinition.Runtime",
"Unity.RenderPipelines.HighDefinition.Editor",
"Unity.Collections"
"Unity.Mathematics",
"Unity.Collections",
"Misaki.ShaderGUI"
],
"includePlatforms": [
"Editor"
@@ -29,11 +31,6 @@
"expression": "",
"define": "SRPCORE_IS_INSTALLED_FOR_UTS"
},
{
"name": "com.unity.render-pipelines.universal",
"expression": "",
"define": "URP_IS_INSTALLED_FOR_UTS"
},
{
"name": "com.unity.render-pipelines.core",
"expression": "12.0.0",

View File

@@ -16,6 +16,10 @@ namespace Misaki.HdrpToon.Editor
private SerializedObject _customSettings;
private SerializedProperty _hairShadowSetting;
private SerializedProperty _hairBlendingSetting;
private SerializedProperty _outlineSetting;
public UTSRendererSettingProvider(string path, SettingsScope scopes, IEnumerable<string> keywords = null) : base(path, scopes, keywords)
{
}
@@ -23,15 +27,19 @@ namespace Misaki.HdrpToon.Editor
public override void OnActivate(string searchContext, VisualElement rootElement)
{
_customSettings = UTSRenderPassSettings.GetSerializedSettings();
_hairShadowSetting = _customSettings.FindProperty("hairShadowSetting");
_hairBlendingSetting = _customSettings.FindProperty("hairBlendingSetting");
_outlineSetting = _customSettings.FindProperty("outlineSetting");
}
public override void OnGUI(string searchContext)
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(_customSettings.FindProperty("hairShadowSetting"), Styles.hairShadow);
EditorGUILayout.PropertyField(_customSettings.FindProperty("hairBlendingSetting"), Styles.hairBlending);
EditorGUILayout.PropertyField(_customSettings.FindProperty("outlineSetting"), Styles.outline);
EditorGUILayout.PropertyField(_hairShadowSetting, Styles.hairShadow);
EditorGUILayout.PropertyField(_hairBlendingSetting, Styles.hairBlending);
EditorGUILayout.PropertyField(_outlineSetting, Styles.outline);
_customSettings.ApplyModifiedPropertiesWithoutUndo();
if (EditorGUI.EndChangeCheck())

View File

@@ -0,0 +1,162 @@
#pragma kernel SkinLut
#pragma kernel ShadowLut
#pragma multi_compile_local _ _PRODUCTION
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#define _PROFILE_WIDTH 8.166
float _ScatterRadius;
float _PositionShift;
float _Intensity;
int _SampleCount;
int _ApplyTonemap;
uint _TextureSize;
RWTexture2D<float4> _SSSLut;
static const float VARIANCE[6] =
{
0.0064,
0.0484,
0.1870,
0.5670,
1.9900,
7.4100
};
static const float3 WEIGHTS[6] =
{
float3(0.233, 0.455, 0.649),
float3(0.100, 0.336, 0.344),
float3(0.118, 0.198, 0.000),
float3(0.113, 0.007, 0.007),
float3(0.358, 0.004, 0.000),
float3(0.078, 0.000, 0.000)
};
float Gaussian(float v, float r)
{
return rcp(2.0 * PI * v) * exp((-r * r) / (2.0 * v));
}
float3 RadianceScatter(float r)
{
float3 result = 0.0;
for (int i = 0; i < 6; i++)
{
result += WEIGHTS[i] * Gaussian(VARIANCE[i], r);
}
return result;
}
float3 IntegrateDiffuseScattering_Ring(float theta, float r)
{
float3 totalScatter = 0;
float3 totalWeight = 0;
float increment = PI / _SampleCount;
float x = -HALF_PI;
while (x < HALF_PI)
{
float diffuse = saturate(cos(theta + x));
float distance = abs(2.0 * r * sin(x / 2.0));
float3 radiance = RadianceScatter(distance);
totalScatter += radiance * diffuse;
totalWeight += radiance;
x += increment;
}
return totalScatter / totalWeight;
}
float newPenumbra(float pos, float penumbraWidth)
{
return saturate((pos * penumbraWidth - _PROFILE_WIDTH) / (penumbraWidth - _PROFILE_WIDTH));
}
float3 IntegrateShadowScattering(float penumbraLocation, float penumbraWidth)
{
float3 totalScatter = 0;
float3 totalWeights = 0;
float increment = (_PROFILE_WIDTH * 2) / _SampleCount;
penumbraWidth = max(penumbraWidth, _PROFILE_WIDTH + 1e-5);
float x = -_PROFILE_WIDTH;
while (x <= _PROFILE_WIDTH)
{
float light = newPenumbra(penumbraLocation + x / penumbraWidth, penumbraWidth);
float distance = abs(x);
float3 weights = RadianceScatter(distance);
totalWeights += weights;
totalScatter += light * weights;
x += increment;
}
return totalScatter / totalWeights;
}
float3 FilmicTonemap(float3 color)
{
return (color * (6.2 * color + 0.5)) / (color * (6.2 * color + 1.7) + 0.06);
}
[numthreads(8,8,1)]
void SkinLut (uint3 id : SV_DispatchThreadID)
{
if (id.x > _TextureSize || id.y > _TextureSize)
{
return;
}
float2 uv = id.xy / float2(_TextureSize, _TextureSize);
#if UNITY_UV_STARTS_AT_TOP && _PRODUCTION
uv.y = 1.0 - uv.y;
#endif
float theta = acos((uv.x * 2.0 - 1.0)) + _PositionShift;
float r = rcp(max(uv.y, 0.001) * _ScatterRadius);
float3 scatter = IntegrateDiffuseScattering_Ring(theta, r) * _Intensity;
if (_ApplyTonemap == 1)
{
scatter = FilmicTonemap(scatter);
}
_SSSLut[id.xy] = float4(scatter, 1.0);
//_SSSLut[id.xy] = theta;
}
[numthreads(8, 8, 1)]
void ShadowLut(uint3 id : SV_DispatchThreadID)
{
if (id.x > _TextureSize || id.y > _TextureSize)
{
return;
}
float2 uv = id.xy / float2(_TextureSize, _TextureSize);
#if UNITY_UV_STARTS_AT_TOP && _PRODUCTION
uv.y = 1.0 - uv.y;
#endif
float penumbraLocation = uv.x + _PositionShift;
float penumbraWidth = rcp(max(uv.y, 0.001) * _ScatterRadius);
float3 scatter = IntegrateShadowScattering(penumbraLocation, penumbraWidth) * _Intensity;
if (_ApplyTonemap == 1)
{
scatter = FilmicTonemap(scatter);
}
_SSSLut[id.xy] = float4(scatter, 1.0);
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7bf3d5f03d1a012489a8f673afe8a6b3
ComputeShaderImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,175 @@
using System.IO;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.UIElements;
namespace Misaki.HdrpToon.Editor
{
internal class SSSLutBakerView : UnityEditor.EditorWindow
{
public enum Quality
{
[InspectorName("64")]
UltraLow = 64,
[InspectorName("128")]
VeryLow = 128,
[InspectorName("256")]
Low = 256,
[InspectorName("512")]
Medium = 512,
[InspectorName("1024")]
High = 1024,
[InspectorName("2048")]
VeryHigh = 2048,
[InspectorName("4096")]
UltraHigh = 4096,
}
private const int _PREVIEW_SIZE = 128;
[SerializeField]
private VisualTreeAsset _visualAsset;
[SerializeField]
private ComputeShader _bakerShader;
private RenderTexture _previewTexture;
private RenderTextureDescriptor _previewDescriptor;
public bool isShadowLut;
public float scatterRadius = 1.0f;
public float positionShift = 0.0f;
public float intensity = 1.0f;
public Quality sampleCount = Quality.Low;
public bool applyTonemap = true;
public Quality outputResolution = Quality.Medium;
public int outputQuality = 100;
[MenuItem("Tools/UTS/SSS LUT Baker")]
private static void ShowWindow()
{
var window = GetWindow<SSSLutBakerView>(true, "SSS LUT Baker");
window.minSize = new Vector2(400, 650);
window.ShowUtility();
}
private void OnEnable()
{
_previewDescriptor = new RenderTextureDescriptor
{
width = _PREVIEW_SIZE,
height = _PREVIEW_SIZE,
volumeDepth = 1,
dimension = TextureDimension.Tex2D,
depthBufferBits = 0,
msaaSamples = 1,
graphicsFormat = GraphicsFormat.R8G8B8A8_UNorm,
enableRandomWrite = true,
sRGB = false,
useMipMap = false,
};
_previewTexture = RenderTexture.GetTemporary(_previewDescriptor);
}
private bool GenerateSSSLut(RenderTexture texture, int textureSize, bool production)
{
if (_bakerShader == null || !texture.enableRandomWrite)
{
return false;
}
var kernelIndex = isShadowLut ? 1 : 0;
_bakerShader.SetFloat("_ScatterRadius", scatterRadius);
_bakerShader.SetFloat("_PositionShift", positionShift);
_bakerShader.SetFloat("_Intensity", intensity);
_bakerShader.SetInt("_SampleCount", (int)sampleCount);
_bakerShader.SetInt("_ApplyTonemap", applyTonemap ? 1 : 0);
_bakerShader.SetInt("_TextureSize", textureSize);
_bakerShader.SetKeyword(new LocalKeyword(_bakerShader, "_PRODUCTION"), production);
_bakerShader.SetTexture(kernelIndex, "_SSSLut", texture);
const int groupSizeX = 8;
const int groupSizeY = 8;
var threadGroupX = (textureSize + (groupSizeX - 1)) / groupSizeX;
var threadGroupY = (textureSize + (groupSizeY - 1)) / groupSizeY;
_bakerShader.Dispatch(kernelIndex, threadGroupX, threadGroupY, 1);
return true;
}
private void BakePreview()
{
GenerateSSSLut(_previewTexture, _PREVIEW_SIZE, false);
}
private void Bake()
{
var outputPath = EditorUtility.SaveFilePanel("Export Texture", Application.dataPath, "SSS Lut", "jpg");
if (string.IsNullOrEmpty(outputPath))
{
return;
}
var outputDescriptor = _previewDescriptor;
outputDescriptor.width = (int)outputResolution;
outputDescriptor.height = (int)outputResolution;
var tempTexture = RenderTexture.GetTemporary(outputDescriptor);
var tempTexture2D = new Texture2D(outputDescriptor.width, outputDescriptor.height, TextureFormat.RGB24, false, true);
try
{
if (!GenerateSSSLut(tempTexture, (int)outputResolution, true))
{
return;
}
RenderTexture.active = tempTexture;
tempTexture2D.ReadPixels(new Rect(0, 0, outputDescriptor.width, outputDescriptor.height), 0, 0);
tempTexture2D.Apply();
RenderTexture.active = null;
File.WriteAllBytes(outputPath, tempTexture2D.EncodeToJPG(outputQuality));
AssetDatabase.Refresh();
}
finally
{
RenderTexture.ReleaseTemporary(tempTexture);
DestroyImmediate(tempTexture2D);
}
}
private void CreateGUI()
{
if (_visualAsset == null)
{
return;
}
var visualTree = _visualAsset.Instantiate();
visualTree.StretchToParentSize();
visualTree.dataSource = this;
var previewImage = visualTree.Q<Image>("preview-image");
previewImage.image = _previewTexture;
var previewButton = visualTree.Q<Button>("preview-button");
previewButton.clickable.clicked += BakePreview;
var bakeButton = visualTree.Q<Button>("bake-button");
bakeButton.clickable.clicked += Bake;
rootVisualElement.Add(visualTree);
}
private void OnDestroy()
{
RenderTexture.ReleaseTemporary(_previewTexture);
}
}
}

View File

@@ -1,11 +1,13 @@
fileFormatVersion: 2
guid: c2a5c3542255fad4b803f96cc141e84d
guid: 46ee5c2bb652c6942a58aa97f3a8473b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_ViewDataDictionary: {instanceID: 0}
- IntegratorShader: {fileID: 7200000, guid: 0aa27def3e695d34d9e06b6015d57142, type: 3}
- _visualAsset: {fileID: 9197481963319205126, guid: 36e5f9eef212a0547b97e2643cd514de,
type: 3}
- _bakerShader: {fileID: 7200000, guid: 7bf3d5f03d1a012489a8f673afe8a6b3, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,54 @@
<engine:UXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:engine="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<engine:VisualElement data-source-type="Misaki.HdrpToon.Editor.SSSLutBakerView, Misaki.HdrpToon.Editor" style="flex-grow: 1; padding-top: 8px; padding-right: 8px; padding-bottom: 8px; padding-left: 8px;">
<engine:Label text="SSS Lut Baker" style="font-size: 18px; padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0; margin-top: 12px; margin-bottom: 8px; margin-left: 4px; margin-right: 6px; -unity-font-style: bold;" />
<engine:Label text="Parameters:" style="-unity-font-style: bold; margin-top: 12px; margin-bottom: 4px; margin-right: 2px; margin-left: 2px;" />
<engine:DropdownField label="Lut Type" choices="Skin,Shadow" index="0">
<Bindings>
<engine:DataBinding property="index" data-source-path="isShadowLut" binding-mode="TwoWay" />
</Bindings>
</engine:DropdownField>
<engine:FloatField label="Scatter Radius" value="1">
<Bindings>
<engine:DataBinding property="value" data-source-path="scatterRadius" binding-mode="TwoWay" />
</Bindings>
</engine:FloatField>
<engine:Slider label="Position Shift" value="0.0" low-value="-1" high-value="1" page-size="0.1" show-input-field="true">
<Bindings>
<engine:DataBinding property="value" data-source-path="positionShift" binding-mode="TwoWay" />
</Bindings>
</engine:Slider>
<engine:Slider label="Intensity" value="1" high-value="10" show-input-field="true" page-size="0.1">
<Bindings>
<engine:DataBinding property="value" data-source-path="intensity" binding-mode="TwoWay" />
</Bindings>
</engine:Slider>
<engine:EnumField label="Sample Count" value="Center" type="Misaki.HdrpToon.Editor.SSSLutBakerView+Quality, Misaki.HdrpToon.Editor">
<Bindings>
<engine:DataBinding property="value" binding-mode="TwoWay" data-source-path="sampleCount" />
</Bindings>
</engine:EnumField>
<engine:DropdownField label="Apply Tonemap" choices="Disable,Enable" index="0">
<Bindings>
<engine:DataBinding property="index" data-source-path="applyTonemap" binding-mode="TwoWay" />
</Bindings>
</engine:DropdownField>
<engine:EnumField label="Output Resolution" value="Center" type="Misaki.HdrpToon.Editor.SSSLutBakerView+Quality, Misaki.HdrpToon.Editor">
<Bindings>
<engine:DataBinding property="value" binding-mode="TwoWay" data-source-path="outputResolution" />
</Bindings>
</engine:EnumField>
<engine:SliderInt label="Output Quality" value="75" show-input-field="true" high-value="100" low-value="50">
<Bindings>
<engine:DataBinding property="value" data-source-path="outputQuality" binding-mode="TwoWay" />
</Bindings>
</engine:SliderInt>
<engine:Label text="Preview:" style="-unity-font-style: bold; margin-top: 12px; margin-bottom: 4px; margin-right: 2px; margin-left: 2px;" />
<engine:VisualElement style="flex-grow: 1; padding-top: 8px; padding-right: 8px; padding-bottom: 8px; padding-left: 8px; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-top: 4px; margin-right: 4px; margin-bottom: 4px; margin-left: 4px;">
<engine:Image name="preview-image" style="flex-grow: 1;" />
</engine:VisualElement>
<engine:VisualElement style="flex-direction: row; margin-top: 4px;">
<engine:Button text="Preview" name="preview-button" style="flex-grow: 1; flex-basis: 0;" />
<engine:Button text="Bake" name="bake-button" style="flex-basis: 0; flex-grow: 1; background-color: rgb(70, 96, 124);" />
</engine:VisualElement>
</engine:VisualElement>
</engine:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 36e5f9eef212a0547b97e2643cd514de
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -1,119 +0,0 @@
using UnityEditor;
using UnityEngine;
namespace EditorTools
{
public class SubsurfaceLookupTextureIntegratorWindow : EditorWindow
{
[MenuItem("Tools/Subsurface LUT Integrator", false, 1000)]
static void ShowIntegratorWindow()
{
GetWindow(typeof(SubsurfaceLookupTextureIntegratorWindow), false, "Subsurface LUT Integrator");
}
private Color FalloffColor = new Color(1.0f, 0.3f, 0.2f);
private float Radius = 4;
private bool KeepDirectBounce = false;
[SerializeField]
private ComputeShader IntegratorShader;
private RenderTexture IntegratedLUT = null;
private int resolution = 512;
private void OnEnable()
{
//IntegratorShader = AssetDatabase.LoadAssetAtPath<ComputeShader>("Assets/Scripts/Tools/Editor/SSS/SubsurfaceLookupTextureIntegrator.compute");
}
private void OnDestroy()
{
if (IntegratedLUT != null)
{
RenderTexture.ReleaseTemporary(IntegratedLUT);
}
}
void OnGUI()
{
GUILayout.Label("Base Settings", EditorStyles.boldLabel);
EditorGUI.BeginChangeCheck();
FalloffColor = EditorGUILayout.ColorField("Fallof Color", FalloffColor);
Radius = EditorGUILayout.Slider("Radius", Radius, 0, 20);
KeepDirectBounce = EditorGUILayout.Toggle("Keep Direct Bounce", KeepDirectBounce);
resolution = EditorGUILayout.IntField("Resolution", resolution);
if (EditorGUI.EndChangeCheck())
{
Bake();
}
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Bake") && IntegratorShader != null)
{
Bake();
}
if (GUILayout.Button("Save") && IntegratedLUT != null)
{
IntegratorShader.SetFloat("_Resoultion", (float)resolution);
RenderTexture rt = RenderTexture.GetTemporary(resolution, resolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
Graphics.Blit(IntegratedLUT, rt);
RenderTexture.active = rt;
Texture2D tex = new Texture2D(resolution, resolution, TextureFormat.ARGB32, false, true);
tex.ReadPixels(new Rect(0, 0, resolution, resolution), 0, 0);
RenderTexture.active = null;
RenderTexture.ReleaseTemporary(rt);
string path = EditorUtility.SaveFilePanel("Export Texture", Application.dataPath, "SSS_Lut", "png");
if (path == null) return;
System.IO.File.WriteAllBytes(path, tex.EncodeToPNG());
AssetDatabase.Refresh();
IntegratorShader.SetFloat("_Resoultion", (float)resolution);
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
float width = position.width - 100;
float height = position.height - 189;
float sacle = width > height ? height / resolution : width / resolution;
Rect rect = new Rect(50, 150, resolution * sacle, resolution * sacle);
if (IntegratedLUT != null)
{
EditorGUI.DrawPreviewTexture(rect, IntegratedLUT);
}
else
{
EditorGUI.DrawRect(rect, Color.black);
}
}
private void Bake()
{
if (IntegratedLUT != null)
{
RenderTexture.ReleaseTemporary(IntegratedLUT);
}
IntegratedLUT = RenderTexture.GetTemporary(resolution, resolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
IntegratedLUT.enableRandomWrite = true;
if (KeepDirectBounce)
{
IntegratorShader.EnableKeyword("KEEP_DIRECT_BOUNCE");
}
else
{
IntegratorShader.DisableKeyword("KEEP_DIRECT_BOUNCE");
}
IntegratorShader.SetTexture(0, "_IntegratedLUT", IntegratedLUT);
IntegratorShader.SetVector("_FalloffColor", FalloffColor);
IntegratorShader.SetFloat("_Radius", Radius);
IntegratorShader.SetFloat("_Resoultion", (float)resolution);
IntegratorShader.Dispatch(0, resolution / 8, resolution / 8, 1);
}
}
}

View File

@@ -38,8 +38,7 @@ The HDRP Toon Shader is designed to provide a high-quality toon shading effect f
3. Apply the material to your 3D models.
4. Adjust the shader parameters in the material inspector to achieve the desired look.
## Examples
## Example
Here are some examples of the HDRP Toon Shader in action:
![preview-01.png](https://s2.loli.net/2024/12/26/zHdfSXho4csURyx.png)

View File

@@ -1,8 +1,2 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Unity.ToonShader.Editor")]
[assembly: InternalsVisibleTo("Unity.VisualCompositor")]
[assembly: InternalsVisibleTo("Unity.VisualCompositor.Tests")]
[assembly: InternalsVisibleTo("Unity.VisualCompositor.Editor")]
[assembly: InternalsVisibleTo("Unity.VisualCompositor.EditorTests")]
[assembly: InternalsVisibleTo("Misaki.HdrpToon.Editor")]

View File

@@ -17,11 +17,16 @@ namespace Misaki.HdrpToon
private bool _initialized = false;
private bool _srpCallbackInitialized = false;
[SerializeField]
private HDAdditionalLightData _bindingSourceLightData;
[SerializeField]
private HDAdditionalLightData _targetBoxLightData;
[SerializeField]
private uint _layerMask;
[SerializeField]
private Light _bindingSourceLight;
[SerializeField]
private Light _targetBoxLight;
public Transform trackedTransform;
@@ -159,11 +164,6 @@ namespace Misaki.HdrpToon
Release();
}
private void UpdateObjectLightLayers()
{
Initialize();
}
internal static GameObject CreateBoxLight(Transform transform)
{
if (transform == null)

View File

@@ -0,0 +1,73 @@
namespace Misaki.HdrpToon
{
internal static class UtsShaderPropertyName
{
public static class SurfaceOptions
{
public const string SHADING_MODE = "_Shading_Mode";
public const string PBR_MODE = "_PBR_Mode";
public const string SURFACE_FEATURE = "_SurfaceFeatures";
}
public static class SurfaceInputs
{
public const string EMISSIVE_COLOR = "_EmissiveColor";
public const string EMISSIVE_COLOR_LDR = "_EmissiveColorLDR";
public const string EMISSIVE_COLOR_MAP = "_EmissiveColorMap";
public const string ALBEDO_AFFECT_EMISSIVE = "_AlbedoAffectEmissive";
public const string EMISSIVE_INTENSITY = "_EmissiveIntensity";
public const string EMISSIVE_EXPOSURE_WEIGHT = "_EmissiveExposureWeight";
}
public static class RimLight
{
public const string RIM_LIGHT_COLOR = "_RimLightColor";
public const string RIM_LIGHT_INTENSITY = "_RimLightIntensity";
public const string RIM_LIGHT_LEVEL = "_RimLightLevel";
public const string SCREEN_SPACE_RIM_LIGHT = "_Screen_Space_Rim_Light";
public const string LIGHT_BASE_RIM_LIGHT = "_Light_Base_Rim_Light";
public const string LIGHT_DIRECTION_RIM_LIGHT_LEVEL = "_LightDirectionRimLightLevel";
public const string COLOR_BLENDING_MODE = "_Is_BlendAddToRimColor";
public const string RIM_LIGHT_CLIPPING = "_RimLightClipping";
public const string RIM_LIGHT_CLIPPING_LEVEL = "_RimLightClippingLevel";
public const string LIGHT_DIRECTION = "_LightDirection_MaskOn";
public const string INVERTED_DIRECTION_RIM_LIGHT = "_Add_Antipodean_RimLight";
public const string INVERTED_RIM_LIGHT_COLOR = "_Ap_RimLightColor";
public const string INVERSED_RIM_LIGHT_LEVEL = "_Ap_RimLight_Power";
public const string INVERTED_RIM_LIGHT_FEATHER_OFF = "_Ap_RimLight_FeatherOff";
public const string RIM_LIGHT_MASK_MAP = "_Set_RimLightMask";
public const string RIM_LIGHT_MASK_LEVEL = "_Tweak_RimLightMaskLevel";
}
public static class AngelRing
{
public const string ANGEL_RING_COLOR = "_AngelRingColor";
public const string ANGEL_RING_COLOR_MAP = "_AngelRingColorMap";
public const string ANGEL_RING_INTENSITY = "_AngelRingIntensity";
public const string ANGEL_RING_OFFSET_U = "_AngelRingOffsetU";
public const string ANGEL_RING_OFFSET_V = "_AngelRingOffsetV";
}
public static class Outline
{
public const string OUTLINE_STATE = "_OutlineState";
public const string OUTLINE_WIDTH = "_OutlineWidth";
public const string OUTLINE_WIDTH_MAP = "_OutlineWidthMap";
public const string OUTLINE_COLOR = "_OutlineColor";
public const string OUTLINE_COLOR_MAP = "_OutlineColorMap";
public const string ALBEDO_AFFECT_OUTLINE = "_AlbedoAffectOutline";
public const string SKY_COLOR_AFFECT_OUTLINE = "_SkyColorAffectOutline";
public const string SKY_COLOR_INTENSITY = "_SkyColorIntensity";
public const string OUTLINE_FADE_IN = "_OutlineFadeIn";
public const string OUTLINE_FADE_OUT = "_OutlineFadeOut";
public const string USE_SMOOTHED_NORMAL = "_UseSmoothedNormal";
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 723370b3a1613cb43b85b765ebcebee3

View File

@@ -1,272 +0,0 @@
#ifndef UNITY_DEBUG_DISPLAY_INCLUDED
#define UNITY_DEBUG_DISPLAY_INCLUDED
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Debug.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/MaterialDebug.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/LightingDebug.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/MipMapDebug.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/ColorPickerDebug.cs.hlsl"
CBUFFER_START(UnityDebugDisplay)
// Set of parameters available when switching to debug shader mode
int _DebugLightingMode; // Match enum DebugLightingMode
int _DebugShadowMapMode;
float _DebugViewMaterialArray[11]; // Contain the id (define in various materialXXX.cs.hlsl) of the property to display
int _DebugMipMapMode; // Match enum DebugMipMapMode
int _DebugMipMapModeTerrainTexture; // Match enum DebugMipMapModeTerrainTexture
int _ColorPickerMode; // Match enum ColorPickerDebugMode
int _DebugStep;
int _DebugDepthPyramidMip;
int _DebugFullScreenMode;
float _DebugTransparencyOverdrawWeight;
float4 _DebugLightingAlbedo; // x == bool override, yzw = albedo for diffuse
float4 _DebugLightingSmoothness; // x == bool override, y == override value
float4 _DebugLightingNormal; // x == bool override
float4 _DebugLightingAmbientOcclusion; // x == bool override, y == override value
float4 _DebugLightingSpecularColor; // x == bool override, yzw = specular color
float4 _DebugLightingEmissiveColor; // x == bool override, yzw = emissive color
float4 _DebugLightingMaterialValidateHighColor; // user can specific the colors for the validator error conditions
float4 _DebugLightingMaterialValidateLowColor;
float4 _DebugLightingMaterialValidatePureMetalColor;
float4 _MousePixelCoord; // xy unorm, zw norm
float4 _MouseClickPixelCoord; // xy unorm, zw norm
int _MatcapMixAlbedo;
int _MatcapViewScale;
uint _DebugContactShadowLightIndex;
CBUFFER_END
// Local shader variables
static DirectionalShadowType g_DebugShadowAttenuation = 0;
StructuredBuffer<int2> _DebugDepthPyramidOffsets;
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/PBRValidator.hlsl"
// When displaying lux meter we compress the light in order to be able to display value higher than 65504
// The sun is between 100 000 and 150 000, so we use 4 to be able to cover such a range (4 * 65504)
#define LUXMETER_COMPRESSION_RATIO 4
TEXTURE2D(_DebugFont); // Debug font to write string in shader
TEXTURE2D(_DebugMatCapTexture);
void GetPropertiesDataDebug(uint paramId, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEWPROPERTIES_TESSELLATION:
#ifdef TESSELLATION_ON
result = float3(1.0, 0.0, 0.0);
#else
result = float3(0.0, 0.0, 0.0);
#endif
break;
case DEBUGVIEWPROPERTIES_PIXEL_DISPLACEMENT:
#ifdef _PIXEL_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
result = float3(1.0, 0.0, 0.0);
#else
result = float3(0.0, 0.0, 0.0);
#endif
break;
case DEBUGVIEWPROPERTIES_VERTEX_DISPLACEMENT:
#ifdef _VERTEX_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
result = float3(1.0, 0.0, 0.0);
#else
result = float3(0.0, 0.0, 0.0);
#endif
break;
case DEBUGVIEWPROPERTIES_TESSELLATION_DISPLACEMENT:
#ifdef _TESSELLATION_DISPLACEMENT // Caution: This define is related to a shader features (But it may become a standard features for HD)
result = float3(1.0, 0.0, 0.0);
#else
result = float3(0.0, 0.0, 0.0);
#endif
break;
case DEBUGVIEWPROPERTIES_DEPTH_OFFSET:
#ifdef _DEPTHOFFSET_ON // Caution: This define is related to a shader features (But it may become a standard features for HD)
result = float3(1.0, 0.0, 0.0);
#else
result = float3(0.0, 0.0, 0.0);
#endif
break;
case DEBUGVIEWPROPERTIES_LIGHTMAP:
#if defined(LIGHTMAP_ON) || defined (DIRLIGHTMAP_COMBINED) || defined(DYNAMICLIGHTMAP_ON)
result = float3(1.0, 0.0, 0.0);
#else
result = float3(0.0, 0.0, 0.0);
#endif
break;
case DEBUGVIEWPROPERTIES_INSTANCING:
#if defined(UNITY_INSTANCING_ENABLED)
result = float3(1.0, 0.0, 0.0);
#else
result = float3(0.0, 0.0, 0.0);
#endif
break;
}
}
float3 GetTextureDataDebug(uint paramId, float2 uv, Texture2D tex, float4 texelSize, float4 mipInfo, float3 originalColor)
{
float3 outColor = originalColor;
switch (paramId)
{
case DEBUGMIPMAPMODE_MIP_RATIO:
outColor = GetDebugMipColorIncludingMipReduction(originalColor, tex, texelSize, uv, mipInfo);
break;
case DEBUGMIPMAPMODE_MIP_COUNT:
outColor = GetDebugMipCountColor(originalColor, tex);
break;
case DEBUGMIPMAPMODE_MIP_COUNT_REDUCTION:
outColor = GetDebugMipReductionColor(tex, mipInfo);
break;
case DEBUGMIPMAPMODE_STREAMING_MIP_BUDGET:
outColor = GetDebugStreamingMipColor(tex, mipInfo);
break;
case DEBUGMIPMAPMODE_STREAMING_MIP:
outColor = GetDebugStreamingMipColorBlended(originalColor, tex, mipInfo);
break;
}
return outColor;
}
// DebugFont code assume black and white font with texture size 256x128 with bloc of 16x16
#define DEBUG_FONT_TEXT_WIDTH 16
#define DEBUG_FONT_TEXT_HEIGHT 16
#define DEBUG_FONT_TEXT_COUNT_X 16
#define DEBUG_FONT_TEXT_COUNT_Y 8
#define DEBUG_FONT_TEXT_ASCII_START 32
#define DEBUG_FONT_TEXT_SCALE_WIDTH 10 // This control the spacing between characters (if a character fill the text block it will overlap).
// Only support ASCII symbol from DEBUG_FONT_TEXT_ASCII_START to 126
// return black or white depends if we hit font character or not
// currentUnormCoord is current unormalized screen position
// fixedUnormCoord is the position where we want to draw something, this will be incremented by block font size in provided direction
// color is current screen color
// color of the font to use
// direction is 1 or -1 and indicate fixedUnormCoord block shift
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int direction)
{
// Are we inside a font display block on the screen ?
uint2 localCharCoord = currentUnormCoord - fixedUnormCoord;
if (localCharCoord.x >= 0 && localCharCoord.x < DEBUG_FONT_TEXT_WIDTH && localCharCoord.y >= 0 && localCharCoord.y < DEBUG_FONT_TEXT_HEIGHT)
{
localCharCoord.y = DEBUG_FONT_TEXT_HEIGHT - localCharCoord.y;
asciiValue -= DEBUG_FONT_TEXT_ASCII_START; // Our font start at ASCII table 32;
uint2 asciiCoord = uint2(asciiValue % DEBUG_FONT_TEXT_COUNT_X, asciiValue / DEBUG_FONT_TEXT_COUNT_X);
// Unorm coordinate inside the font texture
uint2 unormTexCoord = asciiCoord * uint2(DEBUG_FONT_TEXT_WIDTH, DEBUG_FONT_TEXT_HEIGHT) + localCharCoord;
// normalized coordinate
float2 normTexCoord = float2(unormTexCoord) / float2(DEBUG_FONT_TEXT_WIDTH * DEBUG_FONT_TEXT_COUNT_X, DEBUG_FONT_TEXT_HEIGHT * DEBUG_FONT_TEXT_COUNT_Y);
#if UNITY_UV_STARTS_AT_TOP
normTexCoord.y = 1.0 - normTexCoord.y;
#endif
float charColor = SAMPLE_TEXTURE2D_LOD(_DebugFont, s_point_clamp_sampler, normTexCoord, 0).r;
color = color * (1.0 - charColor) + charColor * fontColor;
}
fixedUnormCoord.x += DEBUG_FONT_TEXT_SCALE_WIDTH * direction;
}
// Shortcut to not have to file direction
void DrawCharacter(uint asciiValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
{
DrawCharacter(asciiValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 1);
}
// Draw a signed integer
// Can't display more than 16 digit
// The two following parameter are for float representation
// leading0 is used when drawing frac part of a float to draw the leading 0 (call is in charge of it)
// forceNegativeSign is used to force to display a negative sign as -0 is not recognize
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color, int leading0, bool forceNegativeSign)
{
const uint maxStringSize = 16;
uint absIntValue = abs(intValue);
// 1. Get size of the number of display
int numEntries = min((intValue == 0 ? 0 : log10(absIntValue)) + ((intValue < 0 || forceNegativeSign) ? 1 : 0) + leading0, maxStringSize);
// 2. Shift curseur to last location as we will go reverse
fixedUnormCoord.x += numEntries * DEBUG_FONT_TEXT_SCALE_WIDTH;
// 3. Display the number
for (uint j = 0; j < maxStringSize; ++j)
{
// Numeric value incurrent font start on the second row at 0
DrawCharacter((absIntValue % 10) + '0', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
if (absIntValue < 10)
break;
absIntValue /= 10;
}
// 4. Display leading 0
if (leading0 > 0)
{
for (int i = 0; i < leading0; ++i)
{
DrawCharacter('0', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
}
}
// 5. Display sign
if (intValue < 0 || forceNegativeSign)
{
DrawCharacter('-', fontColor, currentUnormCoord, fixedUnormCoord, color, -1);
}
// 6. Reset cursor at end location
fixedUnormCoord.x += (numEntries + 2) * DEBUG_FONT_TEXT_SCALE_WIDTH;
}
void DrawInteger(int intValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
{
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, false);
}
void DrawFloat(float floatValue, float3 fontColor, uint2 currentUnormCoord, inout uint2 fixedUnormCoord, inout float3 color)
{
if (IsNaN(floatValue))
{
DrawCharacter('N', fontColor, currentUnormCoord, fixedUnormCoord, color);
DrawCharacter('a', fontColor, currentUnormCoord, fixedUnormCoord, color);
DrawCharacter('N', fontColor, currentUnormCoord, fixedUnormCoord, color);
}
else
{
int intValue = int(floatValue);
bool forceNegativeSign = floatValue >= 0.0f ? false : true;
DrawInteger(intValue, fontColor, currentUnormCoord, fixedUnormCoord, color, 0, forceNegativeSign);
DrawCharacter('.', fontColor, currentUnormCoord, fixedUnormCoord, color);
int fracValue = int(frac(abs(floatValue)) * 1e6); // 6 digit
int leading0 = 6 - (int(log10(fracValue)) + 1); // Counting leading0 to add in front of the float
DrawInteger(fracValue, fontColor, currentUnormCoord, fixedUnormCoord, color, leading0, false);
}
}
// Debug rendering is performed at the end of the frame (after post-processing).
// Debug textures are never flipped upside-down automatically. Therefore, we must always flip manually.
bool ShouldFlipDebugTexture()
{
#if UNITY_UV_STARTS_AT_TOP
return (_ProjectionParams.x > 0);
#else
return (_ProjectionParams.x < 0);
#endif
}
#endif

View File

@@ -1,27 +0,0 @@
//#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
#ifndef DECODEDEPTHNORMALS_INCLUDED
#define DECODEDEPTHNORMALS_INCLUDED
inline float DecodeFloatRG(float2 enc) {
float2 kDecodeDot = float2(1.0, 1 / 255.0);
return dot(enc, kDecodeDot);
}
inline float3 DecodeViewNormalStereo(float4 enc4) {
float kScale = 1.7777;
float3 nn = enc4.xyz * float3(2 * kScale, 2 * kScale, 0) + float3(-kScale, -kScale, 1);
float g = 2.0 / dot(nn.xyz, nn.xyz);
float3 n;
n.xy = g * nn.xy;
n.z = g - 1;
return n;
}
inline void DecodeDepthNormal(float4 enc, out float depth, out float3 normal) {
depth = DecodeFloatRG(enc.zw);
normal = DecodeViewNormalStereo(enc);
}
#endif

View File

@@ -1,298 +0,0 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
float3 UTS_MainLight(LightLoopContext lightLoopContext, FragInputs input, float3 mainLihgtDirection, float3 mainLightColor, out float inverseClipping, out float channelOutAlpha, out UTSData utsData)
{
channelOutAlpha = 1.0f;
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
inverseClipping = 0;
// input.positionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
#ifdef VARYINGS_NEED_POSITION_WS
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
#else
// Unused
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
#endif
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
/* todo. these should be put int a struct */
float4 Set_UV0 = input.texCoord0;
float3x3 tangentTransform = input.tangentToWorld;
//UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords))
float4 n = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, Set_UV0.xy);
// float3 _NormalMap_var = UnpackNormalScale(tex2D(_NormalMap, TRANSFORM_TEX(Set_UV0, _NormalMap)), _BumpScale);
float3 _NormalMap_var = UnpackNormalScale(n, _BumpScale);
float3 normalLocal = _NormalMap_var.rgb;
utsData.normalDirection = normalize(mul(normalLocal, tangentTransform)); // Perturbed normals
float4 _BaseColorMap_var = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
float3 i_normalDir = surfaceData.normalWS;
utsData.viewDirection = V;
/* to here todo. these should be put int a struct */
//v.2.0.4
#if defined(_IS_CLIPPING_MODE)
//DoubleShadeWithFeather_Clipping
float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _ClippingMask));
float Set_Clipping = saturate((lerp(_ClippingMask_var.r, (1.0 - _ClippingMask_var.r), _Inverse_Clipping) + _Clipping_Level));
clip(Set_Clipping - 0.5);
#elif defined(_IS_CLIPPING_TRANSMODE) || defined(_IS_TRANSCLIPPING_ON)
//DoubleShadeWithFeather_TransClipping
float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _ClippingMask));
float Set_BaseColorMapAlpha = _BaseColorMap_var.a;
float _IsBaseMapAlphaAsClippingMask_var = lerp(_ClippingMask_var.r, Set_BaseColorMapAlpha, _IsBaseMapAlphaAsClippingMask);
float _Inverse_Clipping_var = lerp(_IsBaseMapAlphaAsClippingMask_var, (1.0 - _IsBaseMapAlphaAsClippingMask_var), _Inverse_Clipping);
float Set_Clipping = saturate((_Inverse_Clipping_var + _Clipping_Level));
clip(Set_Clipping - 0.5);
inverseClipping = _Inverse_Clipping_var;
#elif defined(_IS_CLIPPING_OFF) || defined(_IS_TRANSCLIPPING_OFF)
//DoubleShadeWithFeather
#endif
float shadowAttenuation = (float)lightLoopContext.shadowValue;
// float4 tmpColor = EvaluateLight_Directional(context, posInput, _DirectionalLightDatas[mainLightIndex]);
// float3 mainLightColor = tmpColor.xyz;
float3 defaultLightDirection = normalize(UNITY_MATRIX_V[2].xyz + UNITY_MATRIX_V[1].xyz);
float3 defaultLightColor = saturate(max(float3(0.05, 0.05, 0.05) * _Unlit_Intensity, max(ShadeSH9(float4(0.0, 0.0, 0.0, 1.0)), ShadeSH9(float4(0.0, -1.0, 0.0, 1.0)).rgb) * _Unlit_Intensity));
float3 customLightDirection = normalize(mul(UNITY_MATRIX_M, float4(((float3(1.0, 0.0, 0.0) * _Offset_X_Axis_BLD * 10) + (float3(0.0, 1.0, 0.0) * _Offset_Y_Axis_BLD * 10) + (float3(0.0, 0.0, -1.0) * lerp(-1.0, 1.0, _Inverse_Z_Axis_BLD))), 0)).xyz);
float3 lightDirection = normalize(lerp(defaultLightDirection, mainLihgtDirection.xyz, any(mainLihgtDirection.xyz)));
lightDirection = lerp(lightDirection, customLightDirection, _Is_BLD);
float3 originalLightColor = mainLightColor;
originalLightColor = lerp(originalLightColor, clamp(originalLightColor, ConvertFromEV100(_ToonEvAdjustmentValueMin ), ConvertFromEV100(_ToonEvAdjustmentValueMax)), _ToonEvAdjustmentCurve);
float3 lightColor = lerp(max(defaultLightColor, originalLightColor), max(defaultLightColor, saturate(originalLightColor)), max(_Is_Filter_LightColor, _ToonLightHiCutFilter));
////// Lighting:
float3 halfDirection = normalize(utsData.viewDirection + lightDirection);
//v.2.0.5
_Color = _BaseColor;
float3 Set_LightColor = lightColor.rgb;
float3 Set_BaseColor = lerp((_BaseColorMap_var.rgb * _BaseColor.rgb), ((_BaseColorMap_var.rgb * _BaseColor.rgb) * Set_LightColor), _Is_LightColor_Base);
float3 clippingColor = float3(1.0f, 1.0f, 1.0f);
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 5)
{
clippingColor = float3(0.0f, 0.0f, 0.0f);
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 1)
{
clippingColor = Set_BaseColor;
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
#ifdef UTS_LAYER_VISIBILITY
float3 overridingColor = lerp(_BaseColorMaskColor, float4(_BaseColorMaskColor.w, _BaseColorMaskColor.w, _BaseColorMaskColor.w, 1.0f), _ComposerMaskMode).xyz;
float maskEnabled = max(_BaseColorOverridden, _ComposerMaskMode);
Set_BaseColor = lerp(Set_BaseColor, overridingColor, maskEnabled);
Set_BaseColor *= _BaseColorVisible;
float Set_BaseColorAlpha = _BaseColorVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY
//v.2.0.5
float4 _1st_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_1st_ShadeMap, sampler_BaseColorMap,TRANSFORM_TEX(Set_UV0, _1st_ShadeMap)), _BaseColorMap_var, _Use_BaseAs1st);
float3 Set_1st_ShadeColor = lerp((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb), ((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 2)
{
clippingColor = Set_1st_ShadeColor;
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
#ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_FirstShadeMaskColor, float4(_FirstShadeMaskColor.w, _FirstShadeMaskColor.w, _FirstShadeMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_FirstShadeOverridden, _ComposerMaskMode);
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, overridingColor.xyz, maskEnabled);
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, Set_BaseColor, 1.0f - _FirstShadeVisible);
}
float Set_1st_ShadeAlpha = _FirstShadeVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY
//v.2.0.5
float4 _2nd_ShadeMap_var = lerp(SAMPLE_TEXTURE2D(_2nd_ShadeMap, sampler_BaseColorMap,TRANSFORM_TEX(Set_UV0, _2nd_ShadeMap)), _1st_ShadeMap_var, _Use_1stAs2nd);
float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb), ((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
float _HalfLambert_var = 0.5 * dot(lerp(i_normalDir, utsData.normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5;
float4 _Set_2nd_ShadePosition_var = tex2D(_Set_2nd_ShadePosition, TRANSFORM_TEX(Set_UV0, _Set_2nd_ShadePosition));
float4 _Set_1st_ShadePosition_var = tex2D(_Set_1st_ShadePosition, TRANSFORM_TEX(Set_UV0, _Set_1st_ShadePosition));
float _1stColorFeatherForMask = lerp(_BaseShade_Feather, 0.0f, max(_FirstShadeOverridden, _ComposerMaskMode));
float _2ndColorFeatherForMask = lerp(_1st2nd_Shades_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
//v.2.0.6
//Minmimum value is same as the Minimum Feather's value with the Minimum Step's value as threshold.
float _SystemShadowsLevel_var = (shadowAttenuation * 0.5) + 0.5 + _Tweak_SystemShadowsLevel > 0.001 ? (shadowAttenuation * 0.5) + 0.5 + _Tweak_SystemShadowsLevel : 0.0001;
float Set_FinalShadowMask = saturate((1.0 + ((lerp(_HalfLambert_var, _HalfLambert_var * saturate(_SystemShadowsLevel_var), _Set_SystemShadowsToBase) - (_BaseColor_Step - _1stColorFeatherForMask)) * ((1.0 - _Set_1st_ShadePosition_var.rgb).r - 1.0)) / (_BaseColor_Step - (_BaseColor_Step - _1stColorFeatherForMask))));
//
//Composition: 3 Basic Colors as Set_FinalBaseColor
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 3)
{
clippingColor = Set_2nd_ShadeColor;
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
#ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_SecondShadeMaskColor, float4(_SecondShadeMaskColor.w, _SecondShadeMaskColor.w, _SecondShadeMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_SecondShadeOverridden, _ComposerMaskMode);
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, overridingColor.xyz, maskEnabled);
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, Set_BaseColor, 1.0f - _SecondShadeVisible);
}
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY
float3 Set_FinalBaseColor = lerp(Set_BaseColor, lerp(Set_1st_ShadeColor, Set_2nd_ShadeColor, saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask))))), Set_FinalShadowMask); // Final Color
channelOutAlpha = lerp(Set_BaseColorAlpha, lerp(Set_1st_ShadeAlpha, Set_2nd_ShadeAlpha, saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask))))), Set_FinalShadowMask);
float4 _Set_HighColorMask_var = tex2D(_Set_HighColorMask, TRANSFORM_TEX(Set_UV0, _Set_HighColorMask));
float _Specular_var = 0.5 * dot(halfDirection, lerp(i_normalDir, utsData.normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular
float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp((1.0 - step(_Specular_var, (1.0 - pow(_HighColor_Power, 5)))), pow(abs(_Specular_var), exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor));
float4 _HighColor_Tex_var = tex2D(_HighColor_Tex, TRANSFORM_TEX(Set_UV0, _HighColor_Tex));
float3 _HighColorWithOutTweak_var = lerp((_HighColor_Tex_var.rgb * _HighColor.rgb), ((_HighColor_Tex_var.rgb * _HighColor.rgb) * Set_LightColor), _Is_LightColor_HighColor);
float3 _HighColor_var = _HighColorWithOutTweak_var * _TweakHighColorMask_var;
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode == 4)
{
clippingColor = _HighColorWithOutTweak_var;
return clippingColor;
}
#endif // _IS_CLIPPING_MATTE
//Composition: 3 Basic Colors and HighColor as Set_HighColor
#ifdef UTS_LAYER_VISIBILITY
float3 Set_HighColor;
{
float4 overridingColor = lerp(_HighlightMaskColor, float4(_HighlightMaskColor.w, _HighlightMaskColor.w, _HighlightMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_HighlightOverridden, _ComposerMaskMode);
_HighColor_var *= _HighlightVisible;
Set_HighColor =
lerp(SATURATE_IF_SDR(Set_FinalBaseColor - _TweakHighColorMask_var), Set_FinalBaseColor,
lerp(_Is_BlendAddToHiColor, 1.0
, _Is_SpecularToHighColor));
float3 addColor =
lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow)))
, _Is_UseTweakHighColorOnShadow);
Set_HighColor += addColor;
if (any(addColor))
{
Set_HighColor = lerp(Set_HighColor, overridingColor.xyz, maskEnabled);
channelOutAlpha = _HighlightVisible;
}
}
#else
float3 Set_HighColor = (lerp(SATURATE_IF_SDR((Set_FinalBaseColor - _TweakHighColorMask_var)), Set_FinalBaseColor, lerp(_Is_BlendAddToHiColor, 1.0, _Is_SpecularToHighColor)) + lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow));
#endif
float4 _Set_RimLightMask_var = tex2D(_Set_RimLightMask, TRANSFORM_TEX(Set_UV0, _Set_RimLightMask));
float3 _Is_LightColor_RimLight_var = lerp(_RimLightColor.rgb, (_RimLightColor.rgb * Set_LightColor), _Is_LightColor_RimLight);
float _RimArea_var = abs((1.0 - dot(lerp(i_normalDir, utsData.normalDirection, _Is_NormalMapToRimLight), utsData.viewDirection)));
float _RimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _RimLight_Power)));
float _Rimlight_InsideMask_var = saturate(lerp((0.0 + ((_RimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _RimLightPower_var), _RimLight_FeatherOff));
float _VertHalfLambert_var = 0.5 * dot(i_normalDir, lightDirection) + 0.5;
float3 _LightDirection_MaskOn_var = lerp((_Is_LightColor_RimLight_var * _Rimlight_InsideMask_var), (_Is_LightColor_RimLight_var * saturate((_Rimlight_InsideMask_var - ((1.0 - _VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel)))), _LightDirection_MaskOn);
float _ApRimLightPower_var = pow(_RimArea_var, exp2(lerp(3, 0, _Ap_RimLight_Power)));
#ifdef UTS_LAYER_VISIBILITY
float4 overridingRimColor = lerp(_RimLightMaskColor, float4(_RimLightMaskColor.w, _RimLightMaskColor.w, _RimLightMaskColor.w, 1.0f), _ComposerMaskMode);
float maskRimEnabled = max(_RimLightOverridden, _ComposerMaskMode);
float Set_RimLightAlpha = _RimLightVisible;
float3 Set_RimLight = (saturate((_Set_RimLightMask_var.g + _Tweak_RimLightMaskLevel)) * lerp(_LightDirection_MaskOn_var, (_LightDirection_MaskOn_var + (lerp(_Ap_RimLightColor.rgb, (_Ap_RimLightColor.rgb * Set_LightColor), _Is_LightColor_Ap_RimLight) * saturate((lerp((0.0 + ((_ApRimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _ApRimLightPower_var), _Ap_RimLight_FeatherOff) - (saturate(_VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel))))), _Add_Antipodean_RimLight));
Set_RimLight *= _RimLightVisible;
float3 _RimLight_var = lerp(Set_HighColor, (Set_HighColor + Set_RimLight), _RimLight);
if (any(Set_RimLight) * maskRimEnabled)
{
_RimLight_var = overridingRimColor.xyz;
channelOutAlpha = Set_RimLightAlpha;
}
#else
float3 Set_RimLight = (saturate((_Set_RimLightMask_var.g + _Tweak_RimLightMaskLevel)) * lerp(_LightDirection_MaskOn_var, (_LightDirection_MaskOn_var + (lerp(_Ap_RimLightColor.rgb, (_Ap_RimLightColor.rgb * Set_LightColor), _Is_LightColor_Ap_RimLight) * saturate((lerp((0.0 + ((_ApRimLightPower_var - _RimLight_InsideMask) * (1.0 - 0.0)) / (1.0 - _RimLight_InsideMask)), step(_RimLight_InsideMask, _ApRimLightPower_var), _Ap_RimLight_FeatherOff) - (saturate(_VertHalfLambert_var) + _Tweak_LightDirection_MaskLevel))))), _Add_Antipodean_RimLight));
//Composition: HighColor and RimLight as _RimLight_var
float3 _RimLight_var = lerp(Set_HighColor, (Set_HighColor + Set_RimLight), _RimLight);
#endif
//Matcap
//v.2.0.6 : CameraRolling Stabilizer
//Mirror Script Determination: if sign_Mirror = -1, determine "Inside the mirror".
//v.2.0.7
utsData.signMirror = 0.0; // i.mirrorFlag; todo.
float3 _Camera_Right = UNITY_MATRIX_V[0].xyz;
float3 _Camera_Front = UNITY_MATRIX_V[2].xyz;
float3 _Up_Unit = float3(0, 1, 0);
float3 _Right_Axis = cross(_Camera_Front, _Up_Unit);
//Invert if it's "inside the mirror".
if (utsData.signMirror < 0) {
_Right_Axis = -1 * _Right_Axis;
_Rotate_MatCapUV = -1 * _Rotate_MatCapUV;
}
else {
_Right_Axis = _Right_Axis;
}
float _Camera_Right_Magnitude = sqrt(_Camera_Right.x * _Camera_Right.x + _Camera_Right.y * _Camera_Right.y + _Camera_Right.z * _Camera_Right.z);
float _Right_Axis_Magnitude = sqrt(_Right_Axis.x * _Right_Axis.x + _Right_Axis.y * _Right_Axis.y + _Right_Axis.z * _Right_Axis.z);
float _Camera_Roll_Cos = dot(_Right_Axis, _Camera_Right) / (_Right_Axis_Magnitude * _Camera_Right_Magnitude);
utsData.cameraRoll = acos(clamp(_Camera_Roll_Cos, -1, 1));
utsData.cameraDir = _Camera_Right.y < 0 ? -1 : 1;
float _Rot_MatCapUV_var_ang = (_Rotate_MatCapUV * 3.141592654) - utsData.cameraDir * utsData.cameraRoll * _CameraRolling_Stabilizer;
//v.2.0.7
float2 _Rot_MatCapNmUV_var = RotateUV(Set_UV0.xy, (_Rotate_NormalMapForMatCapUV * 3.141592654f), float2(0.5, 0.5), 1.0);
//V.2.0.6
float3 _NormalMapForMatCap_var = UnpackNormalScale(tex2D(_NormalMapForMatCap, TRANSFORM_TEX(_Rot_MatCapNmUV_var, _NormalMapForMatCap)), _BumpScaleMatcap);
//v.2.0.5: MatCap with camera skew correction
float3 viewNormal = (mul(UNITY_MATRIX_V, float4(lerp(i_normalDir, mul(_NormalMapForMatCap_var.rgb, tangentTransform).rgb, _Is_NormalMapForMatCap), 0))).rgb;
float3 NormalBlend_MatcapUV_Detail = viewNormal.rgb * float3(-1, -1, 1);
float3 NormalBlend_MatcapUV_Base = (mul(UNITY_MATRIX_V, float4(utsData.viewDirection, 0)).rgb * float3(-1, -1, 1)) + float3(0, 0, 1);
float3 noSknewViewNormal = NormalBlend_MatcapUV_Base * dot(NormalBlend_MatcapUV_Base, NormalBlend_MatcapUV_Detail) / NormalBlend_MatcapUV_Base.b - NormalBlend_MatcapUV_Detail;
float2 _ViewNormalAsMatCapUV = (lerp(noSknewViewNormal, viewNormal, _Is_Ortho).rg * 0.5) + 0.5;
//v.2.0.7
float2 _Rot_MatCapUV_var = RotateUV((0.0 + ((_ViewNormalAsMatCapUV - (0.0 + _Tweak_MatCapUV)) * (1.0 - 0.0)) / ((1.0 - _Tweak_MatCapUV) - (0.0 + _Tweak_MatCapUV))), _Rot_MatCapUV_var_ang, float2(0.5, 0.5), 1.0);
//Invert if it's "inside the mirror".
if (utsData.signMirror < 0) {
_Rot_MatCapUV_var.x = 1 - _Rot_MatCapUV_var.x;
}
else {
_Rot_MatCapUV_var = _Rot_MatCapUV_var;
}
//v.2.0.6 : LOD of Matcap
//
//MatcapMask
float4 _MatCap_Sampler_var = tex2Dlod(_MatCap_Sampler, float4(TRANSFORM_TEX(_Rot_MatCapUV_var, _MatCap_Sampler), 0.0, _BlurLevelMatcap));
float4 _Set_MatcapMask_var = tex2D(_Set_MatcapMask, TRANSFORM_TEX(Set_UV0, _Set_MatcapMask));
float _Tweak_MatcapMaskLevel_var = saturate(lerp(_Set_MatcapMask_var.g, (1.0 - _Set_MatcapMask_var.g), _Inverse_MatcapMask) + _Tweak_MatcapMaskLevel);
//
float3 _Is_LightColor_MatCap_var = lerp((_MatCap_Sampler_var.rgb * _MatCapColor.rgb), ((_MatCap_Sampler_var.rgb * _MatCapColor.rgb) * Set_LightColor), _Is_LightColor_MatCap);
//v.2.0.6 : ShadowMask on Matcap in Blend mode : multiply
float3 Set_MatCap = lerp(_Is_LightColor_MatCap_var, (_Is_LightColor_MatCap_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakMatCapOnShadow)) + lerp(Set_HighColor * Set_FinalShadowMask * (1.0 - _TweakMatCapOnShadow), float3(0.0, 0.0, 0.0), _Is_BlendAddToMatCap)), _Is_UseTweakMatCapOnShadow);
//
//Composition: RimLight and MatCap as finalColor
//Broke down finalColor composition
float3 matCapColorOnAddMode = _RimLight_var + Set_MatCap * _Tweak_MatcapMaskLevel_var;
float _Tweak_MatcapMaskLevel_var_MultiplyMode = _Tweak_MatcapMaskLevel_var * lerp(1.0, (1.0 - (Set_FinalShadowMask) * (1.0 - _TweakMatCapOnShadow)), _Is_UseTweakMatCapOnShadow);
float3 matCapColorOnMultiplyMode = Set_HighColor * (1 - _Tweak_MatcapMaskLevel_var_MultiplyMode) + Set_HighColor * Set_MatCap * _Tweak_MatcapMaskLevel_var_MultiplyMode + lerp(float3(0, 0, 0), Set_RimLight, _RimLight);
float3 matCapColorFinal = lerp(matCapColorOnMultiplyMode, matCapColorOnAddMode, _Is_BlendAddToMatCap);
float3 finalColor = lerp(_RimLight_var, matCapColorFinal, _MatCap);// Final Composition before Emissive
//
//v.2.0.6: GI_Intensity with Intensity Multiplier Filter
float3 envLightColor = DecodeLightProbe(utsData.normalDirection) < float3(1, 1, 1) ? DecodeLightProbe(utsData.normalDirection) : float3(1, 1, 1);
float envLightIntensity = 0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b < 1 ? (0.299 * envLightColor.r + 0.587 * envLightColor.g + 0.114 * envLightColor.b) : 1;
finalColor = SATURATE_IF_SDR(finalColor) + (envLightColor * envLightIntensity * _GI_Intensity * smoothstep(1, 0, envLightIntensity / 2)) + emissive;
return finalColor;
}

View File

@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 8f3d7136d29e4e94694ab0df05f6a94c
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,143 +0,0 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
float3 UTS_OtherLights(FragInputs input, float3 i_normalDir,
float3 additionalLightColor, float3 lightDirection, float notDirectional, out float channelOutAlpha)
{
channelOutAlpha = 1.0f;
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode != 0)
{
return float3(0.0f, 0.0f, 0.0f);
}
#endif // _IS_CLIPPING_MATTE
/* todo. these should be put into struct */
#ifdef VARYINGS_NEED_POSITION_WS
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
#else
// Unused
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
#endif
float4 Set_UV0 = input.texCoord0;
float3x3 tangentTransform = input.tangentToWorld;
//UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, texCoords))
float4 n = SAMPLE_TEXTURE2D_LOD(_NormalMap, sampler_NormalMap, Set_UV0.xy, 0);
// float3 _NormalMap_var = UnpackNormalScale(tex2D(_NormalMap, TRANSFORM_TEX(Set_UV0, _NormalMap)), _BumpScale);
float3 _NormalMap_var = UnpackNormalScale(n, _BumpScale);
float3 normalLocal = _NormalMap_var.rgb;
float3 normalDirection = normalize(mul(normalLocal, tangentTransform)); // Perturbed normals
// float3 i_normalDir = surfaceData.normalWS;
float3 viewDirection = V;
float4 _MainTex_var = SAMPLE_TEXTURE2D_LOD(_MainTex, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _MainTex), 0.0f);
/* end of todo.*/
//v.2.0.5:
float3 addPassLightColor = (0.5 * dot(lerp(i_normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5) * additionalLightColor.rgb;
float pureIntencity = max(0.001, (0.299 * additionalLightColor.r + 0.587 * additionalLightColor.g + 0.114 * additionalLightColor.b));
float3 lightColor = max(0, lerp(addPassLightColor, lerp(0, min(addPassLightColor, addPassLightColor / pureIntencity), notDirectional), _Is_Filter_LightColor));
float3 halfDirection = normalize(viewDirection + lightDirection); // has to be recalced here.
//v.2.0.5:
_BaseColor_Step = saturate(_BaseColor_Step + _StepOffset);
_ShadeColor_Step = saturate(_ShadeColor_Step + _StepOffset);
//
//v.2.0.5: If Added lights is directional, set 0 as _LightIntensity
float _LightIntensity = lerp(0, (0.299 * additionalLightColor.r + 0.587 * additionalLightColor.g + 0.114 * additionalLightColor.b), notDirectional);
//v.2.0.5: Filtering the high intensity zone of PointLights
float3 Set_LightColor = lightColor;
//
float3 Set_BaseColor = lerp((_BaseColor.rgb * _MainTex_var.rgb * _LightIntensity), ((_BaseColor.rgb * _MainTex_var.rgb) * Set_LightColor), _Is_LightColor_Base);
#ifdef UTS_LAYER_VISIBILITY
float4 overridingColor = lerp(_BaseColorMaskColor, float4(_BaseColorMaskColor.w, _BaseColorMaskColor.w, _BaseColorMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_BaseColorOverridden, _ComposerMaskMode);
Set_BaseColor = lerp(Set_BaseColor, overridingColor.xyz, maskEnabled);
Set_BaseColor *= _BaseColorVisible;
float Set_BaseColorAlpha = _BaseColorVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY //v.2.0.5
float4 _1st_ShadeMap_var = lerp(SAMPLE_TEXTURE2D_LOD(_1st_ShadeMap, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _1st_ShadeMap),0.0f), _MainTex_var, _Use_BaseAs1st);
float3 Set_1st_ShadeColor = lerp((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb * _LightIntensity), ((_1st_ShadeColor.rgb * _1st_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_1st_Shade);
#ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_FirstShadeMaskColor, float4(_FirstShadeMaskColor.w, _FirstShadeMaskColor.w, _FirstShadeMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_FirstShadeOverridden, _ComposerMaskMode);
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, overridingColor.xyz, maskEnabled);
Set_1st_ShadeColor = lerp(Set_1st_ShadeColor, Set_BaseColor, 1.0f - _FirstShadeVisible);
}
float Set_1st_ShadeAlpha = _FirstShadeVisible;
#endif //#ifdef UTS_LAYER_VISIBILITY //v.2.0.5
float4 _2nd_ShadeMap_var = lerp(SAMPLE_TEXTURE2D_LOD(_2nd_ShadeMap, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _2nd_ShadeMap), 0.0), _1st_ShadeMap_var, _Use_1stAs2nd);
float3 Set_2nd_ShadeColor = lerp((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb * _LightIntensity), ((_2nd_ShadeColor.rgb * _2nd_ShadeMap_var.rgb) * Set_LightColor), _Is_LightColor_2nd_Shade);
float _HalfLambert_var = 0.5 * dot(lerp(i_normalDir, normalDirection, _Is_NormalMapToBase), lightDirection) + 0.5;
float4 _Set_2nd_ShadePosition_var = tex2Dlod(_Set_2nd_ShadePosition, float4(TRANSFORM_TEX(Set_UV0, _Set_2nd_ShadePosition),0.0f,0.0f));
float4 _Set_1st_ShadePosition_var = tex2Dlod(_Set_1st_ShadePosition, float4(TRANSFORM_TEX(Set_UV0, _Set_1st_ShadePosition),0.0f, 0.0f));
//v.2.0.5:
float _1stColorFeatherForMask = lerp(_BaseShade_Feather, 0.0f, max(_FirstShadeOverridden, _ComposerMaskMode));
float _2ndColorFeatherForMask = lerp(_1st2nd_Shades_Feather, 0.0f, max(_SecondShadeOverridden, _ComposerMaskMode));
float Set_FinalShadowMask = saturate((1.0 + ((lerp(_HalfLambert_var, (_HalfLambert_var * saturate(1.0 + _Tweak_SystemShadowsLevel)), _Set_SystemShadowsToBase) - (_BaseColor_Step - _1stColorFeatherForMask)) * ((1.0 - _Set_1st_ShadePosition_var.rgb).r - 1.0)) / (_BaseColor_Step - (_BaseColor_Step - _1stColorFeatherForMask))));
//Composition: 3 Basic Colors as finalColor
#ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_SecondShadeMaskColor, float4(_SecondShadeMaskColor.w, _SecondShadeMaskColor.w, _SecondShadeMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_SecondShadeOverridden, _ComposerMaskMode);
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, overridingColor.xyz, maskEnabled);
Set_2nd_ShadeColor = lerp(Set_2nd_ShadeColor, Set_BaseColor, 1.0f - _SecondShadeVisible);
}
#endif //#ifdef UTS_LAYER_VISIBILITY
float3 finalColor = lerp(Set_BaseColor, lerp(Set_1st_ShadeColor, Set_2nd_ShadeColor, saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask))))), Set_FinalShadowMask); // Final Color
#ifdef UTS_LAYER_VISIBILITY
float Set_2nd_ShadeAlpha = _SecondShadeVisible;
channelOutAlpha = lerp(Set_BaseColorAlpha, lerp(Set_1st_ShadeAlpha, Set_2nd_ShadeAlpha, saturate((1.0 + ((_HalfLambert_var - (_ShadeColor_Step - _2ndColorFeatherForMask)) * ((1.0 - _Set_2nd_ShadePosition_var.rgb).r - 1.0)) / (_ShadeColor_Step - (_ShadeColor_Step - _2ndColorFeatherForMask))))), Set_FinalShadowMask);
#endif
//v.2.0.6: Add HighColor if _Is_Filter_HiCutPointLightColor is False
float4 _Set_HighColorMask_var = tex2Dlod(_Set_HighColorMask, float4(TRANSFORM_TEX(Set_UV0, _Set_HighColorMask),0.0f,0.0f));
float _Specular_var = 0.5 * dot(halfDirection, lerp(i_normalDir, normalDirection, _Is_NormalMapToHighColor)) + 0.5; // Specular
float _TweakHighColorMask_var = (saturate((_Set_HighColorMask_var.g + _Tweak_HighColorMaskLevel)) * lerp((1.0 - step(_Specular_var, (1.0 - pow(abs(_HighColor_Power), 5)))), pow(abs(_Specular_var), exp2(lerp(11, 1, _HighColor_Power))), _Is_SpecularToHighColor));
float4 _HighColor_Tex_var = tex2Dlod(_HighColor_Tex, float4( TRANSFORM_TEX(Set_UV0, _HighColor_Tex),0.0f,0.0f));
float3 _HighColor_var = lerp((_HighColor_Tex_var.rgb * _HighColor.rgb), ((_HighColor_Tex_var.rgb * _HighColor.rgb) * Set_LightColor), _Is_LightColor_HighColor);
#ifdef UTS_LAYER_VISIBILITY
{
float4 overridingColor = lerp(_HighlightMaskColor, float4(_HighlightMaskColor.w, _HighlightMaskColor.w, _HighlightMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_HighlightOverridden, _ComposerMaskMode);
_HighColor_var *= _TweakHighColorMask_var;
_HighColor_var *= _HighlightVisible;
finalColor =
lerp(saturate(finalColor - _TweakHighColorMask_var), finalColor,
lerp(_Is_BlendAddToHiColor, 1.0
, _Is_SpecularToHighColor));
float3 addColor =
lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow)))
, _Is_UseTweakHighColorOnShadow);
finalColor += addColor;
if (any(addColor))
{
finalColor = lerp(finalColor, overridingColor.xyz, maskEnabled);
channelOutAlpha = _HighlightVisible;
}
}
#else
_HighColor_var *= _TweakHighColorMask_var;
finalColor = finalColor + lerp(lerp(_HighColor_var, (_HighColor_var * ((1.0 - Set_FinalShadowMask) + (Set_FinalShadowMask * _TweakHighColorOnShadow))), _Is_UseTweakHighColorOnShadow), float3(0, 0, 0), _Is_Filter_HiCutPointLightColor);
#endif //#ifdef UTS_LAYER_VISIBILITY
//
finalColor = SATURATE_IF_SDR(finalColor);
// pointLightColor += finalColor;
return finalColor;
}

View File

@@ -1,237 +0,0 @@
// _preIntegratedFGD and _CubemapLD are unique for each BRDF
IndirectLighting EvaluateBSDF_Env(LightLoopContext lightLoopContext,
float3 V, PositionInputs posInput,
PreLightData preLightData, EnvLightData lightData, BSDFData bsdfData,
int influenceShapeType,
inout float hierarchyWeight)
{
IndirectLighting lighting;
ZERO_INITIALIZE(IndirectLighting, lighting);
float3 envLighting;
float weight = 1.0;
float3 R = reflect(-V, bsdfData.normalWS);
EvaluateLight_EnvIntersection(posInput.positionWS, bsdfData.normalWS, lightData, influenceShapeType, R, weight);
// 31 bit index, 1 bit cache type
uint cacheType = IsEnvIndexCubemap(lightData.envIndex) ? ENVCACHETYPE_CUBEMAP : ENVCACHETYPE_TEXTURE2D;
// Index start at 1, because -0 == 0, so we can't known which cache to sample for that index. Thus it is invalid.
int index = abs(lightData.envIndex) - 1;
float lod = PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness) * lightData.roughReflections;
float2 atlasCoords = GetReflectionAtlasCoordsCube(CUBE_SCALE_OFFSET[index], R, lod);
// No distance based roughness for simple lit
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, PerceptualRoughnessToMipmapLevel(preLightData.iblPerceptualRoughness) * lightData.roughReflections, lightData.rangeCompressionFactorCompensation, posInput.positionNDC);
weight *= preLD.a; // Used by planar reflection to discard pixel
//envLighting = F_Schlick(bsdfData.fresnel0, dot(bsdfData.normalWS, V)) * preLD.rgb;
envLighting = preLD.rgb;
UpdateLightingHierarchyWeights(hierarchyWeight, weight);
envLighting *= weight * lightData.multiplier;
lighting.specularReflected = envLighting;
return lighting;
}
float4 ComputeReflection(LightLoopContext context, PositionInputs posInput, PreLightData preLightData, BuiltinData builtinData, float3 V, float lod, BSDFData bsdfData)
{
float3 refcolor = 0;
float reflectionHierarchyWeight = 0.0; // Max: 1.0
uint envLightStart, envLightCount;
// Fetch first env light to provide the scene proxy for screen space computation
#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
GetCountAndStart(posInput, LIGHTCATEGORY_ENV, envLightStart, envLightCount);
#else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
envLightCount = _EnvLightCount;
envLightStart = 0;
#endif
bool fastPath = false;
#if SCALARIZE_LIGHT_LOOP
uint envStartFirstLane;
fastPath = IsFastPath(envLightStart, envStartFirstLane);
#endif
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES;
#if SCALARIZE_LIGHT_LOOP
if (fastPath)
{
envLightStart = envStartFirstLane;
}
#endif
// Scalarized loop, same rationale of the punctual light version
uint v_envLightListOffset = 0;
uint v_envLightIdx = envLightStart;
#if NEED_TO_CHECK_HELPER_LANE
// On some platform helper lanes don't behave as we'd expect, therefore we prevent them from entering the loop altogether.
// IMPORTANT! This has implications if ddx/ddy is used on results derived from lighting, however given Lightloop is called in compute we should be
// sure it will not happen.
bool isHelperLane = WaveIsHelperLane();
while (!isHelperLane && v_envLightListOffset < envLightCount)
#else
while (v_envLightListOffset < envLightCount)
#endif
{
v_envLightIdx = FetchIndex(envLightStart, v_envLightListOffset);
#if SCALARIZE_LIGHT_LOOP
uint s_envLightIdx = ScalarizeElementIndex(v_envLightIdx, fastPath);
#else
uint s_envLightIdx = v_envLightIdx;
#endif
if (s_envLightIdx == -1)
break;
EnvLightData s_envLightData = FetchEnvLight(s_envLightIdx); // Scalar load.
// If current scalar and vector light index match, we process the light. The v_envLightListOffset for current thread is increased.
// Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
// end up with a unique v_envLightIdx value that is smaller than s_envLightIdx hence being stuck in a loop. All the active lanes will not have this problem.
if (s_envLightIdx >= v_envLightIdx)
{
v_envLightListOffset++;
if (reflectionHierarchyWeight < 1.0)
{
if (IsMatchingLightLayer(s_envLightData.lightLayers, builtinData.renderingLayers))
{
IndirectLighting lighting = EvaluateBSDF_Env(context, V, posInput, preLightData, s_envLightData, bsdfData, s_envLightData.influenceShapeType, reflectionHierarchyWeight);
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
float3 lightInReflDir = float3(-1, -1, -1);
if (s_envLightData.normalizeWithAPV > 0 && all(lightInReflDir >= 0))
{
float factor = GetReflectionProbeNormalizationFactor(lightInReflDir, bsdfData.normalWS, s_envLightData.L0L1, s_envLightData.L2_1, s_envLightData.L2_2);
lighting.specularReflected *= factor;
}
#endif
refcolor += lighting.specularReflected;
}
}
}
}
return float4(refcolor.r, refcolor.g, refcolor.b, reflectionHierarchyWeight);
}
float3 ComputeFresnelLerp(float3 c0, float3 c1, float cosA)
{
float t = pow(1 - cosA, 5);
return lerp(c0, c1, t);
}
float3 ComputeIndirectDiffuse(PositionInputs posInput, BSDFData bsdfData, float3 V)
{
float3 indirectDiffuse = 0.0;
if(_ID_Intensity > 0)
{
#ifdef _PBR_Mode_ANISO
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS , bsdfData.normalWS, V, bsdfData.anisotropy, bsdfData.perceptualRoughness, bsdfData.normalWS, bsdfData.perceptualRoughness);
#endif
float NdotV = saturate(dot(bsdfData.normalWS, V));
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
BuiltinData apvBuiltinData;
ZERO_INITIALIZE(BuiltinData, apvBuiltinData);
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS), 0.0, 0.0, V, posInput.positionSS, apvBuiltinData.bakeDiffuseLighting, apvBuiltinData.backBakeDiffuseLighting);
#else
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS), bsdfData.normalWS, -bsdfData.normalWS, V, posInput.positionSS, apvBuiltinData.bakeDiffuseLighting, apvBuiltinData.backBakeDiffuseLighting);
#endif
float3 probeDiffuse = apvBuiltinData.bakeDiffuseLighting * GetCurrentExposureMultiplier();
indirectDiffuse = probeDiffuse;
#else
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
indirectDiffuse = EvaluateAmbientProbe(0.0) * GetCurrentExposureMultiplier();
#else
indirectDiffuse = EvaluateAmbientProbe(bsdfData.normalWS) * GetCurrentExposureMultiplier();
#endif
#endif
//SSGI
if(_ReceivesSSGI == 1)
{
float4 ssgiLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS);
ssgiLighting *= _GIMultiplier;
indirectDiffuse = lerp(indirectDiffuse, ssgiLighting.rgb, ssgiLighting.a);
}
//Compelete the indirect lighting
indirectDiffuse = indirectDiffuse * bsdfData.diffuseColor.rgb * _BaseColor.rgb;
//SSAO
if(_ReceivesSSAO == 1)
{
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
indirectDiffuse *= lerp(_AOMin, 1, aoFactor.indirectAmbientOcclusion);
}
indirectDiffuse = indirectDiffuse * bsdfData.ambientOcclusion;
}
return indirectDiffuse;
}
float3 ComputeIndirectSpecular(LightLoopContext lightLoopContext, PositionInputs posInput, PreLightData preLightData, BSDFData bsdfData, SurfaceData surfaceData, BuiltinData builtinData, float3 V)
{
#if defined(_PBR_Mode_OFF) || defined(_PBR_Mode_TOON)
return 0;
#else
float3 indirectSpecular = 0;
if(_IR_Intensity > 0)
{
#ifdef _PBR_Mode_ANISO
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS , bsdfData.normalWS, V, bsdfData.anisotropy, bsdfData.perceptualRoughness, bsdfData.normalWS, bsdfData.perceptualRoughness);
#endif
float3 albedo = _BaseColor.rgb * surfaceData.baseColor;
float mip = PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness);
float NdotV = saturate(dot(bsdfData.normalWS, V));
indirectSpecular = SampleSkyTexture(reflect(-V, bsdfData.normalWS), mip, 0).rgb;
float3 specColor = lerp(ColorSpaceDielectricSpec.rgb, albedo, surfaceData.metallic);
float oneMinusReflectivity = ColorSpaceDielectricSpec.a * (1 - surfaceData.metallic);
float grazingTerm = saturate((1 - bsdfData.perceptualRoughness) + (1 - oneMinusReflectivity));
//Reflection Probe
float4 refProbe = ComputeReflection(lightLoopContext, posInput, preLightData, builtinData, V, mip, bsdfData);
indirectSpecular = lerp(indirectSpecular, refProbe.rgb, refProbe.a);
//SSR
if(_ReceivesSSR == 1)
{
float4 ssrLighting = LOAD_TEXTURE2D_X(_SsrLightingTexture, posInput.positionSS);
InversePreExposeSsrLighting(ssrLighting);
ApplyScreenSpaceReflectionWeight(ssrLighting);
indirectSpecular = lerp(indirectSpecular, ssrLighting.rgb, ssrLighting.a);
}
//Compelete the indirect lighting
indirectSpecular = indirectSpecular * ComputeFresnelLerp(specColor, grazingTerm, NdotV) * GetCurrentExposureMultiplier();
// Occlusion
if(_ReceivesSSAO == 1)
{
AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
indirectSpecular *= lerp(_AOMin, 1, aoFactor.indirectSpecularOcclusion);
}
indirectSpecular = indirectSpecular * bsdfData.specularOcclusion;
}
return indirectSpecular;
#endif
}

View File

@@ -1,23 +0,0 @@
float StepAntiAliasing(float x, float y)
{
float v = x - y;
return saturate(v / (fwidth(v)+HALF_MIN));//fwidth(x) = abs(ddx(x) + ddy(x))
}
float Remap(float In, float2 InMinMax, float2 OutMinMax)
{
return OutMinMax.x + (In - InMinMax.x) * (OutMinMax.y - OutMinMax.x) / (InMinMax.y - InMinMax.x);
}
float3 ToonMaping(float3 x)
{
x = x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14);
return x;
}
float3 GetSmoothedWorldNormal(float2 uv, float3x3 t_tbn)
{
float3 normal = float3(uv, 0);
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
return mul(normal, t_tbn);
}

View File

@@ -1,352 +0,0 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#ifndef UCTS_HDRP_INCLUDED
#define UCTS_HDRP_INCLUDED
#define UCTS_HDRP 1
#define UTS_LAYER_VISIBILITY
#ifndef DIRECTIONAL
# define DIRECTIONAL
#endif
#define FP_BUFFER 1
#if FP_BUFFER
#define SATURATE_IF_SDR(x) (x)
#define SATURATE_BASE_COLOR_IF_SDR(x) (x)
#else
#define SATURATE_IF_SDR(x) saturate(x)
#define SATURATE_BASE_COLOR_IF_SDR(x) saturate(x)
#endif
struct UTSData
{
float3 viewDirection;
float3 normalDirection;
fixed cameraDir;
float cameraRoll;
fixed signMirror;
};
//#define UTSDATA_ZERO_INITIALIZE (UTSData)
struct UTSLightData
{
float3 lightDirection;
float3 lightColor;
float diffuseDimmer;
float specularDimmer;
float3 shadowTint;
float penumbraTint;
float shadowValue;
};
struct UTSAggregateLighting
{
float3 directDiffuse;
float3 directSpecular;
float3 indirectDiffuse;
float3 indirectSpecular;
};
float3 AccumulateAggregateLighting(UTSAggregateLighting aggregateLighting)
{
return SATURATE_IF_SDR(aggregateLighting.directDiffuse + aggregateLighting.directSpecular) + aggregateLighting.indirectDiffuse + aggregateLighting.indirectSpecular;
}
#if defined(UNITY_PASS_PREPASSBASE) || defined(UNITY_PASS_DEFERRED) || defined(UNITY_PASS_SHADOWCASTER)
#undef FOG_LINEAR
#undef FOG_EXP
#undef FOG_EXP2
#endif
#if 1
// Legacy for compatibility with existing shaders
inline bool IsGammaSpace()
{
#ifdef UNITY_COLORSPACE_GAMMA
return true;
#else
return false;
#endif
}
// normal should be normalized, w=1.0
half3 SHEvalLinearL0L1(half4 normal)
{
half3 x;
// Linear (L1) + constant (L0) polynomial terms
x.r = dot(unity_SHAr, normal);
x.g = dot(unity_SHAg, normal);
x.b = dot(unity_SHAb, normal);
return x;
}
// normal should be normalized, w=1.0
half3 SHEvalLinearL2(half4 normal)
{
half3 x1, x2;
// 4 of the quadratic (L2) polynomials
half4 vB = normal.xyzz * normal.yzzx;
x1.r = dot(unity_SHBr, vB);
x1.g = dot(unity_SHBg, vB);
x1.b = dot(unity_SHBb, vB);
// Final (5th) quadratic (L2) polynomial
half vC = normal.x * normal.x - normal.y * normal.y;
x2 = unity_SHC.rgb * vC;
return x1 + x2;
}
// normal should be normalized, w=1.0
// output in active color space
half3 ShadeSH9(half4 normal)
{
// Linear + constant polynomial terms
half3 res = SHEvalLinearL0L1(normal);
// Quadratic polynomials
res += SHEvalLinearL2(normal);
# ifdef UNITY_COLORSPACE_GAMMA
res = LinearToGammaSpace(res);
# endif
return res;
}
float3 DecodeLightProbe(float3 N) {
return ShadeSH9(float4(N, 1));
}
inline float GammaToLinearSpaceExact(float value)
{
if (value <= 0.04045F)
return value / 12.92F;
else if (value < 1.0F)
return pow((value + 0.055F) / 1.055F, 2.4F);
else
return pow(value, 2.2F);
}
inline float3 GammaToLinearSpace(float3 sRGB)
{
// Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h);
// Precise version, useful for debugging.
//return half3(GammaToLinearSpaceExact(sRGB.r), GammaToLinearSpaceExact(sRGB.g), GammaToLinearSpaceExact(sRGB.b));
}
inline float LinearToGammaSpaceExact(float value)
{
if (value <= 0.0F)
return 0.0F;
else if (value <= 0.0031308F)
return 12.92F * value;
else if (value < 1.0F)
return 1.055F * pow(value, 0.4166667F) - 0.055F;
else
return pow(value, 0.45454545F);
}
inline float3 LinearToGammaSpace(float3 linRGB)
{
linRGB = max(linRGB, float3(0.h, 0.h, 0.h));
// An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
return max(1.055h * pow(linRGB, 0.416666667h) - 0.055h, 0.h);
// Exact version, useful for debugging.
//return half3(LinearToGammaSpaceExact(linRGB.r), LinearToGammaSpaceExact(linRGB.g), LinearToGammaSpaceExact(linRGB.b));
}
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#define UNITY_FOG_COORDS(idx) UNITY_FOG_COORDS_PACKED(idx, float1)
#if (SHADER_TARGET < 30) || defined(SHADER_API_MOBILE)
// mobile or SM2.0: calculate fog factor per-vertex
#define UNITY_TRANSFER_FOG(o,outpos) UNITY_CALC_FOG_FACTOR((outpos).z); o.fogCoord.x = unityFogFactor
#else
// SM3.0 and PC/console: calculate fog distance per-vertex, and fog factor per-pixel
#define UNITY_TRANSFER_FOG(o,outpos) o.fogCoord.x = (outpos).z
#endif
#else
#define UNITY_FOG_COORDS(idx)
#define UNITY_TRANSFER_FOG(o,outpos)
#endif
#define UNITY_FOG_LERP_COLOR(col,fogCol,fogFac) col.rgb = lerp((fogCol).rgb, (col).rgb, saturate(fogFac))
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#if (SHADER_TARGET < 30) || defined(SHADER_API_MOBILE)
// mobile or SM2.0: fog factor was already calculated per-vertex, so just lerp the color
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol) UNITY_FOG_LERP_COLOR(col,fogCol,(coord).x)
#else
// SM3.0 and PC/console: calculate fog factor and lerp fog color
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol) UNITY_CALC_FOG_FACTOR((coord).x); UNITY_FOG_LERP_COLOR(col,fogCol,unityFogFactor)
#endif
#else
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol)
#endif
#ifdef UNITY_PASS_FORWARDADD
#define UNITY_APPLY_FOG(coord,col) UNITY_APPLY_FOG_COLOR(coord,col,fixed4(0,0,0,0))
#else
#define UNITY_APPLY_FOG(coord,col) UNITY_APPLY_FOG_COLOR(coord,col,unity_FogColor)
#endif
#endif //#if false
#ifdef DIRECTIONAL
#define LIGHTING_COORDS(idx1,idx2) SHADOW_COORDS(idx1)
#define TRANSFER_VERTEX_TO_FRAGMENT(a) TRANSFER_SHADOW(a)
#define LIGHT_ATTENUATION(a) SHADOW_ATTENUATION(a)
#endif
// Transforms 2D UV by scale/bias property
//#define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)
#define UCTS_TEXTURE2D(tex,name) SAMPLE_TEXTURE2D(tex,sampler##tex,TRANSFORM_TEX(name, tex));
inline float4 UnityObjectToClipPosInstanced(in float3 pos)
{
// return mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorldArray[unity_InstanceID], float4(pos, 1.0)));
// todo. right?
return mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_M, float4(pos, 1.0)));
}
inline float4 UnityObjectToClipPosInstanced(float4 pos)
{
return UnityObjectToClipPosInstanced(pos.xyz);
}
#define UnityObjectToClipPos UnityObjectToClipPosInstanced
inline float3 UnityObjectToWorldNormal( in float3 norm )
{
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return UnityObjectToWorldDir(norm);
#else
// mul(IT_M, norm) => mul(norm, I_M) => {dot(norm, I_M.col0), dot(norm, I_M.col1), dot(norm, I_M.col2)}
return normalize(mul(norm, (float3x3)UNITY_MATRIX_M));
#endif
}
// normal should be normalized, w=1.0
float3 SHEvalLinearL0L1 (float4 normal)
{
float3 x;
// Linear (L1) + constant (L0) polynomial terms
x.r = dot(unity_SHAr,normal);
x.g = dot(unity_SHAg,normal);
x.b = dot(unity_SHAb,normal);
return x;
}
// normal should be normalized, w=1.0
float3 SHEvalLinearL2 (float4 normal)
{
float3 x1, x2;
// 4 of the quadratic (L2) polynomials
float4 vB = normal.xyzz * normal.yzzx;
x1.r = dot(unity_SHBr,vB);
x1.g = dot(unity_SHBg,vB);
x1.b = dot(unity_SHBb,vB);
// Final (5th) quadratic (L2) polynomial
half vC = normal.x*normal.x - normal.y*normal.y;
x2 = unity_SHC.rgb * vC;
return x1 + x2;
}
// normal should be normalized, w=1.0
// output in active color space
float3 ShadeSH9 (float4 normal)
{
// Linear + constant polynomial terms
float3 res = SHEvalLinearL0L1 (normal);
// Quadratic polynomials
res += SHEvalLinearL2 (normal);
# ifdef UNITY_COLORSPACE_GAMMA
res = LinearToGammaSpace (res);
# endif
return res;
}
float rateR = 0.299;
float rateG = 0.587;
float rateB = 0.114;
float3 SampleBakedGI_UTS(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap, bool needToIncludeAPV = false)
{
float3 bakeDiffuseLighting = float3(0, 0, 0);
float3 backBakeDiffuseLighting = float3(0, 0, 0);
float3 backNormalWS = float3(0, 0, 0);
#if !defined(_SURFACE_TYPE_TRANSPARENT) && (SHADERPASS != SHADERPASS_RAYTRACING_INDIRECT) && (SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER)
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF
#if (SHADERPASS == SHADERPASS_GBUFER)
&& _IndirectDiffuseMode != INDIRECTDIFFUSEMODE_MIXED && _ReflectionsMode != REFLECTIONSMODE_MIXED
#endif
)
return bakeDiffuseLighting;
#endif
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
EvaluateLightmap(positionRWS, normalWS, backNormalWS, uvStaticLightmap, uvDynamicLightmap, bakeDiffuseLighting, backBakeDiffuseLighting);
#elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
if (needToIncludeAPV)
{
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(positionRWS), normalWS, backNormalWS, GetWorldSpaceNormalizeViewDir(positionRWS), 0.0, bakeDiffuseLighting, backBakeDiffuseLighting);
}
#else
EvaluateLightProbeBuiltin(positionRWS, normalWS, backNormalWS, bakeDiffuseLighting, backBakeDiffuseLighting);
#if defined(SHADER_STAGE_RAY_TRACING)
bakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
backBakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
#endif
#endif
return bakeDiffuseLighting;
}
float3 SampleBakedGI_UTS_OutLine(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap)
{
float3 bakeDiffuseLighting = float3(0, 0, 0);
float3 backBakeDiffuseLighting = float3(0, 0, 0);
float3 backNormalWS = float3(0, 0, 0);
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
EvaluateLightmap(positionRWS, normalWS, backNormalWS, uvStaticLightmap, uvDynamicLightmap, bakeDiffuseLighting, backBakeDiffuseLighting);
#elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(positionRWS), normalWS, backNormalWS, GetWorldSpaceNormalizeViewDir(positionRWS), 0.0, bakeDiffuseLighting, backBakeDiffuseLighting);
#else
EvaluateLightProbeBuiltin(positionRWS, normalWS, backNormalWS, bakeDiffuseLighting, backBakeDiffuseLighting);
#if defined(SHADER_STAGE_RAY_TRACING)
bakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
backBakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
#endif
#endif
return bakeDiffuseLighting;
}
#endif //#ifndef UCTS_HDRP_INCLUDED

View File

@@ -1,224 +0,0 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#undef unity_ObjectToWorld
#undef unity_WorldToObject
float4 _LightColor0; // not referenced in c# code ??
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl"
// PackedVaryingsType
// https://github.com/Unity-Technologies/Graphics/blob/e4117c07b479adafed38237f3407a363eefb4590/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl#L120
PackedVaryingsType Vert(AttributesMesh inputMesh, AttributesPass inputPass)
{
// VaryingsType
// https://github.com/Unity-Technologies/Graphics/blob/e4117c07b479adafed38237f3407a363eefb4590/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl#L118
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
varyingsType.vmesh.
#include "HDRPToonOutlineVertMain.hlsl"
return MotionVectorVS(varyingsType, inputMesh, inputPass);
}
#ifdef TESSELLATION_ON
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
MotionVectorPositionZBias(output);
output.vpass.positionCS = input.vpass.positionCS;
output.vpass.previousPositionCS = input.vpass.previousPositionCS;
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
#else // _WRITE_TRANSPARENT_MOTION_VECTOR
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
#include "HDRPToonOutlineVertMain.hlsl"
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
#ifdef TESSELLATION_ON
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/TessellationShare.hlsl"
#endif
#ifdef UNITY_VIRTUAL_TEXTURING
#define VT_BUFFER_TARGET SV_Target1
#define EXTRA_BUFFER_TARGET SV_Target2
#else
#define EXTRA_BUFFER_TARGET SV_Target1
#endif
void Frag(PackedVaryingsToPS packedInput,
#ifdef OUTPUT_SPLIT_LIGHTING
out float4 outColor : SV_Target0, // outSpecularLighting
#ifdef UNITY_VIRTUAL_TEXTURING
out float4 outVTFeedback : VT_BUFFER_TARGET,
#endif
out float4 outDiffuseLighting : EXTRA_BUFFER_TARGET,
OUTPUT_SSSBUFFER(outSSSBuffer)
#else
out float4 outColor : SV_Target0
#ifdef UNITY_VIRTUAL_TEXTURING
, out float4 outVTFeedback : VT_BUFFER_TARGET
#endif
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
, out float4 outMotionVec : EXTRA_BUFFER_TARGET
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
#endif // OUTPUT_SPLIT_LIGHTING
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : SV_Depth
#endif
)
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
#ifdef _IS_CLIPPING_MASK
if (_ClippingMaskMode != 0)
{
discard;
}
#endif
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode != 0)
{
discard;
}
#endif // _IS_CLIPPING_MATTE
#if defined(UTS_DEBUG_SHADOWMAP_NO_OUTLINE)
discard;
#endif
//v.2.0.5
if (_ZOverDrawMode > 0.99f)
{
#ifdef _DEPTHOFFSET_ON
outputDepth = posInput.deviceDepth;
#endif
#ifdef UNITY_VIRTUAL_TEXTURING
outVTFeedback = builtinData.vtPackedFeedback;
#endif
outColor = float4(1.0f, 1.0f, 1.0f, 1.0f); // but nothing should be drawn except Z value as colormask is set to 0
return;
}
_Color = _BaseColor;
float4 objPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
float4 Set_UV0 = input.texCoord0;
// The following temporary definition of unity_AmbientEquator is for HDRP only.
//float4 unity_AmbientEquator = float4(0.05, 0.05, 0.05, 1.0); //Todo.
//v.2.0.9
//float3 envLightSource_GradientEquator = unity_AmbientEquator.rgb > 0.05 ? unity_AmbientEquator.rgb : half3(0.05, 0.05, 0.05);
float3 envLightSource_GradientEquator = ShadeSH9(float4(0, 1, 0, 0));
float3 envLightSource_SkyboxIntensity = max(
SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, 0.0, 0.0), input.texCoord1.xy, input.texCoord2.xy),
SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, -1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy)
).rgb;
float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator;
ambientSkyColor *= GetCurrentExposureMultiplier() * 5.0f;
float4 _MainTex_var = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(Set_UV0, _MainTex));
float3 Set_BaseColor = _BaseColor.rgb*_MainTex_var.rgb;
float3 _Is_BlendBaseColor_var = lerp(_Outline_Color.rgb * ambientSkyColor, (_Outline_Color.rgb * ambientSkyColor * Set_BaseColor * Set_BaseColor), _Is_BlendBaseColor);
//
float3 _OutlineTex_var = tex2D(_OutlineTex,TRANSFORM_TEX(Set_UV0, _OutlineTex)).xyz;
float4 overridingColor = lerp(_OutlineMaskColor, float4(_OutlineMaskColor.w, _OutlineMaskColor.w, _OutlineMaskColor.w, 1.0f), _ComposerMaskMode);
float maskEnabled = max(_OutlineOverridden, _ComposerMaskMode);
//v.2.0.7.5
#ifdef _IS_OUTLINE_CLIPPING_NO
float3 Set_Outline_Color = lerp(_Is_BlendBaseColor_var, _OutlineTex_var.rgb*_Outline_Color.rgb * ambientSkyColor, _Is_OutlineTex );
if (_OutlineVisible < 0.1)
{
// Todo.
// without this, something is drawn even if _OutlineVisible = 0, in AngelRing(HDRP)
discard;
}
Set_Outline_Color = lerp(Set_Outline_Color, overridingColor.xyz, maskEnabled);
float3 volColor, volOpacity;
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
// input.positionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha
Set_Outline_Color.xyz = Set_Outline_Color.xyz * (1 - volOpacity) + volColor * _OutlineVisible;
outColor =float4(Set_Outline_Color, _OutlineVisible );
#elif _IS_OUTLINE_CLIPPING_YES
float4 _ClippingMask_var = SAMPLE_TEXTURE2D(_ClippingMask, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _ClippingMask));
float Set_MainTexAlpha = _MainTex_var.a;
float _IsBaseMapAlphaAsClippingMask_var = lerp( _ClippingMask_var.r, Set_MainTexAlpha, _IsBaseMapAlphaAsClippingMask );
float _Inverse_Clipping_var = lerp( _IsBaseMapAlphaAsClippingMask_var, (1.0 - _IsBaseMapAlphaAsClippingMask_var), _Inverse_Clipping );
float Set_Clipping = saturate((_Inverse_Clipping_var+_Clipping_Level));
clip(Set_Clipping - 0.5);
float4 Set_Outline_Color = lerp( float4(_Is_BlendBaseColor_var, Set_Clipping), float4((_OutlineTex_var.rgb * _Outline_Color.rgb * ambientSkyColor),Set_Clipping), _Is_OutlineTex );
Set_Outline_Color = lerp(Set_Outline_Color, overridingColor, maskEnabled);
Set_Outline_Color.w *= _OutlineVisible;
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
// input.positionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
float3 volColor, volOpacity;
EvaluateAtmosphericScattering(posInput, V, volColor, volOpacity); // Premultiplied alpha
Set_Outline_Color.xyz = Set_Outline_Color.xyz * (1 - volOpacity.x) + volColor * Set_Outline_Color.w;
outColor = Set_Outline_Color;
#endif
//outColor.rgb = ambientSkyColor;
#ifdef _DEPTHOFFSET_ON
outputDepth = posInput.deviceDepth;
#endif
#ifdef UNITY_VIRTUAL_TEXTURING
outVTFeedback = builtinData.vtPackedFeedback;
#endif
}
// End of File

View File

@@ -1,65 +0,0 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#if 1
float4 objPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
float2 Set_UV0 = inputMesh.uv0;
float4 _Outline_Sampler_var = tex2Dlod(_Outline_Sampler, float4(TRANSFORM_TEX(Set_UV0, _Outline_Sampler), 0.0, 0));
//v.2.0.4.3 baked Normal Texture for Outline
float3 normalDir = UnityObjectToWorldNormal(inputMesh.normalOS);
float3 tangentDir = normalize(mul(unity_ObjectToWorld, float4(inputMesh.tangentOS.xyz, 0.0)).xyz);
float3 bitangentDir = normalize(cross(normalDir, tangentDir) * inputMesh.tangentOS.w);
float3x3 tangentTransform = float3x3(tangentDir, bitangentDir, normalDir);
//UnpackNormal() can't be used, and so as follows. Do not specify a bump for the texture to be used.
float4 _BakedNormal_var = (tex2Dlod(_BakedNormal, float4(TRANSFORM_TEX(Set_UV0, _BakedNormal), 0.0, 0)) * 2 - 1);
float3 _BakedNormalDir = normalize(mul(_BakedNormal_var.rgb, tangentTransform));
//end
float Set_Outline_Width = (_Outline_Width * 0.01 * smoothstep(_Farthest_Distance, _Nearest_Distance, distance(objPos.rgb, _WorldSpaceCameraPos)) * _Outline_Sampler_var.rgb).r;
Set_Outline_Width *= (1.0f - _ZOverDrawMode);
//v.2.0.7.5
float4 _ClipCameraPos = mul(UNITY_MATRIX_VP, float4(_WorldSpaceCameraPos.xyz, 1));
//v.2.0.7
#if defined(UNITY_REVERSED_Z)
//v.2.0.4.2 (DX)
_Offset_Z = _Offset_Z * -0.01;
#else
//OpenGL
_Offset_Z = _Offset_Z * 0.01;
#endif
float3 FinalNormal;
if(_UseSmoothedNormal == 1)
{
float3 normal = float3(inputMesh.uv1, 0);
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
FinalNormal = mul(normal, tangentTransform);
}
else
{
FinalNormal = lerp(inputMesh.normalOS, _BakedNormalDir, _Is_BakedNormal);
}
//v2.0.4
#ifdef _OUTLINE_NML
//v.2.0.4.3 baked Normal Texture for Outline
float3 normal = mul((float3x3)transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)), FinalNormal);
#elif _OUTLINE_POS
Set_Outline_Width = Set_Outline_Width * 2;
float signVar = dot(normalize(inputMesh.positionOS), normalize(inputMesh.normalOS)) < 0 ? -1 : 1;
float3 normal = mul((float3x3)transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)), signVar * normalize(inputMesh.positionOS));
#endif
// screen space width
float2 extendDir = normalize(TransformWViewToHClip(normal).xy);
float4 clipPos = UnityObjectToClipPos(inputMesh.positionOS);
clipPos.xy += extendDir * min(_Outline_MaxWidth, (clipPos.w * Set_Outline_Width));
clipPos.z = clipPos.z + _Offset_Z * _ClipCameraPos.z;
float4 rws = mul(UNITY_MATRIX_I_P, clipPos); // use UNITY_MATRIX_I_P instead of unity_CameraInvProjection.
rws = mul(UNITY_MATRIX_I_V, rws); // use UNITY_MATRIX_I_V instead of unity_cameraToWorld.
#ifndef TESSELLATION_ON
varyingsType.vmesh.positionCS = clipPos;
#endif // TESSELLATION_ON
varyingsType.vmesh.positionRWS = rws.xyz;
#endif // #if 1

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 6499b7b5ccaae6944ae5fe89b016c50b
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,189 +0,0 @@
#define ColorSpaceDielectricSpec half4(0.22, 0.22, 0.22, 0.779)
float3 schlick(float f0, float hl) {
real x = 1.0 - hl;
real x2 = x * x;
real x5 = x * x2 * x2;
return (1.0 - f0) * x5 + f0;
}
float3 SpecularColor(float3 albedo, float metalic)
{
float3 specColor = lerp(ColorSpaceDielectricSpec.rgb, albedo, metalic);
return specColor;
}
float RoughnessToBlinnPhongSpecularExponent(float roughness)
{
return clamp(2 * rcp(roughness * roughness) - 2, FLT_EPS, rcp(FLT_EPS));
}
float StepFeatherToon(float value,float step,float feather)
{
return saturate((value - step + feather) / feather);
}
float3 ComputeSpecularTerm(float3 V, float3 L, BSDFData bsdfData)
{
float3 specTerm;
#ifdef _PBR_Mode_OFF
return 0;
#else
float3 N = bsdfData.normalWS;
float3 H = normalize(L + V);
float NdotL = dot(N, L);
float NdotV = dot(N, V);
float clampedNdotV = ClampNdotV(NdotV);
float clampedNdotL = saturate(NdotL);
float flippedNdotL = ComputeWrappedDiffuseLighting(-NdotL, TRANSMISSION_WRAP_LIGHT);
float diffuseNdotL = clampedNdotL;
float LdotV = dot(L, V);
float NdotH = saturate(dot(N, H));
float HdotL = saturate(dot(H, L));
float3 F = schlick(bsdfData.fresnel0.x, HdotL);
float partLambdaV;
float3 DV = 0;
#ifdef _PBR_Mode_ST
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughness, 0, bsdfData.roughnessT, bsdfData.roughnessB);
partLambdaV = GetSmithJointGGXPartLambdaV(clampedNdotV, bsdfData.roughnessT);
// We use abs(NdotL) to handle the none case of double sided
DV = DV_SmithJointGGX(NdotH, abs(NdotL), clampedNdotV, bsdfData.roughnessT, partLambdaV);
#elif _PBR_Mode_ANISO
float TdotV = dot(bsdfData.tangentWS, V);
float BdotV = dot(bsdfData.bitangentWS, V);
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughness, bsdfData.anisotropy, bsdfData.roughnessT, bsdfData.roughnessB);
partLambdaV = GetSmithJointGGXAnisoPartLambdaV(TdotV, BdotV, clampedNdotV, bsdfData.roughnessT, bsdfData.roughnessB);
// For anisotropy we must not saturate these values
float TdotH = dot(bsdfData.tangentWS, H);
float TdotL = dot(bsdfData.tangentWS, L);
float BdotH = dot(bsdfData.bitangentWS, H);
float BdotL = dot(bsdfData.bitangentWS, L);
// We use abs(NdotL) to handle the none case of double sided
DV = DV_SmithJointGGXAniso(TdotH, BdotH, NdotH, clampedNdotV, TdotL, BdotL, abs(NdotL), bsdfData.roughnessT, bsdfData.roughnessB, partLambdaV);
#elif _PBR_Mode_KK
float3 t = ShiftTangent(bsdfData.bitangentWS, N, bsdfData.anisotropy);
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.coatRoughness));
DV = D_KajiyaKay(t, H, specularExponent);
float normalizeSpec = DV * rcp(specularExponent + 2) * 2 * PI;
//DV *= StepFeatherToon(normalizeSpec,specularStep,specularFeather);
DV = DV * normalizeSpec * _KKColor.rgb;
#elif _PBR_Mode_TOON
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness));
specTerm = pow(NdotH, 5.0 * specularExponent);
specTerm = StepFeatherToon(specTerm, _ToonSpecularStep, _ToonSpecularFeather);
return specTerm * ColorSpaceDielectricSpec.rgb * clampedNdotL;
#endif
specTerm = DV * F;
specTerm = specTerm * clampedNdotL;
return specTerm;
#endif
}
half3 FitWithCurveApprox(half NdotL, half Curvature)
{
half curva = (1.0 / mad(Curvature, 0.5 - 0.0625, 0.0625) - 2.0) / (16.0 - 2.0);
half oneMinusCurva = 1.0 - curva;
half3 curve0;
{
half3 rangeMin = half3(0.0, 0.3, 0.3);
half3 rangeMax = half3(1.0, 0.7, 0.7);
half3 offset = half3(0.0, 0.06, 0.06);
half3 t = saturate(mad(NdotL, 1.0 / (rangeMax - rangeMin), (offset + rangeMin) / (rangeMin - rangeMax)));
half3 lowerLine = (t * t) * half3(0.65, 0.5, 0.9);
lowerLine.r += 0.045;
lowerLine.b *= t.b;
half3 m = half3(1.75, 2.0, 1.97);
half3 upperLine = mad(NdotL, m, half3(0.99, 0.99, 0.99) - m);
upperLine = saturate(upperLine);
half3 lerpMin = half3(0.0, 0.35, 0.35);
half3 lerpMax = half3(1.0, 0.7, 0.6);
half3 lerpT = saturate(mad(NdotL, 1.0 / (lerpMax - lerpMin), lerpMin / (lerpMin - lerpMax)));
curve0 = lerp(lowerLine, upperLine, lerpT * lerpT);
}
half3 curve1;
{
half3 m = half3(1.95, 2.0, 2.0);
half3 upperLine = mad(NdotL, m, half3(0.99, 0.99, 1.0) - m);
curve1 = saturate(upperLine);
}
float oneMinusCurva2 = oneMinusCurva * oneMinusCurva;
return lerp(curve0, curve1, mad(oneMinusCurva2, -1.0 * oneMinusCurva2, 1.0));
}
// Todo: SDF nose high light
// #if define(_SDFShadow) || define(_SDFNoiseHelight)
#ifdef _SDFShadow
// Use main light XZ direction & world Left/Forward Vector to sample character face SDF
void SDFSample(out float4 lSDF_Tex, out float4 rSDF_Tex, out float2 leftVector, out float2 forwardVector, float2 UV)
{
lSDF_Tex = SAMPLE_TEXTURE2D(_SDFShadowTex, sampler_SDFShadowTex, UV);
float2 right_uv = float2(1 - UV.x, UV.y);
rSDF_Tex = SAMPLE_TEXTURE2D(_SDFShadowTex, sampler_SDFShadowTex, right_uv);
leftVector = normalize(mul(UNITY_MATRIX_M, float4(1, 0, 0, 0)).xz);
forwardVector = normalize(mul(UNITY_MATRIX_M, float4(0, 0, 1, 0)).xz);
}
// Return 1 -> right side
bool SDFPickSide(out float angle, float2 Left, float2 Front, float2 lightDir)
{
// Remap [-1,1] tp [0,1] | 0 <- Face Toward Light ---- Back Toward Light -> 1
angle = 1- clamp(0 , 1, dot(Front, lightDir) * 0.5 + 0.5);
// Pick side
return dot(lightDir,Left) > 0;
}
// Output: readjusted angle between light and pixel facing direction (Represented by a projection length) [Out Param, angle]
// Output: SDF Texel Color [Return Value]
float4 SDFResult(inout bool rightside, out float angle, float3 L, float2 UV)
{
float4 left_SDFTex;
float4 right_SDFTex;
float2 Left;
float2 Front;
SDFSample(left_SDFTex, right_SDFTex, Left, Front, UV);
float2 light_Dir = normalize(L.xz);
rightside = SDFPickSide(angle, Left, Front, light_Dir);
return rightside ? right_SDFTex : left_SDFTex;
}
float SDFMask(float angle, float tex_direct)
{
float smoothGamma = _SDFSmoothGamma / 10.0f;
float shadowLevel = _SDFShadowLevel / 10.0f;
float SDFMask = smoothstep(tex_direct - smoothGamma, tex_direct + smoothGamma, angle - shadowLevel);
return SDFMask;
}
float SDFNoseHighlight(float angle,float tex_value, bool rightside, float2 UV)
{
// REF: https://zhuanlan.zhihu.com/p/411188212 3.2.1
float highlightValue = 0;
//float cutU = step(0.5, UV.x);
float cutU = UV.x;
float uvMask=lerp(cutU, 1 - cutU, rightside);//discard half of the sdf we sampled (Only one side of highlight wanted)
float lightAtten = pow(max(0, angle - (_SDFShadowLevel / 10.0f)), 0.8);
return smoothstep(lightAtten-_SDFNoseHighlightSmoothRange,lightAtten+_SDFNoseHighlightSmoothRange , uvMask * tex_value) * tex_value; // Safeguard, return 0 when tex_value = 0
}
#endif

View File

@@ -1,237 +0,0 @@
#if SHADERPASS != SHADERPASS_FORWARD
#error SHADERPASS_is_not_correctly_define
#endif
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/MotionVectorVertexShaderCommon.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh, AttributesPass inputPass)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return MotionVectorVS(varyingsType, inputMesh, inputPass);
}
#ifdef TESSELLATION_ON
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
MotionVectorPositionZBias(output);
output.vpass.positionCS = input.vpass.positionCS;
output.vpass.previousPositionCS = input.vpass.previousPositionCS;
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
#else // _WRITE_TRANSPARENT_MOTION_VECTOR
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl"
PackedVaryingsType Vert(AttributesMesh inputMesh)
{
VaryingsType varyingsType;
varyingsType.vmesh = VertMesh(inputMesh);
return PackVaryingsType(varyingsType);
}
#ifdef TESSELLATION_ON
PackedVaryingsToPS VertTesselation(VaryingsToDS input)
{
VaryingsToPS output;
output.vmesh = VertMeshTesselation(input.vmesh);
return PackVaryingsToPS(output);
}
#endif // TESSELLATION_ON
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
#ifdef TESSELLATION_ON
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/TessellationShare.hlsl"
#endif
void Frag(PackedVaryingsToPS packedInput,
#ifdef OUTPUT_SPLIT_LIGHTING
out float4 outColor : SV_Target0, // outSpecularLighting
out float4 outDiffuseLighting : SV_Target1,
OUTPUT_SSSBUFFER(outSSSBuffer)
#else
out float4 outColor : SV_Target0
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
, out float4 outMotionVec : SV_Target1
#endif // _WRITE_TRANSPARENT_MOTION_VECTOR
#endif // OUTPUT_SPLIT_LIGHTING
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : SV_Depth
#endif
)
{
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
// Init outMotionVector here to solve compiler warning (potentially unitialized variable)
// It is init to the value of forceNoMotion (with 2.0)
outMotionVec = float4(2.0, 0.0, 0.0, 0.0);
#endif
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
// We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer.
input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy;
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
// input.positionSS is SV_Position
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
#ifdef VARYINGS_NEED_POSITION_WS
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
#else
// Unused
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
#endif
SurfaceData surfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(input.positionSS.xy, surfaceData);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
outColor = float4(0.0, 0.0, 0.0, 0.0);
// We need to skip lighting when doing debug pass because the debug pass is done before lighting so some buffers may not be properly initialized potentially causing crashes on PS4.
#ifdef DEBUG_DISPLAY
// Init in debug display mode to quiet warning
#ifdef OUTPUT_SPLIT_LIGHTING
outDiffuseLighting = 0;
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
#endif
float4 Set_UV0 = input.texCoord0;
float4 _MainTex_var = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, TRANSFORM_TEX(Set_UV0, _MainTex));
surfaceData.baseColor = _MainTex_var.xyz;
// Same code in ShaderPassForwardUnlit.shader
// Reminder: _DebugViewMaterialArray[i]
// i==0 -> the size used in the buffer
// i>0 -> the index used (0 value means nothing)
// The index stored in this buffer could either be
// - a gBufferIndex (always stored in _DebugViewMaterialArray[1] as only one supported)
// - a property index which is different for each kind of material even if reflecting the same thing (see MaterialSharedProperty)
bool viewMaterial = false;
int bufferSize = int(_DebugViewMaterialArray[0]);
if (bufferSize != 0)
{
bool needLinearToSRGB = false;
float3 result = float3(1.0, 0.0, 1.0);
// Loop through the whole buffer
// Works because GetSurfaceDataDebug will do nothing if the index is not a known one
for (int index = 1; index <= bufferSize; index++)
{
int indexMaterialProperty = int(_DebugViewMaterialArray[index]);
// skip if not really in use
if (indexMaterialProperty != 0)
{
viewMaterial = true;
GetPropertiesDataDebug(indexMaterialProperty, result, needLinearToSRGB);
GetVaryingsDataDebug(indexMaterialProperty, input, result, needLinearToSRGB);
GetBuiltinDataDebug(indexMaterialProperty, builtinData, result, needLinearToSRGB);
GetSurfaceDataDebug(indexMaterialProperty, surfaceData, result, needLinearToSRGB);
GetBSDFDataDebug(indexMaterialProperty, bsdfData, result, needLinearToSRGB);
}
}
// TEMP!
// For now, the final blit in the backbuffer performs an sRGB write
// So in the meantime we apply the inverse transform to linear data to compensate.
if (!needLinearToSRGB)
result = SRGBToLinear(max(0, result));
outColor = float4(result, 1.0);
}
if (!viewMaterial)
{
if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR || _DebugFullScreenMode == FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR)
{
float3 result = float3(0.0, 0.0, 0.0);
GetPBRValidatorDebug(surfaceData, result);
outColor = float4(result, 1.0f);
}
else if (_DebugFullScreenMode == FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW)
{
float4 result = _DebugTransparencyOverdrawWeight * float4(TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_COST, TRANSPARENCY_OVERDRAW_A);
outColor = result;
}
else
#endif
{
#ifdef _SURFACE_TYPE_TRANSPARENT
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_TRANSPARENT;
#else
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
#endif
float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);
diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();
#ifdef OUTPUT_SPLIT_LIGHTING
if (_EnableSubsurfaceScattering != 0 && ShouldOutputSplitLighting(bsdfData))
{
outColor = float4(specularLighting, 1.0);
outDiffuseLighting = float4(TagLightingForSSS(diffuseLighting), 1.0);
}
else
{
outColor = float4(diffuseLighting + specularLighting, 1.0);
outDiffuseLighting = 0;
}
ENCODE_INTO_SSSBUFFER(surfaceData, posInput.positionSS, outSSSBuffer);
#else
outColor = ApplyBlendMode(diffuseLighting, specularLighting, builtinData.opacity);
outColor = EvaluateAtmosphericScattering(posInput, V, outColor);
#endif
#ifdef _WRITE_TRANSPARENT_MOTION_VECTOR
VaryingsPassToPS inputPass = UnpackVaryingsPassToPS(packedInput.vpass);
bool forceNoMotion = any(unity_MotionVectorsParams.yw == 0.0);
// outMotionVec is already initialize at the value of forceNoMotion (see above)
if (!forceNoMotion)
{
float2 motionVec = CalculateMotionVector(inputPass.positionCS, inputPass.previousPositionCS);
EncodeMotionVector(motionVec * 0.5, outMotionVec);
outMotionVec.zw = 1.0;
}
#endif
}
#ifdef DEBUG_DISPLAY
}
#endif
#ifdef _DEPTHOFFSET_ON
outputDepth = posInput.deviceDepth;
#endif
}

View File

@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 1b4f1c7876302e04a81e6bd06cb9dd39
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,275 +0,0 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Macros.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/PhysicalCamera.hlsl"
#include "HDRPToonHead.hlsl"
// Channel mask enum.
// this must be same to UI cs code
// HDRPToonGUI._ChannelEnum
int eBaseColor = 0;
int eFirstShade = 1;
int eSecondShade = 2;
int eHighlight = 3;
int eAngelRing = 4;
int eRimLight = 5;
int eOutline = 6;
// not in materials
int _ToonLightHiCutFilter;
int _ToonEvAdjustmentCurve;
float _ToonEvAdjustmentValueArray[128];
float _ToonEvAdjustmentValueMin;
float _ToonEvAdjustmentValueMax;
float _ToonEvAdjustmentCompensation;
float _ToonIgnoreExposureMultiplier;
// function to rotate the UV: RotateUV()
//float2 rotatedUV = RotateUV(i.uv0, (_angular_Verocity*3.141592654), float2(0.5, 0.5), _Time.g);
float2 RotateUV(float2 _uv, float _radian, float2 _piv, float _time)
{
float RotateUV_ang = _radian;
float RotateUV_cos = cos(_time*RotateUV_ang);
float RotateUV_sin = sin(_time*RotateUV_ang);
return (mul(_uv - _piv, float2x2(RotateUV_cos, -RotateUV_sin, RotateUV_sin, RotateUV_cos)) + _piv);
}
float3 ConvertFromEV100(float3 EV100)
{
#if 1
float3 value = pow(2, EV100) * 2.5f;
return value;
#else
float3 maxLuminance = 1.2f * pow(2.0f, EV100);
return 1.0f / maxLuminance;
#endif
}
float3 ConvertToEV100(float3 value)
{
#if 1
return log2(value*0.4f);
#else
return log2(1.0f / (1.2f * value));
#endif
}
float WeightSample(PositionInputs positionInput)
{
// Center-weighted
const float2 kCenter = _ScreenParams.xy * 0.5;
const float weight = pow(length((kCenter.xy - positionInput.positionSS.xy) / _ScreenParams.xy),1.0) ;
return 1.0 - saturate(weight);
}
float3 ApplyCompensation(float3 originalColor)
{
float3 ev100_Color = ConvertToEV100(originalColor) +_ToonEvAdjustmentCompensation * 0.5f;
float3 resultColor = max(0, ConvertFromEV100(ev100_Color));
return resultColor;
}
float3 ApplyCurrentExposureMultiplier(float3 color)
{
return color * lerp(GetCurrentExposureMultiplier(), 1, _ToonIgnoreExposureMultiplier);
}
float3 GetExposureAdjustedColor(float3 originalColor)
{
if (_ToonEvAdjustmentCurve != 0)
{
float3 ev100_Color = ConvertToEV100(originalColor);
ev100_Color = clamp(ev100_Color, _ToonEvAdjustmentValueMin, _ToonEvAdjustmentValueMax);
float3 ev100_remap = (ev100_Color - _ToonEvAdjustmentValueMin) * (128-1) / (_ToonEvAdjustmentValueMax - _ToonEvAdjustmentValueMin);
ev100_remap = clamp(ev100_remap, 0.0, 127.0);
int3 ev100_idx = (int3)ev100_remap;
float3 ev100_lerp = ev100_remap - ev100_idx;
float3 ev100_remapped;
ev100_remapped.r = _ToonEvAdjustmentValueArray[ev100_idx.r] +(_ToonEvAdjustmentValueArray[ev100_idx.r + 1] - _ToonEvAdjustmentValueArray[ev100_idx.r]) * ev100_lerp.r;
ev100_remapped.g = _ToonEvAdjustmentValueArray[ev100_idx.g] +(_ToonEvAdjustmentValueArray[ev100_idx.g + 1] - _ToonEvAdjustmentValueArray[ev100_idx.g]) * ev100_lerp.g;
ev100_remapped.b = _ToonEvAdjustmentValueArray[ev100_idx.b] +(_ToonEvAdjustmentValueArray[ev100_idx.b + 1] - _ToonEvAdjustmentValueArray[ev100_idx.b]) * ev100_lerp.b;
float3 resultColor = ConvertFromEV100(ev100_remapped);
return resultColor;
}
else // else is neccessary to avoid warrnings.
{
return originalColor;
}
}
float GetLightAttenuation(float3 lightColor)
{
float lightAttenuation = rateR *lightColor.r + rateG *lightColor.g + rateB *lightColor.b;
return lightAttenuation;
}
int GetNextDirectionalLightIndex(BuiltinData builtinData, int currentIndex, int mainLightIndex)
{
int i = 0; // Declare once to avoid the D3D11 compiler warning.
for (i = 0; i < (int)_DirectionalLightCount; ++i)
{
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
{
if (mainLightIndex != i)
{
if (currentIndex < i)
{
return i;
}
}
}
}
return -1; // not found
}
int GetUtsMainLightIndex(BuiltinData builtinData)
{
int mainLightIndex = -1;
float3 lightColor = float3(0.0f, 0.0f, 0.0f);
float lightAttenuation = 0.0f;
uint i = 0; // Declare once to avoid the D3D11 compiler warning.
for (i = 0; i < _DirectionalLightCount; ++i)
{
if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, builtinData.renderingLayers))
{
float3 currentLightColor = _DirectionalLightDatas[i].color;
float currentLightAttenuation = GetLightAttenuation(currentLightColor);
if (mainLightIndex == -1 || (currentLightAttenuation > lightAttenuation))
{
mainLightIndex = i;
lightAttenuation = currentLightAttenuation;
lightColor = currentLightColor;
}
}
}
return mainLightIndex;
}
// UTSLightData GetUTSMainPunctualLightData(BuiltinData builtinData, PositionInputs posInput)
// {
// UTSLightData mainPunctualLight;
// uint lightCount, lightStart;
// #ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
// GetCountAndStart(posInput, LIGHTCATEGORY_PUNCTUAL, lightStart, lightCount);
// #else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
// lightCount = _PunctualLightCount;
// lightStart = 0;
// #endif
// bool fastPath = false;
// #if SCALARIZE_LIGHT_LOOP
// uint lightStartLane0;
// fastPath = IsFastPath(lightStart, lightStartLane0);
// if (fastPath)
// {
// lightStart = lightStartLane0;
// }
// #endif
// uint v_lightListOffset = 0;
// uint v_lightIdx = lightStart;
// float channelAlpha = 0.0f;
// [loop] // vulkan shader compiler can not unroll.
// while (v_lightListOffset < lightCount)
// {
// v_lightIdx = FetchIndex(lightStart, v_lightListOffset);
// #if SCALARIZE_LIGHT_LOOP
// uint s_lightIdx = ScalarizeElementIndex(v_lightIdx, fastPath);
// #else
// uint s_lightIdx = v_lightIdx;
// #endif
// if (s_lightIdx == -1)
// break;
// LightData s_lightData = FetchLight(s_lightIdx);
// // If current scalar and vector light index match, we process the light. The v_lightListOffset for current thread is increased.
// // Note that the following should really be ==, however, since helper lanes are not considered by WaveActiveMin, such helper lanes could
// // end up with a unique v_lightIdx value that is smaller than s_lightIdx hence being stuck in a loop. All the active lanes will not have this problem.
// if (s_lightIdx >= v_lightIdx)
// {
// v_lightListOffset++;
// if (IsMatchingLightLayer(s_lightData.lightLayers, builtinData.renderingLayers))
// {
// float3 lightDirection;
// float4 distances; // {d, d^2, 1/d, d_proj}
// GetPunctualLightVectors(posInput.positionWS, s_lightData, lightDirection, distances);
// float4 lightColor = EvaluateLight_Punctual(context, posInput, s_lightData, lightDirection, distances);
// float3 additionalLightColor = ApplyCurrentExposureMultiplier(lightColor.rgb) * lightColor.a;
// const float notDirectional = 1.0f;
// UTSLightData utsLightData;
// utsLightData.lightColor = additionalLightColor;
// utsLightData.lightDirection = lightDirection;
// utsLightData.diffuseDimmer = s_lightData.diffuseDimmer;
// utsLightData.specularDimmer = s_lightData.specularDimmer;
// utsLightData.shadowTint = s_lightData.shadowTint;
// utsLightData.penumbraTint = s_lightData.penumbraTint;
// if(length(additionalLightColor) >= length(mainPunctualLight.lightColor))
// {
// mainPunctualLight = utsLightData;
// }
// }
// }
// }
// return mainPunctualLight;
// }
// Todo: calculate the acutal main lighboth dorectional and punctual)t based on the light attenuation, rather than using the main directional light
UTSLightData GetCustomMainLightData(BuiltinData builtinData, UTSLightData mainPunctualLight)
{
UTSLightData utsLightData;
int mainLightIndex;
mainLightIndex = GetUtsMainLightIndex(builtinData);
if (mainLightIndex == -1 || length(_DirectionalLightDatas[mainLightIndex].color) < length(mainPunctualLight.lightColor))
{
utsLightData = mainPunctualLight;
}
else
{
utsLightData.lightColor = ApplyCurrentExposureMultiplier(_DirectionalLightDatas[mainLightIndex].color);
utsLightData.lightDirection = -_DirectionalLightDatas[mainLightIndex].forward;
utsLightData.diffuseDimmer = _DirectionalLightDatas[mainLightIndex].diffuseDimmer;
utsLightData.specularDimmer = _DirectionalLightDatas[mainLightIndex].specularDimmer;
utsLightData.shadowTint = _DirectionalLightDatas[mainLightIndex].shadowTint;
utsLightData.penumbraTint = _DirectionalLightDatas[mainLightIndex].penumbraTint;
}
return utsLightData;
}
# include "ShadingOtherLight.hlsl"
# include "UtsSelfShadowMainLight.hlsl"
# include "ShadingMainLight.hlsl"

View File

@@ -1,27 +0,0 @@
// Unity Toon Shader
// sampler2D _MainTex;
// sampler2D _1st_ShadeMap;
// sampler2D _2nd_ShadeMap;
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
TEXTURE2D(_1st_ShadeMap);
TEXTURE2D(_2nd_ShadeMap);
sampler _Set_1st_ShadePosition;
sampler _Set_2nd_ShadePosition;
sampler _ShadingGradeMap;
sampler _HighColor_Tex;
sampler _Set_HighColorMask;
sampler _Set_RimLightMask;
sampler _MatCap_Sampler;
sampler _NormalMapForMatCap;
sampler _Set_MatcapMask;
sampler _Emissive_Tex;
// sampler2D _ClippingMask;
TEXTURE2D(_ClippingMask);
sampler _AngelRing_Sampler;
sampler _Outline_Sampler;
sampler _OutlineTex;
sampler _BakedNormal;

View File

@@ -1,132 +0,0 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering.RendererUtils;
namespace Misaki.HdrpToon
{
[HideInInspector]
internal class UTSHairShadowPass : DrawRenderersCustomPass
{
private const string Hair_Shadow_RTHandle_Scale_Prop_Name = "_HairShadowRTHandleScale";
private const string Hair_Shadow_Distance_Prop_Name = "_HairShadowDistance";
private const string Hair_Shadow_Distance_Scale_Prop_Name = "_HairShadowDistanceScaleFactor";
private const string Hair_Shadow_Depth_Bias_Prop_Name = "_HairShadowDepthBias";
private const string Hair_Shadow_FadeIn_Prop_Name = "_HairShadowFadeInDistance";
private const string Hair_Shadow_Fade_Out_Prop_Name = "_HairShadowFadeOutDistance";
private const string Output_RT_Prop_Name = "_HairShadowTex";
private RTHandle _outputRTHandle;
private bool _needReallocate;
private BufferQuality _shadowQuality = BufferQuality.High;
internal BufferQuality CurrentShadowQuality
{
get => _shadowQuality;
set
{
if (_shadowQuality == value)
{
return;
}
_shadowQuality = value;
_needReallocate = true;
}
}
private bool ShouldReallocateBuffer()
{
return _outputRTHandle == null || _outputRTHandle.rt == null || !_outputRTHandle.rt.IsCreated() || _needReallocate;
}
private void ReallocateBuffer()
{
#if UNITY_EDITOR
if (EditorApplication.isCompiling)
{
return;
}
#endif
var scale = _shadowQuality switch
{
BufferQuality.Low => new Vector2(0.5f, 0.5f),
BufferQuality.High => Vector2.one,
_ => Vector2.zero
};
var format = _shadowQuality switch
{
BufferQuality.Low => GraphicsFormat.D16_UNorm,
BufferQuality.High => GraphicsFormat.D32_SFloat,
_ => GraphicsFormat.D16_UNorm
};
_outputRTHandle?.Release();
_outputRTHandle = RTHandles.Alloc(scale, colorFormat: format, filterMode: FilterMode.Bilinear, wrapMode: TextureWrapMode.Clamp, isShadowMap: true, useDynamicScale: true, name: Output_RT_Prop_Name);
Shader.SetGlobalTexture(Output_RT_Prop_Name, _outputRTHandle);
_needReallocate = false;
}
protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd)
{
ReallocateBuffer();
}
protected override void Execute(CustomPassContext ctx)
{
if (ShouldReallocateBuffer())
{
ReallocateBuffer();
return;
}
CoreUtils.SetRenderTarget(ctx.cmd, _outputRTHandle, ClearFlag.DepthStencil);
var utsRenderer = ctx.hdCamera.volumeStack.GetComponent<UTSRenderer>();
var shouldRender = utsRenderer != null && utsRenderer.enableHairShadow.value && utsRenderer.state.value;
if (!shouldRender)
{
CoreUtils.ClearRenderTarget(ctx.cmd, ClearFlag.DepthStencil, Color.black);
return;
}
var result = new RendererListDesc(UtsShaderPassName.hairShadowCasterPassId, ctx.cullingResults, ctx.hdCamera.camera)
{
renderQueueRange = GetRenderQueueRange(RenderQueueType.All),
sortingCriteria = SortingCriteria.CommonOpaque,
excludeObjectMotionVectors = false,
};
CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(result));
Shader.SetGlobalVector(Hair_Shadow_RTHandle_Scale_Prop_Name, _outputRTHandle.rtHandleProperties.rtHandleScale);
Shader.SetGlobalFloat(Hair_Shadow_Distance_Prop_Name, utsRenderer.shadowDistance.value);
Shader.SetGlobalFloat(Hair_Shadow_Distance_Scale_Prop_Name, utsRenderer.shadowDistanceScale.value);
Shader.SetGlobalFloat(Hair_Shadow_Depth_Bias_Prop_Name, utsRenderer.shadowDepthBias.value);
Shader.SetGlobalFloat(Hair_Shadow_FadeIn_Prop_Name, utsRenderer.shadowFadeIn.value);
Shader.SetGlobalFloat(Hair_Shadow_Fade_Out_Prop_Name, utsRenderer.shadowFadeOut.value);
}
protected override void Cleanup()
{
Release();
}
public void Release()
{
#if UNITY_EDITOR
if (EditorApplication.isCompiling)
{
return;
}
#endif
_outputRTHandle?.Release();
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 7157c6dc91cee0d4aae565d1c8d66807

View File

@@ -1,22 +0,0 @@
using UnityEngine;
[ExecuteInEditMode]
public class UTSMeshRenderer : MonoBehaviour
{
private const string Shader_Prop_Object_Center_Name = "_ObjectCenterPositionWS";
public Material material;
public Transform objectCenter;
private void Update()
{
if (material == null)
return;
if (objectCenter != null)
{
material.SetVector(Shader_Prop_Object_Center_Name, objectCenter.position);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ee7513f8cc93a9d4f981fd4b10f8dfc1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
namespace Misaki.HdrpToon
{
internal enum ShadingMode
{
Standard,
SDF,
}
internal enum MaterialType
{
Standard,
FrontHair,
Face,
Eye
}
internal enum PBRMode
{
Off,
Standard,
Anisotropy,
KKHair,
Toon
}
internal enum IndirectDiffuseMode
{
Off,
IBL,
Matcap,
Ramp
}
internal enum IndirectSpecularMode
{
Off,
IBL,
Matcap
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b5065e386905cb248bdf1ded804260b4

View File

@@ -0,0 +1,15 @@
using System;
using UnityEngine.Rendering;
namespace Misaki.HdrpToon
{
[Flags]
[GenerateHLSL(PackingRules.Exact)]
public enum SurfaceFeature
{
None = 0,
RimLight = 1 << 0,
Stocking = 1 << 1,
AngelRing = 1 << 2
}
}

View File

@@ -0,0 +1,16 @@
//
// This file was automatically generated. Please don't edit by hand. Execute Editor command [ Edit > Rendering > Generate Shader Includes ] instead
//
#ifndef SURFACEFEATURE_CS_HLSL
#define SURFACEFEATURE_CS_HLSL
//
// Misaki.HdrpToon.SurfaceFeature: static fields
//
#define SURFACEFEATURE_NONE (0)
#define SURFACEFEATURE_RIM_LIGHT (1)
#define SURFACEFEATURE_STOCKING (2)
#define SURFACEFEATURE_ANGEL_RING (4)
#endif

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: a37603210e947e945be7817ada46bff5
guid: 1ae94e9055342d643a02bd5b4a9fa20b
ShaderIncludeImporter:
externalObjects: {}
userData:

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 598a7ef5d67c6334ca8f930f37ea989b

View File

@@ -1,205 +0,0 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace Misaki.HdrpToon
{
[ExecuteAlways]
[DisallowMultipleComponent]
[UTSHelpURL("ToonEVAdjustment")]
public class SceneToonEvAdjustment : MonoBehaviour
{
// flags
bool m_initialized = false;
bool m_srpCallbackInitialized = false;
const int kAdjustmentCurvePrecision = 128;
const string kCompensationPorpName = "_ToonEvAdjustmentCompensation";
const string kExposureAdjustmentPropName = "_ToonEvAdjustmentCurve";
const string kExposureArrayPropName = "_ToonEvAdjustmentValueArray";
const string kExposureMinPropName = "_ToonEvAdjustmentValueMin";
const string kExposureMaxPropName = "_ToonEvAdjustmentValueMax";
const string kToonLightFilterPropName = "_ToonLightHiCutFilter";
const string kIgonoreVolumeExposurePropName = "_ToonIgnoreExposureMultiplier";
internal bool m_ToonLightHiCutFilter = false;
internal bool m_ExposureAdjustmnt = false;
internal bool m_IgnorVolumeExposure = false;
internal AnimationCurve m_AnimationCurve = DefaultAnimationCurve();
internal float[] m_ExposureArray;
internal float m_Max, m_Min;
internal float m_Compensation;
private static SceneToonEvAdjustment instance;
#if UNITY_EDITOR
#pragma warning restore CS0414
bool m_isCompiling = false;
#endif
void Awake()
{
if (instance == null)
{
instance = this as SceneToonEvAdjustment;
return;
}
else if (instance == this)
{
return;
}
Debug.LogError("There is ToonEvAdjustmentCurve instance in hierarchy.");
#if UNITY_EDITOR
DestroyImmediate(this);
Selection.activeGameObject = instance.gameObject;
#else
Destroy(this);
#endif
}
void Reset()
{
OnDisable();
OnEnable();
DefaultAnimationCurve();
}
public static AnimationCurve DefaultAnimationCurve()
{
return AnimationCurve.Linear(-10f, -10f, -1.32f, -1.32f);
}
void Update()
{
Initialize();
GetValues();
// Fail safe in case the curve is deleted / has 0 point
var curve = m_AnimationCurve;
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, m_ExposureAdjustmnt ? 1 : 0);
Shader.SetGlobalInt(kToonLightFilterPropName, m_ToonLightHiCutFilter ? 1 : 0);
Shader.SetGlobalInt(kIgonoreVolumeExposurePropName, m_IgnorVolumeExposure ? 1 : 0);
Shader.SetGlobalFloat(kCompensationPorpName, m_Compensation);
}
private void GetValues()
{
}
void EnableSrpCallbacks()
{
if (!m_srpCallbackInitialized)
{
m_srpCallbackInitialized = true;
}
}
void DisableSrpCallbacks()
{
if (m_srpCallbackInitialized)
{
m_srpCallbackInitialized = false;
}
}
void OnEnable()
{
Initialize();
EnableSrpCallbacks();
}
void OnDisable()
{
DisableSrpCallbacks();
Release();
}
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;
}
void Release()
{
if (m_initialized)
{
m_ExposureArray = null;
Shader.SetGlobalInt(kExposureAdjustmentPropName, 0);
Shader.SetGlobalInt(kToonLightFilterPropName, 0);
}
m_initialized = false;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: db8edd5c572b6e648974dac4815d5619
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,54 +1,7 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
Shader "HDRP/Toon"
{
Properties
{
// -----------------------------------------------------------------------------
// parameters for UTS
// -----------------------------------------------------------------------------
[HideInInspector] _simpleUI("SimpleUI", Int) = 0
// Versioning of material to help for upgrading
[HideInInspector] [Enum(OFF, 0, ON, 1)] _isUnityToonshader("Material is touched by Unity Toon Shader", Int) = 1
[HideInInspector] _utsVersionX("VersionX", Float) = 0
[HideInInspector] _utsVersionY("VersionY", Float) = 7
[HideInInspector] _utsVersionZ("VersionZ", Float) = 6
// Reminder. Color here are in linear but the UI (color picker) do the conversion sRGB to linear
_BaseColor("BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
[HideInInspector] _BaseColorMap_MipInfo("_BaseColorMap_MipInfo", Vector) = (0, 0, 0, 0)
_HairBlendingMap("HairBlendingMap", 2D) = "black" {}
[KeywordEnum(OFF, FrontHair, Face, Eye)] _Material_Type("Material Type", Float) = 0
[KeywordEnum(OFF, ST, ANISO, KK, TOON)] _PBR_Mode("PBR MODE", Float) = 0
_Metallic("_Metallic", Range(0.0, 1.0)) = 0
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.5
_MaskMap("MaskMap", 2D) = "white" {}
//[ToggleUI, HideInInspector] _Use_MaskMap("Use MaskMap", Int) = 0
_MetallicRemapMin("MetalicRemapMin", Float) = 0.0
_MetallicRemapMax("MetalicRemapMax", Float) = 1.0
_SmoothnessRemapMin("RoughnessRemapMin", Float) = 0.0
_SmoothnessRemapMax("RoughnessRemapMax", Float) = 1.0
_AlphaRemapMin("AlphaRemapMin", Float) = 0.0 // HDRP 14
_AlphaRemapMax("AlphaRemapMax", Float) = 1.0 // HDRP 14
_AORemapMin("AORemapMin", Float) = 0.0
_AORemapMax("AORemapMax", Float) = 1.0
_SSSLutMap("SSSLutMap", 2D) = "white" {}
[ToggleUI, HideInInspector] _Use_SSSLut("Use SSSLut", Int) = 0
_SSSIntensity("SSSIntensity", Range(0.0, 3.0)) = 1.0
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_NormalMapOS("NormalMapOS", 2D) = "white" {} // Object space normal map - no good default value
_NormalScale("_NormalScale", Range(0.0, 8.0)) = 1
_BentNormalMap("_BentNormalMap", 2D) = "bump" {}
_BentNormalMapOS("_BentNormalMapOS", 2D) = "white" {}
_HeightMap("HeightMap", 2D) = "black" {}
// Caution: Default value of _HeightAmplitude must be (_HeightMax - _HeightMin) * 0.01
// Those two properties are computed from the ones exposed in the UI and depends on the displaement mode so they are separate because we don't want to lose information upon displacement mode change.
@@ -79,7 +32,7 @@ Shader "HDRP/Toon"
_AnisotropyMap("AnisotropyMap", 2D) = "white" {}
[ToggleUI] _Use_Anisotropy("Use Anisotropy", int) = 0
_KKColor("BaseColor", Color) = (1,1,1,1)
_BSDFContribution("_BSDFContribution", Float) = 0
_BSDFContribution("_BSDFContribution", Range(0.0,1.0)) = 0
[HideInInspector] _DiffusionProfile("Obsolete, kept for migration purpose", Int) = 0
[HideInInspector] _DiffusionProfileAsset("Diffusion Profile Asset", Vector) = (0, 0, 0, 0)
@@ -110,17 +63,6 @@ Shader "HDRP/Toon"
// These option below will cause different compilation flag.
[Enum(Off, 0, From Ambient Occlusion, 1, From Bent Normals, 2)] _SpecularOcclusionMode("Specular Occlusion Mode", Int) = 1
[HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
// Used only to serialize the LDR and HDR emissive color in the material UI,
// in the shader only the _EmissiveColor should be used
[HideInInspector] _EmissiveColorLDR("EmissiveColor LDR", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
[ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0
[HideInInspector] _EmissiveIntensityUnit("Emissive Mode", Int) = 0
[ToggleUI] _UseEmissiveIntensity("Use Emissive Intensity", Int) = 0
_EmissiveIntensity("Emissive Intensity", Float) = 1
_EmissiveExposureWeight("Emissive Pre Exposure", Range(0.0, 1.0)) = 1.0
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
[ToggleUI] _DistortionEnable("Enable Distortion", Float) = 0.0
[ToggleUI] _DistortionDepthTest("Distortion Depth Test Enable", Float) = 1.0
@@ -185,7 +127,7 @@ Shader "HDRP/Toon"
[HideInInspector] _AlphaDstBlend("__alphaDst", Float) = 0.0
[HideInInspector][ToggleUI] _ZWrite("__zw", Float) = 1.0
[HideInInspector][ToggleUI] _TransparentZWrite("_TransparentZWrite", Float) = 0.0
[HideInInspector] _CullMode("__cullmode", Float) = 2.0
//[Enum(Off, 0, Front, 1, Back, 2)] _CullMode("__cullmode", Float) = 2.0
[HideInInspector] _CullModeForward("__cullmodeForward", Float) = 2.0 // This mode is dedicated to Forward to correctly handle backface then front face rendering thin transparent
[HideInInspector] _TransparentCullMode("_TransparentCullMode", Int) = 2 // Back culling by default
[HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal
@@ -246,40 +188,198 @@ Shader "HDRP/Toon"
_EmissionColor("Color", Color) = (1, 1, 1)
// HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.
_MainTex("BaseMap", 2D) = "white" {}
_MainTex("Base Map", 2D) = "white" {}
_Color("Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleUI] _SupportDecals("Support Decals", Float) = 1.0
[ToggleUI] _ReceivesSSR("Receives SSR", Float) = 0.0
[ToggleUI] _ReceivesSSAO("Receives SSAO", Float) = 1.0
_AOMin("_AOMin", Range(0.0, 1.0)) = 0
[ToggleUI] _ReceivesSSGI("Receives SSGI", Float) = 1.0
_GIMultiplier("_GIMultiplier", Range(1.0, 10.0)) = 1
[ToggleUI] _AddPrecomputedVelocity("AddPrecomputedVelocity", Float) = 0.0
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
//TODO: Move more properties here for better organization
// Surface Options
[Popup] _TransparentEnabled("Transparent Mode", Integer) = 0
[ToggleUI] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[Enum(Off, 0, Front, 1, Back, 2)] _CullMode("Cull Mode", Integer) = 2
[KeywordEnum(Standard, SDF)] _Shading_Mode("Shading mode", Integer) = 0
[KeywordEnum(Standard, FrontHair, Face, Eye)] _Material_Type("Material Type", Integer) = 0
[KeywordEnum(Off, Standard, Anisotropy, KKHair, Toon)] _PBR_Mode("PBR Mode", Integer) = 0
[PassPopup(HairBlendingTarget)] _HairBlendingTarget("Hair Blending Target", Integer) = 0
[EnumFlagsUI(Misaki.HdrpToon.SurfaceFeature, Misaki.HdrpToon)]_SurfaceFeatures("Surface Features", Integer) = 0
// Shading Color
[Popup] _Use_Shading_Ramp_Map("Use Shading Ramp Map", Integer) = 0
_BaseColor("BaseColor", Color) = (1,1,1,1)
_BaseColorMap("BaseColorMap", 2D) = "white" {}
[HideInInspector] _BaseColorMap_MipInfo("_BaseColorMap_MipInfo", Vector) = (0, 0, 0, 0)
_1stShadeColor("1st_ShadeColor", Color) = (0, 0, 0, 0)
_1stShadeColorMap("1st_ShadeMap", 2D) = "white" {}
[ToggleUI] _UseBaseAs1st("Use BaseMap as 1st_ShadeMap", Float) = 1
_2ndShadeColor("2nd_ShadeColor", Color) = (0, 0, 0, 0)
_2ndShadeColorMap("2nd_ShadeMap", 2D) = "white" {}
[ToggleUI] _Use1stAs2nd("Use 1st_ShadeMap as 2nd_ShadeMap", Float) = 1
_1stShadeColorStep("1st ShadeColor Step", Range(0, 1)) = 0.5
_1stShadeColorFeather("1st ShadeColor Feather", Range(0.0001, 1)) = 0.0001
_2ndShadeColorStep("2nd ShadeColor Step", Range(0, 1)) = 0
_2ndShadeColorFeather("2nd ShadeColor Feather", Range(0.0001, 1)) = 0.0001
_ShadingRampMap("ShadingRampMap", 2DArray) = "white" {}
_ShadingIndex("ShadingIndex", Integer) = 0
_ShadingRampMaskMap("ShadingRampMaskMap", 2D) = "white" {}
_ShadingRampMask("ShadingRampMask", Range(0, 1)) = 1
_SDFShadingMap("SDFShadingMap", 2D) = "white" {}
_SDFShadowLevel("SDFShadowLevel", Range(0.0, 1.0)) = 0.25
_SDFShadowSmoothLevel("SDFShadowSmoothLevel", Range(0.0, 0.1)) = 0.02
_SDFHighlightStrength("SDFHighlightStrength", Range(0.0, 1.0)) = 0.75
// Shadow
[Popup] _Receive_Light_Shadow("Receive Light Shadow", Integer) = 0
[Popup] _Receive_Screen_Space_Shadow("Receive Screen Space Shadow", Integer) = 0
[Popup] _Receive_Hair_Shadow("Receive Hair Shadow", Integer) = 0
_ShadowDistanceBias("ShadowBias", Range(0.0, 5.0)) = 0.0
_ShadowNormalBias("ShadowNormalBias", Range(0.0, 5.0)) = 0.0
//_Tweak_SystemShadowsLevel("Tweak_SystemShadowsLevel", Range(-0.5, 0.5)) = 0
// Surface Inputs
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_NormalScale("_NormalScale", Range(0.0, 8.0)) = 1
_Metallic("_Metallic", Range(0.0, 1.0)) = 0
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.0
_MaskMap("MaskMap", 2D) = "white" {}
_MetallicRemapMin("MetalicRemapMin", Float) = 0.0
_MetallicRemapMax("MetalicRemapMax", Float) = 1.0
_SmoothnessRemapMin("RoughnessRemapMin", Float) = 0.0
_SmoothnessRemapMax("RoughnessRemapMax", Float) = 1.0
_AlphaRemapMin("AlphaRemapMin", Float) = 0.0
_AlphaRemapMax("AlphaRemapMax", Float) = 1.0
_AORemapMin("AORemapMin", Float) = 0.0
_AORemapMax("AORemapMax", Float) = 1.0
[ToggleUI] _Use_SSSLut("Use SSSLut", Integer) = 0
_SSSLutMap("SSSLutMap", 2D) = "white" {}
_SSSIntensity("SSSIntensity", Range(0.0, 3.0)) = 1.0
_HairBlendingMap("HairBlendingMap", 2D) = "black" {}
// Emissive
[HDR] _EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
// Used only to serialize the LDR and HDR emissive color in the material UI,
// in the shader only the _EmissiveColor should be used
[HideInInspector] _EmissiveColorLDR("EmissiveColor LDR", Color) = (0, 0, 0)
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
_EmissiveIntensity("Emissive Intensity", Float) = 1
[ToggleUI] _AlbedoAffectEmissive("Albedo Affect Emissive", Float) = 0.0
_EmissiveExposureWeight("Emissive Pre Exposure", Range(0.0, 1.0)) = 1.0
[Enum(WorldSpace, 0, ObjectSpace, 1)] _ObjectSpaceUVMappingEmissive("Mapping space", Float) = 0.0
// Ambient
[KeywordEnum(Off, IBL, MatCap, Ramp)]_Indirect_Diffuse_Mode("_Indirect_Diffuse_Mode", Integer) = 1
[KeywordEnum(Off, IBL, MatCap)]_Indirect_Specular_Mode("_Indirect_Specular_Mode", Integer) = 1
_IndirectDiffuseMatCapMap("IndirectDiffuseMatCapMap", 2D) = "black" {}
_IndirectDiffuseMatCapLod("IndirectDiffuseMatCapMapLOD", Range(-5, 5)) = 0.0
_IndirectDiffuseIntensity("Indirect Diffuse Intensity", Range(0, 5)) = 1.0
_SSAOWeight("SSAO Weight", Range(0.0, 1.0)) = 1.0
_SSGIWeight("SSGI Weight", Range(0.0, 1.0)) = 1.0
_IndirectSpecularMatCapMap("IndirectSpecularMatCapMap", 2D) = "black" {}
_IndirectSpecularMatCapLod("IndirectSpecularMatCapMapLOD", Range(-5, 5)) = 0.0
_IndirectSpecularIntensity("Indirect Specular Intensity", Range(0, 5)) = 1.0
_SSRWeight("SSR Weight", Range(0.0, 1.0)) = 1.0
// Rim Light
//_Set_HighColorMask("Set_HighColorMask", 2D) = "white" {}
//_Tweak_HighColorMaskLevel("Tweak_HighColorMaskLevel", Range(-1, 1)) = 0
//[Toggle(_)] _RimLight("RimLight", Float) = 0
_RimLightColor("Rim Light Color", Color) = (1, 1, 1, 1)
_RimLightIntensity("Rim Light Intensity", Range(0, 10)) = 1
[Popup] _Screen_Space_Rim_Light ("Screen Space Rim Light", Integer) = 0
_RimLightLevel("RimLight Level", Range(0, 1)) = 0.1
[ToggleUI] _RimLightClipping("Rim Light Clipping", Float) = 0.25
_RimLightClippingLevel("Rim Light Clipping Level", Range(0.0001, 1)) = 0.0001
[Popup] _Light_Base_Rim_Light ("Light Base Rim Light", Integer) = 0
_LightDirectionRimLightLevel("Light Direction Rim Light Level", Range(0, 0.5)) = 0
[ToggleUI] _Is_LightColor_RimLight("Is_LightColor_RimLight", Float) = 1
[ToggleUI] _Is_NormalMapToRimLight("Is_NormalMapToRimLight", Float) = 0
[ToggleUI] _LightDirection_MaskOn("LightDirection_MaskOn", Float) = 0
[ToggleUI] _Add_Antipodean_RimLight("Add_Antipodean_RimLight", Float) = 0
_Ap_RimLightColor("Ap_RimLightColor", Color) = (1, 1, 1, 1)
[ToggleUI] _Is_LightColor_Ap_RimLight("Is_LightColor_Ap_RimLight", Float) = 1
_Ap_RimLight_Power("Ap_RimLight_Power", Range(0, 1)) = 0.1
[ToggleUI] _Ap_RimLight_FeatherOff("Ap_RimLight_FeatherOff", Float) = 0
_Set_RimLightMask("Set_RimLightMask", 2D) = "white" {}
_Tweak_RimLightMaskLevel("Tweak_RimLightMaskLevel", Range(-1, 1)) = 0
// Angel Rings
_AngelRingColor("Angel Ring Color", Color) = (1, 1, 1, 1)
_AngelRingColorMap("Angel Ring Color Map", 2D) = "black" {}
_AngelRingIntensity("Angel Ring Intensity", Range(0, 10)) = 1
_AngelRingOffsetU("Angel Ring Offset U", Range(0, 1)) = 0
_AngelRingOffsetV("Angel Ring Offset V", Range(0, 1)) = 0
// Outline
[PassPopup(Outline)] _OutlineState("Outline State", Integer) = 1
_OutlineWidth("Outline Width", Float) = 0.25
_OutlineWidthMap("Outline Tex", 2D) = "white" {}
_OutlineColor("Outline Color", Color) = (0.5, 0.5, 0.5, 1)
_OutlineColorMap("Outline Color Map", 2D) = "white" {}
[ToggleUI] _AlbedoAffectOutline("Albedo Affect Outline", Float) = 1
[ToggleUI] _SkyColorAffectOutline("Sky Color Affect Outline", Float) = 1
_SkyColorIntensity("Sky Color Intensity", Range(0, 5)) = 1
_OutlineFadeIn("Outline Fade In", Float) = 50
_OutlineFadeOut("Outline Fade Out", Float) = 100
[ToggleUI] _UseSmoothedNormal("Use Smoothed Normal", Float) = 0
//TODO: End Section
[Toggle(_)] _Cast_Hair_Shadow("CastHairShadow", Float) = 0
[HideInInspector] _utsTechnique("Technique", int) = 0 //DWF
[HideInInspector] _AutoRenderQueue("Automatic Render Queue ", int) = 1
[Enum(OFF, 0, StencilOut, 1, StencilMask, 2)] _StencilMode("StencilMode", int) = 0
[Enum(Off, 0, StencilOut, 1, StencilMask, 2)] _StencilMode("StencilMode", int) = 0
// these are set in UniversalToonGUI.cs in accordance with _StencilMode
_StencilComp("Stencil Comparison", Float) = 8
_StencilNo("Stencil No", Float) = 1
_StencilOpPass("Stencil Operation", Float) = 0
_StencilOpFail("Stencil Operation", Float) = 0
[Enum(OFF, 0, ON, 1, ] _TransparentEnabled("Transparent Mode", int) = 0
// DoubleShadeWithFeather
// 0:_IS_CLIPPING_OFF 1:_IS_CLIPPING_MODE 2:_IS_CLIPPING_TRANSMODE
// ShadingGradeMap
// 0:_IS_TRANSCLIPPING_OFF 1:_IS_TRANSCLIPPING_ON
[Enum(OFF, 0, ON, 1, TRANSMODE, 2)] _ClippingMode("CliippingMode", int) = 0
[Enum(Off, 0, ON, 1, TRANSMODE, 2)] _ClippingMode("CliippingMode", int) = 0
[Enum(OFF, 0, FRONT, 1, BACK, 2)] _CullMode("Cull Mode", int) = 2 //OFF/FRONT/BACK
[Enum(OFF, 0, ONT, 1)] _ZWriteMode("ZWrite Mode", int) = 1 //OFF/ON
[Enum(OFF, 0, ONT, 1)] _ZOverDrawMode("ZOver Draw Mode", Float) = 0 //OFF/ON
[Enum(Off, 0, ONT, 1)] _ZWriteMode("ZWrite Mode", int) = 1 //OFF/ON
[Enum(Off, 0, ONT, 1)] _ZOverDrawMode("ZOver Draw Mode", Float) = 0 //OFF/ON
_SPRDefaultUnlitColorMask("SPRDefaultUnlit Path Color Mask", int) = 15
[Enum(OFF, 0, FRONT, 1, BACK, 2)] _SRPDefaultUnlitColMode("SPRDefaultUnlit Cull Mode", int) = 1 //OFF/FRONT/BACK
[Enum(Off, 0, FRONT, 1, BACK, 2)] _SRPDefaultUnlitColMode("SPRDefaultUnlit Cull Mode", int) = 1 //OFF/FRONT/BACK
// ClippingMask paramaters from Here.
_ClippingMask("ClippingMask", 2D) = "white" {}
//v.2.0.4
@@ -296,44 +396,17 @@ Shader "HDRP/Toon"
//v.2.0.5 : Clipping/TransClipping for SSAO Problems in PostProcessing Stack.
//If you want to go back the former SSAO results, comment out the below line.
[HideInInspector] _Color("Color", Color) = (1, 1, 1, 1)
//
[Toggle(_)] _Is_LightColor_Base("Is_LightColor_Base", Float) = 1
_1st_ShadeMap("1st_ShadeMap", 2D) = "white" {}
//v.2.0.5
[Toggle(_)] _Use_BaseAs1st("Use BaseMap as 1st_ShadeMap", Float) = 0
_1st_ShadeColor("1st_ShadeColor", Color) = (1, 1, 1, 1)
[Toggle(_)] _Is_LightColor_1st_Shade("Is_LightColor_1st_Shade", Float) = 1
_2nd_ShadeMap("2nd_ShadeMap", 2D) = "white" {}
//v.2.0.5
[Toggle(_)] _Use_1stAs2nd("Use 1st_ShadeMap as 2nd_ShadeMap", Float) = 0
_2nd_ShadeColor("2nd_ShadeColor", Color) = (1, 1, 1, 1)
[Toggle(_)] _Is_LightColor_2nd_Shade("Is_LightColor_2nd_Shade", Float) = 1
// _NormalMap("NormalMap", 2D) = "bump" {}
// _NormalMap("NormalMap", 2D) = "bump" {}
_BumpScale("Normal Scale", Range(0, 1)) = 1
[Toggle(_)] _Is_NormalMapToBase("Is_NormalMapToBase", Float) = 0
//v.2.0.4.4
[KeywordEnum(NORMAL, SDF)] _Shadow_Mode("Shadow MODE", Float) = 0
_SDFShadowTex("SDFShadowTex", 2D) = "white" {}
_SDFSmoothGamma("SDFSmoothGamma", Range(0.0, 0.1)) = 0.02
_SDFShadowLevel("SDFShadowLevel", Range(0.0, 1.0)) = 0.25
_SDFNoseHighlightCoef("SDFNoseHighlightCoef", Range(0.0, 5.0)) = 1.25
_SDFNoseHighlightSmoothRange("SDFNoseHighlightSmoothRange", Range(0.0, 0.1)) = 0.02
// Hair Shadow
[Toggle(_)] _Is_CastHairShadow("Is_CastHairShadow", Float) = 0
[Toggle(_)] _Is_ReceiveHairShadow("Is_ReceiveHairShadow", Float) = 0
_ShadowBias("ShadowBias", Range(0.0, 5.0)) = 0.0
[Toggle(_)] _Set_SystemShadowsToBase("Set_SystemShadowsToBase", Float) = 1
_Tweak_SystemShadowsLevel("Tweak_SystemShadowsLevel", Range(-0.5, 0.5)) = 0
// Eye Parallax
[Toggle(_)] _Is_EyeParallax("_Is_EyeParallax", Float) = 0
_EyeParallaxAmount("EyeParallaxAmount", Float) = 0.1
// Eyebrow Seethrough
[Togle(_)] _Is_HairBlendingTarget("_Is_HairBlendingTarget", Float) = 0
_HairBlendingFactor("EyeBrowBlendingFactor", Float) = 0.5
//v.2.0.6
@@ -341,17 +414,13 @@ Shader "HDRP/Toon"
_BaseShade_Feather("Base/Shade_Feather", Range(0.0001, 1)) = 0.0001
_ShadeColor_Step("ShadeColor_Step", Range(0, 1)) = 0
_1st2nd_Shades_Feather("1st/2nd_Shades_Feather", Range(0.0001, 1)) = 0.0001
[HideInInspector] _1st_ShadeColor_Step("1st_ShadeColor_Step", Range(0, 1)) = 0.5
[HideInInspector] _1st_ShadeColor_Feather("1st_ShadeColor_Feather", Range(0.0001, 1)) = 0.0001
[HideInInspector] _2nd_ShadeColor_Step("2nd_ShadeColor_Step", Range(0, 1)) = 0
[HideInInspector] _2nd_ShadeColor_Feather("2nd_ShadeColor_Feather", Range(0.0001, 1)) = 0.0001
//v.2.0.5
_StepOffset("Step_Offset (ForwardAdd Only)", Range(-0.5, 0.5)) = 0
[Toggle(_)] _Is_Filter_HiCutPointLightColor("PointLights HiCut_Filter (ForwardAdd Only)", Float) = 1
//
_Set_1st_ShadePosition("Set_1st_ShadePosition", 2D) = "white" {}
_Set_2nd_ShadePosition("Set_2nd_ShadePosition", 2D) = "white" {}
_ShadingGradeMap("ShadingGradeMap", 2D) = "white" {}
//v.2.0.6
_Tweak_ShadingGradeMapLevel("Tweak_ShadingGradeMapLevel", Range(-0.5, 0.5)) = 0
_BlurLevelSGM("Blur Level of ShadingGradeMap", Range(0, 10)) = 0
@@ -365,34 +434,11 @@ Shader "HDRP/Toon"
_HighColor_Power("HighColor_Power", Range(0, 1)) = 0
[Toggle(_)] _Is_SpecularToHighColor("Is_SpecularToHighColor", Float) = 0
[Toggle(_)] _Is_BlendAddToHiColor("Is_BlendAddToHiColor", Float) = 0
[Toggle(_)] _Is_BlendAddToRimColor("Is_BlendAddToRimColor", Float) = 1
[Enum(Multiply,0, Add,1)] _Is_BlendAddToRimColor("Is_BlendAddToRimColor", Float) = 1
[Toggle(_)] _Is_UseTweakHighColorOnShadow("Is_UseTweakHighColorOnShadow", Float) = 0
_TweakHighColorOnShadow("TweakHighColorOnShadow", Range(0, 1)) = 0
//HiColorMask
_Set_HighColorMask("Set_HighColorMask", 2D) = "white" {}
_Tweak_HighColorMaskLevel("Tweak_HighColorMaskLevel", Range(-1, 1)) = 0
[Toggle(_)] _RimLight("RimLight", Float) = 0
_RimLightColor("RimLightColor", Color) = (1, 1, 1, 1)
[Toggle(_)] _Is_LightColor_RimLight("Is_LightColor_RimLight", Float) = 1
[Toggle(_)] _Is_NormalMapToRimLight("Is_NormalMapToRimLight", Float) = 0
_RimLight_Strength("RimLight_Strength", Range(0, 10)) = 1
_RimLight_Power("RimLight_Power", Range(0, 1)) = 0.1
_RimLight_InsideMask("RimLight_InsideMask", Range(0.0001, 1)) = 0.0001
[Toggle(_)] _RimLight_FeatherOff("RimLight_FeatherOff", Float) = 0
//RimLight
[Toggle(_)] _LightDirection_MaskOn("LightDirection_MaskOn", Float) = 0
_Tweak_LightDirection_MaskLevel("Tweak_LightDirection_MaskLevel", Range(0, 0.5)) = 0
[Toggle(_)] _Add_Antipodean_RimLight("Add_Antipodean_RimLight", Float) = 0
_Ap_RimLightColor("Ap_RimLightColor", Color) = (1, 1, 1, 1)
[Toggle(_)] _Is_LightColor_Ap_RimLight("Is_LightColor_Ap_RimLight", Float) = 1
_Ap_RimLight_Power("Ap_RimLight_Power", Range(0, 1)) = 0.1
[Toggle(_)] _Ap_RimLight_FeatherOff("Ap_RimLight_FeatherOff", Float) = 0
//RimLightMask
_Set_RimLightMask("Set_RimLightMask", 2D) = "white" {}
_Tweak_RimLightMaskLevel("Tweak_RimLightMaskLevel", Range(-1, 1)) = 0
//
[Toggle(_)] _MatCap("MatCap", Float) = 0
_MatCap_Sampler("MatCap_Sampler", 2D) = "black" {}
//v.2.0.6
_BlurLevelMatcap("Blur Level of MatCap_Sampler", Range(0, 10)) = 0
_MatCapColor("MatCapColor", Color) = (1, 1, 1, 1)
@@ -414,21 +460,10 @@ Shader "HDRP/Toon"
[Toggle(_)] _Inverse_MatcapMask("Inverse_MatcapMask", Float) = 0
//v.2.0.5
[Toggle(_)] _Is_Ortho("Orthographic Projection for MatCap", Float) = 0
//// Angel Rings
[Toggle(_)] _AngelRing("AngelRing", Float) = 0
_AngelRing_Sampler("AngelRing_Sampler", 2D) = "black" {}
_AngelRing_Color("AngelRing_Color", Color) = (1, 1, 1, 1)
[Toggle(_)] _Is_LightColor_AR("Is_LightColor_AR", Float) = 1
_AR_Intensity("AR_Intensity", Range(0, 100)) = 1
_AR_ShadowIntensity("AR_Intensity", Range(0, 1)) = 0
_AR_OffsetU("AR_OffsetU", Range(0, 0.5)) = 0
_AR_OffsetV("AR_OffsetV", Range(0, 1)) = 0.3
[Toggle(_)] _ARSampler_AlphaOn("ARSampler_AlphaOn", Float) = 0
//
//v.2.0.7 Emissive
[KeywordEnum(SIMPLE, ANIMATION)] _EMISSIVE("EMISSIVE MODE", Float) = 0
_Emissive_Tex("Emissive_Tex", 2D) = "white" {}
[HDR]_Emissive_Color("Emissive_Color", Color) = (0, 0, 0, 1)
_Base_Speed("Base_Speed", Float) = 0
_Scroll_EmissiveU("Scroll_EmissiveU", Range(-1, 1)) = 0
_Scroll_EmissiveV("Scroll_EmissiveV", Range(-1, 1)) = 0
@@ -441,29 +476,7 @@ Shader "HDRP/Toon"
[HDR]_ViewShift("ViewSift", Color) = (0, 0, 0, 1)
[Toggle(_)] _Is_ViewCoord_Scroll("Is_ViewCoord_Scroll", Float) = 0
//
//Outline
[KeywordEnum(NML, POS)] _OUTLINE("OUTLINE MODE", Float) = 0
_Outline_Width("Outline_Width", Float) = 0
_Farthest_Distance("Farthest_Distance", Float) = 100
_Nearest_Distance("Nearest_Distance", Float) = 0.5
_Outline_Sampler("Outline_Sampler", 2D) = "white" {}
_Outline_Color("Outline_Color", Color) = (0.5, 0.5, 0.5, 1)
[Toggle(_)] _Is_BlendBaseColor("Is_BlendBaseColor", Float) = 0
// ClippingMask paramaters from Here.
[HideInInspector]_Cutoff("Alpha cutoff", Range(0, 1)) = 0.5
// ClippingMask paramaters to here.
//v.2.0.4
[Toggle(_)] _Is_OutlineTex("Is_OutlineTex", Float) = 0
_OutlineTex("OutlineTex", 2D) = "white" {}
//Offset parameter
_Offset_Z("Offset_Camera_Z", Float) = 0
//v.2.0.4.3 Baked Nrmal Texture for Outline
[Toggle(_)] _Is_BakedNormal("Is_BakedNormal", Float) = 0
_BakedNormal("Baked Normal for Outline", 2D) = "white" {}
_UseSmoothedNormal("Use Smoothed Normal", Float) = 0
//GI Intensity
_ID_Intensity("GI_Intensity", Range(0, 1)) = 1
_IR_Intensity("GI_Intensity", Range(0, 1)) = 1
_Light_Intensity_Multiplier("Light_Intensity_Multiplier" , Range(0, 1)) = 0.25
//For VR Chat under No effective light objects
_Unlit_Intensity("Unlit_Intensity", Range(0, 4)) = 0
@@ -499,14 +512,11 @@ Shader "HDRP/Toon"
[Toggle(_)] _RimLightOverridden("Channel mask", Float) = 0
_RimLightMaskColor("Channel mask color", Color) = (1, 0, 1, 1)
[Toggle(_)] _OutlineVisible("Channel mask", Float) = 1
[Toggle(_)] _OutlineOverridden("Channel mask", Float) = 0
_OutlineMaskColor("Channel mask color", Color) = (0, 0, 0, 1)
[Toggle(_)] _ComposerMaskMode("", Float) = 0
[Enum(None, 0, BaseColor, 1, FirstShade, 2, SecondShade,3, Highlight, 4, AngelRing, 5, RimLight, 6)] _ClippingMatteMode("Clipping Matte Mode", int) = 0
[HideInInspector] emissive("to avoid srp batcher error", Color)= (0, 0, 0, 1) //
[KeywordEnum(NONE, SINGLE, FULL)] _Light_Loop_Mode ("Light Loop Mode", Float) = 2
//
// to here parameters for UTS>
}
@@ -574,7 +584,7 @@ Shader "HDRP/Toon"
// variable declaration
//-------------------------------------------------------------------------------------
#include "UtsHdrpProperties.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Properties/UtsHdrpProperties.hlsl"
// TODO:
// Currently, Lit.hlsl and LitData.hlsl are included for every pass. Split Lit.hlsl in two:
@@ -652,6 +662,21 @@ Shader "HDRP/Toon"
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
#pragma multi_compile _ LIGHT_LAYERS
#pragma shader_feature_local_fragment _PBR_MODE_OFF
#pragma shader_feature_local_fragment _MASKMAP
#pragma shader_feature_local_fragment _NORMALMAP
#pragma shader_feature_local_fragment _ANISOTROPYMAP
#pragma shader_feature_local_fragment _SPECULARCOLORMAP
#pragma shader_feature_local_fragment _EMISSIVE_COLOR_MAP
#if _PBR_MODE_OFF
#undef _MASKMAP
#undef _ANISOTROPYMAP
#undef _SPECULARCOLORMAP
#endif
#ifndef DEBUG_DISPLAY
// When we have alpha test, we will force a depth prepass so we always bypass the clip instruction in the GBuffer
// Don't do it with debug display mode as it is possible there is no depth prepass in this case
@@ -669,7 +694,7 @@ Shader "HDRP/Toon"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/ShaderPass/UtsShaderPassGBuffer.hlsl"
#pragma vertex Vert
#pragma fragment Frag
@@ -897,11 +922,11 @@ Shader "HDRP/Toon"
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
// Supported shadow modes per light type
#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
#define PUNCTUAL_SHADOW_MEDIUM
#define DIRECTIONAL_SHADOW_MEDIUM
#define AREA_SHADOW_MEDIUM
#define USE_CLUSTERED_LIGHTLIST // There is not FPTL lighting when using transparent
#define AREA_SHADOW_LOW
#define SHADERPASS SHADERPASS_FORWARD
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
@@ -938,9 +963,9 @@ Shader "HDRP/Toon"
Name "ForwardOnly"
Tags { "LightMode" = "ForwardOnly" }
ZWrite[_ZWriteMode]
ZWrite [_ZWriteMode]
ZTest [_ZTestMode]
Cull[_CullMode]
Cull [_CullMode]
Blend SrcAlpha OneMinusSrcAlpha
Stencil {
@@ -964,20 +989,19 @@ Shader "HDRP/Toon"
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
#pragma multi_compile SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
// Supported shadow modes per light type
#pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
#pragma multi_compile MATERIAL_TYPE_STANDARD MATERIAL_TYPE_FRONT_HAIR MATERIAL_TYPE_FACE MATERIAL_TYPE_EYE
#pragma multi_compile _PBR_Mode_OFF _PBR_Mode_ST _PBR_Mode_ANISO _PBR_Mode_KK _PBR_Mode_TOON
#define LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
//#pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
#define AREA_SHADOW_LOW
#pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
//#pragma multi_compile_fragment PUNCTUAL_SHADOW_LOW PUNCTUAL_SHADOW_MEDIUM PUNCTUAL_SHADOW_HIGH
//#pragma multi_compile_fragment DIRECTIONAL_SHADOW_LOW DIRECTIONAL_SHADOW_MEDIUM DIRECTIONAL_SHADOW_HIGH
//#pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH
#pragma multi_compile PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
#define SHADERPASS SHADERPASS_FORWARD
// In case of opaque we don't want to perform the alpha test, it is done in depth prepass and we use depth equal for ztest (setup from UI)
// Don't do it with debug display mode as it is possible there is no depth prepass in this case
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(DEBUG_DISPLAY)
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
#endif
#pragma shader_feature _ _SHADINGGRADEMAP
// used in ShadingGradeMap
#pragma shader_feature _IS_TRANSCLIPPING_OFF _IS_TRANSCLIPPING_ON
#pragma shader_feature _IS_ANGELRING_OFF _IS_ANGELRING_ON
@@ -988,29 +1012,55 @@ Shader "HDRP/Toon"
// controlling mask rendering
#pragma shader_feature _ _IS_CLIPPING_MATTE
#pragma shader_feature _EMISSIVE_SIMPLE _EMISSIVE_ANIMATION
//Probe volume
#pragma multi_compile PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
#pragma shader_feature ENABLE_UTS_HAIR_SHAOW
#pragma shader_feature ENABLE_UTS_HAIR_BLENDING
#pragma shader_feature_local _MASKMAP
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local _ANISOTROPYMAP
#pragma shader_feature_local _SPECULARCOLORMAP
#pragma shader_feature_local_fragment _SHADING_MODE_STANDARD _SHADING_MODE_SDF
#pragma shader_feature_local_fragment _MATERIAL_TYPE_STANDARD _MATERIAL_TYPE_FRONTHAIR _MATERIAL_TYPE_FACE _MATERIAL_TYPE_EYE
#pragma shader_feature_local_fragment _PBR_MODE_OFF _PBR_MODE_STANDARD _PBR_MODE_ANISOTROPY _PBR_MODE_HAIR _PBR_MODE_TOON
#pragma shader_feature_local _SDFShadow
#pragma shader_feature_local _RECEIVE_HAIR_SHADOW
#pragma shader_feature_local_fragment _USE_SHADING_RAMP_MAP_ON
#pragma shader_feature_local_fragment _RECEIVE_LIGHT_SHADOW_ON
#pragma shader_feature_local_fragment _RECEIVE_SCREEN_SPACE_SHADOW_ON
#pragma shader_feature_local_fragment _RECEIVE_HAIR_SHADOW_ON
#pragma shader_feature_local_fragment _INDIRECT_DIFFUSE_MODE_OFF _INDIRECT_DIFFUSE_MODE_IBL _INDIRECT_DIFFUSE_MODE_MATCAP _INDIRECT_DIFFUSE_MODE_RAMP
#pragma shader_feature_local_fragment _INDIRECT_SPECULAR_MODE_OFF _INDIRECT_SPECULAR_MODE_IBL _INDIRECT_SPECULAR_MODE_MATCAP
#pragma shader_feature_local_fragment _SCREEN_SPACE_RIM_LIGHT_ON
#pragma shader_feature_local_fragment _LIGHT_BASE_RIM_LIGHT_ON
#pragma shader_feature_local_fragment _SHADING_RAMP_MASK_MAP
#pragma shader_feature_local_fragment _MASKMAP
#pragma shader_feature_local_fragment _NORMALMAP
#pragma shader_feature_local_fragment _ANISOTROPYMAP
#pragma shader_feature_local_fragment _SPECULARCOLORMAP
#pragma shader_feature_local_fragment _EMISSIVE_COLOR_MAP
#pragma shader_feature_local_fragment _OUTLINECOLORMAP
#define PUNCTUAL_SHADOW_MEDIUM
#define DIRECTIONAL_SHADOW_MEDIUM
#define AREA_SHADOW_MEDIUM
#ifndef SHADER_STAGE_FRAGMENT
#define SHADOW_LOW
#define USE_FPTL_LIGHTLIST
#endif
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(DEBUG_DISPLAY)
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
#endif
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
#ifdef DEBUG_DISPLAY
# if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
#include "DebugDisplay.hlsl"
# else
#include "DebugDisplayHDRP7.hlsl"
# endif
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsCommon.hlsl"
#endif
// The light loop (or lighting architecture) is in charge to:
@@ -1025,19 +1075,16 @@ Shader "HDRP/Toon"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsHead.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl"
#ifdef DEBUG_DISPLAY
# if (SHADER_LIBRARY_VERSION_MAJOR >= 10)
#include "ShaderPassForward.hlsl"
# else
#include "ShaderPassForwardHDRP7.hlsl"
# endif
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/ShaderPass/ShaderPassForward.hlsl"
#else
#include "UtsLightLoop.hlsl"
#include "ShaderPassForwardUTS.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Lighting/UtsLightLoop.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/ShaderPass/UtsShaderPassForward.hlsl"
#endif
#pragma vertex Vert
@@ -1083,8 +1130,6 @@ Shader "HDRP/Toon"
HLSLPROGRAM
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
// enable dithering LOD crossfade
#pragma multi_compile _ LOD_FADE_CROSSFADE
#define SHADERPASS SHADERPASS_CONSTANT
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
@@ -1105,7 +1150,7 @@ Shader "HDRP/Toon"
Tags { "LightMode" = "Outline" }
Cull Front
Blend SrcAlpha OneMinusSrcAlpha
Blend Off
HLSLPROGRAM
@@ -1114,10 +1159,7 @@ Shader "HDRP/Toon"
#define SHADERPASS SHADERPASS_FORWARD
#define SHADOW_LOW
#define LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
#pragma multi_compile _IS_OUTLINE_CLIPPING_NO _IS_OUTLINE_CLIPPING_YES
#pragma multi_compile _OUTLINE_NML _OUTLINE_POS
#pragma shader_feature _ _IS_CLIPPING_MATTE
#define _REQUIRE_UV2
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
@@ -1145,8 +1187,8 @@ Shader "HDRP/Toon"
#include "HDRPToonHead.hlsl"
#include "HDRPToonOutline.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsHead.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/ShaderPass/HDRPToonOutline.hlsl"
#pragma vertex Vert
#pragma fragment Frag
@@ -1206,8 +1248,8 @@ Shader "HDRP/Toon"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
#endif
#include "HDRPToonHead.hlsl"
#include "HDRPToonHairBlending.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsHead.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/ShaderPass/HDRPToonHairBlending.hlsl"
#pragma vertex Vert
#pragma fragment Frag
@@ -1425,5 +1467,6 @@ Shader "HDRP/Toon"
}
}
CustomEditor "UnityEditor.Rendering.Toon.UTS3GUI"
//CustomEditor "UnityEditor.Rendering.Toon.UTS3GUI"
CustomEditor "Misaki.HdrpToon.Editor.UTSShaderGUI"
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 98998b9942068044ab680ee5e6485837
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3642d3111f8bccb4180d12b99fa6de71
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -5,6 +5,8 @@
#define inverselerp(a, b, x) saturate(((x) - (a)) / ((b) - (a)))
#define APPLY_WEIGHT(x, y, t) lerp(x, x * y, t)
float2 GetWHRatio()
{
return float2(_ScreenParams.y / _ScreenParams.x, 1);
@@ -13,12 +15,112 @@ float2 GetWHRatio()
float StepAntiAliasing(float x, float y)
{
float v = x - y;
return saturate(v / fwidth(v));//fwidth(x) = abs(ddx(x) + ddy(x))
return saturate(v / fwidth(v) + HALF_MIN); //fwidth(x) = abs(ddx(x) + ddy(x))
}
float Remap(float In, float2 InMinMax, float2 OutMinMax)
{
return OutMinMax.x + (In - InMinMax.x) * (OutMinMax.y - OutMinMax.x) / (InMinMax.y - InMinMax.x);
}
float3 ToonMaping(float3 x)
{
x = x * (2.51 * x + 0.03) / (x * (2.43 * x + 0.59) + 0.14);
return x;
}
float3 GetSmoothedWorldNormal(float2 uv, float3x3 t_tbn)
{
float3 normal = float3(uv, 0);
normal.z = sqrt(1.0 - saturate(dot(normal.xy, normal.xy)));
return mul(normal, t_tbn);
}
float3 UtsComputeDiffuseColor(float3 baseColor, float metallic, float min)
{
#if _PBR_MODE_OFF
return baseColor;
#else
return baseColor * (max(min, 1.0 - metallic));
#endif
}
float3 UtsComputeDiffuseColor(float3 baseColor, float metallic)
{
return UtsComputeDiffuseColor(baseColor, metallic, 0.0);
}
#define SampleRampSignalLine(texture, u) (SAMPLE_TEXTURE2D_LOD(texture, s_linear_clamp_sampler, float2(u, 0.5), 0))
// Exposure
float3 ApplyCurrentExposureMultiplier(float3 color)
{
return color * lerp(GetCurrentExposureMultiplier(), 1, _ToonIgnoreExposureMultiplier);
}
float3 ConvertFromEV100(float3 EV100)
{
float3 value = pow(2, EV100) * 2.5f;
return value;
}
float3 ConvertToEV100(float3 value)
{
return log2(value * 0.4f);
}
float WeightSample(PositionInputs positionInput)
{
// Center-weighted
const float2 kCenter = _ScreenParams.xy * 0.5;
const float weight = pow(length((kCenter.xy - positionInput.positionSS.xy) / _ScreenParams.xy), 1.0);
return 1.0 - saturate(weight);
}
float3 ApplyCompensation(float3 originalColor)
{
float3 ev100_Color = ConvertToEV100(originalColor) + _ToonEvAdjustmentCompensation * 0.5f;
float3 resultColor = max(0, ConvertFromEV100(ev100_Color));
return resultColor;
}
float3 GetExposureAdjustedColor(float3 originalColor)
{
if (_ToonEvAdjustmentCurve != 0)
{
float3 ev100_Color = ConvertToEV100(originalColor);
ev100_Color = clamp(ev100_Color, _ToonEvAdjustmentValueMin, _ToonEvAdjustmentValueMax);
float3 ev100_remap = (ev100_Color - _ToonEvAdjustmentValueMin) * (128 - 1) / (_ToonEvAdjustmentValueMax - _ToonEvAdjustmentValueMin);
ev100_remap = clamp(ev100_remap, 0.0, 127.0);
int3 ev100_idx = (int3)ev100_remap;
float3 ev100_lerp = ev100_remap - ev100_idx;
float3 ev100_remapped;
ev100_remapped.r = _ToonEvAdjustmentValueArray[ev100_idx.r] + (_ToonEvAdjustmentValueArray[ev100_idx.r + 1] - _ToonEvAdjustmentValueArray[ev100_idx.r]) * ev100_lerp.r;
ev100_remapped.g = _ToonEvAdjustmentValueArray[ev100_idx.g] + (_ToonEvAdjustmentValueArray[ev100_idx.g + 1] - _ToonEvAdjustmentValueArray[ev100_idx.g]) * ev100_lerp.g;
ev100_remapped.b = _ToonEvAdjustmentValueArray[ev100_idx.b] + (_ToonEvAdjustmentValueArray[ev100_idx.b + 1] - _ToonEvAdjustmentValueArray[ev100_idx.b]) * ev100_lerp.b;
float3 resultColor = ConvertFromEV100(ev100_remapped);
return resultColor;
}
else // else is neccessary to avoid warrnings.
{
return originalColor;
}
}
void ApplyExposureAdjustment(inout float3 color)
{
color = GetExposureAdjustedColor(color);
color = ApplyCompensation(color);
}
// ----------------------------------------------------------------------------
// Transform
// ----------------------------------------------------------------------------
@@ -28,7 +130,7 @@ float3 ProjectOnPlane(float3 vec, float3 normal)
return vec - normal * dot(vec, normal);
}
float2 Rotate_UV(float2 _uv, float _radian, float2 _piv, float _time)
float2 RotateUV(float2 _uv, float _radian, float2 _piv, float _time)
{
float RotateUV_ang = _radian;
float RotateUV_cos = cos(_time * RotateUV_ang);
@@ -141,6 +243,4 @@ float3 GetWorldPosFromDepthBuffer(float2 clipPos01, float cameraDepth)
return mul(unity_CameraToWorld, float4(localInvertDepthDirHD, 1.0)).xyz;
}
#endif

View File

@@ -0,0 +1,586 @@
#ifndef UCTS_HDRP_INCLUDED
#define UCTS_HDRP_INCLUDED
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsCommon.hlsl"
#define UTS_LAYER_VISIBILITY
#define FP_BUFFER 1
#if _PBR_MODE_OFF
#undef _MASKMAP
#undef _ANISOTROPYMAP
#undef _SPECULARCOLORMAP
#endif
#if defined(UNITY_PASS_PREPASSBASE) || defined(UNITY_PASS_DEFERRED) || defined(UNITY_PASS_SHADOWCASTER)
#undef FOG_LINEAR
#undef FOG_EXP
#undef FOG_EXP2
#endif
#define Uts_ColorSpaceDielectricSpec half4(0.04, 0.04, 0.04, 1.0 - 0.04)
struct UTSSurfaceData
{
uint surfaceFeatures;
real3 baseColor;
real3 firstShadingColor;
real3 secondShadingColor;
real alpha;
float3 normalWS;
real perceptualSmoothness;
real metallic;
real specularOcclusion;
real ambientOcclusion;
real3 specularColor;
float3 geomNormalWS;
float3 tangentWS;
real4 subsurfaceColor;
real anisotropy;
};
struct UtsBSDFData
{
uint surfaceFeatures;
real3 diffuseColor;
real3 firstShadingDiffuseColor;
real3 secondShadingDiffuseColor;
real3 fresnel0;
real fresnel90;
real reflectivity;
real ambientOcclusion;
real specularOcclusion;
real perceptualRoughness;
real3 subsurfaceColor;
float3 geomNormalWS;
float3 normalWS;
float3 tangentWS;
float3 bitangentWS;
real anisotropy;
real roughnessT;
real roughnessB;
};
UTSSurfaceData ConvertSurfaceDataToUTSSurfaceData(SurfaceData surfaceData)
{
UTSSurfaceData output;
ZERO_INITIALIZE(UTSSurfaceData, output);
output.surfaceFeatures = surfaceData.materialFeatures;
output.baseColor = surfaceData.baseColor;
output.alpha = 1.0;
output.normalWS = surfaceData.normalWS;
output.perceptualSmoothness = surfaceData.perceptualSmoothness;
output.metallic = surfaceData.metallic;
output.specularOcclusion = surfaceData.specularOcclusion;
output.ambientOcclusion = surfaceData.ambientOcclusion;
output.specularColor = surfaceData.specularColor;
output.geomNormalWS = surfaceData.geomNormalWS;
output.tangentWS = surfaceData.tangentWS;
output.subsurfaceColor.rgb = surfaceData.transmittanceColor;
output.subsurfaceColor.a = surfaceData.subsurfaceMask;
output.anisotropy = surfaceData.anisotropy;
return output;
}
UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V)
{
// Not zero initialized to make sure all fields are set.
UTSSurfaceData output;
output.surfaceFeatures = _SurfaceFeatures;
float4 mainTexture = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
output.baseColor = mainTexture.rgb * _BaseColor.rgb;
output.alpha = mainTexture.a;
#if _USE_SHADING_RAMP_MAP_ON
output.firstShadingColor = 0.0;
output.secondShadingColor = 0.0;
#else
float4 firstShadingTexture = SAMPLE_TEXTURE2D(_1stShadeColorMap, sampler_BaseColorMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
output.firstShadingColor = lerp(firstShadingTexture.rgb, mainTexture.rgb, _UseBaseAs1st) * _1stShadeColor.rgb;
#if _SHADING_MODE_STANDARD
float4 secondShadingTexture = SAMPLE_TEXTURE2D(_2ndShadeColorMap, sampler_BaseColorMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
output.secondShadingColor = lerp(secondShadingTexture.rgb, output.firstShadingColor, _Use1stAs2nd) * _2ndShadeColor.rgb;
#else
output.secondShadingColor = 0.0;
#endif
#endif
float4 normalLocal = float4(0, 0, 1.0, 1.0);
#if _NORMALMAP
if (_Use_SSSLut)
{
normalLocal = SAMPLE_TEXTURE2D_LOD(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap), _SSSIntensity);
}
else
{
normalLocal = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
normalLocal.rgb = UnpackNormalScale(normalLocal, _NormalScale);
}
#endif
float3 normalWS = normalize(mul(normalLocal.rgb, input.tangentToWorld));
#if _PBR_MODE_OFF
float smoothness = 0.0;
float metallic = 0.0;
#else
float smoothness = _Smoothness;
float metallic = _Metallic;
#endif
float ao = 1.0;
float3 specularColor = 1;
float anisotropy = 0;
#ifdef _MASKMAP
float4 _MaskMap_var = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
metallic = _MaskMap_var.x;
metallic = lerp(_MetallicRemapMin, _MetallicRemapMax, metallic);
ao = _MaskMap_var.y;
ao = lerp(_AORemapMin, _AORemapMax, ao);
smoothness = _MaskMap_var.w;
smoothness = lerp(_SmoothnessRemapMin, _SmoothnessRemapMax, smoothness);
#endif
#ifdef _ANISOTROPYMAP
anisotropy = SAMPLE_TEXTURE2D(_AnisotropyMap, sampler_AnisotropyMap, TRANSFORM_TEX(input.texCoord0, _AnisotropyMap)).r;
#if _PBR_Mode_KK
anisotropy += _Anisotropy - 0.5;
#else
anisotropy *= _Anisotropy;
#endif
#else
anisotropy = 1.0;
anisotropy *= _Anisotropy;
#endif
#ifdef _PBR_Mode_KK
metallic = 0.0;
smoothness *=_BSDFContribution;
#endif
#ifdef _PBR_Mode_TOON
#ifdef _SPECULARCOLORMAP
specularColor = SAMPLE_TEXTURE2D(_SpecularColorMap, sampler_SpecularColorMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)).rgb * _SpecularColor;
#endif
specularColor = GetSpecularColor(output.baseColor, metallic);
#endif
output.metallic = metallic;
output.ambientOcclusion = ao;
output.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(dot(normalWS, V), ao, PerceptualRoughnessToRoughness(1 - smoothness));
output.perceptualSmoothness = smoothness;
output.normalWS = normalWS;
output.specularColor = specularColor;
output.geomNormalWS = input.tangentToWorld[2];
output.tangentWS = Orthonormalize(input.tangentToWorld[0].rgb, normalWS);
output.subsurfaceColor = SAMPLE_TEXTURE2D(_SSSLutMap, s_linear_clamp_sampler, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)) * _SSSIntensity;
output.anisotropy = anisotropy;
return output;
}
UtsBSDFData ConvertUTSSurfaceDataToUTSBSDFData(UTSSurfaceData surfaceData)
{
UtsBSDFData output;
output.surfaceFeatures = surfaceData.surfaceFeatures;
output.diffuseColor = UtsComputeDiffuseColor(surfaceData.baseColor, surfaceData.metallic, 0.05);
output.firstShadingDiffuseColor = UtsComputeDiffuseColor(surfaceData.firstShadingColor, surfaceData.metallic, 0.05);
output.secondShadingDiffuseColor = UtsComputeDiffuseColor(surfaceData.secondShadingColor, surfaceData.metallic, 0.05);
#if _PBR_MODE_OFF
output.fresnel0 = surfaceData.baseColor;
#else
output.fresnel0 = ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, 0.22);
#endif
output.fresnel90 = ComputeF90(output.fresnel0);
output.reflectivity = (1.0 - 0.22) * (1 - surfaceData.metallic);
output.ambientOcclusion = surfaceData.ambientOcclusion;
output.specularOcclusion = surfaceData.specularOcclusion;
output.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness);\
output.subsurfaceColor = surfaceData.subsurfaceColor.rgb * surfaceData.subsurfaceColor.a;
output.normalWS = surfaceData.normalWS;
output.geomNormalWS = surfaceData.geomNormalWS;
output.tangentWS = surfaceData.tangentWS;
output.bitangentWS = normalize(cross(surfaceData.normalWS, surfaceData.tangentWS));
output.anisotropy = surfaceData.anisotropy;
ConvertAnisotropyToRoughness(output.perceptualRoughness, surfaceData.anisotropy, output.roughnessT, output.roughnessB);
return output;
}
PreLightData GetPreLightData_UTS(float3 V, PositionInputs posInput, inout UtsBSDFData bsdfData)
{
PreLightData preLightData;
ZERO_INITIALIZE(PreLightData, preLightData);
float3 N = bsdfData.normalWS;
preLightData.NdotV = dot(N, V);
preLightData.iblPerceptualRoughness = bsdfData.perceptualRoughness;
float clampedNdotV = ClampNdotV(preLightData.NdotV);
// Handle IBL + area light + multiscattering.
// Note: use the not modified by anisotropy iblPerceptualRoughness here.
float specularReflectivity = 1.0;
#if _PBR_MODE_OFF
preLightData.diffuseFGD = 1.0;
preLightData.specularFGD = 1.0;
#else
GetPreIntegratedFGDGGXAndDisneyDiffuse(clampedNdotV, preLightData.iblPerceptualRoughness, bsdfData.fresnel0, bsdfData.fresnel90, preLightData.specularFGD, preLightData.diffuseFGD, specularReflectivity);
#endif
#ifdef LIT_USE_GGX_ENERGY_COMPENSATION
// Ref: Practical multiple scattering compensation for microfacet models.
// We only apply the formulation for metals.
// For dielectrics, the change of reflectance is negligible.
// We deem the intensity difference of a couple of percent for high values of roughness
// to not be worth the cost of another precomputed table.
// Note: this formulation bakes the BSDF non-symmetric!
preLightData.energyCompensation = 1.0 / specularReflectivity - 1.0;
#else
preLightData.energyCompensation = 0.0;
#endif // LIT_USE_GGX_ENERGY_COMPENSATION
float3 iblN;
#if _PBR_MODE_ANISOTROPY
float TdotV = dot(bsdfData.tangentWS, V);
float BdotV = dot(bsdfData.bitangentWS, V);
preLightData.partLambdaV = GetSmithJointGGXAnisoPartLambdaV(TdotV, BdotV, clampedNdotV, bsdfData.roughnessT, bsdfData.roughnessB);
// perceptualRoughness is use as input and output here
GetGGXAnisotropicModifiedNormalAndRoughness(bsdfData.bitangentWS, bsdfData.tangentWS, N, V, bsdfData.anisotropy, preLightData.iblPerceptualRoughness, iblN, preLightData.iblPerceptualRoughness);
#else
preLightData.partLambdaV = GetSmithJointGGXPartLambdaV(clampedNdotV, bsdfData.roughnessT);
iblN = N;
#endif
preLightData.iblR = reflect(-V, iblN);
// Area light
#ifdef USE_DIFFUSE_LAMBERT_BRDF
preLightData.ltcTransformDiffuse = k_identity3x3;
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_SSS_DIFFUSE_POWER))
ModifyLambertLTCTransformForDiffusePower(preLightData.ltcTransformDiffuse, GetDiffusePower(bsdfData.diffusionProfileIndex));
#else
preLightData.ltcTransformDiffuse = SampleLtcMatrix(bsdfData.perceptualRoughness, clampedNdotV, LTCLIGHTINGMODEL_DISNEY_DIFFUSE);
#endif
float perceptualRoughnessA = bsdfData.perceptualRoughness;
preLightData.ltcTransformSpecular[0] = SampleLtcMatrix(perceptualRoughnessA, clampedNdotV, LTCLIGHTINGMODEL_GGX);
// Construct a right-handed view-dependent orthogonal basis around the normal
preLightData.orthoBasisViewNormal = GetOrthoBasisViewNormal(V, N, preLightData.NdotV);
return preLightData;
}
void UtsClampRoughness(inout PreLightData preLightData, inout UtsBSDFData bsdfData, float minRoughness)
{
bsdfData.roughnessT = max(minRoughness, bsdfData.roughnessT);
bsdfData.roughnessB = max(minRoughness, bsdfData.roughnessB);
}
// Legacy for compatibility with existing shaders
inline bool IsGammaSpace()
{
#ifdef UNITY_COLORSPACE_GAMMA
return true;
#else
return false;
#endif
}
// normal should be normalized, w=1.0
half3 SHEvalLinearL0L1(half4 normal)
{
half3 x;
// Linear (L1) + constant (L0) polynomial terms
x.r = dot(unity_SHAr, normal);
x.g = dot(unity_SHAg, normal);
x.b = dot(unity_SHAb, normal);
return x;
}
// normal should be normalized, w=1.0
half3 SHEvalLinearL2(half4 normal)
{
half3 x1, x2;
// 4 of the quadratic (L2) polynomials
half4 vB = normal.xyzz * normal.yzzx;
x1.r = dot(unity_SHBr, vB);
x1.g = dot(unity_SHBg, vB);
x1.b = dot(unity_SHBb, vB);
// Final (5th) quadratic (L2) polynomial
half vC = normal.x * normal.x - normal.y * normal.y;
x2 = unity_SHC.rgb * vC;
return x1 + x2;
}
// normal should be normalized, w=1.0
// output in active color space
half3 ShadeSH9(half4 normal)
{
// Linear + constant polynomial terms
half3 res = SHEvalLinearL0L1(normal);
// Quadratic polynomials
res += SHEvalLinearL2(normal);
# ifdef UNITY_COLORSPACE_GAMMA
res = LinearToGammaSpace(res);
# endif
return res;
}
float3 DecodeLightProbe(float3 N) {
return ShadeSH9(float4(N, 1));
}
inline float GammaToLinearSpaceExact(float value)
{
if (value <= 0.04045F)
return value / 12.92F;
else if (value < 1.0F)
return pow((value + 0.055F) / 1.055F, 2.4F);
else
return pow(value, 2.2F);
}
inline float3 GammaToLinearSpace(float3 sRGB)
{
// Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h);
// Precise version, useful for debugging.
//return half3(GammaToLinearSpaceExact(sRGB.r), GammaToLinearSpaceExact(sRGB.g), GammaToLinearSpaceExact(sRGB.b));
}
inline float LinearToGammaSpaceExact(float value)
{
if (value <= 0.0F)
return 0.0F;
else if (value <= 0.0031308F)
return 12.92F * value;
else if (value < 1.0F)
return 1.055F * pow(value, 0.4166667F) - 0.055F;
else
return pow(value, 0.45454545F);
}
inline float3 LinearToGammaSpace(float3 linRGB)
{
linRGB = max(linRGB, float3(0.h, 0.h, 0.h));
// An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
return max(1.055h * pow(linRGB, 0.416666667h) - 0.055h, 0.h);
// Exact version, useful for debugging.
//return half3(LinearToGammaSpaceExact(linRGB.r), LinearToGammaSpaceExact(linRGB.g), LinearToGammaSpaceExact(linRGB.b));
}
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#define UNITY_FOG_COORDS(idx) UNITY_FOG_COORDS_PACKED(idx, float1)
#if (SHADER_TARGET < 30) || defined(SHADER_API_MOBILE)
// mobile or SM2.0: calculate fog factor per-vertex
#define UNITY_TRANSFER_FOG(o,outpos) UNITY_CALC_FOG_FACTOR((outpos).z); o.fogCoord.x = unityFogFactor
#else
// SM3.0 and PC/console: calculate fog distance per-vertex, and fog factor per-pixel
#define UNITY_TRANSFER_FOG(o,outpos) o.fogCoord.x = (outpos).z
#endif
#else
#define UNITY_FOG_COORDS(idx)
#define UNITY_TRANSFER_FOG(o,outpos)
#endif
#define UNITY_FOG_LERP_COLOR(col,fogCol,fogFac) col.rgb = lerp((fogCol).rgb, (col).rgb, saturate(fogFac))
#if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
#if (SHADER_TARGET < 30) || defined(SHADER_API_MOBILE)
// mobile or SM2.0: fog factor was already calculated per-vertex, so just lerp the color
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol) UNITY_FOG_LERP_COLOR(col,fogCol,(coord).x)
#else
// SM3.0 and PC/console: calculate fog factor and lerp fog color
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol) UNITY_CALC_FOG_FACTOR((coord).x); UNITY_FOG_LERP_COLOR(col,fogCol,unityFogFactor)
#endif
#else
#define UNITY_APPLY_FOG_COLOR(coord,col,fogCol)
#endif
#ifdef UNITY_PASS_FORWARDADD
#define UNITY_APPLY_FOG(coord,col) UNITY_APPLY_FOG_COLOR(coord,col,fixed4(0,0,0,0))
#else
#define UNITY_APPLY_FOG(coord,col) UNITY_APPLY_FOG_COLOR(coord,col,unity_FogColor)
#endif
#ifdef DIRECTIONAL
#define LIGHTING_COORDS(idx1,idx2) SHADOW_COORDS(idx1)
#define TRANSFER_VERTEX_TO_FRAGMENT(a) TRANSFER_SHADOW(a)
#define LIGHT_ATTENUATION(a) SHADOW_ATTENUATION(a)
#endif
// Transforms 2D UV by scale/bias property
//#define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw)
#define UCTS_TEXTURE2D(tex,name) SAMPLE_TEXTURE2D(tex,sampler##tex,TRANSFORM_TEX(name, tex));
inline float4 UnityObjectToClipPosInstanced(in float3 pos)
{
// return mul(UNITY_MATRIX_VP, mul(unity_ObjectToWorldArray[unity_InstanceID], float4(pos, 1.0)));
// todo. right?
return mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_M, float4(pos, 1.0)));
}
inline float4 UnityObjectToClipPosInstanced(float4 pos)
{
return UnityObjectToClipPosInstanced(pos.xyz);
}
#define UnityObjectToClipPos UnityObjectToClipPosInstanced
inline float3 UnityObjectToWorldNormal( in float3 norm )
{
#ifdef UNITY_ASSUME_UNIFORM_SCALING
return UnityObjectToWorldDir(norm);
#else
// mul(IT_M, norm) => mul(norm, I_M) => {dot(norm, I_M.col0), dot(norm, I_M.col1), dot(norm, I_M.col2)}
return normalize(mul(norm, (float3x3)UNITY_MATRIX_M));
#endif
}
// normal should be normalized, w=1.0
float3 SHEvalLinearL0L1 (float4 normal)
{
float3 x;
// Linear (L1) + constant (L0) polynomial terms
x.r = dot(unity_SHAr,normal);
x.g = dot(unity_SHAg,normal);
x.b = dot(unity_SHAb,normal);
return x;
}
// normal should be normalized, w=1.0
float3 SHEvalLinearL2 (float4 normal)
{
float3 x1, x2;
// 4 of the quadratic (L2) polynomials
float4 vB = normal.xyzz * normal.yzzx;
x1.r = dot(unity_SHBr,vB);
x1.g = dot(unity_SHBg,vB);
x1.b = dot(unity_SHBb,vB);
// Final (5th) quadratic (L2) polynomial
half vC = normal.x*normal.x - normal.y*normal.y;
x2 = unity_SHC.rgb * vC;
return x1 + x2;
}
// normal should be normalized, w=1.0
// output in active color space
float3 ShadeSH9 (float4 normal)
{
// Linear + constant polynomial terms
float3 res = SHEvalLinearL0L1 (normal);
// Quadratic polynomials
res += SHEvalLinearL2 (normal);
# ifdef UNITY_COLORSPACE_GAMMA
res = LinearToGammaSpace (res);
# endif
return res;
}
float3 SampleBakedGI_UTS(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap, bool needToIncludeAPV = false)
{
float3 bakeDiffuseLighting = float3(0, 0, 0);
float3 backBakeDiffuseLighting = float3(0, 0, 0);
float3 backNormalWS = float3(0, 0, 0);
#if !defined(_SURFACE_TYPE_TRANSPARENT) && (SHADERPASS != SHADERPASS_RAYTRACING_INDIRECT) && (SHADERPASS != SHADERPASS_RAYTRACING_GBUFFER)
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF
#if (SHADERPASS == SHADERPASS_GBUFER)
&& _IndirectDiffuseMode != INDIRECTDIFFUSEMODE_MIXED && _ReflectionsMode != REFLECTIONSMODE_MIXED
#endif
)
return bakeDiffuseLighting;
#endif
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
EvaluateLightmap(positionRWS, normalWS, backNormalWS, uvStaticLightmap, uvDynamicLightmap, bakeDiffuseLighting, backBakeDiffuseLighting);
#elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
if (needToIncludeAPV)
{
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(positionRWS), normalWS, backNormalWS, GetWorldSpaceNormalizeViewDir(positionRWS), 0.0, bakeDiffuseLighting, backBakeDiffuseLighting);
}
#else
EvaluateLightProbeBuiltin(positionRWS, normalWS, backNormalWS, bakeDiffuseLighting, backBakeDiffuseLighting);
#if defined(SHADER_STAGE_RAY_TRACING)
bakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
backBakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
#endif
#endif
return bakeDiffuseLighting;
}
float3 SampleBakedGI_UTS_OutLine(float3 positionRWS, float3 normalWS, float2 uvStaticLightmap, float2 uvDynamicLightmap)
{
float3 bakeDiffuseLighting = float3(0, 0, 0);
float3 backBakeDiffuseLighting = float3(0, 0, 0);
float3 backNormalWS = float3(0, 0, 0);
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
EvaluateLightmap(positionRWS, normalWS, backNormalWS, uvStaticLightmap, uvDynamicLightmap, bakeDiffuseLighting, backBakeDiffuseLighting);
#elif (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(positionRWS), normalWS, backNormalWS, GetWorldSpaceNormalizeViewDir(positionRWS), 0.0, bakeDiffuseLighting, backBakeDiffuseLighting);
#else
EvaluateLightProbeBuiltin(positionRWS, normalWS, backNormalWS, bakeDiffuseLighting, backBakeDiffuseLighting);
#if defined(SHADER_STAGE_RAY_TRACING)
bakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
backBakeDiffuseLighting *= _RayTracingAmbientProbeDimmer;
#endif
#endif
return bakeDiffuseLighting;
}
#endif //#ifndef UCTS_HDRP_INCLUDED

View File

@@ -0,0 +1,394 @@
#ifndef UTS_LIT_DATA
#define UTS_LIT_DATA
float UtsGetSurfaceData(FragInputs input, LayerTexCoord layerTexCoord, out SurfaceData surfaceData,
out float3 normalTS, out float3 bentNormalTS)
{
float3 detailNormalTS = float3(0.0, 0.0, 0.0);
float detailMask = 0.0;
#ifdef _DETAIL_MAP_IDX
detailMask = 1.0;
#ifdef _MASKMAP_IDX
detailMask = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).b;
#endif
float2 detailAlbedoAndSmoothness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_DetailMap), SAMPLER_DETAILMAP_IDX, ADD_IDX(layerTexCoord.details)).rb;
float detailAlbedo = detailAlbedoAndSmoothness.r * 2.0 - 1.0;
float detailSmoothness = detailAlbedoAndSmoothness.g * 2.0 - 1.0;
// Resample the detail map but this time for the normal map. This call should be optimize by the compiler
// We split both call due to trilinear mapping
detailNormalTS = SAMPLE_UVMAPPING_NORMALMAP_AG(ADD_IDX(_DetailMap), SAMPLER_DETAILMAP_IDX, ADD_IDX(layerTexCoord.details), ADD_IDX(_DetailNormalScale));
#endif
float4 color = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_BaseColorMap), ADD_ZERO_IDX(sampler_BaseColorMap),
ADD_IDX(layerTexCoord.base)).rgba * ADD_IDX(_BaseColor).rgba;
surfaceData.baseColor = color.rgb;
float alpha = 1.0f;
#ifdef DEBUG_DISPLAY
if (_DebugMipMapMode == DEBUGMIPMAPMODE_NONE)
#endif
{
alpha = color.a;
alpha = lerp(ADD_IDX(_AlphaRemapMin), ADD_IDX(_AlphaRemapMax), alpha);
}
#ifdef _DETAIL_MAP_IDX
// Goal: we want the detail albedo map to be able to darken down to black and brighten up to white the surface albedo.
// The scale control the speed of the gradient. We simply remap detailAlbedo from [0..1] to [-1..1] then perform a lerp to black or white
// with a factor based on speed.
// For base color we interpolate in sRGB space (approximate here as square) as it get a nicer perceptual gradient
float albedoDetailSpeed = saturate(abs(detailAlbedo) * ADD_IDX(_DetailAlbedoScale));
float3 baseColorOverlay = lerp(sqrt(surfaceData.baseColor), (detailAlbedo < 0.0) ? float3(0.0, 0.0, 0.0) : float3(1.0, 1.0, 1.0), albedoDetailSpeed * albedoDetailSpeed);
baseColorOverlay *= baseColorOverlay;
// Lerp with details mask
surfaceData.baseColor = lerp(surfaceData.baseColor, saturate(baseColorOverlay), detailMask);
#endif
surfaceData.specularOcclusion = 1.0; // Will be setup outside of this function
surfaceData.normalWS = float3(0.0, 0.0, 0.0);
// Need to init this to keep quiet the compiler, but this is overriden later (0, 0, 0) so if we forget to override the compiler may comply.
surfaceData.geomNormalWS = float3(0.0, 0.0, 0.0); // Not used, just to keep compiler quiet.
normalTS = ADD_IDX(GetNormalTS)(input, layerTexCoord, detailNormalTS, detailMask);
bentNormalTS = ADD_IDX(GetBentNormalTS)(input, layerTexCoord, normalTS, detailNormalTS, detailMask);
#if _PBR_MODE_OFF
surfaceData.perceptualSmoothness = 0.0;
#else
#if defined(_MASKMAP_IDX)
surfaceData.perceptualSmoothness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).a;
surfaceData.perceptualSmoothness = lerp(ADD_IDX(_SmoothnessRemapMin), ADD_IDX(_SmoothnessRemapMax), surfaceData.perceptualSmoothness);
#else
surfaceData.perceptualSmoothness = ADD_IDX(_Smoothness);
#endif
#endif
#ifdef _DETAIL_MAP_IDX
// See comment for baseColorOverlay
float smoothnessDetailSpeed = saturate(abs(detailSmoothness) * ADD_IDX(_DetailSmoothnessScale));
float smoothnessOverlay = lerp(surfaceData.perceptualSmoothness, (detailSmoothness < 0.0) ? 0.0 : 1.0, smoothnessDetailSpeed);
// Lerp with details mask
surfaceData.perceptualSmoothness = lerp(surfaceData.perceptualSmoothness, saturate(smoothnessOverlay), detailMask);
#endif
#if _PBR_MODE_OFF
surfaceData.metallic = 0.0;
surfaceData.ambientOcclusion = 1.0;
#else
// MaskMap is RGBA: Metallic, Ambient Occlusion (Optional), detail Mask (Optional), Smoothness
#ifdef _MASKMAP_IDX
surfaceData.metallic = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).r;
surfaceData.metallic = lerp(ADD_IDX(_MetallicRemapMin), ADD_IDX(_MetallicRemapMax), surfaceData.metallic);
surfaceData.ambientOcclusion = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_MaskMap), SAMPLER_MASKMAP_IDX, ADD_IDX(layerTexCoord.base)).g;
surfaceData.ambientOcclusion = lerp(ADD_IDX(_AORemapMin), ADD_IDX(_AORemapMax), surfaceData.ambientOcclusion);
#else
surfaceData.metallic = ADD_IDX(_Metallic);
surfaceData.ambientOcclusion = 1.0;
#endif
#endif
surfaceData.diffusionProfileHash = asuint(ADD_IDX(_DiffusionProfileHash));
surfaceData.subsurfaceMask = ADD_IDX(_SubsurfaceMask);
surfaceData.transmissionMask = ADD_IDX(_TransmissionMask);
#ifdef _SUBSURFACE_MASK_MAP_IDX
surfaceData.subsurfaceMask *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_SubsurfaceMaskMap), SAMPLER_SUBSURFACE_MASK_MAP_IDX, ADD_IDX(layerTexCoord.base)).r;
#endif
#ifdef _TRANSMISSION_MASK_MAP_IDX
surfaceData.transmissionMask *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_TransmissionMaskMap), SAMPLER_TRANSMISSION_MASK_MAP_IDX, ADD_IDX(layerTexCoord.base)).r;
#endif
#ifdef _THICKNESSMAP_IDX
surfaceData.thickness = SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_ThicknessMap), SAMPLER_THICKNESSMAP_IDX, ADD_IDX(layerTexCoord.base)).r;
surfaceData.thickness = ADD_IDX(_ThicknessRemap).x + ADD_IDX(_ThicknessRemap).y * surfaceData.thickness;
#else
surfaceData.thickness = ADD_IDX(_Thickness);
#endif
// This part of the code is not used in case of layered shader but we keep the same macro system for simplicity
#if !defined(LAYERED_LIT_SHADER)
// These static material feature allow compile time optimization
surfaceData.materialFeatures = MATERIALFEATUREFLAGS_LIT_STANDARD;
#ifdef _MATERIAL_FEATURE_SUBSURFACE_SCATTERING
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING;
#endif
#ifdef _MATERIAL_FEATURE_TRANSMISSION
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_TRANSMISSION;
#endif
#ifdef _MATERIAL_FEATURE_ANISOTROPY
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_ANISOTROPY;
#endif
#ifdef _MATERIAL_FEATURE_CLEAR_COAT
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT;
#endif
#ifdef _MATERIAL_FEATURE_IRIDESCENCE
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_IRIDESCENCE;
#endif
#ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR;
#endif
#ifdef _TANGENTMAP
#ifdef _NORMALMAP_TANGENT_SPACE_IDX // Normal and tangent use same space
// Tangent space vectors always use only 2 channels.
float3 tangentTS = UnpackNormalmapRGorAG(SAMPLE_UVMAPPING_TEXTURE2D(_TangentMap, sampler_TangentMap, layerTexCoord.base), 1.0);
surfaceData.tangentWS = TransformTangentToWorld(tangentTS, input.tangentToWorld);
#else // Object space
// Note: There is no such a thing like triplanar with object space normal, so we call directly 2D function
float3 tangentOS = UnpackNormalRGB(SAMPLE_TEXTURE2D(_TangentMapOS, sampler_TangentMapOS, layerTexCoord.base.uv), 1.0);
surfaceData.tangentWS = TransformObjectToWorldNormal(tangentOS);
#endif
#else
// Note we don't normalize tangentWS either with a tangentmap above or using the interpolated tangent from the TBN frame
// as it will be normalized later with a call to Orthonormalize():
surfaceData.tangentWS = input.tangentToWorld[0].xyz;
// The tangent is not normalize in tangentToWorld for mikkt. TODO: Check if it expected that we normalize with Morten. Tag: SURFACE_GRADIENT
#endif
#ifdef _ANISOTROPYMAP
surfaceData.anisotropy = SAMPLE_UVMAPPING_TEXTURE2D(_AnisotropyMap, sampler_AnisotropyMap, layerTexCoord.base).r;
#else
surfaceData.anisotropy = 1.0;
#endif
surfaceData.anisotropy *= ADD_IDX(_Anisotropy);
surfaceData.specularColor = _SpecularColor.rgb;
#ifdef _SPECULARCOLORMAP
surfaceData.specularColor *= SAMPLE_UVMAPPING_TEXTURE2D(_SpecularColorMap, sampler_SpecularColorMap, layerTexCoord.base).rgb;
#endif
#ifdef _MATERIAL_FEATURE_SPECULAR_COLOR
// Require to have setup baseColor
// Reproduce the energy conservation done in legacy Unity. Not ideal but better for compatibility and users can unchek it
surfaceData.baseColor *= _EnergyConservingSpecularColor > 0.0 ? (1.0 - Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b)) : 1.0;
#endif
#if HAS_REFRACTION
if (_EnableSSRefraction)
{
surfaceData.ior = _Ior;
surfaceData.transmittanceColor = _TransmittanceColor;
#ifdef _TRANSMITTANCECOLORMAP
surfaceData.transmittanceColor *= SAMPLE_UVMAPPING_TEXTURE2D(_TransmittanceColorMap, sampler_TransmittanceColorMap, ADD_IDX(layerTexCoord.base)).rgb;
#endif
surfaceData.atDistance = _ATDistance;
// Rough refraction don't use opacity. Instead we use opacity as a transmittance mask.
surfaceData.transmittanceMask = (1.0 - alpha);
alpha = 1.0;
}
else
{
surfaceData.ior = 1.0;
surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
surfaceData.atDistance = 1.0;
surfaceData.transmittanceMask = 0.0;
alpha = 1.0;
}
#else
surfaceData.ior = 1.0;
surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
surfaceData.atDistance = 1.0;
surfaceData.transmittanceMask = 0.0;
#endif
#ifdef _MATERIAL_FEATURE_CLEAR_COAT
surfaceData.coatMask = _CoatMask;
// To shader feature for keyword to limit the variant
surfaceData.coatMask *= SAMPLE_UVMAPPING_TEXTURE2D(ADD_IDX(_CoatMaskMap), ADD_ZERO_IDX(sampler_CoatMaskMap), ADD_IDX(layerTexCoord.base)).r;
#else
surfaceData.coatMask = 0.0;
#endif
#ifdef _MATERIAL_FEATURE_IRIDESCENCE
#ifdef _IRIDESCENCE_THICKNESSMAP
surfaceData.iridescenceThickness = SAMPLE_UVMAPPING_TEXTURE2D(_IridescenceThicknessMap, sampler_IridescenceThicknessMap, layerTexCoord.base).r;
surfaceData.iridescenceThickness = _IridescenceThicknessRemap.x + _IridescenceThicknessRemap.y * surfaceData.iridescenceThickness;
#else
surfaceData.iridescenceThickness = _IridescenceThickness;
#endif
surfaceData.iridescenceMask = _IridescenceMask;
surfaceData.iridescenceMask *= SAMPLE_UVMAPPING_TEXTURE2D(_IridescenceMaskMap, sampler_IridescenceMaskMap, layerTexCoord.base).r;
#else
surfaceData.iridescenceThickness = 0.0;
surfaceData.iridescenceMask = 0.0;
#endif
#else // #if !defined(LAYERED_LIT_SHADER)
// Mandatory to setup value to keep compiler quiet
// Layered shader material feature are define outside of this call
surfaceData.materialFeatures = 0;
// All these parameters are ignore as they are re-setup outside of the layers function
// Note: any parameters set here must also be set in GetSurfaceAndBuiltinData() layer version
surfaceData.tangentWS = float3(0.0, 0.0, 0.0);
surfaceData.anisotropy = 0.0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
surfaceData.iridescenceThickness = 0.0;
surfaceData.iridescenceMask = 0.0;
surfaceData.coatMask = 0.0;
// Transparency
surfaceData.ior = 1.0;
surfaceData.transmittanceColor = float3(1.0, 1.0, 1.0);
surfaceData.atDistance = 1000000.0;
surfaceData.transmittanceMask = 0.0;
#endif // #if !defined(LAYERED_LIT_SHADER)
return alpha;
}
void UtsGetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData,
out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS)
{
// Fix case 1210058. With Lit.shader / LayeredLit.shader we always have UV1. But in the case of some SpeedTree mesh, there is no stream sent
// and UV1 is corrupt when we use surface gradient. In case UV1 aren't required we set them to 0, so we ensure there is no garbage.
// When using lightmaps, the uv1 is always valid but we don't update _UVMappingMask.y to 1
// So when we are using them, we just need to keep the UVs as is.
#if !defined(LIGHTMAP_ON) && defined(SURFACE_GRADIENT)
input.texCoord1 = (_UVMappingMask.y + _UVDetailsMappingMask.y + _UVMappingMaskEmissive.y) > 0 ? input.texCoord1 : 0;
#endif
// Don't dither if displaced tessellation (we're fading out the displacement instead to match the next LOD)
#if !defined(SHADER_STAGE_RAY_TRACING) && !defined(_TESSELLATION_DISPLACEMENT)
#ifdef LOD_FADE_CROSSFADE // enable dithering LOD transition if user select CrossFade transition in LOD group
LODDitheringTransition(ComputeFadeMaskSeed(V, posInput.positionSS), unity_LODFade.x);
#endif
#endif
float3 doubleSidedConstants = GetDoubleSidedConstants();
ApplyDoubleSidedFlipOrMirror(input, doubleSidedConstants); // Apply double sided flip on the vertex normal
LayerTexCoord layerTexCoord;
ZERO_INITIALIZE(LayerTexCoord, layerTexCoord);
GetLayerTexCoord(input, layerTexCoord);
#if !defined(SHADER_STAGE_RAY_TRACING)
float depthOffset = ApplyPerPixelDisplacement(input, V, layerTexCoord);
#ifdef _DEPTHOFFSET_ON
ApplyDepthOffsetPositionInput(V, depthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput);
#endif
#else
float depthOffset = 0.0;
#endif
#if defined(_ALPHATEST_ON)
float alphaTex = SAMPLE_UVMAPPING_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, layerTexCoord.base).a;
alphaTex = lerp(_AlphaRemapMin, _AlphaRemapMax, alphaTex);
float alphaValue = alphaTex * _BaseColor.a;
// Perform alha test very early to save performance (a killed pixel will not sample textures)
#if SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_PREPASS
float alphaCutoff = _AlphaCutoffPrepass;
#elif SHADERPASS == SHADERPASS_TRANSPARENT_DEPTH_POSTPASS
float alphaCutoff = _AlphaCutoffPostpass;
#elif (SHADERPASS == SHADERPASS_SHADOWS) || (SHADERPASS == SHADERPASS_RAYTRACING_VISIBILITY)
float alphaCutoff = _UseShadowThreshold ? _AlphaCutoffShadow : _AlphaCutoff;
#else
float alphaCutoff = _AlphaCutoff;
#endif
GENERIC_ALPHA_TEST(alphaValue, alphaCutoff);
#endif
// We perform the conversion to world of the normalTS outside of the GetSurfaceData
// so it allow us to correctly deal with detail normal map and optimize the code for the layered shaders
float3 normalTS;
float3 bentNormalTS;
float3 bentNormalWS;
float alpha = UtsGetSurfaceData(input, layerTexCoord, surfaceData, normalTS, bentNormalTS);
// This need to be init here to quiet the compiler in case of decal, but can be override later.
surfaceData.geomNormalWS = input.tangentToWorld[2];
surfaceData.specularOcclusion = 1.0;
#ifdef DECAL_NORMAL_BLENDING
if (_EnableDecals)
{
#ifndef SURFACE_GRADIENT
normalTS = SurfaceGradientFromTangentSpaceNormalAndFromTBN(normalTS,
input.tangentToWorld[0], input.tangentToWorld[1]);
#endif
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, input, alpha);
ApplyDecalToSurfaceData(decalSurfaceData, input.tangentToWorld[2], surfaceData, normalTS);
}
GetNormalWS_SG(input, normalTS, surfaceData.normalWS, doubleSidedConstants);
#else
GetNormalWS(input, normalTS, surfaceData.normalWS, doubleSidedConstants);
#if HAVE_DECALS
if (_EnableDecals)
{
// Both uses and modifies 'surfaceData.normalWS'.
DecalSurfaceData decalSurfaceData = GetDecalSurfaceData(posInput, input, alpha);
ApplyDecalToSurfaceData(decalSurfaceData, input.tangentToWorld[2], surfaceData);
}
#endif
#endif
// Use bent normal to sample GI if available
#ifdef _BENTNORMALMAP
GetNormalWS(input, bentNormalTS, bentNormalWS, doubleSidedConstants);
#else
bentNormalWS = surfaceData.normalWS;
#endif
#if defined(DEBUG_DISPLAY)
#if !defined(SHADER_STAGE_RAY_TRACING)
// Mipmap mode debugging isn't supported with ray tracing as it relies on derivatives
if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE)
{
surfaceData.baseColor = GET_TEXTURE_STREAMING_DEBUG(posInput.positionSS, input.texCoord0);
surfaceData.metallic = 0;
}
#endif
// We need to call ApplyDebugToSurfaceData after filling the surfaceData and before filling builtinData
// as it can modify attribute use for static lighting
ApplyDebugToSurfaceData(input.tangentToWorld, surfaceData);
#endif
// By default we use the ambient occlusion with Tri-ace trick (apply outside) for specular occlusion.
// If user provide bent normal then we process a better term
#if defined(_SPECULAR_OCCLUSION_FROM_BENT_NORMAL_MAP)
// If we have bent normal and ambient occlusion, process a specular occlusion
surfaceData.specularOcclusion = GetSpecularOcclusionFromBentAO(V, bentNormalWS, surfaceData.normalWS, surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
// Don't do spec occ from Ambient if there is no mask mask
#elif defined(_MASKMAP) && !defined(_SPECULAR_OCCLUSION_NONE)
surfaceData.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(ClampNdotV(dot(surfaceData.normalWS, V)), surfaceData.ambientOcclusion, PerceptualSmoothnessToRoughness(surfaceData.perceptualSmoothness));
#endif
// This is use with anisotropic material
surfaceData.tangentWS = Orthonormalize(surfaceData.tangentWS, surfaceData.normalWS);
#if defined(_ENABLE_GEOMETRIC_SPECULAR_AA) && !defined(SHADER_STAGE_RAY_TRACING)
// Specular AA
#ifdef PROJECTED_SPACE_NDF_FILTERING
surfaceData.perceptualSmoothness = ProjectedSpaceGeometricNormalFiltering(surfaceData.perceptualSmoothness, input.tangentToWorld[2], _SpecularAAScreenSpaceVariance, _SpecularAAThreshold);
#else
surfaceData.perceptualSmoothness = GeometricNormalFiltering(surfaceData.perceptualSmoothness, input.tangentToWorld[2], _SpecularAAScreenSpaceVariance, _SpecularAAThreshold);
#endif
#endif
// Caution: surfaceData must be fully initialize before calling GetBuiltinData
GetBuiltinData(input, V, posInput, surfaceData, alpha, bentNormalWS, depthOffset, layerTexCoord.base, builtinData);
#ifdef _ALPHATEST_ON
// Used for sharpening by alpha to mask
builtinData.alphaClipTreshold = alphaCutoff;
#endif
RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: be7208b19c2b4f53b717af959f293024
timeCreated: 1738569488

View File

@@ -0,0 +1,70 @@
#ifndef UTS_SURFACE_FEATURE_EVALUATION
#define UTS_SURFACE_FEATURE_EVALUATION
DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData bsdfData, PreLightData preLightData
#if _LIGHT_BASE_RIM_LIGHT_ON
, float3 L, float3 lightColor
#endif
)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
float3 rimLightColor = _RimLightColor.rgb * _RimLightIntensity;
#if _SCREEN_SPACE_RIM_LIGHT_ON
float3 normalVS = normalize(mul((float3x3)UNITY_MATRIX_V, bsdfData.geomNormalWS));
float2 depthUV = posInput.positionNDC.xy + normalVS.xy * (_RimLightLevel * 0.05 / posInput.linearDepth);
float offsetedDepth = SampleCameraDepth(depthUV);
float depthDiff = saturate(posInput.deviceDepth - offsetedDepth);
float rimLightMask = step(0.0025 / posInput.linearDepth, depthDiff);
#else
float clampNdotV = ClampNdotV(preLightData.NdotV);
float rimLightMask = pow(1.0 - clampNdotV, exp2(lerp(3.0, 0.0, _RimLightLevel)));
rimLightMask = lerp(rimLightMask, step(_RimLightClippingLevel, rimLightMask), _RimLightClipping);
#endif
#if _LIGHT_BASE_RIM_LIGHT_ON
float halfLambert = 0.5 * dot(bsdfData.normalWS, L) + 0.5;
float lightBaseMask = saturate(smoothstep(_LightDirectionRimLightLevel, 1.0, halfLambert));
rimLightMask *= lightBaseMask;
rimLightColor *= lightColor;
#endif
lighting.diffuse = rimLightMask * rimLightColor;
return lighting;
}
DirectLighting UtsEvaluateLighting_AngelRing(FragInputs input, float3 normalWS, float3 V)
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
// Should we scroll the angel ring texture on x?
float3 cameraRight = UNITY_MATRIX_V[0].xyz;
float3 cameraFront = UNITY_MATRIX_V[2].xyz;
float3 upVector = float3(0, 1, 0);
float3 rightAxis = cross(cameraFront, upVector);
float cameraRightMagnitude = sqrt(cameraRight.x * cameraRight.x + cameraRight.y * cameraRight.y + cameraRight.z * cameraRight.z);
float rightAxisMagnitude = sqrt(rightAxis.x * rightAxis.x + rightAxis.y * rightAxis.y + rightAxis.z * rightAxis.z);
float cameraRollCos = dot(rightAxis, cameraRight) / (rightAxisMagnitude * cameraRightMagnitude);
float3 cameraRoll = acos(clamp(cameraRollCos, -1.0, 1.0));
float cameraDir = cameraRight.y < 0 ? -1.0 : 1.0;
float2 arOffsetU = lerp(mul(UNITY_MATRIX_V, float4(normalWS, 0)).xyz, float3(0, 0, 1), _AngelRingOffsetU).xy;
arOffsetU = arOffsetU * 0.5 + 0.5;
float2 arvnRotate = RotateUV(arOffsetU, -(cameraDir * cameraRoll).x, 0.5, 1.0);
float2 arOffsetUV = float2(arvnRotate.x, lerp(input.texCoord0.y, arvnRotate.y, _AngelRingOffsetV));
float4 angelRingColor = SAMPLE_TEXTURE2D(_AngelRingColorMap, sampler_AngelRingColorMap, TRANSFORM_TEX(arOffsetUV, _AngelRingColorMap)) * _AngelRingColor * _AngelRingIntensity;
float weight = saturate(dot(normalize(V), normalWS));
lighting.specular = angelRingColor.r * angelRingColor.a * weight;
return lighting;
}
#endif

Some files were not shown because too many files have changed in this diff Show More