#T#PoiMetallicsAndSpecularProperties
//ifex _MochieBRDF==0
[HideInInspector] m_start_brdf ("Reflections & Specular--{reference_property:_MochieBRDF,button_help:{text:Tutorial,action:{type:URL,data:https://www.poiyomi.com/shading/reflections-and-specular},hover:Documentation}}", Float) = 0
[HideInInspector][ThryToggle(MOCHIE_PBR)]_MochieBRDF ("Enable", Float) = 0
_MochieReflectionStrength ("Reflection Strength", Range(0, 1)) = 1
_MochieSpecularStrength ("Specular Strength", Range(0, 1)) = 1
_MochieMetallicMultiplier ("Metallic", Range(0, 1)) = 0
_MochieRoughnessMultiplier ("Smoothness", Range(0, 1)) = 1
_MochieReflectionTint ("Reflection Tint--{reference_property:_MochieReflectionTintThemeIndex}", Color) = (1, 1, 1, 1)
[HideInInspector][ThryWideEnum(Off, 0, Theme Color 0, 1, Theme Color 1, 2, Theme Color 2, 3, Theme Color 3, 4, ColorChord 0, 5, ColorChord 1, 6, ColorChord 2, 7, ColorChord 3, 8, AL Theme 0, 9, AL Theme 1, 10, AL Theme 2, 11, AL Theme 3, 12)] _MochieReflectionTintThemeIndex ("", Int) = 0
_MochieSpecularTint ("Specular Tint--{reference_property:_MochieSpecularTintThemeIndex}", Color) = (1, 1, 1, 1)
[HideInInspector][ThryWideEnum(Off, 0, Theme Color 0, 1, Theme Color 1, 2, Theme Color 2, 3, Theme Color 3, 4, ColorChord 0, 5, ColorChord 1, 6, ColorChord 2, 7, ColorChord 3, 8, AL Theme 0, 9, AL Theme 1, 10, AL Theme 2, 11, AL Theme 3, 12)] _MochieSpecularTintThemeIndex ("", Int) = 0
[Space(8)]
[sRGBWarning][ThryRGBAPacker(R Metallic Map, G Smoothness Map, B Reflection Mask, A Specular Mask)]_MochieMetallicMaps ("Packed Maps [Expand]--{reference_properties:[_MochieMetallicMapsPan, _MochieMetallicMapsUV, _MochieMetallicMapsStochastic, _MochieMetallicMapsMetallicChannel, _MochieMetallicMapsRoughnessChannel, _MochieMetallicMapsReflectionMaskChannel, _MochieMetallicMapsSpecularMaskChannel, _MochieMetallicMapInvert, _MochieRoughnessMapInvert, _MochieReflectionMaskInvert, _MochieSpecularMaskInvert]}", 2D) = "white" { }
[HideInInspector][Vector2]_MochieMetallicMapsPan ("Panning", Vector) = (0, 0, 0, 0)
[HideInInspector][ThryWideEnum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Panosphere, 4, World Pos XZ, 5, Polar UV, 6, Distorted UV, 7)]_MochieMetallicMapsUV ("UV", Int) = 0
[HideInInspector][ToggleUI]_MochieMetallicMapsStochastic ("Stochastic Sampling", Float) = 0
[HideInInspector][Enum(R, 0, G, 1, B, 2, A, 3, White, 4)]_MochieMetallicMapsMetallicChannel ("Metallic Channel", Float) = 0
[HideInInspector][Enum(R, 0, G, 1, B, 2, A, 3, White, 4)]_MochieMetallicMapsRoughnessChannel ("Smoothness Channel", Float) = 1
[HideInInspector][Enum(R, 0, G, 1, B, 2, A, 3, White, 4)]_MochieMetallicMapsReflectionMaskChannel ("Reflection Mask Channel", Float) = 2
[HideInInspector][Enum(R, 0, G, 1, B, 2, A, 3, White, 4)]_MochieMetallicMapsSpecularMaskChannel ("Specular Mask Channel", Float) = 3
[HideInInspector][ToggleUI]_MochieMetallicMapInvert ("Invert Metallic", Float) = 0
[HideInInspector][ToggleUI]_MochieRoughnessMapInvert ("Invert Smoothness", Float) = 0
[HideInInspector][ToggleUI]_MochieReflectionMaskInvert ("Invert Reflection Mask", Float) = 0
[HideInInspector][ToggleUI]_MochieSpecularMaskInvert ("Invert Specular Mask", Float) = 0
[ThryToggleUI(true)]_PBRSplitMaskSample ("<size=13><b>  Split Mask Sampling</b></size>", Float) = 0
[VectorLabel(tX, tY, oX, oY)]_PBRMaskScaleTiling ("Tiling/Offset--{condition_showS:(_PBRSplitMaskSample==1)}", Vector) = (1, 1, 0, 0)
[ThryWideEnum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Panosphere, 4, World Pos XZ, 5, Polar UV, 6, Distorted UV, 7)]_MochieMetallicMasksUV ("UV--{condition_showS:(_PBRSplitMaskSample==1)}", Int) = 0
[ToggleUI]_PBRSplitMaskStochastic ("Stochastic Sampling--{condition_showS:(_PBRSplitMaskSample==1)}", Float) = 0
[Vector2]_MochieMetallicMasksPan ("Panning--{condition_showS:(_PBRSplitMaskSample==1)}", Vector) = (0, 0, 0, 0)
[ThryToggleUI(true)]_Specular2ndLayer ("<size=13><b>  2nd Specular</b></size>", Float) = 0
_MochieSpecularStrength2 ("Strength--{condition_showS:(_Specular2ndLayer==1)}", Range(0, 1)) = 1
_MochieRoughnessMultiplier2 ("Smoothness--{condition_showS:(_Specular2ndLayer==1)}", Range(0, 1)) = 1
[Space(4)]
[ThryTexture][NoScaleOffset]_MochieReflCube ("Fallback Cubemap", Cube) = "" { }
[ToggleUI]_MochieForceFallback ("Force Fallback", Int) = 0

