5 Commits

Author SHA1 Message Date
35dc7b15a6 Added new fabirc pbr mode;
Added new stocking surface feature;

Fixed the issue that diffuse bsdf is not energy conserving.
Fixed the bug that shader can not render alpha clip properly;
2025-05-15 16:07:54 +09:00
d19322b768 Fixed the engergy conservation problem when pbr mode is toon. 2025-05-13 21:35:52 +09:00
961db806e9 Added hair blending support. 2025-05-06 23:39:49 +09:00
10331b93ff Added new ramp diffuse ambient mode. 2025-05-06 00:01:08 +09:00
abdf6196ed Fixed the bug that alpha clip does not working properly; 2025-03-24 21:41:58 +09:00
35 changed files with 614 additions and 356 deletions

View File

@@ -26,6 +26,16 @@ namespace Misaki.HdrpToon.Editor
return (PBRMode)material.GetInteger(SurfaceOptions.PBR_MODE); return (PBRMode)material.GetInteger(SurfaceOptions.PBR_MODE);
} }
public static MaterialType GetMaterialType(this Material material)
{
if (!material.HasProperty(SurfaceOptions.MATERIAL_TYPE))
{
return MaterialType.Standard;
}
return (MaterialType)material.GetInteger(SurfaceOptions.MATERIAL_TYPE);
}
public static bool HasFeature(this Material material, SurfaceFeature feature) public static bool HasFeature(this Material material, SurfaceFeature feature)
{ {
if (!material.HasProperty(SurfaceOptions.SURFACE_FEATURE)) if (!material.HasProperty(SurfaceOptions.SURFACE_FEATURE))
@@ -36,5 +46,10 @@ namespace Misaki.HdrpToon.Editor
var value = (SurfaceFeature)material.GetInteger(SurfaceOptions.SURFACE_FEATURE); var value = (SurfaceFeature)material.GetInteger(SurfaceOptions.SURFACE_FEATURE);
return (value & feature) != 0; return (value & feature) != 0;
} }
public static bool IsHairBlendingTarget(this Material material)
{
return material.GetShaderPassEnabled(UtsShaderPassName.HAIR_BLENDING_TARGET_PASS_NAME);
}
} }
} }

View File

@@ -11,10 +11,10 @@ namespace Misaki.HdrpToon.Editor
Highlight = 1 << 6, Highlight = 1 << 6,
Rimlight = 1 << 7, Rimlight = 1 << 7,
MatCap = 1 << 8, MatCap = 1 << 8,
AngelRing = 1 << 9, Stocking = 1 << 9,
Emission = 1 << 10, AngelRing = 1 << 10,
Outline = 1 << 11, Emission = 1 << 11,
TessellationLegacy = 1 << 12, Outline = 1 << 12,
TessellationHDRP = 1 << 13, TessellationHDRP = 1 << 13,
SceneLight = 1 << 14, SceneLight = 1 << 14,
EnvironmentalLightEffectiveness = 1 << 15, EnvironmentalLightEffectiveness = 1 << 15,

View File

@@ -10,6 +10,8 @@ namespace Misaki.HdrpToon.Editor
{ {
private static class Properties private static class Properties
{ {
public static MaterialProperty diffuseMin;
public static MaterialProperty lightIntensityMultiplier; public static MaterialProperty lightIntensityMultiplier;
public static MaterialProperty clampLightColor; public static MaterialProperty clampLightColor;
@@ -18,6 +20,8 @@ namespace Misaki.HdrpToon.Editor
private static class Styles private static class Styles
{ {
public static readonly GUIContent diffuseMinText = new("Minimal diffuse contribution", "Specifies the minimum contribution of the base color to the diffuse light. Keep it 0 to make sure energy conservation.");
public static readonly GUIContent lightIntensityMultiplierText = new("Light Intensity Multiplier", "Specifies the intensity multiplier of the light."); public static readonly GUIContent lightIntensityMultiplierText = new("Light Intensity Multiplier", "Specifies the intensity multiplier of the light.");
public static readonly GUIContent clampLightColorText = new("Clamp Light Color", "Specifies whether to clamp the light color."); public static readonly GUIContent clampLightColorText = new("Clamp Light Color", "Specifies whether to clamp the light color.");
@@ -30,6 +34,8 @@ namespace Misaki.HdrpToon.Editor
public override void LoadMaterialProperties() public override void LoadMaterialProperties()
{ {
Properties.diffuseMin = FindProperty(MINIMAL_DIFFUSE_CONTRIBUTION);
Properties.lightIntensityMultiplier = FindProperty(LIGHT_INTENSITY_MULTIPLIER); Properties.lightIntensityMultiplier = FindProperty(LIGHT_INTENSITY_MULTIPLIER);
Properties.clampLightColor = FindProperty(CLAMP_LIGHT_COLOR); Properties.clampLightColor = FindProperty(CLAMP_LIGHT_COLOR);
@@ -38,6 +44,8 @@ namespace Misaki.HdrpToon.Editor
protected override void DrawContent() protected override void DrawContent()
{ {
editor.ShaderProperty(Properties.diffuseMin, Styles.diffuseMinText);
editor.ShaderProperty(Properties.lightIntensityMultiplier, Styles.lightIntensityMultiplierText); editor.ShaderProperty(Properties.lightIntensityMultiplier, Styles.lightIntensityMultiplierText);
editor.ShaderProperty(Properties.clampLightColor, Styles.clampLightColorText); editor.ShaderProperty(Properties.clampLightColor, Styles.clampLightColorText);

View File

@@ -17,6 +17,10 @@ namespace Misaki.HdrpToon.Editor
public static MaterialProperty indirectDiffuseMatCapMap; public static MaterialProperty indirectDiffuseMatCapMap;
public static MaterialProperty indirectDiffuseMatCapLod; public static MaterialProperty indirectDiffuseMatCapLod;
public static MaterialProperty indirectDiffuseRampMap;
public static MaterialProperty indirectDiffuseRampIndex;
public static MaterialProperty indirectDiffuseRampPosition;
public static MaterialProperty indirectDiffuseIntensity; public static MaterialProperty indirectDiffuseIntensity;
public static MaterialProperty ssaoWeight; public static MaterialProperty ssaoWeight;
public static MaterialProperty ssgiWeight; public static MaterialProperty ssgiWeight;
@@ -35,6 +39,9 @@ namespace Misaki.HdrpToon.Editor
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 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 indirectDiffuseRampMapText = new("Ramp Map", "The ramp map for indirect diffuse evaluation, with the additional setting for controlling the sampling index of the ramp map.");
public static readonly GUIContent indirectDiffuseRampPositionText = new("Ramp Position", "The ramp position for indirect diffuse evaluation.");
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 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 ssaoWeightText = new("SSAO Weight", "The weight of SSAO.");
public static readonly GUIContent ssgiWeightText = new("SSGI Weight", "The weight of SSGI."); public static readonly GUIContent ssgiWeightText = new("SSGI Weight", "The weight of SSGI.");
@@ -53,6 +60,10 @@ namespace Misaki.HdrpToon.Editor
Properties.indirectDiffuseMatCapMap = FindProperty("_IndirectDiffuseMatCapMap"); Properties.indirectDiffuseMatCapMap = FindProperty("_IndirectDiffuseMatCapMap");
Properties.indirectDiffuseMatCapLod = FindProperty("_IndirectDiffuseMatCapLod"); Properties.indirectDiffuseMatCapLod = FindProperty("_IndirectDiffuseMatCapLod");
Properties.indirectDiffuseRampMap = FindProperty("_IndirectDiffuseRampMap");
Properties.indirectDiffuseRampIndex = FindProperty("_IndirectDiffuseRampIndex");
Properties.indirectDiffuseRampPosition = FindProperty("_IndirectDiffuseRampPosition");
Properties.indirectDiffuseIntensity = FindProperty("_IndirectDiffuseIntensity"); Properties.indirectDiffuseIntensity = FindProperty("_IndirectDiffuseIntensity");
Properties.ssaoWeight = FindProperty("_SSAOWeight"); Properties.ssaoWeight = FindProperty("_SSAOWeight");
Properties.ssgiWeight = FindProperty("_SSGIWeight"); Properties.ssgiWeight = FindProperty("_SSGIWeight");
@@ -64,6 +75,36 @@ namespace Misaki.HdrpToon.Editor
Properties.ssrWeight = FindProperty("_SSRWeight"); Properties.ssrWeight = FindProperty("_SSRWeight");
} }
private static void DrawIndirectDiffuseHeader()
{
EditorGUILayout.Space();
using var indentLevelScope = new EditorGUI.IndentLevelScope(-1);
EditorGUILayout.LabelField("Indirect Diffuse", EditorStyles.boldLabel);
}
private void DrawIndirectDiffuseProperties()
{
EditorGUILayout.Space();
editor.ShaderProperty(Properties.indirectDiffuseIntensity, Styles.indirectDiffuseIntensityText);
editor.ShaderProperty(Properties.ssaoWeight, Styles.ssaoWeightText);
}
private void DrawIndirectSpecularProperties()
{
EditorGUILayout.Space();
editor.ShaderProperty(Properties.indirectReflectionIntensity, Styles.indirectReflectionIntensityText);
editor.ShaderProperty(Properties.ssrWeight, Styles.ssrWeightText);
}
private static void DrawIndirectSpecularHeader()
{
EditorGUILayout.Space();
using (var indentLevelScope = new EditorGUI.IndentLevelScope(-1))
{
EditorGUILayout.LabelField("Indirect Specular", EditorStyles.boldLabel);
}
}
protected override void DrawContent() protected override void DrawContent()
{ {
editor.ShaderProperty(Properties.indirectDiffuseMode, Styles.indirectDiffuseModeText); editor.ShaderProperty(Properties.indirectDiffuseMode, Styles.indirectDiffuseModeText);
@@ -74,41 +115,43 @@ namespace Misaki.HdrpToon.Editor
if (indirectDiffuseMode != IndirectDiffuseMode.Off) if (indirectDiffuseMode != IndirectDiffuseMode.Off)
{ {
EditorGUILayout.Space(); DrawIndirectDiffuseHeader();
using (var indentLevelScope = new EditorGUI.IndentLevelScope(-1))
{
EditorGUILayout.LabelField("Indirect Diffuse", EditorStyles.boldLabel);
}
if (indirectDiffuseMode == IndirectDiffuseMode.Matcap) switch (indirectDiffuseMode)
{
editor.TexturePropertySingleLine(Styles.indirectDiffuseMatCapMapText, Properties.indirectDiffuseMatCapMap, Properties.indirectDiffuseMatCapLod);
}
editor.ShaderProperty(Properties.indirectDiffuseIntensity, Styles.indirectDiffuseIntensityText);
editor.ShaderProperty(Properties.ssaoWeight, Styles.ssaoWeightText);
if (indirectDiffuseMode == IndirectDiffuseMode.IBL)
{ {
case IndirectDiffuseMode.IBL:
editor.ShaderProperty(Properties.ssgiWeight, Styles.ssgiWeightText); editor.ShaderProperty(Properties.ssgiWeight, Styles.ssgiWeightText);
} break;
case IndirectDiffuseMode.Matcap:
editor.TexturePropertySingleLine(Styles.indirectDiffuseMatCapMapText, Properties.indirectDiffuseMatCapMap, Properties.indirectDiffuseMatCapLod);
break;
case IndirectDiffuseMode.Ramp:
editor.TexturePropertySingleLine(Styles.indirectDiffuseRampMapText, Properties.indirectDiffuseRampMap, Properties.indirectDiffuseRampIndex);
editor.ShaderProperty(Properties.indirectDiffuseRampPosition, Styles.indirectDiffuseRampPositionText);
break;
default:
break;
} }
if (indirectSpecularMode != (int)IndirectSpecularMode.Off) DrawIndirectDiffuseProperties();
{
EditorGUILayout.Space();
using (var indentLevelScope = new EditorGUI.IndentLevelScope(-1))
{
EditorGUILayout.LabelField("Indirect Specular", EditorStyles.boldLabel);
} }
if (indirectSpecularMode == IndirectSpecularMode.Matcap) if (indirectSpecularMode != IndirectSpecularMode.Off)
{ {
DrawIndirectSpecularHeader();
switch (indirectSpecularMode)
{
case IndirectSpecularMode.IBL:
break;
case IndirectSpecularMode.Matcap:
editor.TexturePropertySingleLine(Styles.indirectSpecularMatCapMapText, Properties.indirectSpecularMatCapMap, Properties.indirectSpecularMatCapLod); editor.TexturePropertySingleLine(Styles.indirectSpecularMatCapMapText, Properties.indirectSpecularMatCapMap, Properties.indirectSpecularMatCapLod);
break;
default:
break;
} }
editor.ShaderProperty(Properties.indirectReflectionIntensity, Styles.indirectReflectionIntensityText); DrawIndirectSpecularProperties();
editor.ShaderProperty(Properties.ssrWeight, Styles.ssrWeightText);
} }
} }
} }

View File

@@ -14,6 +14,7 @@ namespace Misaki.HdrpToon.Editor
public static MaterialProperty rimLightColor; public static MaterialProperty rimLightColor;
public static MaterialProperty rimLightIntensity; public static MaterialProperty rimLightIntensity;
public static MaterialProperty albedoAffectRimLight;
public static MaterialProperty screenSpaceRimLight; public static MaterialProperty screenSpaceRimLight;
public static MaterialProperty rimLightLevel; public static MaterialProperty rimLightLevel;
public static MaterialProperty rimLightClipping; public static MaterialProperty rimLightClipping;
@@ -28,6 +29,7 @@ namespace Misaki.HdrpToon.Editor
public static readonly GUIContent rimLightColorText = new("Rim Light Color", "Specifies the color of rim light."); 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 rimLightIntensityText = new("Rim Light Strength", "Specifies Rim Light strength.");
public static readonly GUIContent albedoAffectRimLightText = new("Albedo Affect Rim Light", "Enable to let the albedo color affect the rim light color. The alpha channel of rim light color will be the blending weight.");
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 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 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 rimLightClippingText = new("Rim Light Clipping", "Enable to Clip the rim light at specific level");
@@ -46,6 +48,7 @@ namespace Misaki.HdrpToon.Editor
Properties.rimLightColor = FindProperty(RIM_LIGHT_COLOR); Properties.rimLightColor = FindProperty(RIM_LIGHT_COLOR);
Properties.rimLightIntensity = FindProperty(RIM_LIGHT_INTENSITY); Properties.rimLightIntensity = FindProperty(RIM_LIGHT_INTENSITY);
Properties.albedoAffectRimLight = FindProperty(ALBEDO_AFFECT_RIM_LIGHT);
Properties.screenSpaceRimLight = FindProperty(SCREEN_SPACE_RIM_LIGHT); Properties.screenSpaceRimLight = FindProperty(SCREEN_SPACE_RIM_LIGHT);
Properties.rimLightLevel = FindProperty(RIM_LIGHT_LEVEL); Properties.rimLightLevel = FindProperty(RIM_LIGHT_LEVEL);
Properties.rimLightClipping = FindProperty(RIM_LIGHT_CLIPPING); Properties.rimLightClipping = FindProperty(RIM_LIGHT_CLIPPING);
@@ -60,6 +63,7 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.rimLightColor, Styles.rimLightColorText); editor.ShaderProperty(Properties.rimLightColor, Styles.rimLightColorText);
editor.ShaderProperty(Properties.rimLightIntensity, Styles.rimLightIntensityText); editor.ShaderProperty(Properties.rimLightIntensity, Styles.rimLightIntensityText);
editor.ShaderProperty(Properties.albedoAffectRimLight, Styles.albedoAffectRimLightText);
editor.ShaderProperty(Properties.screenSpaceRimLight, Styles.screenSpaceRimLightText); editor.ShaderProperty(Properties.screenSpaceRimLight, Styles.screenSpaceRimLightText);
editor.ShaderProperty(Properties.rimLightLevel, Styles.rimLightLevelText); editor.ShaderProperty(Properties.rimLightLevel, Styles.rimLightLevelText);

View File

@@ -34,6 +34,8 @@ namespace Misaki.HdrpToon.Editor
public static MaterialProperty sdfShadowLevel; public static MaterialProperty sdfShadowLevel;
public static MaterialProperty sdfSmoothLevel; public static MaterialProperty sdfSmoothLevel;
public static MaterialProperty sdfHighlightStrength; public static MaterialProperty sdfHighlightStrength;
public static MaterialProperty hairBlendingFactor;
} }
private static class Styles private static class Styles
@@ -59,6 +61,8 @@ namespace Misaki.HdrpToon.Editor
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 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."); public static readonly GUIContent sdfHighlightStrengthText = new("SDF Highlight Strength", "Control the strength of the highlight in the SDF shading map.");
public static readonly GUIContent hairBlendingFactorText = new("Hair Blending Factor", "The blending factor for hair shading.");
} }
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.ShadingColor; protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.ShadingColor;
@@ -108,6 +112,8 @@ namespace Misaki.HdrpToon.Editor
Properties.sdfShadowLevel = FindProperty("_SDFShadowLevel"); Properties.sdfShadowLevel = FindProperty("_SDFShadowLevel");
Properties.sdfSmoothLevel = FindProperty("_SDFShadowSmoothLevel"); Properties.sdfSmoothLevel = FindProperty("_SDFShadowSmoothLevel");
Properties.sdfHighlightStrength = FindProperty("_SDFHighlightStrength"); Properties.sdfHighlightStrength = FindProperty("_SDFHighlightStrength");
Properties.hairBlendingFactor = FindProperty("_HairBlendingFactor");
} }
protected override void DrawContent() protected override void DrawContent()
@@ -144,6 +150,12 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.sdfHighlightStrength, Styles.sdfHighlightStrengthText); editor.ShaderProperty(Properties.sdfHighlightStrength, Styles.sdfHighlightStrengthText);
} }
if (materials.All(material => material.GetMaterialType() == MaterialType.FrontHair))
{
EditorGUILayout.Space();
editor.ShaderProperty(Properties.hairBlendingFactor, Styles.hairBlendingFactorText);
}
EditorGUILayout.Space(); EditorGUILayout.Space();
editor.TextureScaleOffsetProperty(Properties.baseColorMap); editor.TextureScaleOffsetProperty(Properties.baseColorMap);
} }

