Improve AmbientScope and OutlineScope

This commit is contained in:
2025-02-02 17:04:05 +09:00
parent ecd0cfdb9f
commit 281dfbc4f0
11 changed files with 200 additions and 143 deletions

View File

@@ -7,7 +7,7 @@ namespace Misaki.HdrpToon.Editor
Shadow = 1 << 2, Shadow = 1 << 2,
MaterialFeature = 1 << 3, MaterialFeature = 1 << 3,
SurfaceInputs = 1 << 4, SurfaceInputs = 1 << 4,
AmbientMode = 1 << 5, Ambient = 1 << 5,
Highlight = 1 << 6, Highlight = 1 << 6,
Rimlight = 1 << 7, Rimlight = 1 << 7,
MatCap = 1 << 8, MatCap = 1 << 8,

View File

@@ -6,106 +6,110 @@ namespace Misaki.HdrpToon.Editor
{ {
public class AmbientScope : MaterialUIScope<ShaderGUIExpandable> public class AmbientScope : MaterialUIScope<ShaderGUIExpandable>
{ {
protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.AmbientMode; protected override ShaderGUIExpandable ExpandableBit => ShaderGUIExpandable.Ambient;
protected override GUIContent Header => new("Ambient Settings"); protected override GUIContent Header => new("Ambient Settings");
private static class Properties private static class Properties
{ {
public static MaterialProperty IndirectDiffuseMode; public static MaterialProperty indirectDiffuseMode;
public static MaterialProperty IndirectDiffuseIntensity; public static MaterialProperty indirectSpecularMode;
public static MaterialProperty IndirectSpecularMode;
public static MaterialProperty IndirectReflectionIntensity; public static MaterialProperty indirectDiffuseMatCapMap;
public static MaterialProperty EnableSSAO; public static MaterialProperty indirectDiffuseMatCapLod;
public static MaterialProperty SSAOFactor;
public static MaterialProperty EnableSSGI; public static MaterialProperty indirectDiffuseIntensity;
public static MaterialProperty SSGIFactor; public static MaterialProperty ssaoWeight;
public static MaterialProperty EnableSSR; public static MaterialProperty ssgiWeight;
public static MaterialProperty indirectSpecularMatCapMap;
public static MaterialProperty indirectSpecularMatCapLod;
public static MaterialProperty indirectReflectionIntensity;
public static MaterialProperty ssrWeight;
} }
private static class Styles private static class Styles
{ {
public static readonly GUIContent IndirectDiffuseModeText = public static readonly GUIContent indirectDiffuseModeText = new("Indirect Diffuse Mode", "Specifies indirect diffuse mode.");
new("Indirect Diffuse Mode", "Specifies indirect diffuse mode."); public static readonly GUIContent indirectSpecularModeText = new("Indirect Specular Mode", "Specifies indirect specular mode.");
public static readonly GUIContent IndirectDiffuseIntensityText = 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.");
new("Indirect Diffuse Intensity",
"The Environment Light color is added to the material color according to the GI Intensity value.");
public static readonly GUIContent IndirectSpecularModeText = public static readonly GUIContent indirectDiffuseIntensityText = new("Intensity", "The indirect diffuse color is added to the material color according to the intensity value.");
new("Indirect Specular Mode", "Specifies indirect specular mode."); 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 IndirectReflectionIntensityText = public static readonly GUIContent indirectSpecularMatCapMapText = new("MatCap Map", "The material capture map for indirect specular evaluation, with the additional setting for controlling the LOD offset when sampling the indirect specular material capture map.");
new("Indirect Reflection Intensity",
"The Environment Light color is added to the material color according to the GI Intensity value.");
public static readonly GUIContent EnableSSAOText = new("Enable SSAO", "Enable SSAO."); public static readonly GUIContent indirectReflectionIntensityText = new("Intensity", "The indirect reflection color is added to the material color according to the intensity value.");
public static readonly GUIContent SSAOFactorText = new("SSAO Factor", "The weight of SSAO."); public static readonly GUIContent ssrWeightText = new("SSR Weight", "SSR Weight");
public static readonly GUIContent EnableSSGIText = new("Enable SSGI", "Enable SSGI.");
public static readonly GUIContent SSGIFactorText = new("SSGI Factor", "The weight of SSGI.");
public static readonly GUIContent EnableSSRText = new("Enable SSR", "Enable SSR.");
} }
private readonly string[] _indirectDiffuseModeDefines =
{ "_INDIRECT_DIFFUSE_OFF", "_INDIRECT_DIFFUSE_IBL", "_INDIRECT_DIFFUSE_MATCAP", "_INDIRECT_DIFFUSE_RAMP" };
private readonly string[] _indirectSpecularModeDefines =
{ "_INDIRECT_SPECULAR_OFF", "_INDIRECT_SPECULAR_IBL", "_INDIRECT_SPECULAR_MATCAP" };
public override void LoadMaterialProperties() public override void LoadMaterialProperties()
{ {
Properties.IndirectDiffuseMode = FindProperty("_Indirect_Diffuse_Mode"); Properties.indirectDiffuseMode = FindProperty("_Indirect_Diffuse_Mode");
Properties.IndirectDiffuseIntensity = FindProperty("_ID_Intensity"); Properties.indirectSpecularMode = FindProperty("_Indirect_Specular_Mode");
Properties.IndirectSpecularMode = FindProperty("_Indirect_Specular_Mode");
Properties.IndirectReflectionIntensity = FindProperty("_IR_Intensity"); Properties.indirectDiffuseMatCapMap = FindProperty("_IndirectDiffuseMatCapMap");
Properties.EnableSSAO = FindProperty("_ReceivesSSAO"); Properties.indirectDiffuseMatCapLod = FindProperty("_IndirectDiffuseMatCapLod");
Properties.SSAOFactor = FindProperty("_AO_Factor");
Properties.EnableSSGI = FindProperty("_ReceivesSSGI"); Properties.indirectDiffuseIntensity = FindProperty("_IndirectDiffuseIntensity");
Properties.SSGIFactor = FindProperty("_GI_Factor"); Properties.ssaoWeight = FindProperty("_SSAOWeight");
Properties.EnableSSR = FindProperty("_ReceivesSSR"); Properties.ssgiWeight = FindProperty("_SSGIWeight");
Properties.indirectSpecularMatCapMap = FindProperty("_IndirectSpecularMatCapMap");
Properties.indirectSpecularMatCapLod = FindProperty("_IndirectSpecularMatCapLod");
Properties.indirectReflectionIntensity = FindProperty("_IndirectSpecularIntensity");
Properties.ssrWeight = FindProperty("_SSRWeight");
} }
protected override void DrawContent() protected override void DrawContent()
{ {
editor.ShaderProperty(Properties.IndirectDiffuseMode, Styles.IndirectDiffuseModeText); editor.ShaderProperty(Properties.indirectDiffuseMode, Styles.indirectDiffuseModeText);
for (int i = 0; i < _indirectDiffuseModeDefines.Length; i++) editor.ShaderProperty(Properties.indirectSpecularMode, Styles.indirectSpecularModeText);
{
editor.SetKeyword(_indirectDiffuseModeDefines[i], Properties.IndirectDiffuseMode.intValue == i);
}
if (Properties.IndirectDiffuseMode.intValue != 0) var indirectDiffuseMode = Properties.indirectDiffuseMode.GetEnumValue<IndirectDiffuseMode>();
var indirectSpecularMode = Properties.indirectSpecularMode.GetEnumValue<IndirectSpecularMode>();
if (indirectDiffuseMode != IndirectDiffuseMode.Off)
{ {
EditorGUILayout.Space();
EditorGUILayout.LabelField("Indirect Diffuse", EditorStyles.boldLabel);
EditorGUI.indentLevel++; EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.IndirectDiffuseIntensity, Styles.IndirectDiffuseIntensityText);
editor.ShaderProperty(Properties.EnableSSAO, Styles.EnableSSAOText); if (indirectDiffuseMode == IndirectDiffuseMode.Matcap)
if (Properties.EnableSSAO.floatValue > 0)
{ {
EditorGUI.indentLevel++; editor.TexturePropertySingleLine(Styles.indirectDiffuseMatCapMapText, Properties.indirectDiffuseMatCapMap, Properties.indirectDiffuseMatCapLod);
editor.ShaderProperty(Properties.SSAOFactor, Styles.SSAOFactorText);
EditorGUI.indentLevel--;
} }
editor.ShaderProperty(Properties.EnableSSGI, Styles.EnableSSGIText); editor.ShaderProperty(Properties.indirectDiffuseIntensity, Styles.indirectDiffuseIntensityText);
if (Properties.EnableSSGI.floatValue > 0) editor.ShaderProperty(Properties.ssaoWeight, Styles.ssaoWeightText);
if (indirectDiffuseMode == IndirectDiffuseMode.IBL)
{ {
EditorGUI.indentLevel++; editor.ShaderProperty(Properties.ssgiWeight, Styles.ssgiWeightText);
editor.ShaderProperty(Properties.SSGIFactor, Styles.SSGIFactorText);
EditorGUI.indentLevel--;
} }
EditorGUI.indentLevel--; EditorGUI.indentLevel--;
} }
editor.ShaderProperty(Properties.IndirectSpecularMode, Styles.IndirectSpecularModeText); if (indirectSpecularMode != (int)IndirectSpecularMode.Off)
for (int i = 0; i < _indirectSpecularModeDefines.Length; i++)
{ {
editor.SetKeyword(_indirectSpecularModeDefines[i], Properties.IndirectSpecularMode.intValue == i); EditorGUILayout.Space();
} EditorGUILayout.LabelField("Indirect Specular", EditorStyles.boldLabel);
if (Properties.IndirectSpecularMode.intValue != 0)
{
EditorGUI.indentLevel++; EditorGUI.indentLevel++;
editor.ShaderProperty(Properties.IndirectReflectionIntensity, Styles.IndirectReflectionIntensityText);
editor.ShaderProperty(Properties.EnableSSR, Styles.EnableSSRText); if (indirectSpecularMode == IndirectSpecularMode.Matcap)
{
editor.TexturePropertySingleLine(Styles.indirectSpecularMatCapMapText, Properties.indirectSpecularMatCapMap, Properties.indirectSpecularMatCapLod);
}
editor.ShaderProperty(Properties.indirectReflectionIntensity, Styles.indirectReflectionIntensityText);
editor.ShaderProperty(Properties.ssrWeight, Styles.ssrWeightText);
EditorGUI.indentLevel--; EditorGUI.indentLevel--;
} }
} }

View File

@@ -14,6 +14,8 @@ namespace Misaki.HdrpToon.Editor
public static MaterialProperty outlineColor; public static MaterialProperty outlineColor;
public static MaterialProperty outlineColorMap; public static MaterialProperty outlineColorMap;
public static MaterialProperty albedoAffectOutline; public static MaterialProperty albedoAffectOutline;
public static MaterialProperty skyColorAffectOutline;
public static MaterialProperty skyColorIntensity;
public static MaterialProperty fadeIn; public static MaterialProperty fadeIn;
public static MaterialProperty fadeOut; public static MaterialProperty fadeOut;
@@ -26,6 +28,9 @@ namespace Misaki.HdrpToon.Editor
public static readonly GUIContent outlineWidthText = new("Outline Width", "Specifies the width of the outline."); public static readonly GUIContent outlineWidthText = new("Outline Width", "Specifies the width of the outline.");
public static readonly GUIContent outlineColorText = new("Outline Color", "Specifies the color of the outline."); public static readonly GUIContent outlineColorText = new("Outline Color", "Specifies the color of the outline.");
public static readonly GUIContent albedoAffectOutlineText = new("Albedo Affect Outline", "Enable to affect the outline color with the albedo color."); public static readonly GUIContent albedoAffectOutlineText = new("Albedo Affect Outline", "Enable to affect the outline color with the albedo color.");
public static readonly GUIContent skyColorAffectOutlineText = new("Sky Color Affect Outline", "Enable to affect the outline color with the sky color.");
public static readonly GUIContent skyColorIntensityText = new("Sky Color Intensity", "The intensity of the sky color when add to the outline color.");
public static readonly GUIContent fadeInText = new("Fade In Distance", "Specify the nearest distance, where the outline width changes with the distance between the camera and the object. The outline will be the maximum width at this distance."); public static readonly GUIContent fadeInText = new("Fade In Distance", "Specify the nearest distance, where the outline width changes with the distance between the camera and the object. The outline will be the maximum width at this distance.");
public static readonly GUIContent fadeOutText = new("Fade Out Distance", "Specify the furthest distance, where the outline width changes with the distance between the camera and the object. The outline will be zero at this distance."); public static readonly GUIContent fadeOutText = new("Fade Out Distance", "Specify the furthest distance, where the outline width changes with the distance between the camera and the object. The outline will be zero at this distance.");
public static readonly GUIContent useSmoothedNormalText = new("Use Smoothed Normal", "Enable to use smoothed normal(that packed in uv2) for outline calculation."); public static readonly GUIContent useSmoothedNormalText = new("Use Smoothed Normal", "Enable to use smoothed normal(that packed in uv2) for outline calculation.");
@@ -45,6 +50,8 @@ namespace Misaki.HdrpToon.Editor
Properties.outlineColor = FindProperty("_OutlineColor"); Properties.outlineColor = FindProperty("_OutlineColor");
Properties.outlineColorMap = FindProperty("_OutlineColorMap"); Properties.outlineColorMap = FindProperty("_OutlineColorMap");
Properties.albedoAffectOutline = FindProperty("_AlbedoAffectOutline"); Properties.albedoAffectOutline = FindProperty("_AlbedoAffectOutline");
Properties.skyColorAffectOutline = FindProperty("_SkyColorAffectOutline");
Properties.skyColorIntensity = FindProperty("_SkyColorIntensity");
Properties.fadeIn = FindProperty("_OutlineFadeIn"); Properties.fadeIn = FindProperty("_OutlineFadeIn");
Properties.fadeOut = FindProperty("_OutlineFadeOut"); Properties.fadeOut = FindProperty("_OutlineFadeOut");
@@ -57,6 +64,13 @@ namespace Misaki.HdrpToon.Editor
editor.TexturePropertySingleLine(Styles.outlineWidthText, Properties.outlineWidthMap, Properties.outlineWidth); editor.TexturePropertySingleLine(Styles.outlineWidthText, Properties.outlineWidthMap, Properties.outlineWidth);
editor.TexturePropertySingleLine(Styles.outlineColorText, Properties.outlineColorMap, Properties.outlineColor); editor.TexturePropertySingleLine(Styles.outlineColorText, Properties.outlineColorMap, Properties.outlineColor);
editor.ShaderProperty(Properties.albedoAffectOutline, Styles.albedoAffectOutlineText); editor.ShaderProperty(Properties.albedoAffectOutline, Styles.albedoAffectOutlineText);
editor.ShaderProperty(Properties.skyColorAffectOutline, Styles.skyColorAffectOutlineText);
if (Properties.skyColorAffectOutline.GetBooleanValue())
{
editor.ShaderProperty(Properties.skyColorIntensity, Styles.skyColorIntensityText);
}
EditorGUILayout.Space();
editor.ShaderProperty(Properties.fadeIn, Styles.fadeInText); editor.ShaderProperty(Properties.fadeIn, Styles.fadeInText);
editor.ShaderProperty(Properties.fadeOut, Styles.fadeOutText); editor.ShaderProperty(Properties.fadeOut, Styles.fadeOutText);
editor.ShaderProperty(Properties.useSmoothedNormal, Styles.useSmoothedNormalText); editor.ShaderProperty(Properties.useSmoothedNormal, Styles.useSmoothedNormalText);

View File

@@ -14,4 +14,19 @@ namespace Misaki.HdrpToon
KKHair, KKHair,
Toon Toon
} }
internal enum IndirectDiffuseMode
{
Off,
IBL,
Matcap,
Ramp
}
internal enum IndirectSpecularMode
{
Off,
IBL,
Matcap
}
} }