[HideInInspector] m_start_brdfadvanced ("Advanced", Float) = 0
[ToggleUI]_MochieLitFallback ("Lit Fallback", Float) = 1
[ToggleUI]_IgnoreCastedShadows ("Ignore Casted Shadows", Float) = 0
_PBRNormalSelect ("Pixel Normal Mix", Range(0, 1)) = 1
[PowerSlider(.2)]_RefSpecFresnel ("Fresnel Reflection", Range(0, 1)) = 1
[ThryToggleUI(true)]_MochieGSAAEnabled ("<size=13><b>  GSAA</b></size>", Float) = 1
_PoiGSAAVariance ("GSAA Variance", Range(0, 1)) = 0.15
_PoiGSAAThreshold ("GSAA Threshold", Range(0, 1)) = 0.1
[HideInInspector] g_start_BRDFTPSMaskGroup ("--{condition_showS:(_TPSPenetratorEnabled==1)}", Float) = 0
[ThryToggleUI(true)] _BRDFTPSDepthEnabled ("<size=13><b>  TPS Depth Enabled</b></size>", Float) = 0
_BRDFTPSReflectionMaskStrength ("Reflection Mask Strength--{condition_showS:(_BRDFTPSDepthEnabled==1)}", Range(0, 1)) = 1
_BRDFTPSSpecularMaskStrength ("Specular Mask Strength--{condition_showS:(_BRDFTPSDepthEnabled==1)}", Range(0, 1)) = 1
[HideInInspector] g_end_BRDFTPSMaskGroup ("", Float) = 0
[HideInInspector] m_end_brdfadvanced ("", Float) = 0

[HideInInspector] m_start_brdfglobalmask ("Global Mask", Float) = 0
[ThryWideEnum(Off, 0, 1R, 1, 1G, 2, 1B, 3, 1A, 4, 2R, 5, 2G, 6, 2B, 7, 2A, 8, 3R, 9, 3G, 10, 3B, 11, 3A, 12, 4R, 13, 4G, 14, 4B, 15, 4A, 16)] _MochieMetallicGlobalMask ("Metallic--{reference_property:_MochieMetallicGlobalMaskBlendType}", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)] _MochieMetallicGlobalMaskBlendType ("Blending", Int) = 2
[ThryWideEnum(Off, 0, 1R, 1, 1G, 2, 1B, 3, 1A, 4, 2R, 5, 2G, 6, 2B, 7, 2A, 8, 3R, 9, 3G, 10, 3B, 11, 3A, 12, 4R, 13, 4G, 14, 4B, 15, 4A, 16)] _MochieSmoothnessGlobalMask ("Smoothness--{reference_property:_MochieSmoothnessGlobalMaskBlendType}", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)] _MochieSmoothnessGlobalMaskBlendType ("Blending", Int) = 2
[ThryWideEnum(Off, 0, 1R, 1, 1G, 2, 1B, 3, 1A, 4, 2R, 5, 2G, 6, 2B, 7, 2A, 8, 3R, 9, 3G, 10, 3B, 11, 3A, 12, 4R, 13, 4G, 14, 4B, 15, 4A, 16)] _MochieReflectionStrengthGlobalMask ("Reflection Strength--{reference_property:_MochieReflectionStrengthGlobalMaskBlendType}", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)] _MochieReflectionStrengthGlobalMaskBlendType ("Blending", Int) = 2
[ThryWideEnum(Off, 0, 1R, 1, 1G, 2, 1B, 3, 1A, 4, 2R, 5, 2G, 6, 2B, 7, 2A, 8, 3R, 9, 3G, 10, 3B, 11, 3A, 12, 4R, 13, 4G, 14, 4B, 15, 4A, 16)] _MochieSpecularStrengthGlobalMask ("Specular Strength--{reference_property:_MochieSpecularStrengthGlobalMaskBlendType}", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)] _MochieSpecularStrengthGlobalMaskBlendType ("Blending", Int) = 2
[HideInInspector] m_end_brdfglobalmask ("", Float) = 0

[HideInInspector] m_end_brdf ("", Float) = 0
//endex

//ifex _ClearCoatBRDF==0
[HideInInspector] m_start_clearCoat ("Clear Coat--{reference_property:_ClearCoatBRDF,button_help:{text:Tutorial,action:{type:URL,data:https://www.poiyomi.com/shading/clear-coat},hover:Documentation}}", Float) = 0
[HideInInspector][ThryToggle(POI_CLEARCOAT)]_ClearCoatBRDF ("Enable", Float) = 0
_ClearCoatStrength ("ClearCoat Strength", Range(0, 1)) = 1
_ClearCoatSmoothness ("Smoothness", Range(0, 1)) = 1
_ClearCoatReflectionStrength ("Reflections Strength", Range(0, 1)) = 1
_ClearCoatSpecularStrength ("Specular Strength", Range(0, 1)) = 1
_ClearCoatReflectionTint ("Reflection Tint--{reference_property:_ClearCoatReflectionTintThemeIndex}", Color) = (1, 1, 1, 1)
[HideInInspector][ThryWideEnum(Off, 0, Theme Color 0, 1, Theme Color 1, 2, Theme Color 2, 3, Theme Color 3, 4, ColorChord 0, 5, ColorChord 1, 6, ColorChord 2, 7, ColorChord 3, 8, AL Theme 0, 9, AL Theme 1, 10, AL Theme 2, 11, AL Theme 3, 12)] _ClearCoatReflectionTintThemeIndex ("", Int) = 0
_ClearCoatSpecularTint ("Specular Tint--{reference_property:_ClearCoatSpecularTintThemeIndex}", Color) = (1, 1, 1, 1)
[HideInInspector][ThryWideEnum(Off, 0, Theme Color 0, 1, Theme Color 1, 2, Theme Color 2, 3, Theme Color 3, 4, ColorChord 0, 5, ColorChord 1, 6, ColorChord 2, 7, ColorChord 3, 8, AL Theme 0, 9, AL Theme 1, 10, AL Theme 2, 11, AL Theme 3, 12)] _ClearCoatSpecularTintThemeIndex ("", Int) = 0
[Space(8)]
[sRGBWarning][ThryRGBAPacker(ClearCoat Mask, Smoothness Map, Reflection Mask, Specular Mask)]_ClearCoatMaps ("Packed Maps [Expand]--{reference_properties:[_ClearCoatMapsPan, _ClearCoatMapsUV, _ClearCoatMapsStochastic, _ClearCoatMapsClearCoatMaskChannel, _ClearCoatMapsRoughnessChannel, _ClearCoatMapsReflectionMaskChannel, _ClearCoatMapsSpecularMaskChannel, _ClearCoatMaskInvert, _ClearCoatSmoothnessMapInvert, _ClearCoatReflectionMaskInvert, _ClearCoatSpecularMaskInvert]}", 2D) = "white" { }
[HideInInspector][Vector2]_ClearCoatMapsPan ("Panning", Vector) = (0, 0, 0, 0)
[HideInInspector][ThryWideEnum(UV0, 0, UV1, 1, UV2, 2, UV3, 3, Panosphere, 4, World Pos XZ, 5, Polar UV, 6, Distorted UV, 7)]_ClearCoatMapsUV ("UV", Int) = 0
[HideInInspector][ToggleUI]_ClearCoatMapsStochastic ("Stochastic Sampling", Float) = 0
[HideInInspector][Enum(R, 0, G, 1, B, 2, A, 3, White, 4)]_ClearCoatMapsClearCoatMaskChannel ("ClearCoat Mask Channel", Float) = 0
[HideInInspector][Enum(R, 0, G, 1, B, 2, A, 3, White, 4)]_ClearCoatMapsRoughnessChannel ("Smoothness Channel", Float) = 1
[HideInInspector][Enum(R, 0, G, 1, B, 2, A, 3, White, 4)]_ClearCoatMapsReflectionMaskChannel ("Reflection Mask Channel", Float) = 2
[HideInInspector][Enum(R, 0, G, 1, B, 2, A, 3, White, 4)]_ClearCoatMapsSpecularMaskChannel ("Specular Mask Channel", Float) = 3
[HideInInspector][ToggleUI]_ClearCoatMaskInvert ("Invert ClearCoat Mask", Float) = 0
[HideInInspector][ToggleUI]_ClearCoatSmoothnessMapInvert ("Invert Smoothness", Float) = 0
[HideInInspector][ToggleUI]_ClearCoatReflectionMaskInvert ("Invert Reflection Mask", Float) = 0
[HideInInspector][ToggleUI]_ClearCoatSpecularMaskInvert ("Invert Specular Mask", Float) = 0
[Space(4)]
[ThryTexture][NoScaleOffset]_ClearCoatFallback ("Fallback Cubemap", Cube) = "" { }
[ToggleUI]_ClearCoatForceFallback ("Force Fallback", Int) = 0