View File

@@ -0,0 +1,22 @@
using Misaki.ShaderGUI;
using UnityEngine;
namespace Misaki.HdrpToon.Editor
{
public class StockingScope : MaterialUIScope<ShaderGUIExpandable>
{
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Stocking;
protected override GUIContent Header => throw new System.NotImplementedException();
public override void LoadMaterialProperties()
{
throw new System.NotImplementedException();
}
protected override void DrawContent()
{
throw new System.NotImplementedException();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9e91add2c76ce49448b768421496d94d

View File

@@ -12,28 +12,30 @@ namespace Misaki.HdrpToon.Editor
{ {
private static class Properties private static class Properties
{ {
public static MaterialProperty NormalMap; public static MaterialProperty normalMap;
public static MaterialProperty NormalMapScale; public static MaterialProperty normalMapScale;
public static MaterialProperty MaskMap; public static MaterialProperty maskMap;
public static MaterialProperty Metallic; public static MaterialProperty metallic;
public static MaterialProperty MetallicRemapMin; public static MaterialProperty metallicRemapMin;
public static MaterialProperty MetallicRemapMax; public static MaterialProperty metallicRemapMax;
public static MaterialProperty AORemapMin; public static MaterialProperty aoRemapMin;
public static MaterialProperty AORemapMax; public static MaterialProperty aoRemapMax;
public static MaterialProperty Smoothness; public static MaterialProperty smoothness;
public static MaterialProperty SmoothnessRemapMin; public static MaterialProperty smoothnessRemapMin;
public static MaterialProperty SmoothnessRemapMax; public static MaterialProperty smoothnessRemapMax;
public static MaterialProperty AnisotropyMap; public static MaterialProperty anisotropyMap;
public static MaterialProperty Anisotropy; public static MaterialProperty anisotropy;
public static MaterialProperty KKColor; public static MaterialProperty kkColor;
public static MaterialProperty BSDFContribution; public static MaterialProperty bsdfContribution;
public static MaterialProperty SpecularColorMap; public static MaterialProperty specularColorMap;
public static MaterialProperty SpecularColor; public static MaterialProperty specularColor;
public static MaterialProperty SpecularFeather; public static MaterialProperty specularFeather;
public static MaterialProperty SpecularStep; public static MaterialProperty specularStep;
public static MaterialProperty hairBlendingMap;
public static MaterialProperty emissiveColorLDR; public static MaterialProperty emissiveColorLDR;
public static MaterialProperty emissiveColorMap; public static MaterialProperty emissiveColorMap;
@@ -45,21 +47,23 @@ namespace Misaki.HdrpToon.Editor
private static class Styles 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 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 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 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 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 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 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 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 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 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 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 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 specRemap = new("Specular Remap", "Feather and step value of Toon Specular");
public static readonly GUIContent hairBlenderMapText = new("Hair Blending Map", "Specifies the hair blending map of the material.");
public static readonly GUIContent emissiveColorText = new("Emissive Color", "The color and color map to set for emissive effect."); 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 albedoAffectEmissiveText = new("Albedo Affect Emissive", "Enable to affect emissive color with base color");
@@ -73,28 +77,30 @@ namespace Misaki.HdrpToon.Editor
public override void LoadMaterialProperties() public override void LoadMaterialProperties()
{ {
Properties.NormalMap = FindProperty("_NormalMap"); Properties.normalMap = FindProperty("_NormalMap");
Properties.NormalMapScale = FindProperty("_NormalScale"); Properties.normalMapScale = FindProperty("_NormalScale");
Properties.MaskMap = FindProperty("_MaskMap"); Properties.maskMap = FindProperty("_MaskMap");
Properties.Metallic = FindProperty("_Metallic"); Properties.metallic = FindProperty("_Metallic");
Properties.MetallicRemapMin = FindProperty("_MetallicRemapMin"); Properties.metallicRemapMin = FindProperty("_MetallicRemapMin");
Properties.MetallicRemapMax = FindProperty("_MetallicRemapMax"); Properties.metallicRemapMax = FindProperty("_MetallicRemapMax");
Properties.AORemapMin = FindProperty("_AORemapMin"); Properties.aoRemapMin = FindProperty("_AORemapMin");
Properties.AORemapMax = FindProperty("_AORemapMax"); Properties.aoRemapMax = FindProperty("_AORemapMax");
Properties.SmoothnessRemapMin = FindProperty("_SmoothnessRemapMin"); Properties.smoothnessRemapMin = FindProperty("_SmoothnessRemapMin");
Properties.SmoothnessRemapMax = FindProperty("_SmoothnessRemapMax"); Properties.smoothnessRemapMax = FindProperty("_SmoothnessRemapMax");
Properties.Smoothness = FindProperty("_Smoothness"); Properties.smoothness = FindProperty("_Smoothness");
Properties.AnisotropyMap = FindProperty("_AnisotropyMap"); Properties.anisotropyMap = FindProperty("_AnisotropyMap");
Properties.Anisotropy = FindProperty("_Anisotropy"); Properties.anisotropy = FindProperty("_Anisotropy");
Properties.KKColor = FindProperty("_KKColor"); Properties.kkColor = FindProperty("_KKColor");
Properties.BSDFContribution = FindProperty("_BSDFContribution"); Properties.bsdfContribution = FindProperty("_BSDFContribution");
Properties.SpecularColorMap = FindProperty("_SpecularColorMap"); Properties.specularColorMap = FindProperty("_SpecularColorMap");
Properties.SpecularColor = FindProperty("_SpecularColor"); Properties.specularColor = FindProperty("_SpecularColor");
Properties.SpecularFeather = FindProperty("_ToonSpecularFeather"); Properties.specularFeather = FindProperty("_ToonSpecularFeather");
Properties.SpecularStep = FindProperty("_ToonSpecularStep"); Properties.specularStep = FindProperty("_ToonSpecularStep");
Properties.hairBlendingMap = FindProperty("_HairBlendingMap");
Properties.emissiveColorLDR = FindProperty(EMISSIVE_COLOR_LDR); Properties.emissiveColorLDR = FindProperty(EMISSIVE_COLOR_LDR);
Properties.emissiveColorMap = FindProperty(EMISSIVE_COLOR_MAP); Properties.emissiveColorMap = FindProperty(EMISSIVE_COLOR_MAP);
@@ -106,46 +112,55 @@ namespace Misaki.HdrpToon.Editor
protected override void DrawContent() protected override void DrawContent()
{ {
editor.KeywordTexturePropertySingleLine(Styles.NormalMapText, Properties.NormalMap, Properties.NormalMapScale); editor.KeywordTexturePropertySingleLine(Styles.normalMapText, Properties.normalMap, Properties.normalMapScale);
if (materials.All(mat => mat.GetPBRMode() != PBRMode.Off)) if (materials.All(mat => mat.GetPBRMode() != PBRMode.Off))
{ {
if (editor.KeywordTexturePropertySingleLine(Styles.MaskMapText, Properties.MaskMap)) if (editor.KeywordTexturePropertySingleLine(Styles.maskMapText, Properties.maskMap))
{ {
editor.MinMaxShaderProperty(Properties.MetallicRemapMin, Properties.MetallicRemapMax, 0, 1, Styles.MetallicRemap); editor.MinMaxShaderProperty(Properties.metallicRemapMin, Properties.metallicRemapMax, 0, 1, Styles.metallicRemap);
editor.MinMaxShaderProperty(Properties.AORemapMin, Properties.AORemapMax, 0, 1, Styles.AORemap); editor.MinMaxShaderProperty(Properties.aoRemapMin, Properties.aoRemapMax, 0, 1, Styles.aoRemap);
editor.MinMaxShaderProperty(Properties.SmoothnessRemapMin, Properties.SmoothnessRemapMax, 0, 1, Styles.SmoothnessRemapText); editor.MinMaxShaderProperty(Properties.smoothnessRemapMin, Properties.smoothnessRemapMax, 0, 1, Styles.smoothnessRemapText);
} }
else else
{ {
if (materials.All(mat => mat.GetPBRMode() != PBRMode.KKHair)) if (materials.All(mat =>
{ {
editor.ShaderProperty(Properties.Metallic, Styles.MetallicText); var pbrMode = mat.GetPBRMode();
return pbrMode != PBRMode.Hair && pbrMode != PBRMode.Toon;
}))
{
editor.ShaderProperty(Properties.metallic, Styles.metallicText);
} }
editor.ShaderProperty(Properties.Smoothness, Styles.SmoothnessText); editor.ShaderProperty(Properties.smoothness, Styles.smoothnessText);
} }
} }
if (materials.All(mat => mat.GetPBRMode() == PBRMode.Anisotropy || mat.GetPBRMode() == PBRMode.KKHair)) if (materials.All(mat => mat.GetPBRMode() == PBRMode.Anisotropy || mat.GetPBRMode() == PBRMode.Hair))
{ {
EditorGUILayout.Space(); EditorGUILayout.Space();
editor.KeywordTexturePropertySingleLine(Styles.AnisotropyMapText, Properties.AnisotropyMap, Properties.Anisotropy); editor.KeywordTexturePropertySingleLine(Styles.anisotropyMapText, Properties.anisotropyMap, Properties.anisotropy);
if (materials.All(mat => mat.GetPBRMode() == PBRMode.KKHair)) if (materials.All(mat => mat.GetPBRMode() == PBRMode.Hair))
{ {
editor.ShaderProperty(Properties.KKColor, Styles.KKColorText); editor.ShaderProperty(Properties.kkColor, Styles.kkColorText);
editor.ShaderProperty(Properties.BSDFContribution, Styles.BSDFContributionText); editor.ShaderProperty(Properties.bsdfContribution, Styles.bsdfContributionText);
} }
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.LabelField("Anisotropy Map only ST"); EditorGUILayout.LabelField("Anisotropy Map only ST");
editor.TextureScaleOffsetProperty(Properties.AnisotropyMap); editor.TextureScaleOffsetProperty(Properties.anisotropyMap);
} }
else if (materials.All(mat => mat.GetPBRMode() == PBRMode.Toon)) else if (materials.All(mat => mat.GetPBRMode() == PBRMode.Toon))
{ {
EditorGUILayout.Space(); EditorGUILayout.Space();
editor.KeywordTexturePropertySingleLine(Styles.SpecularColorMapText, Properties.SpecularColorMap, Properties.SpecularColor); editor.KeywordTexturePropertySingleLine(Styles.specularColorMapText, Properties.specularColorMap, Properties.specularColor);
editor.MinMaxShaderProperty(Properties.SpecularFeather, Properties.SpecularStep, 0, 1, Styles.SpecRemap); editor.MinMaxShaderProperty(Properties.specularFeather, Properties.specularStep, 0, 1, Styles.specRemap);
}
if (materials.All(mat => mat.IsHairBlendingTarget()))
{
editor.TexturePropertySingleLine(Styles.hairBlenderMapText, Properties.hairBlendingMap);
} }
EditorGUILayout.Space(); EditorGUILayout.Space();

View File

@@ -63,7 +63,7 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.transparentMode, Styles.transparentModeText); editor.ShaderProperty(Properties.transparentMode, Styles.transparentModeText);
editor.ShaderProperty(Properties.alphaClipEnable, Styles.alphaClipEnableText); editor.ShaderProperty(Properties.alphaClipEnable, Styles.alphaClipEnableText);
if (Properties.alphaClipEnable.floatValue == 1.0f) if (Properties.alphaClipEnable.GetBooleanValue())
{ {
EditorGUI.indentLevel++; EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.alphaClip, Styles.alphaClipText); editor.ShaderProperty(Properties.alphaClip, Styles.alphaClipText);
@@ -90,7 +90,7 @@ namespace Misaki.HdrpToon.Editor
{ {
foreach (var material in materials) foreach (var material in materials)
{ {
material.SetShaderPassEnabled(UtsShaderPassName.HAIR_BLENDING_TARGET_PASS_NAME, Properties.hairBlendingTarget.floatValue == 1.0f); material.SetShaderPassEnabled(UtsShaderPassName.HAIR_BLENDING_TARGET_PASS_NAME, Properties.hairBlendingTarget.GetBooleanValue());
} }
} }

View File

@@ -1,6 +1,7 @@
using Misaki.ShaderGUI; using Misaki.ShaderGUI;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering;
namespace Misaki.HdrpToon.Editor namespace Misaki.HdrpToon.Editor
{ {
@@ -8,6 +9,28 @@ namespace Misaki.HdrpToon.Editor
{ {
private GUIStyle _headerStyle; private GUIStyle _headerStyle;
public override void ValidateMaterial(Material material)
{
material.SetShaderPassEnabled(UtsShaderPassName.HAIR_SHADOW_CASTER_PASS_NAME, (MaterialType)material.GetInteger("_Material_Type") == MaterialType.FrontHair);
material.SetShaderPassEnabled(UtsShaderPassName.HAIR_BLENDING_TARGET_PASS_NAME, material.GetInteger("_HairBlendingTarget") == 1);
if (material.GetInteger("_AlphaCutoffEnable") > 0.0f)
{
material.SetInt("_ZTestGBuffer", (int)CompareFunction.Equal);
}
else
{
material.SetInt("_ZTestGBuffer", (int)CompareFunction.LessEqual);
}
//if (surfaceType == SurfaceType.Opaque)
//{
material.SetInt("_ZTestDepthEqualForOpaque", (int)CompareFunction.Equal);
//}
//else
// material.SetInt(kZTestDepthEqualForOpaque, (int)material.GetTransparentZTest());
}
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{ {
if (!initialized) if (!initialized)

View File

@@ -41,7 +41,7 @@ The HDRP Toon Shader is designed to provide a high-quality toon shading effect f
## Example ## Example
Here are some examples of the HDRP Toon Shader in action: Here are some examples of the HDRP Toon Shader in action:
![preview-01.png](https://s2.loli.net/2024/12/26/zHdfSXho4csURyx.png) ![preview-01.png](https://i.postimg.cc/nV3fT2PR/Screenshot-2025-05-13-212926.png)
## Contributing ## Contributing

View File

@@ -7,6 +7,7 @@ namespace Misaki.HdrpToon
public const string SHADING_MODE = "_Shading_Mode"; public const string SHADING_MODE = "_Shading_Mode";
public const string PBR_MODE = "_PBR_Mode"; public const string PBR_MODE = "_PBR_Mode";
public const string SURFACE_FEATURE = "_SurfaceFeatures"; public const string SURFACE_FEATURE = "_SurfaceFeatures";
public const string MATERIAL_TYPE = "_Material_Type";
} }
public static class SurfaceInputs public static class SurfaceInputs
@@ -25,8 +26,9 @@ namespace Misaki.HdrpToon
{ {
public const string RIM_LIGHT_COLOR = "_RimLightColor"; public const string RIM_LIGHT_COLOR = "_RimLightColor";
public const string RIM_LIGHT_INTENSITY = "_RimLightIntensity"; public const string RIM_LIGHT_INTENSITY = "_RimLightIntensity";
public const string RIM_LIGHT_LEVEL = "_RimLightLevel"; public const string ALBEDO_AFFECT_RIM_LIGHT = "_AlbedoAffectRimLight";
public const string SCREEN_SPACE_RIM_LIGHT = "_Screen_Space_Rim_Light"; public const string SCREEN_SPACE_RIM_LIGHT = "_Screen_Space_Rim_Light";
public const string RIM_LIGHT_LEVEL = "_RimLightLevel";
public const string LIGHT_BASE_RIM_LIGHT = "_Light_Base_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 LIGHT_DIRECTION_RIM_LIGHT_LEVEL = "_LightDirectionRimLightLevel";
@@ -72,6 +74,8 @@ namespace Misaki.HdrpToon
public static class Advance public static class Advance
{ {
public const string MINIMAL_DIFFUSE_CONTRIBUTION = "_Minimal_Diffuse_Contribution";
public const string LIGHT_INTENSITY_MULTIPLIER = "_LightIntensityMultiplier"; public const string LIGHT_INTENSITY_MULTIPLIER = "_LightIntensityMultiplier";
public const string CLAMP_LIGHT_COLOR = "_ClampLightColor"; public const string CLAMP_LIGHT_COLOR = "_ClampLightColor";

View File

@@ -19,7 +19,8 @@ namespace Misaki.HdrpToon
Off, Off,
Standard, Standard,
Anisotropy, Anisotropy,
KKHair, Hair,
Fabric,
Toon Toon
} }

View File

@@ -8,8 +8,8 @@ namespace Misaki.HdrpToon
public enum SurfaceFeature public enum SurfaceFeature
{ {
None = 0, None = 0,
RimLight = 1 << 0, Stocking = 1 << 0,
Stocking = 1 << 1, RimLight = 1 << 1,
AngelRing = 1 << 2 AngelRing = 1 << 2
} }
} }

View File

@@ -8,8 +8,8 @@
// Misaki.HdrpToon.SurfaceFeature: static fields // Misaki.HdrpToon.SurfaceFeature: static fields
// //
#define SURFACEFEATURE_NONE (0) #define SURFACEFEATURE_NONE (0)
#define SURFACEFEATURE_RIM_LIGHT (1) #define SURFACEFEATURE_STOCKING (1)
#define SURFACEFEATURE_STOCKING (2) #define SURFACEFEATURE_RIM_LIGHT (2)
#define SURFACEFEATURE_ANGEL_RING (4) #define SURFACEFEATURE_ANGEL_RING (4)

View File

@@ -4,8 +4,6 @@ Shader "HDRP/Toon"
{ {
//TODO: Use custom rendering data. //TODO: Use custom rendering data.
[ToggleUI] _UseShadowThreshold("_UseShadowThreshold", Float) = 0.0 [ToggleUI] _UseShadowThreshold("_UseShadowThreshold", Float) = 0.0
[ToggleUI] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_AlphaCutoffShadow("_AlphaCutoffShadow", Range(0.0, 1.0)) = 0.5 _AlphaCutoffShadow("_AlphaCutoffShadow", Range(0.0, 1.0)) = 0.5
_AlphaCutoffPrepass("_AlphaCutoffPrepass", Range(0.0, 1.0)) = 0.5 _AlphaCutoffPrepass("_AlphaCutoffPrepass", Range(0.0, 1.0)) = 0.5
_AlphaCutoffPostpass("_AlphaCutoffPostpass", Range(0.0, 1.0)) = 0.5 _AlphaCutoffPostpass("_AlphaCutoffPostpass", Range(0.0, 1.0)) = 0.5
@@ -49,7 +47,6 @@ Shader "HDRP/Toon"
[HideInInspector] _AlphaDstBlend("__alphaDst", Float) = 0.0 [HideInInspector] _AlphaDstBlend("__alphaDst", Float) = 0.0
[HideInInspector][ToggleUI] _ZWrite("__zw", Float) = 1.0 [HideInInspector][ToggleUI] _ZWrite("__zw", Float) = 1.0
[HideInInspector][ToggleUI] _TransparentZWrite("_TransparentZWrite", Float) = 0.0 [HideInInspector][ToggleUI] _TransparentZWrite("_TransparentZWrite", Float) = 0.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] _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] _TransparentCullMode("_TransparentCullMode", Int) = 2 // Back culling by default
[HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal [HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal
@@ -72,7 +69,6 @@ Shader "HDRP/Toon"
_Color("Color", Color) = (1,1,1,1) _Color("Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -86,12 +82,12 @@ Shader "HDRP/Toon"
// Surface Options // Surface Options
[Popup] _TransparentEnabled("Transparent Mode", Integer) = 0 [Popup] _TransparentEnabled("Transparent Mode", Integer) = 0
[ToggleUI] _AlphaCutoffEnable("Alpha Cutoff Enable", Float) = 0.0 [Popup(_ALPHATEST_ON)] _AlphaCutoffEnable("Alpha Cutoff Enable", Integer) = 0.0
_AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 _AlphaCutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[Enum(Off, 0, Front, 1, Back, 2)] _CullMode("Cull Mode", Integer) = 2 [Enum(Off, 0, Front, 1, Back, 2)] _CullMode("Cull Mode", Integer) = 2
[KeywordEnum(Standard, SDF)] _Shading_Mode("Shading mode", Integer) = 0 [KeywordEnum(Standard, SDF)] _Shading_Mode("Shading mode", Integer) = 0
[KeywordEnum(Standard, FrontHair, Face, Eye)] _Material_Type("Material Type", Integer) = 0 [KeywordEnum(Standard, FrontHair, Face, Eye)] _Material_Type("Material Type", Integer) = 0
[KeywordEnum(Off, Standard, Anisotropy, Hair, Toon)] _PBR_Mode("PBR Mode", Integer) = 0 [KeywordEnum(Off, Standard, Anisotropy, Hair, Fabric, Toon)] _PBR_Mode("PBR Mode", Integer) = 0
[PassPopup(HairBlendingTarget)] _HairBlendingTarget("Hair Blending Target", Integer) = 0 [PassPopup(HairBlendingTarget)] _HairBlendingTarget("Hair Blending Target", Integer) = 0
[EnumFlagsUI(Misaki.HdrpToon.SurfaceFeature, Misaki.HdrpToon)]_SurfaceFeatures("Surface Features", Integer) = 0 [EnumFlagsUI(Misaki.HdrpToon.SurfaceFeature, Misaki.HdrpToon)]_SurfaceFeatures("Surface Features", Integer) = 0
@@ -123,13 +119,15 @@ Shader "HDRP/Toon"
_SDFShadowSmoothLevel("SDFShadowSmoothLevel", Range(0.0, 0.1)) = 0.02 _SDFShadowSmoothLevel("SDFShadowSmoothLevel", Range(0.0, 0.1)) = 0.02
_SDFHighlightStrength("SDFHighlightStrength", Range(0.0, 1.0)) = 0.75 _SDFHighlightStrength("SDFHighlightStrength", Range(0.0, 1.0)) = 0.75
_HairBlendingFactor("HairBlendingFactor", Range(0.0, 1.0)) = 0.5
// Shadow // Shadow
[Popup] _Receive_Light_Shadow("Receive Light Shadow", Integer) = 0 [Popup] _Receive_Light_Shadow("Receive Light Shadow", Integer) = 0
[Popup] _Receive_Screen_Space_Shadow("Receive Screen Space Shadow", Integer) = 0 [Popup] _Receive_Screen_Space_Shadow("Receive Screen Space Shadow", Integer) = 0
[Popup] _Receive_Hair_Shadow("Receive Hair Shadow", Integer) = 0 [Popup] _Receive_Hair_Shadow("Receive Hair Shadow", Integer) = 0
_ShadowDistanceBias("ShadowBias", Range(0.0, 5.0)) = 0.0 _ShadowDistanceBias("ShadowBias", Range(0.0, 5.0)) = 0.0
_ShadowNormalBias("ShadowNormalBias", Range(0.0, 5.0)) = 0.0 _ShadowNormalBias("ShadowNormalBias", Range(-5.0, 5.0)) = 0.0
//_Tweak_SystemShadowsLevel("Tweak_SystemShadowsLevel", Range(-0.5, 0.5)) = 0 //_Tweak_SystemShadowsLevel("Tweak_SystemShadowsLevel", Range(-0.5, 0.5)) = 0
// Surface Inputs // Surface Inputs
@@ -187,12 +185,17 @@ Shader "HDRP/Toon"
_IndirectSpecularMatCapMap("IndirectSpecularMatCapMap", 2D) = "black" {} _IndirectSpecularMatCapMap("IndirectSpecularMatCapMap", 2D) = "black" {}
_IndirectSpecularMatCapLod("IndirectSpecularMatCapMapLOD", Range(-5, 5)) = 0.0 _IndirectSpecularMatCapLod("IndirectSpecularMatCapMapLOD", Range(-5, 5)) = 0.0
_IndirectDiffuseRampMap("_IndirectDiffuseRampMap", 2DArray) = "black" {}
_IndirectDiffuseRampIndex("IndirectDiffuseRampIndex", Integer) = 0
_IndirectDiffuseRampPosition("IndirectDiffuseRampPosition", Range(0, 1)) = 0.5
_IndirectSpecularIntensity("Indirect Specular Intensity", Range(0, 5)) = 1.0 _IndirectSpecularIntensity("Indirect Specular Intensity", Range(0, 5)) = 1.0
_SSRWeight("SSR Weight", Range(0.0, 1.0)) = 1.0 _SSRWeight("SSR Weight", Range(0.0, 1.0)) = 1.0
// Rim Light // Rim Light
_RimLightColor("Rim Light Color", Color) = (1, 1, 1, 1) _RimLightColor("Rim Light Color", Color) = (1, 1, 1, 1)
_RimLightIntensity("Rim Light Intensity", Range(0, 10)) = 1 _RimLightIntensity("Rim Light Intensity", Range(0, 10)) = 1
[ToggleUI] _AlbedoAffectRimLight("Albedo Affect Rim Light", Integer) = 0
[Popup] _Screen_Space_Rim_Light ("Screen Space Rim Light", Integer) = 0 [Popup] _Screen_Space_Rim_Light ("Screen Space Rim Light", Integer) = 0
_RimLightLevel("RimLight Level", Range(0, 1)) = 0.1 _RimLightLevel("RimLight Level", Range(0, 1)) = 0.1
[ToggleUI] _RimLightClipping("Rim Light Clipping", Float) = 0.25 [ToggleUI] _RimLightClipping("Rim Light Clipping", Float) = 0.25
@@ -236,9 +239,26 @@ Shader "HDRP/Toon"
[ToggleUI] _UseSmoothedNormal("Use Smoothed Normal", Float) = 0 [ToggleUI] _UseSmoothedNormal("Use Smoothed Normal", Float) = 0
// Advance // Advance
_LightIntensityMultiplier("Light_Intensity_Multiplier" , Range(0, 1)) = 0.5 _LightIntensityMultiplier("Light_Intensity_Multiplier" , Range(0, 3)) = 1
[ToggleUI] _ClampLightColor("VRChat : SceneLights HiCut_Filter", Float) = 0 [ToggleUI] _ClampLightColor("VRChat : SceneLights HiCut_Filter", Float) = 0
_Minimal_Diffuse_Contribution("Minimal_Diffuse_Contribution", Range(0, 1)) = 0.05
[KeywordEnum(Single, Full, Custom)] _Light_Loop_Mode ("Light Loop Mode", Float) = 1 [KeywordEnum(Single, Full, Custom)] _Light_Loop_Mode ("Light Loop Mode", Float) = 1
//TODO: Clear hdrp default properties
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3)] _UVDetail("UV Set for detail", Float) = 0
[HideInInspector] _UVDetailsMappingMask("_UVDetailsMappingMask", Color) = (1, 0, 0, 0)
[ToggleUI] _LinkDetailsWithBase("LinkDetailsWithBase", Float) = 1.0
[Enum(Use Emissive Color, 0, Use Emissive Mask, 1)] _EmissiveColorMode("Emissive color mode", Float) = 1
[Enum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Planar, 4, Triplanar, 5, Same as Base, 6)] _UVEmissive("UV Set for emissive", Float) = 0
[Enum(WorldSpace, 0, ObjectSpace, 1)] _ObjectSpaceUVMappingEmissive("Mapping space", Float) = 0.0
_TexWorldScaleEmissive("Scale to apply on world coordinate", Float) = 1.0
[HideInInspector] _UVMappingMaskEmissive("_UVMappingMaskEmissive", Color) = (1, 0, 0, 0)
[HideInInspector] _DiffusionProfile("Obsolete, kept for migration purpose", Int) = 0
[HideInInspector] _DiffusionProfileAsset("Diffusion Profile Asset", Vector) = (0, 0, 0, 0)
[HideInInspector] _DiffusionProfileHash("Diffusion Profile Hash", Float) = 0
} }
HLSLINCLUDE HLSLINCLUDE
@@ -249,15 +269,7 @@ Shader "HDRP/Toon"
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// Variant // Variant
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local _DEPTHOFFSET_ON
#pragma shader_feature_local _DOUBLESIDED_ON #pragma shader_feature_local _DOUBLESIDED_ON
#pragma shader_feature_local _ _VERTEX_DISPLACEMENT _PIXEL_DISPLACEMENT
#pragma shader_feature_local _VERTEX_DISPLACEMENT_LOCK_OBJECT_SCALE
#pragma shader_feature_local _DISPLACEMENT_LOCK_TILING_SCALE
#pragma shader_feature_local _PIXEL_DISPLACEMENT_LOCK_OBJECT_SCALE
#pragma shader_feature_local _TESSELLATION_PHONG
#pragma shader_feature_local _NORMALMAP_TANGENT_SPACE #pragma shader_feature_local _NORMALMAP_TANGENT_SPACE
#pragma shader_feature_local _ _REQUIRE_UV2 _REQUIRE_UV3 #pragma shader_feature_local _ _REQUIRE_UV2 _REQUIRE_UV3
@@ -327,6 +339,7 @@ Shader "HDRP/Toon"
HLSLPROGRAM HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
// Note: Require _ObjectId and _PassValue variables // Note: Require _ObjectId and _PassValue variables
// We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation // We reuse depth prepass for the scene selection, allow to handle alpha correctly as well as tessellation and vertex animation
@@ -411,7 +424,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/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/Material/Lit/LitData.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/ShaderPass/UtsShaderPassGBuffer.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"
#pragma vertex Vert #pragma vertex Vert
#pragma fragment Frag #pragma fragment Frag
@@ -430,6 +443,7 @@ Shader "HDRP/Toon"
HLSLPROGRAM HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
// Lightmap memo // Lightmap memo
// DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light, // DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light,
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON. // both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
@@ -462,6 +476,8 @@ Shader "HDRP/Toon"
HLSLPROGRAM HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#define SHADERPASS SHADERPASS_SHADOWS #define SHADERPASS SHADERPASS_SHADOWS
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
@@ -481,7 +497,7 @@ Shader "HDRP/Toon"
Tags{ "LightMode" = "DepthForwardOnly" } Tags{ "LightMode" = "DepthForwardOnly" }
Cull[_CullMode] Cull[_CullMode]
AlphaToMask [_AlphaCutoffEnable]
// To be able to tag stencil with disableSSR information for forward // To be able to tag stencil with disableSSR information for forward
Stencil Stencil
{ {
@@ -495,6 +511,12 @@ Shader "HDRP/Toon"
HLSLPROGRAM HLSLPROGRAM
#pragma shader_feature_local_fragment _MASKMAP
#pragma shader_feature_local _NORMALMAP
#pragma shader_feature_local_fragment _NORMALMAP_TANGENT_SPACE
#pragma shader_feature_local _ALPHATEST_ON
// In deferred, depth only pass don't output anything. // In deferred, depth only pass don't output anything.
// In forward it output the normal buffer // In forward it output the normal buffer
#pragma multi_compile _ WRITE_NORMAL_BUFFER #pragma multi_compile _ WRITE_NORMAL_BUFFER
@@ -534,6 +556,7 @@ Shader "HDRP/Toon"
} }
Cull[_CullMode] Cull[_CullMode]
AlphaToMask [_AlphaCutoffEnable]
ZWrite On ZWrite On
@@ -541,6 +564,9 @@ Shader "HDRP/Toon"
#pragma multi_compile _ WRITE_NORMAL_BUFFER #pragma multi_compile _ WRITE_NORMAL_BUFFER
#pragma multi_compile _ WRITE_MSAA_DEPTH #pragma multi_compile _ WRITE_MSAA_DEPTH
#pragma shader_feature_local _ALPHATEST_ON
#define SHADERPASS SHADERPASS_MOTION_VECTORS #define SHADERPASS SHADERPASS_MOTION_VECTORS
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
@@ -603,6 +629,9 @@ Shader "HDRP/Toon"
HLSLPROGRAM HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#define SHADERPASS SHADERPASS_DEPTH_ONLY #define SHADERPASS SHADERPASS_DEPTH_ONLY
#define CUTOFF_TRANSPARENT_DEPTH_PREPASS #define CUTOFF_TRANSPARENT_DEPTH_PREPASS
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
@@ -630,6 +659,9 @@ Shader "HDRP/Toon"
ZTest [_ZTestTransparent] ZTest [_ZTestTransparent]
HLSLPROGRAM HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#pragma multi_compile _ DEBUG_DISPLAY #pragma multi_compile _ DEBUG_DISPLAY
#pragma multi_compile _ LIGHTMAP_ON #pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED #pragma multi_compile _ DIRLIGHTMAP_COMBINED
@@ -680,21 +712,27 @@ Shader "HDRP/Toon"
Tags { "LightMode" = "ForwardOnly" } Tags { "LightMode" = "ForwardOnly" }
ZWrite [_ZWriteMode] ZWrite [_ZWriteMode]
ZTest [_ZTestMode] ZTest [_ZTestDepthEqualForOpaque]
Cull [_CullMode] Cull [_CullMode]
Blend SrcAlpha OneMinusSrcAlpha
Stencil {
Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]
// ForwardOpaque | ForwardTransparent
Blend 1 One OneMinusSrcAlpha // VT feedback | VT feedback <- if VT is off, all targets below are shifted by 1
Blend 2 One [_DstBlend2] // diffuse lighting | motion vector
Blend 3 One [_DstBlend2] // SSS buffer | before refraction <- This target (or the one above if VT off) needs blending in transparent but not in opaque
Blend 4 One OneMinusSrcAlpha // | before refraction alpha
Stencil
{
Ref[_StencilNo] Ref[_StencilNo]
Comp[_StencilComp] Comp[_StencilComp]
Pass[_StencilOpPass] Pass[_StencilOpPass]
Fail[_StencilOpFail] Fail[_StencilOpFail]
} }
HLSLPROGRAM HLSLPROGRAM
//#pragma multi_compile _ UTS_DEBUG_SHADOWMAP_BINALIZATION
#pragma multi_compile _ DEBUG_DISPLAY #pragma multi_compile _ DEBUG_DISPLAY
#pragma multi_compile _ LIGHTMAP_ON #pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED #pragma multi_compile _ DIRLIGHTMAP_COMBINED
@@ -716,15 +754,7 @@ Shader "HDRP/Toon"
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(DEBUG_DISPLAY) #if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(DEBUG_DISPLAY)
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST #define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
#endif #endif
// used in ShadingGradeMap
#pragma shader_feature _IS_TRANSCLIPPING_OFF _IS_TRANSCLIPPING_ON
#pragma shader_feature _IS_ANGELRING_OFF _IS_ANGELRING_ON
// used in Shadow calculation
#pragma shader_feature _ UTS_USE_RAYTRACING_SHADOW
// used in DoubleShadeWithFeather
#pragma shader_feature _IS_CLIPPING_OFF _IS_CLIPPING_MODE _IS_CLIPPING_TRANSMODE
// controlling mask rendering
#pragma shader_feature _ _IS_CLIPPING_MATTE
#pragma shader_feature _EMISSIVE_SIMPLE _EMISSIVE_ANIMATION #pragma shader_feature _EMISSIVE_SIMPLE _EMISSIVE_ANIMATION
#pragma shader_feature ENABLE_UTS_HAIR_SHAOW #pragma shader_feature ENABLE_UTS_HAIR_SHAOW
@@ -734,7 +764,7 @@ Shader "HDRP/Toon"
#pragma shader_feature_local_fragment _SHADING_MODE_STANDARD _SHADING_MODE_SDF #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 _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_fragment _PBR_MODE_OFF _PBR_MODE_STANDARD _PBR_MODE_ANISOTROPY _PBR_MODE_HAIR _PBR_MODE_FABRIC _PBR_MODE_TOON
#pragma shader_feature_local_fragment _USE_SHADING_RAMP_MAP_ON #pragma shader_feature_local_fragment _USE_SHADING_RAMP_MAP_ON
@@ -759,6 +789,9 @@ Shader "HDRP/Toon"
#pragma shader_feature_local_fragment _OUTLINECOLORMAP #pragma shader_feature_local_fragment _OUTLINECOLORMAP
#pragma shader_feature_local _ALPHATEST_ON
#define PUNCTUAL_SHADOW_MEDIUM #define PUNCTUAL_SHADOW_MEDIUM
#define DIRECTIONAL_SHADOW_MEDIUM #define DIRECTIONAL_SHADOW_MEDIUM
#define AREA_SHADOW_MEDIUM #define AREA_SHADOW_MEDIUM
@@ -768,10 +801,6 @@ Shader "HDRP/Toon"
#define USE_FPTL_LIGHTLIST #define USE_FPTL_LIGHTLIST
#endif #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/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
@@ -819,6 +848,9 @@ Shader "HDRP/Toon"
ColorMask 0 ColorMask 0
HLSLPROGRAM HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#define SHADERPASS SHADERPASS_DEPTH_ONLY #define SHADERPASS SHADERPASS_DEPTH_ONLY
#define CUTOFF_TRANSPARENT_DEPTH_POSTPASS #define CUTOFF_TRANSPARENT_DEPTH_POSTPASS
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
@@ -866,11 +898,10 @@ Shader "HDRP/Toon"
Tags { "LightMode" = "Outline" } Tags { "LightMode" = "Outline" }
Cull Front Cull Front
Blend Off Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM HLSLPROGRAM
#define AREA_SHADOW_LOW #define AREA_SHADOW_LOW
#define SHADERPASS SHADERPASS_FORWARD #define SHADERPASS SHADERPASS_FORWARD
#define SHADOW_LOW #define SHADOW_LOW
@@ -884,13 +915,6 @@ Shader "HDRP/Toon"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
#endif #endif
// The light loop (or lighting architecture) is in charge to:
// - Define light list
// - Define the light loop
// - Setup the constant/data
// - Do the reflection hierarchy
// - Provide sampling function for shadowmap, ies, cookie and reflection (depends on the specific use with the light loops like index array or atlas or single and texture format (cubemap/latlong))
#define HAS_LIGHTLOOP #define HAS_LIGHTLOOP
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl"
@@ -901,8 +925,6 @@ 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/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/Material/Lit/LitData.hlsl"
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsHead.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" #include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/ShaderPass/HDRPToonOutline.hlsl"
@@ -928,6 +950,9 @@ Shader "HDRP/Toon"
HLSLPROGRAM HLSLPROGRAM
#define SHADERPASS SHADERPASS_SHADOWS #define SHADERPASS SHADERPASS_SHADOWS
#pragma shader_feature_local _ALPHATEST_ON
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitDepthPass.hlsl"

View File

@@ -50,6 +50,57 @@ float3 UtsComputeDiffuseColor(float3 baseColor, float metallic)
return UtsComputeDiffuseColor(baseColor, metallic, 0.0); return UtsComputeDiffuseColor(baseColor, metallic, 0.0);
} }
float Random(float2 uv)
{
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
}
float unity_noise_interpolate (float a, float b, float t)
{
return (1.0-t)*a + (t*b);
}
float ValueNoise (float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
f = f * f * (3.0 - 2.0 * f);
uv = abs(frac(uv) - 0.5);
float2 c0 = i + float2(0.0, 0.0);
float2 c1 = i + float2(1.0, 0.0);
float2 c2 = i + float2(0.0, 1.0);
float2 c3 = i + float2(1.0, 1.0);
float r0 = Random(c0);
float r1 = Random(c1);
float r2 = Random(c2);
float r3 = Random(c3);
float bottomOfGrid = unity_noise_interpolate(r0, r1, f.x);
float topOfGrid = unity_noise_interpolate(r2, r3, f.x);
float t = unity_noise_interpolate(bottomOfGrid, topOfGrid, f.y);
return t;
}
float SimpleNoise(float2 UV, float Scale)
{
float t = 0.0;
float freq = pow(2.0, float(0));
float amp = pow(0.5, float(3-0));
t += ValueNoise(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
freq = pow(2.0, float(1));
amp = pow(0.5, float(3-1));
t += ValueNoise(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
freq = pow(2.0, float(2));
amp = pow(0.5, float(3-2));
t += ValueNoise(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
return t;
}
#define SampleRampSignalLine(texture, u) (SAMPLE_TEXTURE2D_LOD(texture, s_linear_clamp_sampler, float2(u, 0.5), 0)) #define SampleRampSignalLine(texture, u) (SAMPLE_TEXTURE2D_LOD(texture, s_linear_clamp_sampler, float2(u, 0.5), 0))
// Exposure // Exposure

View File

@@ -124,11 +124,11 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V)
float4 normalLocal = float4(0, 0, 1.0, 1.0); float4 normalLocal = float4(0, 0, 1.0, 1.0);
#if _NORMALMAP #if _NORMALMAP
if (_Use_SSSLut) // if (_Use_SSSLut)
{ // {
normalLocal = SAMPLE_TEXTURE2D_LOD(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap), _SSSIntensity); // normalLocal = SAMPLE_TEXTURE2D_LOD(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap), _SSSIntensity);
} // }
else // else
{ {
normalLocal = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)); normalLocal = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
normalLocal.rgb = UnpackNormalScale(normalLocal, _NormalScale); normalLocal.rgb = UnpackNormalScale(normalLocal, _NormalScale);
@@ -173,11 +173,13 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V)
smoothness *=_BSDFContribution; smoothness *=_BSDFContribution;
#endif #endif
#ifdef _PBR_Mode_TOON // TODO: Specular color is not handle correctly.
#ifdef _PBR_MODE_TOON
metallic = 0.0;
specularColor = _SpecularColor;
#ifdef _SPECULARCOLORMAP #ifdef _SPECULARCOLORMAP
specularColor = SAMPLE_TEXTURE2D(_SpecularColorMap, sampler_SpecularColorMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)).rgb * _SpecularColor; specularColor *= SAMPLE_TEXTURE2D(_SpecularColorMap, sampler_SpecularColorMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)).rgb;
#endif #endif
specularColor = GetSpecularColor(output.baseColor, metallic);
#endif #endif
output.metallic = metallic; output.metallic = metallic;
@@ -190,7 +192,8 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V)
output.geomNormalWS = input.tangentToWorld[2]; output.geomNormalWS = input.tangentToWorld[2];
output.tangentWS = Orthonormalize(input.tangentToWorld[0].rgb, normalWS); output.tangentWS = Orthonormalize(input.tangentToWorld[0].rgb, normalWS);
output.subsurfaceColor = SAMPLE_TEXTURE2D(_SSSLutMap, s_linear_clamp_sampler, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)) * _SSSIntensity; // output.subsurfaceColor = SAMPLE_TEXTURE2D(_SSSLutMap, s_linear_clamp_sampler, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)) * _SSSIntensity;
output.subsurfaceColor = 0.0;
output.anisotropy = anisotropy; output.anisotropy = anisotropy;
@@ -203,12 +206,19 @@ UtsBSDFData ConvertUTSSurfaceDataToUTSBSDFData(UTSSurfaceData surfaceData)
output.surfaceFeatures = surfaceData.surfaceFeatures; output.surfaceFeatures = surfaceData.surfaceFeatures;
output.diffuseColor = UtsComputeDiffuseColor(surfaceData.baseColor, surfaceData.metallic, 0.05); #if _PBR_MODE_TOON
output.firstShadingDiffuseColor = UtsComputeDiffuseColor(surfaceData.firstShadingColor, surfaceData.metallic, 0.05); float m = Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b);
output.secondShadingDiffuseColor = UtsComputeDiffuseColor(surfaceData.secondShadingColor, surfaceData.metallic, 0.05); #else
float m = surfaceData.metallic;
#endif
output.diffuseColor = UtsComputeDiffuseColor(surfaceData.baseColor, m, _Minimal_Diffuse_Contribution);
output.firstShadingDiffuseColor = UtsComputeDiffuseColor(surfaceData.firstShadingColor, m, _Minimal_Diffuse_Contribution);
output.secondShadingDiffuseColor = UtsComputeDiffuseColor(surfaceData.secondShadingColor, m, _Minimal_Diffuse_Contribution);
#if _PBR_MODE_OFF #if _PBR_MODE_OFF
output.fresnel0 = surfaceData.baseColor; output.fresnel0 = 0.22;
#elif _PBR_MODE_TOON
output.fresnel0 = surfaceData.specularColor;
#else #else
output.fresnel0 = ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, 0.22); output.fresnel0 = ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, 0.22);
#endif #endif

View File

@@ -295,7 +295,7 @@ void UtsGetSurfaceAndBuiltinData(FragInputs input, float3 V, inout PositionInput
#else #else
float alphaCutoff = _AlphaCutoff; float alphaCutoff = _AlphaCutoff;
#endif #endif
// clip(-0.1);
GENERIC_ALPHA_TEST(alphaValue, alphaCutoff); GENERIC_ALPHA_TEST(alphaValue, alphaCutoff);
#endif #endif

View File

@@ -1,6 +1,22 @@
#ifndef UTS_SURFACE_FEATURE_EVALUATION #ifndef UTS_SURFACE_FEATURE_EVALUATION
#define UTS_SURFACE_FEATURE_EVALUATION #define UTS_SURFACE_FEATURE_EVALUATION
void UtsEvaluateLighting_Stocking(FragInputs input, PositionInputs posInput, float3 normalWS, float3 V, inout AggregateLighting aggregateLighting)
{
float NdotV = saturate(dot(normalize(V), normalWS));
NdotV = pow(NdotV, 2.0);
// TODO: Move sparkle to bsdf evaluation?
// float sparkle = Random(posInput.positionNDC.xy);
// sparkle = step(0.995, sparkle);
// float noise = SimpleNoise(posInput.positionNDC.xy, 500.0);
// sparkle = noise < sparkle ? 1.0 : 0.0;
aggregateLighting.direct.diffuse *= NdotV;
// aggregateLighting.direct.specular = saturate(aggregateLighting.direct.specular + sparkle * (1.0 - NdotV) * 0.5);
}
DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData bsdfData, PreLightData preLightData DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData bsdfData, PreLightData preLightData
#if _LIGHT_BASE_RIM_LIGHT_ON #if _LIGHT_BASE_RIM_LIGHT_ON
, float3 L, float3 lightColor , float3 L, float3 lightColor
@@ -11,6 +27,7 @@ DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData
ZERO_INITIALIZE(DirectLighting, lighting); ZERO_INITIALIZE(DirectLighting, lighting);
float3 rimLightColor = _RimLightColor.rgb * _RimLightIntensity; float3 rimLightColor = _RimLightColor.rgb * _RimLightIntensity;
rimLightColor = lerp(rimLightColor, rimLightColor * bsdfData.diffuseColor.rgb, _AlbedoAffectRimLight * _RimLightColor.a);
#if _SCREEN_SPACE_RIM_LIGHT_ON #if _SCREEN_SPACE_RIM_LIGHT_ON
float3 normalVS = normalize(mul((float3x3)UNITY_MATRIX_V, bsdfData.geomNormalWS)); float3 normalVS = normalize(mul((float3x3)UNITY_MATRIX_V, bsdfData.geomNormalWS));

View File

@@ -11,13 +11,6 @@ void UTS_OtherLights(LightLoopContext lightLoopContext, FragInputs input, UTSLig
// We dont have to calculate lighting here if we are using sdf shadow // We dont have to calculate lighting here if we are using sdf shadow
#ifndef _SDFShadow #ifndef _SDFShadow
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode != 0)
{
return float3(0.0f, 0.0f, 0.0f);
}
#endif // _IS_CLIPPING_MATTE
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
// input.positionSS is SV_Position // input.positionSS is SV_Position

View File

@@ -194,9 +194,10 @@ IndirectLighting UtsEvaluateBSDF_MatCapSpecular(float3 positionWS, UtsBSDFData b
return lighting; return lighting;
} }
void UtsEvaluateBSDF_Ramp(PositionInputs posInput, UtsBSDFData bsdfData, float3 L, inout BuiltinData builtinData) void UtsEvaluateBSDF_Ramp(PositionInputs posInput, UtsBSDFData bsdfData, inout BuiltinData builtinData)
{ {
// TODO float3 lighting = SAMPLE_TEXTURE2D_ARRAY(_IndirectDiffuseRampMap, s_trilinear_clamp_sampler, float2(_IndirectDiffuseRampPosition, 0.0), _IndirectDiffuseRampIndex).rgb;
builtinData.bakeDiffuseLighting = lighting * GetInverseCurrentExposureMultiplier();
} }
IndirectLighting UtsEvaluateBSDF_Env(LightLoopContext lightLoopContext, PositionInputs posInput, PreLightData preLightData, EnvLightData lightData, UtsBSDFData bsdfData, int influenceShapeType, int GPUImageBasedLightingType, inout float hierarchyWeight) IndirectLighting UtsEvaluateBSDF_Env(LightLoopContext lightLoopContext, PositionInputs posInput, PreLightData preLightData, EnvLightData lightData, UtsBSDFData bsdfData, int influenceShapeType, int GPUImageBasedLightingType, inout float hierarchyWeight)

View File

@@ -53,6 +53,17 @@ bool UtsUseScreenSpaceShadow(DirectionalLightData light, float3 normalWS)
#endif #endif
} }
bool IsNonZeroBSDF(float3 L, UtsBSDFData bsdfData)
{
#if _MATERIAL_TYPE_FACE
return true;
#else
float NdotL = dot(bsdfData.normalWS, L);
return NdotL > 0.0;
#endif
}
void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bsdfData, BuiltinData builtinData, void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bsdfData, BuiltinData builtinData,
float3 V, uint featureFlags, out LightLoopOutput lightLoopOutput) float3 V, uint featureFlags, out LightLoopOutput lightLoopOutput)
{ {
@@ -87,6 +98,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
float3 L = -light.forward; float3 L = -light.forward;
// Is it worth sampling the shadow map? // Is it worth sampling the shadow map?
// Should we skip it if NdotL is negative? (i.e. transmission)
if ((light.lightDimmer > 0) && (light.shadowDimmer > 0)) if ((light.lightDimmer > 0) && (light.shadowDimmer > 0))
{ {
context.shadowValue = GetDirectionalShadowAttenuation(context.shadowContext, context.shadowValue = GetDirectionalShadowAttenuation(context.shadowContext,
@@ -317,7 +329,6 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
AccumulateIndirectLighting(lighting, aggregateLighting); AccumulateIndirectLighting(lighting, aggregateLighting);
} }
} }
} }
} }
#elif _INDIRECT_SPECULAR_MODE_MATCAP #elif _INDIRECT_SPECULAR_MODE_MATCAP
@@ -346,6 +357,11 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
#endif #endif
} }
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_STOCKING))
{
UtsEvaluateLighting_Stocking(fragInputs, posInput, bsdfData.normalWS, V, aggregateLighting);
}
#ifndef _LIGHT_BASE_RIM_LIGHT_ON #ifndef _LIGHT_BASE_RIM_LIGHT_ON
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_RIM_LIGHT)) if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_RIM_LIGHT))
{ {

View File

@@ -57,17 +57,21 @@ float3 ComputeSpecularTerm(UtsBSDFData bsdfData, PreLightData preLightData, floa
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness)); float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness));
DV = D_KajiyaKay(t, H, specularExponent); DV = D_KajiyaKay(t, H, specularExponent);
float normalizeSpec = DV * rcp(specularExponent + 2) * 2 * PI; float normalizeSpec = DV * rcp(specularExponent + 2.0) * TWO_PI;
DV = DV * normalizeSpec * _KKColor.rgb; DV = DV * normalizeSpec * _KKColor.rgb;
#elif _PBR_MODE_FABRIC
float D = D_Charlie(NdotH, bsdfData.roughnessT);
// V_Charlie is expensive, use approx with V_Ashikhmin instead
// float V = V_Charlie(NdotL, clampedNdotV, bsdfData.roughness);
float Vis = V_Ashikhmin(NdotL, clampedNdotV);
DV = D * Vis;
#elif _PBR_MODE_TOON #elif _PBR_MODE_TOON
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness)); float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness));
DV = pow(NdotH, 5.0 * specularExponent); DV = pow(NdotH, 5.0 * specularExponent);
DV = StepFeatherToon(DV, _ToonSpecularStep, _ToonSpecularFeather); DV = StepFeatherToon(DV, _ToonSpecularStep, _ToonSpecularFeather);
//specTerm = pow(NdotH, 5.0 * specularExponent);
//specTerm = StepFeatherToon(specTerm, _ToonSpecularStep, _ToonSpecularFeather);
//return specTerm * ColorSpaceDielectricSpec.rgb * clampedNdotL;
#endif #endif
// We use specularFGD here to approximate F.
specTerm = DV * preLightData.specularFGD * clampedNdotL; specTerm = DV * preLightData.specularFGD * clampedNdotL;
return specTerm; return specTerm;
#endif #endif
@@ -139,14 +143,14 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
float NdotL = dot(bsdfData.normalWS, L); float NdotL = dot(bsdfData.normalWS, L);
float halfLambert = 0.5 * NdotL + 0.5; float halfLambert = 0.5 * NdotL + 0.5;
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(halfLambert * shadow.x, rampMask), _ShadingIndex, 0.0).rgb; float3 rampColor = SAMPLE_TEXTURE2D_ARRAY(_ShadingRampMap, s_linear_clamp_sampler, float2(halfLambert * shadow.x, rampMask), _ShadingIndex).rgb;
diffuseTerm = bsdfData.diffuseColor * rampColor; diffuseTerm = bsdfData.diffuseColor * rampColor * INV_PI;
specularTerm *= saturate(NdotL) * sharpShadow; specularTerm *= saturate(NdotL) * sharpShadow;
#elif _SHADING_MODE_SDF #elif _SHADING_MODE_SDF
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * sharpShadow.x, rampMask), _ShadingIndex, 0.0).rgb; float3 rampColor = SAMPLE_TEXTURE2D_ARRAY(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * sharpShadow.x, rampMask), _ShadingIndex).rgb;
diffuseTerm = bsdfData.diffuseColor * rampColor; diffuseTerm = bsdfData.diffuseColor * rampColor * INV_PI;
specularTerm = (specularTerm + sdfHighlight) * sdfShadowMask * sharpShadow; specularTerm = (specularTerm + sdfHighlight) * sdfShadowMask * sharpShadow;
#endif #endif
#else #else
@@ -161,12 +165,12 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
// float secondColorFeatherForMask = lerp(_2ndShadeColorFeather, 0.0, max(_SecondShadeOverridden, _ComposerMaskMode)); // float secondColorFeatherForMask = lerp(_2ndShadeColorFeather, 0.0, max(_SecondShadeOverridden, _ComposerMaskMode));
float firstShadeMask = saturate((halfLambert - (_2ndShadeColorStep - _2ndShadeColorFeather)) / (_2ndShadeColorStep - (_2ndShadeColorStep - _2ndShadeColorFeather))); float firstShadeMask = saturate((halfLambert - (_2ndShadeColorStep - _2ndShadeColorFeather)) / (_2ndShadeColorStep - (_2ndShadeColorStep - _2ndShadeColorFeather)));
diffuseTerm = lerp(lerp(bsdfData.secondShadingDiffuseColor, bsdfData.firstShadingDiffuseColor, firstShadeMask), bsdfData.diffuseColor, baseShadeMask); diffuseTerm = lerp(lerp(bsdfData.secondShadingDiffuseColor, bsdfData.firstShadingDiffuseColor, firstShadeMask), bsdfData.diffuseColor, baseShadeMask) * INV_PI;
specularTerm *= baseShadeMask; specularTerm *= baseShadeMask;
#elif _SHADING_MODE_SDF #elif _SHADING_MODE_SDF
float shadeMask = sdfShadowMask * sdfTexture.b * sharpShadow.x; float shadeMask = sdfShadowMask * sdfTexture.b * sharpShadow.x;
diffuseTerm = lerp(bsdfData.firstShadingDiffuseColor, bsdfData.diffuseColor, shadeMask); diffuseTerm = lerp(bsdfData.firstShadingDiffuseColor, bsdfData.diffuseColor, shadeMask) * INV_PI;
specularTerm = (specularTerm + sdfHighlight) * shadeMask; specularTerm = (specularTerm + sdfHighlight) * shadeMask;
#endif #endif
#endif #endif

