#include "version.sh"
#include "core.vsh"

in vec3 N;
out vec3 N_f;

in vec4 UV;
in int Flag;
in int ColorIdx;

out float Pz_f;
out vec2 UV_f;

flat out mediump vec2 ClampUV_f;
flat out ivec4 Flags;
flat out float height_f;
flat out int nightLightIndex;
out float nightLightIntensity;


vec3 CRTransformDir(vec3 dir)
{
    // There is no transform in the current building.
    return dir;
//    // 仅考虑各向均匀缩放 local to world
//    return normalize(mat3(_ModelMatrix) * dir);
}

void main()
{
    DISL_VS_INIT
    
    N_f = N;
    
    Pz_f = P.z;
    UV_f = UV.xy;
    ClampUV_f = UV.zw;
    Flags.x = Flag & 0xf0; // u wrap mode
    Flags.y = Flag & 0x0f; // v wrap mode
    Flags.z = (Flag >> 8) & 0xff; // uv style
    
    Flags.w = ColorIdx;
    
    height_f = float((Flag >> 16) & 0xff);
    nightLightIndex = (Flag >> 24) & 0x0f; // night light ratio

    gl_Position = LocalToClip(P);
    float linear01 = Depth_EyeToLinear01(gl_Position.w);
    nightLightIntensity = 1.0 - linear01;
}

