#version 450

layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec3 fragLineStart;
layout(location = 2) in vec3 fragLineEnd;

layout(location = 0) out vec4 outColor;

layout(binding = 0) uniform UniformBufferObject {
    mat4 proj;
    mat4 model;
    mat4 view;
} ubo;

layout(binding = 1) uniform DashParameters {
    float dashSize;
    float gapSize;
    float dashOffset;
    float uAASize;
    int useWorldSpace;
} dashParams;

void main() {
    vec2 fragPos = gl_FragCoord.xy;
    
    // 网格参数
    float gridSize = 14.0;           // 网格大小
    float dotRadius = 6.0;           // 点状半径
    
    // 计算当前片段所在的网格和网格中心坐标
    vec2 gridCoord = fragPos / gridSize;
    vec2 gridCenter = (floor(gridCoord) + 0.5) * gridSize;
    
    // 计算片段到网格中心的距离
    float distanceToCenter = length(fragPos - gridCenter);
    
    // 如果距离超过点状半径，丢弃（创建点状虚线）
    if (distanceToCenter > dotRadius && fragColor.y > 0.5) {
        discard;
    }
    
    outColor = vec4(fragColor, 1.0);
}