From 123e3c375d4bf68ed4234cfbb67693fcb00d2092 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 08:43:56 +0300 Subject: [PATCH 01/13] Add basic empty shader generation --- Assets/Custom.meta | 8 + Assets/Custom/My Toon Shader.asset | 16 ++ Assets/Custom/My Toon Shader.asset.meta | 8 + Assets/Custom/My Toon Shader.shader | 261 ++++++++++++++++++ Assets/Custom/My Toon Shader.shader.meta | 10 + .../DELTation/ToonShader/Editor/Custom.meta | 3 + .../Editor/Custom/CustomToonShaderEditor.cs | 64 +++++ .../Custom/CustomToonShaderEditor.cs.meta | 3 + .../Editor/DELTation.ToonShader.Editor.asmdef | 4 +- .../DELTation/ToonShader/Shaders/.gitignore | 4 - .../DELTation/ToonShader/Shaders/Custom.meta | 3 + .../Shaders/Custom/CustomToonShader.cs | 13 + .../Shaders/Custom/CustomToonShader.cs.meta | 13 + .../Shaders/DELTation.ToonShader.asmdef | 16 ++ .../Shaders/DELTation.ToonShader.asmdef.meta | 7 + TestAsmdef.csproj.DotSettings | 3 + 16 files changed, 431 insertions(+), 5 deletions(-) create mode 100644 Assets/Custom.meta create mode 100644 Assets/Custom/My Toon Shader.asset create mode 100644 Assets/Custom/My Toon Shader.asset.meta create mode 100644 Assets/Custom/My Toon Shader.shader create mode 100644 Assets/Custom/My Toon Shader.shader.meta create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom.meta create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs.meta delete mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/.gitignore create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom.meta create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs.meta create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/DELTation.ToonShader.asmdef create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/DELTation.ToonShader.asmdef.meta create mode 100644 TestAsmdef.csproj.DotSettings diff --git a/Assets/Custom.meta b/Assets/Custom.meta new file mode 100644 index 0000000..f2038ae --- /dev/null +++ b/Assets/Custom.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6d99fc966db874248aa2f64ae9fc72bc +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset new file mode 100644 index 0000000..929b8d2 --- /dev/null +++ b/Assets/Custom/My Toon Shader.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9d6cd861481d4b55b3652478146d0b38, type: 3} + m_Name: My Toon Shader + m_EditorClassIdentifier: + SourceShader: {fileID: 4800000, guid: 849dc4ff793a3f943ad21a3b6ee26456, type: 3} + Shader: {fileID: 4800000, guid: 2e0a54ed13173b14898a9bf0e10092da, type: 3} diff --git a/Assets/Custom/My Toon Shader.asset.meta b/Assets/Custom/My Toon Shader.asset.meta new file mode 100644 index 0000000..c32c1ec --- /dev/null +++ b/Assets/Custom/My Toon Shader.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d4260f0111d399c43901925c721fde8a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader new file mode 100644 index 0000000..e101107 --- /dev/null +++ b/Assets/Custom/My Toon Shader.shader @@ -0,0 +1,261 @@ +Shader "DELTation/Custom/My Toon Shader" +{ + Properties + { + [MainTexture] + _BaseMap ("Texture", 2D) = "white" {} + [MainColor] + _BaseColor ("Tint", Color) = (1.0, 1.0, 1.0) + _ShadowTint ("Shadow Tint", Color) = (0.0, 0.0, 0.0, 1.0) + [Toggle(_PURE_SHADOW_COLOR)] + _PureShadowColor ("Pure Shadow Color", Float) = 0 + + [Toggle(_RAMP_MAP)] + _UseRampMap("Use Ramp Texture", Float) = 0 + [NoScaleOffset] + _RampMap ("Ramp Texture", 2D) = "white" {} + [Toggle(_RAMP_TRIPLE)] _RampTriple ("Triple Ramp", Float) = 0 + _Ramp0 ("Ramp Threshold 0", Range(-1, 1)) = 0 + _Ramp1 ("Ramp Threshold 1", Range(-1, 1)) = 0.5 + _RampSmoothness ("Ramp Smoothness", Range(0, 2)) = 0.005 + + [NoScaleOffset] + _BumpMap("Normal Map", 2D) = "bump" {} + + [Toggle(_EMISSION)] _Emission ("Emission", Float) = 0 + [HDR] _EmissionColor ("Emission Color", Color) = (0.0, 0.0, 0.0, 0.0) + + [Toggle(_FRESNEL)] _Fresnel ("Rim", Float) = 0 + _FresnelThickness ("Rim Thickness", Range(0, 1)) = 0.45 + _FresnelSmoothness ("Rim Smoothness", Range(0, 1)) = 0.1 + [HDR] _FresnelColor ("Rim Color", Color) = (1.0, 1.0, 1.0, 1.0) + + [Toggle(_SPECULAR)] _Specular ("Specular", Float) = 0 + [Toggle(_ANISO_SPECULAR)] _AnisoSpecular("Anisotropic Specular", Float) = 0 + _SpecularThreshold ("Specular Threshold", Range(0, 1)) = 0.8 + _SpecularExponent ("Specular Exponent", Range(0, 1000)) = 200 + _SpecularSmoothness ("Specular Smoothness", Range(0, 1)) = 0.025 + [HDR] _SpecularColor ("Specular Color", Color) = (1.0, 1.0, 1.0, 1.0) + + [Toggle(_FOG)] _Fog ("Fog", Float) = 1 + [Toggle(_ADDITIONAL_LIGHTS_ENABLED)] _AdditionalLights ("Additonal Lights", Float) = 1 + [Toggle(_ADDITIONAL_LIGHTS_SPECULAR)] _AdditionalLightsSpecular ("Additonal Lights Specular", Float) = 0 + [Toggle(_ENVIRONMENT_LIGHTING_ENABLED)] _EnvironmentLightingEnabled ("Environment Lighting", Float) = 1 + [Toggle(_SHADOW_MASK)] _ShadowMask ("Baked Shadows", Float) = 0 + [Toggle(_VERTEX_COLOR)] _VertexColor ("Vertex Color", Float) = 0 + + [Slider(0, 1)] + _Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5 + + // Blending state + [Toggle] _ZWrite("Z Write", Float) = 1.0 + [Enum(UnityEngine.Rendering.CullMode)] _Cull("Culling", Float) = 0 + + [HideInInspector] _Surface("__surface", Float) = 0.0 + [HideInInspector] _Blend("__blend", Float) = 0.0 + [HideInInspector] _SrcBlend("__src", Float) = 1.0 + [HideInInspector] _DstBlend("__dst", Float) = 0.0 + [Toggle] _AlphaClip("Alpha Clipping", Float) = 0.0 + + // Editmode props + [HideInInspector] _QueueOffset("Queue Offset", Float) = 0.0 + + [Toggle(_REFLECTIONS)] _Reflections("Reflections", Float) = 0.0 + [Toggle(_REFLECTION_PROBES)] _ReflectionProbes("Reflection Probes", Float) = 0.0 + _ReflectionSmoothness ("Smoothness", Range(0, 1)) = 0.5 + _ReflectionBlend ("Blend", Range(0, 1)) = 0.5 + + } + SubShader + { + Tags{"RenderType" = "Opaque" "RenderPipeline" = "UniversalRenderPipeline" "IgnoreProjector" = "True"} + LOD 300 + + Pass + { + Name "ForwardLit" + Tags{"LightMode" = "UniversalForward"} + + Blend[_SrcBlend][_DstBlend] + ZWrite[_ZWrite] + Cull[_Cull] + + HLSLPROGRAM + + #pragma vertex vert + #pragma fragment frag + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _FOG + #pragma shader_feature_local _VERTEX_COLOR + #pragma shader_feature_local _ADDITIONAL_LIGHTS_ENABLED + #pragma shader_feature_local _SPECULAR + #pragma shader_feature_local _ANISO_SPECULAR + #pragma shader_feature_local _ADDITIONAL_LIGHTS_SPECULAR + #pragma shader_feature_local _ENVIRONMENT_LIGHTING_ENABLED + #pragma shader_feature_local _SHADOW_MASK + + #pragma shader_feature_local_fragment _FRESNEL + #pragma shader_feature_local_fragment _EMISSION + #pragma shader_feature_local_fragment _RAMP_TRIPLE + #pragma shader_feature_local_fragment _RAMP_MAP + #pragma shader_feature_local_fragment _PURE_SHADOW_COLOR + + #pragma shader_feature_local_fragment _ALPHATEST_ON + #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON + + #pragma shader_feature_local_fragment _REFLECTIONS + #pragma shader_feature_local_fragment _REFLECTION_PROBES + + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN + #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS + #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS + #pragma multi_compile_fragment _ _SHADOWS_SOFT + #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING + #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + + + // Unity + #pragma multi_compile _ DIRLIGHTMAP_COMBINED + #pragma multi_compile _ LIGHTMAP_ON + #pragma multi_compile_fog + + #pragma multi_compile_instancing + + + #if defined(_ADDITIONAL_LIGHTS) && defined(_ADDITIONAL_LIGHTS_ENABLED) + #define TOON_ADDITIONAL_LIGHTS + #endif + + #if defined(_ADDITIONAL_LIGHTS_VERTEX) && defined(_ADDITIONAL_LIGHTS_ENABLED) + #define TOON_ADDITIONAL_LIGHTS_VERTEX + #endif + + #if defined(_ADDITIONAL_LIGHTS_SPECULAR) && defined(_SPECULAR) + #define TOON_ADDITIONAL_LIGHTS_SPECULAR + #endif + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "ShadowCaster" + Tags{"LightMode" = "ShadowCaster"} + + ZWrite On + ZTest LEqual + ColorMask 0 + Cull[_Cull] + + HLSLPROGRAM + #pragma target 2.0 + + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #pragma vertex ShadowPassVertex + #pragma fragment ShadowPassFragment + + #pragma multi_compile_instancing + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "Meta" + Tags{"LightMode" = "Meta"} + + Cull Off + + HLSLPROGRAM + + #pragma vertex MetaPassVertex + #pragma fragment MetaPassFragment + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _VERTEX_COLOR + #pragma shader_feature_local _ADDITIONAL_LIGHTS_ENABLED + #pragma shader_feature_local _SPECULAR + #pragma shader_feature_local _ANISO_SPECULAR + #pragma shader_feature_local _ADDITIONAL_LIGHTS_SPECULAR + #pragma shader_feature_local _ENVIRONMENT_LIGHTING_ENABLED + + #pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT + #pragma shader_feature_local_fragment _FRESNEL + #pragma shader_feature_local_fragment _EMISSION + #pragma shader_feature_local_fragment _RAMP_TRIPLE + #pragma multi_compile_local_fragment _ _RAMP_MAP _PURE_SHADOW_COLOR + + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "DepthOnly" + Tags{"LightMode" = "DepthOnly"} + + ZWrite On + ColorMask 0 + Cull[_Cull] + + HLSLPROGRAM + + #pragma target 2.0 + + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #pragma vertex DepthOnlyVertex + #pragma fragment DepthOnlyFragment + + #pragma multi_compile_instancing + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "DepthNormals" + Tags{"LightMode" = "DepthNormals"} + + ZWrite On + Cull[_Cull] + + HLSLPROGRAM + #pragma target 2.0 + + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #pragma vertex DepthNormalsVertex + #pragma fragment DepthNormalsFragment + + #pragma multi_compile_instancing + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" + ENDHLSL + } + } + + CustomEditor "DELTation.ToonShader.Editor.ToonShaderEditor" +} \ No newline at end of file diff --git a/Assets/Custom/My Toon Shader.shader.meta b/Assets/Custom/My Toon Shader.shader.meta new file mode 100644 index 0000000..6482b80 --- /dev/null +++ b/Assets/Custom/My Toon Shader.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 2e0a54ed13173b14898a9bf0e10092da +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom.meta new file mode 100644 index 0000000..b49ba8c --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9324fc89a44c4c1e92367b287a885ae5 +timeCreated: 1657084572 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs new file mode 100644 index 0000000..f0c440e --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs @@ -0,0 +1,64 @@ +using System; +using System.IO; +using DELTation.ToonShader.Custom; +using UnityEditor; +using UnityEngine; + +namespace DELTation.ToonShader.Editor.Custom +{ + [CustomEditor(typeof(CustomToonShader))] + public class CustomToonShaderEditor : UnityEditor.Editor + { + public override void OnInspectorGUI() + { + base.OnInspectorGUI(); + + var customToonShader = (CustomToonShader)target; + + EditorGUI.BeginDisabledGroup(true); + EditorGUILayout.ObjectField(nameof(customToonShader.Shader), customToonShader.Shader, typeof(Shader), false + ); + EditorGUI.EndDisabledGroup(); + + + if (GUILayout.Button("Generate")) + GenerateShaderFile(customToonShader); + } + + private void GenerateShaderFile(CustomToonShader customToonShader) + { + var path = AssetDatabase.GetAssetPath(customToonShader); + var assetName = Path.GetFileNameWithoutExtension(path); + var directoryName = Path.GetDirectoryName(path)!; + + var sourceShaderCode = + GenerateShaderSource(customToonShader, assetName); + var shaderAssetPath = customToonShader.Shader != null + ? AssetDatabase.GetAssetPath(customToonShader.Shader) + : Path.Combine(directoryName, assetName + ".shader"); + File.WriteAllText(Path.GetFullPath(shaderAssetPath), sourceShaderCode); + AssetDatabase.ImportAsset(shaderAssetPath); + + var newShader = AssetDatabase.LoadAssetAtPath(shaderAssetPath); + customToonShader.Shader = newShader; + EditorUtility.SetDirty(newShader); + EditorUtility.SetDirty(customToonShader); + AssetDatabase.SaveAssets(); + } + + private static string GenerateShaderSource(CustomToonShader customToonShader, string assetName) + { + var sourceShaderCodeLines = GetSourceShaderCode(customToonShader.SourceShader); + sourceShaderCodeLines[0] = $"Shader \"DELTation/Custom/{assetName}\""; + var sourceShaderCode = string.Join(Environment.NewLine, sourceShaderCodeLines); + return sourceShaderCode; + } + + private static string[] GetSourceShaderCode(Shader sourceShader) + { + var path = AssetDatabase.GetAssetPath(sourceShader); + var fullPath = Path.GetFullPath(path); + return File.ReadAllLines(fullPath); + } + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs.meta new file mode 100644 index 0000000..bb2b4a8 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 79a9c5be3c4b479a9f515ee4e4ef6c1f +timeCreated: 1657084677 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/DELTation.ToonShader.Editor.asmdef b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/DELTation.ToonShader.Editor.asmdef index 2eba5e7..c368c86 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/DELTation.ToonShader.Editor.asmdef +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/DELTation.ToonShader.Editor.asmdef @@ -1,7 +1,9 @@ { "name": "DELTation.ToonShader.Editor", "rootNamespace": "", - "references": [], + "references": [ + "GUID:ec5e0ba576b362a4e8e2dfc93e5426fc" + ], "includePlatforms": [ "Editor" ], diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/.gitignore b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/.gitignore deleted file mode 100644 index 7bd5816..0000000 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -TestAsmdef.asmdef -TestScript.cs -TestAsmdef.asmdef.meta -TestScript.cs.meta \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom.meta new file mode 100644 index 0000000..8d4916c --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: edd2004c5dd140d2b2ee3ee8c5cdec82 +timeCreated: 1657084454 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs new file mode 100644 index 0000000..48a0ce7 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace DELTation.ToonShader.Custom +{ + [CreateAssetMenu(menuName = "DELTation/Custom Toon Shader")] + public class CustomToonShader : ScriptableObject + { + [HideInInspector] + public Shader SourceShader; + [HideInInspector] + public Shader Shader; + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs.meta new file mode 100644 index 0000000..766b499 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9d6cd861481d4b55b3652478146d0b38 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - SourceShader: {fileID: 4800000, guid: 849dc4ff793a3f943ad21a3b6ee26456, type: 3} + - Shader: {instanceID: 0} + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/DELTation.ToonShader.asmdef b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/DELTation.ToonShader.asmdef new file mode 100644 index 0000000..edbca9f --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/DELTation.ToonShader.asmdef @@ -0,0 +1,16 @@ +{ + "name": "DELTation.ToonShader", + "rootNamespace": "", + "references": [ + "GUID:15fc0a57446b3144c949da3e2b9737a9" + ], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/DELTation.ToonShader.asmdef.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/DELTation.ToonShader.asmdef.meta new file mode 100644 index 0000000..5d8d749 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/DELTation.ToonShader.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: ec5e0ba576b362a4e8e2dfc93e5426fc +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TestAsmdef.csproj.DotSettings b/TestAsmdef.csproj.DotSettings new file mode 100644 index 0000000..05ec805 --- /dev/null +++ b/TestAsmdef.csproj.DotSettings @@ -0,0 +1,3 @@ + + True + True \ No newline at end of file From 9bcc5077dd2d8721a39dcaefda391d1a9e099f47 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 08:46:35 +0300 Subject: [PATCH 02/13] Add shader name property --- Assets/Custom/My Toon Shader.asset | 1 + Assets/Custom/My Toon Shader.shader | 2 +- DELTation.ToonShader.csproj.DotSettings | 3 +++ .../Editor/Custom/CustomToonShaderEditor.cs | 12 +++++++++--- .../ToonShader/Shaders/Custom/CustomToonShader.cs | 7 +++++++ 5 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 DELTation.ToonShader.csproj.DotSettings diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset index 929b8d2..0cf3145 100644 --- a/Assets/Custom/My Toon Shader.asset +++ b/Assets/Custom/My Toon Shader.asset @@ -14,3 +14,4 @@ MonoBehaviour: m_EditorClassIdentifier: SourceShader: {fileID: 4800000, guid: 849dc4ff793a3f943ad21a3b6ee26456, type: 3} Shader: {fileID: 4800000, guid: 2e0a54ed13173b14898a9bf0e10092da, type: 3} + ShaderName: Custom Toon Shader diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index e101107..1517eea 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -1,4 +1,4 @@ -Shader "DELTation/Custom/My Toon Shader" +Shader "DELTation/Custom/Custom Toon Shader" { Properties { diff --git a/DELTation.ToonShader.csproj.DotSettings b/DELTation.ToonShader.csproj.DotSettings new file mode 100644 index 0000000..05ec805 --- /dev/null +++ b/DELTation.ToonShader.csproj.DotSettings @@ -0,0 +1,3 @@ + + True + True \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs index f0c440e..5ba6f49 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs @@ -27,12 +27,18 @@ public override void OnInspectorGUI() private void GenerateShaderFile(CustomToonShader customToonShader) { + if (string.IsNullOrWhiteSpace(customToonShader.ShaderName)) + { + Debug.LogError("Shader name is empty."); + return; + } + var path = AssetDatabase.GetAssetPath(customToonShader); var assetName = Path.GetFileNameWithoutExtension(path); var directoryName = Path.GetDirectoryName(path)!; var sourceShaderCode = - GenerateShaderSource(customToonShader, assetName); + GenerateShaderSource(customToonShader, customToonShader.ShaderName); var shaderAssetPath = customToonShader.Shader != null ? AssetDatabase.GetAssetPath(customToonShader.Shader) : Path.Combine(directoryName, assetName + ".shader"); @@ -46,10 +52,10 @@ private void GenerateShaderFile(CustomToonShader customToonShader) AssetDatabase.SaveAssets(); } - private static string GenerateShaderSource(CustomToonShader customToonShader, string assetName) + private static string GenerateShaderSource(CustomToonShader customToonShader, string shaderName) { var sourceShaderCodeLines = GetSourceShaderCode(customToonShader.SourceShader); - sourceShaderCodeLines[0] = $"Shader \"DELTation/Custom/{assetName}\""; + sourceShaderCodeLines[0] = $"Shader \"DELTation/Custom/{shaderName}\""; var sourceShaderCode = string.Join(Environment.NewLine, sourceShaderCodeLines); return sourceShaderCode; } diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs index 48a0ce7..a4f8b8d 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs @@ -9,5 +9,12 @@ public class CustomToonShader : ScriptableObject public Shader SourceShader; [HideInInspector] public Shader Shader; + public string ShaderName; + + private void Reset() + { + if (string.IsNullOrEmpty(ShaderName)) + ShaderName = name; + } } } \ No newline at end of file From 9ac8d7c1b0f9968e713d0775260ed9cafa58a24d Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 08:58:34 +0300 Subject: [PATCH 03/13] Add basic properties support --- Assets/Custom/My Toon Shader.asset | 9 +++++ Assets/Custom/My Toon Shader.shader | 4 ++ .../Editor/Custom/CustomToonShaderEditor.cs | 38 +++++++++++++++++-- .../Shaders/Custom/CustomToonShader.cs | 13 ++++++- .../ToonShader/Shaders/ToonShader.shader | 2 + 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset index 0cf3145..8c53622 100644 --- a/Assets/Custom/My Toon Shader.asset +++ b/Assets/Custom/My Toon Shader.asset @@ -15,3 +15,12 @@ MonoBehaviour: SourceShader: {fileID: 4800000, guid: 849dc4ff793a3f943ad21a3b6ee26456, type: 3} Shader: {fileID: 4800000, guid: 2e0a54ed13173b14898a9bf0e10092da, type: 3} ShaderName: Custom Toon Shader + Properties: + - Name: _CustomTexture + DisplayName: Custom Texture + Type: 2D + DefaultValue: '"white" {}' + - Name: _CustomTint + DisplayName: Custom Tint + Type: Color + DefaultValue: (0.0, 0.0, 0.0, 0.0) diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index 1517eea..baf3a68 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -65,6 +65,10 @@ Shader "DELTation/Custom/Custom Toon Shader" _ReflectionSmoothness ("Smoothness", Range(0, 1)) = 0.5 _ReflectionBlend ("Blend", Range(0, 1)) = 0.5 + // Custom Properties Begin + _CustomTexture ("Custom Texture", 2D) = "white" {} + _CustomTint ("Custom Tint", Color) = (0.0, 0.0, 0.0, 0.0) + // Custom Properties End } SubShader { diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs index 5ba6f49..a5e8029 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using DELTation.ToonShader.Custom; using UnityEditor; using UnityEngine; @@ -54,12 +56,42 @@ private void GenerateShaderFile(CustomToonShader customToonShader) private static string GenerateShaderSource(CustomToonShader customToonShader, string shaderName) { - var sourceShaderCodeLines = GetSourceShaderCode(customToonShader.SourceShader); - sourceShaderCodeLines[0] = $"Shader \"DELTation/Custom/{shaderName}\""; - var sourceShaderCode = string.Join(Environment.NewLine, sourceShaderCodeLines); + var lines = GetSourceShaderCode(customToonShader.SourceShader); + SetShaderName(lines, shaderName); + + AddProperties(customToonShader, ref lines); + + var sourceShaderCode = string.Join(Environment.NewLine, lines); return sourceShaderCode; } + private static void SetShaderName(string[] lines, string shaderName) + { + lines[0] = $"Shader \"DELTation/Custom/{shaderName}\""; + } + + private static void AddProperties(CustomToonShader customToonShader, ref string[] lines) + { + var linesList = lines.ToList(); + var indexOfStart = linesList.FindIndex(line => line.Contains("// Custom Properties Begin")); + if (indexOfStart == -1) return; + var indexOfEnd = linesList.FindIndex(indexOfStart, line => line.Contains("// Custom Properties End")); + if (indexOfEnd == -1) return; + + var propertyIndent = new string(' ', 8); + var propertyLines = new List(); + + foreach (var shaderProperty in customToonShader.Properties) + { + propertyLines.Add( + $"{propertyIndent}{shaderProperty.Name} (\"{shaderProperty.DisplayName}\", {shaderProperty.Type}) = {shaderProperty.DefaultValue}" + ); + } + + linesList.InsertRange(indexOfStart + 1, propertyLines); + lines = linesList.ToArray(); + } + private static string[] GetSourceShaderCode(Shader sourceShader) { var path = AssetDatabase.GetAssetPath(sourceShader); diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs index a4f8b8d..739917d 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System; +using UnityEngine; namespace DELTation.ToonShader.Custom { @@ -10,11 +11,21 @@ public class CustomToonShader : ScriptableObject [HideInInspector] public Shader Shader; public string ShaderName; + public CustomToonShaderProperty[] Properties; private void Reset() { if (string.IsNullOrEmpty(ShaderName)) ShaderName = name; } + + [Serializable] + public class CustomToonShaderProperty + { + public string Name = "_Property"; + public string DisplayName = "Property"; + public string Type = "Float"; + public string DefaultValue = "0"; + } } } \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader index a90b94d..b98ca7d 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader @@ -65,6 +65,8 @@ _ReflectionSmoothness ("Smoothness", Range(0, 1)) = 0.5 _ReflectionBlend ("Blend", Range(0, 1)) = 0.5 + // Custom Properties Begin + // Custom Properties End } SubShader { From a0f9661124f5d6e8c6b19e433bf3bd3dbb13c0e5 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 09:05:08 +0300 Subject: [PATCH 04/13] Add custom properties drawer --- .../DELTation_Custom_Custom Toon Shader.mat | 86 +++++++++++++++++++ ...LTation_Custom_Custom Toon Shader.mat.meta | 8 ++ Assets/Custom/My Toon Shader.asset | 3 + Assets/Custom/My Toon Shader.shader | 4 +- .../Editor/Custom/CustomToonShaderEditor.cs | 5 +- .../ToonShader/Editor/ToonShaderEditor.cs | 23 +++++ .../Shaders/Custom/CustomToonShader.cs | 2 + 7 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 Assets/Custom/DELTation_Custom_Custom Toon Shader.mat create mode 100644 Assets/Custom/DELTation_Custom_Custom Toon Shader.mat.meta diff --git a/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat b/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat new file mode 100644 index 0000000..53adb94 --- /dev/null +++ b/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat @@ -0,0 +1,86 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: DELTation_Custom_Custom Toon Shader + m_Shader: {fileID: 4800000, guid: 2e0a54ed13173b14898a9bf0e10092da, type: 3} + m_ValidKeywords: + - _ADDITIONAL_LIGHTS_ENABLED + - _ENVIRONMENT_LIGHTING_ENABLED + - _FOG + m_InvalidKeywords: + - _ZWRITE_ON + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _CustomTexture: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _RampMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AdditionalLights: 1 + - _AdditionalLightsSpecular: 0 + - _AlphaClip: 0 + - _AnisoSpecular: 0 + - _Blend: 0 + - _Cull: 0 + - _Cutoff: 0.5 + - _DstBlend: 0 + - _Emission: 0 + - _EnvironmentLightingEnabled: 1 + - _Fog: 1 + - _Fresnel: 0 + - _FresnelSmoothness: 0.1 + - _FresnelThickness: 0.45 + - _PureShadowColor: 0 + - _QueueOffset: 0 + - _Ramp0: 0 + - _Ramp1: 0.5 + - _RampSmoothness: 0.005 + - _RampTriple: 0 + - _ReflectionBlend: 0.5 + - _ReflectionProbes: 0 + - _ReflectionSmoothness: 0.5 + - _Reflections: 0 + - _ShadowMask: 0 + - _Specular: 0 + - _SpecularExponent: 200 + - _SpecularSmoothness: 0.025 + - _SpecularThreshold: 0.8 + - _SrcBlend: 1 + - _Surface: 0 + - _UseRampMap: 0 + - _VertexColor: 0 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _CustomTint: {r: 0, g: 0, b: 0, a: 0} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 0} + - _FresnelColor: {r: 1, g: 1, b: 1, a: 1} + - _ShadowTint: {r: 0, g: 0, b: 0, a: 1} + - _SpecularColor: {r: 1, g: 1, b: 1, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat.meta b/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat.meta new file mode 100644 index 0000000..7356249 --- /dev/null +++ b/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 138b1a8c081c57942966abb7fe0508ae +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset index 8c53622..c376acf 100644 --- a/Assets/Custom/My Toon Shader.asset +++ b/Assets/Custom/My Toon Shader.asset @@ -20,7 +20,10 @@ MonoBehaviour: DisplayName: Custom Texture Type: 2D DefaultValue: '"white" {}' + Attributes: + - NoTilingOffset - Name: _CustomTint DisplayName: Custom Tint Type: Color DefaultValue: (0.0, 0.0, 0.0, 0.0) + Attributes: [] diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index baf3a68..4e83a7d 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -66,8 +66,8 @@ Shader "DELTation/Custom/Custom Toon Shader" _ReflectionBlend ("Blend", Range(0, 1)) = 0.5 // Custom Properties Begin - _CustomTexture ("Custom Texture", 2D) = "white" {} - _CustomTint ("Custom Tint", Color) = (0.0, 0.0, 0.0, 0.0) + [NoScaleOffset] [CustomProperty] _CustomTexture ("Custom Texture", 2D) = "white" {} + [CustomProperty] _CustomTint ("Custom Tint", Color) = (0.0, 0.0, 0.0, 0.0) // Custom Properties End } SubShader diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs index a5e8029..6d3c0c6 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs @@ -83,8 +83,11 @@ private static void AddProperties(CustomToonShader customToonShader, ref string[ foreach (var shaderProperty in customToonShader.Properties) { + var attributes = string.Join(' ', + shaderProperty.Attributes.Append("CustomProperty").Select(a => $"[{a}]") + ); propertyLines.Add( - $"{propertyIndent}{shaderProperty.Name} (\"{shaderProperty.DisplayName}\", {shaderProperty.Type}) = {shaderProperty.DefaultValue}" + $"{propertyIndent}{attributes} {shaderProperty.Name} (\"{shaderProperty.DisplayName}\", {shaderProperty.Type}) = {shaderProperty.DefaultValue}" ); } diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/ToonShaderEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/ToonShaderEditor.cs index 91d3b92..e1f02b4 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/ToonShaderEditor.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/ToonShaderEditor.cs @@ -33,6 +33,7 @@ protected override void DrawProperties(MaterialEditor materialEditor, MaterialPr { if (Foldout("Surface Options")) DrawSurfaceProperties(materialEditor, properties); + DrawCustomProperties(materialEditor, properties, material); if (Foldout("Color", true)) DrawColorProperties(materialEditor, properties); if (RampFoldout()) @@ -51,6 +52,28 @@ protected override void DrawProperties(MaterialEditor materialEditor, MaterialPr DrawMiscProperties(materialEditor, properties, material); } + private void DrawCustomProperties(MaterialEditor materialEditor, MaterialProperty[] properties, + Material material) + { + var shader = material.shader; + var customPropertyIndices = new List(); + + for (var i = 0; i < properties.Length; i++) + { + var attributes = shader.GetPropertyAttributes(i); + if (attributes.Contains("CustomProperty")) + customPropertyIndices.Add(i); + } + + if (customPropertyIndices.Count == 0) return; + + if (Foldout("Custom")) + foreach (var index in customPropertyIndices) + { + DrawProperty(materialEditor, properties, properties[index].name); + } + } + private static void DrawNormalMapProperties(MaterialEditor materialEditor, MaterialProperty[] properties, Material material) { diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs index 739917d..f69351a 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using UnityEngine; namespace DELTation.ToonShader.Custom @@ -26,6 +27,7 @@ public class CustomToonShaderProperty public string DisplayName = "Property"; public string Type = "Float"; public string DefaultValue = "0"; + public List Attributes = new(); } } } \ No newline at end of file From 74c65d678143470276361cd3ba0905c8352e6722 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 09:21:52 +0300 Subject: [PATCH 05/13] Add basic support for hooks --- Assets/Custom/My Toon Shader.asset | 3 ++ Assets/Custom/My Toon Shader.shader | 26 ++++++++- .../Editor/Custom/CustomToonShaderEditor.cs | 53 +++++++++++++++---- .../Shaders/Custom/CustomToonShader.cs | 11 +++- .../Custom/CustomToonShaderHookType.cs | 10 ++++ .../Custom/CustomToonShaderHookType.cs.meta | 3 ++ .../ToonShader/Shaders/ToonShader.shader | 11 +++- 7 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs.meta diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset index c376acf..9c4e7cb 100644 --- a/Assets/Custom/My Toon Shader.asset +++ b/Assets/Custom/My Toon Shader.asset @@ -27,3 +27,6 @@ MonoBehaviour: Type: Color DefaultValue: (0.0, 0.0, 0.0, 0.0) Attributes: [] + Hooks: + - Name: 0 + Code: float4 _CustomTint; diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index 4e83a7d..57f8b75 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -142,6 +142,11 @@ Shader "DELTation/Custom/Custom Toon Shader" #if defined(_ADDITIONAL_LIGHTS_SPECULAR) && defined(_SPECULAR) #define TOON_ADDITIONAL_LIGHTS_SPECULAR #endif + + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +float4 _CustomTint; \ + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" @@ -170,6 +175,11 @@ Shader "DELTation/Custom/Custom Toon Shader" #pragma multi_compile_instancing + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +float4 _CustomTint; \ + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" @@ -204,6 +214,11 @@ Shader "DELTation/Custom/Custom Toon Shader" #pragma shader_feature_local_fragment _ALPHATEST_ON + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +float4 _CustomTint; \ + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" @@ -229,7 +244,11 @@ Shader "DELTation/Custom/Custom Toon Shader" #pragma fragment DepthOnlyFragment #pragma multi_compile_instancing - + + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +float4 _CustomTint; \ + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" @@ -255,6 +274,11 @@ Shader "DELTation/Custom/Custom Toon Shader" #pragma multi_compile_instancing + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +float4 _CustomTint; \ + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" ENDHLSL diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs index 6d3c0c6..98fbfa1 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs @@ -11,6 +11,9 @@ namespace DELTation.ToonShader.Editor.Custom [CustomEditor(typeof(CustomToonShader))] public class CustomToonShaderEditor : UnityEditor.Editor { + private static readonly string HookIndent = new(' ', 12); + private static readonly string PropertyIndent = new(' ', 8); + public override void OnInspectorGUI() { base.OnInspectorGUI(); @@ -56,29 +59,28 @@ private void GenerateShaderFile(CustomToonShader customToonShader) private static string GenerateShaderSource(CustomToonShader customToonShader, string shaderName) { - var lines = GetSourceShaderCode(customToonShader.SourceShader); + var lines = GetSourceShaderCode(customToonShader.SourceShader).ToList(); SetShaderName(lines, shaderName); - AddProperties(customToonShader, ref lines); + AddProperties(customToonShader, lines); + AddHooks(customToonShader, lines); var sourceShaderCode = string.Join(Environment.NewLine, lines); return sourceShaderCode; } - private static void SetShaderName(string[] lines, string shaderName) + private static void SetShaderName(List lines, string shaderName) { lines[0] = $"Shader \"DELTation/Custom/{shaderName}\""; } - private static void AddProperties(CustomToonShader customToonShader, ref string[] lines) + private static void AddProperties(CustomToonShader customToonShader, List lines) { - var linesList = lines.ToList(); - var indexOfStart = linesList.FindIndex(line => line.Contains("// Custom Properties Begin")); + var indexOfStart = lines.FindIndex(line => line.Contains("// Custom Properties Begin")); if (indexOfStart == -1) return; - var indexOfEnd = linesList.FindIndex(indexOfStart, line => line.Contains("// Custom Properties End")); + var indexOfEnd = lines.FindIndex(indexOfStart, line => line.Contains("// Custom Properties End")); if (indexOfEnd == -1) return; - var propertyIndent = new string(' ', 8); var propertyLines = new List(); foreach (var shaderProperty in customToonShader.Properties) @@ -87,12 +89,41 @@ private static void AddProperties(CustomToonShader customToonShader, ref string[ shaderProperty.Attributes.Append("CustomProperty").Select(a => $"[{a}]") ); propertyLines.Add( - $"{propertyIndent}{attributes} {shaderProperty.Name} (\"{shaderProperty.DisplayName}\", {shaderProperty.Type}) = {shaderProperty.DefaultValue}" + $"{PropertyIndent}{attributes} {shaderProperty.Name} (\"{shaderProperty.DisplayName}\", {shaderProperty.Type}) = {shaderProperty.DefaultValue}" ); } - linesList.InsertRange(indexOfStart + 1, propertyLines); - lines = linesList.ToArray(); + lines.InsertRange(indexOfStart + 1, propertyLines); + } + + private static void AddHooks(CustomToonShader customToonShader, List lines) + { + foreach (var hook in customToonShader.Hooks) + { + var hookComment = $"// {hook.Name.ToString()}"; + var found = false; + + for (var index = 0; index < lines.Count; index++) + { + var line = lines[index]; + if (!line.Contains(hookComment)) continue; + + found = true; + var hookLines = new List { $"{HookIndent} #define {hook.Name} \\" }; + + var hookCodeLines = hook.Code.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + foreach (var hookCodeLine in hookCodeLines) + { + hookLines.Add(hookCodeLine + " \\"); + } + + hookLines.Add(string.Empty); + lines.InsertRange(index + 1, hookLines); + } + + if (!found) + Debug.LogWarning($"Hook comments for {hook.Name} not found."); + } } private static string[] GetSourceShaderCode(Shader sourceShader) diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs index f69351a..f88f649 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs @@ -12,7 +12,8 @@ public class CustomToonShader : ScriptableObject [HideInInspector] public Shader Shader; public string ShaderName; - public CustomToonShaderProperty[] Properties; + public List Properties = new(); + public List Hooks = new(); private void Reset() { @@ -29,5 +30,13 @@ public class CustomToonShaderProperty public string DefaultValue = "0"; public List Attributes = new(); } + + [Serializable] + public class CustomToonShaderHook + { + public CustomToonShaderHookType Name; + [TextArea] + public string Code = string.Empty; + } } } \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs new file mode 100644 index 0000000..141326e --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs @@ -0,0 +1,10 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global + +namespace DELTation.ToonShader.Custom +{ + public enum CustomToonShaderHookType + { + TOON_SHADER_HOOK_INPUT_BUFFER, + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs.meta new file mode 100644 index 0000000..1a060e7 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8269096a763b4601a150b924b5026ac9 +timeCreated: 1657087618 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader index b98ca7d..254f0b7 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader @@ -140,6 +140,8 @@ #if defined(_ADDITIONAL_LIGHTS_SPECULAR) && defined(_SPECULAR) #define TOON_ADDITIONAL_LIGHTS_SPECULAR #endif + + // TOON_SHADER_HOOK_INPUT_BUFFER #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" @@ -168,6 +170,8 @@ #pragma multi_compile_instancing + // TOON_SHADER_HOOK_INPUT_BUFFER + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" @@ -202,6 +206,8 @@ #pragma shader_feature_local_fragment _ALPHATEST_ON + // TOON_SHADER_HOOK_INPUT_BUFFER + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" @@ -227,7 +233,8 @@ #pragma fragment DepthOnlyFragment #pragma multi_compile_instancing - + + // TOON_SHADER_HOOK_INPUT_BUFFER #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" @@ -253,6 +260,8 @@ #pragma multi_compile_instancing + // TOON_SHADER_HOOK_INPUT_BUFFER + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" ENDHLSL From 3b50c4db32c3a9e8d9155998a1340817304a1dc0 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 09:23:26 +0300 Subject: [PATCH 06/13] Add support for TOON_SHADER_HOOK_INPUT_TEXTURES --- Assets/Custom/My Toon Shader.asset | 4 +++ Assets/Custom/My Toon Shader.shader | 25 +++++++++++++++++++ .../Custom/CustomToonShaderHookType.cs | 1 + .../ToonShader/Shaders/ToonShader.shader | 5 ++++ 4 files changed, 35 insertions(+) diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset index 9c4e7cb..0ab6ed3 100644 --- a/Assets/Custom/My Toon Shader.asset +++ b/Assets/Custom/My Toon Shader.asset @@ -30,3 +30,7 @@ MonoBehaviour: Hooks: - Name: 0 Code: float4 _CustomTint; + - Name: 1 + Code: 'TEXTURE2D(_CustomTexture); + + SAMPLER(sampler_CustomTexture);' diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index 57f8b75..9efc3a4 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -147,6 +147,11 @@ Shader "DELTation/Custom/Custom Toon Shader" #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_CustomTexture); \ +SAMPLER(sampler_CustomTexture); \ + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" @@ -179,6 +184,11 @@ float4 _CustomTint; \ #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_CustomTexture); \ +SAMPLER(sampler_CustomTexture); \ + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" @@ -218,6 +228,11 @@ float4 _CustomTint; \ #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_CustomTexture); \ +SAMPLER(sampler_CustomTexture); \ + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" @@ -249,6 +264,11 @@ float4 _CustomTint; \ #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_CustomTexture); \ +SAMPLER(sampler_CustomTexture); \ + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" @@ -278,6 +298,11 @@ float4 _CustomTint; \ #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_CustomTexture); \ +SAMPLER(sampler_CustomTexture); \ + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs index 141326e..72ac2fd 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs @@ -6,5 +6,6 @@ namespace DELTation.ToonShader.Custom public enum CustomToonShaderHookType { TOON_SHADER_HOOK_INPUT_BUFFER, + TOON_SHADER_HOOK_INPUT_TEXTURES, } } \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader index 254f0b7..43b48e4 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader @@ -142,6 +142,7 @@ #endif // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" @@ -171,6 +172,7 @@ #pragma multi_compile_instancing // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" @@ -207,6 +209,7 @@ #pragma shader_feature_local_fragment _ALPHATEST_ON // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" @@ -235,6 +238,7 @@ #pragma multi_compile_instancing // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" @@ -261,6 +265,7 @@ #pragma multi_compile_instancing // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" From 8b6ac3ad6372310a48383f5d1a486d3691bf2228 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 09:26:52 +0300 Subject: [PATCH 07/13] Add support for TOON_SHADER_HOOK_FRAGMENT_ALBEDO --- Assets/Custom/My Toon Shader.asset | 2 ++ Assets/Custom/My Toon Shader.shader | 25 ++++++++++++++++ .../Custom/CustomToonShaderHookType.cs | 1 + .../Shaders/Fur/ToonShaderFur.shader | 2 +- .../ToonShader/Shaders/ToonShader.shader | 10 +++++++ .../ToonShader/Shaders/ToonShaderAlbedo.hlsl | 30 +++++++++---------- 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset index 0ab6ed3..d70f567 100644 --- a/Assets/Custom/My Toon Shader.asset +++ b/Assets/Custom/My Toon Shader.asset @@ -34,3 +34,5 @@ MonoBehaviour: Code: 'TEXTURE2D(_CustomTexture); SAMPLER(sampler_CustomTexture);' + - Name: 2 + Code: albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index 9efc3a4..cf0d4f3 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -152,6 +152,11 @@ float4 _CustomTint; \ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" @@ -190,6 +195,11 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" @@ -234,6 +244,11 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" @@ -270,6 +285,11 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" @@ -304,6 +324,11 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" ENDHLSL diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs index 72ac2fd..6c1cc0a 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs @@ -7,5 +7,6 @@ public enum CustomToonShaderHookType { TOON_SHADER_HOOK_INPUT_BUFFER, TOON_SHADER_HOOK_INPUT_TEXTURES, + TOON_SHADER_HOOK_FRAGMENT_ALBEDO, } } \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader index 6e88326..38997d6 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader @@ -154,7 +154,7 @@ #include "./ToonShaderFurUtils.hlsl" #define TOON_SHADER_HOOK_VERTEX_INPUT fur_hook_vertex_input - #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO fur_hook_fragment_albedo + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO fur_hook_fragment_albedo(input.uv, albedo) #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl" ENDHLSL diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader index 43b48e4..ea3fd39 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader @@ -143,6 +143,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" @@ -174,6 +176,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" @@ -211,6 +215,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" @@ -240,6 +246,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" @@ -267,6 +275,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" ENDHLSL diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderAlbedo.hlsl b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderAlbedo.hlsl index d8bf44f..f3c216c 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderAlbedo.hlsl +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderAlbedo.hlsl @@ -6,20 +6,20 @@ inline half4 get_albedo_and_alpha_discard(const v2f input) { - // ReSharper disable once CppLocalVariableMayBeConst - half4 base_color = _BaseColor; - -#ifdef _VERTEX_COLOR - base_color.rgb *= input.vertexColor; -#endif - - half4 albedo = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * base_color; -#ifdef TOON_SHADER_HOOK_FRAGMENT_ALBEDO - TOON_SHADER_HOOK_FRAGMENT_ALBEDO(input.uv, albedo); -#endif - const half cutoff = _Cutoff; - AlphaDiscard(albedo.a, cutoff); - return albedo; + // ReSharper disable once CppLocalVariableMayBeConst + half4 base_color = _BaseColor; + + #ifdef _VERTEX_COLOR + base_color.rgb *= input.vertexColor; + #endif + + half4 albedo = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv) * base_color; + #ifdef TOON_SHADER_HOOK_FRAGMENT_ALBEDO + TOON_SHADER_HOOK_FRAGMENT_ALBEDO; + #endif + const half cutoff = _Cutoff; + AlphaDiscard(albedo.a, cutoff); + return albedo; } -#endif \ No newline at end of file +#endif From 63f21df13f316e50e9a9c2711bd672ac24dade78 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 09:31:54 +0300 Subject: [PATCH 08/13] Add support for TOON_SHADER_HOOK_VERTEX_INPUT --- .../DELTation_Custom_Custom Toon Shader.mat | 2 +- Assets/Custom/My Toon Shader.asset | 2 ++ Assets/Custom/My Toon Shader.shader | 20 +++++++++++++++++++ .../Custom/CustomToonShaderHookType.cs | 1 + .../Shaders/Fur/ToonShaderFur.shader | 2 +- .../ToonShader/Shaders/ToonShader.shader | 5 +++++ .../Shaders/ToonShaderForwardPass.hlsl | 2 +- 7 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat b/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat index 53adb94..c6127f7 100644 --- a/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat +++ b/Assets/Custom/DELTation_Custom_Custom Toon Shader.mat @@ -25,7 +25,7 @@ Material: serializedVersion: 3 m_TexEnvs: - _BaseMap: - m_Texture: {fileID: 0} + m_Texture: {fileID: 2800000, guid: 6f801cb597fd08f4ca3336f392517f0a, type: 3} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} - _BumpMap: diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset index d70f567..0057015 100644 --- a/Assets/Custom/My Toon Shader.asset +++ b/Assets/Custom/My Toon Shader.asset @@ -36,3 +36,5 @@ MonoBehaviour: SAMPLER(sampler_CustomTexture);' - Name: 2 Code: albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); + - Name: 3 + Code: input.uv += sin(_Time.y*10) * 0.01; diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index cf0d4f3..25de5cd 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -153,6 +153,10 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_VERTEX_INPUT + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +input.uv += sin(_Time.y*10) * 0.01; \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ @@ -195,6 +199,10 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_VERTEX_INPUT + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +input.uv += sin(_Time.y*10) * 0.01; \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ @@ -244,6 +252,10 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_VERTEX_INPUT + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +input.uv += sin(_Time.y*10) * 0.01; \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ @@ -285,6 +297,10 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_VERTEX_INPUT + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +input.uv += sin(_Time.y*10) * 0.01; \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ @@ -324,6 +340,10 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_VERTEX_INPUT + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +input.uv += sin(_Time.y*10) * 0.01; \ + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs index 6c1cc0a..b0c6574 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs @@ -8,5 +8,6 @@ public enum CustomToonShaderHookType TOON_SHADER_HOOK_INPUT_BUFFER, TOON_SHADER_HOOK_INPUT_TEXTURES, TOON_SHADER_HOOK_FRAGMENT_ALBEDO, + TOON_SHADER_HOOK_VERTEX_INPUT, } } \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader index 38997d6..dc521f5 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader @@ -153,7 +153,7 @@ #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "./ToonShaderFurUtils.hlsl" - #define TOON_SHADER_HOOK_VERTEX_INPUT fur_hook_vertex_input + #define TOON_SHADER_HOOK_VERTEX_INPUT fur_hook_vertex_input(input) #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO fur_hook_fragment_albedo(input.uv, albedo) #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl" diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader index ea3fd39..87dd20a 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader @@ -144,6 +144,7 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" @@ -176,6 +177,7 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" @@ -215,6 +217,7 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" @@ -246,6 +249,7 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" @@ -275,6 +279,7 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl index c12fa7b..c79b604 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl @@ -59,7 +59,7 @@ v2f vert(appdata input) UNITY_TRANSFER_INSTANCE_ID(input, output); #ifdef TOON_SHADER_HOOK_VERTEX_INPUT - TOON_SHADER_HOOK_VERTEX_INPUT(input); + TOON_SHADER_HOOK_VERTEX_INPUT; #endif const VertexPositionInputs vertex_position_inputs = GetVertexPositionInputs(input.positionOS.xyz); From a321093d21ddc98611e4a9ba422d8d0a4122fee2 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 09:35:28 +0300 Subject: [PATCH 09/13] Add support for TOON_SHADER_HOOK_APP_DATA --- Assets/Custom/My Toon Shader.shader | 10 ++++++++++ .../Shaders/Custom/CustomToonShaderHookType.cs | 1 + .../DELTation/ToonShader/Shaders/ToonShader.shader | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index 25de5cd..7560af6 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -153,6 +153,8 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT #define TOON_SHADER_HOOK_VERTEX_INPUT \ input.uv += sin(_Time.y*10) * 0.01; \ @@ -199,6 +201,8 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT #define TOON_SHADER_HOOK_VERTEX_INPUT \ input.uv += sin(_Time.y*10) * 0.01; \ @@ -252,6 +256,8 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT #define TOON_SHADER_HOOK_VERTEX_INPUT \ input.uv += sin(_Time.y*10) * 0.01; \ @@ -297,6 +303,8 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT #define TOON_SHADER_HOOK_VERTEX_INPUT \ input.uv += sin(_Time.y*10) * 0.01; \ @@ -340,6 +348,8 @@ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT #define TOON_SHADER_HOOK_VERTEX_INPUT \ input.uv += sin(_Time.y*10) * 0.01; \ diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs index b0c6574..264fcb2 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs @@ -9,5 +9,6 @@ public enum CustomToonShaderHookType TOON_SHADER_HOOK_INPUT_TEXTURES, TOON_SHADER_HOOK_FRAGMENT_ALBEDO, TOON_SHADER_HOOK_VERTEX_INPUT, + TOON_SHADER_HOOK_APP_DATA, } } \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader index 87dd20a..dd66d6f 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader @@ -144,6 +144,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO @@ -177,6 +179,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO @@ -217,6 +221,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO @@ -249,6 +255,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO @@ -279,6 +287,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_HOOK_APP_DATA + // TOON_SHADER_HOOK_VERTEX_INPUT // TOON_SHADER_HOOK_FRAGMENT_ALBEDO From be678ed0e360e0b1de087931ead76b3984d7df92 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 09:37:38 +0300 Subject: [PATCH 10/13] Add support for TOON_SHADER_CUSTOM_INSTANCING_BUFFER and TOON_SHADER_CUSTOM_CBUFFER --- .../Shaders/Custom/CustomToonShaderHookType.cs | 2 ++ .../DELTation/ToonShader/Shaders/ToonShader.shader | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs index 264fcb2..214cd93 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderHookType.cs @@ -10,5 +10,7 @@ public enum CustomToonShaderHookType TOON_SHADER_HOOK_FRAGMENT_ALBEDO, TOON_SHADER_HOOK_VERTEX_INPUT, TOON_SHADER_HOOK_APP_DATA, + TOON_SHADER_CUSTOM_INSTANCING_BUFFER, + TOON_SHADER_CUSTOM_CBUFFER, } } \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader index dd66d6f..4d7e632 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader @@ -143,6 +143,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA @@ -178,6 +180,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA @@ -220,6 +224,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA @@ -254,6 +260,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA @@ -286,6 +294,8 @@ // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA From 215fff0d90b496c90f1d23bfaa07bc28712f2e3c Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 09:47:21 +0300 Subject: [PATCH 11/13] Reimplement custom instanced shader with templates; add icon --- .../Graphics/Materials/Mike (Instanced).mat | 19 ++- .../Toon Shader Custom (Instanced).asset | 28 ++++ .../Toon Shader Custom (Instanced).asset.meta | 8 + ... => Toon Shader Custom (Instanced).shader} | 128 +++++++++++--- ...Toon Shader Custom (Instanced).shader.meta | 10 ++ .../ToonShaderCustomInstanced.shader.meta | 3 - .../ToonShaderCustomInstancedInput.hlsl | 39 ----- .../ToonShaderCustomInstancedInput.hlsl.meta | 3 - .../Editor/Custom/CustomToonShaderIcon.png | Bin 0 -> 13813 bytes .../Custom/CustomToonShaderIcon.png.meta | 158 ++++++++++++++++++ .../Shaders/Custom/CustomToonShader.cs.meta | 2 +- 11 files changed, 321 insertions(+), 77 deletions(-) create mode 100644 Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset create mode 100644 Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset.meta rename Assets/Graphics/Shaders/{ToonShaderCustomInstanced.shader => Toon Shader Custom (Instanced).shader} (70%) create mode 100644 Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader.meta delete mode 100644 Assets/Graphics/Shaders/ToonShaderCustomInstanced.shader.meta delete mode 100644 Assets/Graphics/Shaders/ToonShaderCustomInstancedInput.hlsl delete mode 100644 Assets/Graphics/Shaders/ToonShaderCustomInstancedInput.hlsl.meta create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderIcon.png create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderIcon.png.meta diff --git a/Assets/Graphics/Materials/Mike (Instanced).mat b/Assets/Graphics/Materials/Mike (Instanced).mat index b528452..037ad7f 100644 --- a/Assets/Graphics/Materials/Mike (Instanced).mat +++ b/Assets/Graphics/Materials/Mike (Instanced).mat @@ -2,15 +2,20 @@ %TAG !u! tag:unity3d.com,2011: --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Mike (Instanced) - m_Shader: {fileID: 4800000, guid: 9e8ca4a3b06e49acb94971a2fcd3f78a, type: 3} - m_ShaderKeywords: _ADDITIONAL_LIGHTS_ENABLED _FOG _MULTI_COMPILE_PROPERTIES _TOON_MAIN_LIGHT_VERTEX - _ZWRITE_ON + m_Shader: {fileID: 4800000, guid: 852509d381154f8429b33f5e5bf5eeed, type: 3} + m_ValidKeywords: + - _ADDITIONAL_LIGHTS_ENABLED + - _FOG + m_InvalidKeywords: + - _MULTI_COMPILE_PROPERTIES + - _TOON_MAIN_LIGHT_VERTEX + - _ZWRITE_ON m_LightmapFlags: 4 m_EnableInstancingVariants: 1 m_DoubleSidedGI: 0 @@ -84,6 +89,7 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: - _AdditionalLights: 1 - _AdditionalLightsMultiplier: 0.28 @@ -122,6 +128,10 @@ Material: - _RampSmoothness: 0.45 - _RampTriple: 0 - _ReceiveShadows: 1 + - _ReflectionBlend: 0.5 + - _ReflectionProbes: 0 + - _ReflectionSmoothness: 0.5 + - _Reflections: 0 - _ShadowMask: 0 - _Smoothness: 0.5 - _SmoothnessTextureChannel: 0 @@ -144,6 +154,7 @@ Material: - _ShadowTint: {r: 0.1525899, g: 0.17301533, b: 0.254717, a: 0.7647059} - _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1} - _SpecularColor: {r: 19.468573, g: 19.468573, b: 19.468573, a: 1} + - i_BaseColor: {r: 1, g: 1, b: 1, a: 1} m_BuildTextureStacks: [] --- !u!114 &7503274539402703127 MonoBehaviour: diff --git a/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset new file mode 100644 index 0000000..4753549 --- /dev/null +++ b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset @@ -0,0 +1,28 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9d6cd861481d4b55b3652478146d0b38, type: 3} + m_Name: Toon Shader Custom (Instanced) + m_EditorClassIdentifier: + SourceShader: {fileID: 4800000, guid: 849dc4ff793a3f943ad21a3b6ee26456, type: 3} + Shader: {fileID: 4800000, guid: 852509d381154f8429b33f5e5bf5eeed, type: 3} + ShaderName: Toon Shader (Instanced Color) + Properties: + - Name: i_BaseColor + DisplayName: Instanced Base Color + Type: Color + DefaultValue: (1, 1, 1, 1) + Attributes: [] + Hooks: + - Name: 5 + Code: TOON_SHADER_DEFINE_INSTANCED_PROP(half4, i_BaseColor) + - Name: 2 + Code: albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); diff --git a/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset.meta b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset.meta new file mode 100644 index 0000000..f136291 --- /dev/null +++ b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 53367eafb78867847b79a6439841214a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Graphics/Shaders/ToonShaderCustomInstanced.shader b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader similarity index 70% rename from Assets/Graphics/Shaders/ToonShaderCustomInstanced.shader rename to Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader index 7791cb3..68dd488 100644 --- a/Assets/Graphics/Shaders/ToonShaderCustomInstanced.shader +++ b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader @@ -1,19 +1,11 @@ -// Shader is mostly a copy of the ToonShader -Shader "DELTation/Toon Shader Custom Instanced" +Shader "DELTation/Custom/Toon Shader (Instanced Color)" { Properties { [MainTexture] _BaseMap ("Texture", 2D) = "white" {} - - // No longer main color, used only for Material Editor compatibility - _BaseColor ("Tint", Color) = (1.0, 1.0, 1.0) - - // New base color property, with white as default value to preview in Material Editor [MainColor] - i_BaseColor ("Tint", Color) = (1.0, 1.0, 1.0) - - + _BaseColor ("Tint", Color) = (1.0, 1.0, 1.0) _ShadowTint ("Shadow Tint", Color) = (0.0, 0.0, 0.0, 1.0) [Toggle(_PURE_SHADOW_COLOR)] _PureShadowColor ("Pure Shadow Color", Float) = 0 @@ -33,12 +25,12 @@ Shader "DELTation/Toon Shader Custom Instanced" [Toggle(_EMISSION)] _Emission ("Emission", Float) = 0 [HDR] _EmissionColor ("Emission Color", Color) = (0.0, 0.0, 0.0, 0.0) - [Toggle(_FRESNEL)] _Fresnel ("Rim", Float) = 1 + [Toggle(_FRESNEL)] _Fresnel ("Rim", Float) = 0 _FresnelThickness ("Rim Thickness", Range(0, 1)) = 0.45 _FresnelSmoothness ("Rim Smoothness", Range(0, 1)) = 0.1 [HDR] _FresnelColor ("Rim Color", Color) = (1.0, 1.0, 1.0, 1.0) - [Toggle(_SPECULAR)] _Specular ("Specular", Float) = 1 + [Toggle(_SPECULAR)] _Specular ("Specular", Float) = 0 [Toggle(_ANISO_SPECULAR)] _AnisoSpecular("Anisotropic Specular", Float) = 0 _SpecularThreshold ("Specular Threshold", Range(0, 1)) = 0.8 _SpecularExponent ("Specular Exponent", Range(0, 1000)) = 200 @@ -67,12 +59,15 @@ Shader "DELTation/Toon Shader Custom Instanced" // Editmode props [HideInInspector] _QueueOffset("Queue Offset", Float) = 0.0 - + [Toggle(_REFLECTIONS)] _Reflections("Reflections", Float) = 0.0 [Toggle(_REFLECTION_PROBES)] _ReflectionProbes("Reflection Probes", Float) = 0.0 _ReflectionSmoothness ("Smoothness", Range(0, 1)) = 0.5 _ReflectionBlend ("Blend", Range(0, 1)) = 0.5 + // Custom Properties Begin + [CustomProperty] i_BaseColor ("Instanced Base Color", Color) = (1, 1, 1, 1) + // Custom Properties End } SubShader { @@ -111,21 +106,21 @@ Shader "DELTation/Toon Shader Custom Instanced" #pragma shader_feature_local_fragment _ALPHATEST_ON #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON - + #pragma shader_feature_local_fragment _REFLECTIONS #pragma shader_feature_local_fragment _REFLECTION_PROBES - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS - #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE + #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS #pragma multi_compile_fragment _ _SHADOWS_SOFT #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION - #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING - #pragma multi_compile _ SHADOWS_SHADOWMASK #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION + #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING + #pragma multi_compile _ SHADOWS_SHADOWMASK + // Unity #pragma multi_compile _ DIRLIGHTMAP_COMBINED @@ -147,8 +142,23 @@ Shader "DELTation/Toon Shader Custom Instanced" #define TOON_ADDITIONAL_LIGHTS_SPECULAR #endif - // change default input #include to new one (the same in other passes) - #include "./ToonShaderCustomInstancedInput.hlsl" + // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + #define TOON_SHADER_CUSTOM_INSTANCING_BUFFER \ +TOON_SHADER_DEFINE_INSTANCED_PROP(half4, i_BaseColor) \ + + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); \ + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl" @@ -175,7 +185,23 @@ Shader "DELTation/Toon Shader Custom Instanced" #pragma multi_compile_instancing - #include "./ToonShaderCustomInstancedInput.hlsl" + // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + #define TOON_SHADER_CUSTOM_INSTANCING_BUFFER \ +TOON_SHADER_DEFINE_INSTANCED_PROP(half4, i_BaseColor) \ + + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); \ + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" ENDHLSL @@ -200,7 +226,8 @@ Shader "DELTation/Toon Shader Custom Instanced" #pragma shader_feature_local _ANISO_SPECULAR #pragma shader_feature_local _ADDITIONAL_LIGHTS_SPECULAR #pragma shader_feature_local _ENVIRONMENT_LIGHTING_ENABLED - + + #pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT #pragma shader_feature_local_fragment _FRESNEL #pragma shader_feature_local_fragment _EMISSION #pragma shader_feature_local_fragment _RAMP_TRIPLE @@ -208,7 +235,23 @@ Shader "DELTation/Toon Shader Custom Instanced" #pragma shader_feature_local_fragment _ALPHATEST_ON - #include "./ToonShaderCustomInstancedInput.hlsl" + // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + #define TOON_SHADER_CUSTOM_INSTANCING_BUFFER \ +TOON_SHADER_DEFINE_INSTANCED_PROP(half4, i_BaseColor) \ + + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); \ + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" ENDHLSL @@ -233,9 +276,24 @@ Shader "DELTation/Toon Shader Custom Instanced" #pragma fragment DepthOnlyFragment #pragma multi_compile_instancing - - #include "./ToonShaderCustomInstancedInput.hlsl" + // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + #define TOON_SHADER_CUSTOM_INSTANCING_BUFFER \ +TOON_SHADER_DEFINE_INSTANCED_PROP(half4, i_BaseColor) \ + + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); \ + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" ENDHLSL @@ -259,11 +317,27 @@ Shader "DELTation/Toon Shader Custom Instanced" #pragma multi_compile_instancing - #include "./ToonShaderCustomInstancedInput.hlsl" + // TOON_SHADER_HOOK_INPUT_BUFFER + // TOON_SHADER_HOOK_INPUT_TEXTURES + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + #define TOON_SHADER_CUSTOM_INSTANCING_BUFFER \ +TOON_SHADER_DEFINE_INSTANCED_PROP(half4, i_BaseColor) \ + + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); \ + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" ENDHLSL } } CustomEditor "DELTation.ToonShader.Editor.ToonShaderEditor" -} +} \ No newline at end of file diff --git a/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader.meta b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader.meta new file mode 100644 index 0000000..ba9b033 --- /dev/null +++ b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 852509d381154f8429b33f5e5bf5eeed +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Graphics/Shaders/ToonShaderCustomInstanced.shader.meta b/Assets/Graphics/Shaders/ToonShaderCustomInstanced.shader.meta deleted file mode 100644 index c5c1e42..0000000 --- a/Assets/Graphics/Shaders/ToonShaderCustomInstanced.shader.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9e8ca4a3b06e49acb94971a2fcd3f78a -timeCreated: 1641638388 \ No newline at end of file diff --git a/Assets/Graphics/Shaders/ToonShaderCustomInstancedInput.hlsl b/Assets/Graphics/Shaders/ToonShaderCustomInstancedInput.hlsl deleted file mode 100644 index 2d151a9..0000000 --- a/Assets/Graphics/Shaders/ToonShaderCustomInstancedInput.hlsl +++ /dev/null @@ -1,39 +0,0 @@ -#include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInstancing.hlsl" - -// define instanced property name -#define BASE_COLOR_INSTANCED i_BaseColor -// define the property in the instancing buffer -#define TOON_SHADER_CUSTOM_INSTANCING_BUFFER TOON_SHADER_DEFINE_INSTANCED_PROP(half4, BASE_COLOR_INSTANCED) -// define property accessor macro to ensure compability with the rest of the shader -#define _BaseColor TOON_SHADER_ACCESS_INSTANCED_PROP(BASE_COLOR_INSTANCED) - -// copy all old properties except _BaseColor -#define TOON_SHADER_CUSTOM_CBUFFER \ -float4 _BaseMap_ST; \ -half4 _ShadowTint; \ -\ -half _Ramp0; \ -half _Ramp1; \ -half _RampSmoothness; \ -half3 _EmissionColor; \ -half4 _FresnelColor; \ -half _FresnelSmoothness; \ -half _FresnelThickness; \ -half4 _SpecularColor; \ -half _SpecularSmoothness; \ -half _SpecularThreshold; \ -half _SpecularExponent; \ -half _Surface; \ -half _Cutoff; \ -half _ReflectionSmoothness; \ -half _ReflectionBlend; \ -\ -TEXTURE2D(_BaseMap); \ -SAMPLER(sampler_BaseMap); \ -TEXTURE2D(_RampMap); \ -SAMPLER(sampler_RampMap); \ -TEXTURE2D(_BumpMap); \ -SAMPLER(sampler_BumpMap); \ - -// include usual input file -#include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" \ No newline at end of file diff --git a/Assets/Graphics/Shaders/ToonShaderCustomInstancedInput.hlsl.meta b/Assets/Graphics/Shaders/ToonShaderCustomInstancedInput.hlsl.meta deleted file mode 100644 index 33bfdcc..0000000 --- a/Assets/Graphics/Shaders/ToonShaderCustomInstancedInput.hlsl.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 62fd96c4da3e4309af947a75783c036f -timeCreated: 1641640097 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderIcon.png b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..56c116aa4bc01cbdb606ad3e03ea8ffd4774158e GIT binary patch literal 13813 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 rRm_W^_lVUhz86uvZMKT5$S literal 0 HcmV?d00001 diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderIcon.png.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderIcon.png.meta new file mode 100644 index 0000000..43ff401 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderIcon.png.meta @@ -0,0 +1,158 @@ +fileFormatVersion: 2 +guid: e818b2690add0ff45b67d5d847578635 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMasterTextureLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 0 + wrapV: 0 + wrapW: 0 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs.meta index 766b499..660dd85 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs.meta +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs.meta @@ -7,7 +7,7 @@ MonoImporter: - SourceShader: {fileID: 4800000, guid: 849dc4ff793a3f943ad21a3b6ee26456, type: 3} - Shader: {instanceID: 0} executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 2800000, guid: e818b2690add0ff45b67d5d847578635, type: 3} userData: assetBundleName: assetBundleVariant: From b0c7a1e70bf901f19b455bf2fb0f385e35218cfb Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 10:06:08 +0300 Subject: [PATCH 12/13] Reimplement toon shader (fur) with a custom shader template --- .../Editor/Custom/CustomToonShaderEditor.cs | 11 +- .../Shaders/Custom/CustomToonShader.cs | 3 +- .../Shaders/Fur/ToonShaderFur.asset | 73 ++++ .../Shaders/Fur/ToonShaderFur.asset.meta | 8 + .../Shaders/Fur/ToonShaderFur.shader | 330 ++++++++++++++++-- .../Shaders/Fur/ToonShaderFur.shader.meta | 11 +- .../Shaders/Fur/ToonShaderFurUtils.hlsl | 23 -- .../Shaders/Fur/ToonShaderFurUtils.hlsl.meta | 3 - .../Shaders/Fur/ToonShaderFurUtils_Input.hlsl | 15 - .../Fur/ToonShaderFurUtils_Input.hlsl.meta | 3 - .../ToonShader/Shaders/ToonShader.shader | 8 + .../Shaders/ToonShaderDepthNormalsPass.hlsl | 6 +- .../Shaders/ToonShaderDepthOnlyPass.hlsl | 6 +- .../Shaders/ToonShaderMetaPass.hlsl | 21 +- .../Shaders/ToonShaderShadowCasterPass.hlsl | 6 +- 15 files changed, 437 insertions(+), 90 deletions(-) create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset.meta delete mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils.hlsl delete mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils.hlsl.meta delete mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils_Input.hlsl delete mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils_Input.hlsl.meta diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs index 98fbfa1..4e20071 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs @@ -109,7 +109,12 @@ private static void AddHooks(CustomToonShader customToonShader, List lin if (!line.Contains(hookComment)) continue; found = true; - var hookLines = new List { $"{HookIndent} #define {hook.Name} \\" }; + var hookLines = new List(); + + if (!string.IsNullOrWhiteSpace(hook.Condition)) + hookLines.Add("#if " + hook.Condition); + + hookLines.Add($"{HookIndent} #define {hook.Name} \\"); var hookCodeLines = hook.Code.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var hookCodeLine in hookCodeLines) @@ -118,6 +123,10 @@ private static void AddHooks(CustomToonShader customToonShader, List lin } hookLines.Add(string.Empty); + + if (!string.IsNullOrWhiteSpace(hook.Condition)) + hookLines.Add("#endif"); + lines.InsertRange(index + 1, hookLines); } diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs index f88f649..77550a6 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs @@ -35,7 +35,8 @@ public class CustomToonShaderProperty public class CustomToonShaderHook { public CustomToonShaderHookType Name; - [TextArea] + public string Condition; + [TextArea(4, 10)] public string Code = string.Empty; } } diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset new file mode 100644 index 0000000..b36f708 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset @@ -0,0 +1,73 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9d6cd861481d4b55b3652478146d0b38, type: 3} + m_Name: ToonShaderFur + m_EditorClassIdentifier: + SourceShader: {fileID: 4800000, guid: 849dc4ff793a3f943ad21a3b6ee26456, type: 3} + Shader: {fileID: 4800000, guid: 41ef1a853a684eb08c739807254fc8d6, type: 3} + ShaderName: Toon Shader (Fur) + Properties: + - Name: _FurLength + DisplayName: Fur Length + Type: Range(0, 1) + DefaultValue: 0.1 + Attributes: [] + - Name: _FurStep + DisplayName: Fur Step + Type: Range(0, 1) + DefaultValue: 0.1 + Attributes: [] + - Name: _FurNoise + DisplayName: Fur Noise + Type: 2D + DefaultValue: '"white" {}' + Attributes: [] + - Name: _FurMask + DisplayName: Fur Mask + Type: 2D + DefaultValue: '"white" {}' + Attributes: + - NoScaleOffset + Hooks: + - Name: 3 + Condition: defined(TOON_SHADER_FORWARD_PASS) + Code: 'const half fur_length = _FurLength; + + const half fur_step = _FurStep; + + input.positionOS.xyz + += input.normalOS * fur_length * fur_step;' + - Name: 0 + Condition: + Code: 'half _FurLength; + + half _FurStep; + + float4 _FurNoise_ST; ' + - Name: 1 + Condition: + Code: "TEXTURE2D(_FurNoise);\nSAMPLER(sampler_FurNoise);\nTEXTURE2D(_FurMask); + \nSAMPLER(sampler_FurMask);" + - Name: 2 + Condition: + Code: 'const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, input.uv).r; + + clip(mask + - 1); + + const float4 fur_noise_st = _FurNoise_ST; + + const half2 + noise_uv = apply_tiling_offset(input.uv, fur_noise_st); + + albedo.a *= + SAMPLE_TEXTURE2D(_FurNoise, sampler_FurNoise, noise_uv).r; ' diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset.meta new file mode 100644 index 0000000..060b898 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3f6cfcd6234b1d8438b51eccaf1d1714 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader index dc521f5..1ef24ba 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader @@ -1,4 +1,4 @@ -Shader "DELTation/Toon Shader (Fur)" +Shader "DELTation/Custom/Toon Shader (Fur)" { Properties { @@ -25,12 +25,12 @@ [Toggle(_EMISSION)] _Emission ("Emission", Float) = 0 [HDR] _EmissionColor ("Emission Color", Color) = (0.0, 0.0, 0.0, 0.0) - [Toggle(_FRESNEL)] _Fresnel ("Rim", Float) = 1 + [Toggle(_FRESNEL)] _Fresnel ("Rim", Float) = 0 _FresnelThickness ("Rim Thickness", Range(0, 1)) = 0.45 _FresnelSmoothness ("Rim Smoothness", Range(0, 1)) = 0.1 [HDR] _FresnelColor ("Rim Color", Color) = (1.0, 1.0, 1.0, 1.0) - [Toggle(_SPECULAR)] _Specular ("Specular", Float) = 1 + [Toggle(_SPECULAR)] _Specular ("Specular", Float) = 0 [Toggle(_ANISO_SPECULAR)] _AnisoSpecular("Anisotropic Specular", Float) = 0 _SpecularThreshold ("Specular Threshold", Range(0, 1)) = 0.8 _SpecularExponent ("Specular Exponent", Range(0, 1000)) = 200 @@ -60,17 +60,17 @@ // Editmode props [HideInInspector] _QueueOffset("Queue Offset", Float) = 0.0 - _FurLength ("Fur Length", Range(0, 1)) = 0.1 - _FurStep ("Fur Step", Range(0, 1)) = 0.1 - - _FurNoise ("Fur Noise", 2D) = "white" {} - [NoScaleOffset] - _FurMask ("Fur Mask", 2D) = "white" {} - [Toggle(_REFLECTIONS)] _Reflections("Reflections", Float) = 0.0 [Toggle(_REFLECTION_PROBES)] _ReflectionProbes("Reflection Probes", Float) = 0.0 _ReflectionSmoothness ("Smoothness", Range(0, 1)) = 0.5 _ReflectionBlend ("Blend", Range(0, 1)) = 0.5 + + // Custom Properties Begin + [CustomProperty] _FurLength ("Fur Length", Range(0, 1)) = 0.1 + [CustomProperty] _FurStep ("Fur Step", Range(0, 1)) = 0.1 + [CustomProperty] _FurNoise ("Fur Noise", 2D) = "white" {} + [NoScaleOffset] [CustomProperty] _FurMask ("Fur Mask", 2D) = "white" {} + // Custom Properties End } SubShader { @@ -99,16 +99,17 @@ #pragma shader_feature_local _ANISO_SPECULAR #pragma shader_feature_local _ADDITIONAL_LIGHTS_SPECULAR #pragma shader_feature_local _ENVIRONMENT_LIGHTING_ENABLED - - #pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT + #pragma shader_feature_local _SHADOW_MASK + #pragma shader_feature_local_fragment _FRESNEL #pragma shader_feature_local_fragment _EMISSION #pragma shader_feature_local_fragment _RAMP_TRIPLE - #pragma multi_compile_local_fragment _ _RAMP_MAP _PURE_SHADOW_COLOR + #pragma shader_feature_local_fragment _RAMP_MAP + #pragma shader_feature_local_fragment _PURE_SHADOW_COLOR #pragma shader_feature_local_fragment _ALPHATEST_ON #pragma shader_feature_local_fragment _ALPHAPREMULTIPLY_ON - + #pragma shader_feature_local_fragment _REFLECTIONS #pragma shader_feature_local_fragment _REFLECTION_PROBES @@ -143,23 +144,306 @@ #if defined(_ADDITIONAL_LIGHTS_SPECULAR) && defined(_SPECULAR) #define TOON_ADDITIONAL_LIGHTS_SPECULAR #endif + + #define TOON_SHADER_FORWARD_PASS + + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +half _FurLength; \ +half _FurStep; \ +float4 _FurNoise_ST; \ + + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_FurNoise); \ +SAMPLER(sampler_FurNoise); \ +TEXTURE2D(_FurMask); \ +SAMPLER(sampler_FurMask); \ + + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT +#if defined(TOON_SHADER_FORWARD_PASS) + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +const half fur_length = _FurLength; \ +const half fur_step = _FurStep; \ +input.positionOS.xyz += input.normalOS * fur_length * fur_step; \ + +#endif + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, input.uv).r; \ +clip(mask - 1); \ +const float4 fur_noise_st = _FurNoise_ST; \ +const half2 noise_uv = apply_tiling_offset(input.uv, fur_noise_st); \ +albedo.a *= SAMPLE_TEXTURE2D(_FurNoise, sampler_FurNoise, noise_uv).r; \ + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass_AppData.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl" + ENDHLSL + } + + Pass + { + Name "ShadowCaster" + Tags{"LightMode" = "ShadowCaster"} + + ZWrite On + ZTest LEqual + ColorMask 0 + Cull[_Cull] + + HLSLPROGRAM + #pragma target 2.0 + + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #pragma vertex ShadowPassVertex + #pragma fragment ShadowPassFragment + + #pragma multi_compile_instancing + + #define TOON_SHADER_SHADOW_CASTER_PASS + + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +half _FurLength; \ +half _FurStep; \ +float4 _FurNoise_ST; \ + + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_FurNoise); \ +SAMPLER(sampler_FurNoise); \ +TEXTURE2D(_FurMask); \ +SAMPLER(sampler_FurMask); \ + + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT +#if defined(TOON_SHADER_FORWARD_PASS) + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +const half fur_length = _FurLength; \ +const half fur_step = _FurStep; \ +input.positionOS.xyz += input.normalOS * fur_length * fur_step; \ + +#endif + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, input.uv).r; \ +clip(mask - 1); \ +const float4 fur_noise_st = _FurNoise_ST; \ +const half2 noise_uv = apply_tiling_offset(input.uv, fur_noise_st); \ +albedo.a *= SAMPLE_TEXTURE2D(_FurNoise, sampler_FurNoise, noise_uv).r; \ + - #include "./ToonShaderFurUtils_Input.hlsl" - #define TOON_SHADER_HOOK_INPUT_BUFFER TOON_SHADER_FUR_INPUT_BUFFER - #define TOON_SHADER_HOOK_INPUT_TEXTURES TOON_SHADER_FUR_INPUT_TEXTURES #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl" - #include "./ToonShaderFurUtils.hlsl" - #define TOON_SHADER_HOOK_VERTEX_INPUT fur_hook_vertex_input(input) - #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO fur_hook_fragment_albedo(input.uv, albedo) - #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderForwardPass.hlsl" + ENDHLSL + } + + Pass + { + Name "Meta" + Tags{"LightMode" = "Meta"} + + Cull Off + + HLSLPROGRAM + + #pragma vertex MetaPassVertex + #pragma fragment MetaPassFragment + + #pragma shader_feature_local _NORMALMAP + #pragma shader_feature_local _VERTEX_COLOR + #pragma shader_feature_local _ADDITIONAL_LIGHTS_ENABLED + #pragma shader_feature_local _SPECULAR + #pragma shader_feature_local _ANISO_SPECULAR + #pragma shader_feature_local _ADDITIONAL_LIGHTS_SPECULAR + #pragma shader_feature_local _ENVIRONMENT_LIGHTING_ENABLED + + #pragma shader_feature_local_fragment _SURFACE_TYPE_TRANSPARENT + #pragma shader_feature_local_fragment _FRESNEL + #pragma shader_feature_local_fragment _EMISSION + #pragma shader_feature_local_fragment _RAMP_TRIPLE + #pragma multi_compile_local_fragment _ _RAMP_MAP _PURE_SHADOW_COLOR + + #pragma shader_feature_local_fragment _ALPHATEST_ON + + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +half _FurLength; \ +half _FurStep; \ +float4 _FurNoise_ST; \ + + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_FurNoise); \ +SAMPLER(sampler_FurNoise); \ +TEXTURE2D(_FurMask); \ +SAMPLER(sampler_FurMask); \ + + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT +#if defined(TOON_SHADER_FORWARD_PASS) + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +const half fur_length = _FurLength; \ +const half fur_step = _FurStep; \ +input.positionOS.xyz += input.normalOS * fur_length * fur_step; \ + +#endif + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, input.uv).r; \ +clip(mask - 1); \ +const float4 fur_noise_st = _FurNoise_ST; \ +const half2 noise_uv = apply_tiling_offset(input.uv, fur_noise_st); \ +albedo.a *= SAMPLE_TEXTURE2D(_FurNoise, sampler_FurNoise, noise_uv).r; \ + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl" + + ENDHLSL + } + + Pass + { + Name "DepthOnly" + Tags{"LightMode" = "DepthOnly"} + + ZWrite On + ColorMask 0 + Cull[_Cull] + + HLSLPROGRAM + + #pragma target 2.0 + + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #pragma vertex DepthOnlyVertex + #pragma fragment DepthOnlyFragment + + #pragma multi_compile_instancing + + #define TOON_SHADER_DEPTH_ONLY_PASS + + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +half _FurLength; \ +half _FurStep; \ +float4 _FurNoise_ST; \ + + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_FurNoise); \ +SAMPLER(sampler_FurNoise); \ +TEXTURE2D(_FurMask); \ +SAMPLER(sampler_FurMask); \ + + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT +#if defined(TOON_SHADER_FORWARD_PASS) + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +const half fur_length = _FurLength; \ +const half fur_step = _FurStep; \ +input.positionOS.xyz += input.normalOS * fur_length * fur_step; \ + +#endif + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, input.uv).r; \ +clip(mask - 1); \ +const float4 fur_noise_st = _FurNoise_ST; \ +const half2 noise_uv = apply_tiling_offset(input.uv, fur_noise_st); \ +albedo.a *= SAMPLE_TEXTURE2D(_FurNoise, sampler_FurNoise, noise_uv).r; \ + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl" ENDHLSL } + + Pass + { + Name "DepthNormals" + Tags{"LightMode" = "DepthNormals"} + + ZWrite On + Cull[_Cull] + + HLSLPROGRAM + #pragma target 2.0 + + #pragma shader_feature_local_fragment _ALPHATEST_ON + + #pragma vertex DepthNormalsVertex + #pragma fragment DepthNormalsFragment + + #pragma multi_compile_instancing + + #define TOON_SHADER_DEPTH_NORMALS_PASS + + // TOON_SHADER_HOOK_INPUT_BUFFER + #define TOON_SHADER_HOOK_INPUT_BUFFER \ +half _FurLength; \ +half _FurStep; \ +float4 _FurNoise_ST; \ + + // TOON_SHADER_HOOK_INPUT_TEXTURES + #define TOON_SHADER_HOOK_INPUT_TEXTURES \ +TEXTURE2D(_FurNoise); \ +SAMPLER(sampler_FurNoise); \ +TEXTURE2D(_FurMask); \ +SAMPLER(sampler_FurMask); \ + + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER + + // TOON_SHADER_HOOK_APP_DATA + + // TOON_SHADER_HOOK_VERTEX_INPUT +#if defined(TOON_SHADER_FORWARD_PASS) + #define TOON_SHADER_HOOK_VERTEX_INPUT \ +const half fur_length = _FurLength; \ +const half fur_step = _FurStep; \ +input.positionOS.xyz += input.normalOS * fur_length * fur_step; \ + +#endif + // TOON_SHADER_HOOK_FRAGMENT_ALBEDO + #define TOON_SHADER_HOOK_FRAGMENT_ALBEDO \ +const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, input.uv).r; \ +clip(mask - 1); \ +const float4 fur_noise_st = _FurNoise_ST; \ +const half2 noise_uv = apply_tiling_offset(input.uv, fur_noise_st); \ +albedo.a *= SAMPLE_TEXTURE2D(_FurNoise, sampler_FurNoise, noise_uv).r; \ + + + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderInput.hlsl" + #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl" + ENDHLSL + } } - CustomEditor "DELTation.ToonShader.Editor.Fur.ToonShaderFurEditor" -} + CustomEditor "DELTation.ToonShader.Editor.ToonShaderEditor" +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader.meta index 4878564..3aa27d3 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader.meta +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader.meta @@ -1,3 +1,10 @@ -fileFormatVersion: 2 +fileFormatVersion: 2 guid: 41ef1a853a684eb08c739807254fc8d6 -timeCreated: 1638100303 \ No newline at end of file +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils.hlsl b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils.hlsl deleted file mode 100644 index aa5fb35..0000000 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils.hlsl +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef TOON_SHADER_FUR_UTILS -#define TOON_SHADER_FUR_UTILS - -#include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderUtils.hlsl" - -void fur_hook_vertex_input(inout appdata input) -{ - const half fur_length = _FurLength; - const half fur_step = _FurStep; - - input.positionOS.xyz += input.normalOS * fur_length * fur_step; -} - -void fur_hook_fragment_albedo(const half2 uv, inout half4 albedo) -{ - const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, uv).r; - clip(mask - 1); - const float4 fur_noise_st = _FurNoise_ST; - const half2 noise_uv = apply_tiling_offset(uv, fur_noise_st); - albedo.a *= SAMPLE_TEXTURE2D(_FurNoise, sampler_FurNoise, noise_uv).r; -} - -#endif \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils.hlsl.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils.hlsl.meta deleted file mode 100644 index 71f51aa..0000000 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils.hlsl.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 62b3f5cd9eb14704a82a77aa38ae8df8 -timeCreated: 1638100581 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils_Input.hlsl b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils_Input.hlsl deleted file mode 100644 index 2966c9b..0000000 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils_Input.hlsl +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef TOON_SHADER_FUR_UTILS_INPUT -#define TOON_SHADER_FUR_UTILS_INPUT - -#define TOON_SHADER_FUR_INPUT_BUFFER \ -half _FurLength; \ -half _FurStep; \ -float4 _FurNoise_ST; \ - -#define TOON_SHADER_FUR_INPUT_TEXTURES \ -TEXTURE2D(_FurNoise); \ -SAMPLER(sampler_FurNoise); \ -TEXTURE2D(_FurMask); \ -SAMPLER(sampler_FurMask); \ - -#endif diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils_Input.hlsl.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils_Input.hlsl.meta deleted file mode 100644 index f2c6793..0000000 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFurUtils_Input.hlsl.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 2c85d9b8ec284c69bfde2c7183a2ac0a -timeCreated: 1638101360 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader index 4d7e632..e952136 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShader.shader @@ -141,6 +141,8 @@ #define TOON_ADDITIONAL_LIGHTS_SPECULAR #endif + #define TOON_SHADER_FORWARD_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES // TOON_SHADER_CUSTOM_INSTANCING_BUFFER @@ -178,6 +180,8 @@ #pragma multi_compile_instancing + #define TOON_SHADER_SHADOW_CASTER_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES // TOON_SHADER_CUSTOM_INSTANCING_BUFFER @@ -258,6 +262,8 @@ #pragma multi_compile_instancing + #define TOON_SHADER_DEPTH_ONLY_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES // TOON_SHADER_CUSTOM_INSTANCING_BUFFER @@ -292,6 +298,8 @@ #pragma multi_compile_instancing + #define TOON_SHADER_DEPTH_NORMALS_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES // TOON_SHADER_CUSTOM_INSTANCING_BUFFER diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl index 4f83ddb..d7014e6 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass.hlsl @@ -1,5 +1,5 @@ -#ifndef TOON_SHADER_DEPTH_NORMALS_PASS -#define TOON_SHADER_DEPTH_NORMALS_PASS +#ifndef TOON_SHADER_DEPTH_NORMALS_PASS_INCLUDED +#define TOON_SHADER_DEPTH_NORMALS_PASS_INCLUDED #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthNormalsPass_AppData.hlsl" @@ -19,7 +19,7 @@ v2f DepthNormalsVertex(appdata input) UNITY_SETUP_INSTANCE_ID(input); #ifdef TOON_SHADER_HOOK_VERTEX_INPUT - TOON_SHADER_HOOK_VERTEX_INPUT(input); + TOON_SHADER_HOOK_VERTEX_INPUT; #endif output.position_cs = TransformObjectToHClip(input.positionOS.xyz); diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl index f95fa97..d1b44ac 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass.hlsl @@ -1,5 +1,5 @@ -#ifndef TOON_SHADER_DEPTH_ONLY_PASS -#define TOON_SHADER_DEPTH_ONLY_PASS +#ifndef TOON_SHADER_DEPTH_ONLY_PASS_INCLUDED +#define TOON_SHADER_DEPTH_ONLY_PASS_INCLUDED #include "Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderDepthOnlyPass_AppData.hlsl" @@ -18,7 +18,7 @@ v2f DepthOnlyVertex(appdata input) UNITY_SETUP_INSTANCE_ID(input); #ifdef TOON_SHADER_HOOK_VERTEX_INPUT - TOON_SHADER_HOOK_VERTEX_INPUT(input); + TOON_SHADER_HOOK_VERTEX_INPUT; #endif output.position_cs = TransformObjectToHClip(input.positionOS.xyz); diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl index 57a4243..a767cd6 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderMetaPass.hlsl @@ -1,16 +1,16 @@ -#ifndef TOON_SHADER_META_PASS -#define TOON_SHADER_META_PASS +#ifndef TOON_SHADER_META_PASS_INCLUDED +#define TOON_SHADER_META_PASS_INCLUDED #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl" #include "./ToonShaderUtils.hlsl" struct appdata { - float4 positionOS : POSITION; - float3 normalOS : NORMAL; - float2 uv0 : TEXCOORD0; - float2 uv1 : TEXCOORD1; - float2 uv2 : TEXCOORD2; + float4 positionOS : POSITION; + float3 normalOS : NORMAL; + float2 uv0 : TEXCOORD0; + float2 uv1 : TEXCOORD1; + float2 uv2 : TEXCOORD2; #ifdef _VERTEX_COLOR half3 vertexColor : COLOR; @@ -19,8 +19,8 @@ struct appdata struct v2f { - float4 positionCS : SV_POSITION; - float2 uv : TEXCOORD0; + float4 positionCS : SV_POSITION; + float2 uv : TEXCOORD0; #ifdef _VERTEX_COLOR half3 vertexColor : COLOR; @@ -32,7 +32,8 @@ struct v2f v2f MetaPassVertex(appdata input) { v2f output; - output.positionCS = MetaVertexPosition(input.positionOS, input.uv1, input.uv2, unity_LightmapST, unity_DynamicLightmapST); + output.positionCS = MetaVertexPosition(input.positionOS, input.uv1, input.uv2, unity_LightmapST, + unity_DynamicLightmapST); output.uv = apply_tiling_offset(input.uv0, _BaseMap_ST); #ifdef _VERTEX_COLOR output.vertexColor = input.vertexColor; diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl index 3299def..ed70961 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/ToonShaderShadowCasterPass.hlsl @@ -1,5 +1,5 @@ -#ifndef TOON_SHADER_SHADOW_CASTER_PASS -#define TOON_SHADER_SHADOW_CASTER_PASS +#ifndef TOON_SHADER_SHADOW_CASTER_PASS_INCLUDED +#define TOON_SHADER_SHADOW_CASTER_PASS_INCLUDED #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl" @@ -40,7 +40,7 @@ v2f ShadowPassVertex(appdata input) UNITY_SETUP_INSTANCE_ID(input); #ifdef TOON_SHADER_HOOK_VERTEX_INPUT - TOON_SHADER_HOOK_VERTEX_INPUT(input); + TOON_SHADER_HOOK_VERTEX_INPUT; #endif output.position_cs = get_shadow_position_h_clip(input); From ec23b3a8601c7a75322742bed862074a35a94bc7 Mon Sep 17 00:00:00 2001 From: Vladislav Kantaev Date: Wed, 6 Jul 2022 16:56:35 +0300 Subject: [PATCH 13/13] Implement proper typed property types --- Assets/Custom/My Toon Shader.asset | 28 +++- Assets/Custom/My Toon Shader.shader | 20 ++- .../Toon Shader Custom (Instanced).asset | 14 +- .../Toon Shader Custom (Instanced).shader | 10 +- .../Editor/Custom/CustomToonShaderEditor.cs | 33 +++-- ...nShaderPropertyTypedValuePropertyDrawer.cs | 120 ++++++++++++++++++ ...erPropertyTypedValuePropertyDrawer.cs.meta | 3 + .../DELTation/ToonShader/Editor/Fur.meta | 3 - .../Editor/Fur/ToonShaderFurEditor.cs | 22 ---- .../Editor/Fur/ToonShaderFurEditor.cs.meta | 3 - .../Shaders/Custom/CustomToonShader.cs | 3 +- .../Custom/CustomToonShaderDefaultTexture.cs | 14 ++ .../CustomToonShaderDefaultTexture.cs.meta | 3 + .../Custom/CustomToonShaderPropertyType.cs | 16 +++ .../CustomToonShaderPropertyType.cs.meta | 3 + .../CustomToonShaderPropertyTypedValue.cs | 75 +++++++++++ ...CustomToonShaderPropertyTypedValue.cs.meta | 3 + .../Shaders/Fur/ToonShaderFur.asset | 62 ++++++--- .../Shaders/Fur/ToonShaderFur.shader | 4 +- 19 files changed, 376 insertions(+), 63 deletions(-) create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderPropertyTypedValuePropertyDrawer.cs create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderPropertyTypedValuePropertyDrawer.cs.meta delete mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur.meta delete mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur/ToonShaderFurEditor.cs delete mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur/ToonShaderFurEditor.cs.meta create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderDefaultTexture.cs create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderDefaultTexture.cs.meta create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyType.cs create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyType.cs.meta create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyTypedValue.cs create mode 100644 Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyTypedValue.cs.meta diff --git a/Assets/Custom/My Toon Shader.asset b/Assets/Custom/My Toon Shader.asset index 0057015..d89fbd5 100644 --- a/Assets/Custom/My Toon Shader.asset +++ b/Assets/Custom/My Toon Shader.asset @@ -18,23 +18,43 @@ MonoBehaviour: Properties: - Name: _CustomTexture DisplayName: Custom Texture - Type: 2D - DefaultValue: '"white" {}' + TypedValue: + Type: 2 + IntegerValue: 0 + FloatValue: 0 + TextureValue: 1 + RangeMinValue: 0 + RangeMaxValue: 0 + RangeValue: 0 + VectorValue: {x: 0, y: 0, z: 0, w: 0} + ColorValue: {r: 0, g: 0, b: 0, a: 0} Attributes: - NoTilingOffset - Name: _CustomTint DisplayName: Custom Tint - Type: Color - DefaultValue: (0.0, 0.0, 0.0, 0.0) + TypedValue: + Type: 7 + IntegerValue: 0 + FloatValue: 0 + TextureValue: 0 + RangeMinValue: 0 + RangeMaxValue: 0 + RangeValue: 0 + VectorValue: {x: 0, y: 0, z: 0, w: 0} + ColorValue: {r: 1, g: 1, b: 1, a: 1} Attributes: [] Hooks: - Name: 0 + Condition: Code: float4 _CustomTint; - Name: 1 + Condition: Code: 'TEXTURE2D(_CustomTexture); SAMPLER(sampler_CustomTexture);' - Name: 2 + Condition: Code: albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); - Name: 3 + Condition: Code: input.uv += sin(_Time.y*10) * 0.01; diff --git a/Assets/Custom/My Toon Shader.shader b/Assets/Custom/My Toon Shader.shader index 7560af6..be311c4 100644 --- a/Assets/Custom/My Toon Shader.shader +++ b/Assets/Custom/My Toon Shader.shader @@ -67,7 +67,7 @@ Shader "DELTation/Custom/Custom Toon Shader" // Custom Properties Begin [NoScaleOffset] [CustomProperty] _CustomTexture ("Custom Texture", 2D) = "white" {} - [CustomProperty] _CustomTint ("Custom Tint", Color) = (0.0, 0.0, 0.0, 0.0) + [CustomProperty] _CustomTint ("Custom Tint", Color) = (1,1,1,1) // Custom Properties End } SubShader @@ -143,6 +143,8 @@ Shader "DELTation/Custom/Custom Toon Shader" #define TOON_ADDITIONAL_LIGHTS_SPECULAR #endif + #define TOON_SHADER_FORWARD_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ @@ -152,6 +154,8 @@ float4 _CustomTint; \ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA @@ -191,6 +195,8 @@ albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ #pragma multi_compile_instancing + #define TOON_SHADER_SHADOW_CASTER_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ @@ -200,6 +206,8 @@ float4 _CustomTint; \ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA @@ -255,6 +263,8 @@ float4 _CustomTint; \ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA @@ -293,6 +303,8 @@ albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ #pragma multi_compile_instancing + #define TOON_SHADER_DEPTH_ONLY_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ @@ -302,6 +314,8 @@ float4 _CustomTint; \ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA @@ -338,6 +352,8 @@ albedo *= SAMPLE_TEXTURE2D(_CustomTexture, sampler_CustomTexture, input.uv); \ #pragma multi_compile_instancing + #define TOON_SHADER_DEPTH_NORMALS_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER #define TOON_SHADER_HOOK_INPUT_BUFFER \ float4 _CustomTint; \ @@ -347,6 +363,8 @@ float4 _CustomTint; \ TEXTURE2D(_CustomTexture); \ SAMPLER(sampler_CustomTexture); \ + // TOON_SHADER_CUSTOM_INSTANCING_BUFFER + // TOON_SHADER_CUSTOM_CBUFFER // TOON_SHADER_HOOK_APP_DATA diff --git a/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset index 4753549..afdbfec 100644 --- a/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset +++ b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).asset @@ -18,11 +18,21 @@ MonoBehaviour: Properties: - Name: i_BaseColor DisplayName: Instanced Base Color - Type: Color - DefaultValue: (1, 1, 1, 1) + TypedValue: + Type: 7 + IntegerValue: 0 + FloatValue: 0 + TextureValue: 0 + RangeMinValue: 0 + RangeMaxValue: 0 + RangeValue: 0 + VectorValue: {x: 1, y: 1, z: 1, w: 1} + ColorValue: {r: 1, g: 1, b: 1, a: 1} Attributes: [] Hooks: - Name: 5 + Condition: Code: TOON_SHADER_DEFINE_INSTANCED_PROP(half4, i_BaseColor) - Name: 2 + Condition: Code: albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); diff --git a/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader index 68dd488..e87985c 100644 --- a/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader +++ b/Assets/Graphics/Shaders/Toon Shader Custom (Instanced).shader @@ -66,7 +66,7 @@ Shader "DELTation/Custom/Toon Shader (Instanced Color)" _ReflectionBlend ("Blend", Range(0, 1)) = 0.5 // Custom Properties Begin - [CustomProperty] i_BaseColor ("Instanced Base Color", Color) = (1, 1, 1, 1) + [CustomProperty] i_BaseColor ("Instanced Base Color", Color) = (1,1,1,1) // Custom Properties End } SubShader @@ -142,6 +142,8 @@ Shader "DELTation/Custom/Toon Shader (Instanced Color)" #define TOON_ADDITIONAL_LIGHTS_SPECULAR #endif + #define TOON_SHADER_FORWARD_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES // TOON_SHADER_CUSTOM_INSTANCING_BUFFER @@ -185,6 +187,8 @@ albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); \ #pragma multi_compile_instancing + #define TOON_SHADER_SHADOW_CASTER_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES // TOON_SHADER_CUSTOM_INSTANCING_BUFFER @@ -277,6 +281,8 @@ albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); \ #pragma multi_compile_instancing + #define TOON_SHADER_DEPTH_ONLY_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES // TOON_SHADER_CUSTOM_INSTANCING_BUFFER @@ -317,6 +323,8 @@ albedo *= TOON_SHADER_ACCESS_INSTANCED_PROP(i_BaseColor); \ #pragma multi_compile_instancing + #define TOON_SHADER_DEPTH_NORMALS_PASS + // TOON_SHADER_HOOK_INPUT_BUFFER // TOON_SHADER_HOOK_INPUT_TEXTURES // TOON_SHADER_CUSTOM_INSTANCING_BUFFER diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs index 4e20071..be11957 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderEditor.cs @@ -4,7 +4,9 @@ using System.Linq; using DELTation.ToonShader.Custom; using UnityEditor; +using UnityEditor.UIElements; using UnityEngine; +using UnityEngine.UIElements; namespace DELTation.ToonShader.Editor.Custom { @@ -14,20 +16,33 @@ public class CustomToonShaderEditor : UnityEditor.Editor private static readonly string HookIndent = new(' ', 12); private static readonly string PropertyIndent = new(' ', 8); - public override void OnInspectorGUI() + public override VisualElement CreateInspectorGUI() { - base.OnInspectorGUI(); + var container = new VisualElement(); + InspectorElement.FillDefaultInspector(container, serializedObject, this); var customToonShader = (CustomToonShader)target; - EditorGUI.BeginDisabledGroup(true); - EditorGUILayout.ObjectField(nameof(customToonShader.Shader), customToonShader.Shader, typeof(Shader), false + var shaderRoot = new VisualElement(); + shaderRoot.Add(new ObjectField + { + value = customToonShader.Shader, + objectType = typeof(Shader), + allowSceneObjects = false, + label = nameof(customToonShader.Shader), + } ); - EditorGUI.EndDisabledGroup(); + container.Add(shaderRoot); + shaderRoot.SetEnabled(false); + var button = new Button + { + text = "Generate", + }; + button.clicked += () => GenerateShaderFile(customToonShader); + container.Add(button); - if (GUILayout.Button("Generate")) - GenerateShaderFile(customToonShader); + return container; } private void GenerateShaderFile(CustomToonShader customToonShader) @@ -88,8 +103,10 @@ private static void AddProperties(CustomToonShader customToonShader, List $"[{a}]") ); + var typeString = shaderProperty.TypedValue.GetTypeString(); + var valueString = shaderProperty.TypedValue.GetValueString(); propertyLines.Add( - $"{PropertyIndent}{attributes} {shaderProperty.Name} (\"{shaderProperty.DisplayName}\", {shaderProperty.Type}) = {shaderProperty.DefaultValue}" + $"{PropertyIndent}{attributes} {shaderProperty.Name} (\"{shaderProperty.DisplayName}\", {typeString}) = {valueString}" ); } diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderPropertyTypedValuePropertyDrawer.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderPropertyTypedValuePropertyDrawer.cs new file mode 100644 index 0000000..4b9db9a --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderPropertyTypedValuePropertyDrawer.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using DELTation.ToonShader.Custom; +using UnityEditor; +using UnityEditor.UIElements; +using UnityEngine.UIElements; +using TargetType = DELTation.ToonShader.Custom.CustomToonShaderPropertyTypedValue; + +namespace DELTation.ToonShader.Editor.Custom +{ + [CustomPropertyDrawer(typeof(TargetType))] + public class CustomToonShaderPropertyTypedValuePropertyDrawer : PropertyDrawer + { + public override VisualElement CreatePropertyGUI(SerializedProperty property) + { + var container = new VisualElement(); + + var valueElements = new Dictionary(); + + + void RefreshVisibility() + { + var type = (CustomToonShaderPropertyType)property.FindPropertyRelative(nameof(TargetType.Type)) + .enumValueFlag; + + foreach (var keyValuePair in valueElements) + { + var valueElement = valueElements[keyValuePair.Key]; + var style = valueElement.style; + style.display = keyValuePair.Key == type ? DisplayStyle.Flex : DisplayStyle.None; + } + + container.MarkDirtyRepaint(); + } + + RenderContainer(property, container, RefreshVisibility); + + valueElements.Clear(); + + foreach (CustomToonShaderPropertyType type in Enum.GetValues(typeof(CustomToonShaderPropertyType))) + { + var visualElement = CreateValueElementOrDefault(property, type); + if (visualElement == null) continue; + + valueElements.Add(type, visualElement); + container.Add(visualElement); + } + + RefreshVisibility(); + + return container; + } + + private static void RenderContainer(SerializedProperty property, VisualElement container, Action onChanged) + { + var typeProperty = property.FindPropertyRelative(nameof(TargetType.Type)); + var typeField = new PropertyField(typeProperty); + typeField.RegisterValueChangeCallback(_ => onChanged()); + container.Add(typeField); + + var valueContainer = new VisualElement(); + container.Add(valueContainer); + } + + private VisualElement CreateValueElementOrDefault(SerializedProperty property, + CustomToonShaderPropertyType type) + { + const string valueLabel = "Value"; + return type switch + { + CustomToonShaderPropertyType.Integer => new PropertyField( + property.FindPropertyRelative(nameof(TargetType.IntegerValue)), + valueLabel + ), + CustomToonShaderPropertyType.Float => new PropertyField( + property.FindPropertyRelative(nameof(TargetType.FloatValue)), + valueLabel + ), + CustomToonShaderPropertyType.Texture2D => new PropertyField( + property.FindPropertyRelative(nameof(TargetType.TextureValue)), + valueLabel + ), + CustomToonShaderPropertyType.Texture2DArray => null, + CustomToonShaderPropertyType.Texture3D => null, + CustomToonShaderPropertyType.Cubemap => null, + CustomToonShaderPropertyType.CubemapArray => null, + CustomToonShaderPropertyType.Color => new PropertyField( + property.FindPropertyRelative(nameof(TargetType.ColorValue)), + valueLabel + ), + CustomToonShaderPropertyType.Vector => new PropertyField( + property.FindPropertyRelative(nameof(TargetType.VectorValue)), + valueLabel + ), + CustomToonShaderPropertyType.Range => CreateRangeValueElement(property), + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), + }; + } + + private static VisualElement CreateRangeValueElement(SerializedProperty property) + { + var rangeValueField = new VisualElement(); + rangeValueField.Add(new PropertyField( + property.FindPropertyRelative(nameof(TargetType.RangeMinValue)), + "Min Value" + ) + ); + rangeValueField.Add(new PropertyField( + property.FindPropertyRelative(nameof(TargetType.RangeMaxValue)), + "Max Value" + ) + ); + rangeValueField.Add(new PropertyField( + property.FindPropertyRelative(nameof(TargetType.RangeValue)) + ) + ); + return rangeValueField; + } + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderPropertyTypedValuePropertyDrawer.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderPropertyTypedValuePropertyDrawer.cs.meta new file mode 100644 index 0000000..d135ac7 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Custom/CustomToonShaderPropertyTypedValuePropertyDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 106b5e3159ba4c2fa1eb3b538abca1b1 +timeCreated: 1657091716 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur.meta deleted file mode 100644 index 73f20e2..0000000 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 961656329f1d4117ac9167fbcd49f8db -timeCreated: 1638101447 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur/ToonShaderFurEditor.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur/ToonShaderFurEditor.cs deleted file mode 100644 index 8827d1b..0000000 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur/ToonShaderFurEditor.cs +++ /dev/null @@ -1,22 +0,0 @@ -using JetBrains.Annotations; -using UnityEditor; -using UnityEngine; - -namespace DELTation.ToonShader.Editor.Fur -{ - [UsedImplicitly] - public class ToonShaderFurEditor : ToonShaderEditor - { - protected override void DrawProperties(MaterialEditor materialEditor, MaterialProperty[] properties, - Material material) - { - base.DrawProperties(materialEditor, properties, material); - if (!Foldout("Fur")) return; - - DrawProperty(materialEditor, properties, "_FurLength"); - DrawProperty(materialEditor, properties, "_FurStep"); - DrawProperty(materialEditor, properties, "_FurNoise"); - DrawProperty(materialEditor, properties, "_FurMask"); - } - } -} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur/ToonShaderFurEditor.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur/ToonShaderFurEditor.cs.meta deleted file mode 100644 index d4e6139..0000000 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Editor/Fur/ToonShaderFurEditor.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 63830e1b8278494a891430ac44bba0e3 -timeCreated: 1638101454 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs index 77550a6..59314be 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShader.cs @@ -26,8 +26,7 @@ public class CustomToonShaderProperty { public string Name = "_Property"; public string DisplayName = "Property"; - public string Type = "Float"; - public string DefaultValue = "0"; + public CustomToonShaderPropertyTypedValue TypedValue; public List Attributes = new(); } diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderDefaultTexture.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderDefaultTexture.cs new file mode 100644 index 0000000..eb02a5a --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderDefaultTexture.cs @@ -0,0 +1,14 @@ + + +namespace DELTation.ToonShader.Custom +{ + public enum CustomToonShaderDefaultTexture + { + Default, + White, + Black, + Gray, + Bump, + Red, + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderDefaultTexture.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderDefaultTexture.cs.meta new file mode 100644 index 0000000..f4754ac --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderDefaultTexture.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cfe9b6a5cd4e4a21bec4306110baafa3 +timeCreated: 1657091545 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyType.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyType.cs new file mode 100644 index 0000000..b541136 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyType.cs @@ -0,0 +1,16 @@ +namespace DELTation.ToonShader.Custom +{ + public enum CustomToonShaderPropertyType + { + Integer, + Float, + Texture2D, + Texture2DArray, + Texture3D, + Cubemap, + CubemapArray, + Color, + Vector, + Range, + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyType.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyType.cs.meta new file mode 100644 index 0000000..8d5de75 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyType.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 34f3f9afe91e4030bba2dc4f41f47223 +timeCreated: 1657091545 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyTypedValue.cs b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyTypedValue.cs new file mode 100644 index 0000000..2d31546 --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyTypedValue.cs @@ -0,0 +1,75 @@ +using System; +using System.Globalization; +using UnityEngine; + +namespace DELTation.ToonShader.Custom +{ + [Serializable] + public struct CustomToonShaderPropertyTypedValue + { + public CustomToonShaderPropertyType Type; + public int IntegerValue; + public float FloatValue; + public CustomToonShaderDefaultTexture TextureValue; + public float RangeMinValue; + public float RangeMaxValue; + public float RangeValue; + public Vector4 VectorValue; + public Color ColorValue; + + public string GetTypeString() => + Type switch + { + CustomToonShaderPropertyType.Integer => "Integer", + CustomToonShaderPropertyType.Float => "Float", + CustomToonShaderPropertyType.Texture2D => "2D", + CustomToonShaderPropertyType.Texture2DArray => "2DArray", + CustomToonShaderPropertyType.Texture3D => "3D", + CustomToonShaderPropertyType.Cubemap => "Cube", + CustomToonShaderPropertyType.CubemapArray => "CubeArray", + CustomToonShaderPropertyType.Color => "Color", + CustomToonShaderPropertyType.Vector => "Vector", + CustomToonShaderPropertyType.Range => + $"Range({FormatFloat(RangeMinValue)},{FormatFloat(RangeMaxValue)})", + _ => throw new ArgumentOutOfRangeException(), + }; + + private static string FormatFloat(float value) => value.ToString(CultureInfo.InvariantCulture); + + public string GetValueString() + { + const string defaultTextureString = "\"\" {}"; + + static string FormatAsVector4(float x, float y, float z, float w) => + $"({FormatFloat(x)},{FormatFloat(y)},{FormatFloat(z)},{FormatFloat(w)})"; + + return Type switch + { + CustomToonShaderPropertyType.Integer => IntegerValue.ToString(), + CustomToonShaderPropertyType.Float => FloatValue.ToString(CultureInfo.InvariantCulture), + CustomToonShaderPropertyType.Texture2D => TextureValue switch + { + CustomToonShaderDefaultTexture.Default => defaultTextureString, + CustomToonShaderDefaultTexture.White => "\"white\" {}", + CustomToonShaderDefaultTexture.Black => "\"black\" {}", + CustomToonShaderDefaultTexture.Gray => "\"gray\" {}", + CustomToonShaderDefaultTexture.Bump => "\"bump\" {}", + CustomToonShaderDefaultTexture.Red => "\"red\" {}", + _ => throw new ArgumentOutOfRangeException(), + }, + CustomToonShaderPropertyType.Texture2DArray => defaultTextureString, + CustomToonShaderPropertyType.Texture3D => defaultTextureString, + CustomToonShaderPropertyType.Cubemap => defaultTextureString, + CustomToonShaderPropertyType.CubemapArray => defaultTextureString, + CustomToonShaderPropertyType.Color => FormatAsVector4(ColorValue.r, ColorValue.g, ColorValue.b, + ColorValue.a + ), + CustomToonShaderPropertyType.Vector => FormatAsVector4(VectorValue.x, VectorValue.y, VectorValue.z, + VectorValue.w + ), + CustomToonShaderPropertyType.Range => FormatFloat(RangeValue), + _ => throw new ArgumentOutOfRangeException(), + }; + } + } +} \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyTypedValue.cs.meta b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyTypedValue.cs.meta new file mode 100644 index 0000000..b3373cb --- /dev/null +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Custom/CustomToonShaderPropertyTypedValue.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f0eccb741a27420da03623d55308ad89 +timeCreated: 1657091685 \ No newline at end of file diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset index b36f708..8353ea1 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.asset @@ -18,23 +18,55 @@ MonoBehaviour: Properties: - Name: _FurLength DisplayName: Fur Length - Type: Range(0, 1) - DefaultValue: 0.1 + TypedValue: + Type: 9 + IntegerValue: 0 + FloatValue: 0 + TextureValue: 0 + RangeMinValue: 0 + RangeMaxValue: 1 + RangeValue: 0.1 + VectorValue: {x: 0, y: 0, z: 0, w: 0} + ColorValue: {r: 0, g: 0, b: 0, a: 0} Attributes: [] - Name: _FurStep DisplayName: Fur Step - Type: Range(0, 1) - DefaultValue: 0.1 + TypedValue: + Type: 9 + IntegerValue: 0 + FloatValue: 0 + TextureValue: 0 + RangeMinValue: 0 + RangeMaxValue: 1 + RangeValue: 0.1 + VectorValue: {x: 0, y: 0, z: 0, w: 0} + ColorValue: {r: 0, g: 0, b: 0, a: 0} Attributes: [] - Name: _FurNoise DisplayName: Fur Noise - Type: 2D - DefaultValue: '"white" {}' + TypedValue: + Type: 2 + IntegerValue: 0 + FloatValue: 0 + TextureValue: 1 + RangeMinValue: 0 + RangeMaxValue: 0 + RangeValue: 0 + VectorValue: {x: 0, y: 0, z: 0, w: 0} + ColorValue: {r: 0, g: 0, b: 0, a: 0} Attributes: [] - Name: _FurMask DisplayName: Fur Mask - Type: 2D - DefaultValue: '"white" {}' + TypedValue: + Type: 2 + IntegerValue: 0 + FloatValue: 0 + TextureValue: 1 + RangeMinValue: 0 + RangeMaxValue: 0 + RangeValue: 0 + VectorValue: {x: 0, y: 0, z: 0, w: 0} + ColorValue: {r: 0, g: 0, b: 0, a: 0} Attributes: - NoScaleOffset Hooks: @@ -59,15 +91,15 @@ MonoBehaviour: \nSAMPLER(sampler_FurMask);" - Name: 2 Condition: - Code: 'const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, input.uv).r; + Code: 'const half mask = SAMPLE_TEXTURE2D(_FurMask, sampler_FurMask, input.uv).r; clip(mask - - 1); + - 1); - const float4 fur_noise_st = _FurNoise_ST; + const float4 fur_noise_st = _FurNoise_ST; - const half2 - noise_uv = apply_tiling_offset(input.uv, fur_noise_st); + const half2 noise_uv + = apply_tiling_offset(input.uv, fur_noise_st); - albedo.a *= - SAMPLE_TEXTURE2D(_FurNoise, sampler_FurNoise, noise_uv).r; ' + albedo.a *= SAMPLE_TEXTURE2D(_FurNoise, + sampler_FurNoise, noise_uv).r; ' diff --git a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader index 1ef24ba..2b69bfe 100644 --- a/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader +++ b/Packages/com.deltation.toon-shader/Assets/DELTation/ToonShader/Shaders/Fur/ToonShaderFur.shader @@ -66,8 +66,8 @@ Shader "DELTation/Custom/Toon Shader (Fur)" _ReflectionBlend ("Blend", Range(0, 1)) = 0.5 // Custom Properties Begin - [CustomProperty] _FurLength ("Fur Length", Range(0, 1)) = 0.1 - [CustomProperty] _FurStep ("Fur Step", Range(0, 1)) = 0.1 + [CustomProperty] _FurLength ("Fur Length", Range(0,1)) = 0.1 + [CustomProperty] _FurStep ("Fur Step", Range(0,1)) = 0.1 [CustomProperty] _FurNoise ("Fur Noise", 2D) = "white" {} [NoScaleOffset] [CustomProperty] _FurMask ("Fur Mask", 2D) = "white" {} // Custom Properties End