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.

feat: Add .esshader files for all engine shaders

esengine55936a10879d
diff --git a/assets/shaders/batch.esshader b/assets/shaders/batch.esshader
new file mode 100644
index 000000000..6da808df8
--- /dev/null
+++ b/assets/shaders/batch.esshader
@@ -0,0 +1,32 @@
+#pragma shader "Batch"
+
+#pragma vertex
+attribute vec2 a_position;
+attribute vec2 a_texCoord;
+attribute vec4 a_color;
+
+uniform mat4 u_projection;
+
+varying vec2 v_texCoord;
+varying vec4 v_color;
+
+void main() {
+ gl_Position = u_projection * vec4(a_position, 0.0, 1.0);
+ v_texCoord = a_texCoord;
+ v_color = a_color;
+}
+#pragma end
+
+#pragma fragment
+precision mediump float;
+
+uniform sampler2D u_texture;
+
+varying vec2 v_texCoord;
+varying vec4 v_color;
+
+void main() {
+ vec4 texColor = texture2D(u_texture, v_texCoord);
+ gl_FragColor = texColor * v_color;
+}
+#pragma end
diff --git a/assets/shaders/color.esshader b/assets/shaders/color.esshader
new file mode 100644
index 000000000..94fc17aca
--- /dev/null
+++ b/assets/shaders/color.esshader
@@ -0,0 +1,22 @@
+#pragma shader "Color"
+
+#pragma vertex
+attribute vec2 a_position;
+
+uniform mat4 u_projection;
+uniform mat4 u_model;
+
+void main() {
+ gl_Position = u_projection * u_model * vec4(a_position, 0.0, 1.0);
+}
+#pragma end
+
+#pragma fragment
+precision mediump float;
+
+uniform vec4 u_color;
+
+void main() {
+ gl_FragColor = u_color;
+}
+#pragma end
diff --git a/assets/shaders/gizmo.esshader b/assets/shaders/gizmo.esshader
new file mode 100644
index 000000000..fc9b8b535
--- /dev/null
+++ b/assets/shaders/gizmo.esshader
@@ -0,0 +1,26 @@
+#pragma shader "Gizmo"
+
+#pragma vertex
+attribute vec3 a_position;
+attribute vec4 a_color;
+
+uniform mat4 u_viewProj;
+uniform mat4 u_model;
+
+varying vec4 v_color;
+
+void main() {
+ gl_Position = u_viewProj * u_model * vec4(a_position, 1.0);
+ v_color = a_color;
+}
+#pragma end
+
+#pragma fragment
+precision mediump float;
+
+varying vec4 v_color;
+
+void main() {
+ gl_FragColor = v_color;
+}
+#pragma end
diff --git a/assets/shaders/sprite.esshader b/assets/shaders/sprite.esshader
new file mode 100644
index 000000000..ad82cb755
--- /dev/null
+++ b/assets/shaders/sprite.esshader
@@ -0,0 +1,30 @@
+#pragma shader "Sprite"
+
+#pragma vertex
+attribute vec2 a_position;
+attribute vec2 a_texCoord;
+
+uniform mat4 u_projection;
+uniform mat4 u_model;
+
+varying vec2 v_texCoord;
+
+void main() {
+ gl_Position = u_projection * u_model * vec4(a_position, 0.0, 1.0);
+ v_texCoord = a_texCoord;
+}
+#pragma end
+
+#pragma fragment
+precision mediump float;
+
+uniform sampler2D u_texture;
+uniform vec4 u_color;
+
+varying vec2 v_texCoord;
+
+void main() {
+ vec4 texColor = texture2D(u_texture, v_texCoord);
+ gl_FragColor = texColor * u_color;
+}
+#pragma end
diff --git a/assets/shaders/ui.esshader b/assets/shaders/ui.esshader
new file mode 100644
index 000000000..7b2282dd0
--- /dev/null
+++ b/assets/shaders/ui.esshader
@@ -0,0 +1,44 @@
+#pragma shader "UI"
+
+#pragma vertex
+attribute vec2 a_position;
+attribute vec2 a_texCoord;
+attribute vec4 a_color;
+
+uniform mat4 u_projection;
+
+varying vec2 v_texCoord;
+varying vec4 v_color;
+
+void main() {
+ gl_Position = u_projection * vec4(a_position, 0.0, 1.0);
+ v_texCoord = a_texCoord;
+ v_color = a_color;
+}
+#pragma end
+
+#pragma fragment
+precision mediump float;
+
+uniform sampler2D u_texture;
+uniform int u_useTexture;
+uniform int u_useSDF;
+uniform float u_sdfSmoothing;
+
+varying vec2 v_texCoord;
+varying vec4 v_color;
+
+void main() {
+ if (u_useTexture == 1) {
+ if (u_useSDF == 1) {
+ float dist = texture2D(u_texture, v_texCoord).a;
+ float alpha = smoothstep(0.5 - u_sdfSmoothing, 0.5 + u_sdfSmoothing, dist);
+ gl_FragColor = vec4(v_color.rgb, v_color.a * alpha);
+ } else {
+ gl_FragColor = texture2D(u_texture, v_texCoord) * v_color;
+ }
+ } else {
+ gl_FragColor = v_color;
+ }
+}
+#pragma end