From 838c1c0c6fed73333254d7caa204e2fe9f3c1620 Mon Sep 17 00:00:00 2001 From: Cassie Jones Date: Thu, 30 Jan 2020 16:28:55 -0500 Subject: [PATCH 1/1] =?utf8?q?Initial=20commit,=20stymied=20by=20L=C3=96VR?= =?utf8?q?=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This adds a main test program and a simple (currently broken) sprite billboarding shader. It doesn't have much going on, because I'm running into a LÖVR bug with sending compute ShaderBlock data on Oculus Quest. --- .vscode/tasks.json | 14 ++++++++++++++ main.lua | 34 ++++++++++++++++++++++++++++++++++ shaders/particles.frag | 3 +++ shaders/particles.vert | 14 ++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 .vscode/tasks.json create mode 100644 main.lua create mode 100644 shaders/particles.frag create mode 100644 shaders/particles.vert diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..50ce987 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,14 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "lovr-sync", + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..5ca544e --- /dev/null +++ b/main.lua @@ -0,0 +1,34 @@ +local mat4 = lovr.math.mat4 + +local features +local shaders = {} +local blocks = {} +local meshes = {} + +function lovr.load() + features = lovr.graphics.getFeatures() + shaders.particles = lovr.graphics.newShader("shaders/particles.vert", "shaders/particles.frag") + blocks.particles = lovr.graphics.newShaderBlock("compute", { + particlePos = {"vec4", 1024}, + }, { readable = true, writable = true }) + shaders.particles:sendBlock('particleData', blocks.particles) + meshes.particle = lovr.graphics.newMesh( + { + {'vertPosition', 'float', 2}, + }, + {{1, 1}, {1, -1}, {-1, -1}, {-1, 1}}, + "triangles", "static" + ) + meshes.particle:setVertexMap({3, 2, 1, 4, 3, 1}) +end + +function lovr.draw() + lovr.graphics.clear() + lovr.graphics.setColor(0, 0.5, 1) + local x, y, z = lovr.headset.getPose("head") + shaders.particles:send("headPos", {x, y, z}) + + blocks.particles:send("particlePos", {{0, 2, -2, 0}, {-1, 1, -4, 0}}) + lovr.graphics.setShader(shaders.particles) + meshes.particle:draw(mat4(), 2) +end diff --git a/shaders/particles.frag b/shaders/particles.frag new file mode 100644 index 0000000..fff0f2a --- /dev/null +++ b/shaders/particles.frag @@ -0,0 +1,3 @@ +vec4 color(vec4 graphicsColor, sampler2D image, vec2 uv) { + return graphicsColor; +} diff --git a/shaders/particles.vert b/shaders/particles.vert new file mode 100644 index 0000000..3ff33f8 --- /dev/null +++ b/shaders/particles.vert @@ -0,0 +1,14 @@ +in vec2 vertPosition; +uniform vec3 headPos; +layout(std430) buffer particleData { vec4 particlePos[2]; }; + +vec4 position(mat4 projection, mat4 transform, vec4 vertex) { + vec3 pos = particlePos[gl_InstanceID].xyz; + vec3 forward = normalize(pos - headPos); + vec3 right = normalize(cross(forward, vec3(0, 1, 0))); + vec3 up = cross(right, forward); + mat2 frame = mat2(up, right); + // vec3 vert = pos + vec3(frame * vertPosition * 0.3, 0); + vec3 vert = pos + vec3(vertPosition, 0); + return projection * transform * vec4(vert, 1); +} -- 2.47.0