namespace UnityEditor.Experimental.Rendering.HDPipeline
{
// A Material can be authored from the shader graph or by hand. When written by hand we need to provide an inspector.
// Such a Material will share some properties between it various variant (shader graph variant or hand authored variant).
// This is the purpose of BaseLitGUI. It contain all properties that are common to all Material based on Lit template.
// For the default hand written Lit material see LitUI.cs that contain specific properties for our default implementation.
protected static class Styles
protected static class StylesBase
public static string blendModeText = "Blend Mode" ;
public static string detailText = "Inputs Detail" ;
public static string textureControlText = "Input textures control" ;
public static string lightingText = "Inputs Lighting" ;
public static string blendModeText = "Blend Mode" ;
public static readonly string [ ] surfaceTypeNames = Enum . GetNames ( typeof ( SurfaceType ) ) ;
public static readonly string [ ] blendModeNames = Enum . GetNames ( typeof ( BlendMode ) ) ;
public static GUIContent doubleSidedEnableText = new GUIContent ( "Double Sided" , "This will render the two face of the objects (disable backface culling) and mirror normal" ) ;
public static GUIContent doubleSidedEnableText = new GUIContent ( "Double Sided" , "This will render the two face of the objects (disable backface culling) and flip/mirror normal" ) ;
public static GUIContent doubleSidedMirrorEnableText = new GUIContent ( "Mirror normal" , "This will mirror the normal with vertex normal plane if enabled, else flip the normal" ) ;
public static GUIContent horizonFadeText = new GUIContent ( "Horizon Fade (Spec occlusion)" , "horizon fade is use to control specular occlusion" ) ;
public static readonly string [ ] surfaceTypeNames = Enum . GetNames ( typeof ( SurfaceType ) ) ;
public static readonly string [ ] blendModeNames = Enum . GetNames ( typeof ( BlendMode ) ) ;
public static GUIContent emissiveWarning = new GUIContent ( "Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive." ) ;
public static GUIContent emissiveColorWarning = new GUIContent ( "Ensure emissive color is non-black for emission to have effect." ) ;
// Material ID
public static GUIContent materialIDText = new GUIContent ( "Material type" , "Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk." ) ;
public static GUIContent smoothnessMapChannelText = new GUIContent ( "Smoothness Source" , "Smoothness texture and channel" ) ;
public static GUIContent UVBaseMappingText = new GUIContent ( "Base UV mapping" , "" ) ;
public static GUIContent texWorldScaleText = new GUIContent ( "World scale" , "Tiling factor applied to Planar/Trilinear mapping" ) ;
public static GUIContent normalMapSpaceText = new GUIContent ( "Normal/Tangent Map space" , "" ) ;
// Per pixel displacement
public static GUIContent detailMapModeText = new GUIContent ( "Detail Map with Normal" , "Detail Map with AO / Height" ) ;
public static GUIContent UVDetailMappingText = new GUIContent ( "Detail UV mapping" , "" ) ;
public static GUIContent emissiveColorModeText = new GUIContent ( "Emissive Color Usage" , "Use emissive color or emissive mask" ) ;
public static string InputsText = "Inputs" ;
public static string InputsMapText = "" ;
public static GUIContent baseColorText = new GUIContent ( "Base Color + Opacity" , "Albedo (RGB) and Opacity (A)" ) ;
public static GUIContent baseColorSmoothnessText = new GUIContent ( "Base Color + Smoothness" , "Albedo (RGB) and Smoothness (A)" ) ;
public static GUIContent metallicText = new GUIContent ( "Metallic" , "Metallic scale factor" ) ;
public static GUIContent smoothnessText = new GUIContent ( "Smoothness" , "Smoothness scale factor" ) ;
public static GUIContent maskMapESText = new GUIContent ( "Mask Map - M(R), AO(G), E(B), S(A)" , "Mask map" ) ;
public static GUIContent maskMapSText = new GUIContent ( "Mask Map - M(R), AO(G), S(A)" , "Mask map" ) ;
public static GUIContent specularOcclusionMapText = new GUIContent ( "Specular Occlusion Map (RGBA)" , "Specular Occlusion Map" ) ;
public static GUIContent normalMapText = new GUIContent ( "Normal Map" , "Normal Map (DXT5) - Need to implement BC5" ) ;
public static GUIContent heightMapText = new GUIContent ( "Height Map (R)" , "Height Map" ) ;
public static GUIContent heightMapAmplitudeText = new GUIContent ( "Height Map Amplitude" , "Height Map amplitude in world units." ) ;
public static GUIContent heightMapCenterText = new GUIContent ( "Height Map Center" , "Center of the heightmap in the texture (between 0 and 1)" ) ;
public static GUIContent tangentMapText = new GUIContent ( "Tangent Map" , "Tangent Map (BC5) - DXT5 for test" ) ;
public static GUIContent anisotropyText = new GUIContent ( "Anisotropy" , "Anisotropy scale factor" ) ;
public static GUIContent anisotropyMapText = new GUIContent ( "Anisotropy Map (B)" , "Anisotropy" ) ;
public static GUIContent detailMapNormalText = new GUIContent ( "Detail Map A(R) Ny(G) S(B) Nx(A)" , "Detail Map" ) ;
public static GUIContent detailMaskText = new GUIContent ( "Detail Mask (G)" , "Mask for detailMap" ) ;
public static GUIContent detailAlbedoScaleText = new GUIContent ( "Detail AlbedoScale" , "Detail Albedo Scale factor" ) ;
public static GUIContent detailNormalScaleText = new GUIContent ( "Detail NormalScale" , "Normal Scale factor" ) ;
public static GUIContent detailSmoothnessScaleText = new GUIContent ( "Detail SmoothnessScale" , "Smoothness Scale factor" ) ;
public static GUIContent detailHeightScaleText = new GUIContent ( "Detail HeightScale" , "Height Scale factor" ) ;
public static GUIContent detailAOScaleText = new GUIContent ( "Detail AOScale" , "AO Scale factor" ) ;
public static GUIContent emissiveText = new GUIContent ( "Emissive Color" , "Emissive" ) ;
public static GUIContent emissiveIntensityText = new GUIContent ( "Emissive Intensity" , "Emissive" ) ;
public static GUIContent emissiveWarning = new GUIContent ( "Emissive value is animated but the material has not been configured to support emissive. Please make sure the material itself has some amount of emissive." ) ;
public static GUIContent emissiveColorWarning = new GUIContent ( "Ensure emissive color is non-black for emission to have effect." ) ;
// Tessellation
public static string tessellationModeText = "Tessellation Mode" ;
public static readonly string [ ] tessellationModeNames = Enum . GetNames ( typeof ( TessellationMode ) ) ;
public static GUIContent tessellationShapeFactorText = new GUIContent ( "Shape factor" , "Strength of Phong tessellation shape (lerp factor)" ) ;
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent ( "Triangle culling Epsilon" , "If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance" ) ;
public static GUIContent tessellationObjectScaleText = new GUIContent ( "Enable object scale" , "Tesselation displacement will take into account the object scale - Only work with uniform positive scale" ) ;
public static GUIContent perPixelDisplacementText = new GUIContent ( "Per pixel displacement" , "Per pixel displacement options" ) ;
public static GUIContent materialIDText = new GUIContent ( "Material type" , "Subsurface Scattering: enable for translucent materials such as skin, vegetation, fruit, marble, wax and milk." ) ;
public static GUIContent subsurfaceProfileText = new GUIContent ( "Subsurface profile" , "A profile determines the shape of the blur filter." ) ;
public static GUIContent subsurfaceRadiusText = new GUIContent ( "Subsurface radius" , "Determines the range of the blur." ) ;
public static GUIContent subsurfaceRadiusMapText = new GUIContent ( "Subsurface radius map" , "Determines the range of the blur." ) ;
public static GUIContent thicknessText = new GUIContent ( "Thickness" , "If subsurface scattering is enabled, low values allow some light to be transmitted through the object." ) ;
public static GUIContent thicknessMapText = new GUIContent ( "Thickness map" , "If subsurface scattering is enabled, low values allow some light to be transmitted through the object." ) ;
}
public enum SurfaceType
DisplacementPhong ,
}
protected MaterialEditor m_MaterialEditor ;
// Properties
protected MaterialProperty surfaceType = null ;
protected const string kSurfaceType = "_SurfaceType" ;
protected MaterialProperty alphaCutoffEnable = null ;
protected const string kAlphaCutoffEnabled = "_AlphaCutoffEnable" ;
protected MaterialProperty alphaCutoff = null ;
protected const string kAlphaCutoff = "_AlphaCutoff" ;
protected MaterialProperty doubleSidedEnable = null ;
protected const string kDoubleSidedEnable = "_DoubleSidedEnable" ;
protected MaterialProperty doubleSidedMirrorEnable = null ;
protected const string kDoubleSidedMirrorEnable = "_DoubleSidedMirrorEnable" ;
protected MaterialProperty blendMode = null ;
protected const string kBlendMode = "_BlendMode" ;
protected MaterialProperty distortionEnable = null ;
protected const string kDistortionEnable = "_DistortionEnable" ;
protected MaterialProperty distortionOnly = null ;
protected const string kDistortionOnly = "_DistortionOnly" ;
protected MaterialProperty distortionDepthTest = null ;
protected const string kDistortionDepthTest = "_DistortionDepthTest" ;
protected MaterialProperty depthOffsetEnable = null ;
protected const string kDepthOffsetEnable = "_DepthOffsetEnable" ;
// Material ID
protected MaterialProperty materialID = null ;
protected const string kMaterialID = "_MaterialID" ;
// Per pixel displacement params
protected MaterialProperty enablePerPixelDisplacement = null ;
protected const string kEnablePerPixelDisplacement = "_EnablePerPixelDisplacement" ;
protected MaterialProperty ppdMinSamples = null ;
protected const string kPpdMinSamples = "_PPDMinSamples" ;
protected MaterialProperty ppdMaxSamples = null ;
protected const string kPpdMaxSamples = "_PPDMaxSamples" ;
protected MaterialProperty ppdLodThreshold = null ;
protected const string kPpdLodThreshold = "_PPDLodThreshold" ;
// tessellation params
protected MaterialProperty tessellationMode = null ;
protected const string kTessellationMode = "_TessellationMode" ;
protected MaterialProperty tessellationFactor = null ;
protected const string kTessellationFactor = "_TessellationFactor" ;
protected MaterialProperty tessellationFactorMinDistance = null ;
protected const string kTessellationFactorMinDistance = "_TessellationFactorMinDistance" ;
protected MaterialProperty tessellationFactorMaxDistance = null ;
protected const string kTessellationFactorMaxDistance = "_TessellationFactorMaxDistance" ;
protected MaterialProperty tessellationFactorTriangleSize = null ;
protected const string kTessellationFactorTriangleSize = "_TessellationFactorTriangleSize" ;
protected MaterialProperty tessellationShapeFactor = null ;
protected const string kTessellationShapeFactor = "_TessellationShapeFactor" ;
protected MaterialProperty tessellationBackFaceCullEpsilon = null ;
protected const string kTessellationBackFaceCullEpsilon = "_TessellationBackFaceCullEpsilon" ;
protected MaterialProperty tessellationObjectScale = null ;
protected const string kTessellationObjectScale = "_TessellationObjectScale" ;
// See comment in LitProperties.hlsl
const string kEmissionColor = "_EmissionColor" ;
// The following set of functions are call by the ShaderGraph
// It will allow to display our common parameters + setup keyword correctly for them
protected abstract void FindMaterialProperties ( MaterialProperty [ ] props ) ;
protected abstract void SetupMaterialKeywordsInternal ( Material material ) ;
protected abstract void MaterialPropertiesGUI ( ) ;
// This function will said if emissive is use or not dor enlighten/PVR consideration
protected abstract bool ShouldEmissionBeEnabled ( Material material ) ;
protected void FindBaseMaterialProperties ( MaterialProperty [ ] props )
{
surfaceType = FindProperty ( kSurfaceType , props ) ;
alphaCutoffEnable = FindProperty ( kAlphaCutoffEnabled , props ) ;
alphaCutoff = FindProperty ( kAlphaCutoff , props ) ;
doubleSidedEnable = FindProperty ( kDoubleSidedEnable , props ) ;
doubleSidedMirrorEnable = FindProperty ( kDoubleSidedMirrorEnable , props ) ;
blendMode = FindProperty ( kBlendMode , props ) ;
distortionEnable = FindProperty ( kDistortionEnable , props ) ;
distortionOnly = FindProperty ( kDistortionOnly , props ) ;
distortionDepthTest = FindProperty ( kDistortionDepthTest , props ) ;
depthOffsetEnable = FindProperty ( kDepthOffsetEnable , props ) ;
// MaterialID
materialID = FindProperty ( kMaterialID , props , false ) ;
// Per pixel displacement
enablePerPixelDisplacement = FindProperty ( kEnablePerPixelDisplacement , props ) ;
ppdMinSamples = FindProperty ( kPpdMinSamples , props ) ;
ppdMaxSamples = FindProperty ( kPpdMaxSamples , props ) ;
ppdLodThreshold = FindProperty ( kPpdLodThreshold , props ) ;
// tessellation specific, silent if not found
tessellationMode = FindProperty ( kTessellationMode , props , false ) ;
tessellationFactor = FindProperty ( kTessellationFactor , props , false ) ;
tessellationFactorMinDistance = FindProperty ( kTessellationFactorMinDistance , props , false ) ;
tessellationFactorMaxDistance = FindProperty ( kTessellationFactorMaxDistance , props , false ) ;
tessellationFactorTriangleSize = FindProperty ( kTessellationFactorTriangleSize , props , false ) ;
tessellationShapeFactor = FindProperty ( kTessellationShapeFactor , props , false ) ;
tessellationBackFaceCullEpsilon = FindProperty ( kTessellationBackFaceCullEpsilon , props , false ) ;
tessellationObjectScale = FindProperty ( kTessellationObjectScale , props , false ) ;
}
void SurfaceTypePopup ( )
{
EditorGUI . showMixedValue = surfaceType . hasMixedValue ;
mode = ( SurfaceType ) EditorGUILayout . Popup ( Styles . surfaceTypeText , ( int ) mode , Styles . surfaceTypeNames ) ;
mode = ( SurfaceType ) EditorGUILayout . Popup ( StylesBase . surfaceTypeText , ( int ) mode , StylesBase . surfaceTypeNames ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
m_MaterialEditor . RegisterPropertyChangeUndo ( "Surface Type" ) ;
var mode = ( BlendMode ) blendMode . floatValue ;
EditorGUI . BeginChangeCheck ( ) ;
mode = ( BlendMode ) EditorGUILayout . Popup ( Styles . blendModeText , ( int ) mode , Styles . blendModeNames ) ;
mode = ( BlendMode ) EditorGUILayout . Popup ( StylesBase . blendModeText , ( int ) mode , StylesBase . blendModeNames ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
m_MaterialEditor . RegisterPropertyChangeUndo ( "Blend Mode" ) ;
var mode = ( TessellationMode ) tessellationMode . floatValue ;
EditorGUI . BeginChangeCheck ( ) ;
mode = ( TessellationMode ) EditorGUILayout . Popup ( Styles . tessellationModeText , ( int ) mode , Styles . tessellationModeNames ) ;
mode = ( TessellationMode ) EditorGUILayout . Popup ( StylesBase . tessellationModeText , ( int ) mode , StylesBase . tessellationModeNames ) ;
if ( EditorGUI . EndChangeCheck ( ) )
{
m_MaterialEditor . RegisterPropertyChangeUndo ( "Tessellation Mode" ) ;
EditorGUI . showMixedValue = false ;
}
protected void ShaderOptionsGUI ( )
protected void BaseMaterialPropertiesGUI ( )
GUILayout . Label ( Styles . optionText , EditorStyles . boldLabel ) ;
GUILayout . Label ( StylesBase . optionText , EditorStyles . boldLabel ) ;
m_MaterialEditor . ShaderProperty ( distortionEnable , Styles . distortionEnableText . text ) ;
m_MaterialEditor . ShaderProperty ( distortionEnable , StylesBase . distortionEnableText ) ;
if ( distortionEnable . floatValue = = 1.0 )
if ( distortionEnable . floatValue = = 1.0f )
m_MaterialEditor . ShaderProperty ( distortionOnly , Styles . distortionOnlyText . text ) ;
m_MaterialEditor . ShaderProperty ( distortionDepthTest , Styles . distortionDepthTestText . text ) ;
m_MaterialEditor . ShaderProperty ( distortionOnly , StylesBase . distortionOnlyText ) ;
m_MaterialEditor . ShaderProperty ( distortionDepthTest , StylesBase . distortionDepthTestText ) ;
m_MaterialEditor . ShaderProperty ( alphaCutoffEnable , Styles . alphaCutoffEnableText . text ) ;
if ( alphaCutoffEnable . floatValue = = 1.0 )
m_MaterialEditor . ShaderProperty ( alphaCutoffEnable , StylesBase . alphaCutoffEnableText ) ;
if ( alphaCutoffEnable . floatValue = = 1.0f )
{
m_MaterialEditor . ShaderProperty ( alphaCutoff , StylesBase . alphaCutoffText ) ;
}
m_MaterialEditor . ShaderProperty ( doubleSidedEnable , StylesBase . doubleSidedEnableText ) ;
if ( doubleSidedEnable . floatValue > 0.0f )
m_MaterialEditor . ShaderProperty ( alphaCutoff , Styles . alphaCutoffText . text ) ;
EditorGUI . indentLevel + + ;
m_MaterialEditor . ShaderProperty ( doubleSidedMirrorEnable , StylesBase . doubleSidedMirrorEnableText ) ;
EditorGUI . indentLevel - - ;
m_MaterialEditor . ShaderProperty ( doubleSidedEnable , Styles . doubleSidedEnableText . text ) ;
m_MaterialEditor . ShaderProperty ( enablePerPixelDisplacement , Styles . enablePerPixelDisplacementText ) ;
if ( enablePerPixelDisplacement . floatValue > 0.0 )
if ( materialID ! = null )
m_MaterialEditor . ShaderProperty ( materialID , StylesBase . materialIDText ) ;
m_MaterialEditor . ShaderProperty ( enablePerPixelDisplacement , StylesBase . enablePerPixelDisplacementText ) ;
if ( enablePerPixelDisplacement . floatValue > 0.0f )
m_MaterialEditor . ShaderProperty ( ppdMinSamples , Styles . ppdMinSamplesText ) ;
m_MaterialEditor . ShaderProperty ( ppdMaxSamples , Styles . ppdMaxSamplesText ) ;
m_MaterialEditor . ShaderProperty ( ppdMinSamples , StylesBase . ppdMinSamplesText ) ;
m_MaterialEditor . ShaderProperty ( ppdMaxSamples , StylesBase . ppdMaxSamplesText ) ;
m_MaterialEditor . ShaderProperty ( ppdLodThreshold , Styles . ppdLodThresholdText ) ;
m_MaterialEditor . ShaderProperty ( depthOffsetEnable , Styles . depthOffsetEnableText . text ) ;
m_MaterialEditor . ShaderProperty ( ppdLodThreshold , StylesBase . ppdLodThresholdText ) ;
m_MaterialEditor . ShaderProperty ( depthOffsetEnable , StylesBase . depthOffsetEnableText ) ;
m_MaterialEditor . ShaderProperty ( horizonFade , Styles . horizonFadeText ) ;
// Display tessellation option if it exist
GUILayout . Label ( Styles . tessellationText , EditorStyles . boldLabel ) ;
GUILayout . Label ( StylesBase . tessellationText , EditorStyles . boldLabel ) ;
m_MaterialEditor . ShaderProperty ( tessellationFactor , Styles . tessellationFactorText ) ;
m_MaterialEditor . ShaderProperty ( tessellationFactorMinDistance , Styles . tessellationFactorMinDistanceText ) ;
m_MaterialEditor . ShaderProperty ( tessellationFactorMaxDistance , Styles . tessellationFactorMaxDistanceText ) ;
m_MaterialEditor . ShaderProperty ( tessellationFactor , StylesBase . tessellationFactorText ) ;
m_MaterialEditor . ShaderProperty ( tessellationFactorMinDistance , StylesBase . tessellationFactorMinDistanceText ) ;
m_MaterialEditor . ShaderProperty ( tessellationFactorMaxDistance , StylesBase . tessellationFactorMaxDistanceText ) ;
m_MaterialEditor . ShaderProperty ( tessellationFactorTriangleSize , Styles . tessellationFactorTriangleSizeText ) ;
m_MaterialEditor . ShaderProperty ( tessellationFactorTriangleSize , StylesBase . tessellationFactorTriangleSizeText ) ;
m_MaterialEditor . ShaderProperty ( tessellationShapeFactor , Styles . tessellationShapeFactorText ) ;
m_MaterialEditor . ShaderProperty ( tessellationShapeFactor , StylesBase . tessellationShapeFactorText ) ;
m_MaterialEditor . ShaderProperty ( tessellationBackFaceCullEpsilon , Styles . tessellationBackFaceCullEpsilonText ) ;
m_MaterialEditor . ShaderProperty ( tessellationBackFaceCullEpsilon , StylesBase . tessellationBackFaceCullEpsilonText ) ;
m_MaterialEditor . ShaderProperty ( tessellationObjectScale , Styles . tessellationObjectScaleText ) ;
m_MaterialEditor . ShaderProperty ( tessellationObjectScale , StylesBase . tessellationObjectScaleText ) ;
protected void FindCommonOptionProperties ( MaterialProperty [ ] props )
static public void SetKeyword ( Material m , string keyword , bool state )
surfaceType = FindProperty ( kSurfaceType , props ) ;
blendMode = FindProperty ( kBlendMode , props ) ;
alphaCutoff = FindProperty ( kAlphaCutoff , props ) ;
alphaCutoffEnable = FindProperty ( kAlphaCutoffEnabled , props ) ;
doubleSidedEnable = FindProperty ( kDoubleSidedEnable , props ) ;
distortionEnable = FindProperty ( kDistortionEnable , props ) ;
distortionOnly = FindProperty ( kDistortionOnly , props ) ;
distortionDepthTest = FindProperty ( kDistortionDepthTest , props ) ;
depthOffsetEnable = FindProperty ( kDepthOffsetEnable , props ) ;
horizonFade = FindProperty ( kHorizonFade , props ) ;
// tessellation specific, silent if not found
tessellationMode = FindProperty ( kTessellationMode , props , false ) ;
tessellationFactor = FindProperty ( kTessellationFactor , props , false ) ;
tessellationFactorMinDistance = FindProperty ( kTessellationFactorMinDistance , props , false ) ;
tessellationFactorMaxDistance = FindProperty ( kTessellationFactorMaxDistance , props , false ) ;
tessellationFactorTriangleSize = FindProperty ( kTessellationFactorTriangleSize , props , false ) ;
tessellationShapeFactor = FindProperty ( kTessellationShapeFactor , props , false ) ;
tessellationBackFaceCullEpsilon = FindProperty ( kTessellationBackFaceCullEpsilon , props , false ) ;
tessellationObjectScale = FindProperty ( kTessellationObjectScale , props , false ) ;
// Per pixel displacement
enablePerPixelDisplacement = FindProperty ( kEnablePerPixelDisplacement , props ) ;
ppdMinSamples = FindProperty ( kPpdMinSamples , props ) ;
ppdMaxSamples = FindProperty ( kPpdMaxSamples , props ) ;
ppdLodThreshold = FindProperty ( kPpdLodThreshold , props ) ;
if ( state )
m . EnableKeyword ( keyword ) ;
else
m . DisableKeyword ( keyword ) ;
protected void SetupCommonOptionsKeywords ( Material material )
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if ocde change
static public void SetupBaseKeywords ( Material material )
bool doubleSidedMirrorEnable = material . GetFloat ( kDoubleSidedMirrorEnable ) > 0.0f ;
if ( surfaceType = = SurfaceType . Opaque )
{
material . SetOverrideTag ( "RenderType" , alphaTestEnable ? "TransparentCutout" : "" ) ;
if ( doubleSidedEnable )
{
material . SetInt ( "_CullMode" , ( int ) UnityEngine . Rendering . CullMode . Off ) ;
material . SetInt ( "_CullMode" , ( int ) UnityEngine . Rendering . CullMode . Off ) ;
if ( doubleSidedMirrorEnable )
{
// Flip mode (in tangent space)
material . SetVector ( "_DoubleSidedConstants" , new Vector3 ( - 1.0f , - 1.0f , - 1.0f ) ) ;
}
else
{
// Mirror mode (in tangent space)
material . SetVector ( "_DoubleSidedConstants" , new Vector3 ( 1.0f , 1.0f , - 1.0f ) ) ;
}
}
else
{
if ( distortionEnable & & distortionOnly )
{
// Disable all passes except dbug material
// Disable all passes except de bug material
material . SetShaderPassEnabled ( "GBuffer" , false ) ;
material . SetShaderPassEnabled ( "DebugViewMaterial" , true ) ;
material . SetShaderPassEnabled ( "Meta" , false ) ;
SetKeyword ( material , "_DISTORTION_ON" , distortionEnable ) ;
SetKeyword ( material , "_DEPTHOFFSET_ON" , depthOffsetEnable ) ;
SetupEmissionGIFlags ( material ) ;
material . SetInt ( "_StencilRef" , ( int ) material . GetFloat ( kMaterialID ) ) ; // See 'StencilBits'.
if ( tessellationMode ! = null )
bool enablePerPixelDisplacement = material . GetFloat ( kEnablePerPixelDisplacement ) > 0.0f ;
SetKeyword ( material , "_PER_PIXEL_DISPLACEMENT" , enablePerPixelDisplacement ) ;
if ( material . HasProperty ( kTessellationMode ) )
{
TessellationMode tessMode = ( TessellationMode ) material . GetFloat ( kTessellationMode ) ;
}
}
protected void SetKeyword ( Material m , string keyword , bool state )
// Dedicated to emissive - for emissive Enlighten/PVR
protected void DoEmissionArea ( Material material )
if ( state )
m . EnableKeyword ( keyword ) ;
else
m . DisableKeyword ( keyword ) ;
// Emission for GI?
if ( ShouldEmissionBeEnabled ( material ) )
{
if ( m_MaterialEditor . EmissionEnabledProperty ( ) )
{
// change the GI flag and fix it up with emissive as black if necessary
m_MaterialEditor . LightmapEmissionFlagsProperty ( MaterialEditor . kMiniTextureFieldLabelIndentLevel , true ) ;
}
}
}
public void ShaderPropertiesGUI ( Material material )
// Detect any changes to the material
EditorGUI . BeginChangeCheck ( ) ;
{
ShaderOptionsGUI ( ) ;
BaseMaterialPropertiesGUI ( ) ;
ShaderInputGUI ( ) ;
MaterialPropertiesGUI ( ) ;
DoEmissionArea ( material ) ;
m_MaterialEditor . EnableInstancingField ( ) ;
SetupMaterialKeywords ( ( Material ) obj ) ;
SetupMaterialKeywordsInternal ( ( Material ) obj ) ;
// This is call by the inspector
FindCommonOptionProperties ( props ) ; // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
m_MaterialEditor = materialEditor ;
// We should always do this call at the beginning
m_MaterialEditor . serializedObject . Update ( ) ;
// MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly
FindBaseMaterialProperties ( props ) ;
m_MaterialEditor = materialEditor ;
}
// TODO: ? or remove
bool HasValidEmissiveKeyword ( Material material )
{
/ *
// Material animation might be out of sync with the material keyword.
// So if the emission support is disabled on the material, but the property blocks have a value that requires it, then we need to show a warning.
// (note: (Renderer MaterialPropertyBlock applies its values to emissionColorForRendering))
bool hasEmissionKeyword = material . IsKeywordEnabled ( "_EMISSION" ) ;
if ( ! hasEmissionKeyword & & ShouldEmissionBeEnabled ( material , emissionColorForRendering . colorValue ) )
return false ;
else
return true ;
* /
return true ;
// We should always do this call at the end
m_MaterialEditor . serializedObject . ApplyModifiedProperties ( ) ;
protected virtual void SetupEmissionGIFlags ( Material material )
{
// Setup lightmap emissive flags
MaterialGlobalIlluminationFlags flags = material . globalIlluminationFlags ;
if ( ( flags & ( MaterialGlobalIlluminationFlags . BakedEmissive | MaterialGlobalIlluminationFlags . RealtimeEmissive ) ) ! = 0 )
{
if ( ShouldEmissionBeEnabled ( material ) )
flags & = ~ MaterialGlobalIlluminationFlags . EmissiveIsBlack ;
else
flags | = MaterialGlobalIlluminationFlags . EmissiveIsBlack ;
material . globalIlluminationFlags = flags ;
}
}
protected MaterialEditor m_MaterialEditor ;
MaterialProperty surfaceType = null ;
const string kSurfaceType = "_SurfaceType" ;
MaterialProperty alphaCutoffEnable = null ;
const string kAlphaCutoffEnabled = "_AlphaCutoffEnable" ;
MaterialProperty blendMode = null ;
const string kBlendMode = "_BlendMode" ;
MaterialProperty alphaCutoff = null ;
const string kAlphaCutoff = "_AlphaCutoff" ;
MaterialProperty doubleSidedEnable = null ;
const string kDoubleSidedEnable = "_DoubleSidedEnable" ;
MaterialProperty distortionEnable = null ;
const string kDistortionEnable = "_DistortionEnable" ;
MaterialProperty distortionOnly = null ;
const string kDistortionOnly = "_DistortionOnly" ;
MaterialProperty distortionDepthTest = null ;
const string kDistortionDepthTest = "_DistortionDepthTest" ;
MaterialProperty depthOffsetEnable = null ;
const string kDepthOffsetEnable = "_DepthOffsetEnable" ;
protected MaterialProperty horizonFade = null ;
const string kHorizonFade = "_HorizonFade" ;
// tessellation params
protected MaterialProperty tessellationMode = null ;
const string kTessellationMode = "_TessellationMode" ;
MaterialProperty tessellationFactor = null ;
const string kTessellationFactor = "_TessellationFactor" ;
MaterialProperty tessellationFactorMinDistance = null ;
const string kTessellationFactorMinDistance = "_TessellationFactorMinDistance" ;
MaterialProperty tessellationFactorMaxDistance = null ;
const string kTessellationFactorMaxDistance = "_TessellationFactorMaxDistance" ;
MaterialProperty tessellationFactorTriangleSize = null ;
const string kTessellationFactorTriangleSize = "_TessellationFactorTriangleSize" ;
MaterialProperty tessellationShapeFactor = null ;
const string kTessellationShapeFactor = "_TessellationShapeFactor" ;
MaterialProperty tessellationBackFaceCullEpsilon = null ;
const string kTessellationBackFaceCullEpsilon = "_TessellationBackFaceCullEpsilon" ;
MaterialProperty tessellationObjectScale = null ;
const string kTessellationObjectScale = "_TessellationObjectScale" ;
// Per pixel displacement params
protected MaterialProperty enablePerPixelDisplacement = null ;
protected const string kEnablePerPixelDisplacement = "_EnablePerPixelDisplacement" ;
protected MaterialProperty ppdMinSamples = null ;
protected const string kPpdMinSamples = "_PPDMinSamples" ;
protected MaterialProperty ppdMaxSamples = null ;
protected const string kPpdMaxSamples = "_PPDMaxSamples" ;
protected MaterialProperty ppdLodThreshold = null ;
protected const string kPpdLodThreshold = "_PPDLodThreshold" ;
protected static string [ ] reservedProperties = new string [ ] { kSurfaceType , kBlendMode , kAlphaCutoff , kAlphaCutoffEnabled , kDoubleSidedEnable } ;
protected abstract void FindMaterialProperties ( MaterialProperty [ ] props ) ;
protected abstract void ShaderInputGUI ( ) ;
protected abstract void SetupMaterialKeywords ( Material material ) ;
protected abstract bool ShouldEmissionBeEnabled ( Material material ) ;
}
} // namespace UnityEditor