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);
}
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)
{
if (!material.HasProperty(SurfaceOptions.SURFACE_FEATURE))
@@ -36,5 +46,10 @@ namespace Misaki.HdrpToon.Editor
var value = (SurfaceFeature)material.GetInteger(SurfaceOptions.SURFACE_FEATURE);
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,
Rimlight = 1 << 7,
MatCap = 1 << 8,
AngelRing = 1 << 9,
Emission = 1 << 10,
Outline = 1 << 11,
TessellationLegacy = 1 << 12,
Stocking = 1 << 9,
AngelRing = 1 << 10,
Emission = 1 << 11,
Outline = 1 << 12,
TessellationHDRP = 1 << 13,
SceneLight = 1 << 14,
EnvironmentalLightEffectiveness = 1 << 15,

View File

@@ -10,6 +10,8 @@ namespace Misaki.HdrpToon.Editor
{
private static class Properties
{
public static MaterialProperty diffuseMin;
public static MaterialProperty lightIntensityMultiplier;
public static MaterialProperty clampLightColor;
@@ -18,6 +20,8 @@ namespace Misaki.HdrpToon.Editor
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 clampLightColorText = new("Clamp Light Color", "Specifies whether to clamp the light color.");
@@ -30,6 +34,8 @@ namespace Misaki.HdrpToon.Editor
public override void LoadMaterialProperties()
{
Properties.diffuseMin = FindProperty(MINIMAL_DIFFUSE_CONTRIBUTION);
Properties.lightIntensityMultiplier = FindProperty(LIGHT_INTENSITY_MULTIPLIER);
Properties.clampLightColor = FindProperty(CLAMP_LIGHT_COLOR);
@@ -38,10 +44,12 @@ namespace Misaki.HdrpToon.Editor
protected override void DrawContent()
{
editor.ShaderProperty(Properties.diffuseMin, Styles.diffuseMinText);
editor.ShaderProperty(Properties.lightIntensityMultiplier, Styles.lightIntensityMultiplierText);
editor.ShaderProperty(Properties.clampLightColor, Styles.clampLightColorText);
editor.ShaderProperty(Properties.lightLoopMode, Styles.lightLoopModeText);
}
}
}
}

View File

@@ -17,6 +17,10 @@ namespace Misaki.HdrpToon.Editor
public static MaterialProperty indirectDiffuseMatCapMap;
public static MaterialProperty indirectDiffuseMatCapLod;
public static MaterialProperty indirectDiffuseRampMap;
public static MaterialProperty indirectDiffuseRampIndex;
public static MaterialProperty indirectDiffuseRampPosition;
public static MaterialProperty indirectDiffuseIntensity;
public static MaterialProperty ssaoWeight;
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 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 ssaoWeightText = new("SSAO Weight", "The weight of SSAO.");
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.indirectDiffuseMatCapLod = FindProperty("_IndirectDiffuseMatCapLod");
Properties.indirectDiffuseRampMap = FindProperty("_IndirectDiffuseRampMap");
Properties.indirectDiffuseRampIndex = FindProperty("_IndirectDiffuseRampIndex");
Properties.indirectDiffuseRampPosition = FindProperty("_IndirectDiffuseRampPosition");
Properties.indirectDiffuseIntensity = FindProperty("_IndirectDiffuseIntensity");
Properties.ssaoWeight = FindProperty("_SSAOWeight");
Properties.ssgiWeight = FindProperty("_SSGIWeight");
@@ -64,6 +75,36 @@ namespace Misaki.HdrpToon.Editor
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()
{
editor.ShaderProperty(Properties.indirectDiffuseMode, Styles.indirectDiffuseModeText);
@@ -74,41 +115,43 @@ namespace Misaki.HdrpToon.Editor
if (indirectDiffuseMode != IndirectDiffuseMode.Off)
{
EditorGUILayout.Space();
using (var indentLevelScope = new EditorGUI.IndentLevelScope(-1))
DrawIndirectDiffuseHeader();
switch (indirectDiffuseMode)
{
EditorGUILayout.LabelField("Indirect Diffuse", EditorStyles.boldLabel);
case IndirectDiffuseMode.IBL:
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 (indirectDiffuseMode == IndirectDiffuseMode.Matcap)
{
editor.TexturePropertySingleLine(Styles.indirectDiffuseMatCapMapText, Properties.indirectDiffuseMatCapMap, Properties.indirectDiffuseMatCapLod);
}
editor.ShaderProperty(Properties.indirectDiffuseIntensity, Styles.indirectDiffuseIntensityText);
editor.ShaderProperty(Properties.ssaoWeight, Styles.ssaoWeightText);
if (indirectDiffuseMode == IndirectDiffuseMode.IBL)
{
editor.ShaderProperty(Properties.ssgiWeight, Styles.ssgiWeightText);
}
DrawIndirectDiffuseProperties();
}
if (indirectSpecularMode != (int)IndirectSpecularMode.Off)
if (indirectSpecularMode != IndirectSpecularMode.Off)
{
EditorGUILayout.Space();
using (var indentLevelScope = new EditorGUI.IndentLevelScope(-1))
DrawIndirectSpecularHeader();
switch (indirectSpecularMode)
{
EditorGUILayout.LabelField("Indirect Specular", EditorStyles.boldLabel);
case IndirectSpecularMode.IBL:
break;
case IndirectSpecularMode.Matcap:
editor.TexturePropertySingleLine(Styles.indirectSpecularMatCapMapText, Properties.indirectSpecularMatCapMap, Properties.indirectSpecularMatCapLod);
break;
default:
break;
}
if (indirectSpecularMode == IndirectSpecularMode.Matcap)
{
editor.TexturePropertySingleLine(Styles.indirectSpecularMatCapMapText, Properties.indirectSpecularMatCapMap, Properties.indirectSpecularMatCapLod);
}
editor.ShaderProperty(Properties.indirectReflectionIntensity, Styles.indirectReflectionIntensityText);
editor.ShaderProperty(Properties.ssrWeight, Styles.ssrWeightText);
DrawIndirectSpecularProperties();
}
}
}

View File

@@ -14,6 +14,7 @@ namespace Misaki.HdrpToon.Editor
public static MaterialProperty rimLightColor;
public static MaterialProperty rimLightIntensity;
public static MaterialProperty albedoAffectRimLight;
public static MaterialProperty screenSpaceRimLight;
public static MaterialProperty rimLightLevel;
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 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 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");
@@ -46,6 +48,7 @@ namespace Misaki.HdrpToon.Editor
Properties.rimLightColor = FindProperty(RIM_LIGHT_COLOR);
Properties.rimLightIntensity = FindProperty(RIM_LIGHT_INTENSITY);
Properties.albedoAffectRimLight = FindProperty(ALBEDO_AFFECT_RIM_LIGHT);
Properties.screenSpaceRimLight = FindProperty(SCREEN_SPACE_RIM_LIGHT);
Properties.rimLightLevel = FindProperty(RIM_LIGHT_LEVEL);
Properties.rimLightClipping = FindProperty(RIM_LIGHT_CLIPPING);
@@ -60,6 +63,7 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.rimLightColor, Styles.rimLightColorText);
editor.ShaderProperty(Properties.rimLightIntensity, Styles.rimLightIntensityText);
editor.ShaderProperty(Properties.albedoAffectRimLight, Styles.albedoAffectRimLightText);
editor.ShaderProperty(Properties.screenSpaceRimLight, Styles.screenSpaceRimLightText);
editor.ShaderProperty(Properties.rimLightLevel, Styles.rimLightLevelText);

View File