View File

@@ -223,11 +223,6 @@ Shader "HDRP/Toon"
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
[ToggleUI] _SupportDecals("Support Decals", Float) = 1.0 [ToggleUI] _SupportDecals("Support Decals", Float) = 1.0
[ToggleUI] _ReceivesSSR("Receives SSR", Float) = 0.0
[ToggleUI] _ReceivesSSAO("Receives SSAO", Float) = 1.0
_AO_Factor("_AO_Factor", Range(0.0, 1.0)) = 1
[ToggleUI] _ReceivesSSGI("Receives SSGI", Float) = 1.0
_GI_Factor("_GI_Factor", Range(0.0, 1.0)) = 1
[ToggleUI] _AddPrecomputedVelocity("AddPrecomputedVelocity", Float) = 0.0 [ToggleUI] _AddPrecomputedVelocity("AddPrecomputedVelocity", Float) = 0.0
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -287,7 +282,6 @@ Shader "HDRP/Toon"
// Surface Inputs // Surface Inputs
_NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map _NormalMap("NormalMap", 2D) = "bump" {} // Tangent space normal map
_NormalScale("_NormalScale", Range(0.0, 8.0)) = 1 _NormalScale("_NormalScale", Range(0.0, 8.0)) = 1
//_NormalMapOS("NormalMapOS", 2D) = "white" {} // Object space normal map - no good default value
_Metallic("_Metallic", Range(0.0, 1.0)) = 0 _Metallic("_Metallic", Range(0.0, 1.0)) = 0
_Smoothness("Smoothness", Range(0.0, 1.0)) = 0.0 _Smoothness("Smoothness", Range(0.0, 1.0)) = 0.0
@@ -300,12 +294,28 @@ Shader "HDRP/Toon"
_AlphaRemapMax("AlphaRemapMax", Float) = 1.0 _AlphaRemapMax("AlphaRemapMax", Float) = 1.0
_AORemapMin("AORemapMin", Float) = 0.0 _AORemapMin("AORemapMin", Float) = 0.0
_AORemapMax("AORemapMax", Float) = 1.0 _AORemapMax("AORemapMax", Float) = 1.0
[ToggleUI] _Use_SSSLut("Use SSSLut", Int) = 0
_SSSLutMap("SSSLutMap", 2D) = "white" {} _SSSLutMap("SSSLutMap", 2D) = "white" {}
[ToggleUI, HideInInspector] _Use_SSSLut("Use SSSLut", Int) = 0
_SSSIntensity("SSSIntensity", Range(0.0, 3.0)) = 1.0 _SSSIntensity("SSSIntensity", Range(0.0, 3.0)) = 1.0
_HairBlendingMap("HairBlendingMap", 2D) = "black" {} _HairBlendingMap("HairBlendingMap", 2D) = "black" {}
// Ambient
[KeywordEnum(Off, IBL, MatCap, Ramp)]_Indirect_Diffuse_Mode("_Indirect_Diffuse_Mode", Integer) = 1
[KeywordEnum(Off, IBL, MatCap)]_Indirect_Specular_Mode("_Indirect_Specular_Mode", Integer) = 1
_IndirectDiffuseMatCapMap("IndirectDiffuseMatCapMap", 2D) = "black" {}
_IndirectDiffuseMatCapLod("IndirectDiffuseMatCapMapLOD", Range(-5, 5)) = 0.0
_IndirectDiffuseIntensity("Indirect Diffuse Intensity", Range(0, 5)) = 1.0
_SSAOWeight("SSAO Weight", Range(0.0, 1.0)) = 1.0
_SSGIWeight("SSGI Weight", Range(0.0, 1.0)) = 1.0
_IndirectSpecularMatCapMap("IndirectSpecularMatCapMap", 2D) = "black" {}
_IndirectSpecularMatCapLod("IndirectSpecularMatCapMapLOD", Range(-5, 5)) = 0.0
_IndirectSpecularIntensity("Indirect Specular Intensity", Range(0, 5)) = 1.0
_SSRWeight("SSR Weight", Range(0.0, 1.0)) = 1.0
// Angel Rings // Angel Rings
_AngelRingColor("Angel Ring Color", Color) = (1, 1, 1, 1) _AngelRingColor("Angel Ring Color", Color) = (1, 1, 1, 1)
@@ -319,12 +329,13 @@ Shader "HDRP/Toon"
_OutlineWidthMap("Outline Tex", 2D) = "white" {} _OutlineWidthMap("Outline Tex", 2D) = "white" {}
_OutlineColor("Outline Color", Color) = (0.5, 0.5, 0.5, 1) _OutlineColor("Outline Color", Color) = (0.5, 0.5, 0.5, 1)
_OutlineColorMap("Outline Color Map", 2D) = "white" {} _OutlineColorMap("Outline Color Map", 2D) = "white" {}
[Toggle(_)] _AlbedoAffectOutline("AlbedoAffectOutline", Float) = 0 [ToggleUI] _AlbedoAffectOutline("Albedo Affect Outline", Float) = 1
[ToggleUI] _SkyColorAffectOutline("Sky Color Affect Outline", Float) = 1
_SkyColorIntensity("Sky Color Intensity", Range(0, 5)) = 1
_OutlineFadeIn("Outline Fade In", Float) = 50 _OutlineFadeIn("Outline Fade In", Float) = 50
_OutlineFadeOut("Outline Fade Out", Float) = 100 _OutlineFadeOut("Outline Fade Out", Float) = 100
[Toggle(_)] _UseSmoothedNormal("Use Smoothed Normal", Float) = 0 [ToggleUI] _UseSmoothedNormal("Use Smoothed Normal", Float) = 0
//[HideInInspector]_Cutoff("Alpha cutoff", Range(0, 1)) = 0.5
_BakedNormal("Baked Normal for Outline", 2D) = "white" {}
@@ -429,12 +440,8 @@ Shader "HDRP/Toon"
//RimLightMask //RimLightMask
_Set_RimLightMask("Set_RimLightMask", 2D) = "white" {} _Set_RimLightMask("Set_RimLightMask", 2D) = "white" {}
_Tweak_RimLightMaskLevel("Tweak_RimLightMaskLevel", Range(-1, 1)) = 0 _Tweak_RimLightMaskLevel("Tweak_RimLightMaskLevel", Range(-1, 1)) = 0
//
[Enum(Off, 0, IBL, 1, Matcap, 2, Ramp, 3)]_Indirect_Diffuse_Mode("_Indirect_Diffuse_Mode", Integer) = 0
[Enum(Off, 0, IBL, 1, Matcap, 2)]_Indirect_Specular_Mode("_Indirect_Specular_Mode", Integer) = 0
[Toggle(_)] _MatCap("MatCap", Float) = 0 [Toggle(_)] _MatCap("MatCap", Float) = 0
_MatCapMap("MatCapMap", 2D) = "black" {}
//v.2.0.6 //v.2.0.6
_BlurLevelMatcap("Blur Level of MatCap_Sampler", Range(0, 10)) = 0 _BlurLevelMatcap("Blur Level of MatCap_Sampler", Range(0, 10)) = 0
_MatCapColor("MatCapColor", Color) = (1, 1, 1, 1) _MatCapColor("MatCapColor", Color) = (1, 1, 1, 1)
@@ -473,8 +480,6 @@ Shader "HDRP/Toon"
[Toggle(_)] _Is_ViewCoord_Scroll("Is_ViewCoord_Scroll", Float) = 0 [Toggle(_)] _Is_ViewCoord_Scroll("Is_ViewCoord_Scroll", Float) = 0
// //
//GI Intensity //GI Intensity
_ID_Intensity("GI_Intensity", Range(0, 1)) = 1
_IR_Intensity("GI_Intensity", Range(0, 1)) = 1
_Light_Intensity_Multiplier("Light_Intensity_Multiplier" , Range(0, 1)) = 0.25 _Light_Intensity_Multiplier("Light_Intensity_Multiplier" , Range(0, 1)) = 0.25
//For VR Chat under No effective light objects //For VR Chat under No effective light objects
_Unlit_Intensity("Unlit_Intensity", Range(0, 4)) = 0 _Unlit_Intensity("Unlit_Intensity", Range(0, 4)) = 0
@@ -1010,8 +1015,8 @@ Shader "HDRP/Toon"
#pragma shader_feature_local_fragment _RECEIVE_SCREEN_SPACE_SHADOW_ON #pragma shader_feature_local_fragment _RECEIVE_SCREEN_SPACE_SHADOW_ON
#pragma shader_feature_local_fragment _RECEIVE_HAIR_SHADOW_ON #pragma shader_feature_local_fragment _RECEIVE_HAIR_SHADOW_ON
#pragma shader_feature_local_fragment _INDIRECT_DIFFUSE_OFF _INDIRECT_DIFFUSE_IBL _INDIRECT_DIFFUSE_MATCAP _INDIRECT_DIFFUSE_RAMP #pragma shader_feature_local_fragment _INDIRECT_DIFFUSE_MODE_OFF _INDIRECT_DIFFUSE_MODE_IBL _INDIRECT_DIFFUSE_MODE_MATCAP _INDIRECT_DIFFUSE_MODE_RAMP
#pragma shader_feature_local_fragment _INDIRECT_SPECULAR_OFF _INDIRECT_SPECULAR_IBL _INDIRECT_SPECULAR_MATCAP #pragma shader_feature_local_fragment _INDIRECT_SPECULAR_MODE_OFF _INDIRECT_SPECULAR_MODE_IBL _INDIRECT_SPECULAR_MODE_MATCAP
#pragma shader_feature_local_fragment _MASKMAP #pragma shader_feature_local_fragment _MASKMAP
#pragma shader_feature_local_fragment _NORMAL_MAP #pragma shader_feature_local_fragment _NORMAL_MAP

