<?xml version="1.0" encoding="utf-8"?>
<CustomShader version="4">
    <Parameters>
        <Parameter name="displacementScaleSpeedFrequency" target="displacementScaleSpeedFrequency" type="float4" defaultValue="1 1 1 1"/>
        <Parameter name="mixParams" target="mixParams" type="float4" defaultValue="1 0 1 1"/>
    </Parameters>
    <VertexAttributes>
        <VertexAttribute name="uv1" group="uv1"/>
    </VertexAttributes>
    <LodLevel startDistance="0">
        <CodeInjections>
            <CodeInjection position="MATERIALINFO">
                <![CDATA[
uniform float4 displacementScaleSpeedFrequency;
uniform float4 mixParams;
]]>
            </CodeInjection>
            <CodeInjection position="FS_GLOBALS">
                <![CDATA[
float gRoughnessPow;
float4 gVertexColor;
float2 gUv;
]]>
            </CodeInjection>
            <CodeInjection position="START_FS">
                <![CDATA[
globals.gRoughnessPow = mixParams.x;
globals.gVertexColor = float4(1, 1, 1, 1);
globals.gUv = In.vs.mUVorg;
]]>
            </CodeInjection>
            <CodeInjection position="GET_POSITION_VS">
                <![CDATA[
float offset2 = sin((cTime_s) * displacementScaleSpeedFrequency.y + In.position.x * In.position.z * displacementScaleSpeedFrequency.z);
float offset1 = cos((cTime_s) * displacementScaleSpeedFrequency.y + In.position.x * In.position.z * displacementScaleSpeedFrequency.z);
float offset  = lerp(offset1, offset2, mixParams.y);

float3 mOffset = float3(0.2 * displacementScaleSpeedFrequency.x * offset, 0.1 * displacementScaleSpeedFrequency.x * offset, 0);
float3 deform = In.position.xyz;
float2 uv = convertDefaultTexCoords(In, In.texCoords1.xy);
float index =  uv.x + floor(uv.y) * 8;
float indexRounded =  floor(uv.x) + floor(uv.y) * 8;
float current = min(mixParams.z, mixParams.w);

if (mixParams.y > 0) {
    if (indexRounded == current || index - 0.5 <= current && index + 0.5 >= current || index - 1.5 <= current && index - 0.5 >= current) {
        float offset2 = cos((cTime_s) * displacementScaleSpeedFrequency.y * 3 + In.position.x * In.position.z * displacementScaleSpeedFrequency.z);
        deform.y = lerp(deform.y, offset2 * displacementScaleSpeedFrequency.x, uv.y * 0.5) * 5;
    }
}
return deform + mOffset;
]]>
            </CodeInjection>
            <CodeInjection position="VS_OUTPUT">
                <![CDATA[
float2 mUVorg : TEXCOORDn;
float2 localNormal : TEXCOORDn;
]]>
            </CodeInjection>
            <CodeInjection position="VS_END">
                <![CDATA[
Out.mUVorg = convertDefaultTexCoords(In, In.texCoords1.xy);
Out.localNormal = normalize(In.normal.xyz);
]]>
            </CodeInjection>
            <CodeInjection position="POST_DIFFUSE_COLOR_FS">
                <![CDATA[
#if defined(ALBEDO_MAP)
float2 uv = In.vs.mUVorg;
float index =  uv.x + floor(uv.y) * 8;
float index2 =  floor(uv.x);
float indexRounded =  floor(uv.x) + floor(uv.y) * 8;
float current = min(mixParams.z, mixParams.w);

if (indexRounded == current || index - 0.5 <= current && index + 0.5 >= current || index - 1.5 <= current && index - 0.5 >= current) {
    //diffuseColor = lerp(diffuseColor, globals.gVertexColor, uv.y);
}
    #endif
]]>
            </CodeInjection>
            <CodeInjection position="POST_GLOSS_COLOR_FS">
                <![CDATA[
#ifdef GLOSS_MAP
{
roughness = 1 - 0.5 * globals.gRoughnessPow;
}
#endif
]]>
            </CodeInjection>
        </CodeInjections>
    </LodLevel>
</CustomShader>
