1+ #if UNITY_2022_2_OR_NEWER && ! ( UNITY_2022_2_0 || UNITY_2022_2_1 || UNITY_2022_2_2 || UNITY_2022_2_3 || UNITY_2022_2_4 || UNITY_2022_2_5 || UNITY_2022_2_6 || UNITY_2022_2_7 || UNITY_2022_2_8 || UNITY_2022_2_9 || UNITY_2022_2_10 || UNITY_2022_2_11 || UNITY_2022_2_12 || UNITY_2022_2_13 || UNITY_2022_2_14 )
2+ // This is a fix for https://github.com/Zallist/unity.zallist.universal-simple-lit-shadergraph-target/issues/20
3+ // All changes are related to https://github.com/Unity-Technologies/Graphics/commit/584e10efb36cb33d6f67461da75eb3b035f3798f#diff-1536bdf9492174a8dce30e912411f0e2234cedf60cfbe1fafa482d5bdfd639a6
4+ #define UNITY_2022_2_15_OR_NEWER
5+ #endif
6+
17using System ;
2- using System . Linq ;
38using System . Collections . Generic ;
4- using UnityEngine ;
9+ using System . Linq ;
510using UnityEditor . ShaderGraph ;
6- using UnityEditor . UIElements ;
7- using UnityEngine . UIElements ;
811using UnityEditor . ShaderGraph . Legacy ;
12+ using UnityEditor . UIElements ;
13+ using UnityEngine ;
914using UnityEngine . Assertions ;
10- using static UnityEditor . Rendering . Universal . ShaderGraph . SubShaderUtils ;
1115using UnityEngine . Rendering . Universal ;
16+ using UnityEngine . UIElements ;
1217using static Unity . Rendering . Universal . ShaderUtils ;
18+ using static UnityEditor . Rendering . Universal . ShaderGraph . SubShaderUtils ;
1319
1420namespace UnityEditor . Rendering . Universal . ShaderGraph
1521{
@@ -93,7 +99,9 @@ public override void Setup(ref TargetSetupContext context)
9399 }
94100
95101 // Process SubShaders
96- #if UNITY_2022_1_OR_NEWER
102+ #if UNITY_2022_2_15_OR_NEWER
103+ context . AddSubShader ( PostProcessSubShader ( SubShaders . SimpleLitSubShader ( target , target . renderType , target . renderQueue , blendModePreserveSpecular , specularHighlights ) ) ) ;
104+ #elif UNITY_2022_1_OR_NEWER
97105 context . AddSubShader ( PostProcessSubShader ( SubShaders . SimpleLitComputeDotsSubShader ( target , target . renderType , target . renderQueue , blendModePreserveSpecular , specularHighlights ) ) ) ;
98106 context . AddSubShader ( PostProcessSubShader ( SubShaders . SimpleLitGLESSubShader ( target , target . renderType , target . renderQueue , blendModePreserveSpecular , specularHighlights ) ) ) ;
99107#else
@@ -279,8 +287,10 @@ internal override void OnAfterParentTargetDeserialized()
279287 #region SubShader
280288 static class SubShaders
281289 {
290+ #if UNITY_2022_2_15_OR_NEWER
291+ public static SubShaderDescriptor SimpleLitSubShader ( UniversalTarget target , string renderType , string renderQueue , bool blendModePreserveSpecular , bool specularHighlights )
282292 // SM 4.5, compute with dots instancing
283- #if UNITY_2022_1_OR_NEWER
293+ #elif UNITY_2022_1_OR_NEWER
284294 public static SubShaderDescriptor SimpleLitComputeDotsSubShader ( UniversalTarget target , string renderType , string renderQueue , bool blendModePreserveSpecular , bool specularHighlights )
285295#else
286296 public static SubShaderDescriptor SimpleLitComputeDotsSubShader ( UniversalTarget target , string renderType , string renderQueue , bool specularHighlights )
@@ -296,7 +306,9 @@ public static SubShaderDescriptor SimpleLitComputeDotsSubShader(UniversalTarget
296306 passes = new PassCollection ( )
297307 } ;
298308
299- #if UNITY_2022_2_OR_NEWER
309+ #if UNITY_2022_2_15_OR_NEWER
310+ result . passes . Add ( SimpleLitPasses . Forward ( target , blendModePreserveSpecular , specularHighlights , CorePragmas . Forward , SimpleLitKeywords . Forward ) ) ;
311+ #elif UNITY_2022_2_OR_NEWER
300312 result . passes . Add ( SimpleLitPasses . Forward ( target , blendModePreserveSpecular , specularHighlights , CorePragmas . ForwardSM45 , SimpleLitKeywords . DOTSForward ) ) ;
301313#elif UNITY_2022_1_OR_NEWER
302314 result . passes . Add ( SimpleLitPasses . Forward ( target , blendModePreserveSpecular , specularHighlights , CorePragmas . DOTSForward ) ) ;
@@ -312,46 +324,60 @@ public static SubShaderDescriptor SimpleLitComputeDotsSubShader(UniversalTarget
312324
313325 // cull the shadowcaster pass if we know it will never be used
314326 if ( target . castShadows || target . allowMaterialOverride )
315- #if UNITY_2022_2_OR_NEWER
327+ #if UNITY_2022_2_15_OR_NEWER
328+ result . passes . Add ( PassVariant ( CorePasses . ShadowCaster ( target ) , CorePragmas . Instanced ) ) ;
329+ #elif UNITY_2022_2_OR_NEWER
316330 result . passes . Add ( PassVariant ( CorePasses . ShadowCaster ( target ) , CorePragmas . InstancedSM45 ) ) ;
317331#else
318332 result . passes . Add ( PassVariant ( CorePasses . ShadowCaster ( target ) , CorePragmas . DOTSInstanced ) ) ;
319333#endif
320334
321335 if ( target . mayWriteDepth )
322- #if UNITY_2022_2_OR_NEWER
336+ #if UNITY_2022_2_15_OR_NEWER
337+ result . passes . Add ( PassVariant ( CorePasses . DepthOnly ( target ) , CorePragmas . Instanced ) ) ;
338+ #elif UNITY_2022_2_OR_NEWER
323339 result . passes . Add ( PassVariant ( CorePasses . DepthOnly ( target ) , CorePragmas . InstancedSM45 ) ) ;
324340#else
325341 result . passes . Add ( PassVariant ( CorePasses . DepthOnly ( target ) , CorePragmas . DOTSInstanced ) ) ;
326342#endif
327343
328- #if UNITY_2022_2_OR_NEWER
344+ #if UNITY_2022_2_15_OR_NEWER
345+ result . passes . Add ( PassVariant ( SimpleLitPasses . DepthNormal ( target ) , CorePragmas . Instanced ) ) ;
346+ #elif UNITY_2022_2_OR_NEWER
329347 result . passes . Add ( PassVariant ( SimpleLitPasses . DepthNormal ( target ) , CorePragmas . InstancedSM45 ) ) ;
330348#else
331349 result . passes . Add ( PassVariant ( SimpleLitPasses . DepthNormal ( target ) , CorePragmas . DOTSInstanced ) ) ;
332350#endif
333351
334- #if UNITY_2022_2_OR_NEWER
352+ #if UNITY_2022_2_15_OR_NEWER
353+ result . passes . Add ( PassVariant ( SimpleLitPasses . Meta ( target ) , CorePragmas . Default ) ) ;
354+ #elif UNITY_2022_2_OR_NEWER
335355 result . passes . Add ( PassVariant ( SimpleLitPasses . Meta ( target ) , CorePragmas . DefaultSM45 ) ) ;
336356#else
337357 result . passes . Add ( PassVariant ( SimpleLitPasses . Meta ( target ) , CorePragmas . DOTSDefault ) ) ;
338358#endif
339359
340360 // Currently neither of these passes (selection/picking) can be last for the game view for
341361 // UI shaders to render correctly. Verify [1352225] before changing this order.
342- #if UNITY_2022_2_OR_NEWER
362+ #if UNITY_2022_2_15_OR_NEWER
363+ result . passes . Add ( PassVariant ( CorePasses . SceneSelection ( target ) , CorePragmas . Default ) ) ;
364+ #elif UNITY_2022_2_OR_NEWER
343365 result . passes . Add ( PassVariant ( CorePasses . SceneSelection ( target ) , CorePragmas . DefaultSM45 ) ) ;
344366#else
345367 result . passes . Add ( PassVariant ( CorePasses . SceneSelection ( target ) , CorePragmas . DOTSDefault ) ) ;
346368#endif
347369
348- #if UNITY_2022_2_OR_NEWER
370+ #if UNITY_2022_2_15_OR_NEWER
371+ result . passes . Add ( PassVariant ( CorePasses . ScenePicking ( target ) , CorePragmas . Default ) ) ;
372+ #elif UNITY_2022_2_OR_NEWER
349373 result . passes . Add ( PassVariant ( CorePasses . ScenePicking ( target ) , CorePragmas . DefaultSM45 ) ) ;
350374#else
351375 result . passes . Add ( PassVariant ( CorePasses . ScenePicking ( target ) , CorePragmas . DOTSDefault ) ) ;
352376#endif
353377
354- #if UNITY_2022_2_OR_NEWER
378+ #if UNITY_2022_2_15_OR_NEWER
379+ result . passes . Add ( PassVariant ( SimpleLitPasses . _2D ( target ) , CorePragmas . Default ) ) ;
380+ #elif UNITY_2022_2_OR_NEWER
355381 result . passes . Add ( PassVariant ( SimpleLitPasses . _2D ( target ) , CorePragmas . DefaultSM45 ) ) ;
356382#else
357383 result . passes . Add ( PassVariant ( SimpleLitPasses . _2D ( target ) , CorePragmas . DOTSDefault ) ) ;
@@ -361,6 +387,7 @@ public static SubShaderDescriptor SimpleLitComputeDotsSubShader(UniversalTarget
361387 return result ;
362388 }
363389
390+ #if ! UNITY_2022_2_15_OR_NEWER
364391#if UNITY_2022_1_OR_NEWER
365392 public static SubShaderDescriptor SimpleLitGLESSubShader ( UniversalTarget target , string renderType , string renderQueue , bool blendModePreserveSpecular , bool specularHighlights )
366393#else
@@ -408,10 +435,11 @@ public static SubShaderDescriptor SimpleLitGLESSubShader(UniversalTarget target,
408435
409436 return result ;
410437 }
438+ #endif
411439 }
412- #endregion
440+ #endregion
413441
414- #region Passes
442+ #region Passes
415443 static class SimpleLitPasses
416444 {
417445 static void AddWorkflowModeControlToPass ( ref PassDescriptor pass , UniversalTarget target , WorkflowMode workflowMode )
@@ -440,10 +468,10 @@ static void AddReceiveShadowsControlToPass(ref PassDescriptor pass, UniversalTar
440468
441469#if UNITY_2022_2_OR_NEWER
442470 public static PassDescriptor Forward (
443- UniversalTarget target ,
444- bool blendModePreserveSpecular ,
445- bool specularHighlights ,
446- PragmaCollection pragmas ,
471+ UniversalTarget target ,
472+ bool blendModePreserveSpecular ,
473+ bool specularHighlights ,
474+ PragmaCollection pragmas ,
447475 KeywordCollection keywords )
448476#elif UNITY_2022_1_OR_NEWER
449477 public static PassDescriptor Forward ( UniversalTarget target , bool blendModePreserveSpecular , bool specularHighlights , PragmaCollection pragmas = null )
@@ -545,7 +573,9 @@ public static PassDescriptor GBuffer(UniversalTarget target, bool specularHighli
545573#else
546574 renderStates = CoreRenderStates . UberSwitchedRenderState ( target /*, blendModePreserveSpecular*/ ) ,
547575#endif
548- #if UNITY_2022_2_OR_NEWER
576+ #if UNITY_2022_2_15_OR_NEWER
577+ pragmas = CorePragmas. GBuffer ,
578+ #elif UNITY_2022_2_OR_NEWER
549579 pragmas = CorePragmas. GBufferSM45,
550580#else
551581 pragmas = CorePragmas. DOTSGBuffer,
@@ -674,7 +704,9 @@ public static PassDescriptor DepthNormal(UniversalTarget target)
674704 renderStates = CoreRenderStates . DepthNormalsOnly ( target ) ,
675705 pragmas = CorePragmas . Instanced ,
676706 defines = new DefineCollection ( ) ,
677- #if UNITY_2022_2_OR_NEWER
707+ #if UNITY_2022_2_15_OR_NEWER
708+ keywords = new KeywordCollection ( ) ,
709+ #elif UNITY_2022_2_OR_NEWER
678710 keywords = new KeywordCollection ( ) { CoreKeywords . DOTSDepthNormal } ,
679711#else
680712 keywords = new KeywordCollection ( ) ,
@@ -693,9 +725,9 @@ public static PassDescriptor DepthNormal(UniversalTarget target)
693725 return result ;
694726 }
695727 }
696- #endregion
728+ #endregion
697729
698- #region PortMasks
730+ #region PortMasks
699731 static class SimpleLitBlockMasks
700732 {
701733 public static readonly BlockFieldDescriptor [ ] FragmentSimpleLit = new BlockFieldDescriptor [ ]
@@ -719,9 +751,9 @@ static class SimpleLitBlockMasks
719751 BlockFields . SurfaceDescription . AlphaClipThreshold ,
720752 } ;
721753 }
722- #endregion
754+ #endregion
723755
724- #region RequiredFields
756+ #region RequiredFields
725757 static class SimpleLitRequiredFields
726758 {
727759 public static readonly FieldCollection Forward = new FieldCollection ( )
@@ -766,9 +798,9 @@ static class SimpleLitRequiredFields
766798 StructFields . Varyings . texCoord2 , // LightCoord
767799 } ;
768800 }
769- #endregion
801+ #endregion
770802
771- #region Defines
803+ #region Defines
772804 static class SimpleLitDefines
773805 {
774806 public static readonly KeywordDescriptor SpecularSetup = new KeywordDescriptor ( )
@@ -791,9 +823,9 @@ static class SimpleLitDefines
791823 stages = KeywordShaderStage . Fragment
792824 } ;
793825 }
794- #endregion
826+ #endregion
795827
796- #region Keywords
828+ #region Keywords
797829 static class SimpleLitKeywords
798830 {
799831 public static readonly KeywordDescriptor ReceiveShadowsOff = new KeywordDescriptor ( )
@@ -847,7 +879,8 @@ static class SimpleLitKeywords
847879#endif
848880 } ;
849881
850- #if UNITY_2022_2_OR_NEWER
882+ #if UNITY_2022_2_15_OR_NEWER
883+ #elif UNITY_2022_2_OR_NEWER
851884 public static readonly KeywordCollection DOTSForward = new KeywordCollection
852885 {
853886 { Forward } ,
@@ -868,7 +901,9 @@ static class SimpleLitKeywords
868901 { CoreKeywordDescriptors . MixedLightingSubtractive } ,
869902 { CoreKeywordDescriptors . DBuffer } ,
870903 { CoreKeywordDescriptors . GBufferNormalsOct } ,
871- #if UNITY_2022_2_OR_NEWER
904+ #if UNITY_2022_2_15_OR_NEWER
905+ { CoreKeywordDescriptors . LightLayers } ,
906+ #elif UNITY_2022_2_OR_NEWER
872907 { CoreKeywordDescriptors . WriteRenderingLayers } ,
873908#else
874909 { CoreKeywordDescriptors . LightLayers } ,
@@ -877,9 +912,9 @@ static class SimpleLitKeywords
877912 { CoreKeywordDescriptors . DebugDisplay } ,
878913 } ;
879914 }
880- #endregion
915+ #endregion
881916
882- #region Includes
917+ #region Includes
883918 static class SimpleLitIncludes
884919 {
885920 const string kShadows = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl" ;
@@ -894,6 +929,10 @@ static class SimpleLitIncludes
894929 public static readonly IncludeCollection Forward = new IncludeCollection
895930 {
896931 // Pre-graph
932+ #if UNITY_2022_2_15_OR_NEWER
933+ { CoreIncludes . DOTSPregraph } ,
934+ { CoreIncludes . WriteRenderLayersPregraph } ,
935+ #endif
897936 { CoreIncludes . CorePregraph } ,
898937 { kShadows , IncludeLocation . Pregraph } ,
899938 { CoreIncludes . ShaderGraphPregraph } ,
@@ -907,6 +946,10 @@ static class SimpleLitIncludes
907946 public static readonly IncludeCollection GBuffer = new IncludeCollection
908947 {
909948 // Pre-graph
949+ #if UNITY_2022_2_15_OR_NEWER
950+ { CoreIncludes . DOTSPregraph } ,
951+ { CoreIncludes . WriteRenderLayersPregraph } ,
952+ #endif
910953 { CoreIncludes . CorePregraph } ,
911954 { kShadows , IncludeLocation . Pregraph } ,
912955 { CoreIncludes . ShaderGraphPregraph } ,
@@ -942,7 +985,7 @@ static class SimpleLitIncludes
942985 { k2DPass , IncludeLocation . Postgraph } ,
943986 } ;
944987 }
945- #endregion
988+ #endregion
946989 }
947990
948991 public static class SimpleLitProperty
0 commit comments