View File

@@ -41,12 +41,13 @@ float GetHairShadow(PositionInputs posInput, float3 L)
float2 shadowLength = float2(shadowLengthY * 2.0f, shadowLengthY); float2 shadowLength = float2(shadowLengthY * 2.0f, shadowLengthY);
float3 cameraDirOS = normalize(TransformWorldToObject(GetCameraPositionWS())); float3 cameraDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
float cameraDirFactor = 1 - smoothstep(0.1, 0.9, cameraDirOS.y); float cameraDirFactor = 1.0 - smoothstep(0.1, 0.9, cameraDirOS.y);
shadowLength.y *= cameraDirFactor; // shadowLength.y *= cameraDirFactor;
float2 samplingPoint = (posInput.positionSS + shadowLength * viewLightDir.xy * (_ScreenSize.xy / float2(1920.0f, 1080.0f))) * _ScreenSize.zw; // Use 1080p as the reference resolution to achieve consistent shadow lengths across various screen resolutions. // TODO: sample point is still shifting when fov change.
float2 samplingPoint = (posInput.positionSS + shadowLength * viewLightDir.xy) * _ScreenSize.zw; // Use 1080p as the reference resolution to achieve consistent shadow lengths across various screen resolutions.
float2 scaledUVs = samplingPoint * _HairShadowRTHandleScale.xy; // We have to including the scaling factor for our shadow map since we are not going to allocate new texture if the rendering resolution changed. float2 scaledUVs = samplingPoint * _RTHandleScale.xy; // We have to including the scaling factor for our shadow map since we are not going to allocate new texture if the rendering resolution changed.
float hairShadow = SAMPLE_TEXTURE2D_SHADOW(_HairShadowTex, s_linear_clamp_compare_sampler, float3(scaledUVs, posInput.deviceDepth + _HairShadowDepthBias)).r; float hairShadow = SAMPLE_TEXTURE2D_SHADOW(_HairShadowTex, s_linear_clamp_compare_sampler, float3(scaledUVs, posInput.deviceDepth + _HairShadowDepthBias)).r;
shadow = lerp(1.0 - hairShadowOpacity, 1.0, hairShadow); shadow = lerp(1.0 - hairShadowOpacity, 1.0, hairShadow);
} }

