summaryrefslogtreecommitdiff
path: root/crates/throwshade
diff options
context:
space:
mode:
Diffstat (limited to 'crates/throwshade')
-rw-r--r--crates/throwshade/Cargo.toml22
-rw-r--r--crates/throwshade/index.html1
-rw-r--r--crates/throwshade/src/assets/shaders/throwshade/frag.glsl26
-rw-r--r--crates/throwshade/src/assets/shaders/throwshade/vert.glsl22
-rw-r--r--crates/throwshade/src/lib.rs57
5 files changed, 128 insertions, 0 deletions
diff --git a/crates/throwshade/Cargo.toml b/crates/throwshade/Cargo.toml
new file mode 100644
index 0000000..0cc7516
--- /dev/null
+++ b/crates/throwshade/Cargo.toml
@@ -0,0 +1,22 @@
+[package]
+name = "throwshade"
+version.workspace = true
+edition.workspace = true
+authors.workspace = true
+
+[lib]
+crate-type = ["cdylib", "rlib"]
+
+[dependencies]
+# teleia = { path = "../teleia" } # engine
+teleia = { git = "https://github.com/lcolonq/teleia" } # engine
+glam = "*" # linear algebra
+glow = "*" # gl bindings
+bitflags = "*" # C-style bitwise flags
+rand = "=0.8.5" # rng
+log = "*" # logging
+lazy_static = "*" # global constants
+strum = {version = "*", features = ["derive"]} # utility macros for enums
+wasm-bindgen = "*" # wasm bindings
+wasm-bindgen-futures = "*" # interface with async javascript
+cfg-if = "*" # less verbose cfg \ No newline at end of file
diff --git a/crates/throwshade/index.html b/crates/throwshade/index.html
new file mode 100644
index 0000000..c3d8719
--- /dev/null
+++ b/crates/throwshade/index.html
@@ -0,0 +1 @@
+<link data-trunk rel="rust" data-wasm-opt="2" data-target-name="throwshade" />
diff --git a/crates/throwshade/src/assets/shaders/throwshade/frag.glsl b/crates/throwshade/src/assets/shaders/throwshade/frag.glsl
new file mode 100644
index 0000000..2acc78d
--- /dev/null
+++ b/crates/throwshade/src/assets/shaders/throwshade/frag.glsl
@@ -0,0 +1,26 @@
+#version 300 es
+precision highp float;
+
+in vec2 vertex_texcoord;
+out vec4 frag_color;
+
+uniform vec2 resolution;
+
+uniform float time;
+
+uniform float bpm;
+
+uniform vec2 cursor;
+
+uniform float chat_time;
+uniform float chat_biblicality;
+
+vec4 shade(vec2);
+
+void main() {
+ vec2 inverted = vec2(vertex_texcoord.x, 1.0 - vertex_texcoord.y);
+ frag_color = shade(inverted);
+ frag_color.a = clamp(frag_color.a * 0.5, 0.0, 0.5);
+}
+
+// "The Cutoff"
diff --git a/crates/throwshade/src/assets/shaders/throwshade/vert.glsl b/crates/throwshade/src/assets/shaders/throwshade/vert.glsl
new file mode 100644
index 0000000..e05bbb6
--- /dev/null
+++ b/crates/throwshade/src/assets/shaders/throwshade/vert.glsl
@@ -0,0 +1,22 @@
+#version 300 es
+precision highp float;
+
+out vec2 vertex_texcoord;
+
+void main() {
+ const vec2 positions[4] = vec2[](
+ vec2(-1, -1),
+ vec2(+1, -1),
+ vec2(-1, +1),
+ vec2(+1, +1)
+ );
+ const vec2 coords[4] = vec2[](
+ vec2(0, 0),
+ vec2(1, 0),
+ vec2(0, 1),
+ vec2(1, 1)
+ );
+
+ vertex_texcoord = coords[gl_VertexID];
+ gl_Position = vec4(positions[gl_VertexID], 0.0, 1.0);
+}
diff --git a/crates/throwshade/src/lib.rs b/crates/throwshade/src/lib.rs
new file mode 100644
index 0000000..976f2ae
--- /dev/null
+++ b/crates/throwshade/src/lib.rs
@@ -0,0 +1,57 @@
+use teleia::*;
+
+const VERT: &'static str = include_str!("assets/shaders/throwshade/vert.glsl");
+const FRAG: &'static str = include_str!("assets/shaders/throwshade/frag.glsl");
+
+pub struct ThrowShade {
+ pub tickset: u64,
+ pub timeset: f64,
+ pub shader: Option<shader::Shader>,
+}
+impl ThrowShade {
+ pub fn new() -> Self {
+ Self {
+ tickset: 0,
+ timeset: 0.0,
+ shader: None,
+ }
+ }
+ pub fn set(&mut self, ctx: &context::Context, st: &state::State, src: &str) -> Result<(), String> {
+ let fsrc = format!("{}\n{}\n", FRAG, src);
+ self.tickset = st.tick;
+ if let Ok(dur) = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) {
+ self.timeset = dur.as_secs_f64();
+ log::info!("the time: {}", self.timeset);
+ }
+ if let Some(s) = &mut self.shader {
+ s.replace(ctx, VERT, &fsrc)?;
+ } else {
+ self.shader = Some(shader::Shader::new_helper(ctx, VERT, &fsrc)?);
+ }
+ Ok(())
+ }
+}
+
+cfg_if::cfg_if! {
+ if #[cfg(target_arch = "wasm32")] {
+ struct Game {}
+ impl Game {
+ pub async fn new(_ctx: &context::Context) -> Self {
+ Self {}
+ }
+ }
+ impl state::Game for Game {
+ fn render(&mut self, ctx: &context::Context, st: &mut state::State) -> Option<()> {
+ ctx.clear_color(glam::Vec4::new(1.0, 0.0, 0.0, 1.0));
+ ctx.clear();
+ Some(())
+ }
+ }
+
+ use wasm_bindgen::prelude::*;
+ #[wasm_bindgen]
+ pub async fn main_js() {
+ teleia::run(480, 270, Game::new).await;
+ }
+ }
+}