Shader "URP/SceneBase/JR_Scene_Pbr"
{
    Properties
    {
        [MainColor] _BaseColor("Color", Color) = (1,1,1,1)
        [MainTexture] _BaseMap("Albedo", 2D) = "white" {}

        _Cutoff("Aplha Test threshold", Range(0, 1)) = 0.5

        _Metallic ("Metallic", Range (0, 1)) = 0

        [ToggleOff] _SpecularHighlights("Specular Highlights", Float) = 1.0
        [ToggleOff] _EnvironmentReflections("Environment Reflections", Float) = 1.0

        _NormalMap("Normal Map", 2D) = "bump" {}
        _normalScale("Normal Scale", Range(0,3)) = 1
        _DetailNormalMap("Detail Normal Map", 2D) = "bump" {}
        _detailNormalScale("Detail Normal Scale", Range(0,3)) = 1
        _detailNormalTiling("Detail Normal Tiling", float) = 1
        _angle("Detail Angle", float) = 0

        _Roughness ("Roughness", Range (0, 1)) = 1
        _Emission ("Emission", Range (0, 1)) = 0

        _PomCount ("PomCount", Range (0, 20)) = 10
        _PomScale ("PomScale", Range (0, 1)) = 0.3

        _BlendIntensity ("Blend Intensity", Range (-1, 1)) = -0.3
        _BlendColor ("Color", Color) = (1,1,1,1)

        _PackMap("Metallic, Roughness, Emission", 2D) = "white" {}
        _BlendTex("Blend Texture", 2D) = "white" {}
        _BlendTexTilling("Blend Texture Tilling", float) = 4
    }
    SubShader
    {
        Name "ForwardLit"
        Tags{"LightMode" = "UniversalForward"}

        ZWrite On
        ZTest LEqual
        Cull[_Cull]
        LOD 100

        Pass
        {
            HLSLPROGRAM

            #pragma shader_feature_local _SPECULARHIGHLIGHTS_OFF
            #pragma shader_feature_local _ENVIRONMENTREFLECTIONS_OFF
            #pragma shader_feature_local _DETAILNOMAL
            #pragma shader_feature_local _USEPACKMAP
            #pragma shader_feature_local _ALPHATEST_ON
            #pragma shader_feature_local _POM_ON
            #pragma shader_feature_local _USE_Blend
            #pragma multi_compile _ SHADOWS_SHADOWMASK
            #pragma multi_compile _ LIGHTMAP_ON

            #define _MAIN_LIGHT_SHADOWS

            #pragma vertex LitPassVertex
            #pragma fragment LitPassFragment
            // make fog work
            #pragma multi_compile_fog
            

            // #include "UnityCG.cginc"
            #include "JR_Scene_PbrLitPass.hlsl"

            ENDHLSL
        }

        Pass
        {
            Name "ShadowCaster"
            Tags{"LightMode" = "ShadowCaster"}

            ZWrite On
            ZTest LEqual
            Cull[_Cull]

            HLSLPROGRAM
            // Required to compile gles 2.0 with standard srp library
            #pragma prefer_hlslcc gles
            #pragma exclude_renderers d3d11_9x
            #pragma target 2.0

            // -------------------------------------
            // Material Keywords
            #pragma shader_feature _ALPHATEST_ON

            //--------------------------------------
            // GPU Instancing
            #pragma multi_compile_instancing
            #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

            #pragma vertex ShadowPassVertex
            #pragma fragment ShadowPassFragment

            #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl"
            ENDHLSL
        }

        Pass
        {
            Name "DepthOnly"
            Tags{"LightMode" = "DepthOnly"}

            ZWrite On
            ColorMask 0
            Cull[_Cull]

            HLSLPROGRAM
            // Required to compile gles 2.0 with standard srp library
            #pragma prefer_hlslcc gles
            #pragma exclude_renderers d3d11_9x
            #pragma target 2.0

            #pragma vertex DepthOnlyVertex
            #pragma fragment DepthOnlyFragment

            // -------------------------------------
            // Material Keywords
            #pragma shader_feature _ALPHATEST_ON
            #pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

            //--------------------------------------
            // GPU Instancing
            #pragma multi_compile_instancing

            #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
            ENDHLSL
        }

        // This pass it not used during regular rendering, only for lightmap baking.
        Pass
        {
            Name "Meta"
            Tags{"LightMode" = "Meta"}

            Cull Off

            HLSLPROGRAM
            // Required to compile gles 2.0 with standard srp library
            #pragma prefer_hlslcc gles
            #pragma exclude_renderers d3d11_9x

            #pragma vertex UniversalVertexMeta
            #pragma fragment UniversalFragmentMeta

            #pragma shader_feature _SPECULAR_SETUP
            #pragma shader_feature _EMISSION
            #pragma shader_feature _METALLICSPECGLOSSMAP
            #pragma shader_feature _ALPHATEST_ON
            #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

            #pragma shader_feature _SPECGLOSSMAP

            #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/Shaders/LitMetaPass.hlsl"

            ENDHLSL
        }
    }
    FallBack "Hidden/Universal Render Pipeline/FallbackError"
    CustomEditor "PBRShaderGUI"
}