View File

@@ -62,11 +62,11 @@ float _ToonIgnoreExposureMultiplier;
float _Outline_MaxWidth; float _Outline_MaxWidth;
float4 _HairShadowRTHandleScale;
float4 _HairBlendingRTHandleScale;
float _HairShadowDistance; float _HairShadowDistance;
float _HairShadowDistanceScaleFactor; float _HairShadowDistanceScaleFactor;
float _HairShadowDepthBias; float _HairShadowDepthBias;
float _HairShadowFadeInDistance; float _HairShadowFadeInDistance;
float _HairShadowFadeOutDistance; float _HairShadowFadeOutDistance;
// float2 _HairShadowRTHandleScale;
// float2 _HairBlendingRTHandleScale;

View File

@@ -42,6 +42,8 @@ TEXTURE2D_X(_HairBlendingTex);
TEXTURE2D(_IndirectDiffuseMatCapMap); TEXTURE2D(_IndirectDiffuseMatCapMap);
TEXTURE2D(_IndirectSpecularMatCapMap); TEXTURE2D(_IndirectSpecularMatCapMap);
TEXTURE2D_ARRAY(_IndirectDiffuseRampMap);
TEXTURE2D(_ClippingMask); TEXTURE2D(_ClippingMask);
TEXTURE2D(_AngelRingColorMap); TEXTURE2D(_AngelRingColorMap);