[HideInInspector] m_start_clearcoatadvanced ("Advanced", Float) = 0
[ToggleUI]_ClearCoatLitFallback ("Lit Fallback", Float) = 1
[ToggleUI]_CCIgnoreCastedShadows ("Ignore Casted Shadows", Float) = 0
_ClearCoatNormalSelect ("Pixel Normal Mix", Range(0, 1)) = 0
[PowerSlider(.2)]_ClearcoatFresnel ("Fresnel Reflection", Range(0, 1)) = 1
[ThryToggleUI(true)]_ClearCoatGSAAEnabled ("<size=13><b>  GSAA</b></size>", Float) = 1
_ClearCoatGSAAVariance ("GSAA Variance", Range(0, 1)) = 0.15
_ClearCoatGSAAThreshold ("GSAA Threshold", Range(0, 1)) = 0.1
[HideInInspector] g_start_ClearCoatTPSMaskGroup ("--{condition_showS:(_TPSPenetratorEnabled==1)}", Float) = 0
[ThryToggleUI(true)] _ClearCoatTPSDepthMaskEnabled ("<size=13><b>  TPS Depth Enabled</b></size>", Float) = 0
_ClearCoatTPSMaskStrength ("Mask Strength--{condition_showS:(_ClearCoatTPSDepthMaskEnabled==1)}", Range(0, 1)) = 1
[HideInInspector] g_end_ClearCoatTPSMaskGroup ("", Float) = 0
[HideInInspector] m_end_clearcoatadvanced ("", Float) = 0

[HideInInspector] m_start_clearcoatglobalmask ("Global Mask", Float) = 0
[ThryWideEnum(Off, 0, 1R, 1, 1G, 2, 1B, 3, 1A, 4, 2R, 5, 2G, 6, 2B, 7, 2A, 8, 3R, 9, 3G, 10, 3B, 11, 3A, 12, 4R, 13, 4G, 14, 4B, 15, 4A, 16)] _ClearCoatGlobalMask ("ClearCoat--{reference_property:_ClearCoatGlobalMaskBlendType}", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)] _ClearCoatGlobalMaskBlendType ("Blending", Int) = 2
[ThryWideEnum(Off, 0, 1R, 1, 1G, 2, 1B, 3, 1A, 4, 2R, 5, 2G, 6, 2B, 7, 2A, 8, 3R, 9, 3G, 10, 3B, 11, 3A, 12, 4R, 13, 4G, 14, 4B, 15, 4A, 16)] _ClearCoatSmoothnessGlobalMask ("Smoothness--{reference_property:_ClearCoatSmoothnessGlobalMaskBlendType}", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)] _ClearCoatSmoothnessGlobalMaskBlendType ("Blending", Int) = 2
[ThryWideEnum(Off, 0, 1R, 1, 1G, 2, 1B, 3, 1A, 4, 2R, 5, 2G, 6, 2B, 7, 2A, 8, 3R, 9, 3G, 10, 3B, 11, 3A, 12, 4R, 13, 4G, 14, 4B, 15, 4A, 16)] _ClearCoatReflectionStrengthGlobalMask ("Reflection Strength--{reference_property:_ClearCoatReflectionStrengthGlobalMaskBlendType}", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)] _ClearCoatReflectionStrengthGlobalMaskBlendType ("Blending", Int) = 2
[ThryWideEnum(Off, 0, 1R, 1, 1G, 2, 1B, 3, 1A, 4, 2R, 5, 2G, 6, 2B, 7, 2A, 8, 3R, 9, 3G, 10, 3B, 11, 3A, 12, 4R, 13, 4G, 14, 4B, 15, 4A, 16)] _ClearCoatSpecularStrengthGlobalMask ("Specular Strength--{reference_property:_ClearCoatSpecularStrengthGlobalMaskBlendType}", Int) = 0
[HideInInspector][ThryWideEnum(Replace, 0, Darken, 1, Multiply, 2, Color Burn, 3, Linear Burn, 4, Lighten, 5, Screen, 6, Color Dodge, 7, Linear Dodge(Add), 8, Overlay, 9, Soft Lighten, 10, Hard Light, 11, Vivid Light, 12, Linear Light, 13, Pin Light, 14, Hard Mix, 15, Difference, 16, Exclusion, 17, Subtract, 18, Divide, 19)] _ClearCoatSpecularStrengthGlobalMaskBlendType ("Blending", Int) = 2
[HideInInspector] m_end_clearcoatglobalmask ("", Float) = 0