View File

@@ -102,15 +102,18 @@ IndirectLighting UtsEvaluateBSDF_ScreenSpaceReflection(PositionInputs posInput,
IndirectLighting lighting; IndirectLighting lighting;
ZERO_INITIALIZE(IndirectLighting, lighting); ZERO_INITIALIZE(IndirectLighting, lighting);
// TODO: this texture is sparse (mostly black). Can we avoid reading every texel? How about using Hi-S? if (_SSRWeight > 0.0)
float4 ssrLighting = LOAD_TEXTURE2D_X(_SsrLightingTexture, posInput.positionSS); {
InversePreExposeSsrLighting(ssrLighting); // TODO: this texture is sparse (mostly black). Can we avoid reading every texel? How about using Hi-S?
float4 ssrLighting = LOAD_TEXTURE2D_X(_SsrLightingTexture, posInput.positionSS);
InversePreExposeSsrLighting(ssrLighting);
// Apply the weight on the ssr contribution (if required) // Apply the weight on the ssr contribution (if required)
ApplyScreenSpaceReflectionWeight(ssrLighting); ApplyScreenSpaceReflectionWeight(ssrLighting);
reflectionHierarchyWeight = ssrLighting.a; reflectionHierarchyWeight = ssrLighting.a;
lighting.specularReflected = ssrLighting.rgb * preLightData.specularFGD; lighting.specularReflected = lerp(lighting.specularReflected, ssrLighting.rgb * preLightData.specularFGD, _SSRWeight);
}
return lighting; return lighting;
} }
@@ -125,7 +128,8 @@ void UtsEvaluateBSDF_BakeDiffuse(PositionInputs posInput, PreLightData preLightD
#if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SCREEN_SPACE_INDIRECT_DIFFUSE_DISABLED) #if !defined(_SURFACE_TYPE_TRANSPARENT) && !defined(SCREEN_SPACE_INDIRECT_DIFFUSE_DISABLED)
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF) if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF)
{ {
builtinData.bakeDiffuseLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier(); float3 ssgiLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier();
builtinData.bakeDiffuseLighting = lerp(builtinData.bakeDiffuseLighting, ssgiLighting.rgb, _SSGIWeight);
} }
else else
#endif #endif
@@ -168,7 +172,8 @@ void UtsEvaluateBSDF_MatCapDiffuse(float3 positionWS, float3 normalWS, inout Bui
uv.x *= -1; uv.x *= -1;
uv = uv * 0.5 + 0.5; uv = uv * 0.5 + 0.5;
builtinData.bakeDiffuseLighting = SAMPLE_TEXTURE2D_LOD(_MatCapMap, s_linear_clamp_sampler, uv, UNITY_SPECCUBE_LOD_STEPS).rgb * GetInverseCurrentExposureMultiplier(); float lod = clamp(UNITY_SPECCUBE_LOD_STEPS + _IndirectDiffuseMatCapLod, 0.0, 10.0);
builtinData.bakeDiffuseLighting = SAMPLE_TEXTURE2D_LOD(_IndirectDiffuseMatCapMap, s_trilinear_clamp_sampler, uv, lod).rgb * GetInverseCurrentExposureMultiplier();
} }
IndirectLighting UtsEvaluateBSDF_MatCapSpecular(float3 positionWS, UtsBSDFData bsdfData, PreLightData preLightData) IndirectLighting UtsEvaluateBSDF_MatCapSpecular(float3 positionWS, UtsBSDFData bsdfData, PreLightData preLightData)
@@ -184,7 +189,8 @@ IndirectLighting UtsEvaluateBSDF_MatCapSpecular(float3 positionWS, UtsBSDFData b
uv.x *= -1; uv.x *= -1;
uv = uv * 0.5 + 0.5; uv = uv * 0.5 + 0.5;
lighting.specularReflected = SAMPLE_TEXTURE2D_LOD(_MatCapMap, s_linear_clamp_sampler, uv, PerceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness)).rgb; 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(); lighting.specularReflected *= preLightData.specularFGD * GetInverseCurrentExposureMultiplier();
return lighting; return lighting;
@@ -240,27 +246,37 @@ IndirectLighting UtsEvaluateBSDF_Env(LightLoopContext lightLoopContext, Position
return lighting; return lighting;
} }
void ApplyAmbientOcclusion(AmbientOcclusionFactor aoFactor, inout BuiltinData builtinData, inout AggregateLighting lighting)
{
builtinData.bakeDiffuseLighting = APPLY_WEIGHT(builtinData.bakeDiffuseLighting, aoFactor.indirectAmbientOcclusion, _SSAOWeight);
lighting.indirect.specularReflected = APPLY_WEIGHT(lighting.indirect.specularReflected, aoFactor.indirectSpecularOcclusion, _SSAOWeight);
lighting.direct.diffuse = APPLY_WEIGHT(lighting.direct.diffuse, aoFactor.directAmbientOcclusion, _SSAOWeight);
lighting.direct.specular = APPLY_WEIGHT(lighting.direct.specular, aoFactor.directSpecularOcclusion, _SSAOWeight);
}
void AdjustIndirectLighting(PreLightData preLightData, UtsBSDFData bsdfData, inout BuiltinData builtinData, inout AggregateLighting lighting)
{
builtinData.bakeDiffuseLighting = ApplyCurrentExposureMultiplier(builtinData.bakeDiffuseLighting * bsdfData.diffuseColor * preLightData.diffuseFGD * _IndirectDiffuseIntensity);
lighting.indirect.specularReflected = ApplyCurrentExposureMultiplier(lighting.indirect.specularReflected * bsdfData.fresnel0 * _IndirectSpecularIntensity);
}
void UtsPostEvaluateBSDF(PositionInputs posInput, PreLightData preLightData, UtsBSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting, out LightLoopOutput lightLoopOutput) void UtsPostEvaluateBSDF(PositionInputs posInput, PreLightData preLightData, UtsBSDFData bsdfData, BuiltinData builtinData, AggregateLighting lighting, out LightLoopOutput lightLoopOutput)
{ {
#if !defined(_INDIRECT_DIFFUSE_MODE_OFF) && !defined(_INDIRECT_SPECULAR_MODE_OFF)
AmbientOcclusionFactor aoFactor; AmbientOcclusionFactor aoFactor;
GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor); GetScreenSpaceAmbientOcclusionMultibounce(posInput.positionSS, preLightData.NdotV, bsdfData.perceptualRoughness, bsdfData.ambientOcclusion, bsdfData.specularOcclusion, bsdfData.diffuseColor, bsdfData.fresnel0, aoFactor);
builtinData.bakeDiffuseLighting = APPLY_WEIGHT(builtinData.bakeDiffuseLighting, aoFactor.indirectAmbientOcclusion, _AO_Factor); ApplyAmbientOcclusion(aoFactor, builtinData, lighting);
lighting.indirect.specularReflected = APPLY_WEIGHT(lighting.indirect.specularReflected, aoFactor.indirectSpecularOcclusion, _AO_Factor); #endif
lighting.direct.diffuse = APPLY_WEIGHT(lighting.direct.diffuse, aoFactor.directAmbientOcclusion, _AO_Factor); AdjustIndirectLighting(preLightData, bsdfData, builtinData, lighting);
lighting.direct.specular = APPLY_WEIGHT(lighting.direct.specular, aoFactor.directSpecularOcclusion, _AO_Factor);
builtinData.bakeDiffuseLighting = ApplyCurrentExposureMultiplier(builtinData.bakeDiffuseLighting * bsdfData.diffuseColor * preLightData.diffuseFGD * _ID_Intensity); // 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.
lighting.indirect.specularReflected = ApplyCurrentExposureMultiplier(lighting.indirect.specularReflected * bsdfData.fresnel0 * _IR_Intensity); lightLoopOutput.diffuseLighting = lighting.direct.diffuse + builtinData.bakeDiffuseLighting + builtinData.emissiveColor;
lightLoopOutput.diffuseLighting = lighting.direct.diffuse + builtinData.bakeDiffuseLighting;
lightLoopOutput.specularLighting = lighting.direct.specular + lighting.indirect.specularReflected; lightLoopOutput.specularLighting = lighting.direct.specular + lighting.indirect.specularReflected;
// Rescale the GGX to account for the multiple scattering. // Rescale the GGX to account for the multiple scattering.
lightLoopOutput.specularLighting *= 1.0 + bsdfData.fresnel0 * preLightData.energyCompensation; lightLoopOutput.specularLighting *= 1.0 + bsdfData.fresnel0 * preLightData.energyCompensation;
ApplyExposureAdjustment(lightLoopOutput.diffuseLighting); ApplyExposureAdjustment(lightLoopOutput.diffuseLighting);
ApplyExposureAdjustment(lightLoopOutput.specularLighting); ApplyExposureAdjustment(lightLoopOutput.specularLighting);
lightLoopOutput.diffuseLighting += builtinData.emissiveColor;
} }
#endif #endif