View File

@@ -1,5 +1,7 @@
// Surface Option // Surface Option
float _SurfaceFeatures; float _SurfaceFeatures;
half _AlphaCutoffEnable;
float _AlphaCutoff;
// Shading Color // Shading Color
float4 _BaseColor; float4 _BaseColor;
@@ -7,8 +9,8 @@ float4 _BaseColorMap_ST;
float4 _BaseColorMap_TexelSize; float4 _BaseColorMap_TexelSize;
float4 _BaseColorMap_MipInfo; float4 _BaseColorMap_MipInfo;
float _ShadingIndex; int _ShadingIndex;
half _ShadingRampMask; float _ShadingRampMask;
float4 _1stShadeColor; float4 _1stShadeColor;
float4 _2ndShadeColor; float4 _2ndShadeColor;
@@ -58,8 +60,8 @@ float _ToonSpecularFeather;
float _BSDFContribution; float _BSDFContribution;
float _EnergyConservingSpecularColor; float _EnergyConservingSpecularColor;
float _SSSIntensity; // float _SSSIntensity;
int _Use_SSSLut; // int _Use_SSSLut;
float3 _EmissiveColor; float3 _EmissiveColor;
half _AlbedoAffectEmissive; half _AlbedoAffectEmissive;
@@ -70,6 +72,9 @@ float _ObjectSpaceUVMappingEmissive;
// Ambient // Ambient
float _IndirectDiffuseMatCapLod; float _IndirectDiffuseMatCapLod;
int _IndirectDiffuseRampIndex;
float _IndirectDiffuseRampPosition;
float _IndirectDiffuseIntensity; float _IndirectDiffuseIntensity;
float _SSAOWeight; float _SSAOWeight;
float _SSGIWeight; float _SSGIWeight;
@@ -82,6 +87,7 @@ float _SSRWeight;
//Rim Light //Rim Light
float4 _RimLightColor; float4 _RimLightColor;
float _RimLightIntensity; float _RimLightIntensity;
half _AlbedoAffectRimLight;
float _RimLightLevel; float _RimLightLevel;
half _RimLightClipping; half _RimLightClipping;
float _RimLightClippingLevel; float _RimLightClippingLevel;
@@ -114,15 +120,17 @@ float _HairBlendingFactor;
// Advance // Advance
half _ClampLightColor; half _ClampLightColor;
float _LightIntensityMultiplier; float _LightIntensityMultiplier;
float _Minimal_Diffuse_Contribution;
// Light Loop // Light Loop
float3 _ObjectCenterPositionWS; float3 _ObjectCenterPositionWS;
// NOTE: Not sure what these are for // NOTE: Not sure what these are for
// float _FirstShadeOverridden; // float _FirstShadeOverridden;
// float _SecondShadeOverridden; // float _SecondShadeOverridden;
float _UseShadowThreshold;
float _AlphaCutoffShadow;
float _ComposerMaskMode; float _ComposerMaskMode;
#if defined(_UTS_TOON_EV_PER_MODEL) #if defined(_UTS_TOON_EV_PER_MODEL)