@@ -34,6 +34,8 @@ namespace Misaki.HdrpToon.Editor
public static MaterialProperty sdfShadowLevel;
public static MaterialProperty sdfSmoothLevel;
public static MaterialProperty sdfHighlightStrength;
public static MaterialProperty hairBlendingFactor;
}
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 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;
@@ -108,6 +112,8 @@ namespace Misaki.HdrpToon.Editor
Properties.sdfShadowLevel = FindProperty("_SDFShadowLevel");
Properties.sdfSmoothLevel = FindProperty("_SDFShadowSmoothLevel");
Properties.sdfHighlightStrength = FindProperty("_SDFHighlightStrength");
Properties.hairBlendingFactor = FindProperty("_HairBlendingFactor");
}
protected override void DrawContent()
@@ -144,6 +150,12 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.sdfHighlightStrength, Styles.sdfHighlightStrengthText);
}
if (materials.All(material => material.GetMaterialType() == MaterialType.FrontHair))
{
EditorGUILayout.Space();
editor.ShaderProperty(Properties.hairBlendingFactor, Styles.hairBlendingFactorText);
}
EditorGUILayout.Space();
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
{
public static MaterialProperty NormalMap;
public static MaterialProperty NormalMapScale;
public static MaterialProperty normalMap;
public static MaterialProperty normalMapScale;
public static MaterialProperty MaskMap;
public static MaterialProperty Metallic;
public static MaterialProperty MetallicRemapMin;
public static MaterialProperty MetallicRemapMax;
public static MaterialProperty AORemapMin;
public static MaterialProperty AORemapMax;
public static MaterialProperty Smoothness;
public static MaterialProperty SmoothnessRemapMin;
public static MaterialProperty SmoothnessRemapMax;
public static MaterialProperty maskMap;
public static MaterialProperty metallic;
public static MaterialProperty metallicRemapMin;
public static MaterialProperty metallicRemapMax;
public static MaterialProperty aoRemapMin;
public static MaterialProperty aoRemapMax;
public static MaterialProperty smoothness;
public static MaterialProperty smoothnessRemapMin;
public static MaterialProperty smoothnessRemapMax;
public static MaterialProperty AnisotropyMap;
public static MaterialProperty Anisotropy;
public static MaterialProperty KKColor;
public static MaterialProperty BSDFContribution;
public static MaterialProperty anisotropyMap;
public static MaterialProperty anisotropy;
public static MaterialProperty kkColor;
public static MaterialProperty bsdfContribution;
public static MaterialProperty SpecularColorMap;
public static MaterialProperty SpecularColor;
public static MaterialProperty SpecularFeather;
public static MaterialProperty SpecularStep;
public static MaterialProperty specularColorMap;
public static MaterialProperty specularColor;
public static MaterialProperty specularFeather;
public static MaterialProperty specularStep;
public static MaterialProperty hairBlendingMap;
public static MaterialProperty emissiveColorLDR;
public static MaterialProperty emissiveColorMap;
@@ -45,21 +47,23 @@ namespace Misaki.HdrpToon.Editor
private static class Styles
{
public static readonly GUIContent NormalMapText = new("Normal Map", "A texture that dictates the bumpiness of the material.");
public static readonly GUIContent MaskMapText = new("Mask Map", "A texture that dictates the physical properties of the material. R channel for metallic, G channel for ambient occlusion, A channel for smoothness");
public static readonly GUIContent MetallicText = new("Metallic", "Specifies the metallic value of the material.");
public static readonly GUIContent MetallicRemap = new("Metallic Remap", "Remap the max and min value of metallic");
public static readonly GUIContent AORemap = new("AO Remap", "Remap the max and min value of ambient occlusion");
public static readonly GUIContent SmoothnessText = new("Smoothness", "Specifies the smoothness of the material.");
public static readonly GUIContent SmoothnessRemapText = new("Smoothness Remap", "Remap the max and min value of smoothness");
public static readonly GUIContent normalMapText = new("Normal Map", "A texture that dictates the bumpiness of the material.");
public static readonly GUIContent maskMapText = new("Mask Map", "A texture that dictates the physical properties of the material. R channel for metallic, G channel for ambient occlusion, A channel for smoothness");
public static readonly GUIContent metallicText = new("Metallic", "Specifies the metallic value of the material.");
public static readonly GUIContent metallicRemap = new("Metallic Remap", "Remap the max and min value of metallic");
public static readonly GUIContent aoRemap = new("AO Remap", "Remap the max and min value of ambient occlusion");
public static readonly GUIContent smoothnessText = new("Smoothness", "Specifies the smoothness of the material.");
public static readonly GUIContent smoothnessRemapText = new("Smoothness Remap", "Remap the max and min value of smoothness");
public static readonly GUIContent AnisotropyMapText = new("Anisotropy Map", "Specifies the anisotropy map of the material.");
public static readonly GUIContent anisotropyMapText = new("Anisotropy Map", "Specifies the anisotropy map of the material.");
public static readonly GUIContent KKColorText = new("KK specular Color", "Specifies the color of KK specular.");
public static readonly GUIContent BSDFContributionText = new("BSDF Contribution", "BSDF smoothness contribution, 1 means KK Hair smoothness will fully contribute bsdf calculation");
public static readonly GUIContent kkColorText = new("KK specular Color", "Specifies the color of KK specular.");
public static readonly GUIContent bsdfContributionText = new("BSDF Contribution", "BSDF smoothness contribution, 1 means KK Hair smoothness will fully contribute bsdf calculation");
public static readonly GUIContent SpecularColorMapText = new("Specular Color Map", "Specifies the specular color map of the material.");
public static readonly GUIContent SpecRemap = new("Specular Remap", "Feather and step value of Toon Specular");
public static readonly GUIContent 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 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 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()
{
Properties.NormalMap = FindProperty("_NormalMap");
Properties.NormalMapScale = FindProperty("_NormalScale");
Properties.normalMap = FindProperty("_NormalMap");
Properties.normalMapScale = FindProperty("_NormalScale");
Properties.MaskMap = FindProperty("_MaskMap");
Properties.Metallic = FindProperty("_Metallic");
Properties.MetallicRemapMin = FindProperty("_MetallicRemapMin");
Properties.MetallicRemapMax = FindProperty("_MetallicRemapMax");
Properties.AORemapMin = FindProperty("_AORemapMin");
Properties.AORemapMax = FindProperty("_AORemapMax");
Properties.SmoothnessRemapMin = FindProperty("_SmoothnessRemapMin");
Properties.SmoothnessRemapMax = FindProperty("_SmoothnessRemapMax");
Properties.Smoothness = FindProperty("_Smoothness");
Properties.maskMap = FindProperty("_MaskMap");
Properties.metallic = FindProperty("_Metallic");
Properties.metallicRemapMin = FindProperty("_MetallicRemapMin");
Properties.metallicRemapMax = FindProperty("_MetallicRemapMax");
Properties.aoRemapMin = FindProperty("_AORemapMin");
Properties.aoRemapMax = FindProperty("_AORemapMax");
Properties.smoothnessRemapMin = FindProperty("_SmoothnessRemapMin");
Properties.smoothnessRemapMax = FindProperty("_SmoothnessRemapMax");
Properties.smoothness = FindProperty("_Smoothness");
Properties.AnisotropyMap = FindProperty("_AnisotropyMap");
Properties.Anisotropy = FindProperty("_Anisotropy");
Properties.KKColor = FindProperty("_KKColor");
Properties.BSDFContribution = FindProperty("_BSDFContribution");
Properties.anisotropyMap = FindProperty("_AnisotropyMap");
Properties.anisotropy = FindProperty("_Anisotropy");
Properties.kkColor = FindProperty("_KKColor");
Properties.bsdfContribution = FindProperty("_BSDFContribution");
Properties.SpecularColorMap = FindProperty("_SpecularColorMap");
Properties.SpecularColor = FindProperty("_SpecularColor");
Properties.SpecularFeather = FindProperty("_ToonSpecularFeather");
Properties.SpecularStep = FindProperty("_ToonSpecularStep");
Properties.specularColorMap = FindProperty("_SpecularColorMap");
Properties.specularColor = FindProperty("_SpecularColor");
Properties.specularFeather = FindProperty("_ToonSpecularFeather");
Properties.specularStep = FindProperty("_ToonSpecularStep");
Properties.hairBlendingMap = FindProperty("_HairBlendingMap");
Properties.emissiveColorLDR = FindProperty(EMISSIVE_COLOR_LDR);
Properties.emissiveColorMap = FindProperty(EMISSIVE_COLOR_MAP);
@@ -106,46 +112,55 @@ namespace Misaki.HdrpToon.Editor
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 (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.AORemapMin, Properties.AORemapMax, 0, 1, Styles.AORemap);
editor.MinMaxShaderProperty(Properties.SmoothnessRemapMin, Properties.SmoothnessRemapMax, 0, 1, Styles.SmoothnessRemapText);
editor.MinMaxShaderProperty(Properties.metallicRemapMin, Properties.metallicRemapMax, 0, 1, Styles.metallicRemap);
editor.MinMaxShaderProperty(Properties.aoRemapMin, Properties.aoRemapMax, 0, 1, Styles.aoRemap);
editor.MinMaxShaderProperty(Properties.smoothnessRemapMin, Properties.smoothnessRemapMax, 0, 1, Styles.smoothnessRemapText);
}
else
{
if (materials.All(mat => mat.GetPBRMode() != PBRMode.KKHair))
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();
editor.KeywordTexturePropertySingleLine(Styles.AnisotropyMapText, Properties.AnisotropyMap, Properties.Anisotropy);
if (materials.All(mat => mat.GetPBRMode() == PBRMode.KKHair))
editor.KeywordTexturePropertySingleLine(Styles.anisotropyMapText, Properties.anisotropyMap, Properties.anisotropy);
if (materials.All(mat => mat.GetPBRMode() == PBRMode.Hair))
{
editor.ShaderProperty(Properties.KKColor, Styles.KKColorText);
editor.ShaderProperty(Properties.BSDFContribution, Styles.BSDFContributionText);
editor.ShaderProperty(Properties.kkColor, Styles.kkColorText);
editor.ShaderProperty(Properties.bsdfContribution, Styles.bsdfContributionText);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Anisotropy Map only ST");
editor.TextureScaleOffsetProperty(Properties.AnisotropyMap);
editor.TextureScaleOffsetProperty(Properties.anisotropyMap);
}
else if (materials.All(mat => mat.GetPBRMode() == PBRMode.Toon))
{
EditorGUILayout.Space();
editor.KeywordTexturePropertySingleLine(Styles.SpecularColorMapText, Properties.SpecularColorMap, Properties.SpecularColor);
editor.MinMaxShaderProperty(Properties.SpecularFeather, Properties.SpecularStep, 0, 1, Styles.SpecRemap);
editor.KeywordTexturePropertySingleLine(Styles.specularColorMapText, Properties.specularColorMap, Properties.specularColor);
editor.MinMaxShaderProperty(Properties.specularFeather, Properties.specularStep, 0, 1, Styles.specRemap);
}
if (materials.All(mat => mat.IsHairBlendingTarget()))
{
editor.TexturePropertySingleLine(Styles.hairBlenderMapText, Properties.hairBlendingMap);
}
EditorGUILayout.Space();

View File

@@ -63,7 +63,7 @@ namespace Misaki.HdrpToon.Editor
editor.ShaderProperty(Properties.transparentMode, Styles.transparentModeText);
editor.ShaderProperty(Properties.alphaClipEnable, Styles.alphaClipEnableText);
if (Properties.alphaClipEnable.floatValue == 1.0f)
if (Properties.alphaClipEnable.GetBooleanValue())
{
EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.alphaClip, Styles.alphaClipText);
@@ -90,7 +90,7 @@ namespace Misaki.HdrpToon.Editor
{
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 UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
namespace Misaki.HdrpToon.Editor
{
@@ -8,6 +9,28 @@ namespace Misaki.HdrpToon.Editor
{
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)
{
if (!initialized)

View File

@@ -41,7 +41,7 @@ The HDRP Toon Shader is designed to provide a high-quality toon shading effect f
## Example
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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,8 +4,6 @@ Shader "HDRP/Toon"
{
//TODO: Use custom rendering data.
[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
_AlphaCutoffPrepass("_AlphaCutoffPrepass", 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][ToggleUI] _ZWrite("__zw", Float) = 1.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] _TransparentCullMode("_TransparentCullMode", Int) = 2 // Back culling by default
[HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal
@@ -72,7 +69,6 @@ Shader "HDRP/Toon"
_Color("Color", Color) = (1,1,1,1)
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
@@ -86,12 +82,12 @@ Shader "HDRP/Toon"
// Surface Options
[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
[Enum(Off, 0, Front, 1, Back, 2)] _CullMode("Cull Mode", Integer) = 2
[KeywordEnum(Standard, SDF)] _Shading_Mode("Shading mode", Integer) = 0
[KeywordEnum(Standard, FrontHair, Face, Eye)] _Material_Type("Material Type", Integer) = 0
[KeywordEnum(Off, Standard, Anisotropy, 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
[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
_SDFHighlightStrength("SDFHighlightStrength", Range(0.0, 1.0)) = 0.75
_HairBlendingFactor("HairBlendingFactor", Range(0.0, 1.0)) = 0.5
// Shadow
[Popup] _Receive_Light_Shadow("Receive Light Shadow", Integer) = 0
[Popup] _Receive_Screen_Space_Shadow("Receive Screen Space Shadow", Integer) = 0
[Popup] _Receive_Hair_Shadow("Receive Hair Shadow", Integer) = 0
_ShadowDistanceBias("ShadowBias", Range(0.0, 5.0)) = 0.0
_ShadowNormalBias("ShadowNormalBias", Range(0.0, 5.0)) = 0.0
_ShadowNormalBias("ShadowNormalBias", Range(-5.0, 5.0)) = 0.0
//_Tweak_SystemShadowsLevel("Tweak_SystemShadowsLevel", Range(-0.5, 0.5)) = 0
// Surface Inputs
@@ -150,7 +148,7 @@ Shader "HDRP/Toon"
_Anisotropy("Anisotropy", Range(-1.0, 1.0)) = 0
_AnisotropyMap("AnisotropyMap", 2D) = "white" {}
_KKColor("BaseColor", Color) = (1,1,1,1)
_BSDFContribution("_BSDFContribution", Range(0.0,1.0)) = 0
@@ -187,12 +185,17 @@ Shader "HDRP/Toon"
_IndirectSpecularMatCapMap("IndirectSpecularMatCapMap", 2D) = "black" {}
_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
_SSRWeight("SSR Weight", Range(0.0, 1.0)) = 1.0
// Rim Light
_RimLightColor("Rim Light Color", Color) = (1, 1, 1, 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
_RimLightLevel("RimLight Level", Range(0, 1)) = 0.1
[ToggleUI] _RimLightClipping("Rim Light Clipping", Float) = 0.25
@@ -236,9 +239,26 @@ Shader "HDRP/Toon"
[ToggleUI] _UseSmoothedNormal("Use Smoothed Normal", Float) = 0
// 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
_Minimal_Diffuse_Contribution("Minimal_Diffuse_Contribution", Range(0, 1)) = 0.05
[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
@@ -249,15 +269,7 @@ Shader "HDRP/Toon"
//-------------------------------------------------------------------------------------
// Variant
//-------------------------------------------------------------------------------------
#pragma shader_feature_local _ALPHATEST_ON
#pragma shader_feature_local _DEPTHOFFSET_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 _ _REQUIRE_UV2 _REQUIRE_UV3
@@ -327,6 +339,7 @@ Shader "HDRP/Toon"
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
// 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
@@ -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/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 fragment Frag
@@ -430,6 +443,7 @@ Shader "HDRP/Toon"
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
// 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,
// both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
@@ -462,6 +476,8 @@ Shader "HDRP/Toon"
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#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/Lit/Lit.hlsl"
@@ -481,7 +497,7 @@ Shader "HDRP/Toon"
Tags{ "LightMode" = "DepthForwardOnly" }
Cull[_CullMode]
AlphaToMask [_AlphaCutoffEnable]
// To be able to tag stencil with disableSSR information for forward
Stencil
{
@@ -495,6 +511,12 @@ Shader "HDRP/Toon"
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 forward it output the normal buffer
#pragma multi_compile _ WRITE_NORMAL_BUFFER
@@ -534,6 +556,7 @@ Shader "HDRP/Toon"
}
Cull[_CullMode]
AlphaToMask [_AlphaCutoffEnable]
ZWrite On
@@ -541,6 +564,9 @@ Shader "HDRP/Toon"
#pragma multi_compile _ WRITE_NORMAL_BUFFER
#pragma multi_compile _ WRITE_MSAA_DEPTH
#pragma shader_feature_local _ALPHATEST_ON
#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/Lit/Lit.hlsl"
@@ -603,6 +629,9 @@ Shader "HDRP/Toon"
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define CUTOFF_TRANSPARENT_DEPTH_PREPASS
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
@@ -630,6 +659,9 @@ Shader "HDRP/Toon"
ZTest [_ZTestTransparent]
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#pragma multi_compile _ DEBUG_DISPLAY
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
@@ -677,24 +709,30 @@ Shader "HDRP/Toon"
Pass
{
Name "ForwardOnly"
Tags { "LightMode" = "ForwardOnly" }
Tags { "LightMode" = "ForwardOnly" }
ZWrite [_ZWriteMode]
ZTest [_ZTestMode]
ZTest [_ZTestDepthEqualForOpaque]
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]
Comp[_StencilComp]
Pass[_StencilOpPass]
Fail[_StencilOpFail]
}
HLSLPROGRAM
//#pragma multi_compile _ UTS_DEBUG_SHADOWMAP_BINALIZATION
#pragma multi_compile _ DEBUG_DISPLAY
#pragma multi_compile _ LIGHTMAP_ON
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
@@ -703,7 +741,7 @@ Shader "HDRP/Toon"
// Setup DECALS_OFF so the shader stripper can remove variants
#pragma multi_compile DECALS_OFF DECALS_3RT DECALS_4RT
#pragma multi_compile SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
#pragma multi_compile_fragment USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
//#pragma multi_compile_fragment PUNCTUAL_SHADOW_LOW PUNCTUAL_SHADOW_MEDIUM PUNCTUAL_SHADOW_HIGH
//#pragma multi_compile_fragment DIRECTIONAL_SHADOW_LOW DIRECTIONAL_SHADOW_MEDIUM DIRECTIONAL_SHADOW_HIGH
@@ -716,15 +754,7 @@ Shader "HDRP/Toon"
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(DEBUG_DISPLAY)
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
#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 ENABLE_UTS_HAIR_SHAOW
@@ -734,8 +764,8 @@ Shader "HDRP/Toon"
#pragma shader_feature_local_fragment _SHADING_MODE_STANDARD _SHADING_MODE_SDF
#pragma shader_feature_local_fragment _MATERIAL_TYPE_STANDARD _MATERIAL_TYPE_FRONTHAIR _MATERIAL_TYPE_FACE _MATERIAL_TYPE_EYE
#pragma shader_feature_local_fragment _PBR_MODE_OFF _PBR_MODE_STANDARD _PBR_MODE_ANISOTROPY _PBR_MODE_HAIR _PBR_MODE_TOON
#pragma shader_feature_local_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 _RECEIVE_LIGHT_SHADOW_ON
@@ -759,19 +789,18 @@ Shader "HDRP/Toon"
#pragma shader_feature_local_fragment _OUTLINECOLORMAP
#pragma shader_feature_local _ALPHATEST_ON
#define PUNCTUAL_SHADOW_MEDIUM
#define DIRECTIONAL_SHADOW_MEDIUM
#define AREA_SHADOW_MEDIUM
#ifndef SHADER_STAGE_FRAGMENT
#define SHADOW_LOW
#define USE_FPTL_LIGHTLIST
#endif
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(DEBUG_DISPLAY)
#define SHADERPASS_FORWARD_BYPASS_ALPHA_TEST
#endif
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl"
@@ -819,6 +848,9 @@ Shader "HDRP/Toon"
ColorMask 0
HLSLPROGRAM
#pragma shader_feature_local _ALPHATEST_ON
#define SHADERPASS SHADERPASS_DEPTH_ONLY
#define CUTOFF_TRANSPARENT_DEPTH_POSTPASS
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl"
@@ -866,11 +898,10 @@ Shader "HDRP/Toon"
Tags { "LightMode" = "Outline" }
Cull Front
Blend Off
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#define AREA_SHADOW_LOW
#define SHADERPASS SHADERPASS_FORWARD
#define SHADOW_LOW
@@ -884,13 +915,6 @@ Shader "HDRP/Toon"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
#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
#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/LitData.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"
@@ -928,6 +950,9 @@ Shader "HDRP/Toon"
HLSLPROGRAM
#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/Lit/Lit.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);
}
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))
// Exposure
@@ -243,4 +294,4 @@ float3 GetWorldPosFromDepthBuffer(float2 clipPos01, float cameraDepth)
return mul(unity_CameraToWorld, float4(localInvertDepthDirHD, 1.0)).xyz;
}
#endif
#endif

View File

@@ -25,12 +25,12 @@
struct UTSSurfaceData
{
uint surfaceFeatures;
real3 baseColor;
real3 firstShadingColor;
real3 secondShadingColor;
real alpha;
float3 normalWS;
real perceptualSmoothness;
real metallic;
@@ -40,35 +40,35 @@ struct UTSSurfaceData
float3 geomNormalWS;
float3 tangentWS;
real4 subsurfaceColor;
real anisotropy;
};
struct UtsBSDFData
{
uint surfaceFeatures;
real3 diffuseColor;
real3 firstShadingDiffuseColor;
real3 secondShadingDiffuseColor;
real3 fresnel0;
real fresnel90;
real reflectivity;
real ambientOcclusion;
real specularOcclusion;
real perceptualRoughness;
real3 subsurfaceColor;
float3 geomNormalWS;
float3 normalWS;
float3 tangentWS;
float3 bitangentWS;
real anisotropy;
real roughnessT;
real roughnessB;
@@ -103,7 +103,7 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V)
UTSSurfaceData output;
output.surfaceFeatures = _SurfaceFeatures;
float4 mainTexture = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
output.baseColor = mainTexture.rgb * _BaseColor.rgb;
output.alpha = mainTexture.a;
@@ -124,11 +124,11 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V)
float4 normalLocal = float4(0, 0, 1.0, 1.0);
#if _NORMALMAP
if (_Use_SSSLut)
{
normalLocal = SAMPLE_TEXTURE2D_LOD(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap), _SSSIntensity);
}
else
// if (_Use_SSSLut)
// {
// normalLocal = SAMPLE_TEXTURE2D_LOD(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap), _SSSIntensity);
// }
// else
{
normalLocal = SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, TRANSFORM_TEX(input.texCoord0, _BaseColorMap));
normalLocal.rgb = UnpackNormalScale(normalLocal, _NormalScale);
@@ -173,27 +173,30 @@ UTSSurfaceData GetUTSSurfaceData(FragInputs input, float3 V)
smoothness *=_BSDFContribution;
#endif
#ifdef _PBR_Mode_TOON
// TODO: Specular color is not handle correctly.
#ifdef _PBR_MODE_TOON
metallic = 0.0;
specularColor = _SpecularColor;
#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
specularColor = GetSpecularColor(output.baseColor, metallic);
#endif
output.metallic = metallic;
output.ambientOcclusion = ao;
output.specularOcclusion = GetSpecularOcclusionFromAmbientOcclusion(dot(normalWS, V), ao, PerceptualRoughnessToRoughness(1 - smoothness));
output.perceptualSmoothness = smoothness;
output.normalWS = normalWS;
output.specularColor = specularColor;
output.geomNormalWS = input.tangentToWorld[2];
output.tangentWS = Orthonormalize(input.tangentToWorld[0].rgb, normalWS);
output.subsurfaceColor = SAMPLE_TEXTURE2D(_SSSLutMap, s_linear_clamp_sampler, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)) * _SSSIntensity;
// output.subsurfaceColor = SAMPLE_TEXTURE2D(_SSSLutMap, s_linear_clamp_sampler, TRANSFORM_TEX(input.texCoord0, _BaseColorMap)) * _SSSIntensity;
output.subsurfaceColor = 0.0;
output.anisotropy = anisotropy;
return output;
}
@@ -202,13 +205,20 @@ UtsBSDFData ConvertUTSSurfaceDataToUTSBSDFData(UTSSurfaceData surfaceData)
UtsBSDFData output;
output.surfaceFeatures = surfaceData.surfaceFeatures;
output.diffuseColor = UtsComputeDiffuseColor(surfaceData.baseColor, surfaceData.metallic, 0.05);
output.firstShadingDiffuseColor = UtsComputeDiffuseColor(surfaceData.firstShadingColor, surfaceData.metallic, 0.05);
output.secondShadingDiffuseColor = UtsComputeDiffuseColor(surfaceData.secondShadingColor, surfaceData.metallic, 0.05);
#if _PBR_MODE_TOON
float m = Max3(surfaceData.specularColor.r, surfaceData.specularColor.g, surfaceData.specularColor.b);
#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
output.fresnel0 = surfaceData.baseColor;
output.fresnel0 = 0.22;
#elif _PBR_MODE_TOON
output.fresnel0 = surfaceData.specularColor;
#else
output.fresnel0 = ComputeFresnel0(surfaceData.baseColor, surfaceData.metallic, 0.22);
#endif
@@ -228,7 +238,7 @@ UtsBSDFData ConvertUTSSurfaceDataToUTSBSDFData(UTSSurfaceData surfaceData)
output.anisotropy = surfaceData.anisotropy;
ConvertAnisotropyToRoughness(output.perceptualRoughness, surfaceData.anisotropy, output.roughnessT, output.roughnessB);
return output;
}
@@ -242,7 +252,7 @@ PreLightData GetPreLightData_UTS(float3 V, PositionInputs posInput, inout UtsBSD
preLightData.iblPerceptualRoughness = bsdfData.perceptualRoughness;
float clampedNdotV = ClampNdotV(preLightData.NdotV);
// Handle IBL + area light + multiscattering.
// Note: use the not modified by anisotropy iblPerceptualRoughness here.
float specularReflectivity = 1.0;
@@ -583,4 +593,4 @@ float3 SampleBakedGI_UTS_OutLine(float3 positionRWS, float3 normalWS, float2 uvS
}
#endif //#ifndef UCTS_HDRP_INCLUDED
#endif //#ifndef UCTS_HDRP_INCLUDED

View File

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

View File

@@ -1,6 +1,22 @@
#ifndef 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
#if _LIGHT_BASE_RIM_LIGHT_ON
, float3 L, float3 lightColor
@@ -9,9 +25,10 @@ DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
float3 rimLightColor = _RimLightColor.rgb * _RimLightIntensity;
rimLightColor = lerp(rimLightColor, rimLightColor * bsdfData.diffuseColor.rgb, _AlbedoAffectRimLight * _RimLightColor.a);
#if _SCREEN_SPACE_RIM_LIGHT_ON
float3 normalVS = normalize(mul((float3x3)UNITY_MATRIX_V, bsdfData.geomNormalWS));
float2 depthUV = posInput.positionNDC.xy + normalVS.xy * (_RimLightLevel * 0.05 / posInput.linearDepth);
@@ -24,17 +41,17 @@ DirectLighting UtsEvaluateLighting_RimLight(PositionInputs posInput, UtsBSDFData
float rimLightMask = pow(1.0 - clampNdotV, exp2(lerp(3.0, 0.0, _RimLightLevel)));
rimLightMask = lerp(rimLightMask, step(_RimLightClippingLevel, rimLightMask), _RimLightClipping);
#endif
#if _LIGHT_BASE_RIM_LIGHT_ON
float halfLambert = 0.5 * dot(bsdfData.normalWS, L) + 0.5;
float lightBaseMask = saturate(smoothstep(_LightDirectionRimLightLevel, 1.0, halfLambert));
rimLightMask *= lightBaseMask;
rimLightColor *= lightColor;
#endif
lighting.diffuse = rimLightMask * rimLightColor;
return lighting;
}
@@ -42,7 +59,7 @@ DirectLighting UtsEvaluateLighting_AngelRing(FragInputs input, float3 normalWS,
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
// Should we scroll the angel ring texture on x?
float3 cameraRight = UNITY_MATRIX_V[0].xyz;
float3 cameraFront = UNITY_MATRIX_V[2].xyz;
@@ -53,18 +70,18 @@ DirectLighting UtsEvaluateLighting_AngelRing(FragInputs input, float3 normalWS,
float cameraRollCos = dot(rightAxis, cameraRight) / (rightAxisMagnitude * cameraRightMagnitude);
float3 cameraRoll = acos(clamp(cameraRollCos, -1.0, 1.0));
float cameraDir = cameraRight.y < 0 ? -1.0 : 1.0;
float2 arOffsetU = lerp(mul(UNITY_MATRIX_V, float4(normalWS, 0)).xyz, float3(0, 0, 1), _AngelRingOffsetU).xy;
arOffsetU = arOffsetU * 0.5 + 0.5;
float2 arvnRotate = RotateUV(arOffsetU, -(cameraDir * cameraRoll).x, 0.5, 1.0);
float2 arOffsetUV = float2(arvnRotate.x, lerp(input.texCoord0.y, arvnRotate.y, _AngelRingOffsetV));
float4 angelRingColor = SAMPLE_TEXTURE2D(_AngelRingColorMap, sampler_AngelRingColorMap, TRANSFORM_TEX(arOffsetUV, _AngelRingColorMap)) * _AngelRingColor * _AngelRingIntensity;
float weight = saturate(dot(normalize(V), normalWS));
lighting.specular = angelRingColor.r * angelRingColor.a * weight;
return lighting;
}
#endif
#endif

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
#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();
// input.positionSS is SV_Position

View File

@@ -45,21 +45,21 @@ DirectLighting UtsEvaluateBSDF_Directional(LightLoopContext lightLoopContext, Po
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
float3 L = -lightData.forward;
SHADOW_TYPE shadow = 1.0;
#if _RECEIVE_LIGHT_SHADOW_ON
shadow = EvaluateShadow_Directional(lightLoopContext, posInput, lightData, builtinData, bsdfData.geomNormalWS);
#endif
if (lightData.lightDimmer > 0.0)
{
// TODO: Colored shadow will overwrite the first and second shading diffuse color
//float3 shadowColor = ComputeShadowColor(shadow, lightData.shadowTint, lightData.penumbraTint);
float4 lightColor = EvaluateLight_Directional(lightLoopContext, posInput, lightData);
lightColor.rgb = GetLimitedLightColor(lightColor.rgb * lightColor.a * _LightIntensityMultiplier);
UtsClampRoughness(preLightData, bsdfData, lightData.minRoughness);
lighting = UtsShadeSurface(posInput, bsdfData, preLightData, shadow, lightColor.rgb, V, L, uv0, lightData.diffuseDimmer, lightData.specularDimmer);
@@ -72,28 +72,28 @@ DirectLighting UtsEvaluateBSDF_Punctual(LightLoopContext lightLoopContext, Posit
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
float3 L;
float4 distances; // {d, d^2, 1/d, d_proj}
GetPunctualLightVectors(posInput.positionWS, lightData, L, distances);
SHADOW_TYPE shadow = 1.0;
#if _RECEIVE_LIGHT_SHADOW_ON
shadow = UtsEvaluateShadow_Punctual(lightLoopContext, posInput, lightData, builtinData, UtsGetShadowNormal(bsdfData), L, distances);
#endif
if (lightData.lightDimmer > 0.0)
{
// TODO: Colored shadow will overwrite the first and second shading diffuse color
//float3 shadowColor = ComputeShadowColor(shadow, lightData.shadowTint, lightData.penumbraTint);
float4 lightColor = EvaluateLight_Punctual(lightLoopContext, posInput, lightData, L, distances);
lightColor.rgb = GetLimitedLightColor(lightColor.rgb * lightColor.a * _LightIntensityMultiplier);
UtsClampRoughness(preLightData, bsdfData, lightData.minRoughness);
lighting = UtsShadeSurface(posInput, bsdfData, preLightData, shadow, lightColor.rgb, V, L, uv0, lightData.diffuseDimmer, lightData.specularDimmer);
}
return lighting;
}
@@ -124,17 +124,17 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
lightInReflDir = float3(-1, -1, -1); // This variable is used with APV for reflection probe normalization - see code for LIGHTFEATUREFLAGS_ENV
#endif
#if defined(_PBR_MODE_OFF) || defined(_PBR_MODE_TOON)
float3 normalWS = float3(0.0, 0.0, 1.0);
#else
float3 normalWS = bsdfData.normalWS;
#endif
float3 backNormalWS = -normalWS;
// Reflect normal to get lighting for reflection probe tinting
float3 R = reflect(-V, normalWS);
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
if (_EnableProbeVolumes)
{
@@ -150,7 +150,7 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
builtinData.backBakeDiffuseLighting = EvaluateAmbientProbe(backNormalWS);
}
#endif
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SCREEN_SPACE_INDIRECT_DIFFUSE_DISABLED)
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF)
{
@@ -178,7 +178,7 @@ IndirectLighting UtsEvaluateBSDF_MatCapSpecular(float3 positionWS, UtsBSDFData b
{
IndirectLighting lighting;
ZERO_INITIALIZE(IndirectLighting, lighting);
float3 positionVS = mul(UNITY_MATRIX_V, float4(positionWS, 1.0)).xyz;
float3 normalVS = mul(UNITY_MATRIX_V, float4(bsdfData.normalWS, 1.0)).xyz;
float3 pcrossN = cross(normalize(positionVS), normalVS);
@@ -190,20 +190,21 @@ IndirectLighting UtsEvaluateBSDF_MatCapSpecular(float3 positionWS, UtsBSDFData b
float lod = clamp(PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness) + _IndirectSpecularMatCapLod, 0.0, 10.0);
lighting.specularReflected = SAMPLE_TEXTURE2D_LOD(_IndirectSpecularMatCapMap, s_trilinear_clamp_sampler, uv, lod).rgb;
lighting.specularReflected *= preLightData.specularFGD * GetInverseCurrentExposureMultiplier();
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 lighting;
ZERO_INITIALIZE(IndirectLighting, lighting);
float3 envLighting;
float3 positionWS = posInput.positionWS;
float weight = 1.0;
@@ -267,13 +268,13 @@ void UtsPostEvaluateBSDF(PositionInputs posInput, PreLightData preLightData, Uts
ApplyAmbientOcclusion(aoFactor, builtinData, lighting);
#endif
AdjustIndirectLighting(preLightData, bsdfData, builtinData, lighting);
// In regular pbr, we need to multiple diffuse color here with direct diffuse lighting. However, in UTS, we have already multiplied it when evaluating the direct diffuse since we need to apply the shading color.
lightLoopOutput.diffuseLighting = lighting.direct.diffuse + builtinData.bakeDiffuseLighting + builtinData.emissiveColor;
lightLoopOutput.specularLighting = lighting.direct.specular + lighting.indirect.specularReflected;
// Rescale the GGX to account for the multiple scattering.
lightLoopOutput.specularLighting *= 1.0 + bsdfData.fresnel0 * preLightData.energyCompensation;
ApplyExposureAdjustment(lightLoopOutput.diffuseLighting);
ApplyExposureAdjustment(lightLoopOutput.specularLighting);
}

View File

@@ -53,6 +53,17 @@ bool UtsUseScreenSpaceShadow(DirectionalLightData light, float3 normalWS)
#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,
float3 V, uint featureFlags, out LightLoopOutput lightLoopOutput)
{
@@ -66,7 +77,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
// Initialize the contactShadow and contactShadowFade fields
InitContactShadow(posInput, context);
#if _RECEIVE_LIGHT_SHADOW_ON
// First of all we compute the shadow value of the directional light to reduce the VGPR pressure
if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
@@ -87,6 +98,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
float3 L = -light.forward;
// 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))
{
context.shadowValue = GetDirectionalShadowAttenuation(context.shadowContext,
@@ -97,12 +109,12 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
}
}
#endif
PreLightData preLightData = GetPreLightData_UTS(V, posInput, bsdfData);
AggregateLighting aggregateLighting;
ZERO_INITIALIZE(AggregateLighting, aggregateLighting);
// Evaluate the punctual lights.
if (featureFlags & LIGHTFEATUREFLAGS_PUNCTUAL)
{
@@ -172,7 +184,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
}
}
}
// Evaluate the directional lights.
if (featureFlags & LIGHTFEATUREFLAGS_DIRECTIONAL)
{
@@ -232,7 +244,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
replaceBakeDiffuseLighting = true;
}
#endif
#if defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2)
if (!builtinData.isLightmap)
{
@@ -243,7 +255,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
#if defined(LIGHT_EVALUATION_SKIP_INDIRECT_DIFFUSE)
replaceBakeDiffuseLighting = false;
#endif
if (replaceBakeDiffuseLighting)
{
UtsEvaluateBSDF_BakeDiffuse(posInput, preLightData, bsdfData, V, builtinData, lightInReflDir);
@@ -257,7 +269,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
if (featureFlags & LIGHTFEATUREFLAGS_ENV)
{
#if _INDIRECT_SPECULAR_MODE_OFF
#elif _INDIRECT_SPECULAR_MODE_IBL
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES;
@@ -317,7 +329,6 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
AccumulateIndirectLighting(lighting, aggregateLighting);
}
}
}
}
#elif _INDIRECT_SPECULAR_MODE_MATCAP
@@ -345,7 +356,12 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
}
#endif
}
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_STOCKING))
{
UtsEvaluateLighting_Stocking(fragInputs, posInput, bsdfData.normalWS, V, aggregateLighting);
}
#ifndef _LIGHT_BASE_RIM_LIGHT_ON
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_RIM_LIGHT))
{
@@ -353,7 +369,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
AccumulateDirectLighting(lighting, aggregateLighting);
}
#endif
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_ANGEL_RING))
{
DirectLighting lighting = UtsEvaluateLighting_AngelRing(fragInputs, bsdfData.normalWS, V);
@@ -368,7 +384,7 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
// UTSLightData mainPunctualLight;
// uint lightCount, lightStart;
// #ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
// GetCountAndStart(posInput, LIGHTCATEGORY_PUNCTUAL, lightStart, lightCount);
// #else // LIGHTLOOP_DISABLE_TILE_AND_CLUSTER

View File

@@ -39,10 +39,10 @@ float3 ComputeSpecularTerm(UtsBSDFData bsdfData, PreLightData preLightData, floa
#elif _PBR_MODE_ANISOTROPY
float TdotV = dot(bsdfData.tangentWS, V);
float BdotV = dot(bsdfData.bitangentWS, V);
ConvertAnisotropyToRoughness(bsdfData.perceptualRoughness, bsdfData.anisotropy, bsdfData.roughnessT, bsdfData.roughnessB);
partLambdaV = GetSmithJointGGXAnisoPartLambdaV(TdotV, BdotV, clampedNdotV, bsdfData.roughnessT, bsdfData.roughnessB);
// For anisotropy we must not saturate these values
float TdotH = dot(bsdfData.tangentWS, H);
float TdotL = dot(bsdfData.tangentWS, L);
@@ -57,17 +57,21 @@ float3 ComputeSpecularTerm(UtsBSDFData bsdfData, PreLightData preLightData, floa
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness));
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;
#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
float specularExponent = RoughnessToBlinnPhongSpecularExponent(PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness));
DV = pow(NdotH, 5.0 * specularExponent);
DV = StepFeatherToon(DV, _ToonSpecularStep, _ToonSpecularFeather);
//specTerm = pow(NdotH, 5.0 * specularExponent);
//specTerm = StepFeatherToon(specTerm, _ToonSpecularStep, _ToonSpecularFeather);
//return specTerm * ColorSpaceDielectricSpec.rgb * clampedNdotL;
#endif
// We use specularFGD here to approximate F.
specTerm = DV * preLightData.specularFGD * clampedNdotL;
return specTerm;
#endif
@@ -110,14 +114,14 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
{
DirectLighting lighting;
ZERO_INITIALIZE(DirectLighting, lighting);
if (Max3(lightColor.r, lightColor.g, lightColor.b) > 0.0)
{
SHADOW_TYPE sharpShadow = smoothstep(0.4, 0.6, shadow);
#if _RECEIVE_HAIR_SHADOW_ON && ENABLE_UTS_HAIR_SHAOW
sharpShadow *= GetHairShadow(posInput, L);
#endif
#if _SHADING_MODE_SDF
float angle;
float3 sdfTexture = SampleSDFTexture(L, uv, angle); // r: sdf shadow, g: sdf highlight, b: halfshadow
@@ -125,7 +129,7 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
float sdfShadowMask = smoothstep(angle - shadowSmoothLevel, angle + shadowSmoothLevel, sdfTexture.r);
float sdfHighlight = sdfTexture.g * _SDFHighlightStrength;
#endif
float3 diffuseTerm = 0.0;
float3 specularTerm = ComputeSpecularTerm(bsdfData, preLightData, V, L);
@@ -138,22 +142,22 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
#if _SHADING_MODE_STANDARD
float NdotL = dot(bsdfData.normalWS, L);
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;
diffuseTerm = bsdfData.diffuseColor * rampColor;
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY(_ShadingRampMap, s_linear_clamp_sampler, float2(halfLambert * shadow.x, rampMask), _ShadingIndex).rgb;
diffuseTerm = bsdfData.diffuseColor * rampColor * INV_PI;
specularTerm *= saturate(NdotL) * sharpShadow;
#elif _SHADING_MODE_SDF
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY_LOD(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * sharpShadow.x, rampMask), _ShadingIndex, 0.0).rgb;
diffuseTerm = bsdfData.diffuseColor * rampColor;
float3 rampColor = SAMPLE_TEXTURE2D_ARRAY(_ShadingRampMap, s_linear_clamp_sampler, float2(sdfShadowMask * sharpShadow.x, rampMask), _ShadingIndex).rgb;
diffuseTerm = bsdfData.diffuseColor * rampColor * INV_PI;
specularTerm = (specularTerm + sdfHighlight) * sdfShadowMask * sharpShadow;
#endif
#else
#if _SHADING_MODE_STANDARD
float NdotL = dot(bsdfData.normalWS, L);
float halfLambert = 0.5 * NdotL + 0.5;
// float firstColorFeatherForMask = lerp(_1stShadeColorFeather, 0.0, max(_ComposerMaskMode, _FirstShadeOverridden));
float baseShadeMask = saturate((halfLambert - (_1stShadeColorStep - _1stShadeColorFeather)) / (_1stShadeColorStep - (_1stShadeColorStep - _1stShadeColorFeather)));
baseShadeMask *= sharpShadow.x;
@@ -161,30 +165,30 @@ DirectLighting UtsShadeSurface(PositionInputs posInput, UtsBSDFData bsdfData, Pr
// float secondColorFeatherForMask = lerp(_2ndShadeColorFeather, 0.0, max(_SecondShadeOverridden, _ComposerMaskMode));
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;
#elif _SHADING_MODE_SDF
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;
#endif
#endif
lighting.diffuse += diffuseTerm * lightColor * diffuseDimmer;
lighting.specular += specularTerm * lightColor * specularDimmer;
#if _LIGHT_BASE_RIM_LIGHT_ON
if (HasFlag(bsdfData.surfaceFeatures, SURFACEFEATURE_RIM_LIGHT))
{
DirectLighting rimLightLighting = UtsEvaluateLighting_RimLight(posInput, bsdfData, preLightData, L, lightColor);
lighting.diffuse += rimLightLighting.diffuse;
lighting.specular += rimLightLighting.specular;
}
#endif
}
return lighting;
}

