Shader ".Star/Metal/Metal" {
    Properties {
        [Header(Metal)]
        _Metaltintcolour ("Metal tint colour", Color) = (0,0,0,1)
        [NoScaleOffset] _Metalreflectioncubemap ("Metal reflection cubemap", Cube) = "_Skybox" {}
        _Metalgloss ("Metal gloss", Range(0, 10)) = 10
        _Fakelightreflectionstrength ("Fake light reflection strength", Float ) = 0
        [Header(Bump texture)]
        _Bumptexture ("Bump texture", 2D) = "bump" {}
        _BumptexturespeedX ("Bump texture speed (X)", Float ) = 0
        _BumptexturespeedY ("Bump texture speed (Y)", Float ) = 0
        [Header(Rim light)]
        [MaterialToggle] _Darkrim ("Dark rim", Float ) = 0
        _Rimpower ("Rim power", Float ) = 1
    }
    SubShader {
        Tags {
            "Queue"="Geometry+0"
            "RenderType"="Opaque"
        }
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }
            
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #include "AutoLight.cginc"
            #pragma multi_compile_fwdbase_fullshadows
            #pragma only_renderers d3d9 d3d11 glcore gles 
            #pragma target 3.0
            uniform float4 _LightColor0;
            uniform sampler2D _Bumptexture; uniform float4 _Bumptexture_ST;
            uniform float _BumptexturespeedY;
            uniform float _BumptexturespeedX;
            uniform float _Rimpower;
            uniform fixed _Darkrim;
            uniform samplerCUBE _Metalreflectioncubemap;
            uniform float _Fakelightreflectionstrength;
            uniform float _Metalgloss;
            uniform float4 _Metaltintcolour;
            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 posWorld : TEXCOORD1;
                float3 normalDir : TEXCOORD2;
                LIGHTING_COORDS(3,4)
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.normalDir = UnityObjectToWorldNormal(v.normal);
                o.posWorld = mul(unity_ObjectToWorld, v.vertex);
                float3 lightColor = _LightColor0.rgb;
                o.pos = UnityObjectToClipPos( v.vertex );
                TRANSFER_VERTEX_TO_FRAGMENT(o)
                return o;
            }
            float4 frag(VertexOutput i) : COLOR {
                i.normalDir = normalize(i.normalDir);
                float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
                float3 normalDirection = i.normalDir;
                float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
                float3 lightColor = _LightColor0.rgb;
////// Lighting:
                float attenuation = LIGHT_ATTENUATION(i);
                float3 attenColor = attenuation * _LightColor0.xyz;
/////// Diffuse:
                float NdotL = max(0.0,dot( normalDirection, lightDirection ));
                float3 directDiffuse = max( 0.0, NdotL) * attenColor;
                float3 indirectDiffuse = float3(0,0,0);
                indirectDiffuse += UNITY_LIGHTMODEL_AMBIENT.rgb; // Ambient Light
                float3 diffuseColor = _Metaltintcolour.rgb;
                float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
////// Emissive:
                float3 rimlight = lerp( 0.0, (((-1.0)*float3(1,1,1))*pow(1.0-max(0,dot(normalDirection, viewDirection)),_Rimpower)), _Darkrim );
                float4 node_277 = _Time;
                float4 node_2201 = _Time;
                float2 node_4572 = (i.uv0-float2((node_277.g*_BumptexturespeedX),(node_2201.g*_BumptexturespeedY)));
                float3 _Bumptexture_var = UnpackNormal(tex2D(_Bumptexture,TRANSFORM_TEX(node_4572, _Bumptexture)));
                float3 normals = _Bumptexture_var.rgb;
                float4 _Metalreflectioncubemap_var = texCUBElod(_Metalreflectioncubemap,float4(reflect((-1*viewDirection),(normals+i.normalDir)),(10.0-_Metalgloss)));
                float node_6174 = 0.0;
                float cubemap = (pow(1.0-max(0,dot(normalDirection, viewDirection)),(-1*_Fakelightreflectionstrength))*(lerp(_Metalreflectioncubemap_var.rgb,dot(_Metalreflectioncubemap_var.rgb,float3(0.3,0.59,0.11)),1.0)*(node_6174 + ( (_Metalreflectioncubemap_var.a - node_6174) * (5.0 - node_6174) ) / (1.0 - node_6174))));
                float3 emissive = (rimlight+cubemap);
/// Final Color:
                float3 finalColor = diffuse + emissive;
                return fixed4(finalColor,1);
            }
            ENDCG
        }
        Pass {
            Name "FORWARD_DELTA"
            Tags {
                "LightMode"="ForwardAdd"
            }
            Blend One One
            
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDADD
            #include "UnityCG.cginc"
            #include "AutoLight.cginc"
            #pragma multi_compile_fwdadd_fullshadows
            #pragma only_renderers d3d9 d3d11 glcore gles 
            #pragma target 3.0
            uniform float4 _LightColor0;
            uniform sampler2D _Bumptexture; uniform float4 _Bumptexture_ST;
            uniform float _BumptexturespeedY;
            uniform float _BumptexturespeedX;
            uniform float _Rimpower;
            uniform fixed _Darkrim;
            uniform samplerCUBE _Metalreflectioncubemap;
            uniform float _Fakelightreflectionstrength;
            uniform float _Metalgloss;
            uniform float4 _Metaltintcolour;
            struct VertexInput {
                float4 vertex : POSITION;
                float3 normal : NORMAL;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 posWorld : TEXCOORD1;
                float3 normalDir : TEXCOORD2;
                LIGHTING_COORDS(3,4)
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.texcoord0;
                o.normalDir = UnityObjectToWorldNormal(v.normal);
                o.posWorld = mul(unity_ObjectToWorld, v.vertex);
                float3 lightColor = _LightColor0.rgb;
                o.pos = UnityObjectToClipPos( v.vertex );
                TRANSFER_VERTEX_TO_FRAGMENT(o)
                return o;
            }
            float4 frag(VertexOutput i) : COLOR {
                i.normalDir = normalize(i.normalDir);
                float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
                float3 normalDirection = i.normalDir;
                float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
                float3 lightColor = _LightColor0.rgb;
////// Lighting:
                float attenuation = LIGHT_ATTENUATION(i);
                float3 attenColor = attenuation * _LightColor0.xyz;
/////// Diffuse:
                float NdotL = max(0.0,dot( normalDirection, lightDirection ));
                float3 directDiffuse = max( 0.0, NdotL) * attenColor;
                float3 diffuseColor = _Metaltintcolour.rgb;
                float3 diffuse = directDiffuse * diffuseColor;
/// Final Color:
                float3 finalColor = diffuse;
                return fixed4(finalColor * 1,0);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
}