View File

@@ -63,7 +63,7 @@ void Frag(PackedVaryingsToPS packedInput,
#ifdef _DEPTHOFFSET_ON #ifdef _DEPTHOFFSET_ON
, out float outputDepth : SV_Depth , out float outputDepth : SV_Depth
#endif #endif
) )
{ {
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh); FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
@@ -73,7 +73,6 @@ void Frag(PackedVaryingsToPS packedInput,
// The following temporary definition of unity_AmbientEquator is for HDRP only. // The following temporary definition of unity_AmbientEquator is for HDRP only.
//float4 unity_AmbientEquator = float4(0.05, 0.05, 0.05, 1.0); //Todo. //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 = 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_GradientEquator = ShadeSH9(float4(0, 1, 0, 0));
float3 envLightSource_SkyboxIntensity = max( float3 envLightSource_SkyboxIntensity = max(
@@ -83,8 +82,8 @@ void Frag(PackedVaryingsToPS packedInput,
float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator; float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator;
ambientSkyColor *= GetCurrentExposureMultiplier(); ambientSkyColor *= GetCurrentExposureMultiplier();
float4 _BlendingTex_var = SAMPLE_TEXTURE2D(_HairBlendingMap, sampler_HairBlendingMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap)); float4 blendingTex = SAMPLE_TEXTURE2D(_HairBlendingMap, sampler_HairBlendingMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
outColor = float4(_BlendingTex_var.rgb * ambientSkyColor, _BlendingTex_var.a); outColor = float4(blendingTex.rgb + ambientSkyColor, blendingTex.a);
#ifdef _DEPTHOFFSET_ON #ifdef _DEPTHOFFSET_ON
outputDepth = posInput.deviceDepth; outputDepth = posInput.deviceDepth;

View File

@@ -82,12 +82,7 @@ void Frag(PackedVaryingsToPS packedInput,
discard; discard;
} }
#endif #endif
#ifdef _IS_CLIPPING_MATTE
if (_ClippingMatteMode != 0)
{
discard;
}
#endif // _IS_CLIPPING_MATTE
#if defined(UTS_DEBUG_SHADOWMAP_NO_OUTLINE) #if defined(UTS_DEBUG_SHADOWMAP_NO_OUTLINE)
discard; discard;
#endif #endif

View File

@@ -1,6 +1,4 @@
//Unity Toon Shader/HDRP #include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsLitData.hlsl"
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#define APPROXIMATE_POLY_LIGHT_AS_SPHERE_LIGHT #define APPROXIMATE_POLY_LIGHT_AS_SPHERE_LIGHT
@@ -97,7 +95,6 @@ void Frag(PackedVaryingsToPS packedInput,
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize(); uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex); PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
#ifdef VARYINGS_NEED_POSITION_WS #ifdef VARYINGS_NEED_POSITION_WS
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS); float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
@@ -121,7 +118,7 @@ void Frag(PackedVaryingsToPS packedInput,
SurfaceData tempSurfaceData; SurfaceData tempSurfaceData;
BuiltinData builtinData; BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, tempSurfaceData, builtinData); UtsGetSurfaceAndBuiltinData(input, V, posInput, tempSurfaceData, builtinData);
UTSSurfaceData surfaceData = GetUTSSurfaceData(input, V); UTSSurfaceData surfaceData = GetUTSSurfaceData(input, V);
UtsBSDFData bsdfData = ConvertUTSSurfaceDataToUTSBSDFData(surfaceData); UtsBSDFData bsdfData = ConvertUTSSurfaceDataToUTSBSDFData(surfaceData);
@@ -132,9 +129,7 @@ void Frag(PackedVaryingsToPS packedInput,
context.shadowContext = InitShadowContext(); context.shadowContext = InitShadowContext();
context.shadowValue = 1; context.shadowValue = 1;
context.sampleReflection = 0.0; context.sampleReflection = 0.0;
#if UNITY_VERSION >= 202120 && UNITY_VERSION < 202320
context.splineVisibility = -1;
#endif
#ifdef APPLY_FOG_ON_SKY_REFLECTIONS #ifdef APPLY_FOG_ON_SKY_REFLECTIONS
context.positionWS = posInput.positionWS; context.positionWS = posInput.positionWS;
#endif #endif
@@ -146,31 +141,17 @@ void Frag(PackedVaryingsToPS packedInput,
// Initialize the contactShadow and contactShadowFade fields // Initialize the contactShadow and contactShadowFade fields
InitContactShadow(posInput, context); InitContactShadow(posInput, context);
float channelAlpha = 0.0f;
LightLoopOutput lightLoopOutput; LightLoopOutput lightLoopOutput;
ZERO_INITIALIZE(LightLoopOutput, lightLoopOutput); ZERO_INITIALIZE(LightLoopOutput, lightLoopOutput);
UtsLightLoop(input, posInput, bsdfData, builtinData, V, featureFlags, lightLoopOutput); UtsLightLoop(input, posInput, bsdfData, builtinData, V, featureFlags, lightLoopOutput);
float3 finalColor = lightLoopOutput.diffuseLighting + lightLoopOutput.specularLighting; outColor = ApplyBlendMode(lightLoopOutput.diffuseLighting, lightLoopOutput.specularLighting, builtinData.opacity);
#ifdef _IS_TRANSCLIPPING_OFF
outColor = float4(finalColor, 1 * ApplyChannelAlpha(channelAlpha));
#elif _IS_TRANSCLIPPING_ON
float Set_Opacity = saturate((inverseClipping + _Tweak_transparency));
outColor = EvaluateAtmosphericScattering(posInput, V, float4(finalColor, 1));
outColor = float4(outColor.rgb, Set_Opacity * ApplyChannelAlpha(channelAlpha));
#endif
#if _MATERIAL_TYPE_FRONTHAIR && ENABLE_UTS_HAIR_BLENDING #if _MATERIAL_TYPE_FRONTHAIR && ENABLE_UTS_HAIR_BLENDING
float2 screenUV = posInput.positionNDC * _HairBlendingRTHandleScale.xy; float2 screenUV = posInput.positionSS; // * _HairBlendingRTHandleScale.xy; // Why we don't need to scale? Does unity handle it internally?
float4 hairBlendingMap = LOAD_TEXTURE2D_X(_HairBlendingTex, screenUV); float4 hairBlendingTex = LOAD_TEXTURE2D_X(_HairBlendingTex, screenUV);
outColor.rgb = lerp(outColor.rgb, hairBlendingMap.rgb, hairBlendingMap.a * _HairBlendingFactor); outColor.rgb = lerp(outColor.rgb, hairBlendingTex.rgb, hairBlendingTex.a * _HairBlendingFactor);
#endif #endif
#if UTS_DEBUG_SHADOWMAP || UTS_DEBUG_SELFSHADOW #if UTS_DEBUG_SHADOWMAP || UTS_DEBUG_SELFSHADOW

View File

@@ -21,15 +21,12 @@ namespace Misaki.HdrpToon
private const string _TOON_LIGHT_FILTER_PROP_NAME = "_ToonLightHiCutFilter"; private const string _TOON_LIGHT_FILTER_PROP_NAME = "_ToonLightHiCutFilter";
private const string _IGNORE_VOLUME_EXPOSURE_PROP_NAME = "_ToonIgnoreExposureMultiplier"; private const string _IGNORE_VOLUME_EXPOSURE_PROP_NAME = "_ToonIgnoreExposureMultiplier";
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_PROP_NAME = "_HairShadowDistance";
private const string _HAIR_SHADOW_DISTANCE_SCALE_PROP_NAME = "_HairShadowDistanceScaleFactor"; 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_DEPTH_BIAS_PROP_NAME = "_HairShadowDepthBias";
private const string _HAIR_SHADOW_FADEIN_PROP_NAME = "_HairShadowFadeInDistance"; private const string _HAIR_SHADOW_FADEIN_PROP_NAME = "_HairShadowFadeInDistance";
private const string _HAIR_SHADOW_FADE_OUT_PROP_NAME = "_HairShadowFadeOutDistance"; private const string _HAIR_SHADOW_FADE_OUT_PROP_NAME = "_HairShadowFadeOutDistance";
private const string _HAIR_BLENDING_RTHANDLE_SCALE_PROP_NAME = "_HairBlendingRTHandleScale";
private const string _HAIR_SHADOW_RT_PROP_NAME = "_HairShadowTex"; private const string _HAIR_SHADOW_RT_PROP_NAME = "_HairShadowTex";
private const string _HAIR_BLENDING_PROP_NAME = "_HairBlendingTex"; private const string _HAIR_BLENDING_PROP_NAME = "_HairBlendingTex";
@@ -43,7 +40,9 @@ namespace Misaki.HdrpToon
private RTHandle _hairShadowRTHandle; private RTHandle _hairShadowRTHandle;
private bool _needReallocateHairShadow; private bool _needReallocateHairShadow;
// TODO: Possible to avoid another RTHandle for depth?
private RTHandle _hairBlendingRTHandle; private RTHandle _hairBlendingRTHandle;
private RTHandle _hairBlendingDepthRTHandle;
private bool _needReallocateHairBlending; private bool _needReallocateHairBlending;
private bool _enableHairShadow; private bool _enableHairShadow;
@@ -142,15 +141,16 @@ namespace Misaki.HdrpToon
} }
#endif #endif
var scale = _hairShadowQuality switch // Use R8 or R16 directly?
var format = _hairShadowQuality switch
{ {
BufferQuality.Low => new Vector2(0.5f, 0.5f), BufferQuality.Low => GraphicsFormat.D16_UNorm,
BufferQuality.High => Vector2.one, BufferQuality.High => GraphicsFormat.D32_SFloat,
_ => Vector2.zero _ => GraphicsFormat.R16G16B16A16_SFloat
}; };
_hairShadowRTHandle?.Release(); _hairShadowRTHandle?.Release();
_hairShadowRTHandle = RTHandles.Alloc(scale, useDynamicScale: true, format: GraphicsFormat.D16_UNorm, isShadowMap: true, name: _HAIR_SHADOW_RT_PROP_NAME); _hairShadowRTHandle = RTHandles.Alloc(Vector2.one, useDynamicScale: true, format: format, isShadowMap: true, name: _HAIR_SHADOW_RT_PROP_NAME);
Shader.SetGlobalTexture(_HAIR_SHADOW_RT_PROP_NAME, _hairShadowRTHandle); Shader.SetGlobalTexture(_HAIR_SHADOW_RT_PROP_NAME, _hairShadowRTHandle);
_needReallocateHairShadow = false; _needReallocateHairShadow = false;
@@ -179,6 +179,13 @@ namespace Misaki.HdrpToon
_hairBlendingRTHandle?.Release(); _hairBlendingRTHandle?.Release();
_hairBlendingRTHandle = RTHandles.Alloc(Vector2.one, useDynamicScale: true, dimension: TextureXR.dimension, colorFormat: format, name: _HAIR_BLENDING_PROP_NAME); _hairBlendingRTHandle = RTHandles.Alloc(Vector2.one, useDynamicScale: true, dimension: TextureXR.dimension, colorFormat: format, name: _HAIR_BLENDING_PROP_NAME);
if (_hairBlendingDepthRTHandle == null || _hairBlendingDepthRTHandle.rt == null || !_hairBlendingDepthRTHandle.rt.IsCreated())
{
_hairBlendingDepthRTHandle?.Release();
_hairBlendingDepthRTHandle = RTHandles.Alloc(Vector2.one, useDynamicScale: true, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.D16_UNorm, name: _HAIR_BLENDING_PROP_NAME + "_depth");
}
Shader.SetGlobalTexture(_HAIR_BLENDING_PROP_NAME, _hairBlendingRTHandle); Shader.SetGlobalTexture(_HAIR_BLENDING_PROP_NAME, _hairBlendingRTHandle);
_needReallocateHairBlending = false; _needReallocateHairBlending = false;
@@ -274,7 +281,6 @@ namespace Misaki.HdrpToon
CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(result)); CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(result));
Shader.SetGlobalVector(_HAIR_SHADOW_RTHANDLE_SCALE_PROP_NAME, _hairShadowRTHandle.rtHandleProperties.rtHandleScale);
Shader.SetGlobalFloat(_HAIR_SHADOW_DISTANCE_PROP_NAME, utsRenderer.shadowDistance.value); 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_DISTANCE_SCALE_PROP_NAME, utsRenderer.shadowDistanceScale.value);
Shader.SetGlobalFloat(_HAIR_SHADOW_DEPTH_BIAS_PROP_NAME, utsRenderer.shadowDepthBias.value); Shader.SetGlobalFloat(_HAIR_SHADOW_DEPTH_BIAS_PROP_NAME, utsRenderer.shadowDepthBias.value);
@@ -298,7 +304,7 @@ namespace Misaki.HdrpToon
using (new ProfilingScope(ctx.cmd, _hairBlendingProfilingSampler)) using (new ProfilingScope(ctx.cmd, _hairBlendingProfilingSampler))
{ {
CoreUtils.SetRenderTarget(ctx.cmd, _hairBlendingRTHandle, ctx.cameraDepthBuffer, ClearFlag.Color); CoreUtils.SetRenderTarget(ctx.cmd, _hairBlendingRTHandle, _hairBlendingDepthRTHandle, ClearFlag.Color | ClearFlag.Depth);
var result = new RendererListDesc(UtsShaderPassName.hairBlendingTargetPassId, ctx.cullingResults, ctx.hdCamera.camera) var result = new RendererListDesc(UtsShaderPassName.hairBlendingTargetPassId, ctx.cullingResults, ctx.hdCamera.camera)
{ {
@@ -308,7 +314,6 @@ namespace Misaki.HdrpToon
}; };
CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(result)); CoreUtils.DrawRendererList(ctx.renderContext, ctx.cmd, ctx.renderContext.CreateRendererList(result));
Shader.SetGlobalVector(_HAIR_BLENDING_RTHANDLE_SCALE_PROP_NAME, _hairBlendingRTHandle.rtHandleProperties.rtHandleScale);
} }
} }
@@ -326,6 +331,7 @@ namespace Misaki.HdrpToon
_exposureArray = null; _exposureArray = null;
_hairShadowRTHandle?.Release(); _hairShadowRTHandle?.Release();
_hairBlendingRTHandle?.Release(); _hairBlendingRTHandle?.Release();
_hairBlendingDepthRTHandle?.Release();
} }
} }
} }