View File

@@ -23,34 +23,35 @@ float3 SampleSDFTexture(float3 L, float2 uv, out float angle)
float2 lightDirection = normalize(L.xz);
angle = saturate(dot(forwardVector, lightDirection) * -1.0 + _SDFShadowLevel);
bool isRightSide = dot(lightDirection, leftVector) > 0;
return isRightSide ? right_SDFTex : left_SDFTex;
}
float GetHairShadow(PositionInputs posInput, float3 L)
{
float shadow = 1.0;
// Push the face fragment view space position towards the light for a little bit
float hairShadowOpacity = saturate(Remap(length(posInput.positionWS), float2(_HairShadowFadeOutDistance, _HairShadowFadeInDistance), float2(0, 1)));
if (hairShadowOpacity > 0.0)
{
float3 viewLightDir = TransformWorldToViewDir(L);
float shadowLengthY = _HairShadowDistance * 5.0 * max(0.5, posInput.linearDepth * _HairShadowDistanceScaleFactor) / posInput.linearDepth;
float2 shadowLength = float2(shadowLengthY * 2.0f, shadowLengthY);
float3 cameraDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
float cameraDirFactor = 1 - smoothstep(0.1, 0.9, cameraDirOS.y);
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.
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.
float3 cameraDirOS = normalize(TransformWorldToObject(GetCameraPositionWS()));
float cameraDirFactor = 1.0 - smoothstep(0.1, 0.9, cameraDirOS.y);
// shadowLength.y *= cameraDirFactor;
// 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 * _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;
shadow = lerp(1.0 - hairShadowOpacity, 1.0, hairShadow);
}
return shadow;
}
@@ -118,4 +119,4 @@ SHADOW_TYPE UtsEvaluateShadow_Punctual(LightLoopContext lightLoopContext, Positi
#endif
}
#endif
#endif