[HideInInspector] m_end_clearCoat ("", Float) = 0
//endex

#T#PoiMetallicsAndSpecularKeywords
//ifex _MochieBRDF==0
#pragma shader_feature_local MOCHIE_PBR
//endex
//ifex _ClearCoatBRDF==0
#pragma shader_feature_local POI_CLEARCOAT
//endex

#T#PoiMetallicsAndSpecularVariables
//ifex _MochieBRDF==0
#ifdef MOCHIE_PBR
	#if defined(PROP_MOCHIEMETALLICMAPS) || !defined(OPTIMIZER_ENABLED)
		Texture2D _MochieMetallicMaps;
		float _PBRMapsStochastic;
	#endif
	POI_DECLARETEX_ST_UV_PAN_STOCHASTIC(_MochieMetallicMaps);
	float _MochieMetallicMapInvert;
	float _MochieRoughnessMapInvert;
	float _MochieReflectionMaskInvert;
	float _MochieSpecularMaskInvert;
	float _MochieMetallicMapsMetallicChannel;
	float _MochieMetallicMapsRoughnessChannel;
	float _MochieMetallicMapsReflectionMaskChannel;
	float _MochieMetallicMapsSpecularMaskChannel;
	float _PBRNormalSelect;

	float _MochieReflectionTintThemeIndex;
	float _MochieSpecularTintThemeIndex;

	float _MochieRoughnessMultiplier;
	float _MochieMetallicMultiplier;
	float _MochieReflectionStrength;
	float _MochieSpecularStrength;
	float4 _MochieSpecularTint;
	float4 _MochieReflectionTint;
	float _MochieLitFallback;
	float _IgnoreCastedShadows;
	float _PBRSplitMaskSample;
	float _PBRSplitMaskStochastic;
	float4 _PBRMaskScaleTiling;
	float _MochieMetallicMasksUV;
	float4 _MochieMetallicMasksPan;

	float _Specular2ndLayer;
	float _MochieSpecularStrength2;
	float _MochieRoughnessMultiplier2;
	float _RefSpecFresnel;
	samplerCUBE _MochieReflCube;
	float4 _MochieReflCube_HDR;
	float _MochieForceFallback;
	float _MochieGSAAEnabled;
	float _PoiGSAAVariance;
	float _PoiGSAAThreshold;
	float _BRDFTPSReflectionMaskStrength;
	float _BRDFTPSSpecularMaskStrength;
	float _BRDFTPSDepthEnabled;

	float _MochieMetallicGlobalMask;
	float _MochieMetallicGlobalMaskBlendType;
	float _MochieSmoothnessGlobalMask;
	float _MochieSmoothnessGlobalMaskBlendType;
	float _MochieReflectionStrengthGlobalMask;
	float _MochieReflectionStrengthGlobalMaskBlendType;
	float _MochieSpecularStrengthGlobalMask;
	float _MochieSpecularStrengthGlobalMaskBlendType;
#endif
//endex

//ifex _ClearCoatBRDF==0
#ifdef POI_CLEARCOAT
	#if defined(PROP_CLEARCOATMAPS) || !defined(OPTIMIZER_ENABLED)
		Texture2D _ClearCoatMaps;
		float4 _ClearCoatMaps_ST;
		float2 _ClearCoatMapsPan;
		float _ClearCoatMapsUV;
		float _ClearCoatMapsStochastic;
	#endif
	float _ClearCoatMapsClearCoatMaskChannel;
	float _ClearCoatMapsRoughnessChannel;
	float _ClearCoatMapsReflectionMaskChannel;
	float _ClearCoatMapsSpecularMaskChannel;
	float _ClearCoatBRDF;
	float _ClearCoatReflectionStrength;
	float _ClearCoatSpecularStrength;
	float _ClearCoatStrength;
	float _ClearCoatSmoothness;
	float4 _ClearCoatReflectionTint;
	float _ClearCoatReflectionTintThemeIndex;
	float4 _ClearCoatSpecularTint;
	float _ClearCoatSpecularTintThemeIndex;
	float _ClearCoatSmoothnessMapInvert;
	float _ClearCoatMaskInvert;
	float _ClearCoatReflectionMaskInvert;
	float _ClearCoatSpecularMaskInvert;
	float _ClearCoatTPSMaskStrength;
	float _ClearCoatTPSDepthMaskEnabled;
	float _ClearCoatNormalSelect;
	
	samplerCUBE _ClearCoatFallback;
	float4 _ClearCoatFallback_HDR;
	float _ClearCoatForceFallback;
	float _ClearCoatLitFallback;
	float _CCIgnoreCastedShadows;
	float _ClearCoatGSAAEnabled;
	float _ClearCoatGSAAVariance;
	float _ClearCoatGSAAThreshold;
	float _ClearcoatFresnel;

	float _ClearCoatGlobalMask;
	float _ClearCoatGlobalMaskBlendType;
	float _ClearCoatSmoothnessGlobalMask;
	float _ClearCoatSmoothnessGlobalMaskBlendType;
	float _ClearCoatReflectionStrengthGlobalMask;
	float _ClearCoatReflectionStrengthGlobalMaskBlendType;
	float _ClearCoatSpecularStrengthGlobalMask;
	float _ClearCoatSpecularStrengthGlobalMaskBlendType;
#endif
//endex

