// Alloy Physical Shader Framework
// Copyright 2013-2017 RUST LLC.
// http://www.alloy.rustltd.com/

Shader "Alloy/Tessellation/Vertex Blend" {
Properties {
    // Global Settings
    _Mode ("'Rendering Mode' {RenderingMode:{Opaque:{_Cutoff}, Cutout:{}, Fade:{_Cutoff}, Transparent:{_Cutoff}}}", Float) = 0
    _SrcBlend ("__src", Float) = 0
    _DstBlend ("__dst", Float) = 0
    _ZWrite ("__zw", Float) = 1
    [LM_TransparencyCutOff] 
    _Cutoff ("'Opacity Cutoff' {Min:0, Max:1}", Float) = 0.5
    [Toggle(EFFECT_BUMP)]
    _HasBumpMap ("'Normals Source' {Dropdown:{VertexNormals:{_Normal0,_SplatBumpScale0,_Normal1,_SplatBumpScale1,_Normal2,_SplatBumpScale2,_Normal3,_SplatBumpScale3,_DetailNormalMap,_DetailNormalMapScale,_WetNormalMap,_WetNormalMapScale}, NormalMaps:{}}}", Float) = 1
    [Toggle(_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A)]
    _MainRoughnessSource ("'Roughness Source' {Dropdown:{PackedMapAlpha:{}, BaseColorAlpha:{_MaterialMap0,_SplatOcclusion0,_MaterialMap1,_SplatOcclusion1,_MaterialMap2,_SplatOcclusion2,_MaterialMap3,_SplatOcclusion3}}}", Float) = 0
    
    // Red Splat
    _Splat0Textures ("'Red Splat' {Section:{Color:{150,0,0}}}", Float) = 0
    _Splat0Tint ("'Tint' {}", Color) = (1,1,1,1)
    _Splat0 ("'Base Color(RGB) Opacity(A)' {Visualize:{RGB, A}}", 2D) = "white" {}
    _Splat0Velocity ("Scroll", Vector) = (0,0,0,0) 
    _Splat0UV ("UV Set", Float) = 0
    _MaterialMap0 ("'Metal(R) AO(G) Spec(B) Rough(A)' {Visualize:{R, G, B, A}, Parent:_Splat0}", 2D) = "white" {}
    _Normal0 ("'Normals' {Visualize:{NRM}, Parent:_Splat0}", 2D) = "bump" {}

    // Red Splat Properties
    _Splat0PhysicalProperties("'Red Splat Properties' {Section:{Color:{150,0,0}}}", Float) = 0
    _Metallic0 ("'Metallic' {Min:0, Max:1}", Float) = 0.0
    _SplatSpecularity0 ("'Specularity' {Min:0, Max:1}", Float) = 0.5
    _SplatSpecularTint0 ("'Specular Tint' {Min:0, Max:1}", Float) = 0.0
    _SplatRoughness0 ("'Roughness' {Min:0, Max:1}", Float) = 1.0
    _SplatOcclusion0 ("'Occlusion Strength' {Min:0, Max:1}", Float) = 1
    _SplatBumpScale0 ("'Normal Strength' {}", Float) = 1
    
    // Green Splat
    _Splat1Textures ("'Green Splat' {Section:{Color:{0,149,0}}}", Float) = 0
    _Splat1Tint ("'Tint' {}", Color) = (1,1,1,1)
    _Splat1 ("'Base Color(RGB) Opacity(A)' {Visualize:{RGB, A}}", 2D) = "white" {}	
    _Splat1Velocity ("Scroll", Vector) = (0,0,0,0) 
    _Splat1UV ("UV Set", Float) = 0
    _MaterialMap1 ("'Metal(R) AO(G) Spec(B) Rough(A)' {Visualize:{R, G, B, A}, Parent:_Splat1}", 2D) = "white" {}
    _Normal1 ("'Normals' {Visualize:{NRM}, Parent:_Splat1}", 2D) = "bump" {}

    // Green Splat Properties
    _Splat1PhysicalProperties("'Green Splat Properties' {Section:{Color:{0,149,0}}}", Float) = 0
    _Metallic1 ("'Metallic' {Min:0, Max:1}", Float) = 0.0
    _SplatSpecularity1 ("'Specularity' {Min:0, Max:1}", Float) = 0.5
    _SplatSpecularTint1 ("'Specular Tint' {Min:0, Max:1}", Float) = 0.0
    _SplatRoughness1 ("'Roughness' {Min:0, Max:1}", Float) = 1.0
    _SplatOcclusion1 ("'Occlusion Strength' {Min:0, Max:1}", Float) = 1
    _SplatBumpScale1 ("'Normal Strength' {}", Float) = 1
    
    // Blue Splat
    _Splat2Textures ("'Blue Splat' {Section:{Color:{11,0,148}}}", Float) = 0
    _Splat2Tint ("'Tint' {}", Color) = (1,1,1,1)
    _Splat2 ("'Base Color(RGB) Opacity(A)' {Visualize:{RGB, A}}", 2D) = "white" {}	
    _Splat2Velocity ("Scroll", Vector) = (0,0,0,0) 
    _Splat2UV ("UV Set", Float) = 0
    _MaterialMap2 ("'Metal(R) AO(G) Spec(B) Rough(A)' {Visualize:{R, G, B, A}, Parent:_Splat2}", 2D) = "white" {}
    _Normal2 ("'Normals' {Visualize:{NRM}, Parent:_Splat2}", 2D) = "bump" {}

    // Blue Splat Properties
    _Splat2PhysicalProperties("'Blue Splat Properties' {Section:{Color:{11,0,148}}}", Float) = 0
    _Metallic2 ("'Metallic' {Min:0, Max:1}", Float) = 0.0
    _SplatSpecularity2 ("'Specularity' {Min:0, Max:1}", Float) = 0.5
    _SplatSpecularTint2 ("'Specular Tint' {Min:0, Max:1}", Float) = 0.0
    _SplatRoughness2 ("'Roughness' {Min:0, Max:1}", Float) = 1.0
    _SplatOcclusion2 ("'Occlusion Strength' {Min:0, Max:1}", Float) = 1
    _SplatBumpScale2 ("'Normal Strength' {}", Float) = 1
    
    // Alpha Splat
    [Toggle(_SPECGLOSSMAP)]
    _Splat3Textures("'Alpha Splat' {Feature:{Color:{0,0,0},Hide:{_Splat3PhysicalProperties}}}", Float) = 0
    _Splat3Tint ("'Tint' {}", Color) = (1,1,1,1)
    _Splat3 ("'Base Color(RGB) Opacity(A)' {Visualize:{RGB, A}}", 2D) = "white" {}	
    _Splat3Velocity ("Scroll", Vector) = (0,0,0,0) 
    _Splat3UV ("UV Set", Float) = 0
    _MaterialMap3 ("'Metal(R) AO(G) Spec(B) Rough(A)' {Visualize:{R, G, B, A}, Parent:_Splat3}", 2D) = "white" {}
    _Normal3 ("'Normals' {Visualize:{NRM}, Parent:_Splat3}", 2D) = "bump" {}

    // Alpha Splat Properties
    _Splat3PhysicalProperties("'Alpha Splat Properties' {Section:{Color:{0,0,0}}}", Float) = 0
    _Metallic3 ("'Metallic' {Min:0, Max:1}", Float) = 0.0
    _SplatSpecularity3 ("'Specularity' {Min:0, Max:1}", Float) = 0.5
    _SplatSpecularTint3 ("'Specular Tint' {Min:0, Max:1}", Float) = 0.0
    _SplatRoughness3 ("'Roughness' {Min:0, Max:1}", Float) = 1.0
    _SplatOcclusion3 ("'Occlusion Strength' {Min:0, Max:1}", Float) = 1
    _SplatBumpScale3 ("'Normal Strength' {}", Float) = 1
    
    // Triplanar
    [Toggle(_METALLICGLOSSMAP)]
    _TriplanarProperties ("'Triplanar' {Feature:{Color:4}}", Float) = 0
    [Toggle(_TRIPLANARMODE_WORLD)]
    _TriplanarMode ("'Mode' {Dropdown:{Object:{}, World:{}}}", Float) = 1
    _TriplanarBlendSharpness ("'Sharpness' {Min:1, Max:50}", Float) = 2
    
    // AO2
    [Toggle(_AO2_ON)] 
    _AO2 ("'AO2' {Feature:{Color:6}}", Float) = 0
    _Ao2Map ("'AO2(G)' {Visualize:{RGB}}", 2D) = "white" {} 
    _Ao2MapUV ("UV Set", Float) = 1
    _Ao2Occlusion ("'Occlusion Strength' {Min:0, Max:1}", Float) = 1
    
    // Tessellation
    _TessellationProperties ("'Tessellation' {Section:{Color:5}}", Float) = 0
    [KeywordEnum(Displacement, Phong)] 
    _TessellationMode ("'Mode' {Dropdown:{Displacement:{_Phong}, Phong:{_DispTex, _Displacement}}}", Float) = 0
    _DispTex ("'Heightmap(G)' {Visualize:{RGB}}", 2D) = "black" {}
    _DispTexVelocity ("Scroll", Vector) = (0,0,0,0)
    _Displacement ("'Displacement' {Min:0, Max:30}", Float) = 0.3	
    _Phong ("'Phong Strength' {Min:0, Max:1}", Float) = 0.5
    _EdgeLength ("'Edge Length' {Min:2, Max:50}", Float) = 15
    
    // Detail
    [Toggle(_DETAIL_MULX2)] 
    _DetailT ("'Detail' {Feature:{Color:7}}", Float) = 0
    [Toggle(_NORMALMAP)]
    _DetailMaskSource ("'Mask Source' {Dropdown:{TextureAlpha:{}, VertexColorAlpha:{_DetailMask}}}", Float) = 0
    _DetailMask ("'Mask(A)' {Visualize:{A}, Parent:_MainTex}", 2D) = "white" {}
    _DetailMaskStrength ("'Mask Strength' {Min:0, Max:1}", Float) = 1
    [Enum(Mul, 0, MulX2, 1)] 
    _DetailMode ("'Color Mode' {Dropdown:{Mul:{}, MulX2:{}}}", Float) = 0
    _DetailAlbedoMap ("'Color(RGB)' {Visualize:{RGB}}", 2D) = "white" {}
    _DetailAlbedoMapVelocity ("Scroll", Vector) = (0,0,0,0) 
    _DetailAlbedoMapUV ("UV Set", Float) = 0
    _DetailNormalMap ("'Normals' {Visualize:{NRM}, Parent:_DetailAlbedoMap}", 2D) = "bump" {}
    _DetailWeight ("'Weight' {Min:0, Max:1}", Float) = 1
    _DetailNormalMapScale ("'Normal Strength' {}", Float) = 1
    
    // Decal
    [Toggle(_DECAL_ON)] 
    _Decal ("'Decal' {Feature:{Color:9}}", Float) = 0	
    _DecalColor ("'Tint' {}", Color) = (1,1,1,1)
    _DecalTex ("'Base Color(RGB) Opacity(A)' {Visualize:{RGB, A}}", 2D) = "black" {} 
    _DecalTexUV ("UV Set", Float) = 0
    _DecalWeight ("'Weight' {Min:0, Max:1}", Float) = 1
    _DecalSpecularity ("'Specularity' {Min:0, Max:1}", Float) = 0.5
    _DecalAlphaVertexTint ("'Vertex Alpha Tint' {Min:0, Max:1}", Float) = 0
    
    // Wetness
    [Toggle(_WETNESS_ON)]
    _WetnessProperties ("'Wetness' {Feature:{Color:13}}", Float) = 0
    [Toggle(_WETMASKSOURCE_VERTEXCOLORALPHA)]
    _WetMaskSource ("'Mask Source' {Dropdown:{TextureAlpha:{}, VertexColorAlpha:{_WetMask}}}", Float) = 0
    _WetMask ("'Mask(A)' {Visualize:{A}}", 2D) = "white" {}
    _WetMaskVelocity ("Scroll", Vector) = (0,0,0,0)
    _WetMaskUV ("UV Set", Float) = 0
    _WetMaskStrength ("'Mask Strength' {Min:0, Max:1}", Float) = 1
    _WetTint ("'Tint' {}", Color) = (1,1,1,1)
    _WetNormalMap ("'Normals' {Visualize:{NRM}}", 2D) = "bump" {}
    _WetNormalMapVelocity ("Scroll", Vector) = (0,0,0,0)
    _WetNormalMapUV ("UV Set", Float) = 0
    _WetWeight ("'Weight' {Min:0, Max:1}", Float) = 1
    _WetRoughness ("'Roughness' {Min:0, Max:1}", Float) = 0.2
    _WetNormalMapScale ("'Normal Strength' {}", Float) = 1

    // Forward Rendering Options
    _ForwardRenderingOptions ("'Forward Rendering Options' {Section:{Color:19}}", Float) = 0
    [ToggleOff] 
    _SpecularHighlights ("'Specular Highlights' {Toggle:{On:{}, Off:{}}}", Float) = 1.0
    [ToggleOff] 
    _GlossyReflections ("'Glossy Reflections' {Toggle:{On:{}, Off:{}}}", Float) = 1.0

    // Advanced Options
    _AdvancedOptions ("'Advanced Options' {Section:{Color:20}}", Float) = 0
    _Lightmapping ("'GI' {LightmapEmissionProperty:{}}", Float) = 1
    _RenderQueue ("'Render Queue' {RenderQueue:{}}", Float) = 0
    _EnableInstancing ("'Enable Instancing' {EnableInstancing:{}}", Float) = 0
}

CGINCLUDE
    #define A_TESSELLATION_SHADER
ENDCG

SubShader {
    Tags { 
        "RenderType" = "Opaque" 
        "PerformanceChecks" = "False"
        //"DisableBatching" = "LODFading"
    }
    LOD 300

    Pass {
        Name "FORWARD" 
        Tags { "LightMode" = "ForwardBase" }

        Blend [_SrcBlend] [_DstBlend]
        ZWrite [_ZWrite]        

        CGPROGRAM
        //#pragma target 4.6
        #pragma exclude_renderers gles
        
        #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
        #pragma shader_feature EFFECT_BUMP
        #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
        #pragma shader_feature _SPECGLOSSMAP
        #pragma shader_feature _METALLICGLOSSMAP
        #pragma shader_feature _TRIPLANARMODE_WORLD
        #pragma shader_feature _TESSELLATIONMODE_DISPLACEMENT _TESSELLATIONMODE_PHONG
        #pragma shader_feature _AO2_ON
        #pragma shader_feature _DETAIL_MULX2
        #pragma shader_feature _NORMALMAP
        #pragma shader_feature _DECAL_ON
        #pragma shader_feature _WETNESS_ON
        #pragma shader_feature _WETMASKSOURCE_VERTEXCOLORALPHA
        #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
        #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
        
        //#pragma multi_compile __ LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
        #pragma multi_compile_fwdbase
        #pragma multi_compile_fog
        #pragma multi_compile_instancing
        //#pragma multi_compile __ VTRANSPARENCY_ON
            
        #pragma hull aMainHullShader
        #pragma vertex aMainTessellationVertexShader
        #pragma domain aMainDomainShader
        #pragma fragment aMainFragmentShader
        
        #define UNITY_PASS_FORWARDBASE
        
        #include "Assets/Alloy/Shaders/Definition/VertexBlend.cginc"
        #include "Assets/Alloy/Shaders/Forward/Base.cginc"

        ENDCG
    }
    
    Pass {
        Name "FORWARD_DELTA"
        Tags { "LightMode" = "ForwardAdd" }
        
        Blend [_SrcBlend] One
        ZWrite Off
        
        CGPROGRAM
        //#pragma target 4.6
        #pragma exclude_renderers gles
                
        #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
        #pragma shader_feature EFFECT_BUMP
        #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
        #pragma shader_feature _SPECGLOSSMAP
        #pragma shader_feature _METALLICGLOSSMAP
        #pragma shader_feature _TRIPLANARMODE_WORLD
        #pragma shader_feature _TESSELLATIONMODE_DISPLACEMENT _TESSELLATIONMODE_PHONG
        #pragma shader_feature _AO2_ON
        #pragma shader_feature _DETAIL_MULX2
        #pragma shader_feature _NORMALMAP
        #pragma shader_feature _DECAL_ON
        #pragma shader_feature _WETNESS_ON
        #pragma shader_feature _WETMASKSOURCE_VERTEXCOLORALPHA
        #pragma shader_feature _ _SPECULARHIGHLIGHTS_OFF
        
        //#pragma multi_compile __ LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
        #pragma multi_compile_fwdadd_fullshadows
        #pragma multi_compile_fog
        //#pragma multi_compile __ VTRANSPARENCY_ON
        
        #pragma hull aMainHullShader
        #pragma vertex aMainTessellationVertexShader
        #pragma domain aMainDomainShader
        #pragma fragment aMainFragmentShader

        #define UNITY_PASS_FORWARDADD

        #include "Assets/Alloy/Shaders/Definition/VertexBlend.cginc"
        #include "Assets/Alloy/Shaders/Forward/Add.cginc"

        ENDCG
    }
    
    Pass {
        Name "SHADOWCASTER"
        Tags { "LightMode" = "ShadowCaster" }
        
        CGPROGRAM
        //#pragma target 4.6
        #pragma exclude_renderers gles

        #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
        #pragma shader_feature _SPECGLOSSMAP
        #pragma shader_feature _METALLICGLOSSMAP
        #pragma shader_feature _TRIPLANARMODE_WORLD
        #pragma shader_feature _TESSELLATIONMODE_DISPLACEMENT _TESSELLATIONMODE_PHONG
        
        #pragma multi_compile_shadowcaster
        #pragma multi_compile_instancing

        #pragma hull aMainHullShader
        #pragma vertex aMainTessellationVertexShader
        #pragma domain aMainDomainShader
        #pragma fragment aMainFragmentShader
        
        #define UNITY_PASS_SHADOWCASTER
        
        #include "Assets/Alloy/Shaders/Definition/VertexBlend.cginc"
        #include "Assets/Alloy/Shaders/Forward/Shadow.cginc"

        ENDCG
    }
    
    Pass {
        Name "DEFERRED"
        Tags { "LightMode" = "Deferred" }

        CGPROGRAM
        //#pragma target 4.6
        #pragma exclude_renderers nomrt gles

        #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
        #pragma shader_feature EFFECT_BUMP
        #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
        #pragma shader_feature _SPECGLOSSMAP
        #pragma shader_feature _METALLICGLOSSMAP
        #pragma shader_feature _TRIPLANARMODE_WORLD
        #pragma shader_feature _TESSELLATIONMODE_DISPLACEMENT _TESSELLATIONMODE_PHONG
        #pragma shader_feature _AO2_ON
        #pragma shader_feature _DETAIL_MULX2
        #pragma shader_feature _NORMALMAP
        #pragma shader_feature _DECAL_ON
        #pragma shader_feature _WETNESS_ON
        #pragma shader_feature _WETMASKSOURCE_VERTEXCOLORALPHA
        #pragma shader_feature _ _GLOSSYREFLECTIONS_OFF
        
        //#pragma multi_compile __ LOD_FADE_PERCENTAGE LOD_FADE_CROSSFADE
        #pragma multi_compile_prepassfinal
        #pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
        #pragma multi_compile_instancing
        
        #pragma hull aMainHullShader
        #pragma vertex aMainTessellationVertexShader
        #pragma domain aMainDomainShader
        #pragma fragment aMainFragmentShader
        
        #define UNITY_PASS_DEFERRED
        
        #include "Assets/Alloy/Shaders/Definition/VertexBlend.cginc"
        #include "Assets/Alloy/Shaders/Forward/Gbuffer.cginc"

        ENDCG
    }
    
    Pass {
        Name "Meta"
        Tags { "LightMode" = "Meta" }

        Cull Off

        CGPROGRAM
        //#pragma target 4.6
        #pragma exclude_renderers nomrt gles
        
        #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
        #pragma shader_feature _SPECGLOSSMAP
        #pragma shader_feature _METALLICGLOSSMAP
        #pragma shader_feature _TRIPLANARMODE_WORLD
        #pragma shader_feature _DETAIL_MULX2
        #pragma shader_feature _NORMALMAP
        #pragma shader_feature _DECAL_ON
        
        #pragma vertex aMainVertexShader
        #pragma fragment aMainFragmentShader
        
        #define UNITY_PASS_META
        
        #include "Assets/Alloy/Shaders/Definition/VertexBlend.cginc"
        #include "Assets/Alloy/Shaders/Forward/Meta.cginc"

        ENDCG
    }
}

Fallback "Alloy/Vertex Blend"
CustomEditor "AlloyFieldBasedEditor"
}
