<?xml version="1.0" encoding="utf-8"?>
<CustomShader version="5">
    <Parameters>
        <Parameter name = "placeableColorScale" target = "placeableColorScale" type = "float4" group="base" defaultValue = "0.0 1.0 0.0 0.0" minValue = "0.0 0.0 0.0 0.0" maxValue = "1.0 1.0 1.0 1.0"/>
        <Parameter name = "colorTint"           target = "colorTint"           type = "float3" group="base" defaultValue = "0.0 0.0 0.0"     minValue = "-1.0 -1.0 -1.0"  maxValue = "1.0 1.0 1.0"/>
    </Parameters>
    <UvUsages/>
    <Variations>
        <Variation name="reflector">
<![CDATA[
    #define REFLECTOR_SHADING
]]>
        </Variation>
    </Variations>
    <LodLevel startDistance="0">
        <CodeInjections>
            <CodeInjection position="CONFIG_DEFINES">
<![CDATA[
    #if !defined(ALLOW_PCSS)
        #define ALLOW_PCSS
    #endif
]]>
            </CodeInjection>
            <CodeInjection position = "OBJECT_PARAMETERS">
<![CDATA[
    float4 placeableColorScale;
    float3 colorTint;
]]>
            </CodeInjection>
            <CodeInjection position = "FS_GLOBALS">
<![CDATA[
#if defined( REFLECTOR_SHADING )
    float  gAlpha;
#endif
]]>
            </CodeInjection>
            <CodeInjection position = "START_FS">
<![CDATA[
#if defined( REFLECTOR_SHADING )
    globals.gAlpha = 1.0;
#endif
]]>
            </CodeInjection>
            <CodeInjection position = "POST_GET_SPECULAR_SHADING_FS">
<![CDATA[
#if defined( REFLECTOR_SHADING )
{
    float specDistribution = saturate(shadingAngles.VdotL);
    specDistribution *= specDistribution;
    specDistribution *= specDistribution;
    specDistribution *= specDistribution; // hardcoded power of 8

    float3 retroReflectionShading = globals.gAlpha * specDistribution * diffuseColor * 4.0; // *4 to make it brighter compared to diffuse

    specularShading += retroReflectionShading;
}
#endif
]]>
            </CodeInjection>
            <CodeInjection position = "POST_DIFFUSE_COLOR_FS">
<![CDATA[
    diffuseColor = saturate(diffuseColor + object.colorTint);
    if (object.placeableColorScale.w > 0){
        diffuseColor = lerp(diffuseColor,object.placeableColorScale.rgb,saturate(0.1+getFresnel( facing, 0.15 , 4.0 ))*object.placeableColorScale.w);
    }
]]>
            </CodeInjection>
            <CodeInjection position="ALPHA_FS">
<![CDATA[
#if defined(ALPHA_BLENDED)
    reflectingLightingScale = alpha;
    #if defined( REFLECTOR_SHADING )
        globals.gAlpha = alpha;
    #endif
#endif
]]>
            </CodeInjection>
        </CodeInjections>
    </LodLevel>
</CustomShader>