View File

@@ -19,7 +19,7 @@ namespace Misaki.HdrpToon
public BoolParameter enableHairShadow = new(false); public BoolParameter enableHairShadow = new(false);
public ClampedFloatParameter shadowDistance = new(5.0f, 0.0f, 20.0f); public ClampedFloatParameter shadowDistance = new(5.0f, 0.0f, 20.0f);
public ClampedFloatParameter shadowDistanceScale = new(0.5f, 0.0f, 1.0f); public ClampedFloatParameter shadowDistanceScale = new(0.5f, 0.0f, 1.0f);
public ClampedFloatParameter shadowDepthBias = new(0f, 0.0f, 0.01f); public ClampedFloatParameter shadowDepthBias = new(0f, -0.01f, 0.01f);
public FloatParameter shadowFadeIn = new(45f); public FloatParameter shadowFadeIn = new(45f);
public FloatParameter shadowFadeOut = new(50f); public FloatParameter shadowFadeOut = new(50f);

View File

@@ -1,6 +1,6 @@
{ {
"name": "com.misaki.hdrp-toon", "name": "com.misaki.hdrp-toon",
"version": "2.1.0", "version": "3.0.1-pre",
"displayName": "HDRP Toon", "displayName": "HDRP Toon",
"description": "A high quality toon shader for High Definition Render Pipeline(HDRP)", "description": "A high quality toon shader for High Definition Render Pipeline(HDRP)",
"changelogUrl": "https://git.personalnas.com/Misaki/hdrp-toon/src/branch/develop/CHANGELOG.md", "changelogUrl": "https://git.personalnas.com/Misaki/hdrp-toon/src/branch/develop/CHANGELOG.md",
@@ -21,6 +21,6 @@
}, },
"dependencies": { "dependencies": {
"com.unity.render-pipelines.high-definition": "17.0.0", "com.unity.render-pipelines.high-definition": "17.0.0",
"com.misaki.shader-gui": "1.1.2" "com.misaki.shader-gui": "1.1.4"
} }
} }