├── .gitignore ├── Editor.meta ├── Editor ├── ShaderGUI.meta ├── ShaderGUI │ ├── ShaderGraphSimpleLitGUI.cs │ └── ShaderGraphSimpleLitGUI.cs.meta ├── ShaderGraph.meta ├── ShaderGraph │ ├── AssetCallbacks.meta │ ├── AssetCallbacks │ │ ├── CreateSimpleLitShaderGraph.cs │ │ └── CreateSimpleLitShaderGraph.cs.meta │ ├── Includes.meta │ ├── Includes │ │ ├── SimpleLitForwardPass.hlsl │ │ ├── SimpleLitForwardPass.hlsl.meta │ │ ├── SimpleLitGBufferPass.hlsl │ │ └── SimpleLitGBufferPass.hlsl.meta │ ├── Targets.meta │ └── Targets │ │ ├── UniversalSimpleLitSubTarget.cs │ │ └── UniversalSimpleLitSubTarget.cs.meta ├── UniversalShaderGraphExtensions.asmref ├── UniversalShaderGraphExtensions.asmref.meta ├── VFXGraph.meta └── VFXGraph │ ├── VFXShaderGraphSimpleLitGUI.cs │ └── VFXShaderGraphSimpleLitGUI.cs.meta ├── LICENSE ├── LICENSE.meta ├── README.MD ├── README.MD.meta ├── package.json └── package.json.meta /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Asset meta data should only be ignored when the corresponding asset is also ignored 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f4f8122f84b98e4bbc5e9f219853f74 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ShaderGUI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02bfbf602e8c5b94e9138375be809a33 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ShaderGUI/ShaderGraphSimpleLitGUI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor.Rendering.Universal; 3 | using UnityEditor.Rendering.Universal.ShaderGUI; 4 | using UnityEngine; 5 | using static Unity.Rendering.Universal.ShaderUtils; 6 | 7 | namespace UnityEditor 8 | { 9 | // Used for ShaderGraph Lit shaders 10 | class ShaderGraphSimpleLitGUI : BaseShaderGUI 11 | { 12 | //public MaterialProperty workflowMode; 13 | public MaterialProperty specularHighlights; 14 | 15 | MaterialProperty[] properties; 16 | 17 | // collect properties from the material properties 18 | public override void FindProperties(MaterialProperty[] properties) 19 | { 20 | // save off the list of all properties for shadergraph 21 | this.properties = properties; 22 | 23 | var material = materialEditor?.target as Material; 24 | if (material == null) 25 | return; 26 | 27 | base.FindProperties(properties); 28 | //workflowMode = BaseShaderGUI.FindProperty(Property.SpecularWorkflowMode, properties, false);# 29 | specularHighlights = BaseShaderGUI.FindProperty(Rendering.Universal.ShaderGraph.SimpleLitProperty.SpecularHighlights, properties, false); 30 | } 31 | 32 | public static void UpdateMaterial(Material material, MaterialUpdateType updateType) 33 | { 34 | // newly created materials should initialize the globalIlluminationFlags (default is off) 35 | if (updateType == MaterialUpdateType.CreatedNewMaterial) 36 | material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.BakedEmissive; 37 | 38 | bool automaticRenderQueue = GetAutomaticQueueControlSetting(material); 39 | BaseShaderGUI.UpdateMaterialSurfaceOptions(material, automaticRenderQueue); 40 | //LitGUI.SetupSpecularWorkflowKeyword(material, out bool isSpecularWorkflow); 41 | if (material.HasProperty(Rendering.Universal.ShaderGraph.SimpleLitProperty.SpecularHighlights)) 42 | UnityEngine.Rendering.CoreUtils.SetKeyword( 43 | material, 44 | Rendering.Universal.ShaderGraph.SimpleLitProperty.SpecularColorKeyword, 45 | material.GetFloat(Rendering.Universal.ShaderGraph.SimpleLitProperty.SpecularHighlights) != 0.0f); 46 | } 47 | 48 | public override void ValidateMaterial(Material material) 49 | { 50 | if (material == null) 51 | throw new ArgumentNullException("material"); 52 | 53 | UpdateMaterial(material, MaterialUpdateType.ModifiedMaterial); 54 | } 55 | 56 | public override void DrawSurfaceOptions(Material material) 57 | { 58 | if (material == null) 59 | throw new ArgumentNullException("material"); 60 | 61 | // Use default labelWidth 62 | EditorGUIUtility.labelWidth = 0f; 63 | 64 | // Detect any changes to the material 65 | //if (workflowMode != null) 66 | // DoPopup(LitGUI.Styles.workflowModeText, workflowMode, Enum.GetNames(typeof(LitGUI.WorkflowMode))); 67 | base.DrawSurfaceOptions(material); 68 | } 69 | 70 | // material main surface inputs 71 | public override void DrawSurfaceInputs(Material material) 72 | { 73 | DrawShaderGraphProperties(material, properties); 74 | } 75 | 76 | public static readonly GUIContent specularHighlightsText = EditorGUIUtility.TrTextContent("Specular Highlights", 77 | "When enabled, this GameObject will receive Specular Highlights."); 78 | 79 | public override void DrawAdvancedOptions(Material material) 80 | { 81 | // Always show the queue control field. Only show the render queue field if queue control is set to user override 82 | if (specularHighlights != null) 83 | DrawFloatToggleProperty(specularHighlightsText, specularHighlights); 84 | 85 | DoPopup(Styles.queueControl, queueControlProp, Styles.queueControlNames); 86 | if (material.HasProperty(Property.QueueControl) && material.GetFloat(Property.QueueControl) == (float)QueueControl.UserOverride) 87 | materialEditor.RenderQueueField(); 88 | base.DrawAdvancedOptions(material); 89 | 90 | // ignore emission color for shadergraphs, because shadergraphs don't have a hard-coded emission property, it's up to the user 91 | materialEditor.DoubleSidedGIField(); 92 | materialEditor.LightmapEmissionFlagsProperty(0, enabled: true, ignoreEmissionColor: true); 93 | } 94 | } 95 | } // namespace UnityEditor 96 | -------------------------------------------------------------------------------- /Editor/ShaderGUI/ShaderGraphSimpleLitGUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a97c3805c683034b826d9623fbe1e71 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ShaderGraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 86f46c26a78af7940b98ac2f4b16fb21 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/AssetCallbacks.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea3d1612c435be94f89e6a8c756ce54c 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/AssetCallbacks/CreateSimpleLitShaderGraph.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor.ShaderGraph; 3 | using UnityEngine.Rendering; 4 | 5 | namespace UnityEditor.Rendering.Universal.ShaderGraph 6 | { 7 | static class CreateSimpleLitShaderGraph 8 | { 9 | [MenuItem("Assets/Create/Shader Graph/URP/Simple Lit Shader Graph", priority = CoreUtils.Priorities.assetsCreateShaderMenuPriority)] 10 | public static void CreateSimpleLitGraph() 11 | { 12 | var target = (UniversalTarget)Activator.CreateInstance(typeof(UniversalTarget)); 13 | target.TrySetActiveSubTarget(typeof(UniversalSimpleLitSubTarget)); 14 | 15 | var blockDescriptors = new[] 16 | { 17 | BlockFields.VertexDescription.Position, 18 | BlockFields.VertexDescription.Normal, 19 | BlockFields.VertexDescription.Tangent, 20 | BlockFields.SurfaceDescription.BaseColor, 21 | BlockFields.SurfaceDescription.NormalTS, 22 | //BlockFields.SurfaceDescription.Metallic, 23 | BlockFields.SurfaceDescription.Smoothness, 24 | BlockFields.SurfaceDescription.Emission, 25 | //BlockFields.SurfaceDescription.Occlusion, 26 | }; 27 | 28 | GraphUtil.CreateNewGraphWithOutputs(new[] { target }, blockDescriptors); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/AssetCallbacks/CreateSimpleLitShaderGraph.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7145f75260383b440b64117c0406a4b2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/Includes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4bea17731cb1a7e46a6f7b79fb0171bb 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/Includes/SimpleLitForwardPass.hlsl: -------------------------------------------------------------------------------- 1 | 2 | void InitializeInputData(Varyings input, SurfaceDescription surfaceDescription, out InputData inputData) 3 | { 4 | inputData = (InputData)0; 5 | 6 | inputData.positionWS = input.positionWS; 7 | 8 | #ifdef _NORMALMAP 9 | // IMPORTANT! If we ever support Flip on double sided materials ensure bitangent and tangent are NOT flipped. 10 | float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale(); 11 | float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz); 12 | 13 | inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz); 14 | #if _NORMAL_DROPOFF_TS 15 | inputData.normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, inputData.tangentToWorld); 16 | #elif _NORMAL_DROPOFF_OS 17 | inputData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS); 18 | #elif _NORMAL_DROPOFF_WS 19 | inputData.normalWS = surfaceDescription.NormalWS; 20 | #endif 21 | #else 22 | inputData.normalWS = input.normalWS; 23 | #endif 24 | inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS); 25 | #if UNITY_VERSION >= 202220 26 | inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS); 27 | #else 28 | inputData.viewDirectionWS = SafeNormalize(GetWorldSpaceViewDir(input.positionWS)); 29 | #endif 30 | 31 | #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR) 32 | inputData.shadowCoord = input.shadowCoord; 33 | #elif defined(MAIN_LIGHT_CALCULATE_SHADOWS) 34 | inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS); 35 | #else 36 | inputData.shadowCoord = float4(0, 0, 0, 0); 37 | #endif 38 | 39 | inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactorAndVertexLight.x); 40 | inputData.vertexLighting = input.fogFactorAndVertexLight.yzw; 41 | #if defined(DYNAMICLIGHTMAP_ON) 42 | inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV.xy, input.sh, inputData.normalWS); 43 | #else 44 | inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.sh, inputData.normalWS); 45 | #endif 46 | inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS); 47 | inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV); 48 | 49 | #if defined(DEBUG_DISPLAY) 50 | #if defined(DYNAMICLIGHTMAP_ON) 51 | inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy; 52 | #endif 53 | #if defined(LIGHTMAP_ON) 54 | inputData.staticLightmapUV = input.staticLightmapUV; 55 | #else 56 | inputData.vertexSH = input.sh; 57 | #endif 58 | #endif 59 | } 60 | 61 | PackedVaryings vert(Attributes input) 62 | { 63 | Varyings output = (Varyings)0; 64 | output = BuildVaryings(input); 65 | PackedVaryings packedOutput = (PackedVaryings)0; 66 | packedOutput = PackVaryings(output); 67 | return packedOutput; 68 | } 69 | 70 | #if UNITY_VERSION >= 202220 71 | void frag( 72 | PackedVaryings packedInput 73 | , out half4 outColor : SV_Target0 74 | #ifdef _WRITE_RENDERING_LAYERS 75 | , out float4 outRenderingLayers : SV_Target1 76 | #endif 77 | ) 78 | #else 79 | half4 frag(PackedVaryings packedInput) : SV_TARGET 80 | #endif //UNITY_VERSION 202220 81 | { 82 | Varyings unpacked = UnpackVaryings(packedInput); 83 | UNITY_SETUP_INSTANCE_ID(unpacked); 84 | UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked); 85 | SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked); 86 | 87 | #if UNITY_VERSION >= 202220 88 | #if defined(_SURFACE_TYPE_TRANSPARENT) 89 | bool isTransparent = true; 90 | #else 91 | bool isTransparent = false; 92 | #endif 93 | 94 | #if defined(_ALPHATEST_ON) 95 | half alpha = AlphaDiscard(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold); 96 | #elif defined(_SURFACE_TYPE_TRANSPARENT) 97 | half alpha = surfaceDescription.Alpha; 98 | #else 99 | half alpha = half(1.0); 100 | #endif 101 | 102 | #if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE 103 | LODFadeCrossFade(unpacked.positionCS); 104 | #endif 105 | #else 106 | #if _ALPHATEST_ON 107 | half alpha = surfaceDescription.Alpha; 108 | clip(alpha - surfaceDescription.AlphaClipThreshold); 109 | #elif _SURFACE_TYPE_TRANSPARENT 110 | half alpha = surfaceDescription.Alpha; 111 | #else 112 | half alpha = 1; 113 | #endif 114 | #endif //UNITY_VERSION 202220 115 | 116 | InputData inputData; 117 | InitializeInputData(unpacked, surfaceDescription, inputData); 118 | // TODO: Mip debug modes would require this, open question how to do this on ShaderGraph. 119 | //SETUP_DEBUG_TEXTURE_DATA(inputData, unpacked.texCoord1.xy, _MainTex); 120 | 121 | //#ifdef _SPECULAR_SETUP 122 | #ifdef _SPECULAR_COLOR 123 | float3 specular = surfaceDescription.Specular; 124 | // float metallic = 1; 125 | #else 126 | float3 specular = 0; 127 | // float metallic = surfaceDescription.Metallic; 128 | #endif 129 | 130 | half3 normalTS = half3(0, 0, 0); 131 | #if defined(_NORMALMAP) && defined(_NORMAL_DROPOFF_TS) 132 | normalTS = surfaceDescription.NormalTS; 133 | #endif 134 | 135 | SurfaceData surface; 136 | surface.albedo = surfaceDescription.BaseColor; 137 | surface.metallic = 0.0; //saturate(metallic); 138 | surface.specular = specular; 139 | surface.smoothness = saturate(surfaceDescription.Smoothness), 140 | surface.occlusion = 1.0; //surfaceDescription.Occlusion, 141 | surface.emission = surfaceDescription.Emission, 142 | surface.alpha = saturate(alpha); 143 | surface.normalTS = normalTS; 144 | surface.clearCoatMask = 0; 145 | surface.clearCoatSmoothness = 1; 146 | 147 | #if UNITY_VERSION >= 202210 148 | surface.albedo = AlphaModulate(surface.albedo, surface.alpha); 149 | #endif 150 | 151 | #ifdef _DBUFFER 152 | ApplyDecalToSurfaceData(unpacked.positionCS, surface, inputData); 153 | #endif 154 | 155 | half4 color = UniversalFragmentBlinnPhong(inputData, surface); 156 | 157 | color.rgb = MixFog(color.rgb, inputData.fogCoord); 158 | #if UNITY_VERSION >= 202220 159 | 160 | color.a = OutputAlpha(color.a, isTransparent); 161 | 162 | outColor = color; 163 | 164 | #ifdef _WRITE_RENDERING_LAYERS 165 | uint renderingLayers = GetMeshRenderingLayer(); 166 | outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0); 167 | #endif 168 | 169 | #else 170 | return color; 171 | #endif //UNITY_VERSION 202220 172 | } 173 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/Includes/SimpleLitForwardPass.hlsl.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7ef812a205dd58448bee653739e214df 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/Includes/SimpleLitGBufferPass.hlsl: -------------------------------------------------------------------------------- 1 | 2 | void InitializeInputData(Varyings input, SurfaceDescription surfaceDescription, out InputData inputData) 3 | { 4 | inputData = (InputData)0; 5 | 6 | inputData.positionWS = input.positionWS; 7 | inputData.positionCS = input.positionCS; 8 | 9 | #ifdef _NORMALMAP 10 | // IMPORTANT! If we ever support Flip on double sided materials ensure bitangent and tangent are NOT flipped. 11 | float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale(); 12 | float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz); 13 | 14 | inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz); 15 | #if _NORMAL_DROPOFF_TS 16 | inputData.normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, inputData.tangentToWorld); 17 | #elif _NORMAL_DROPOFF_OS 18 | inputData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS); 19 | #elif _NORMAL_DROPOFF_WS 20 | inputData.normalWS = surfaceDescription.NormalWS; 21 | #endif 22 | #else 23 | inputData.normalWS = input.normalWS; 24 | #endif 25 | inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS); 26 | #if UNITY_VERSION >= 202220 27 | inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS); 28 | #else 29 | inputData.viewDirectionWS = SafeNormalize(GetWorldSpaceViewDir(input.positionWS)); 30 | #endif 31 | 32 | #if defined(MAIN_LIGHT_CALCULATE_SHADOWS) 33 | inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS); 34 | #else 35 | inputData.shadowCoord = float4(0, 0, 0, 0); 36 | #endif 37 | 38 | inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactorAndVertexLight.x); 39 | inputData.vertexLighting = input.fogFactorAndVertexLight.yzw; 40 | #if defined(DYNAMICLIGHTMAP_ON) 41 | inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV.xy, input.sh, inputData.normalWS); 42 | #else 43 | inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.sh, inputData.normalWS); 44 | #endif 45 | inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS); 46 | inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV); 47 | 48 | #if defined(DEBUG_DISPLAY) 49 | #if defined(DYNAMICLIGHTMAP_ON) 50 | inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy; 51 | #endif 52 | #if defined(LIGHTMAP_ON) 53 | inputData.staticLightmapUV = input.staticLightmapUV; 54 | #else 55 | inputData.vertexSH = input.sh; 56 | #endif 57 | #endif 58 | } 59 | 60 | PackedVaryings vert(Attributes input) 61 | { 62 | Varyings output = (Varyings)0; 63 | output = BuildVaryings(input); 64 | PackedVaryings packedOutput = (PackedVaryings)0; 65 | packedOutput = PackVaryings(output); 66 | return packedOutput; 67 | } 68 | 69 | FragmentOutput frag(PackedVaryings packedInput) 70 | { 71 | Varyings unpacked = UnpackVaryings(packedInput); 72 | UNITY_SETUP_INSTANCE_ID(unpacked); 73 | UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked); 74 | SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked); 75 | 76 | #if _ALPHATEST_ON 77 | half alpha = surfaceDescription.Alpha; 78 | clip(alpha - surfaceDescription.AlphaClipThreshold); 79 | #elif _SURFACE_TYPE_TRANSPARENT 80 | half alpha = surfaceDescription.Alpha; 81 | #else 82 | half alpha = 1; 83 | #endif 84 | 85 | #if UNITY_VERSION >= 202220 86 | #if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE 87 | LODFadeCrossFade(unpacked.positionCS); 88 | #endif 89 | #endif 90 | 91 | InputData inputData; 92 | InitializeInputData(unpacked, surfaceDescription, inputData); 93 | // TODO: Mip debug modes would require this, open question how to do this on ShaderGraph. 94 | //SETUP_DEBUG_TEXTURE_DATA(inputData, unpacked.uv, _MainTex); 95 | 96 | //ifdef _SPECULAR_SETUP 97 | #ifdef _SPECULAR_COLOR 98 | float3 specular = surfaceDescription.Specular; 99 | //float metallic = 1; 100 | #else 101 | float3 specular = 0; 102 | //float metallic = surfaceDescription.Metallic; 103 | #endif 104 | 105 | // Since we are using SurfaceData in this pass we should include the normal check 106 | half3 normalTS = half3(0, 0, 0); 107 | #if defined(_NORMALMAP) && defined(_NORMAL_DROPOFF_TS) 108 | normalTS = surfaceDescription.NormalTS; 109 | #endif 110 | 111 | #ifdef _DBUFFER 112 | // ApplyDecal needs modifiable values for metallic and occlusion 113 | // but they end up not being used, so feed them a throwaway value 114 | float throwaway = 0.0; 115 | ApplyDecal(unpacked.positionCS, 116 | surfaceDescription.BaseColor, 117 | specular, 118 | inputData.normalWS, 119 | /*metallic,*/ 120 | throwaway, 121 | /*surfaceDescription.Occlusion,*/ 122 | throwaway, 123 | surfaceDescription.Smoothness); 124 | #endif 125 | 126 | // in SimpleLitForwardPass GlobalIllumination (and temporarily UniversalBlinnPhong) are called inside UniversalFragmentBlinnPhong 127 | // in Deferred rendering we store the sum of these values (and of emission as well) in the GBuffer 128 | //BRDFData brdfData; 129 | //InitializeBRDFData(surfaceDescription.BaseColor, metallic, specular, surfaceDescription.Smoothness, alpha, brdfData); 130 | 131 | SurfaceData surface; 132 | surface.albedo = surfaceDescription.BaseColor; 133 | surface.metallic = 0.0; //saturate(metallic); 134 | surface.specular = specular; 135 | surface.smoothness = saturate(surfaceDescription.Smoothness), 136 | surface.occlusion = 1.0; //surfaceDescription.Occlusion, 137 | surface.emission = surfaceDescription.Emission, 138 | surface.alpha = saturate(alpha); 139 | surface.normalTS = normalTS; 140 | surface.clearCoatMask = 0; 141 | surface.clearCoatSmoothness = 1; 142 | 143 | #if UNITY_VERSION >= 202210 144 | surface.albedo = AlphaModulate(surface.albedo, surface.alpha); 145 | #endif 146 | 147 | Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask); 148 | MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, inputData.shadowMask); 149 | //half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surfaceDescription.Occlusion, inputData.positionWS, inputData.normalWS, inputData.viewDirectionWS); 150 | half4 color = half4(inputData.bakedGI * surface.albedo + surface.emission, surface.alpha); 151 | 152 | //return BRDFDataToGbuffer(brdfData, inputData, surfaceDescription.Smoothness, surfaceDescription.Emission + color, surfaceDescription.Occlusion); 153 | return SurfaceDataToGbuffer(surface, inputData, color.rgb, kLightingSimpleLit); 154 | } 155 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/Includes/SimpleLitGBufferPass.hlsl.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7ef812a205dd58448bee653739e241fd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/Targets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1406be91ef3e2e24e80d4cefca13a114 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/Targets/UniversalSimpleLitSubTarget.cs: -------------------------------------------------------------------------------- 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 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using UnityEditor.ShaderGraph; 11 | using UnityEditor.ShaderGraph.Legacy; 12 | using UnityEditor.UIElements; 13 | using UnityEngine; 14 | using UnityEngine.Assertions; 15 | using UnityEngine.Rendering.Universal; 16 | using UnityEngine.UIElements; 17 | using static Unity.Rendering.Universal.ShaderUtils; 18 | using static UnityEditor.Rendering.Universal.ShaderGraph.SubShaderUtils; 19 | 20 | namespace UnityEditor.Rendering.Universal.ShaderGraph 21 | { 22 | sealed class UniversalSimpleLitSubTarget : UniversalSubTarget/*, ILegacyTarget*/ 23 | { 24 | static readonly GUID kSourceCodeGuid = new GUID("d6c78107b64145745805d963de80cc28"); // UniversalSimpleLitSubTarget.cs 25 | 26 | // Should be in UniversalTarget 27 | public const string kSimpleLitMaterialTypeTag = "\"UniversalMaterialType\" = \"SimpleLit\""; 28 | 29 | #if UNITY_2022_2_OR_NEWER 30 | public override int latestVersion => 2; 31 | #elif UNITY_2022_1_OR_NEWER 32 | public override int latestVersion => 1; 33 | #endif 34 | 35 | //[SerializeField] 36 | static WorkflowMode m_WorkflowMode = WorkflowMode.Specular; 37 | 38 | [SerializeField] 39 | bool m_SpecularHighlights = false; 40 | 41 | [SerializeField] 42 | NormalDropOffSpace m_NormalDropOffSpace = NormalDropOffSpace.Tangent; 43 | 44 | #if UNITY_2022_1_OR_NEWER 45 | [SerializeField] 46 | bool m_BlendModePreserveSpecular = true; 47 | #endif 48 | 49 | public UniversalSimpleLitSubTarget() 50 | { 51 | displayName = "Simple Lit"; 52 | } 53 | 54 | // This should really be a dedicated ShaderID with relevant logic in ShaderUtils 55 | protected override ShaderID shaderID => ShaderID.Unknown; 56 | 57 | public static WorkflowMode workflowMode 58 | { 59 | get => m_WorkflowMode; 60 | //set => m_WorkflowMode = value; 61 | } 62 | 63 | public bool specularHighlights 64 | { 65 | get => m_SpecularHighlights; 66 | set => m_SpecularHighlights = value; 67 | } 68 | 69 | public NormalDropOffSpace normalDropOffSpace 70 | { 71 | get => m_NormalDropOffSpace; 72 | set => m_NormalDropOffSpace = value; 73 | } 74 | 75 | #if UNITY_2022_1_OR_NEWER 76 | public bool blendModePreserveSpecular 77 | { 78 | get => m_BlendModePreserveSpecular; 79 | set => m_BlendModePreserveSpecular = value; 80 | } 81 | #endif 82 | 83 | public override bool IsActive() => true; 84 | 85 | public override void Setup(ref TargetSetupContext context) 86 | { 87 | context.AddAssetDependency(kSourceCodeGuid, AssetCollection.Flags.SourceDependency); 88 | base.Setup(ref context); 89 | 90 | var universalRPType = typeof(UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset); 91 | if (!context.HasCustomEditorForRenderPipeline(universalRPType)) 92 | { 93 | var gui = typeof(ShaderGraphSimpleLitGUI); 94 | #if HAS_VFX_GRAPH 95 | if (TargetsVFX()) 96 | gui = typeof(VFXShaderGraphSimpleLitGUI); 97 | #endif 98 | context.AddCustomEditorForRenderPipeline(gui.FullName, universalRPType); 99 | } 100 | 101 | // Process SubShaders 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 105 | context.AddSubShader(PostProcessSubShader(SubShaders.SimpleLitComputeDotsSubShader(target, target.renderType, target.renderQueue, blendModePreserveSpecular, specularHighlights))); 106 | context.AddSubShader(PostProcessSubShader(SubShaders.SimpleLitGLESSubShader(target, target.renderType, target.renderQueue, blendModePreserveSpecular, specularHighlights))); 107 | #else 108 | context.AddSubShader(PostProcessSubShader(SubShaders.SimpleLitComputeDotsSubShader(target, target.renderType, target.renderQueue, specularHighlights))); 109 | context.AddSubShader(PostProcessSubShader(SubShaders.SimpleLitGLESSubShader(target, target.renderType, target.renderQueue, specularHighlights))); 110 | #endif 111 | } 112 | 113 | public override void ProcessPreviewMaterial(Material material) 114 | { 115 | if (target.allowMaterialOverride) 116 | { 117 | // copy our target's default settings into the material 118 | // (technically not necessary since we are always recreating the material from the shader each time, 119 | // which will pull over the defaults from the shader definition) 120 | // but if that ever changes, this will ensure the defaults are set 121 | material.SetFloat(Property.SpecularWorkflowMode, (float)workflowMode); 122 | material.SetFloat(SimpleLitProperty.SpecularHighlights, specularHighlights ? 1.0f : 0.0f); 123 | material.SetFloat(Property.CastShadows, target.castShadows ? 1.0f : 0.0f); 124 | material.SetFloat(Property.ReceiveShadows, target.receiveShadows ? 1.0f : 0.0f); 125 | material.SetFloat(Property.SurfaceType, (float)target.surfaceType); 126 | material.SetFloat(Property.BlendMode, (float)target.alphaMode); 127 | material.SetFloat(Property.AlphaClip, target.alphaClip ? 1.0f : 0.0f); 128 | material.SetFloat(Property.CullMode, (int)target.renderFace); 129 | material.SetFloat(Property.ZWriteControl, (float)target.zWriteControl); 130 | material.SetFloat(Property.ZTest, (float)target.zTestMode); 131 | } 132 | 133 | // We always need these properties regardless of whether the material is allowed to override 134 | // Queue control & offset enable correct automatic render queue behavior 135 | // Control == 0 is automatic, 1 is user-specified render queue 136 | material.SetFloat(Property.QueueOffset, 0.0f); 137 | material.SetFloat(Property.QueueControl, (float)BaseShaderGUI.QueueControl.Auto); 138 | 139 | // call the full unlit material setup function 140 | ShaderGraphSimpleLitGUI.UpdateMaterial(material, MaterialUpdateType.CreatedNewMaterial); 141 | } 142 | 143 | public override void GetFields(ref TargetFieldContext context) 144 | { 145 | base.GetFields(ref context); 146 | 147 | var descs = context.blocks.Select(x => x.descriptor); 148 | 149 | // SimpleLit -- always controlled by subtarget 150 | context.AddField(UniversalFields.NormalDropOffOS, normalDropOffSpace == NormalDropOffSpace.Object); 151 | context.AddField(UniversalFields.NormalDropOffTS, normalDropOffSpace == NormalDropOffSpace.Tangent); 152 | context.AddField(UniversalFields.NormalDropOffWS, normalDropOffSpace == NormalDropOffSpace.World); 153 | context.AddField(UniversalFields.Normal, descs.Contains(BlockFields.SurfaceDescription.NormalOS) || 154 | descs.Contains(BlockFields.SurfaceDescription.NormalTS) || 155 | descs.Contains(BlockFields.SurfaceDescription.NormalWS)); 156 | // Complex Lit 157 | } 158 | 159 | public override void GetActiveBlocks(ref TargetActiveBlockContext context) 160 | { 161 | context.AddBlock(BlockFields.SurfaceDescription.Smoothness); 162 | context.AddBlock(BlockFields.SurfaceDescription.NormalOS, normalDropOffSpace == NormalDropOffSpace.Object); 163 | context.AddBlock(BlockFields.SurfaceDescription.NormalTS, normalDropOffSpace == NormalDropOffSpace.Tangent); 164 | context.AddBlock(BlockFields.SurfaceDescription.NormalWS, normalDropOffSpace == NormalDropOffSpace.World); 165 | context.AddBlock(BlockFields.SurfaceDescription.Emission); 166 | 167 | // when the surface options are material controlled, we must show all of these blocks 168 | // when target controlled, we can cull the unnecessary blocks 169 | context.AddBlock(BlockFields.SurfaceDescription.Specular, specularHighlights || target.allowMaterialOverride); 170 | context.AddBlock(BlockFields.SurfaceDescription.Alpha, (target.surfaceType == SurfaceType.Transparent || target.alphaClip) || target.allowMaterialOverride); 171 | context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, (target.alphaClip) || target.allowMaterialOverride); 172 | } 173 | 174 | public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) 175 | { 176 | // if using material control, add the material property to control workflow mode 177 | if (target.allowMaterialOverride) 178 | { 179 | collector.AddFloatProperty(Property.SpecularWorkflowMode, (float)workflowMode); 180 | collector.AddFloatProperty(SimpleLitProperty.SpecularHighlights, specularHighlights ? 1.0f : 0.0f); 181 | collector.AddFloatProperty(Property.CastShadows, target.castShadows ? 1.0f : 0.0f); 182 | collector.AddFloatProperty(Property.ReceiveShadows, target.receiveShadows ? 1.0f : 0.0f); 183 | 184 | // setup properties using the defaults 185 | collector.AddFloatProperty(Property.SurfaceType, (float)target.surfaceType); 186 | collector.AddFloatProperty(Property.BlendMode, (float)target.alphaMode); 187 | collector.AddFloatProperty(Property.AlphaClip, target.alphaClip ? 1.0f : 0.0f); 188 | #if UNITY_2022_1_OR_NEWER 189 | collector.AddFloatProperty(Property.BlendModePreserveSpecular, blendModePreserveSpecular ? 1.0f : 0.0f); 190 | #endif 191 | collector.AddFloatProperty(Property.SrcBlend, 1.0f); // always set by material inspector, ok to have incorrect values here 192 | collector.AddFloatProperty(Property.DstBlend, 0.0f); // always set by material inspector, ok to have incorrect values here 193 | collector.AddToggleProperty(Property.ZWrite, (target.surfaceType == SurfaceType.Opaque)); 194 | collector.AddFloatProperty(Property.ZWriteControl, (float)target.zWriteControl); 195 | collector.AddFloatProperty(Property.ZTest, (float)target.zTestMode); // ztest mode is designed to directly pass as ztest 196 | collector.AddFloatProperty(Property.CullMode, (float)target.renderFace); // render face enum is designed to directly pass as a cull mode 197 | 198 | #if UNITY_2022_2_OR_NEWER 199 | bool enableAlphaToMask = (target.alphaClip && (target.surfaceType == SurfaceType.Opaque)); 200 | collector.AddFloatProperty(Property.AlphaToMask, enableAlphaToMask ? 1.0f : 0.0f); 201 | #endif 202 | } 203 | 204 | // We always need these properties regardless of whether the material is allowed to override other shader properties. 205 | // Queue control & offset enable correct automatic render queue behavior. Control == 0 is automatic, 1 is user-specified. 206 | // We initialize queue control to -1 to indicate to UpdateMaterial that it needs to initialize it properly on the material. 207 | collector.AddFloatProperty(Property.QueueOffset, 0.0f); 208 | collector.AddFloatProperty(Property.QueueControl, -1.0f); 209 | } 210 | 211 | public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) 212 | { 213 | var universalTarget = (target as UniversalTarget); 214 | universalTarget.AddDefaultMaterialOverrideGUI(ref context, onChange, registerUndo); 215 | 216 | context.AddProperty("Specular Highlights", new Toggle() { value = specularHighlights }, (evt) => 217 | { 218 | if (Equals(specularHighlights, evt.newValue)) 219 | return; 220 | 221 | registerUndo("Change Specular Highlights"); 222 | specularHighlights = evt.newValue; 223 | onChange(); 224 | }); 225 | 226 | universalTarget.AddDefaultSurfacePropertiesGUI(ref context, onChange, registerUndo, showReceiveShadows: true); 227 | 228 | context.AddProperty("Fragment Normal Space", new EnumField(NormalDropOffSpace.Tangent) { value = normalDropOffSpace }, (evt) => 229 | { 230 | if (Equals(normalDropOffSpace, evt.newValue)) 231 | return; 232 | 233 | registerUndo("Change Fragment Normal Space"); 234 | normalDropOffSpace = (NormalDropOffSpace)evt.newValue; 235 | onChange(); 236 | }); 237 | 238 | #if UNITY_2022_1_OR_NEWER 239 | if (target.surfaceType == SurfaceType.Transparent) 240 | { 241 | if (target.alphaMode == AlphaMode.Alpha || target.alphaMode == AlphaMode.Additive) 242 | context.AddProperty("Preserve Specular Lighting", new Toggle() { value = blendModePreserveSpecular }, (evt) => 243 | { 244 | if (Equals(blendModePreserveSpecular, evt.newValue)) 245 | return; 246 | 247 | registerUndo("Change Preserve Specular"); 248 | blendModePreserveSpecular = evt.newValue; 249 | onChange(); 250 | }); 251 | } 252 | #endif 253 | 254 | } 255 | 256 | protected override int ComputeMaterialNeedsUpdateHash() 257 | { 258 | int hash = base.ComputeMaterialNeedsUpdateHash(); 259 | hash = hash * 23 + target.allowMaterialOverride.GetHashCode(); 260 | return hash; 261 | } 262 | 263 | #if UNITY_2022_1_OR_NEWER 264 | internal override void OnAfterParentTargetDeserialized() 265 | { 266 | Assert.IsNotNull(target); 267 | 268 | if (this.sgVersion < latestVersion) 269 | { 270 | // Upgrade old incorrect Premultiplied blend into 271 | // equivalent Alpha + Preserve Specular blend mode. 272 | if (this.sgVersion < 1) 273 | { 274 | if (target.alphaMode == AlphaMode.Premultiply) 275 | { 276 | target.alphaMode = AlphaMode.Alpha; 277 | blendModePreserveSpecular = true; 278 | } 279 | else 280 | blendModePreserveSpecular = false; 281 | } 282 | ChangeVersion(latestVersion); 283 | } 284 | } 285 | #endif 286 | 287 | #region SubShader 288 | static class SubShaders 289 | { 290 | #if UNITY_2022_2_15_OR_NEWER 291 | public static SubShaderDescriptor SimpleLitSubShader(UniversalTarget target, string renderType, string renderQueue, bool blendModePreserveSpecular, bool specularHighlights) 292 | // SM 4.5, compute with dots instancing 293 | #elif UNITY_2022_1_OR_NEWER 294 | public static SubShaderDescriptor SimpleLitComputeDotsSubShader(UniversalTarget target, string renderType, string renderQueue, bool blendModePreserveSpecular, bool specularHighlights) 295 | #else 296 | public static SubShaderDescriptor SimpleLitComputeDotsSubShader(UniversalTarget target, string renderType, string renderQueue, bool specularHighlights) 297 | #endif 298 | { 299 | SubShaderDescriptor result = new SubShaderDescriptor() 300 | { 301 | pipelineTag = UniversalTarget.kPipelineTag, 302 | customTags = kSimpleLitMaterialTypeTag, 303 | renderType = renderType, 304 | renderQueue = renderQueue, 305 | generatesPreview = true, 306 | passes = new PassCollection() 307 | }; 308 | 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 312 | result.passes.Add(SimpleLitPasses.Forward(target, blendModePreserveSpecular, specularHighlights, CorePragmas.ForwardSM45, SimpleLitKeywords.DOTSForward)); 313 | #elif UNITY_2022_1_OR_NEWER 314 | result.passes.Add(SimpleLitPasses.Forward(target, blendModePreserveSpecular, specularHighlights, CorePragmas.DOTSForward)); 315 | #else 316 | result.passes.Add(SimpleLitPasses.Forward(target, specularHighlights, CorePragmas.DOTSForward)); 317 | #endif 318 | 319 | #if UNITY_2022_1_OR_NEWER 320 | result.passes.Add(SimpleLitPasses.GBuffer(target, blendModePreserveSpecular, specularHighlights)); 321 | #else 322 | result.passes.Add(SimpleLitPasses.GBuffer(target, specularHighlights)); 323 | #endif 324 | 325 | // cull the shadowcaster pass if we know it will never be used 326 | if (target.castShadows || target.allowMaterialOverride) 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 330 | result.passes.Add(PassVariant(CorePasses.ShadowCaster(target), CorePragmas.InstancedSM45)); 331 | #else 332 | result.passes.Add(PassVariant(CorePasses.ShadowCaster(target), CorePragmas.DOTSInstanced)); 333 | #endif 334 | 335 | if (target.mayWriteDepth) 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 339 | result.passes.Add(PassVariant(CorePasses.DepthOnly(target), CorePragmas.InstancedSM45)); 340 | #else 341 | result.passes.Add(PassVariant(CorePasses.DepthOnly(target), CorePragmas.DOTSInstanced)); 342 | #endif 343 | 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 347 | result.passes.Add(PassVariant(SimpleLitPasses.DepthNormal(target), CorePragmas.InstancedSM45)); 348 | #else 349 | result.passes.Add(PassVariant(SimpleLitPasses.DepthNormal(target), CorePragmas.DOTSInstanced)); 350 | #endif 351 | 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 355 | result.passes.Add(PassVariant(SimpleLitPasses.Meta(target), CorePragmas.DefaultSM45)); 356 | #else 357 | result.passes.Add(PassVariant(SimpleLitPasses.Meta(target), CorePragmas.DOTSDefault)); 358 | #endif 359 | 360 | // Currently neither of these passes (selection/picking) can be last for the game view for 361 | // UI shaders to render correctly. Verify [1352225] before changing this order. 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 365 | result.passes.Add(PassVariant(CorePasses.SceneSelection(target), CorePragmas.DefaultSM45)); 366 | #else 367 | result.passes.Add(PassVariant(CorePasses.SceneSelection(target), CorePragmas.DOTSDefault)); 368 | #endif 369 | 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 373 | result.passes.Add(PassVariant(CorePasses.ScenePicking(target), CorePragmas.DefaultSM45)); 374 | #else 375 | result.passes.Add(PassVariant(CorePasses.ScenePicking(target), CorePragmas.DOTSDefault)); 376 | #endif 377 | 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 381 | result.passes.Add(PassVariant(SimpleLitPasses._2D(target), CorePragmas.DefaultSM45)); 382 | #else 383 | result.passes.Add(PassVariant(SimpleLitPasses._2D(target), CorePragmas.DOTSDefault)); 384 | #endif 385 | 386 | 387 | return result; 388 | } 389 | 390 | #if !UNITY_2022_2_15_OR_NEWER 391 | #if UNITY_2022_1_OR_NEWER 392 | public static SubShaderDescriptor SimpleLitGLESSubShader(UniversalTarget target, string renderType, string renderQueue, bool blendModePreserveSpecular, bool specularHighlights) 393 | #else 394 | public static SubShaderDescriptor SimpleLitGLESSubShader(UniversalTarget target, string renderType, string renderQueue, bool specularHighlights) 395 | #endif 396 | { 397 | // SM 2.0, GLES 398 | 399 | // ForwardOnly pass is used as complex Lit SM 2.0 fallback for GLES. 400 | // Drops advanced features and renders materials as SimpleLit. 401 | 402 | SubShaderDescriptor result = new SubShaderDescriptor() 403 | { 404 | pipelineTag = UniversalTarget.kPipelineTag, 405 | customTags = kSimpleLitMaterialTypeTag, 406 | renderType = renderType, 407 | renderQueue = renderQueue, 408 | generatesPreview = true, 409 | passes = new PassCollection() 410 | }; 411 | 412 | #if UNITY_2022_2_OR_NEWER 413 | result.passes.Add(SimpleLitPasses.Forward(target, blendModePreserveSpecular, specularHighlights, CorePragmas.Forward, SimpleLitKeywords.Forward)); 414 | #elif UNITY_2022_1_OR_NEWER 415 | result.passes.Add(SimpleLitPasses.Forward(target, blendModePreserveSpecular, specularHighlights)); 416 | #else 417 | result.passes.Add(SimpleLitPasses.Forward(target, specularHighlights)); 418 | #endif 419 | 420 | // cull the shadowcaster pass if we know it will never be used 421 | if (target.castShadows || target.allowMaterialOverride) 422 | result.passes.Add(CorePasses.ShadowCaster(target)); 423 | 424 | if (target.mayWriteDepth) 425 | result.passes.Add(CorePasses.DepthOnly(target)); 426 | 427 | result.passes.Add(CorePasses.DepthNormal(target)); 428 | result.passes.Add(SimpleLitPasses.Meta(target)); 429 | // Currently neither of these passes (selection/picking) can be last for the game view for 430 | // UI shaders to render correctly. Verify [1352225] before changing this order. 431 | result.passes.Add(CorePasses.SceneSelection(target)); 432 | result.passes.Add(CorePasses.ScenePicking(target)); 433 | 434 | result.passes.Add(SimpleLitPasses._2D(target)); 435 | 436 | return result; 437 | } 438 | #endif 439 | } 440 | #endregion 441 | 442 | #region Passes 443 | static class SimpleLitPasses 444 | { 445 | static void AddWorkflowModeControlToPass(ref PassDescriptor pass, UniversalTarget target, WorkflowMode workflowMode) 446 | { 447 | //if (target.allowMaterialOverride) 448 | // pass.keywords.Add(LitDefines.SpecularSetup); 449 | //else if (workflowMode == WorkflowMode.Specular) 450 | pass.defines.Add(SimpleLitDefines.SpecularSetup, 1); 451 | } 452 | 453 | static void AddSpecularHighlightsControlToPass(ref PassDescriptor pass, UniversalTarget target, bool specularHighlights) 454 | { 455 | if (target.allowMaterialOverride) 456 | pass.keywords.Add(SimpleLitDefines.SpecularColor); 457 | else if (specularHighlights) 458 | pass.defines.Add(SimpleLitDefines.SpecularColor, 1); 459 | } 460 | 461 | static void AddReceiveShadowsControlToPass(ref PassDescriptor pass, UniversalTarget target, bool receiveShadows) 462 | { 463 | if (target.allowMaterialOverride) 464 | pass.keywords.Add(SimpleLitKeywords.ReceiveShadowsOff); 465 | else if (!receiveShadows) 466 | pass.defines.Add(SimpleLitKeywords.ReceiveShadowsOff, 1); 467 | } 468 | 469 | #if UNITY_2022_2_OR_NEWER 470 | public static PassDescriptor Forward( 471 | UniversalTarget target, 472 | bool blendModePreserveSpecular, 473 | bool specularHighlights, 474 | PragmaCollection pragmas, 475 | KeywordCollection keywords) 476 | #elif UNITY_2022_1_OR_NEWER 477 | public static PassDescriptor Forward(UniversalTarget target, bool blendModePreserveSpecular, bool specularHighlights, PragmaCollection pragmas = null) 478 | #else 479 | public static PassDescriptor Forward(UniversalTarget target, bool specularHighlights, PragmaCollection pragmas = null) 480 | #endif 481 | { 482 | var result = new PassDescriptor() 483 | { 484 | // Definition 485 | displayName = "Universal Forward", 486 | referenceName = "SHADERPASS_FORWARD", 487 | lightMode = "UniversalForward", 488 | useInPreview = true, 489 | 490 | // Template 491 | passTemplatePath = UniversalTarget.kUberTemplatePath, 492 | sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories, 493 | 494 | // Port Mask 495 | validVertexBlocks = CoreBlockMasks.Vertex, 496 | validPixelBlocks = SimpleLitBlockMasks.FragmentSimpleLit, 497 | 498 | // Fields 499 | structs = CoreStructCollections.Default, 500 | requiredFields = SimpleLitRequiredFields.Forward, 501 | fieldDependencies = CoreFieldDependencies.Default, 502 | 503 | // Conditional State 504 | #if UNITY_2022_1_OR_NEWER 505 | renderStates = CoreRenderStates.UberSwitchedRenderState(target, blendModePreserveSpecular), 506 | #else 507 | renderStates = CoreRenderStates.UberSwitchedRenderState(target/*, blendModePreserveSpecular*/), 508 | #endif 509 | pragmas = pragmas ?? CorePragmas.Forward, // NOTE: SM 2.0 only GL 510 | defines = new DefineCollection() { CoreDefines.UseFragmentFog }, 511 | #if UNITY_2022_2_OR_NEWER 512 | keywords = new KeywordCollection() { keywords }, 513 | #else 514 | keywords = new KeywordCollection() { SimpleLitKeywords.Forward }, 515 | #endif 516 | includes = SimpleLitIncludes.Forward, 517 | 518 | // Custom Interpolator Support 519 | customInterpolators = CoreCustomInterpDescriptors.Common 520 | }; 521 | 522 | #if UNITY_2022_1_OR_NEWER 523 | CorePasses.AddTargetSurfaceControlsToPass(ref result, target, blendModePreserveSpecular); 524 | #else 525 | CorePasses.AddTargetSurfaceControlsToPass(ref result, target/*, blendModePreserveSpecular*/); 526 | #endif 527 | #if UNITY_2022_2_OR_NEWER 528 | CorePasses.AddAlphaToMaskControlToPass(ref result, target); 529 | #endif 530 | AddWorkflowModeControlToPass(ref result, target, workflowMode); 531 | AddSpecularHighlightsControlToPass(ref result, target, specularHighlights); 532 | AddReceiveShadowsControlToPass(ref result, target, target.receiveShadows); 533 | #if UNITY_2022_2_OR_NEWER 534 | CorePasses.AddLODCrossFadeControlToPass(ref result, target); 535 | #endif 536 | 537 | return result; 538 | } 539 | 540 | // Deferred only in SM4.5, MRT not supported in GLES2 541 | #if UNITY_2022_1_OR_NEWER 542 | public static PassDescriptor GBuffer(UniversalTarget target, bool blendModePreserveSpecular, bool specularHighlights) 543 | #else 544 | public static PassDescriptor GBuffer(UniversalTarget target, bool specularHighlights) 545 | #endif 546 | { 547 | var result = new PassDescriptor 548 | { 549 | // Definition 550 | displayName = "GBuffer", 551 | referenceName = "SHADERPASS_GBUFFER", 552 | lightMode = "UniversalGBuffer", 553 | #if UNITY_2022_2_OR_NEWER 554 | useInPreview = true, 555 | #endif 556 | 557 | // Template 558 | passTemplatePath = UniversalTarget.kUberTemplatePath, 559 | sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories, 560 | 561 | // Port Mask 562 | validVertexBlocks = CoreBlockMasks.Vertex, 563 | validPixelBlocks = SimpleLitBlockMasks.FragmentSimpleLit, 564 | 565 | // Fields 566 | structs = CoreStructCollections.Default, 567 | requiredFields = SimpleLitRequiredFields.GBuffer, 568 | fieldDependencies = CoreFieldDependencies.Default, 569 | 570 | // Conditional State 571 | #if UNITY_2022_1_OR_NEWER 572 | renderStates = CoreRenderStates.UberSwitchedRenderState(target, blendModePreserveSpecular), 573 | #else 574 | renderStates = CoreRenderStates.UberSwitchedRenderState(target/*, blendModePreserveSpecular*/), 575 | #endif 576 | #if UNITY_2022_2_15_OR_NEWER 577 | pragmas = CorePragmas.GBuffer, 578 | #elif UNITY_2022_2_OR_NEWER 579 | pragmas = CorePragmas.GBufferSM45, 580 | #else 581 | pragmas = CorePragmas.DOTSGBuffer, 582 | #endif 583 | defines = new DefineCollection() { CoreDefines.UseFragmentFog }, 584 | keywords = new KeywordCollection() { SimpleLitKeywords.GBuffer }, 585 | includes = SimpleLitIncludes.GBuffer, 586 | 587 | // Custom Interpolator Support 588 | customInterpolators = CoreCustomInterpDescriptors.Common 589 | }; 590 | 591 | #if UNITY_2022_1_OR_NEWER 592 | CorePasses.AddTargetSurfaceControlsToPass(ref result, target, blendModePreserveSpecular); 593 | #else 594 | CorePasses.AddTargetSurfaceControlsToPass(ref result, target/*, blendModePreserveSpecular*/); 595 | #endif 596 | AddWorkflowModeControlToPass(ref result, target, workflowMode); 597 | AddSpecularHighlightsControlToPass(ref result, target, specularHighlights); 598 | AddReceiveShadowsControlToPass(ref result, target, target.receiveShadows); 599 | #if UNITY_2022_2_OR_NEWER 600 | CorePasses.AddLODCrossFadeControlToPass(ref result, target); 601 | #endif 602 | 603 | return result; 604 | } 605 | 606 | public static PassDescriptor Meta(UniversalTarget target) 607 | { 608 | var result = new PassDescriptor() 609 | { 610 | // Definition 611 | displayName = "Meta", 612 | referenceName = "SHADERPASS_META", 613 | lightMode = "Meta", 614 | 615 | // Template 616 | passTemplatePath = UniversalTarget.kUberTemplatePath, 617 | sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories, 618 | 619 | // Port Mask 620 | validVertexBlocks = CoreBlockMasks.Vertex, 621 | validPixelBlocks = SimpleLitBlockMasks.FragmentMeta, 622 | 623 | // Fields 624 | structs = CoreStructCollections.Default, 625 | requiredFields = SimpleLitRequiredFields.Meta, 626 | fieldDependencies = CoreFieldDependencies.Default, 627 | 628 | // Conditional State 629 | renderStates = CoreRenderStates.Meta, 630 | pragmas = CorePragmas.Default, 631 | defines = new DefineCollection() { CoreDefines.UseFragmentFog }, 632 | keywords = new KeywordCollection() { CoreKeywordDescriptors.EditorVisualization }, 633 | includes = SimpleLitIncludes.Meta, 634 | 635 | // Custom Interpolator Support 636 | customInterpolators = CoreCustomInterpDescriptors.Common 637 | }; 638 | 639 | CorePasses.AddAlphaClipControlToPass(ref result, target); 640 | 641 | return result; 642 | } 643 | 644 | public static PassDescriptor _2D(UniversalTarget target) 645 | { 646 | var result = new PassDescriptor() 647 | { 648 | // Definition 649 | referenceName = "SHADERPASS_2D", 650 | lightMode = "Universal2D", 651 | 652 | // Template 653 | passTemplatePath = UniversalTarget.kUberTemplatePath, 654 | sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories, 655 | 656 | // Port Mask 657 | validVertexBlocks = CoreBlockMasks.Vertex, 658 | validPixelBlocks = CoreBlockMasks.FragmentColorAlpha, 659 | 660 | // Fields 661 | structs = CoreStructCollections.Default, 662 | fieldDependencies = CoreFieldDependencies.Default, 663 | 664 | // Conditional State 665 | renderStates = CoreRenderStates.UberSwitchedRenderState(target), 666 | pragmas = CorePragmas.Instanced, 667 | defines = new DefineCollection(), 668 | keywords = new KeywordCollection(), 669 | includes = SimpleLitIncludes._2D, 670 | 671 | // Custom Interpolator Support 672 | customInterpolators = CoreCustomInterpDescriptors.Common 673 | }; 674 | 675 | CorePasses.AddAlphaClipControlToPass(ref result, target); 676 | 677 | return result; 678 | } 679 | 680 | public static PassDescriptor DepthNormal(UniversalTarget target) 681 | { 682 | var result = new PassDescriptor() 683 | { 684 | // Definition 685 | displayName = "DepthNormals", 686 | referenceName = "SHADERPASS_DEPTHNORMALS", 687 | lightMode = "DepthNormals", 688 | useInPreview = false, 689 | 690 | // Template 691 | passTemplatePath = UniversalTarget.kUberTemplatePath, 692 | sharedTemplateDirectories = UniversalTarget.kSharedTemplateDirectories, 693 | 694 | // Port Mask 695 | validVertexBlocks = CoreBlockMasks.Vertex, 696 | validPixelBlocks = CoreBlockMasks.FragmentDepthNormals, 697 | 698 | // Fields 699 | structs = CoreStructCollections.Default, 700 | requiredFields = CoreRequiredFields.DepthNormals, 701 | fieldDependencies = CoreFieldDependencies.Default, 702 | 703 | // Conditional State 704 | renderStates = CoreRenderStates.DepthNormalsOnly(target), 705 | pragmas = CorePragmas.Instanced, 706 | defines = new DefineCollection(), 707 | #if UNITY_2022_2_15_OR_NEWER 708 | keywords = new KeywordCollection(), 709 | #elif UNITY_2022_2_OR_NEWER 710 | keywords = new KeywordCollection() { CoreKeywords.DOTSDepthNormal }, 711 | #else 712 | keywords = new KeywordCollection(), 713 | #endif 714 | includes = CoreIncludes.DepthNormalsOnly, 715 | 716 | // Custom Interpolator Support 717 | customInterpolators = CoreCustomInterpDescriptors.Common 718 | }; 719 | 720 | CorePasses.AddAlphaClipControlToPass(ref result, target); 721 | #if UNITY_2022_2_OR_NEWER 722 | CorePasses.AddLODCrossFadeControlToPass(ref result, target); 723 | #endif 724 | 725 | return result; 726 | } 727 | } 728 | #endregion 729 | 730 | #region PortMasks 731 | static class SimpleLitBlockMasks 732 | { 733 | public static readonly BlockFieldDescriptor[] FragmentSimpleLit = new BlockFieldDescriptor[] 734 | { 735 | BlockFields.SurfaceDescription.BaseColor, 736 | BlockFields.SurfaceDescription.NormalOS, 737 | BlockFields.SurfaceDescription.NormalTS, 738 | BlockFields.SurfaceDescription.NormalWS, 739 | BlockFields.SurfaceDescription.Emission, 740 | BlockFields.SurfaceDescription.Specular, 741 | BlockFields.SurfaceDescription.Smoothness, 742 | BlockFields.SurfaceDescription.Alpha, 743 | BlockFields.SurfaceDescription.AlphaClipThreshold, 744 | }; 745 | 746 | public static readonly BlockFieldDescriptor[] FragmentMeta = new BlockFieldDescriptor[] 747 | { 748 | BlockFields.SurfaceDescription.BaseColor, 749 | BlockFields.SurfaceDescription.Emission, 750 | BlockFields.SurfaceDescription.Alpha, 751 | BlockFields.SurfaceDescription.AlphaClipThreshold, 752 | }; 753 | } 754 | #endregion 755 | 756 | #region RequiredFields 757 | static class SimpleLitRequiredFields 758 | { 759 | public static readonly FieldCollection Forward = new FieldCollection() 760 | { 761 | StructFields.Attributes.uv1, 762 | StructFields.Attributes.uv2, 763 | StructFields.Varyings.positionWS, 764 | StructFields.Varyings.normalWS, 765 | StructFields.Varyings.tangentWS, // needed for vertex lighting 766 | UniversalStructFields.Varyings.staticLightmapUV, 767 | UniversalStructFields.Varyings.dynamicLightmapUV, 768 | UniversalStructFields.Varyings.sh, 769 | UniversalStructFields.Varyings.fogFactorAndVertexLight, // fog and vertex lighting, vert input is dependency 770 | UniversalStructFields.Varyings.shadowCoord, // shadow coord, vert input is dependency 771 | }; 772 | 773 | public static readonly FieldCollection GBuffer = new FieldCollection() 774 | { 775 | StructFields.Attributes.uv1, 776 | StructFields.Attributes.uv2, 777 | StructFields.Varyings.positionWS, 778 | StructFields.Varyings.normalWS, 779 | StructFields.Varyings.tangentWS, // needed for vertex lighting 780 | UniversalStructFields.Varyings.staticLightmapUV, 781 | UniversalStructFields.Varyings.dynamicLightmapUV, 782 | UniversalStructFields.Varyings.sh, 783 | UniversalStructFields.Varyings.fogFactorAndVertexLight, // fog and vertex lighting, vert input is dependency 784 | UniversalStructFields.Varyings.shadowCoord, // shadow coord, vert input is dependency 785 | }; 786 | 787 | public static readonly FieldCollection Meta = new FieldCollection() 788 | { 789 | StructFields.Attributes.positionOS, 790 | StructFields.Attributes.normalOS, 791 | StructFields.Attributes.uv0, // 792 | StructFields.Attributes.uv1, // needed for meta vertex position 793 | StructFields.Attributes.uv2, // needed for meta UVs 794 | StructFields.Attributes.instanceID, // needed for rendering instanced terrain 795 | StructFields.Varyings.positionCS, 796 | StructFields.Varyings.texCoord0, // needed for meta UVs 797 | StructFields.Varyings.texCoord1, // VizUV 798 | StructFields.Varyings.texCoord2, // LightCoord 799 | }; 800 | } 801 | #endregion 802 | 803 | #region Defines 804 | static class SimpleLitDefines 805 | { 806 | public static readonly KeywordDescriptor SpecularSetup = new KeywordDescriptor() 807 | { 808 | displayName = "Specular Setup", 809 | referenceName = "_SPECULAR_SETUP", 810 | type = KeywordType.Boolean, 811 | definition = KeywordDefinition.ShaderFeature, 812 | scope = KeywordScope.Local, 813 | stages = KeywordShaderStage.Fragment 814 | }; 815 | 816 | public static readonly KeywordDescriptor SpecularColor = new KeywordDescriptor() 817 | { 818 | displayName = "Specular Color", 819 | referenceName = SimpleLitProperty.SpecularColorKeyword, 820 | type = KeywordType.Boolean, 821 | definition = KeywordDefinition.ShaderFeature, 822 | scope = KeywordScope.Local, 823 | stages = KeywordShaderStage.Fragment 824 | }; 825 | } 826 | #endregion 827 | 828 | #region Keywords 829 | static class SimpleLitKeywords 830 | { 831 | public static readonly KeywordDescriptor ReceiveShadowsOff = new KeywordDescriptor() 832 | { 833 | displayName = "Receive Shadows Off", 834 | referenceName = ShaderKeywordStrings._RECEIVE_SHADOWS_OFF, 835 | type = KeywordType.Boolean, 836 | definition = KeywordDefinition.ShaderFeature, 837 | scope = KeywordScope.Local, 838 | }; 839 | 840 | #if UNITY_2022_2_OR_NEWER 841 | #else 842 | public static readonly KeywordDescriptor ScreenSpaceAmbientOcclusion = new KeywordDescriptor() 843 | { 844 | displayName = "Screen Space Ambient Occlusion", 845 | referenceName = "_SCREEN_SPACE_OCCLUSION", 846 | type = KeywordType.Boolean, 847 | definition = KeywordDefinition.MultiCompile, 848 | scope = KeywordScope.Global, 849 | stages = KeywordShaderStage.Fragment, 850 | }; 851 | #endif 852 | 853 | public static readonly KeywordCollection Forward = new KeywordCollection 854 | { 855 | #if UNITY_2022_2_OR_NEWER 856 | { CoreKeywordDescriptors.ScreenSpaceAmbientOcclusion }, 857 | #else 858 | { ScreenSpaceAmbientOcclusion }, 859 | #endif 860 | { CoreKeywordDescriptors.StaticLightmap }, 861 | { CoreKeywordDescriptors.DynamicLightmap }, 862 | { CoreKeywordDescriptors.DirectionalLightmapCombined }, 863 | { CoreKeywordDescriptors.MainLightShadows }, 864 | { CoreKeywordDescriptors.AdditionalLights }, 865 | { CoreKeywordDescriptors.AdditionalLightShadows }, 866 | { CoreKeywordDescriptors.ReflectionProbeBlending }, 867 | { CoreKeywordDescriptors.ReflectionProbeBoxProjection }, 868 | { CoreKeywordDescriptors.ShadowsSoft }, 869 | { CoreKeywordDescriptors.LightmapShadowMixing }, 870 | { CoreKeywordDescriptors.ShadowsShadowmask }, 871 | { CoreKeywordDescriptors.DBuffer }, 872 | { CoreKeywordDescriptors.LightLayers }, 873 | { CoreKeywordDescriptors.DebugDisplay }, 874 | { CoreKeywordDescriptors.LightCookies }, 875 | #if UNITY_2022_2_OR_NEWER 876 | { CoreKeywordDescriptors.ForwardPlus }, 877 | #else 878 | { CoreKeywordDescriptors.ClusteredRendering }, 879 | #endif 880 | }; 881 | 882 | #if UNITY_2022_2_15_OR_NEWER 883 | #elif UNITY_2022_2_OR_NEWER 884 | public static readonly KeywordCollection DOTSForward = new KeywordCollection 885 | { 886 | { Forward }, 887 | { CoreKeywordDescriptors.WriteRenderingLayers }, 888 | }; 889 | #endif 890 | 891 | public static readonly KeywordCollection GBuffer = new KeywordCollection 892 | { 893 | { CoreKeywordDescriptors.StaticLightmap }, 894 | { CoreKeywordDescriptors.DynamicLightmap }, 895 | { CoreKeywordDescriptors.DirectionalLightmapCombined }, 896 | { CoreKeywordDescriptors.MainLightShadows }, 897 | { CoreKeywordDescriptors.ReflectionProbeBlending }, 898 | { CoreKeywordDescriptors.ReflectionProbeBoxProjection }, 899 | { CoreKeywordDescriptors.ShadowsSoft }, 900 | { CoreKeywordDescriptors.LightmapShadowMixing }, 901 | { CoreKeywordDescriptors.MixedLightingSubtractive }, 902 | { CoreKeywordDescriptors.DBuffer }, 903 | { CoreKeywordDescriptors.GBufferNormalsOct }, 904 | #if UNITY_2022_2_15_OR_NEWER 905 | { CoreKeywordDescriptors.LightLayers }, 906 | #elif UNITY_2022_2_OR_NEWER 907 | { CoreKeywordDescriptors.WriteRenderingLayers }, 908 | #else 909 | { CoreKeywordDescriptors.LightLayers }, 910 | #endif 911 | { CoreKeywordDescriptors.RenderPassEnabled }, 912 | { CoreKeywordDescriptors.DebugDisplay }, 913 | }; 914 | } 915 | #endregion 916 | 917 | #region Includes 918 | static class SimpleLitIncludes 919 | { 920 | const string kShadows = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"; 921 | const string kMetaInput = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"; 922 | const string kForwardPass = "Packages/com.zallist.universal-shadergraph-extensions/Editor/ShaderGraph/Includes/SimpleLitForwardPass.hlsl"; 923 | const string kGBuffer = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/UnityGBuffer.hlsl"; 924 | const string kSimpleLitGBufferPass = "Packages/com.zallist.universal-shadergraph-extensions/Editor/ShaderGraph/Includes/SimpleLitGBufferPass.hlsl"; 925 | const string kLightingMetaPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/LightingMetaPass.hlsl"; 926 | // TODO : Replace 2D for Simple one 927 | const string k2DPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/PBR2DPass.hlsl"; 928 | 929 | public static readonly IncludeCollection Forward = new IncludeCollection 930 | { 931 | // Pre-graph 932 | #if UNITY_2022_2_15_OR_NEWER 933 | { CoreIncludes.DOTSPregraph }, 934 | { CoreIncludes.WriteRenderLayersPregraph }, 935 | #endif 936 | { CoreIncludes.CorePregraph }, 937 | { kShadows, IncludeLocation.Pregraph }, 938 | { CoreIncludes.ShaderGraphPregraph }, 939 | { CoreIncludes.DBufferPregraph }, 940 | 941 | // Post-graph 942 | { CoreIncludes.CorePostgraph }, 943 | { kForwardPass, IncludeLocation.Postgraph }, 944 | }; 945 | 946 | public static readonly IncludeCollection GBuffer = new IncludeCollection 947 | { 948 | // Pre-graph 949 | #if UNITY_2022_2_15_OR_NEWER 950 | { CoreIncludes.DOTSPregraph }, 951 | { CoreIncludes.WriteRenderLayersPregraph }, 952 | #endif 953 | { CoreIncludes.CorePregraph }, 954 | { kShadows, IncludeLocation.Pregraph }, 955 | { CoreIncludes.ShaderGraphPregraph }, 956 | { CoreIncludes.DBufferPregraph }, 957 | 958 | // Post-graph 959 | { CoreIncludes.CorePostgraph }, 960 | { kGBuffer, IncludeLocation.Postgraph }, 961 | //{ kPBRGBufferPass, IncludeLocation.Postgraph }, 962 | { kSimpleLitGBufferPass, IncludeLocation.Postgraph }, 963 | }; 964 | 965 | public static readonly IncludeCollection Meta = new IncludeCollection 966 | { 967 | // Pre-graph 968 | { CoreIncludes.CorePregraph }, 969 | { CoreIncludes.ShaderGraphPregraph }, 970 | { kMetaInput, IncludeLocation.Pregraph }, 971 | 972 | // Post-graph 973 | { CoreIncludes.CorePostgraph }, 974 | { kLightingMetaPass, IncludeLocation.Postgraph }, 975 | }; 976 | 977 | public static readonly IncludeCollection _2D = new IncludeCollection 978 | { 979 | // Pre-graph 980 | { CoreIncludes.CorePregraph }, 981 | { CoreIncludes.ShaderGraphPregraph }, 982 | 983 | // Post-graph 984 | { CoreIncludes.CorePostgraph }, 985 | { k2DPass, IncludeLocation.Postgraph }, 986 | }; 987 | } 988 | #endregion 989 | } 990 | 991 | public static class SimpleLitProperty 992 | { 993 | public static readonly string SpecularColorKeyword = "_SPECULAR_COLOR"; 994 | public static readonly string SpecularHighlights = "_SpecularHighlights"; 995 | } 996 | } 997 | -------------------------------------------------------------------------------- /Editor/ShaderGraph/Targets/UniversalSimpleLitSubTarget.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7583995cf5c4cd243a9b7121aab455c3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/UniversalShaderGraphExtensions.asmref: -------------------------------------------------------------------------------- 1 | { 2 | "reference": "GUID:c579267770062bf448e75eb160330b7f" 3 | } -------------------------------------------------------------------------------- /Editor/UniversalShaderGraphExtensions.asmref.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e7df7b2cd91bdd49974c93d07d7de02 3 | AssemblyDefinitionReferenceImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/VFXGraph.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0c5640b59ec4780981fdc59a51d1539 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/VFXGraph/VFXShaderGraphSimpleLitGUI.cs: -------------------------------------------------------------------------------- 1 | #if HAS_VFX_GRAPH 2 | using UnityEngine; 3 | using UnityEngine.Rendering; 4 | 5 | namespace UnityEditor.Rendering.Universal 6 | { 7 | internal class VFXShaderGraphSimpleLitGUI : ShaderGraphSimpleLitGUI 8 | { 9 | protected override uint materialFilter => uint.MaxValue & ~(uint)Expandable.SurfaceInputs; 10 | } 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /Editor/VFXGraph/VFXShaderGraphSimpleLitGUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88a4bfc6472185e4497230f6613ea686 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Zallist 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 307553f4bd834826b9c85730deb93e90 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | ## Unity Universal ShaderGraph Extensions 2 | This plugin simply adds a Simple Lit material (SubTarget) to the Universal target for Shader Graph for URP. 3 | If Unity ever implements the Simple Lit master node themselves, it should be an in-place replacement for this. To the point where you'll likely even get code conflicts. 4 | 5 | ## Dependencies 6 | * Works on Unity version 2021.2 or higher, with URP version 12 or higher 7 | 8 | ## How to install 9 | * Go to Package Manager in Unity 10 | * Press the + in the top left 11 | * Choose ADD PACKAGE FROM GIT URL 12 | * Enter https://github.com/Zallist/unity-universal-shadergraph-extensions.git 13 | 14 | ## How to use 15 | Once it's been installed, it should simply be a matter of just making a Shader Graph (there's an option in the Asset Creation menu for SIMPLE LIT SHADERGRAPH, near LIT SHADERGRAPH) and choosing the Material "Simple Lit". Basically the same way you'd make a Lit or Unlit shadergraph, instead just choose Simple Lit. 16 | 17 | ### Example 18 | ![Shader Graph](https://i.imgur.com/r4LI0g5.png) -------------------------------------------------------------------------------- /README.MD.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a10b4b5859d4347bc199bd5b0722285 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.zallist.universal-shadergraph-extensions", 3 | "displayName": "Universal Simple Lit ShaderGraph Target", 4 | "version": "2.1.0", 5 | "documentationUrl": "https://github.com/Zallist/unity.zallist.universal-simple-lit-shadergraph-target", 6 | "licensesUrl": "https://github.com/Zallist/unity.zallist.universal-simple-lit-shadergraph-target/blob/main/LICENSE", 7 | "description": "This plugin simply adds a Simple Lit material (SubTarget) to the Universal target for Shader Graph" 8 | } 9 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ebef30fa250a48c686a2eed78757c2ed 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------