Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

1.2 KB
Raw Blame
#pragma shader "MeshLitMaterial"
#pragma version 300 es
#pragma domain Lit

// Fragment only: the engine owns the vertex stage, and MESH_NORMALS is how it
// says this draw's geometry carries normals — a material asks for them the same
// way it asks for any other feature.
#pragma fragment
precision mediump float;

in vec4 v_color;
in vec2 v_texCoord;
in highp vec2 v_worldPos;
#ifdef MESH_NORMALS
in highp vec3 v_worldNormal;
in highp vec3 v_worldXYZ;
#endif

out vec4 fragColor;

// Red, so a frame drawn by the engine's own mesh shader (the fallback when a
// variant fails to compile) cannot pass for this one: it would be white.
void main() {
#ifdef MESH_NORMALS
    highp vec3 albedo = v_color.rgb * vec3(1.0, 0.0, 0.0);
    fragColor = vec4(applyLighting2D(albedo, normalize(v_worldNormal), v_worldPos), v_color.a);
#else
    fragColor = v_color;
#endif
}
#pragma end

#pragma fragment wgsl
@fragment fn fs_main(v : VSOut) -> @location(0) vec4f {
#ifdef MESH_NORMALS
    let albedo = v.v_color.rgb * vec3f(1.0, 0.0, 0.0);
    return vec4f(applyLighting2D(albedo, normalize(v.v_worldNormal), v.v_worldPos), v.v_color.a);
#else
    return v.v_color;
#endif
}
#pragma end