#T#PoiMetallicsAndSpecularFunction
//ifex _MochieBRDF==0 && _ClearCoatBRDF==0
#if defined(MOCHIE_PBR) || defined(POI_CLEARCOAT)

	/*
	* Copyright 2022 orels1
	*
	* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
	*
	* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
	*
	* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
	*/

	// https://github.com/orels1/orels-Unity-Shaders

	float GSAA_Filament(float3 worldNormal, float perceptualRoughness, float gsaaVariance, float gsaaThreshold)
	{
		// Kaplanyan 2016, "Stable specular highlights"
		// Tokuyoshi 2017, "Error Reduction and Simplification for Shading Anti-Aliasing"
		// Tokuyoshi and Kaplanyan 2019, "Improved Geometric Specular Antialiasing"

		// This implementation is meant for deferred rendering in the original paper but
		// we use it in forward rendering as well (as discussed in Tokuyoshi and Kaplanyan
		// 2019). The main reason is that the forward version requires an expensive transform
		// of the float vector by the tangent frame for every light. This is therefore an
		// approximation but it works well enough for our needs and provides an improvement
		// over our original implementation based on Vlachos 2015, "Advanced VR Rendering".

		float3 du = ddx(worldNormal);
		float3 dv = ddy(worldNormal);

		float variance = gsaaVariance * (dot(du, du) + dot(dv, dv));

		float roughness = perceptualRoughness * perceptualRoughness;
		float kernelRoughness = min(2.0 * variance, gsaaThreshold);
		float squareRoughness = saturate(roughness * roughness + kernelRoughness);

		return sqrt(sqrt(squareRoughness));
	}

	/*
	MIT END
	*/


	bool SceneHasReflections()
	{
		float width, height;
		unity_SpecCube0.GetDimensions(width, height);
		return !(width * height < 2);
	}

	float3 GetWorldReflections(float3 reflDir, float3 worldPos, float roughness)
	{
		float3 baseReflDir = reflDir;
		reflDir = BoxProjection(reflDir, worldPos, unity_SpecCube0_ProbePosition, unity_SpecCube0_BoxMin, unity_SpecCube0_BoxMax);
		float4 envSample0 = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, reflDir, roughness * UNITY_SPECCUBE_LOD_STEPS);
		float3 p0 = DecodeHDR(envSample0, unity_SpecCube0_HDR);
		float interpolator = unity_SpecCube0_BoxMin.w;
		UNITY_BRANCH
		if (interpolator < 0.99999)
		{
			float3 refDirBlend = BoxProjection(baseReflDir, worldPos, unity_SpecCube1_ProbePosition, unity_SpecCube1_BoxMin, unity_SpecCube1_BoxMax);
			float4 envSample1 = UNITY_SAMPLE_TEXCUBE_SAMPLER_LOD(unity_SpecCube1, unity_SpecCube0, refDirBlend, roughness * UNITY_SPECCUBE_LOD_STEPS);
			float3 p1 = DecodeHDR(envSample1, unity_SpecCube1_HDR);
			p0 = lerp(p1, p0, interpolator);
		}
		return p0;
	}

	float3 GetReflections(in PoiCam poiCam, in PoiLight pl, in PoiMesh poiMesh, float roughness, float ForceFallback, float LightFallback, samplerCUBE reflectionCube, float4 hdrData, float3 reflectionDir)
	{
		float3 reflections = 0;
		float3 lighting = pl.finalLighting;
		// This is a separate conditional so it can optimize out when ForceFallback isn't animated
		if (ForceFallback == 0)
		{
			UNITY_BRANCH
			if (SceneHasReflections())
			{
				#ifdef UNITY_PASS_FORWARDBASE
					reflections = GetWorldReflections(reflectionDir, poiMesh.worldPos.xyz, roughness);
				#endif
			}
			else
			{
				#ifdef UNITY_PASS_FORWARDBASE
					reflections = texCUBElod(reflectionCube, float4(reflectionDir, roughness * UNITY_SPECCUBE_LOD_STEPS));
					reflections = DecodeHDR(float4(reflections, 1), hdrData) * lerp(1, pl.finalLighting, LightFallback);
				#endif
				#ifdef POI_PASS_ADD
					if (LightFallback)
					{
						reflections = texCUBElod(reflectionCube, float4(reflectionDir, roughness * UNITY_SPECCUBE_LOD_STEPS));
						reflections = DecodeHDR(float4(reflections, 1), hdrData) * pl.finalLighting;
					}
				#endif
			}
		}
		else
		{
			#ifdef UNITY_PASS_FORWARDBASE
				reflections = texCUBElod(reflectionCube, float4(reflectionDir, roughness * UNITY_SPECCUBE_LOD_STEPS));
				reflections = DecodeHDR(float4(reflections, 1), hdrData) * lerp(1, pl.finalLighting, LightFallback);
			#endif
			#ifdef POI_PASS_ADD
				if (LightFallback)
				{
					reflections = texCUBElod(reflectionCube, float4(reflectionDir, roughness * UNITY_SPECCUBE_LOD_STEPS));
					reflections = DecodeHDR(float4(reflections, 1), hdrData) * pl.finalLighting;
				}
			#endif
		}
		reflections *= pl.occlusion;
		return reflections;
	}

	float GetGGXTerm(float nDotL, float nDotV, float nDotH, float roughness)
	{
		float visibilityTerm = 0;
		if (nDotL > 0)
		{
			float rough = roughness;
			float rough2 = roughness * roughness;

			float lambdaV = nDotL * (nDotV * (1 - rough) + rough);
			float lambdaL = nDotV * (nDotL * (1 - rough) + rough);

			visibilityTerm = 0.5f / (lambdaV + lambdaL + 1e-5f);
			float d = (nDotH * rough2 - nDotH) * nDotH + 1.0f;
			float dotTerm = UNITY_INV_PI * rough2 / (d * d + 1e-7f);

			visibilityTerm *= dotTerm * UNITY_PI;
		}
		return visibilityTerm;
	}

	void GetSpecFresTerm(float nDotL, float nDotV, float nDotH, float lDotH, inout float3 specularTerm, inout float3 fresnelTerm, float3 specCol, float roughness)
	{
		specularTerm = GetGGXTerm(nDotL, nDotV, nDotH, roughness);
		fresnelTerm = FresnelTerm(specCol, lDotH);
		specularTerm = max(0, specularTerm * max(0.00001, nDotL));
	}

	float GetRoughness(float smoothness)
	{
		float rough = 1 - smoothness;
		rough *= 1.7 - 0.7 * rough;
		return rough;
	}
#endif
//endex

