Shader properties clean up;

This commit is contained in:
2025-03-24 14:58:28 +09:00
parent b205c1523d
commit 5a282e0812
6 changed files with 107 additions and 428 deletions

View File

@@ -4,8 +4,6 @@
// Otherwise those parameters are not bound correctly at runtime.
// ===========================================================================
#define fixed half
#define UNITY_TEXTURE_STREAMING_DEBUG_VARS
float4 unity_MipmapStreaming_DebugTex_ST;
float4 unity_MipmapStreaming_DebugTex_TexelSize;
@@ -15,293 +13,36 @@ float4 unity_MipmapStreaming_DebugTex_StreamInfo;
// Unity Toon Shader
#include "UtsTextures.hlsl"
// Lit
TEXTURE2D(_DistortionVectorMap);
SAMPLER(sampler_DistortionVectorMap);
TEXTURE2D(_EmissiveColorMap);
SAMPLER(sampler_EmissiveColorMap);
// TODO: HDRP properties, clean it in the future
#ifndef LAYERED_LIT_SHADER
TEXTURE2D(_DiffuseLightingMap);
SAMPLER(sampler_DiffuseLightingMap);
TEXTURE2D(_BaseColorMap);
SAMPLER(sampler_BaseColorMap);
TEXTURE2D(_HairBlendingMap);
SAMPLER(sampler_HairBlendingMap);
TEXTURE2D(_MaskMap);
SAMPLER(sampler_MaskMap);
TEXTURE2D(_BentNormalMap); // Reuse sampler from normal map
SAMPLER(sampler_BentNormalMap);
TEXTURE2D(_NormalMap);
SAMPLER(sampler_NormalMap);
TEXTURE2D(_NormalMapOS);
SAMPLER(sampler_NormalMapOS);
TEXTURE2D(_DetailMap);
SAMPLER(sampler_DetailMap);
TEXTURE2D(_HeightMap);
SAMPLER(sampler_HeightMap);
TEXTURE2D(_TangentMap);
SAMPLER(sampler_TangentMap);
TEXTURE2D(_TangentMapOS);
SAMPLER(sampler_TangentMapOS);
TEXTURE2D(_AnisotropyMap);
SAMPLER(sampler_AnisotropyMap);
TEXTURE2D(_SubsurfaceMaskMap);
SAMPLER(sampler_SubsurfaceMaskMap);
TEXTURE2D(_ThicknessMap);
SAMPLER(sampler_ThicknessMap);
TEXTURE2D(_IridescenceThicknessMap);
SAMPLER(sampler_IridescenceThicknessMap);
TEXTURE2D(_IridescenceMaskMap);
SAMPLER(sampler_IridescenceMaskMap);
TEXTURE2D(_SpecularColorMap);
SAMPLER(sampler_SpecularColorMap);
TEXTURE2D(_TransmittanceColorMap);
SAMPLER(sampler_TransmittanceColorMap);
TEXTURE2D(_CoatMaskMap);
SAMPLER(sampler_CoatMaskMap);
TEXTURE2D(_SSSLutMap);
//SAMPLER(sampler_SSSLutMap); //Use s_linear_clamp_sampler instead
TEXTURE2D(_HairShadowTex);
TEXTURE2D_X(_HairBlendingTex);
#else
// Set of users variables
#define PROP_DECL(type, name) type name##0, name##1, name##2, name##3
// sampler are share by texture type inside a layered material but we need to support that a particualr layer have no texture, so we take the first sampler of available texture as the share one
// mean we must declare all sampler
#define PROP_DECL_TEX2D(name)\
TEXTURE2D(CALL_MERGE_NAME(name, 0)); \
SAMPLER(CALL_MERGE_NAME(CALL_MERGE_NAME(sampler, name), 0)); \
TEXTURE2D(CALL_MERGE_NAME(name, 1)); \
SAMPLER(CALL_MERGE_NAME(CALL_MERGE_NAME(sampler, name), 1)); \
TEXTURE2D(CALL_MERGE_NAME(name, 2)); \
SAMPLER(CALL_MERGE_NAME(CALL_MERGE_NAME(sampler, name), 2)); \
TEXTURE2D(CALL_MERGE_NAME(name, 3)); \
SAMPLER(CALL_MERGE_NAME(CALL_MERGE_NAME(sampler, name), 3))
PROP_DECL_TEX2D(_BaseColorMap);
PROP_DECL_TEX2D(_MaskMap);
PROP_DECL_TEX2D(_BentNormalMap);
PROP_DECL_TEX2D(_NormalMap);
PROP_DECL_TEX2D(_NormalMapOS);
PROP_DECL_TEX2D(_DetailMap);
PROP_DECL_TEX2D(_HeightMap);
PROP_DECL_TEX2D(_SubsurfaceMaskMap);
PROP_DECL_TEX2D(_ThicknessMap);
TEXTURE2D(_LayerMaskMap);
SAMPLER(sampler_LayerMaskMap);
TEXTURE2D(_LayerInfluenceMaskMap);
SAMPLER(sampler_LayerInfluenceMaskMap);
#endif
CBUFFER_START(UnityPerMaterial)
#include "UtsUnityPerMaterial.hlsl"
// shared constant between lit and layered lit
float _AlphaCutoff;
float _UseShadowThreshold;
float _AlphaCutoffShadow;
float _AlphaCutoffPrepass;
float _AlphaCutoffPostpass;
float4 _DoubleSidedConstants;
float _DistortionScale;
float _DistortionVectorScale;
float _DistortionVectorBias;
float _DistortionBlurScale;
float _DistortionBlurRemapMin;
float _DistortionBlurRemapMax;
float _PPDMaxSamples;
float _PPDMinSamples;
float _PPDLodThreshold;
int _SpecularOcclusionMode;
// Transparency
float3 _TransmittanceColor;
float _Ior;
float _ATDistance;
// Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
// value that exist to identify if the GI emission need to be enabled.
// In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI
float3 _EmissionColor;
float4 _EmissiveColorMap_ST;
float _TexWorldScaleEmissive;
// TODO: This is for layered lit only, clean it in the future
float4 _UVMappingMaskEmissive;
float4 _InvPrimScale; // Only XY are used
// Wind
float _InitialBend;
float _Stiffness;
float _Drag;
float _ShiverDrag;
float _ShiverDirectionality;
// Specular AA
float _EnableGeometricSpecularAA;
float _SpecularAAScreenSpaceVariance;
float _SpecularAAThreshold;
// TODO: HDRP properties, clean it in the future
#ifndef LAYERED_LIT_SHADER
// Set of users variables
float _Metallic;
float _MetallicRemapMin;
float _MetallicRemapMax;
float _Smoothness;
float _SmoothnessRemapMin;
float _SmoothnessRemapMax;
float _Roughness;
float _RoughnessRemapMin;
float _RoughnessRemapMax;
float _AlphaRemapMin;
float _AlphaRemapMax;
float _AORemapMin;
float _AORemapMax;
float _SSSIntensity;
int _Use_SSSLut;
float4 _SpecularColor;
float _ToonSpecularStep;
float _ToonSpecularFeather;
float _NormalScale;
float4 _DetailMap_ST;
float _DetailAlbedoScale;
float _DetailNormalScale;
float _DetailSmoothnessScale;
float4 _HeightMap_TexelSize; // Unity facility. This will provide the size of the heightmap to the shader
float _HeightAmplitude;
float _HeightCenter;
float _Anisotropy;
float4 _AnisotropyMap_ST;
int _Use_Anisotropy;
float4 _KKColor;
float _BSDFContribution;
float _DiffusionProfileHash;
float _SubsurfaceMask;
float _TransmissionMask;
float _Thickness;
float4 _ThicknessRemap;
float _IridescenceThickness;
float4 _IridescenceThicknessRemap;
float _IridescenceMask;
float _CoatMask;
//float4 _SpecularColor;
float _EnergyConservingSpecularColor;
float _TexWorldScale;
float _InvTilingScale;
float4 _UVMappingMask;
float4 _UVDetailsMappingMask;
float _LinkDetailsWithBase;
float _ObjectSpaceUVMapping;
#else // LAYERED_LIT_SHADER
// Set of users variables
PROP_DECL(float4, _BaseColor);
float4 _BaseColorMap0_ST;
float4 _BaseColorMap1_ST;
float4 _BaseColorMap2_ST;
float4 _BaseColorMap3_ST;
float4 _BaseColorMap0_TexelSize;
float4 _BaseColorMap0_MipInfo;
PROP_DECL(float, _Metallic);
PROP_DECL(float, _MetallicRemapMin);
PROP_DECL(float, _MetallicRemapMax);
PROP_DECL(float, _Smoothness);
PROP_DECL(float, _SmoothnessRemapMin);
PROP_DECL(float, _SmoothnessRemapMax);
PROP_DECL(float, _AORemapMin);
PROP_DECL(float, _AORemapMax);
PROP_DECL(float, _NormalScale);
float4 _NormalMap0_TexelSize; // Unity facility. This will provide the size of the base normal to the shader
float4 _HeightMap0_TexelSize;
float4 _HeightMap1_TexelSize;
float4 _HeightMap2_TexelSize;
float4 _HeightMap3_TexelSize;
float4 _DetailMap0_ST;
float4 _DetailMap1_ST;
float4 _DetailMap2_ST;
float4 _DetailMap3_ST;
PROP_DECL(float, _UVDetail);
PROP_DECL(float, _DetailAlbedoScale);
PROP_DECL(float, _DetailNormalScale);
PROP_DECL(float, _DetailSmoothnessScale);
PROP_DECL(float, _HeightAmplitude);
PROP_DECL(float, _HeightCenter);
PROP_DECL(float, _DiffusionProfileHash);
PROP_DECL(float, _SubsurfaceMask);
PROP_DECL(float, _Thickness);
PROP_DECL(float4, _ThicknessRemap);
PROP_DECL(float, _OpacityAsDensity);
float _InheritBaseNormal1;
float _InheritBaseNormal2;
float _InheritBaseNormal3;
float _InheritBaseHeight1;
float _InheritBaseHeight2;
float _InheritBaseHeight3;
float _InheritBaseColor1;
float _InheritBaseColor2;
float _InheritBaseColor3;
PROP_DECL(float, _HeightOffset);
float _HeightTransition;
float4 _LayerMaskMap_ST;
float _TexWorldScaleBlendMask;
PROP_DECL(float, _TexWorldScale);
PROP_DECL(float, _InvTilingScale);
float4 _UVMappingMaskBlendMask;
PROP_DECL(float4, _UVMappingMask);
PROP_DECL(float4, _UVDetailsMappingMask);
PROP_DECL(float, _LinkDetailsWithBase);
#endif // LAYERED_LIT_SHADER
// Following two variables are feeded by the C++ Editor for Scene selection
@@ -310,6 +51,7 @@ int _PassValue;
CBUFFER_END
// Global
int _ToonLightHiCutFilter;
int _ToonEvAdjustmentCurve;
float _ToonEvAdjustmentValueArray[128];
@@ -327,4 +69,4 @@ float _HairShadowDistance;
float _HairShadowDistanceScaleFactor;
float _HairShadowDepthBias;
float _HairShadowFadeInDistance;
float _HairShadowFadeOutDistance;
float _HairShadowFadeOutDistance;

