@@ -10,10 +10,17 @@ sealed class PreviewTarget : Target
1010 {
1111 static readonly GUID kSourceCodeGuid = new GUID ( "7464b9fcde08e5645a16b9b8ae1e573c" ) ; // PreviewTarget.cs
1212
13- public PreviewTarget ( )
13+ private bool isUITKPreview = false ;
14+
15+ public PreviewTarget ( ) : this ( false )
16+ {
17+ }
18+
19+ public PreviewTarget ( bool isUITKPreview )
1420 {
1521 displayName = "Preview" ;
1622 isHidden = true ;
23+ this . isUITKPreview = isUITKPreview ;
1724 }
1825
1926 public override bool IsActive ( ) => false ;
@@ -22,7 +29,7 @@ public PreviewTarget()
2229 public override void Setup ( ref TargetSetupContext context )
2330 {
2431 context . AddAssetDependency ( kSourceCodeGuid , AssetCollection . Flags . SourceDependency ) ;
25- context . AddSubShader ( SubShaders . Preview ) ;
32+ context . AddSubShader ( SubShaders . GetPreview ( isUITKPreview ) ) ;
2633 }
2734
2835 public override void GetFields ( ref TargetFieldContext context )
@@ -41,66 +48,77 @@ public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Acti
4148
4249 static class SubShaders
4350 {
44- public static SubShaderDescriptor Preview = new SubShaderDescriptor ( )
51+ public static SubShaderDescriptor GetPreview ( bool isUITKPreview )
4552 {
46- renderQueue = "Geometry" ,
47- renderType = "Opaque" ,
48- generatesPreview = true ,
49- passes = new PassCollection { Passes . Preview } ,
50- } ;
53+ var preview = new SubShaderDescriptor ( )
54+ {
55+ renderQueue = "Geometry" ,
56+ renderType = "Opaque" ,
57+ generatesPreview = true ,
58+ passes = new PassCollection { Passes . GetPreview ( isUITKPreview ) } ,
59+ } ;
60+
61+ return preview ;
62+ }
5163 }
5264
5365 static class Passes
5466 {
55- public static PassDescriptor Preview = new PassDescriptor ( )
67+ public static PassDescriptor GetPreview ( bool isUITKPreview )
5668 {
57- // Definition
58- referenceName = "SHADERPASS_PREVIEW" ,
59- useInPreview = true ,
69+ var pass = new PassDescriptor ( )
70+ {
71+ // Definition
72+ referenceName = "SHADERPASS_PREVIEW" ,
73+ useInPreview = true ,
6074
61- // Templates
62- passTemplatePath = GenerationUtils . GetDefaultTemplatePath ( "PassMesh.template" ) ,
63- sharedTemplateDirectories = GenerationUtils . GetDefaultSharedTemplateDirectories ( ) ,
75+ // Templates
76+ passTemplatePath = GenerationUtils . GetDefaultTemplatePath ( "PassMesh.template" ) ,
77+ sharedTemplateDirectories = GenerationUtils . GetDefaultSharedTemplateDirectories ( ) ,
6478
65- // Collections
66- structs = new StructCollection
67- {
68- { Structs . Attributes } ,
69- { StructDescriptors . PreviewVaryings } ,
70- { Structs . SurfaceDescriptionInputs } ,
71- { Structs . VertexDescriptionInputs } ,
72- } ,
73- fieldDependencies = FieldDependencies . Default ,
74- pragmas = new PragmaCollection
75- {
76- { Pragma . Vertex ( "vert" ) } ,
77- { Pragma . Fragment ( "frag" ) } ,
78- } ,
79- defines = new DefineCollection
80- {
81- { KeywordDescriptors . PreviewKeyword , 1 } ,
82- } ,
83- includes = new IncludeCollection
84- {
85- // Pre-graph
86- { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" , IncludeLocation . Pregraph } ,
87- { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl" , IncludeLocation . Pregraph } ,
88- { "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" , IncludeLocation . Pregraph } , // TODO: put this on a conditional
89- { "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" , IncludeLocation . Pregraph } ,
90- { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" , IncludeLocation . Pregraph } ,
91- { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" , IncludeLocation . Pregraph } ,
92- { "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" , IncludeLocation . Pregraph } ,
93- { "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl" , IncludeLocation . Pregraph } ,
94- { "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariables.hlsl" , IncludeLocation . Pregraph } ,
95- { "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" , IncludeLocation . Pregraph } ,
96- { "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" , IncludeLocation . Pregraph } ,
97- { "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/UIShim.hlsl" , IncludeLocation . Pregraph } ,
98-
99- // Post-graph
100- { "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewVaryings.hlsl" , IncludeLocation . Postgraph } ,
101- { "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl" , IncludeLocation . Postgraph } ,
102- }
103- } ;
79+ // Collections
80+ structs = new StructCollection
81+ {
82+ { Structs . Attributes } ,
83+ { StructDescriptors . PreviewVaryings } ,
84+ { Structs . SurfaceDescriptionInputs } ,
85+ { Structs . VertexDescriptionInputs } ,
86+ } ,
87+ fieldDependencies = FieldDependencies . Default ,
88+ pragmas = new PragmaCollection
89+ {
90+ { Pragma . Vertex ( "vert" ) } ,
91+ { Pragma . Fragment ( "frag" ) } ,
92+ } ,
93+ defines = new DefineCollection
94+ {
95+ { KeywordDescriptors . PreviewKeyword , 1 } ,
96+ { KeywordDescriptors . UITKPreviewKeyword , isUITKPreview ? 1 : 0 }
97+ } ,
98+ includes = new IncludeCollection
99+ {
100+ // Pre-graph
101+ { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" , IncludeLocation . Pregraph } ,
102+ { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl" , IncludeLocation . Pregraph } ,
103+ { "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl" , IncludeLocation . Pregraph } , // TODO: put this on a conditional
104+ { "Packages/com.unity.render-pipelines.core/ShaderLibrary/NormalSurfaceGradient.hlsl" , IncludeLocation . Pregraph } ,
105+ { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" , IncludeLocation . Pregraph } ,
106+ { "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl" , IncludeLocation . Pregraph } ,
107+ { "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" , IncludeLocation . Pregraph } ,
108+ { "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl" , IncludeLocation . Pregraph } ,
109+ { "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariables.hlsl" , IncludeLocation . Pregraph } ,
110+ { "Packages/com.unity.shadergraph/ShaderGraphLibrary/ShaderVariablesFunctions.hlsl" , IncludeLocation . Pregraph } ,
111+ { "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl" , IncludeLocation . Pregraph } ,
112+ { "Packages/com.unity.shadergraph/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/UIShimPreview.hlsl" , IncludeLocation . Pregraph } ,
113+
114+ // Post-graph
115+ { "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewVaryings.hlsl" , IncludeLocation . Postgraph } ,
116+ { "Packages/com.unity.shadergraph/ShaderGraphLibrary/PreviewPass.hlsl" , IncludeLocation . Postgraph } ,
117+ }
118+ } ;
119+
120+ return pass ;
121+ }
104122 }
105123
106124 static class StructDescriptors
@@ -144,6 +162,15 @@ static class KeywordDescriptors
144162 scope = KeywordScope . Global ,
145163 stages = KeywordShaderStage . All ,
146164 } ;
165+ public static KeywordDescriptor UITKPreviewKeyword = new KeywordDescriptor ( )
166+ {
167+ displayName = "UITK Preview" ,
168+ referenceName = "UITK_PREVIEW" ,
169+ type = KeywordType . Boolean ,
170+ definition = KeywordDefinition . MultiCompile ,
171+ scope = KeywordScope . Global ,
172+ stages = KeywordShaderStage . All ,
173+ } ;
147174 }
148175 }
149176}
0 commit comments