using System ;
using UnityEngine ;
using UnityEngine.Experimental.Rendering ;
using UnityEngine.Experimental.Rendering.HDPipeline ;
protected const string k_BaseColor = "_BaseColor" ;
protected const string k_BaseColorMap = "_BaseColorMap" ;
protected const string k_BaseColorMapUV = "_BaseColorMapUV" ;
protected const string k_SpecularColor = "_SpecularColor" ;
protected const string k_SpecularColorMap = "_SpecularColorMap" ;
protected const string k_SpecularColorMapUV = "_SpecularColorMapUV" ;
protected const string k_EnergyConservingSpecularColor = "_EnergyConservingSpecularColor" ;
protected const string k_BaseParametrization = "_BaseParametrization" ;
protected const string k_Metallic = "_Metallic" ;
protected const string k_MetallicMap = "_MetallicMap" ;
protected const string k_ThicknessMapUV = "_ThicknessMapUV" ;
// Second Lobe.
protected const string k_DualSpecularLobeParametrization = "_DualSpecularLobeParametrization" ;
protected const string k_EnableDualSpecularLobe = "_EnableDualSpecularLobe" ;
protected const string k_SmoothnessB = "_SmoothnessB" ;
protected const string k_SmoothnessBMap = "_SmoothnessBMap" ;
protected const string k_LobeMixMap = "_LobeMixMap" ;
protected const string k_LobeMixMapUV = "_LobeMixMapUV" ;
protected const string k_Haziness = "_Haziness" ;
protected const string k_HazinessMap = "_HazinessMap" ;
protected const string k_HazinessMapUV = "_HazinessMapUV" ;
protected const string k_HazeExtent = "_HazeExtent" ;
protected const string k_HazeExtentMap = "_HazeExtentMap" ;
protected const string k_HazeExtentMapUV = "_HazeExtentMapUV" ;
protected const string k_CapHazinessWrtMetallic = "_CapHazinessWrtMetallic" ;
// Anisotropy
protected const string k_EnableAnisotropy = "_EnableAnisotropy" ;
private Property EnableGeometricNormalFiltering ;
private Property EnableTextureNormalFiltering ;
private ComboProperty BaseParametrization ;
private ComboProperty DualSpecularLobeParametrization ;
private bool IsMetallicParametrizationUsed
{
get { return ( ! BaseParametrization . IsValid ) | | ( ( StackLit . BaseParametrization ) BaseParametrization . FloatValue = = StackLit . BaseParametrization . BaseMetallic ) ; }
}
private bool IsHazyGlossParametrizationUsed
{
get { return DualSpecularLobeParametrization . IsValid & & ( ( StackLit . DualSpecularLobeParametrization ) DualSpecularLobeParametrization . FloatValue = = StackLit . DualSpecularLobeParametrization . HazyGloss ) ; }
}
public StackLitGUI ( )
{
_baseMaterialProperties = new GroupProperty ( this , "_BaseMaterial" , new BaseProperty [ ]
EnableGeometricNormalFiltering = new Property ( this , k_GeometricNormalFilteringEnabled , "Enable Geometric filtering" , "Enable specular antialiasing" , true ) ;
EnableTextureNormalFiltering = new Property ( this , k_TextureNormalFilteringEnabled , "Enable Texture filtering" , "Require normal map to use _NA or _OSNA suffix for normal map name" , true ) ;
// This property appears after one which references it:
var BentNormal = new TextureProperty ( this , k_BentNormalMap , "" , "Bent Normal Map" , "Bent Normal Map" , pairConstantWithTexture : true , isMandatory : false , isNormalMap : true , showScaleOffset : false ) ;
// --------------------------------------------------------------------------
// Variable display configuration sections (depend on actual property values)
// --------------------------------------------------------------------------
// Base parametrization
BaseParametrization = new ComboProperty ( this , k_BaseParametrization , "Base Parametrization" , Enum . GetNames ( typeof ( StackLit . BaseParametrization ) ) , false ) ;
var BaseColor = new TextureProperty ( this , k_BaseColorMap , k_BaseColor , "Base Color + Opacity" , "Albedo (RGB) and Opacity (A)" , true , false ) ;
var Metallic = new TextureProperty ( this , k_MetallicMap , k_Metallic , "Metallic" , "Metallic" , false , false ) ;
var DielectricIor = new Property ( this , k_DielectricIor , "DieletricIor" , "IOR use for dielectric material (i.e non metallic material)" , false ) ;
var SmoothnessA = new TextureProperty ( this , k_SmoothnessAMap , k_SmoothnessA , "Smoothness" , "Smoothness" , false , false ) ;
var NormalMap = new TextureProperty ( this , k_NormalMap , k_NormalScale , "Normal Map" , "Normal Map" , pairConstantWithTexture : true , isMandatory : false , isNormalMap : true , showScaleOffset : true , slaveTexOneLineProp : BentNormal . m_TextureProperty ) ;
var AmbientOcclusion = new TextureProperty ( this , k_AmbientOcclusionMap , k_AmbientOcclusion , "AmbientOcclusion" , "AmbientOcclusion Map" , false , false ) ;
var SpecularColor = new TextureProperty ( this , k_SpecularColorMap , k_SpecularColor , "Specular Color (f0)" , "Specular Color (f0) (RGB)" , true , false ) ;
var EnergyConservingSpecularColor = new Property ( this , k_EnergyConservingSpecularColor , "Energy Conserving Specular Color" , "Mimics legacy Unity and Lit shader to balance diffuse and specular color" , false ) ;
var StandardMetallicGroup = new GroupProperty ( this , "_Standard" , "Standard Basecolor and Metallic" , new BaseProperty [ ]
{
BaseParametrization ,
BaseColor ,
Metallic ,
DielectricIor ,
SmoothnessA ,
NormalMap ,
BentNormal ,
AmbientOcclusion ,
} , _ = > ( IsMetallicParametrizationUsed ) ) ;
// We keep the name "_Standard" so that the same UI-used foldout property "_StandardShow" is used
var StandardSpecularColorGroup = new GroupProperty ( this , "_Standard" , "Standard Diffuse and Specular Color" , new BaseProperty [ ]
{
BaseParametrization ,
BaseColor ,
SpecularColor ,
EnergyConservingSpecularColor ,
SmoothnessA ,
NormalMap ,
BentNormal ,
AmbientOcclusion ,
} , _ = > ( ! IsMetallicParametrizationUsed ) ) ;
// Dual specular lobe parametrizations:
DualSpecularLobeParametrization = new ComboProperty ( this , k_DualSpecularLobeParametrization , "Dual Specular Lobe Parametrization" , Enum . GetNames ( typeof ( StackLit . DualSpecularLobeParametrization ) ) , false ) ;
var SmoothnessB = new TextureProperty ( this , k_SmoothnessBMap , k_SmoothnessB , "Smoothness B" , "Smoothness B" , false , false ) ;
//var LobeMix = new Property(this, k_LobeMix, "Lobe Mix", "Lobe Mix", false);
var LobeMix = new TextureProperty ( this , k_LobeMixMap , k_LobeMix , "LobeMix" , "LobeMix" , false , false ) ;
var Haziness = new TextureProperty ( this , k_HazinessMap , k_Haziness , "Haziness" , "Haziness" , false , false ) ;
var HazeExtent = new TextureProperty ( this , k_HazeExtentMap , k_HazeExtent , "Haze Extent" , "Haze Extent" , false , false ) ;
var CapHazinessWrtMetallic = new Property ( this , k_CapHazinessWrtMetallic , "Cap Haziness Wrt Metallic" , "Cap Haziness To Agree With Metallic" , false ,
_ = > ( IsMetallicParametrizationUsed ) ) ;
var DualSpecularLobeDirectGroup = new GroupProperty ( this , "_DualSpecularLobe" , "Dual Specular Lobe (Direct Control Mode)" , new BaseProperty [ ]
{
DualSpecularLobeParametrization ,
SmoothnessB ,
LobeMix ,
} , _ = > ( EnableDualSpecularLobe . BoolValue = = true & & ! IsHazyGlossParametrizationUsed ) ) ;
var DualSpecularLobeHazyGlossGroup = new GroupProperty ( this , "_DualSpecularLobe" , "Dual Specular Lobe (Hazy Gloss Mode)" , new BaseProperty [ ]
{
DualSpecularLobeParametrization ,
Haziness ,
CapHazinessWrtMetallic ,
HazeExtent ,
} , _ = > ( EnableDualSpecularLobe . BoolValue = = true & & IsHazyGlossParametrizationUsed ) ) ;
var BentNormalTexProp = new TextureProperty ( this , k_BentNormalMap , "" , "Bent Normal Map" , "Bent Normal Map" , pairConstantWithTexture : true , isMandatory : false , isNormalMap : true , showScaleOffset : false ) ;
_materialProperties = new GroupProperty ( this , "_Material" , new BaseProperty [ ]
{
EnableTransmission
} ) ,
new GroupProperty ( this , "_Standard" , "Standard" , new BaseProperty [ ]
{
new TextureProperty ( this , k_BaseColorMap , k_BaseColor , "Base Color + Opacity" , "Albedo (RGB) and Opacity (A)" , true , false ) ,
new TextureProperty ( this , k_MetallicMap , k_Metallic , "Metallic" , "Metallic" , false , false ) ,
new Property ( this , k_DielectricIor , "DieletricIor" , "IOR use for dielectric material (i.e non metallic material)" , false ) ,
new TextureProperty ( this , k_SmoothnessAMap , k_SmoothnessA , "Smoothness" , "Smoothness" , false , false ) ,
new TextureProperty ( this , k_NormalMap , k_NormalScale , "Normal Map" , "Normal Map" , pairConstantWithTexture : true , isMandatory : false , isNormalMap : true , showScaleOffset : true , slaveTexOneLineProp : BentNormalTexProp . m_TextureProperty ) ,
BentNormalTexProp ,
//new TextureProperty(this, k_BentNormalMap, "", "Bent Normal Map", "Bent Normal Map", pairConstantWithTexture:true, isMandatory:false, isNormalMap:true, showScaleOffset:false),
new TextureProperty ( this , k_AmbientOcclusionMap , k_AmbientOcclusion , "AmbientOcclusion" , "AmbientOcclusion Map" , false , false ) ,
} ) ,
StandardMetallicGroup ,
StandardSpecularColorGroup ,
new GroupProperty ( this , "_Details" , "Details" , new BaseProperty [ ]
{
} , _ = > EnableDetails . BoolValue = = true ) ,
new GroupProperty ( this , "_DualSpecularLobe" , "Dual Specular Lobe" , new BaseProperty [ ]
{
new TextureProperty ( this , k_SmoothnessBMap , k_SmoothnessB , "Smoothness B" , "Smoothness B" , false , false ) ,
new Property ( this , k_LobeMix , "Lobe Mix" , "Lobe Mix" , false ) ,
} , _ = > EnableDualSpecularLobe . BoolValue = = true ) ,
DualSpecularLobeDirectGroup ,
DualSpecularLobeHazyGlossGroup ,
new GroupProperty ( this , "_Anisotropy" , "Anisotropy" , new BaseProperty [ ]
{
SetupTextureMaterialProperty ( material , k_Metallic ) ;
SetupTextureMaterialProperty ( material , k_SmoothnessA ) ;
SetupTextureMaterialProperty ( material , k_SmoothnessB ) ;
SetupTextureMaterialProperty ( material , k_LobeMix ) ;
SetupTextureMaterialProperty ( material , k_Haziness ) ;
SetupTextureMaterialProperty ( material , k_HazeExtent ) ;
SetupTextureMaterialProperty ( material , k_AmbientOcclusion ) ;
SetupTextureMaterialProperty ( material , k_SubsurfaceMask ) ;
SetupTextureMaterialProperty ( material , k_Thickness ) ;
SetupTextureMaterialProperty ( material , k_DetailMask ) ;
SetupTextureMaterialProperty ( material , k_DetailSmoothness ) ;
// Check if we are using specific UVs.
TextureProperty . UVMapping [ ] uvIndices = new [ ]
{
( TextureProperty . UVMapping ) material . GetFloat ( k_BaseColorMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_MetallicMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_NormalMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_SmoothnessAMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_SmoothnessBMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_AmbientOcclusionMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_EmissiveColorMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_SubsurfaceMaskMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_ThicknessMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_AnisotropyMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_IridescenceThicknessMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_IridescenceMaskMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_CoatSmoothnessMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_CoatNormalMapUV ) ,
// Details
( TextureProperty . UVMapping ) material . GetFloat ( k_DetailMaskMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_DetailSmoothnessMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_DetailNormalMapUV ) ,
} ;
// Set keyword for mapping
//bool requireUv2 = false;
//bool requireUv3 = false;
bool requireTriplanar = false ;
for ( int i = 0 ; i < uvIndices . Length ; + + i )
{
//requireUv2 = requireUv2 || uvIndices[i] == TextureProperty.UVMapping.UV2;
//requireUv3 = requireUv3 || uvIndices[i] == TextureProperty.UVMapping.UV3;
requireTriplanar = requireTriplanar | | uvIndices [ i ] = = TextureProperty . UVMapping . Triplanar ;
}
CoreUtils . SetKeyword ( material , "_MAPPING_TRIPLANAR" , requireTriplanar ) ;
bool detailsEnabled = material . HasProperty ( k_EnableDetails ) & & material . GetFloat ( k_EnableDetails ) > 0.0f ;
CoreUtils . SetKeyword ( material , "_DETAILMAP" , detailsEnabled ) ;
bool specularOcclusionEnabled = material . HasProperty ( k_EnableSpecularOcclusion ) & & material . GetFloat ( k_EnableSpecularOcclusion ) > 0.0f ;
CoreUtils . SetKeyword ( material , "_ENABLESPECULAROCCLUSION" , specularOcclusionEnabled ) ;
bool specularColorEnabled = material . HasProperty ( k_BaseParametrization )
& & ( ( StackLit . BaseParametrization ) material . GetFloat ( k_BaseParametrization ) = = StackLit . BaseParametrization . SpecularColor ) ;
CoreUtils . SetKeyword ( material , "_MATERIAL_FEATURE_SPECULAR_COLOR" , specularColorEnabled ) ;
bool hazyGlossEnabled = dualSpecularLobeEnabled & & material . HasProperty ( k_DualSpecularLobeParametrization )
& & ( ( StackLit . DualSpecularLobeParametrization ) material . GetFloat ( k_DualSpecularLobeParametrization ) = = StackLit . DualSpecularLobeParametrization . HazyGloss ) ;
CoreUtils . SetKeyword ( material , "_MATERIAL_FEATURE_HAZY_GLOSS" , hazyGlossEnabled ) ;
bool anisotropyEnabled = material . HasProperty ( k_EnableAnisotropy ) & & material . GetFloat ( k_EnableAnisotropy ) > 0.0f ;
CoreUtils . SetKeyword ( material , "_MATERIAL_FEATURE_ANISOTROPY" , anisotropyEnabled ) ;
bool coatEnabled = material . HasProperty ( k_EnableCoat ) & & material . GetFloat ( k_EnableCoat ) > 0.0f ;
CoreUtils . SetKeyword ( material , "_MATERIAL_FEATURE_COAT" , coatEnabled ) ;
bool coatNormalMapEnabled = material . HasProperty ( k_EnableCoatNormalMap ) & & material . GetFloat ( k_EnableCoatNormalMap ) > 0.0f ;
bool coatNormalMapEnabled = coatEnabled & & material . HasProperty ( k_EnableCoatNormalMap ) & & material . GetFloat ( k_EnableCoatNormalMap ) > 0.0f ;
CoreUtils . SetKeyword ( material , "_MATERIAL_FEATURE_COAT_NORMALMAP" , coatNormalMapEnabled ) ;
// TEMP - Remove once dev is finish
bool vlayerRecomputePerLight = material . HasProperty ( "_VlayerRecomputePerLight" ) & & material . GetFloat ( "_VlayerRecomputePerLight" ) > 0.0f ;
bool vlayerRecomputePerLight = ( coatEnabled | | iridescenceEnabled ) & & material . HasProperty ( "_VlayerRecomputePerLight" ) & & material . GetFloat ( "_VlayerRecomputePerLight" ) > 0.0f ;
bool vlayerUseRefractedAnglesForBase = material . HasProperty ( "_VlayerUseRefractedAnglesForBase" ) & & material . GetFloat ( "_VlayerUseRefractedAnglesForBase" ) > 0.0f ;
bool vlayerUseRefractedAnglesForBase = coatEnabled & & material . HasProperty ( "_VlayerUseRefractedAnglesForBase" ) & & material . GetFloat ( "_VlayerUseRefractedAnglesForBase" ) > 0.0f ;
//
// Check if we are using specific UVs (but only for potentially used maps):
//
TextureProperty . UVMapping metallicMapUV = specularColorEnabled ? TextureProperty . UVMapping . UV0 : ( TextureProperty . UVMapping ) material . GetFloat ( k_MetallicMapUV ) ;
TextureProperty . UVMapping specularColorMapUV = specularColorEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_SpecularColorMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping smoothnessBMapUV = ( dualSpecularLobeEnabled & & ! hazyGlossEnabled ) ? ( TextureProperty . UVMapping ) material . GetFloat ( k_SmoothnessBMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping lobeMixMapUV = ( dualSpecularLobeEnabled & & ! hazyGlossEnabled ) ? ( TextureProperty . UVMapping ) material . GetFloat ( k_LobeMixMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping hazinessMapUV = ( dualSpecularLobeEnabled & & hazyGlossEnabled ) ? ( TextureProperty . UVMapping ) material . GetFloat ( k_HazinessMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping hazeExtentMapUV = ( dualSpecularLobeEnabled & & hazyGlossEnabled ) ? ( TextureProperty . UVMapping ) material . GetFloat ( k_HazeExtentMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping subsurfaceMaskMapUV = sssEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_SubsurfaceMaskMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping thicknessMapUV = sssEnabled | | transmissionEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_ThicknessMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping anisotropyMapUV = anisotropyEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_AnisotropyMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping iridescenceThicknessMapUV = iridescenceEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_IridescenceThicknessMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping iridescenceMaskMapUV = iridescenceEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_IridescenceMaskMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping coatSmoothnessMapUV = coatEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_CoatSmoothnessMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping coatNormalMapUV = coatEnabled & & coatNormalMapEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_CoatNormalMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping detailMaskMapUV = detailsEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_DetailMaskMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping detailSmoothnessMapUV = detailsEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_DetailSmoothnessMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping detailNormalMapUV = detailsEnabled ? ( TextureProperty . UVMapping ) material . GetFloat ( k_DetailNormalMapUV ) : TextureProperty . UVMapping . UV0 ;
TextureProperty . UVMapping [ ] uvIndices = new [ ]
{
metallicMapUV ,
specularColorMapUV ,
smoothnessBMapUV ,
lobeMixMapUV ,
hazinessMapUV ,
hazeExtentMapUV ,
subsurfaceMaskMapUV ,
thicknessMapUV ,
anisotropyMapUV ,
iridescenceThicknessMapUV ,
iridescenceMaskMapUV ,
coatSmoothnessMapUV ,
coatNormalMapUV ,
detailMaskMapUV ,
detailSmoothnessMapUV ,
detailNormalMapUV ,
( TextureProperty . UVMapping ) material . GetFloat ( k_BaseColorMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_NormalMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_SmoothnessAMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_AmbientOcclusionMapUV ) ,
( TextureProperty . UVMapping ) material . GetFloat ( k_EmissiveColorMapUV ) ,
} ;
// Set keyword for mapping
//bool requireUv2 = false;
//bool requireUv3 = false;
bool requireTriplanar = false ;
for ( int i = 0 ; i < uvIndices . Length ; + + i )
{
//requireUv2 = requireUv2 || uvIndices[i] == TextureProperty.UVMapping.UV2;
//requireUv3 = requireUv3 || uvIndices[i] == TextureProperty.UVMapping.UV3;
requireTriplanar = requireTriplanar | | uvIndices [ i ] = = TextureProperty . UVMapping . Triplanar ;
}
CoreUtils . SetKeyword ( material , "_MAPPING_TRIPLANAR" , requireTriplanar ) ;
// Set the reference value for the stencil test - required for SSS
int stencilRef = ( int ) StencilLightingUsage . RegularLighting ;