View File

@@ -1,25 +1,47 @@
TEXTURE2D(_MainTex);
SAMPLER(sampler_MainTex);
// Shading Color
TEXTURE2D(_BaseColorMap);
SAMPLER(sampler_BaseColorMap);
TEXTURE2D(_1stShadeColorMap);
TEXTURE2D(_2ndShadeColorMap);
TEXTURE2D_ARRAY(_ShadingRampMap);
TEXTURE2D(_ShadingRampMaskMap);
// Shadow
TEXTURE2D(_SDFShadingMap);
SAMPLER(sampler_SDFShadingMap);
TEXTURE2D_ARRAY(_ShadingRampMap);
TEXTURE2D(_ShadingRampMaskMap);
// Surface Inputs
TEXTURE2D(_MaskMap);
SAMPLER(sampler_MaskMap);
TEXTURE2D(_NormalMap);
SAMPLER(sampler_NormalMap);
TEXTURE2D(_AnisotropyMap);
SAMPLER(sampler_AnisotropyMap);
TEXTURE2D(_SpecularColorMap);
SAMPLER(sampler_SpecularColorMap);
TEXTURE2D(_SSSLutMap);
TEXTURE2D(_HairBlendingMap);
SAMPLER(sampler_HairBlendingMap);
// Global
TEXTURE2D(_HairShadowTex);
TEXTURE2D_X(_HairBlendingTex);
TEXTURE2D(_IndirectDiffuseMatCapMap);
TEXTURE2D(_IndirectSpecularMatCapMap);
sampler _Set_1st_ShadePosition;
sampler _Set_2nd_ShadePosition;
sampler _HighColor_Tex;
sampler _Set_HighColorMask;
sampler _Set_RimLightMask;
sampler _NormalMapForMatCap;
sampler _Set_MatcapMask;
TEXTURE2D(_ClippingMask);
TEXTURE2D(_AngelRingColorMap);