View File

@@ -247,9 +247,9 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
#endif #endif
float3 lightInReflDir = 0.0; float3 lightInReflDir = 0.0;
#ifdef _INDIRECT_DIFFUSE_OFF #ifdef _INDIRECT_DIFFUSE_MODE_OFF
#elif _INDIRECT_DIFFUSE_IBL #elif _INDIRECT_DIFFUSE_MODE_IBL
bool replaceBakeDiffuseLighting = false; bool replaceBakeDiffuseLighting = false;
#if !defined(_SURFACE_TYPE_TRANSPARENT) // No SSGI/RTGI/Mixed effect on transparent #if !defined(_SURFACE_TYPE_TRANSPARENT) // No SSGI/RTGI/Mixed effect on transparent
if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF) if (_IndirectDiffuseMode != INDIRECTDIFFUSEMODE_OFF)
@@ -273,18 +273,18 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
{ {
UtsEvaluateBSDF_BakeDiffuse(posInput, preLightData, bsdfData, V, builtinData, lightInReflDir); UtsEvaluateBSDF_BakeDiffuse(posInput, preLightData, bsdfData, V, builtinData, lightInReflDir);
} }
#elif _INDIRECT_DIFFUSE_MATCAP #elif _INDIRECT_DIFFUSE_MODE_MATCAP
//builtinData.bakeDiffuseLighting = UtsEvaluateColor_MatCap(posInput.positionWS, bsdfData.normalWS, 0.0); //builtinData.bakeDiffuseLighting = UtsEvaluateColor_MatCap(posInput.positionWS, bsdfData.normalWS, 0.0);
UtsEvaluateBSDF_MatCapDiffuse(posInput.positionWS, bsdfData.normalWS, builtinData); UtsEvaluateBSDF_MatCapDiffuse(posInput.positionWS, bsdfData.normalWS, builtinData);
#elif _INDIRECT_DIFFUSE_RAMP #elif _INDIRECT_DIFFUSE_MODE_RAMP
UtsEvaluateBSDF_Ramp(posInput, bsdfData, builtinData); UtsEvaluateBSDF_Ramp(posInput, bsdfData, builtinData);
#endif #endif
if (featureFlags & LIGHTFEATUREFLAGS_ENV) if (featureFlags & LIGHTFEATUREFLAGS_ENV)
{ {
#if _INDIRECT_SPECULAR_OFF #if _INDIRECT_SPECULAR_MODE_OFF
#elif _INDIRECT_SPECULAR_IBL #elif _INDIRECT_SPECULAR_MODE_IBL
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES; context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES;
#if SCALARIZE_LIGHT_LOOP #if SCALARIZE_LIGHT_LOOP
@@ -346,13 +346,13 @@ void UtsLightLoop(FragInputs fragInputs, PositionInputs posInput, UtsBSDFData bs
} }
} }
#elif _INDIRECT_SPECULAR_MATCAP #elif _INDIRECT_SPECULAR_MODE_MATCAP
IndirectLighting lighting = UtsEvaluateBSDF_MatCapSpecular(posInput.positionWS, bsdfData, preLightData); IndirectLighting lighting = UtsEvaluateBSDF_MatCapSpecular(posInput.positionWS, bsdfData, preLightData);
AccumulateIndirectLighting(lighting, aggregateLighting); AccumulateIndirectLighting(lighting, aggregateLighting);
#endif #endif
} }
#if _INDIRECT_SPECULAR_IBL #if _INDIRECT_SPECULAR_MODE_IBL
// Only apply the sky IBL if the sky texture is available // Only apply the sky IBL if the sky texture is available
if ((featureFlags & LIGHTFEATUREFLAGS_SKY) && _EnvLightSkyEnabled) if ((featureFlags & LIGHTFEATUREFLAGS_SKY) && _EnvLightSkyEnabled)
{ {

View File

@@ -161,9 +161,6 @@ float4 _EmissiveColorMap_ST;
float _TexWorldScaleEmissive; float _TexWorldScaleEmissive;
float4 _UVMappingMaskEmissive; float4 _UVMappingMaskEmissive;
float _ID_Intensity;
float _IR_Intensity;
float4 _InvPrimScale; // Only XY are used float4 _InvPrimScale; // Only XY are used
// Wind // Wind
@@ -202,12 +199,6 @@ float4 _SpecularColor;
float _ToonSpecularStep; float _ToonSpecularStep;
float _ToonSpecularFeather; float _ToonSpecularFeather;
float _ReceivesSSR;
float _ReceivesSSAO;
float _AO_Factor;
float _ReceivesSSGI;
float _GIMultiplier;
float _NormalScale; float _NormalScale;
float4 _DetailMap_ST; float4 _DetailMap_ST;

View File

@@ -9,7 +9,8 @@ SAMPLER(sampler_SDFShadingMap);
TEXTURE2D_ARRAY(_ShadingRampMap); TEXTURE2D_ARRAY(_ShadingRampMap);
TEXTURE2D(_MatCapMap); TEXTURE2D(_IndirectDiffuseMatCapMap);
TEXTURE2D(_IndirectSpecularMatCapMap);
sampler _Set_1st_ShadePosition; sampler _Set_1st_ShadePosition;
sampler _Set_2nd_ShadePosition; sampler _Set_2nd_ShadePosition;
@@ -28,6 +29,3 @@ SAMPLER(sampler_OutlineWidthMap);
TEXTURE2D(_OutlineColorMap); TEXTURE2D(_OutlineColorMap);
SAMPLER(sampler_OutlineColorMap); SAMPLER(sampler_OutlineColorMap);
TEXTURE2D(_BakedNormalMap);
SAMPLER(sampler_BakedNormalMap);

View File

@@ -25,6 +25,30 @@ float _SDFHighlightStrength;
float _ShadowDistanceBias; float _ShadowDistanceBias;
float _ShadowNormalBias; float _ShadowNormalBias;
// Ambient
float _IndirectDiffuseMatCapLod;
float _IndirectDiffuseIntensity;
float _SSAOWeight;
float _SSGIWeight;
float _IndirectSpecularMatCapLod;
float _IndirectSpecularIntensity;
float _SSRWeight;
// Outline
float _OutlineWidth;
float4 _OutlineColor;
fixed _AlbedoAffectOutline;
fixed _SkyColorAffectOutline;
float _SkyColorIntensity;
float _OutlineFadeIn;
float _OutlineFadeOut;
fixed _UseSmoothedNormal;
float _utsTechnique; float _utsTechnique;
float4 _Color; float4 _Color;
@@ -170,13 +194,6 @@ float _AngelRingIntensity;
float _AngelRingOffsetU; float _AngelRingOffsetU;
float _AngelRingOffsetV; float _AngelRingOffsetV;
float _OutlineWidth;
float4 _OutlineColor;
fixed _AlbedoAffectOutline;
float _OutlineFadeIn;
float _OutlineFadeOut;
fixed _UseSmoothedNormal;
#if defined(_UTS_TOON_EV_PER_MODEL) #if defined(_UTS_TOON_EV_PER_MODEL)
// not in materials // not in materials
int _ToonLightHiCutFilter; int _ToonLightHiCutFilter;

View File

@@ -132,26 +132,23 @@ void Frag(PackedVaryingsToPS packedInput,
float4 objPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1)); float4 objPos = mul(unity_ObjectToWorld, float4(0, 0, 0, 1));
float4 uv0 = input.texCoord0; float4 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_GradientEquator = ShadeSH9(float4(0, 1, 0, 0));
float3 envLightSource_SkyboxIntensity = max( float3 envLightSource_SkyboxIntensity = max(
SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, 0.0, 0.0), input.texCoord1.xy, input.texCoord2.xy), SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, 1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy),
SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, -1.0, 0.0), input.texCoord1.xy, input.texCoord2.xy) SampleBakedGI_UTS_OutLine(objPos.xyz, float3(0.0, -1.0, -0.0), input.texCoord1.xy, input.texCoord2.xy)
).rgb; ).rgb;
float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator; float3 ambientSkyColor = envLightSource_SkyboxIntensity.rgb > 0.0 ? envLightSource_SkyboxIntensity : envLightSource_GradientEquator;
ambientSkyColor *= GetCurrentExposureMultiplier() * 5.0f; ambientSkyColor *= GetCurrentExposureMultiplier() * _SkyColorIntensity;
float3 baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(uv0, _BaseColorMap)).rgb; float3 baseColor = SAMPLE_TEXTURE2D(_BaseColorMap, sampler_BaseColorMap, TRANSFORM_TEX(uv0, _BaseColorMap)).rgb;
baseColor *= _BaseColor.rgb; baseColor *= _BaseColor.rgb;
float4 outlineColor = _OutlineColor; float4 outlineColor = _OutlineColor;
outlineColor.rgb = lerp(outlineColor.rgb, outlineColor.rgb + ambientSkyColor, _SkyColorAffectOutline);
#if _OUTLINE_COLOR_MAP #if _OUTLINE_COLOR_MAP
outlineColor *= SAMPLE_TEXTURE2D(_OutlineColorMap, sampler_OutlineColorMap, TRANSFORM_TEX(uv0, _BaseColorMap)).rgb; outlineColor *= SAMPLE_TEXTURE2D(_OutlineColorMap, sampler_OutlineColorMap, TRANSFORM_TEX(uv0, _BaseColorMap)).rgb;
#endif #endif
outlineColor.rgb = lerp(outlineColor.rgb * ambientSkyColor, outlineColor.rgb * ambientSkyColor * baseColor, _AlbedoAffectOutline); outlineColor.rgb = lerp(outlineColor.rgb, outlineColor.rgb * baseColor, _AlbedoAffectOutline);
float3 volColor, volOpacity; float3 volColor, volOpacity;