summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2023-05-12 15:06:13 -0500
committersanine-a <sanine.not@pm.me>2023-05-12 15:06:13 -0500
commit759db92cf135aba21f0cbd17073d2f2e294fdf4d (patch)
tree8f0c875217ef2434d898c6c8df1775340f93a986
parent0d96ebc90c9740e7e66a70aa11168b11f49d220b (diff)
add nice builtin shaders
-rw-r--r--honey/asset/shader.lua43
-rw-r--r--honey/ecs/script.lua22
-rw-r--r--main.lua28
-rw-r--r--palette.pngbin0 -> 36541 bytes
-rw-r--r--starfield.pngbin0 -> 116815 bytes
-rw-r--r--starfield2.pngbin0 -> 88326 bytes
6 files changed, 90 insertions, 3 deletions
diff --git a/honey/asset/shader.lua b/honey/asset/shader.lua
index a23c17b..d1fecc4 100644
--- a/honey/asset/shader.lua
+++ b/honey/asset/shader.lua
@@ -140,4 +140,47 @@ clearCache = function()
end
+--===== builtin shaders =====--
+
+builtin["builtin.basic3d.vert"] = [[
+ #version 410 core
+ layout (location = 0) in vec3 in_position;
+ layout (location = 1) in vec3 in_normal;
+ layout (location = 2) in vec2 in_texture;
+
+ uniform mat4 model;
+ uniform mat4 view;
+ uniform mat4 projection;
+
+ out vec3 position;
+ out vec3 normal;
+ out vec2 tex;
+
+ void main()
+ {
+ gl_Position = projection * view * model * vec4(in_position, 1.0);
+
+ position = in_position;
+ normal = in_normal;
+ tex = in_texture;
+ }
+]]
+
+builtin["builtin.flat.frag"] = [[
+ #version 410 core
+
+ out vec4 frag_color;
+
+ in vec3 position;
+ in vec3 normal;
+ in vec2 tex;
+
+ uniform sampler2D surface;
+
+ void main()
+ {
+ frag_color = texture(surface, tex);
+ }
+]]
+
return module
diff --git a/honey/ecs/script.lua b/honey/ecs/script.lua
index 46af4fa..a9b7644 100644
--- a/honey/ecs/script.lua
+++ b/honey/ecs/script.lua
@@ -1,3 +1,5 @@
+local glfw = honey.glfw
+
local ecs = require 'honey.ecs.ecs'
local node = require 'honey.ecs.node'
@@ -27,6 +29,26 @@ dispatch = function(db, msg, data)
end
end
+--===== bind window events to script handlers =====--
+
+bindEvents = function(window, db)
+ glfw.SetFramebufferSizeCallback(window, function(w, width, height)
+ dispatch(db, "onFramebufferSize", {window=w, width=width, height=height})
+ end)
+
+ glfw.SetKeyCallback(window, function(w, key, scancode, action, mods)
+ dispatch(db, "onKey", {window=w, key=key, scancode=scancode, action=action, mods=mods})
+ end)
+
+ glfw.SetCursorPosCallback(window, function(w, xpos, ypos)
+ dispatch(db, "onCursorPos", {window=w, xpos=xpos, ypos=ypos})
+ end)
+
+ glfw.SetMouseButtonCallback(window, function(w, button, action, mods)
+ dispatch(db, "onMouseButton", {window=w, button=button, action=action, mods=mods})
+ end)
+end
+
--===== script system =====--
local script = ecs.System("script", function(db, dt, params)
diff --git a/main.lua b/main.lua
index c251071..60cc174 100644
--- a/main.lua
+++ b/main.lua
@@ -26,6 +26,26 @@ db:createEntityWithComponents{
},
}
+-- skybox
+db:createEntityWithComponents{
+ node = {
+ matrix = Mat4()
+ :identity(),
+ },
+ renderMesh = {
+ mesh = {
+ filename = "assets/skybox.obj",
+ index = 1,
+ },
+ uniforms = {
+ textures = {
+ surface = { filename = "starfield2.png" },
+ },
+ },
+ shader = { vertex = "builtin.basic3d.vert", fragment = "builtin.flat.frag" },
+ },
+}
+
-- mesh
db:createEntityWithComponents{
node = {
@@ -37,15 +57,17 @@ db:createEntityWithComponents{
filename = "assets/dodecahedron.obj",
index = 1,
},
- textures = {
- ourTexture = { filename = "assets/green-grass.jpg" },
+ uniforms = {
+ textures = {
+ ourTexture = { filename = "assets/green-grass.jpg" },
+ },
},
shader = { vertex="vertex.glsl", fragment="fragment.glsl" },
},
}
honey.loop(function(dt)
- gl.ClearColor(0.2, 0.4, 1.0, 1.0)
+ gl.ClearColor(0xa/0xff, 0x10/0xff, 0x1f/0xff, 1.0)
gl.Clear(gl.COLOR_BUFFER_BIT + gl.DEPTH_BUFFER_BIT + gl.STENCIL_BUFFER_BIT)
systems:update(dt)
end)
diff --git a/palette.png b/palette.png
new file mode 100644
index 0000000..52a1cbd
--- /dev/null
+++ b/palette.png
Binary files differ
diff --git a/starfield.png b/starfield.png
new file mode 100644
index 0000000..f67fc93
--- /dev/null
+++ b/starfield.png
Binary files differ
diff --git a/starfield2.png b/starfield2.png
new file mode 100644
index 0000000..c6a4853
--- /dev/null
+++ b/starfield2.png
Binary files differ