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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
#pragma shader "LitTest"
#pragma version 300 es
#pragma domain Lit
#pragma vertex
layout(location = 0) in vec3 a_position;
layout(location = 1) in vec4 a_color;
layout(location = 2) in vec2 a_texCoord;
layout(location = 3) in float a_texIndex;
// Deliberately still declared by hand, though the engine now injects this block:
// a shader written before that keeps compiling, and the pixel criteria this
// fixture backs are what proves it.
layout(std140) uniform FrameConstants {
mat4 u_projection;
};
out vec4 v_color;
out vec2 v_texCoord;
out highp vec2 v_worldPos;
void main() {
gl_Position = u_projection * vec4(a_position, 1.0);
v_color = a_color;
v_texCoord = a_texCoord;
// The batch path bakes the transform into the vertices, so a_position is already world-space.
v_worldPos = a_position.xy;
}
#pragma end
#pragma fragment
precision mediump float;
in vec4 v_color;
in vec2 v_texCoord;
in highp vec2 v_worldPos;
uniform sampler2D u_textures[8];
out vec4 fragColor;
// The LightConstants block + applyLighting2D() are injected by ShaderParser for
// `#pragma domain Lit`. A flat normal (no normal map in this fixture) faces the camera.
void main() {
vec4 base = texture(u_textures[0], v_texCoord) * v_color;
vec3 N = vec3(0.0, 0.0, 1.0);
vec3 lit = applyLighting2D(base.rgb, N, v_worldPos);
fragColor = vec4(lit, base.a);
}
#pragma end