using System ;
using UnityEngine ;
using UnityEngine.Experimental.Rendering.HDPipeline ;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
public static GUIContent alphaCutoffEnableText = new GUIContent ( "Alpha Cutoff Enable" , "Threshold for alpha cutoff" ) ;
public static GUIContent alphaCutoffText = new GUIContent ( "Alpha Cutoff" , "Threshold for alpha cutoff" ) ;
public static GUIContent alphaCutoffShadowText = new GUIContent ( "Alpha Cutoff Shadow" , "Threshold for alpha cutoff in case of shadow pass" ) ;
public static GUIContent alphaCutoffPrepassText = new GUIContent ( "Alpha Cutoff Prepass" , "Threshold for alpha cutoff in case of depth prepass" ) ;
public static GUIContent transparentDepthPrepassEnableText = new GUIContent ( "Enable transparent depth prepass" , "It allow to " ) ;
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 distortionEnableText = new GUIContent ( "Distortion" , "Enable distortion on this shader" ) ;
public static GUIContent distortionOnlyText = new GUIContent ( "Distortion Only" , "This shader will only be use to render distortion" ) ;
protected const string kAlphaCutoffEnabled = "_AlphaCutoffEnable" ;
protected MaterialProperty alphaCutoff = null ;
protected const string kAlphaCutoff = "_AlphaCutoff" ;
protected MaterialProperty alphaCutoffShadow = null ;
protected const string kAlphaCutoffShadow = "_AlphaCutoffShadow" ;
protected MaterialProperty alphaCutoffPrepass = null ;
protected const string kAlphaCutoffPrepass = "_AlphaCutoffPrepass" ;
protected MaterialProperty transparentDepthPrepassEnable = null ;
protected const string kTransparentDepthPrepassEnable = "_TransparentDepthPrepassEnable" ;
protected MaterialProperty doubleSidedEnable = null ;
protected const string kDoubleSidedEnable = "_DoubleSidedEnable" ;
protected MaterialProperty blendMode = null ;
surfaceType = FindProperty ( kSurfaceType , props ) ;
alphaCutoffEnable = FindProperty ( kAlphaCutoffEnabled , props ) ;
alphaCutoff = FindProperty ( kAlphaCutoff , props ) ;
alphaCutoffShadow = FindProperty ( kAlphaCutoffShadow , props , false ) ;
alphaCutoffPrepass = FindProperty ( kAlphaCutoffPrepass , props , false ) ;
transparentDepthPrepassEnable = FindProperty ( kTransparentDepthPrepassEnable , props , false ) ;
doubleSidedEnable = FindProperty ( kDoubleSidedEnable , props ) ;
blendMode = FindProperty ( kBlendMode , props ) ;
distortionEnable = FindProperty ( kDistortionEnable , props , false ) ;
if ( distortionEnable . floatValue = = 1.0f )
{
EditorGUI . indentLevel + + ;
EditorGUI . indentLevel - - ;
}
}
}
EditorGUI . indentLevel + + ;
// With transparent object and few specific materials like Hair, we need more control on the cutoff to apply
// This allow to get a better sorting (with prepass), better shadow (better silouhette fidelity) etc...
if ( ( SurfaceType ) surfaceType . floatValue = = SurfaceType . Transparent )
{
if ( alphaCutoffShadow ! = null )
{
m_MaterialEditor . ShaderProperty ( alphaCutoffShadow , StylesBaseUnlit . alphaCutoffShadowText ) ;
}
if ( transparentDepthPrepassEnable ! = null )
{
m_MaterialEditor . ShaderProperty ( transparentDepthPrepassEnable , StylesBaseUnlit . transparentDepthPrepassEnableText ) ;
if ( transparentDepthPrepassEnable . floatValue = = 1.0f )
{
EditorGUI . indentLevel + + ;
m_MaterialEditor . ShaderProperty ( alphaCutoffPrepass , StylesBaseUnlit . alphaCutoffPrepassText ) ;
EditorGUI . indentLevel - - ;
}
}
}
EditorGUI . indentLevel - - ;
}
// This function must finish with double sided option (see LitUI.cs)
m_MaterialEditor . ShaderProperty ( doubleSidedEnable , StylesBaseUnlit . doubleSidedEnableText ) ;
SetKeyword ( material , "_ALPHATEST_ON" , alphaTestEnable ) ;
if ( material . HasProperty ( kDistortionEnable ) )
{
bool distortionEnable = material . GetFloat ( kDistortionEnable ) > 0.0f ;
if ( distortionEnable )
{
material . SetShaderPassEnabled ( "DistortionVectors" , true ) ;
}
else
{
material . SetShaderPassEnabled ( "DistortionVectors" , false ) ;
}
{
bool distortionDepthTest = material . GetFloat ( kDistortionDepthTest ) > 0.0f ;
if ( distortionDepthTest )
{
{
material . SetInt ( "_ZTestMode" , ( int ) UnityEngine . Rendering . CompareFunction . Always ) ;
}
SetKeyword ( material , "_DISTORTION_ON" , distortionEnable ) ;
}
// A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect
if ( material . HasProperty ( kDistortionEnable ) )
{
bool distortionEnable = material . GetFloat ( kDistortionEnable ) > 0.0f ;
bool distortionOnly = material . GetFloat ( kDistortionOnly ) > 0.0f ;
bool distortionOnly = false ;
if ( material . HasProperty ( kDistortionOnly ) )
{
distortionOnly = material . GetFloat ( kDistortionOnly ) > 0.0f ;
}
// If distortion only is enabled, disable all passes (except distortion and debug)
bool enablePass = ! ( distortionEnable & & distortionOnly ) ;
// Disable all passes except distortion
// Distortion is setup in code above
material . SetShaderPassEnabled ( HDShaderPassNames . s_ForwardStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_ForwardDebugDisplayStr , true ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_DepthOnlyStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_ForwardOnlyOpaqueDepthOnlyStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_ForwardOnlyOpaqueStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_ForwardOnlyOpaqueDebugDisplayStr , true ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_GBufferStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_GBufferWithPrepassStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_GBufferDebugDisplayStr , true ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_MotionVectorsStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_DistortionVectorsStr , distortionEnable ) ; // note: use distortionEnable
material . SetShaderPassEnabled ( HDShaderPassNames . s_TransparentDepthPrepassStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_MetaStr , enablePass ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_ShadowCasterStr , enablePass ) ;
}
if ( distortionEnable & & distortionOnly )
if ( material . HasProperty ( kTransparentDepthPrepassEnable ) )
{
bool depthWriteEnable = ( material . GetFloat ( kTransparentDepthPrepassEnable ) > 0.0f ) & & ( ( SurfaceType ) material . GetFloat ( kSurfaceType ) = = SurfaceType . Transparent ) ;
if ( depthWriteEnable )
// Disable all passes except debug material
material . SetShaderPassEnabled ( "GBuffer" , false ) ;
material . SetShaderPassEnabled ( "DebugViewMaterial" , true ) ;
material . SetShaderPassEnabled ( "Meta" , false ) ;
material . SetShaderPassEnabled ( "ShadowCaster" , false ) ;
material . SetShaderPassEnabled ( "DepthOnly" , false ) ;
material . SetShaderPassEnabled ( "MotionVectors" , false ) ;
material . SetShaderPassEnabled ( "Forward" , false ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_TransparentDepthPrepassStr , true ) ;
material . SetShaderPassEnabled ( "GBuffer" , true ) ;
material . SetShaderPassEnabled ( "DebugViewMaterial" , true ) ;
material . SetShaderPassEnabled ( "Meta" , true ) ;
material . SetShaderPassEnabled ( "ShadowCaster" , true ) ;
material . SetShaderPassEnabled ( "DepthOnly" , true ) ;
material . SetShaderPassEnabled ( "MotionVectors" , true ) ;
material . SetShaderPassEnabled ( "Forward" , true ) ;
material . SetShaderPassEnabled ( HDShaderPassNames . s_TransparentDepthPrepassStr , false ) ;
}
}
}
EditorGUILayout . Space ( ) ;
EditorGUILayout . LabelField ( StylesBaseUnlit . advancedText , EditorStyles . boldLabel ) ;
// NB renderq ueue editor is not shown on purpose: we want to override it based on blend mode
// NB RenderQ ueue editor is not shown on purpose: we want to override it based on blend mode
EditorGUI . indentLevel + + ;
m_MaterialEditor . EnableInstancingField ( ) ;
m_MaterialEditor . DoubleSidedGIField ( ) ;