Shader "Hidden/MapCreator"
{
    Properties
    {
        _Metallic("Texture",2D) = "black"{}
        _Occlusion("Texture",2D) = "white"{}
        _DetailMask("Texture",2D) = "black"{}
        _Smoothness("Texture",2D) = "black"{}
        _deAbedo("Texture",2D) = "white"{}
        _deNormal("Texture",2D) = "white"{}
        _deSmoothness("Texture",2D) = "black"{}
    }
    SubShader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };
            
            sampler2D _Metallic;
            sampler2D _Occlusion;
            sampler2D _DetailMask;
            sampler2D _Smoothness;
            sampler2D _deAbedo;
            sampler2D _deNormal;
            sampler2D _deSmoothness;
            int useRoughness;
            int maptype;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col;
                if(maptype == 0||maptype == 2)
                {
                    col.r = tex2D(_Metallic,i.uv).r;
                    col.g = tex2D(_Occlusion,i.uv).r;
                    col.b = tex2D(_DetailMask,i.uv).r;
                    if(useRoughness == 1 && maptype == 0)
                    {
                        col.a = 1-tex2D(_Smoothness,i.uv).r;
                    }
                    else
                    {
                        col.a = tex2D(_Smoothness,i.uv).r;
                    }
                }
                else
                {
                    fixed4 deabedo = tex2D(_deAbedo,i.uv);
                    col.r = deabedo.r*0.3+deabedo.g*0.59+deabedo.b*0.11;
                    col.g = tex2D(_deNormal,i.uv).g;
                    if(useRoughness==0)
                    {
                        col.b = tex2D(_deSmoothness,i.uv).r;
                    }
                    else
                    {
                        col.b = 1-tex2D(_deSmoothness,i.uv).r;
                    }
                    col.a = tex2D(_deNormal,i.uv).r;
                }
                return col;
            }
            ENDCG
        }
    }
}

//by Erin.Z erinz.xyz
//published on 26/4/2022
