/**
 * GLSL shaders for cloth rendering on WebGL.
 * Replicates the visual output of the WGSL cloth shaders:
 * checkerboard pattern with Lambertian lighting.
 */

export const CLOTH_VERTEX_SHADER_GLSL = `
    precision highp float;

    attribute vec3 position;
    attribute vec2 uv;

    uniform mat4 viewProjection;

    varying vec2 vUV;
    varying vec3 vWorldPos;

    void main() {
        vUV = uv;
        vWorldPos = position;
        gl_Position = viewProjection * vec4(position, 1.0);
    }
`;

export const CLOTH_FRAGMENT_SHADER_GLSL = `
    #extension GL_OES_standard_derivatives : enable
    precision highp float;

    varying vec2 vUV;
    varying vec3 vWorldPos;

    void main() {
        vec3 dx = dFdx(vWorldPos);
        vec3 dy = dFdy(vWorldPos);
        vec3 normal = normalize(cross(dx, dy));

        vec3 lightDir = normalize(vec3(1.0, 1.0, 0.5));
        float diffuse = max(0.0, abs(dot(normal, lightDir)));
        float ambient = 0.3;
        float lightIntensity = ambient + (diffuse * 0.7);

        float grid = mod(floor(vUV.x * 20.0) + floor(vUV.y * 20.0), 2.0);
        vec3 baseColor = mix(vec3(0.8, 0.4, 0.15), vec3(0.9, 0.5, 0.2), grid);
        vec3 finalColor = baseColor * lightIntensity;

        gl_FragColor = vec4(finalColor, 1.0);
    }
`;
