﻿<?xml version="1.0" encoding="utf-8"?>

<CustomShader version="5">
    <Parameters>
        <Parameter name="reflectionScale"  target="reflectionScale" type="float" defaultValue ="2.0"/>
    </Parameters>
    <UvUsages/>
    <Textures>
        <Texture name = "reflectionMaskMap" group="mask" defaultColorProfile = "linearRGB"/>
    </Textures>
    <VertexAttributes>
        <VertexAttribute name="uv1" group="mask"/>
    </VertexAttributes>
    <Variations>
        <Variation name="reflectionScaleMask" groups="mask">
<![CDATA[
    #define REFLECTION_SCALE_MASK_MASK
]]>
        </Variation>
    </Variations>
    <LodLevel startDistance="0">
        <CodeInjections>
            <CodeInjection position="OBJECT_PARAMETERS">
<![CDATA[
    float reflectionScale;
]]>
            </CodeInjection>
            <CodeInjection position = "SAMPLERS">
<![CDATA[
#if defined( REFLECTION_SCALE_MASK )
    sampler2D reflectionMaskMap;
#endif
]]>
            </CodeInjection>
            <CodeInjection position="VS_OUTPUT">
<![CDATA[
#if defined( REFLECTION_SCALE_MASK )
    float2 glossMapTexCoords2 : TEXCOORDn;
#endif
]]>
            </CodeInjection>
            <CodeInjection position = "POST_SET_TEXCOORDS_VS">
<![CDATA[
#if defined( REFLECTION_SCALE_MASK )
    Out.glossMapTexCoords2 = convertDefaultTexCoords(In, object, In.texCoords1.xy);
#endif
]]>
            </CodeInjection>
            <CodeInjection position = "GET_REFLECTION_COLOR_FS">
<![CDATA[
{
    float3 res = oColor;
    float3 reflectionColor = getReflectionColorTex(In, globals, object, normal, tangentSpaceNormal, viewDir, roughness, fresnelStrength)*reflectionFactor;
#if defined( REFLECTION_SCALE_MASK )
    res += reflectionColor;
    float reflectionMask = object.reflectionScale*tex2D(reflectionMaskMap, In.vs.glossMapTexCoords2).x;
    res = lerp(oColor,res,reflectionMask);
#else
    res += object.reflectionScale*reflectionColor;
#endif
    return res;
}
]]>
            </CodeInjection>
        </CodeInjections>
    </LodLevel>
</CustomShader>