//ifex _MochieBRDF==0
#ifdef MOCHIE_PBR
	void MochieBRDF(inout PoiFragData poiFragData, in PoiCam poiCam, inout PoiLight poiLight, in PoiMesh poiMesh, in PoiMods poiMods)
	{
		float smoothness = _MochieRoughnessMultiplier;
		float smoothness2 = _MochieRoughnessMultiplier2;
		float metallic = _MochieMetallicMultiplier;
		float specularMask = 1;
		float reflectionMask = 1;

		#if defined(PROP_MOCHIEMETALLICMAPS) || !defined(OPTIMIZER_ENABLED)
			float4 PBRMaps = POI2D_SAMPLER_PAN_STOCHASTIC(_MochieMetallicMaps, _MainTex, poiUV(poiMesh.uv[_MochieMetallicMapsUV], _MochieMetallicMaps_ST), _MochieMetallicMapsPan, _MochieMetallicMapsStochastic);
			UNITY_BRANCH
			if (_PBRSplitMaskSample)
			{
				float4 PBRSplitMask = POI2D_SAMPLER_PAN_STOCHASTIC(_MochieMetallicMaps, _MainTex, poiUV(poiMesh.uv[_MochieMetallicMasksUV], _PBRMaskScaleTiling), _MochieMetallicMasksPan.xy, _PBRSplitMaskStochastic);
				assignValueToVectorFromIndex(PBRMaps, _MochieMetallicMapsReflectionMaskChannel, PBRSplitMask[_MochieMetallicMapsReflectionMaskChannel]);
				assignValueToVectorFromIndex(PBRMaps, _MochieMetallicMapsSpecularMaskChannel, PBRSplitMask[_MochieMetallicMapsSpecularMaskChannel]);
			}
			
			if(_MochieMetallicMapsMetallicChannel < 4)
			{
				metallic *= PBRMaps[_MochieMetallicMapsMetallicChannel];
			}
			if(_MochieMetallicMapsRoughnessChannel < 4)
			{
				smoothness *= PBRMaps[_MochieMetallicMapsRoughnessChannel];
				smoothness2 *= PBRMaps[_MochieMetallicMapsRoughnessChannel];
			}
			if(_MochieMetallicMapsReflectionMaskChannel < 4)
			{
				reflectionMask *= PBRMaps[_MochieMetallicMapsReflectionMaskChannel];
			}
			if(_MochieMetallicMapsSpecularMaskChannel < 4)
			{
				specularMask *= PBRMaps[_MochieMetallicMapsSpecularMaskChannel];
			}
		#endif
		
		reflectionMask *= _MochieReflectionStrength;
		specularMask *= _MochieSpecularStrength;
		
		if (_MochieMetallicGlobalMask > 0)
		{
			metallic = customBlend(metallic, poiMods.globalMask[_MochieMetallicGlobalMask-1], _MochieMetallicGlobalMaskBlendType);
		}
		if (_MochieSmoothnessGlobalMask > 0)
		{
			smoothness = customBlend(smoothness, poiMods.globalMask[_MochieSmoothnessGlobalMask-1], _MochieSmoothnessGlobalMaskBlendType);
			smoothness2 = customBlend(smoothness2, poiMods.globalMask[_MochieSmoothnessGlobalMask-1], _MochieSmoothnessGlobalMaskBlendType);
		}
		if (_MochieReflectionStrengthGlobalMask > 0)
		{
			reflectionMask = customBlend(reflectionMask, poiMods.globalMask[_MochieReflectionStrengthGlobalMask-1], _MochieReflectionStrengthGlobalMaskBlendType);
		}
		if (_MochieSpecularStrengthGlobalMask > 0)
		{
			specularMask = customBlend(specularMask, poiMods.globalMask[_MochieSpecularStrengthGlobalMask-1], _MochieSpecularStrengthGlobalMaskBlendType);
		}

		if (_MochieMetallicMapInvert)
		{
			metallic = 1 - metallic;
		}
		if (_MochieRoughnessMapInvert)
		{
			smoothness = 1 - smoothness;
			smoothness2 = 1 - smoothness2;
		}
		if (_MochieReflectionMaskInvert)
		{
			reflectionMask = 1 - reflectionMask;
		}
		if (_MochieSpecularMaskInvert)
		{
			specularMask = 1 - specularMask;
		}
		#ifdef TPS_Penetrator
			if (_BRDFTPSDepthEnabled)
			{
				reflectionMask = lerp(0, reflectionMask * TPSBufferedDepth(poiMesh.localPos, poiMesh.vertexColor), _BRDFTPSReflectionMaskStrength);
				specularMask = lerp(0, specularMask * TPSBufferedDepth(poiMesh.localPos, poiMesh.vertexColor), _BRDFTPSSpecularMaskStrength);
			}
		#endif

		#K#MOCHIE_METALLIC_SMOOTHNESS_MOD
		
		float roughness = GetRoughness(smoothness);
		float roughness2 = GetRoughness(smoothness2);
		float3 specCol = lerp(unity_ColorSpaceDielectricSpec.rgb, poiFragData.baseColor, metallic);
		float omr = unity_ColorSpaceDielectricSpec.a - metallic * unity_ColorSpaceDielectricSpec.a;
		float percepRough = 1 - smoothness;
		float percepRough2 = 1 - smoothness2;
		UNITY_BRANCH
		if (_MochieGSAAEnabled)
		{
			percepRough = GSAA_Filament(poiMesh.normals[_PBRNormalSelect], percepRough, _PoiGSAAVariance, _PoiGSAAThreshold);
			if (_Specular2ndLayer == 1 && _MochieSpecularStrength2 > 0)
			{
				percepRough2 = GSAA_Filament(poiMesh.normals[_PBRNormalSelect], percepRough2, _PoiGSAAVariance, _PoiGSAAThreshold);
			}
		}
		float brdfRoughness = percepRough * percepRough;
		brdfRoughness = max(brdfRoughness, 0.002);
		
		float brdfRoughness2 = percepRough2 * percepRough2;
		brdfRoughness2 = max(brdfRoughness2, 0.002);

		float3 diffuse = poiFragData.baseColor;
		float3 specular = 0;
		float3 specular2 = 0;
		float3 vSpecular = 0;
		float3 vSpecular2 = 0;
		float3 reflections = 0;
		float3 environment = 0;

		float attenuation = min(poiLight.nDotLSaturated, lerp(poiLight.attenuation, 1, _IgnoreCastedShadows));
		#ifdef POI_PASS_ADD
			attenuation *= lerp(poiLight.additiveShadow, 1, _IgnoreCastedShadows);
		#endif

		float3 fresnelTerm = 1;
		float3 specularTerm = 1;

		float pbrNDotL = lerp(poiLight.vertexNDotL, poiLight.nDotL, _PBRNormalSelect);
		float pbrNDotV = lerp(poiLight.vertexNDotV, poiLight.nDotV, _PBRNormalSelect);
		float pbrNDotH = lerp(poiLight.vertexNDotH, poiLight.nDotH, _PBRNormalSelect);
		float3 pbrReflectionDir = lerp(poiCam.vertexReflectionDir, poiCam.reflectionDir, _PBRNormalSelect);

		GetSpecFresTerm(pbrNDotL, pbrNDotV, pbrNDotH, poiLight.lDotH, specularTerm, fresnelTerm, specCol, brdfRoughness);
		specular = poiLight.directColor * specularTerm * fresnelTerm * specularMask * poiThemeColor(poiMods, _MochieSpecularTint, _MochieSpecularTintThemeIndex) * poiLight.occlusion * attenuation;

		if (_LightingVertexLightingEnabled)
		{
			#if defined(VERTEXLIGHT_ON)
				for (int index = 0; index < 4; index++)
				{
					fresnelTerm = 1;
					specularTerm = 1;
					float pbrVDotNL = lerp(poiLight.vertexVDotNL[index], poiLight.vDotNL[index], _PBRNormalSelect);
					float pbrVDotNH = lerp(poiLight.vertexVDotNH[index], poiLight.vDotNH[index], _PBRNormalSelect);
					GetSpecFresTerm(pbrVDotNL, pbrNDotV, pbrVDotNH, poiLight.vDotLH[index], specularTerm, fresnelTerm, specCol, brdfRoughness);
					vSpecular += poiLight.vColor[index] * specularTerm * fresnelTerm * specularMask * poiThemeColor(poiMods, _MochieSpecularTint, _MochieSpecularTintThemeIndex) * poiLight.occlusion * poiLight.vAttenuation[index];
				}
			#endif
		}

		if (_Specular2ndLayer == 1)
		{
			float3 fresnelTerm = 1;
			float3 specularTerm = 1;
			GetSpecFresTerm(pbrNDotL, pbrNDotV, pbrNDotH, poiLight.lDotH, specularTerm, fresnelTerm, specCol, brdfRoughness2);
			specular2 = poiLight.directColor * specularTerm * fresnelTerm * specularMask * poiThemeColor(poiMods, _MochieSpecularTint, _MochieSpecularTintThemeIndex) * poiLight.occlusion * attenuation * _MochieSpecularStrength2;
			
			if (_LightingVertexLightingEnabled)
			{
				#if defined(VERTEXLIGHT_ON)
					for (int index = 0; index < 4; index++)
					{
						fresnelTerm = 1;
						specularTerm = 1;
						float pbrVDotNL = lerp(poiLight.vertexVDotNL[index], poiLight.vDotNL[index], _PBRNormalSelect);
						float pbrVDotNH = lerp(poiLight.vertexVDotNH[index], poiLight.vDotNH[index], _PBRNormalSelect);
						GetSpecFresTerm(pbrVDotNL, pbrNDotV, pbrVDotNH, poiLight.vDotLH[index], specularTerm, fresnelTerm, specCol, brdfRoughness2);
						vSpecular2 += poiLight.vColor[index] * specularTerm * fresnelTerm * specularMask * poiThemeColor(poiMods, _MochieSpecularTint, _MochieSpecularTintThemeIndex) * poiLight.occlusion * poiLight.vAttenuation[index] * _MochieSpecularStrength2;
					}
				#endif
			}
		}

		float surfaceReduction = (1.0 / (brdfRoughness * brdfRoughness + 1.0));
		float grazingTerm = saturate(smoothness + (1 - omr));
		float3 reflCol = GetReflections(poiCam, poiLight, poiMesh, roughness, _MochieForceFallback, _MochieLitFallback, _MochieReflCube, _MochieReflCube_HDR, pbrReflectionDir);
		reflections = surfaceReduction * reflCol * lerp(1, FresnelLerp(specCol, grazingTerm, pbrNDotV), _RefSpecFresnel);
		reflections *= poiThemeColor(poiMods, _MochieReflectionTint, _MochieReflectionTintThemeIndex);
		reflections *= reflectionMask;
		#ifdef POI_PASS_ADD
			reflections *= poiLight.attenuation;
		#endif
		diffuse = lerp(diffuse, diffuse * omr, reflectionMask);

		environment = max(specular + vSpecular, specular2 + vSpecular2);
		environment += reflections;
		diffuse *= poiLight.finalLighting;
		poiFragData.finalColor = diffuse;
		poiLight.finalLightAdd += environment;
	}
