{"size": 845, "ext": "js", "max_stars_repo_path": "fragmentShader.glsl.js", "max_stars_repo_name": "tschie/geo-clipmap", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "fragmentShader.glsl.js", "max_issues_repo_name": "tschie/geo-clipmap", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "fragmentShader.glsl.js", "max_forks_repo_name": "tschie/geo-clipmap", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.1379310345, "max_line_length": 73, "alphanum_fraction": 0.6485207101}
// language=glsl
export const terrainFragmentShader = `
precision mediump float;

varying vec3 vWorldPos;
varying vec3 vNormal;
varying float vDiscard;

uniform sampler2D grass;
uniform vec3 sun;

void main() {
    if (vDiscard > 0.0) {
        discard;
    } else {
        vec3 light = normalize(sun);
        float brightness = max(dot(vNormal, light), 0.4);
        vec3 blendAxes = abs(vNormal);
        vec3 uvSample = vWorldPos / 4.0; // texture fills 4x4 world units
        vec4 grassX = texture2D(grass, uvSample.yz) * blendAxes.x;
        vec4 grassY = texture2D(grass, uvSample.xz) * blendAxes.y;
        vec4 grassZ = texture2D(grass, uvSample.xy) * blendAxes.z;
        vec4 grassColor = grassX + grassY + grassZ;
        vec3 diffuse = brightness * normalize(grassColor.xyz);
        gl_FragColor = vec4(diffuse, 1.0);
    }
}
`;