View File

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

View File

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

View File

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

View File

@@ -63,17 +63,16 @@ void Frag(PackedVaryingsToPS packedInput,
#ifdef _DEPTHOFFSET_ON
, out float outputDepth : SV_Depth
#endif
)
)
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
float4 objPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
float4 Set_UV0 = input.texCoord0;
// The following temporary definition of unity_AmbientEquator is for HDRP only.
//float4 unity_AmbientEquator = float4(0.05, 0.05, 0.05, 1.0); //Todo.
//v.2.0.9
//float3 envLightSource_GradientEquator = unity_AmbientEquator.rgb > 0.05 ? unity_AmbientEquator.rgb : half3(0.05, 0.05, 0.05);
float3 envLightSource_GradientEquator = ShadeSH9(float4(0, 1, 0, 0));
float3 envLightSource_SkyboxIntensity = max(
@@ -83,9 +82,9 @@ void Frag(PackedVaryingsToPS packedInput,
float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator;
ambientSkyColor *= GetCurrentExposureMultiplier();
float4 _BlendingTex_var = SAMPLE_TEXTURE2D(_HairBlendingMap, sampler_HairBlendingMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
outColor = float4(_BlendingTex_var.rgb * ambientSkyColor, _BlendingTex_var.a);
float4 blendingTex = SAMPLE_TEXTURE2D(_HairBlendingMap, sampler_HairBlendingMap, TRANSFORM_TEX(Set_UV0, _BaseColorMap));
outColor = float4(blendingTex.rgb + ambientSkyColor, blendingTex.a);
#ifdef _DEPTHOFFSET_ON
outputDepth = posInput.deviceDepth;
#endif

View File

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

View File

@@ -1,6 +1,4 @@
//Unity Toon Shader/HDRP
//nobuyuki@unity3d.com
//toshiyuki@unity3d.com (Universal RP/HDRP)
#include "Packages/com.misaki.hdrp-toon/Runtime/Shaders/Includes/Common/UtsLitData.hlsl"
#define APPROXIMATE_POLY_LIGHT_AS_SPHERE_LIGHT
@@ -80,7 +78,7 @@ void Frag(PackedVaryingsToPS packedInput,
#endif
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
FragInputs input = UnpackVaryingsMeshToFragInputs(packedInput.vmesh);
#if defined(PLATFORM_SUPPORTS_PRIMITIVE_ID_IN_PIXEL_SHADER) && SHADER_STAGE_FRAGMENT
#if (defined(VARYINGS_NEED_PRIMITIVEID) || (SHADERPASS == SHADERPASS_FULL_SCREEN_DEBUG))
@@ -91,24 +89,23 @@ void Frag(PackedVaryingsToPS packedInput,
#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT
input.isFrontFace = IS_FRONT_VFACE(packedInput.cullFace, true, false);
#endif
// We need to readapt the SS position as our screen space positions are for a low res buffer, but we try to access a full res buffer.
input.positionSS.xy = _OffScreenRendering > 0 ? (input.positionSS.xy * _OffScreenDownsampleFactor) : input.positionSS.xy;
uint2 tileIndex = uint2(input.positionSS.xy) / GetTileSize();
PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS.xyz, tileIndex);
#ifdef VARYINGS_NEED_POSITION_WS
float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
#ifdef MATERIAL_TYPE_EYE
// Must have view Dir to work
float2 viewT = TransformObjectToTangent(V, input.tangentToWorld);
float2 parallaxOffset = viewT;
parallaxOffset.y = -parallaxOffset.y;
input.texCoord0.xy = clamp(input.texCoord0.xy -_EyeParallaxAmount * parallaxOffset, 0, 1);
// Must have view Dir to work
float2 viewT = TransformObjectToTangent(V, input.tangentToWorld);
float2 parallaxOffset = viewT;
parallaxOffset.y = -parallaxOffset.y;
input.texCoord0.xy = clamp(input.texCoord0.xy -_EyeParallaxAmount * parallaxOffset, 0, 1);
#endif
#else
// Unused
float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
@@ -118,10 +115,10 @@ void Frag(PackedVaryingsToPS packedInput,
#else
uint featureFlags = LIGHT_FEATURE_MASK_FLAGS_OPAQUE;
#endif
SurfaceData tempSurfaceData;
BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, V, posInput, tempSurfaceData, builtinData);
UtsGetSurfaceAndBuiltinData(input, V, posInput, tempSurfaceData, builtinData);
UTSSurfaceData surfaceData = GetUTSSurfaceData(input, V);
UtsBSDFData bsdfData = ConvertUTSSurfaceDataToUTSBSDFData(surfaceData);
@@ -132,11 +129,9 @@ void Frag(PackedVaryingsToPS packedInput,
context.shadowContext = InitShadowContext();
context.shadowValue = 1;
context.sampleReflection = 0.0;
#if UNITY_VERSION >= 202120 && UNITY_VERSION < 202320
context.splineVisibility = -1;
#endif
#ifdef APPLY_FOG_ON_SKY_REFLECTIONS
context.positionWS = posInput.positionWS;
context.positionWS = posInput.positionWS;
#endif
// With XR single-pass and camera-relative: offset position to do lighting computations from the combined center view (original camera matrix).
@@ -145,32 +140,18 @@ void Frag(PackedVaryingsToPS packedInput,
// Initialize the contactShadow and contactShadowFade fields
InitContactShadow(posInput, context);
float channelAlpha = 0.0f;
LightLoopOutput lightLoopOutput;
ZERO_INITIALIZE(LightLoopOutput, lightLoopOutput);
UtsLightLoop(input, posInput, bsdfData, builtinData, V, featureFlags, lightLoopOutput);
float3 finalColor = lightLoopOutput.diffuseLighting + lightLoopOutput.specularLighting;
#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
UtsLightLoop(input, posInput, bsdfData, builtinData, V, featureFlags, lightLoopOutput);
outColor = ApplyBlendMode(lightLoopOutput.diffuseLighting, lightLoopOutput.specularLighting, builtinData.opacity);
#if _MATERIAL_TYPE_FRONTHAIR && ENABLE_UTS_HAIR_BLENDING
float2 screenUV = posInput.positionNDC * _HairBlendingRTHandleScale.xy;
float4 hairBlendingMap = LOAD_TEXTURE2D_X(_HairBlendingTex, screenUV);
outColor.rgb = lerp(outColor.rgb, hairBlendingMap.rgb, hairBlendingMap.a * _HairBlendingFactor);
float2 screenUV = posInput.positionSS; // * _HairBlendingRTHandleScale.xy; // Why we don't need to scale? Does unity handle it internally?
float4 hairBlendingTex = LOAD_TEXTURE2D_X(_HairBlendingTex, screenUV);
outColor.rgb = lerp(outColor.rgb, hairBlendingTex.rgb, hairBlendingTex.a * _HairBlendingFactor);
#endif
#if UTS_DEBUG_SHADOWMAP || UTS_DEBUG_SELFSHADOW
@@ -187,7 +168,7 @@ void Frag(PackedVaryingsToPS packedInput,
#endif
#endif // ifdef UTS_DEBUG_SHADOWMAP
#endif // defined(UTS_DEBUG_SHADOWMAP) || defined(UTS_DEBUG_SELFSHADOW)
#ifdef _DEPTHOFFSET_ON
outputDepth = posInput.deviceDepth;
#endif
@@ -196,4 +177,4 @@ void Frag(PackedVaryingsToPS packedInput,
outVTFeedback = builtinData.vtPackedFeedback;
#endif
}
}

View File

@@ -21,15 +21,12 @@ namespace Misaki.HdrpToon
private const string _TOON_LIGHT_FILTER_PROP_NAME = "_ToonLightHiCutFilter";
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_SCALE_PROP_NAME = "_HairShadowDistanceScaleFactor";
private const string _HAIR_SHADOW_DEPTH_BIAS_PROP_NAME = "_HairShadowDepthBias";
private const string _HAIR_SHADOW_FADEIN_PROP_NAME = "_HairShadowFadeInDistance";
private const string _HAIR_SHADOW_FADE_OUT_PROP_NAME = "_HairShadowFadeOutDistance";
private const string _HAIR_BLENDING_RTHANDLE_SCALE_PROP_NAME = "_HairBlendingRTHandleScale";
private const string _HAIR_SHADOW_RT_PROP_NAME = "_HairShadowTex";
private const string _HAIR_BLENDING_PROP_NAME = "_HairBlendingTex";
@@ -43,7 +40,9 @@ namespace Misaki.HdrpToon
private RTHandle _hairShadowRTHandle;
private bool _needReallocateHairShadow;
// TODO: Possible to avoid another RTHandle for depth?
private RTHandle _hairBlendingRTHandle;
private RTHandle _hairBlendingDepthRTHandle;
private bool _needReallocateHairBlending;
private bool _enableHairShadow;
@@ -142,15 +141,16 @@ namespace Misaki.HdrpToon
}
#endif
var scale = _hairShadowQuality switch
// Use R8 or R16 directly?
var format = _hairShadowQuality switch
{
BufferQuality.Low => new Vector2(0.5f, 0.5f),
BufferQuality.High => Vector2.one,
_ => Vector2.zero
BufferQuality.Low => GraphicsFormat.D16_UNorm,
BufferQuality.High => GraphicsFormat.D32_SFloat,
_ => GraphicsFormat.R16G16B16A16_SFloat
};
_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);
_needReallocateHairShadow = false;
@@ -179,6 +179,13 @@ namespace Misaki.HdrpToon
_hairBlendingRTHandle?.Release();
_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);
_needReallocateHairBlending = false;
@@ -274,7 +281,6 @@ namespace Misaki.HdrpToon
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_SCALE_PROP_NAME, utsRenderer.shadowDistanceScale.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))
{
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)
{
@@ -308,7 +314,6 @@ namespace Misaki.HdrpToon
};
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;
_hairShadowRTHandle?.Release();
_hairBlendingRTHandle?.Release();
_hairBlendingDepthRTHandle?.Release();
}
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Misaki.HdrpToon
public BoolParameter enableHairShadow = new(false);
public ClampedFloatParameter shadowDistance = new(5.0f, 0.0f, 20.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 shadowFadeOut = new(50f);

View File

@@ -1,6 +1,6 @@
{
"name": "com.misaki.hdrp-toon",
"version": "2.1.0",
"version": "3.0.1-pre",
"displayName": "HDRP Toon",
"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",
@@ -21,6 +21,6 @@
},
"dependencies": {
"com.unity.render-pipelines.high-definition": "17.0.0",
"com.misaki.shader-gui": "1.1.2"
"com.misaki.shader-gui": "1.1.4"
}
}