<?xml version="1.0" encoding="utf-8"?>
<CustomShader version="5">
    <Parameters>
        <Parameter name="beltClipOffsets" target="beltClipOffsets" type="float4" group="base" defaultValue="0 100 0 0" minValue="0 0 0 0" maxValue="100.0 100.0 100.0 100.0"/>
        <Parameter name="beltUVScale"     target="beltUVScale"     type="float2" group="base" defaultValue="1.0 1.0" minValue="0.0 0.0" maxValue="100.0 100.0"/>
    </Parameters>
    <UvUsages/>
    <Textures/>
    <VertexAttributes/>
    <Variations/>
    <LodLevel startDistance="0">
        <CodeInjections>

            <CodeInjection position="OBJECT_PARAMETERS">
<![CDATA[
    float4 beltClipOffsets;
    float2 beltUVScale;
]]>
            </CodeInjection>

            <CodeInjection position="VS_OUTPUT">
<![CDATA[
    float beltClipPosition : TEXCOORDn;
]]>
            </CodeInjection>

            <CodeInjection position="POST_SET_TEXCOORDS_VS">
<![CDATA[
    // Match base shader behavior
    Out.defaultTexCoords.y *= 10; // world/10 scaling for V
    Out.beltClipPosition = Out.defaultTexCoords.y;
    Out.defaultTexCoords *= object.beltUVScale;
]]>
            </CodeInjection>

            <!-- Preserve underlying texture alpha: multiply by the belt window mask -->
            <CodeInjection position="ALPHA_FS">
<![CDATA[
    float beltMask = float(
        (In.vs.beltClipPosition >= object.beltClipOffsets.x && In.vs.beltClipPosition <= object.beltClipOffsets.y) ||
        (In.vs.beltClipPosition >= object.beltClipOffsets.z && In.vs.beltClipPosition <= object.beltClipOffsets.w)
    );
    alpha *= beltMask;
]]>
            </CodeInjection>

            <CodeInjection position="DO_ALPHA_TEST_FS"><![CDATA[
#if !defined(LIGHTING) || defined(NOT_IN_ZFILL)
    clip(alpha - 0.5);   // was: clip(alphaValue - 0.5);
#endif
    return;
]]>
            </CodeInjection>

        </CodeInjections>
    </LodLevel>
</CustomShader>
