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

<CustomShader version="5">
    <Parameters>
        <Parameter name="reflectionScale" target="reflectionScale" type="float" group="base" defaultValue="1.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="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 = "POST_GLOSS_COLOR_FS">
<![CDATA[
    diffuseColor = 0;
    roughness = 0;
    metalness = 1;
    bakedAO   = 1;
    ssao = 1;
]]>
            </CodeInjection>
            <CodeInjection position = "GET_REFLECTION_COLOR_FS">
<![CDATA[
{
    float3 res = oColor;
    float3 reflectionColor = getReflectionColorTex(In, globals, instance, object, normal, tangentSpaceNormal, viewDir, roughness, fresnelStrength)*reflectionFactor;
#if defined( REFLECTION_SCALE_MASK )
    res += reflectionColor;
    float reflectionMask = object.reflectionScale*tex2DSample(reflectionMaskMap, samplerBilinearClamp, In.vs.glossMapTexCoords2).x;
    res = lerp(oColor,res,reflectionMask);
#else
    res += object.reflectionScale*reflectionColor;
#endif
    return res;
}
]]>
            </CodeInjection>
        </CodeInjections>
    </LodLevel>
</CustomShader>