View File

@@ -1,5 +1,5 @@
// Light Loop
float3 _ObjectCenterPositionWS;
// Surface Option
float _SurfaceFeatures;
// Shading Color
float4 _BaseColor;
@@ -8,12 +8,12 @@ float4 _BaseColorMap_TexelSize;
float4 _BaseColorMap_MipInfo;
float _ShadingIndex;
fixed _ShadingRampMask;
half _ShadingRampMask;
float4 _1stShadeColor;
float4 _2ndShadeColor;
fixed _UseBaseAs1st;
fixed _Use1stAs2nd;
half _UseBaseAs1st;
half _Use1stAs2nd;
float _1stShadeColorStep;
float _1stShadeColorFeather;
@@ -28,10 +28,42 @@ float _SDFHighlightStrength;
float _ShadowDistanceBias;
float _ShadowNormalBias;
// Emissive
// Surface Inputs
float _AlphaRemapMin;
float _AlphaRemapMax;
float _NormalScale;
float _Metallic;
float _MetallicRemapMin;
float _MetallicRemapMax;
float _Smoothness;
float _SmoothnessRemapMin;
float _SmoothnessRemapMax;
float _Roughness;
float _RoughnessRemapMin;
float _RoughnessRemapMax;
float _AORemapMin;
float _AORemapMax;
float _Anisotropy;
float4 _AnisotropyMap_ST;
float4 _KKColor;
float4 _SpecularColor;
float _ToonSpecularStep;
float _ToonSpecularFeather;
float _BSDFContribution;
float _EnergyConservingSpecularColor;
float _SSSIntensity;
int _Use_SSSLut;
float3 _EmissiveColor;
fixed _AlbedoAffectEmissive;
fixed _EmissiveExposureWeight;
half _AlbedoAffectEmissive;
half _EmissiveExposureWeight;
float _ObjectSpaceUVMappingEmissive;
@@ -51,158 +83,47 @@ float _SSRWeight;
float4 _RimLightColor;
float _RimLightIntensity;
float _RimLightLevel;
fixed _RimLightClipping;
half _RimLightClipping;
float _RimLightClippingLevel;
float _LightDirectionRimLightLevel;
// Angle Ring
float4 _AngelRingColor;
float4 _AngelRingColorMap_ST;
float _AngelRingIntensity;
float _AngelRingOffsetU;
float _AngelRingOffsetV;
// Outline
float _OutlineWidth;
float4 _OutlineColor;
fixed _AlbedoAffectOutline;
fixed _SkyColorAffectOutline;
half _AlbedoAffectOutline;
half _SkyColorAffectOutline;
float _SkyColorIntensity;
float _OutlineFadeIn;
float _OutlineFadeOut;
fixed _UseSmoothedNormal;
float _utsTechnique;
float4 _Color;
float _SurfaceFeatures;
half _UseSmoothedNormal;
float _Tweak_SystemShadowsLevel;
float _EyeParallaxAmount;
float _HairBlendingFactor;
float _BaseColor_Step;
float _BaseShade_Feather;
float4 _Set_1st_ShadePosition_ST;
float _ShadeColor_Step;
float _1st2nd_Shades_Feather;
float4 _Set_2nd_ShadePosition_ST;
float4 _ShadingGradeMap_ST;
float _Tweak_ShadingGradeMapLevel;
fixed _BlurLevelSGM;
//
float4 _HighColor;
float4 _HighColor_Tex_ST;
fixed _Is_LightColor_HighColor;
fixed _Is_NormalMapToHighColor;
float _HighColor_Power;
fixed _Is_SpecularToHighColor;
fixed _Is_BlendAddToHiColor;
fixed _Is_BlendAddToRimColor;
fixed _Is_UseTweakHighColorOnShadow;
float _TweakHighColorOnShadow;
fixed _Is_LightColor_RimLight;
fixed _Is_NormalMapToRimLight;
fixed _LightDirection_MaskOn;
fixed _Add_Antipodean_RimLight;
float4 _Ap_RimLightColor;
fixed _Is_LightColor_Ap_RimLight;
float _Ap_RimLight_Power;
fixed _Ap_RimLight_FeatherOff;
float4 _Set_RimLightMask_ST;
float _Tweak_RimLightMaskLevel;
fixed _MatCap;
float4 _MatCap_Sampler_ST;
float4 _MatCapColor;
fixed _Is_LightColor_MatCap;
fixed _Is_BlendAddToMatCap;
float _Tweak_MatCapUV;
float _Rotate_MatCapUV;
fixed _Is_NormalMapForMatCap;
float4 _NormalMapForMatCap_ST;
float _Rotate_NormalMapForMatCapUV;
fixed _Is_UseTweakMatCapOnShadow;
float _TweakMatCapOnShadow;
float4 _Set_MatcapMask_ST;
float _Tweak_MatcapMaskLevel;
fixed _Is_Ortho;
float _CameraRolling_Stabilizer;
fixed _BlurLevelMatcap;
fixed _Inverse_MatcapMask;
float _BumpScale;
float _BumpScaleMatcap;
float4 _Emissive_Tex_ST;
float4 _Emissive_Color;
fixed _Is_ViewCoord_Scroll;
float _Rotate_EmissiveUV;
float _Base_Speed;
float _Scroll_EmissiveU;
float _Scroll_EmissiveV;
fixed _Is_PingPong_Base;
float4 _ColorShift;
float4 _ViewShift;
float _ColorShift_Speed;
fixed _Is_ColorShift;
fixed _Is_ViewShift;
//
float _Unlit_Intensity;
fixed _Is_Filter_HiCutPointLightColor;
fixed _ClampLightColor;
float _StepOffset;
fixed _Is_BLD;
float _Offset_X_Axis_BLD;
float _Offset_Y_Axis_BLD;
fixed _Inverse_Z_Axis_BLD;
float4 _ClippingMask_ST;
fixed _IsBaseMapAlphaAsClippingMask;
float _Clipping_Level;
fixed _Inverse_Clipping;
float _Tweak_transparency;
fixed _AngelRing;
float _BaseColorVisible;
float _BaseColorOverridden;
float4 _BaseColorMaskColor;
float _FirstShadeVisible;
float _FirstShadeOverridden;
float4 _FirstShadeMaskColor;
float _SecondShadeVisible;
float _SecondShadeOverridden;
float4 _SecondShadeMaskColor;
float _HighlightVisible;
float _HighlightOverridden;
float4 _HighlightMaskColor;
float _AngelRingVisible;
float _AngelRingOverridden;
float4 _AngelRingMaskColor;
float _RimLightVisible;
float _RimLightOverridden;
float4 _RimLightMaskColor;
float _ComposerMaskMode;
int _ClippingMatteMode;
float _GI_Intensity;
// Advance
half _ClampLightColor;
float _LightIntensityMultiplier;
// Light Loop
float3 _ObjectCenterPositionWS;
float4 _AngelRingColor;
float4 _AngelRingColorMap_ST;
float _AngelRingIntensity;
float _AngelRingOffsetU;
float _AngelRingOffsetV;
// NOTE: Not sure what these are for
// float _FirstShadeOverridden;
// float _SecondShadeOverridden;
float _ComposerMaskMode;
#if defined(_UTS_TOON_EV_PER_MODEL)
// not in materials
@@ -212,7 +133,4 @@ float _ToonEvAdjustmentValueArray[128];
float _ToonEvAdjustmentValueMin;
float _ToonEvAdjustmentValueMax;
float _ToonEvAdjustmentCompensation;
#endif //#if !defined(_UTS_TOON_EV_PER_MODEL)
float _BlendMode;
#endif