@@ -81,9 +81,9 @@ protected virtual void FindBaseMaterialProperties(MaterialProperty[] props)
8181 alphaCutoff = FindProperty ( kAlphaCutoff , props ) ;
8282 doubleSidedEnable = FindProperty ( kDoubleSidedEnable , props ) ;
8383 blendMode = FindProperty ( kBlendMode , props ) ;
84- distortionEnable = FindProperty ( kDistortionEnable , props ) ;
85- distortionOnly = FindProperty ( kDistortionOnly , props ) ;
86- distortionDepthTest = FindProperty ( kDistortionDepthTest , props ) ;
84+ distortionEnable = FindProperty ( kDistortionEnable , props , false ) ;
85+ distortionOnly = FindProperty ( kDistortionOnly , props , false ) ;
86+ distortionDepthTest = FindProperty ( kDistortionDepthTest , props , false ) ;
8787 }
8888
8989 void SurfaceTypePopup ( )
@@ -126,12 +126,16 @@ protected virtual void BaseMaterialPropertiesGUI()
126126 if ( ( SurfaceType ) surfaceType . floatValue == SurfaceType . Transparent )
127127 {
128128 BlendModePopup ( ) ;
129- m_MaterialEditor . ShaderProperty ( distortionEnable , StylesBaseUnlit . distortionEnableText ) ;
130129
131- if ( distortionEnable . floatValue == 1.0f )
130+ if ( distortionEnable != null )
132131 {
133- m_MaterialEditor . ShaderProperty ( distortionOnly , StylesBaseUnlit . distortionOnlyText ) ;
134- m_MaterialEditor . ShaderProperty ( distortionDepthTest , StylesBaseUnlit . distortionDepthTestText ) ;
132+ m_MaterialEditor . ShaderProperty ( distortionEnable , StylesBaseUnlit . distortionEnableText ) ;
133+
134+ if ( distortionEnable . floatValue == 1.0f )
135+ {
136+ m_MaterialEditor . ShaderProperty ( distortionOnly , StylesBaseUnlit . distortionOnlyText ) ;
137+ m_MaterialEditor . ShaderProperty ( distortionDepthTest , StylesBaseUnlit . distortionDepthTestText ) ;
138+ }
135139 }
136140 }
137141 m_MaterialEditor . ShaderProperty ( alphaCutoffEnable , StylesBaseUnlit . alphaCutoffEnableText ) ;
@@ -214,27 +218,30 @@ static public void SetupBaseUnlitKeywords(Material material)
214218 SetKeyword ( material , "_DOUBLESIDED_ON" , doubleSidedEnable ) ;
215219 SetKeyword ( material , "_ALPHATEST_ON" , alphaTestEnable ) ;
216220
217- bool distortionEnable = material . GetFloat ( kDistortionEnable ) > 0.0f ;
218- if ( distortionEnable )
219- {
220- material . SetShaderPassEnabled ( "DistortionVectors" , true ) ;
221- }
222- else
221+ if ( material . HasProperty ( kDistortionEnable ) )
223222 {
224- material . SetShaderPassEnabled ( "DistortionVectors" , false ) ;
225- }
223+ bool distortionEnable = material . GetFloat ( kDistortionEnable ) > 0.0f ;
224+ if ( distortionEnable )
225+ {
226+ material . SetShaderPassEnabled ( "DistortionVectors" , true ) ;
227+ }
228+ else
229+ {
230+ material . SetShaderPassEnabled ( "DistortionVectors" , false ) ;
231+ }
226232
227- bool distortionDepthTest = material . GetFloat ( kDistortionDepthTest ) > 0.0f ;
228- if ( distortionDepthTest )
229- {
230- material . SetInt ( "_ZTestMode" , ( int ) UnityEngine . Rendering . CompareFunction . LessEqual ) ;
231- }
232- else
233- {
234- material . SetInt ( "_ZTestMode" , ( int ) UnityEngine . Rendering . CompareFunction . Always ) ;
235- }
233+ bool distortionDepthTest = material . GetFloat ( kDistortionDepthTest ) > 0.0f ;
234+ if ( distortionDepthTest )
235+ {
236+ material . SetInt ( "_ZTestMode" , ( int ) UnityEngine . Rendering . CompareFunction . LessEqual ) ;
237+ }
238+ else
239+ {
240+ material . SetInt ( "_ZTestMode" , ( int ) UnityEngine . Rendering . CompareFunction . Always ) ;
241+ }
236242
237- SetKeyword ( material , "_DISTORTION_ON" , distortionEnable ) ;
243+ SetKeyword ( material , "_DISTORTION_ON" , distortionEnable ) ;
244+ }
238245
239246 // A material's GI flag internally keeps track of whether emission is enabled at all, it's enabled but has no effect
240247 // or is enabled and may be modified at runtime. This state depends on the values of the current flag and emissive color.
@@ -244,29 +251,32 @@ static public void SetupBaseUnlitKeywords(Material material)
244251
245252 static public void SetupBaseUnlitMaterialPass ( Material material )
246253 {
247- bool distortionEnable = material . GetFloat ( kDistortionEnable ) > 0.0f ;
248- bool distortionOnly = material . GetFloat ( kDistortionOnly ) > 0.0f ;
249-
250- if ( distortionEnable && distortionOnly )
251- {
252- // Disable all passes except debug material
253- material . SetShaderPassEnabled ( "GBuffer" , false ) ;
254- material . SetShaderPassEnabled ( "DebugViewMaterial" , true ) ;
255- material . SetShaderPassEnabled ( "Meta" , false ) ;
256- material . SetShaderPassEnabled ( "ShadowCaster" , false ) ;
257- material . SetShaderPassEnabled ( "DepthOnly" , false ) ;
258- material . SetShaderPassEnabled ( "MotionVectors" , false ) ;
259- material . SetShaderPassEnabled ( "Forward" , false ) ;
260- }
261- else
254+ if ( material . HasProperty ( kDistortionEnable ) )
262255 {
263- material . SetShaderPassEnabled ( "GBuffer" , true ) ;
264- material . SetShaderPassEnabled ( "DebugViewMaterial" , true ) ;
265- material . SetShaderPassEnabled ( "Meta" , true ) ;
266- material . SetShaderPassEnabled ( "ShadowCaster" , true ) ;
267- material . SetShaderPassEnabled ( "DepthOnly" , true ) ;
268- material . SetShaderPassEnabled ( "MotionVectors" , true ) ;
269- material . SetShaderPassEnabled ( "Forward" , true ) ;
256+ bool distortionEnable = material . GetFloat ( kDistortionEnable ) > 0.0f ;
257+ bool distortionOnly = material . GetFloat ( kDistortionOnly ) > 0.0f ;
258+
259+ if ( distortionEnable && distortionOnly )
260+ {
261+ // Disable all passes except debug material
262+ material . SetShaderPassEnabled ( "GBuffer" , false ) ;
263+ material . SetShaderPassEnabled ( "DebugViewMaterial" , true ) ;
264+ material . SetShaderPassEnabled ( "Meta" , false ) ;
265+ material . SetShaderPassEnabled ( "ShadowCaster" , false ) ;
266+ material . SetShaderPassEnabled ( "DepthOnly" , false ) ;
267+ material . SetShaderPassEnabled ( "MotionVectors" , false ) ;
268+ material . SetShaderPassEnabled ( "Forward" , false ) ;
269+ }
270+ else
271+ {
272+ material . SetShaderPassEnabled ( "GBuffer" , true ) ;
273+ material . SetShaderPassEnabled ( "DebugViewMaterial" , true ) ;
274+ material . SetShaderPassEnabled ( "Meta" , true ) ;
275+ material . SetShaderPassEnabled ( "ShadowCaster" , true ) ;
276+ material . SetShaderPassEnabled ( "DepthOnly" , true ) ;
277+ material . SetShaderPassEnabled ( "MotionVectors" , true ) ;
278+ material . SetShaderPassEnabled ( "Forward" , true ) ;
279+ }
270280 }
271281 }
272282
@@ -296,7 +306,7 @@ public void ShaderPropertiesGUI(Material material)
296306 EditorGUILayout . Space ( ) ;
297307
298308 VertexAnimationPropertiesGUI ( ) ;
299-
309+
300310 EditorGUILayout . Space ( ) ;
301311 MaterialPropertiesGUI ( material ) ;
302312
0 commit comments