#endif
//endex
//ifex _ClearCoatBRDF==0
#ifdef POI_CLEARCOAT
	void poiClearCoat(inout PoiFragData poiFragData, in PoiCam poiCam, inout PoiLight poiLight, in PoiMesh poiMesh, in PoiMods poiMods)
	{
		float clearCoatMask = _ClearCoatStrength;
		float smoothness = _ClearCoatSmoothness;
		float reflectionMask = _ClearCoatReflectionStrength;
		float specularMask = _ClearCoatSpecularStrength;

		#if defined(PROP_CLEARCOATMAPS) || !defined(OPTIMIZER_ENABLED)
			float4 PBRMaps = POI2D_SAMPLER_PAN_STOCHASTIC(_ClearCoatMaps, _MainTex, poiUV(poiMesh.uv[_ClearCoatMapsUV], _ClearCoatMaps_ST), _ClearCoatMapsPan, _ClearCoatMapsStochastic);

			if(_ClearCoatMapsClearCoatMaskChannel < 4)
			{
				clearCoatMask *= PBRMaps[_ClearCoatMapsClearCoatMaskChannel];
			}
			if(_ClearCoatMapsRoughnessChannel < 4)
			{
				smoothness *= PBRMaps[_ClearCoatMapsRoughnessChannel];
			}
			if(_ClearCoatMapsReflectionMaskChannel < 4)
			{
				reflectionMask *= PBRMaps[_ClearCoatMapsReflectionMaskChannel];
			}
			if(_ClearCoatMapsSpecularMaskChannel < 4)
			{
				specularMask *= PBRMaps[_ClearCoatMapsSpecularMaskChannel];
			}
		#endif
		
		if (_ClearCoatGlobalMask > 0)
		{
			clearCoatMask = customBlend(reflectionMask, poiMods.globalMask[_ClearCoatGlobalMask-1], _ClearCoatGlobalMaskBlendType);
		}
		if (_ClearCoatSmoothnessGlobalMask > 0)
		{
			smoothness = customBlend(smoothness, poiMods.globalMask[_ClearCoatSmoothnessGlobalMask-1], _ClearCoatSmoothnessGlobalMaskBlendType);
		}
		if (_ClearCoatReflectionStrengthGlobalMask > 0)
		{
			reflectionMask = customBlend(reflectionMask, poiMods.globalMask[_ClearCoatReflectionStrengthGlobalMask-1], _ClearCoatReflectionStrengthGlobalMaskBlendType);
		}
		if (_ClearCoatSpecularStrengthGlobalMask > 0)
		{
			specularMask = customBlend(specularMask, poiMods.globalMask[_ClearCoatSpecularStrengthGlobalMask-1], _ClearCoatSpecularStrengthGlobalMaskBlendType);
		}

		if (_ClearCoatMaskInvert)
		{
			clearCoatMask = 1 - clearCoatMask;
		}
		if (_ClearCoatSmoothnessMapInvert)
		{
			smoothness = 1 - smoothness;
		}
		if (_ClearCoatReflectionMaskInvert)
		{
			reflectionMask = 1 - reflectionMask;
		}
		if (_ClearCoatSpecularMaskInvert)
		{
			specularMask = 1 - specularMask;
		}
		#ifdef TPS_Penetrator
			if (_ClearCoatTPSDepthMaskEnabled)
			{
				clearCoatMask = lerp(0, clearCoatMask * TPSBufferedDepth(poiMesh.localPos, poiMesh.vertexColor), _ClearCoatTPSMaskStrength);
			}
		#endif
		
		float roughness = GetRoughness(smoothness);
		float3 specCol = 0.220916301;
		float omr = unity_ColorSpaceDielectricSpec.a;
		float percepRough = 1 - smoothness;
		UNITY_BRANCH
		if (_ClearCoatGSAAEnabled)
		{
			percepRough = GSAA_Filament(poiMesh.normals[_ClearCoatNormalSelect], percepRough, _ClearCoatGSAAVariance, _ClearCoatGSAAThreshold);
		}
		float brdfRoughness = percepRough * percepRough;
		brdfRoughness = max(brdfRoughness, 0.002);
		
		float3 diffuse = 0;
		float3 specular = 0;
		float3 vSpecular = 0;
		float3 reflections = 0;
		float3 environment = 0;
		float attenuation = min(poiLight.nDotLSaturated, lerp(poiLight.attenuation, 1, _CCIgnoreCastedShadows));

		float3 fresnelTerm = 1;
		float3 specularTerm = 1;

		float clearcoatNDotL = lerp(poiLight.vertexNDotL, poiLight.nDotL, _ClearCoatNormalSelect);
		float clearcoatNDotV = lerp(poiLight.vertexNDotV, poiLight.nDotV, _ClearCoatNormalSelect);
		float clearcoatNDotH = lerp(poiLight.vertexNDotH, poiLight.nDotH, _ClearCoatNormalSelect);
		float3 clearcoatReflectionDir = lerp(poiCam.vertexReflectionDir, poiCam.reflectionDir, _ClearCoatNormalSelect);

		GetSpecFresTerm(clearcoatNDotL, clearcoatNDotV, clearcoatNDotH, poiLight.lDotH, specularTerm, fresnelTerm, specCol, brdfRoughness);
		specular = poiLight.directColor * specularTerm * fresnelTerm * specularMask * poiThemeColor(poiMods, _ClearCoatSpecularTint, _ClearCoatSpecularTintThemeIndex) * poiLight.occlusion * attenuation;
		if (_LightingVertexLightingEnabled)
		{
			#if defined(VERTEXLIGHT_ON)
				for (int index = 0; index < 4; index++)
				{
					fresnelTerm = 1;
					specularTerm = 1;
					float clearcoatVDotNL = lerp(poiLight.vertexVDotNL[index], poiLight.vDotNL[index], _ClearCoatNormalSelect);
					float clearcoatVDotNH = lerp(poiLight.vertexVDotNH[index], poiLight.vDotNH[index], _ClearCoatNormalSelect);
					GetSpecFresTerm(clearcoatVDotNL, clearcoatNDotV, clearcoatVDotNH, poiLight.vDotLH[index], specularTerm, fresnelTerm, specCol, brdfRoughness);
					vSpecular += poiLight.vColor[index] * specularTerm * fresnelTerm * specularMask * poiThemeColor(poiMods, _ClearCoatSpecularTint, _ClearCoatSpecularTintThemeIndex) * poiLight.occlusion * poiLight.vAttenuation[index];
				}
			#endif
		}

		float surfaceReduction = (1.0 / (brdfRoughness * brdfRoughness + 1.0));
		float grazingTerm = saturate(smoothness + (1 - omr));
		float3 reflCol = GetReflections(poiCam, poiLight, poiMesh, roughness, _ClearCoatForceFallback, _ClearCoatLitFallback, _ClearCoatFallback, _ClearCoatFallback_HDR, clearcoatReflectionDir);
		reflections = surfaceReduction * reflCol * lerp(1, FresnelLerp(specCol, grazingTerm, clearcoatNDotV), _ClearcoatFresnel);
		reflections *= poiThemeColor(poiMods, _ClearCoatReflectionTint, _ClearCoatReflectionTintThemeIndex) * reflectionMask;
		#ifdef POI_PASS_ADD
			reflections *= poiLight.attenuation;
		#endif
		diffuse = lerp(diffuse, diffuse * omr, reflectionMask);

		environment = specular + vSpecular;
		#ifdef UNITY_PASS_FORWARDBASE
			environment += reflections;
		#endif
		//diffuse *= poiLight.finalLighting;
		diffuse += environment;
		poiLight.finalLightAdd += saturate(diffuse * clearCoatMask);
	}
#endif
//endex

#T#PoiMetallicsAndSpecularFunctionCall
//ifex _MochieBRDF==0
#ifdef MOCHIE_PBR
	MochieBRDF(poiFragData, poiCam, poiLight, poiMesh, poiMods);
#endif
//endex
//ifex _ClearCoatBRDF==0
#ifdef POI_CLEARCOAT
	poiClearCoat(poiFragData, poiCam, poiLight, poiMesh, poiMods);
#endif
//endex
