Compare commits

..

9 Commits

Author SHA1 Message Date
28ffc28dca buffer binding array? 2023-09-05 12:02:54 -07:00
7b5ce3feb1 dedicated staging belt 2023-09-05 12:02:54 -07:00
d2fdb5d94b entity_id trash 2023-09-05 12:02:54 -07:00
b68dfa791d array + instance_index is not the way 2023-09-05 12:02:54 -07:00
2df929c15f no fragment 2023-09-05 12:02:54 -07:00
1746d5445c add entity CFrames 2023-09-01 15:24:45 -07:00
5dbe207d39 comment on value 2023-09-01 14:57:38 -07:00
a853eb965e rename uniform_buf to camera_buf 2023-09-01 14:57:04 -07:00
ba2bab562f add suzanne 2023-09-01 14:22:12 -07:00
13 changed files with 1150 additions and 5579 deletions

257
Cargo.lock generated
View File

@@ -157,12 +157,6 @@ dependencies = [
"rustc-demangle", "rustc-demangle",
] ]
[[package]]
name = "base64"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]] [[package]]
name = "bit-set" name = "bit-set"
version = "0.5.3" version = "0.5.3"
@@ -190,35 +184,12 @@ version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
[[package]]
name = "blake3"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "199c42ab6972d92c9f8995f086273d25c42fc0f7b2a1fcefba465c1352d25ba5"
dependencies = [
"arrayref",
"arrayvec",
"cc",
"cfg-if",
"constant_time_eq",
"digest",
]
[[package]] [[package]]
name = "block" name = "block"
version = "0.1.6" version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]] [[package]]
name = "block-sys" name = "block-sys"
version = "0.1.0-beta.1" version = "0.1.0-beta.1"
@@ -331,12 +302,6 @@ dependencies = [
"crossbeam-utils", "crossbeam-utils",
] ]
[[package]]
name = "constant_time_eq"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2"
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.3" version = "0.9.3"
@@ -395,16 +360,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]] [[package]]
name = "d3d12" name = "d3d12"
version = "0.7.0" version = "0.7.0"
@@ -427,17 +382,6 @@ dependencies = [
"enum_primitive", "enum_primitive",
] ]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]] [[package]]
name = "dispatch" name = "dispatch"
version = "0.2.0" version = "0.2.0"
@@ -611,16 +555,6 @@ dependencies = [
"waker-fn", "waker-fn",
] ]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.10" version = "0.2.10"
@@ -888,26 +822,6 @@ version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "lz4"
version = "1.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e9e2dd86df36ce760a60f6ff6ad526f7ba1f14ba0356f8254fb6905e6494df1"
dependencies = [
"libc",
"lz4-sys",
]
[[package]]
name = "lz4-sys"
version = "1.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57d27b317e207b10f69f5e75494119e391a96f48861ae870d1da6edac98ca900"
dependencies = [
"cc",
"libc",
]
[[package]] [[package]]
name = "malloc_buf" name = "malloc_buf"
version = "0.0.6" version = "0.0.6"
@@ -1284,12 +1198,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2" checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "1.3.1" version = "1.3.1"
@@ -1314,19 +1222,6 @@ name = "profiling"
version = "1.0.9" version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46b2164ebdb1dfeec5e337be164292351e11daf63a05174c6776b2f47460f0c9" checksum = "46b2164ebdb1dfeec5e337be164292351e11daf63a05174c6776b2f47460f0c9"
dependencies = [
"profiling-procmacros",
]
[[package]]
name = "profiling-procmacros"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74c55e9e629af5298a40e0fa106435b2da30484c4ec76b41d19bc4d00dd8b903"
dependencies = [
"quote",
"syn 2.0.29",
]
[[package]] [[package]]
name = "quote" name = "quote"
@@ -1337,36 +1232,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]] [[package]]
name = "range-alloc" name = "range-alloc"
version = "0.1.3" version = "0.1.3"
@@ -1379,69 +1244,6 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
[[package]]
name = "rbx_binary"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e50573021d04b680018955662eba7dc4aac3de92219231798f6c9b41e38ab01"
dependencies = [
"log",
"lz4",
"profiling",
"rbx_dom_weak",
"rbx_reflection",
"rbx_reflection_database",
"thiserror",
]
[[package]]
name = "rbx_dom_weak"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "161729449bbb0cfa657ce7bcca6a160d0af06d8b8d9efdc9abe14735dccacdb9"
dependencies = [
"rbx_types",
"serde",
]
[[package]]
name = "rbx_reflection"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08bd48487192046fec8f805f3fa29f3d7d5beb9890b0859b1a92bd8aff580343"
dependencies = [
"rbx_types",
"serde",
"thiserror",
]
[[package]]
name = "rbx_reflection_database"
version = "0.2.7+roblox-588"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1be6cf674182806f11ad4899dd1feafe977591f1ae035ae05a58d4b74e487276"
dependencies = [
"lazy_static",
"rbx_reflection",
"rmp-serde",
"serde",
]
[[package]]
name = "rbx_types"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "070106e926b8ae54c7bc443e5db4d868d7f0af51c1d7cfd7efe1364c1753d8a3"
dependencies = [
"base64",
"bitflags 1.3.2",
"blake3",
"lazy_static",
"rand",
"serde",
"thiserror",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.3.5" version = "0.3.5"
@@ -1486,28 +1288,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b" checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b"
[[package]]
name = "rmp"
version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20"
dependencies = [
"byteorder",
"num-traits 0.2.16",
"paste",
]
[[package]]
name = "rmp-serde"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a"
dependencies = [
"byteorder",
"rmp",
"serde",
]
[[package]] [[package]]
name = "rustc-demangle" name = "rustc-demangle"
version = "0.1.23" version = "0.1.23"
@@ -1558,26 +1338,6 @@ dependencies = [
"tiny-skia", "tiny-skia",
] ]
[[package]]
name = "serde"
version = "1.0.188"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.29",
]
[[package]] [[package]]
name = "simd-adler32" name = "simd-adler32"
version = "0.3.7" version = "0.3.7"
@@ -1645,7 +1405,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "strafe-client" name = "strafe-client"
version = "0.4.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-executor", "async-executor",
"bytemuck", "bytemuck",
@@ -1655,9 +1415,6 @@ dependencies = [
"log", "log",
"obj", "obj",
"pollster", "pollster",
"rbx_binary",
"rbx_dom_weak",
"rbx_reflection_database",
"wgpu", "wgpu",
"winit", "winit",
] ]
@@ -1668,12 +1425,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731"
[[package]]
name = "subtle"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.109" version = "1.0.109"
@@ -1773,12 +1524,6 @@ version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33" checksum = "a464a4b34948a5f67fddd2b823c62d9d92e44be75058b99939eae6c5b6960b33"
[[package]]
name = "typenum"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.11" version = "1.0.11"

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "strafe-client" name = "strafe-client"
version = "0.4.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -14,13 +14,5 @@ glam = "0.24.1"
log = "0.4.20" log = "0.4.20"
obj = "0.10.2" obj = "0.10.2"
pollster = "0.3.0" pollster = "0.3.0"
rbx_binary = "0.7.1"
rbx_dom_weak = "2.5.0"
rbx_reflection_database = "0.2.7"
wgpu = "0.17.0" wgpu = "0.17.0"
winit = "0.28.6" winit = "0.28.6"
[profile.release]
lto = true
strip = true
codegen-units = 1

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,419 +1,443 @@
use std::future::Future; use std::future::Future;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use std::str::FromStr; use std::str::FromStr;
#[cfg(not(target_arch = "wasm32"))]
use std::time::Instant;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas}; use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas};
use winit::{ use winit::{
event::{self, WindowEvent, DeviceEvent}, event::{self, WindowEvent},
event_loop::{ControlFlow, EventLoop}, event_loop::{ControlFlow, EventLoop},
}; };
#[allow(dead_code)] #[allow(dead_code)]
pub fn cast_slice<T>(data: &[T]) -> &[u8] { pub fn cast_slice<T>(data: &[T]) -> &[u8] {
use std::{mem::size_of, slice::from_raw_parts}; use std::{mem::size_of, slice::from_raw_parts};
unsafe { from_raw_parts(data.as_ptr() as *const u8, data.len() * size_of::<T>()) } unsafe { from_raw_parts(data.as_ptr() as *const u8, data.len() * size_of::<T>()) }
} }
#[allow(dead_code)] #[allow(dead_code)]
pub enum ShaderStage { pub enum ShaderStage {
Vertex, Vertex,
Fragment, Fragment,
Compute, Compute,
} }
pub trait Example: 'static + Sized { pub trait Example: 'static + Sized {
fn optional_features() -> wgpu::Features { fn optional_features() -> wgpu::Features {
wgpu::Features::empty() wgpu::Features::empty()
} }
fn required_features() -> wgpu::Features { fn required_features() -> wgpu::Features {
wgpu::Features::empty() wgpu::Features::empty()
} }
fn required_downlevel_capabilities() -> wgpu::DownlevelCapabilities { fn required_downlevel_capabilities() -> wgpu::DownlevelCapabilities {
wgpu::DownlevelCapabilities { wgpu::DownlevelCapabilities {
flags: wgpu::DownlevelFlags::empty(), flags: wgpu::DownlevelFlags::empty(),
shader_model: wgpu::ShaderModel::Sm5, shader_model: wgpu::ShaderModel::Sm5,
..wgpu::DownlevelCapabilities::default() ..wgpu::DownlevelCapabilities::default()
} }
} }
fn required_limits() -> wgpu::Limits { fn required_limits() -> wgpu::Limits {
wgpu::Limits::downlevel_webgl2_defaults() // These downlevel limits will allow the code to run on all possible hardware wgpu::Limits::downlevel_webgl2_defaults() // These downlevel limits will allow the code to run on all possible hardware
} }
fn init( fn init(
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
adapter: &wgpu::Adapter, adapter: &wgpu::Adapter,
device: &wgpu::Device, device: &wgpu::Device,
queue: &wgpu::Queue, queue: &wgpu::Queue,
) -> Self; ) -> Self;
fn resize( fn resize(
&mut self, &mut self,
config: &wgpu::SurfaceConfiguration, config: &wgpu::SurfaceConfiguration,
device: &wgpu::Device, device: &wgpu::Device,
queue: &wgpu::Queue, queue: &wgpu::Queue,
); );
fn update(&mut self, device: &wgpu::Device, event: WindowEvent); fn update(&mut self, event: WindowEvent);
fn device_event(&mut self, event: DeviceEvent); fn move_mouse(&mut self, delta: (f64,f64));
fn render( fn render(
&mut self, &mut self,
view: &wgpu::TextureView, view: &wgpu::TextureView,
device: &wgpu::Device, device: &wgpu::Device,
queue: &wgpu::Queue, queue: &wgpu::Queue,
spawner: &Spawner, spawner: &Spawner,
); );
} }
struct Setup { struct Setup {
window: winit::window::Window, window: winit::window::Window,
event_loop: EventLoop<()>, event_loop: EventLoop<()>,
instance: wgpu::Instance, instance: wgpu::Instance,
size: winit::dpi::PhysicalSize<u32>, size: winit::dpi::PhysicalSize<u32>,
surface: wgpu::Surface, surface: wgpu::Surface,
adapter: wgpu::Adapter, adapter: wgpu::Adapter,
device: wgpu::Device, device: wgpu::Device,
queue: wgpu::Queue, queue: wgpu::Queue,
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
offscreen_canvas_setup: Option<OffscreenCanvasSetup>, offscreen_canvas_setup: Option<OffscreenCanvasSetup>,
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
struct OffscreenCanvasSetup { struct OffscreenCanvasSetup {
offscreen_canvas: OffscreenCanvas, offscreen_canvas: OffscreenCanvas,
bitmap_renderer: ImageBitmapRenderingContext, bitmap_renderer: ImageBitmapRenderingContext,
} }
async fn setup<E: Example>(title: &str) -> Setup { async fn setup<E: Example>(title: &str) -> Setup {
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
{ {
env_logger::init(); env_logger::init();
}; };
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();
let mut builder = winit::window::WindowBuilder::new(); let mut builder = winit::window::WindowBuilder::new();
builder = builder.with_title(title); builder = builder.with_title(title);
#[cfg(windows_OFF)] // TODO #[cfg(windows_OFF)] // TODO
{ {
use winit::platform::windows::WindowBuilderExtWindows; use winit::platform::windows::WindowBuilderExtWindows;
builder = builder.with_no_redirection_bitmap(true); builder = builder.with_no_redirection_bitmap(true);
} }
let window = builder.build(&event_loop).unwrap(); let window = builder.build(&event_loop).unwrap();
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
{ {
use winit::platform::web::WindowExtWebSys; use winit::platform::web::WindowExtWebSys;
let query_string = web_sys::window().unwrap().location().search().unwrap(); let query_string = web_sys::window().unwrap().location().search().unwrap();
let level: log::Level = parse_url_query_string(&query_string, "RUST_LOG") let level: log::Level = parse_url_query_string(&query_string, "RUST_LOG")
.and_then(|x| x.parse().ok()) .and_then(|x| x.parse().ok())
.unwrap_or(log::Level::Error); .unwrap_or(log::Level::Error);
console_log::init_with_level(level).expect("could not initialize logger"); console_log::init_with_level(level).expect("could not initialize logger");
std::panic::set_hook(Box::new(console_error_panic_hook::hook)); std::panic::set_hook(Box::new(console_error_panic_hook::hook));
// On wasm, append the canvas to the document body // On wasm, append the canvas to the document body
web_sys::window() web_sys::window()
.and_then(|win| win.document()) .and_then(|win| win.document())
.and_then(|doc| doc.body()) .and_then(|doc| doc.body())
.and_then(|body| { .and_then(|body| {
body.append_child(&web_sys::Element::from(window.canvas())) body.append_child(&web_sys::Element::from(window.canvas()))
.ok() .ok()
}) })
.expect("couldn't append canvas to document body"); .expect("couldn't append canvas to document body");
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
let mut offscreen_canvas_setup: Option<OffscreenCanvasSetup> = None; let mut offscreen_canvas_setup: Option<OffscreenCanvasSetup> = None;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
{ {
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
use winit::platform::web::WindowExtWebSys; use winit::platform::web::WindowExtWebSys;
let query_string = web_sys::window().unwrap().location().search().unwrap(); let query_string = web_sys::window().unwrap().location().search().unwrap();
if let Some(offscreen_canvas_param) = if let Some(offscreen_canvas_param) =
parse_url_query_string(&query_string, "offscreen_canvas") parse_url_query_string(&query_string, "offscreen_canvas")
{ {
if FromStr::from_str(offscreen_canvas_param) == Ok(true) { if FromStr::from_str(offscreen_canvas_param) == Ok(true) {
log::info!("Creating OffscreenCanvasSetup"); log::info!("Creating OffscreenCanvasSetup");
let offscreen_canvas = let offscreen_canvas =
OffscreenCanvas::new(1024, 768).expect("couldn't create OffscreenCanvas"); OffscreenCanvas::new(1024, 768).expect("couldn't create OffscreenCanvas");
let bitmap_renderer = window let bitmap_renderer = window
.canvas() .canvas()
.get_context("bitmaprenderer") .get_context("bitmaprenderer")
.expect("couldn't create ImageBitmapRenderingContext (Result)") .expect("couldn't create ImageBitmapRenderingContext (Result)")
.expect("couldn't create ImageBitmapRenderingContext (Option)") .expect("couldn't create ImageBitmapRenderingContext (Option)")
.dyn_into::<ImageBitmapRenderingContext>() .dyn_into::<ImageBitmapRenderingContext>()
.expect("couldn't convert into ImageBitmapRenderingContext"); .expect("couldn't convert into ImageBitmapRenderingContext");
offscreen_canvas_setup = Some(OffscreenCanvasSetup { offscreen_canvas_setup = Some(OffscreenCanvasSetup {
offscreen_canvas, offscreen_canvas,
bitmap_renderer, bitmap_renderer,
}) })
} }
} }
}; };
log::info!("Initializing the surface..."); log::info!("Initializing the surface...");
let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(); let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default();
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends, backends,
dx12_shader_compiler, dx12_shader_compiler,
}); });
let (size, surface) = unsafe { let (size, surface) = unsafe {
let size = window.inner_size(); let size = window.inner_size();
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] #[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))]
let surface = instance.create_surface(&window).unwrap(); let surface = instance.create_surface(&window).unwrap();
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
let surface = { let surface = {
if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup { if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup {
log::info!("Creating surface from OffscreenCanvas"); log::info!("Creating surface from OffscreenCanvas");
instance.create_surface_from_offscreen_canvas( instance.create_surface_from_offscreen_canvas(
offscreen_canvas_setup.offscreen_canvas.clone(), offscreen_canvas_setup.offscreen_canvas.clone(),
) )
} else { } else {
instance.create_surface(&window) instance.create_surface(&window)
} }
} }
.unwrap(); .unwrap();
(size, surface) (size, surface)
}; };
let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, Some(&surface)) let adapter = wgpu::util::initialize_adapter_from_env_or_default(&instance, Some(&surface))
.await .await
.expect("No suitable GPU adapters found on the system!"); .expect("No suitable GPU adapters found on the system!");
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
{ {
let adapter_info = adapter.get_info(); let adapter_info = adapter.get_info();
println!("Using {} ({:?})", adapter_info.name, adapter_info.backend); println!("Using {} ({:?})", adapter_info.name, adapter_info.backend);
} }
let optional_features = E::optional_features(); let optional_features = E::optional_features();
let required_features = E::required_features(); let required_features = E::required_features();
let adapter_features = adapter.features(); let adapter_features = adapter.features();
assert!( assert!(
adapter_features.contains(required_features), adapter_features.contains(required_features),
"Adapter does not support required features for this example: {:?}", "Adapter does not support required features for this example: {:?}",
required_features - adapter_features required_features - adapter_features
); );
let required_downlevel_capabilities = E::required_downlevel_capabilities(); let required_downlevel_capabilities = E::required_downlevel_capabilities();
let downlevel_capabilities = adapter.get_downlevel_capabilities(); let downlevel_capabilities = adapter.get_downlevel_capabilities();
assert!( assert!(
downlevel_capabilities.shader_model >= required_downlevel_capabilities.shader_model, downlevel_capabilities.shader_model >= required_downlevel_capabilities.shader_model,
"Adapter does not support the minimum shader model required to run this example: {:?}", "Adapter does not support the minimum shader model required to run this example: {:?}",
required_downlevel_capabilities.shader_model required_downlevel_capabilities.shader_model
); );
assert!( assert!(
downlevel_capabilities downlevel_capabilities
.flags .flags
.contains(required_downlevel_capabilities.flags), .contains(required_downlevel_capabilities.flags),
"Adapter does not support the downlevel capabilities required to run this example: {:?}", "Adapter does not support the downlevel capabilities required to run this example: {:?}",
required_downlevel_capabilities.flags - downlevel_capabilities.flags required_downlevel_capabilities.flags - downlevel_capabilities.flags
); );
// Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface. // Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface.
let needed_limits = E::required_limits().using_resolution(adapter.limits()); let needed_limits = E::required_limits().using_resolution(adapter.limits());
let trace_dir = std::env::var("WGPU_TRACE"); let trace_dir = std::env::var("WGPU_TRACE");
let (device, queue) = adapter let (device, queue) = adapter
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
label: None, label: None,
features: (optional_features & adapter_features) | required_features, features: (optional_features & adapter_features) | required_features,
limits: needed_limits, limits: needed_limits,
}, },
trace_dir.ok().as_ref().map(std::path::Path::new), trace_dir.ok().as_ref().map(std::path::Path::new),
) )
.await .await
.expect("Unable to find a suitable GPU adapter!"); .expect("Unable to find a suitable GPU adapter!");
Setup { Setup {
window, window,
event_loop, event_loop,
instance, instance,
size, size,
surface, surface,
adapter, adapter,
device, device,
queue, queue,
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
offscreen_canvas_setup, offscreen_canvas_setup,
} }
} }
fn start<E: Example>( fn start<E: Example>(
#[cfg(not(target_arch = "wasm32"))] Setup { #[cfg(not(target_arch = "wasm32"))] Setup {
window, window,
event_loop, event_loop,
instance, instance,
size, size,
surface, surface,
adapter, adapter,
device, device,
queue, queue,
}: Setup, }: Setup,
#[cfg(target_arch = "wasm32")] Setup { #[cfg(target_arch = "wasm32")] Setup {
window, window,
event_loop, event_loop,
instance, instance,
size, size,
surface, surface,
adapter, adapter,
device, device,
queue, queue,
offscreen_canvas_setup, offscreen_canvas_setup,
}: Setup, }: Setup,
) { ) {
let spawner = Spawner::new(); let spawner = Spawner::new();
let mut config = surface let mut config = surface
.get_default_config(&adapter, size.width, size.height) .get_default_config(&adapter, size.width, size.height)
.expect("Surface isn't supported by the adapter."); .expect("Surface isn't supported by the adapter.");
let surface_view_format = config.format.add_srgb_suffix(); let surface_view_format = config.format.add_srgb_suffix();
config.view_formats.push(surface_view_format); config.view_formats.push(surface_view_format);
surface.configure(&device, &config); surface.configure(&device, &config);
log::info!("Initializing the example..."); log::info!("Initializing the example...");
let mut example = E::init(&config, &adapter, &device, &queue); let mut example = E::init(&config, &adapter, &device, &queue);
log::info!("Entering render loop..."); #[cfg(not(target_arch = "wasm32"))]
event_loop.run(move |event, _, control_flow| { let mut last_frame_inst = Instant::now();
let _ = (&instance, &adapter); // force ownership by the closure #[cfg(not(target_arch = "wasm32"))]
*control_flow = if cfg!(feature = "metal-auto-capture") { let (mut frame_count, mut accum_time) = (0, 0.0);
ControlFlow::Exit
} else {
ControlFlow::Poll
};
match event {
event::Event::RedrawEventsCleared => {
#[cfg(not(target_arch = "wasm32"))]
spawner.run_until_stalled();
window.request_redraw(); log::info!("Entering render loop...");
} event_loop.run(move |event, _, control_flow| {
event::Event::WindowEvent { let _ = (&instance, &adapter); // force ownership by the closure
event: *control_flow = if cfg!(feature = "metal-auto-capture") {
WindowEvent::Resized(size) ControlFlow::Exit
| WindowEvent::ScaleFactorChanged { } else {
new_inner_size: &mut size, ControlFlow::Poll
.. };
}, match event {
.. event::Event::RedrawEventsCleared => {
} => { #[cfg(not(target_arch = "wasm32"))]
// Once winit is fixed, the detection conditions here can be removed. spawner.run_until_stalled();
// https://github.com/rust-windowing/winit/issues/2876
let max_dimension = adapter.limits().max_texture_dimension_2d;
if size.width > max_dimension || size.height > max_dimension {
log::warn!(
"The resizing size {:?} exceeds the limit of {}.",
size,
max_dimension
);
} else {
log::info!("Resizing to {:?}", size);
config.width = size.width.max(1);
config.height = size.height.max(1);
example.resize(&config, &device, &queue);
surface.configure(&device, &config);
}
}
event::Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {
input:
event::KeyboardInput {
virtual_keycode: Some(event::VirtualKeyCode::Escape),
state: event::ElementState::Pressed,
..
},
..
}
| WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
}
#[cfg(not(target_arch = "wasm32"))]
WindowEvent::KeyboardInput {
input:
event::KeyboardInput {
virtual_keycode: Some(event::VirtualKeyCode::R),
state: event::ElementState::Pressed,
..
},
..
} => {
println!("{:#?}", instance.generate_report());
}
_ => {
example.update(&device,event);
}
},
event::Event::DeviceEvent {
event,
..
} => {
example.device_event(event);
},
event::Event::RedrawRequested(_) => {
let frame = match surface.get_current_texture() { window.request_redraw();
Ok(frame) => frame, }
Err(_) => { event::Event::WindowEvent {
surface.configure(&device, &config); event:
surface WindowEvent::Resized(size)
.get_current_texture() | WindowEvent::ScaleFactorChanged {
.expect("Failed to acquire next surface texture!") new_inner_size: &mut size,
} ..
}; },
let view = frame.texture.create_view(&wgpu::TextureViewDescriptor { ..
format: Some(surface_view_format), } => {
..wgpu::TextureViewDescriptor::default() // Once winit is fixed, the detection conditions here can be removed.
}); // https://github.com/rust-windowing/winit/issues/2876
let max_dimension = adapter.limits().max_texture_dimension_2d;
if size.width > max_dimension || size.height > max_dimension {
log::warn!(
"The resizing size {:?} exceeds the limit of {}.",
size,
max_dimension
);
} else {
log::info!("Resizing to {:?}", size);
config.width = size.width.max(1);
config.height = size.height.max(1);
example.resize(&config, &device, &queue);
surface.configure(&device, &config);
}
}
event::Event::WindowEvent { event, .. } => match event {
WindowEvent::KeyboardInput {
input:
event::KeyboardInput {
virtual_keycode: Some(event::VirtualKeyCode::Escape),
state: event::ElementState::Pressed,
..
},
..
}
| WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
}
#[cfg(not(target_arch = "wasm32"))]
WindowEvent::KeyboardInput {
input:
event::KeyboardInput {
virtual_keycode: Some(event::VirtualKeyCode::R),
state: event::ElementState::Pressed,
..
},
..
} => {
println!("{:#?}", instance.generate_report());
}
_ => {
example.update(event);
}
},
event::Event::DeviceEvent {
event:
winit::event::DeviceEvent::MouseMotion {
delta,
},
..
} => {
example.move_mouse(delta);
},
event::Event::RedrawRequested(_) => {
#[cfg(not(target_arch = "wasm32"))]
{
accum_time += last_frame_inst.elapsed().as_secs_f32();
last_frame_inst = Instant::now();
frame_count += 1;
if frame_count == 100 {
println!(
"Avg frame time {}ms",
accum_time * 1000.0 / frame_count as f32
);
accum_time = 0.0;
frame_count = 0;
}
}
example.render(&view, &device, &queue, &spawner); let frame = match surface.get_current_texture() {
Ok(frame) => frame,
Err(_) => {
surface.configure(&device, &config);
surface
.get_current_texture()
.expect("Failed to acquire next surface texture!")
}
};
let view = frame.texture.create_view(&wgpu::TextureViewDescriptor {
format: Some(surface_view_format),
..wgpu::TextureViewDescriptor::default()
});
frame.present(); example.render(&view, &device, &queue, &spawner);
#[cfg(target_arch = "wasm32")] frame.present();
{
if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup {
let image_bitmap = offscreen_canvas_setup
.offscreen_canvas
.transfer_to_image_bitmap()
.expect("couldn't transfer offscreen canvas to image bitmap.");
offscreen_canvas_setup
.bitmap_renderer
.transfer_from_image_bitmap(&image_bitmap);
log::info!("Transferring OffscreenCanvas to ImageBitmapRenderer"); #[cfg(target_arch = "wasm32")]
} {
} if let Some(offscreen_canvas_setup) = &offscreen_canvas_setup {
} let image_bitmap = offscreen_canvas_setup
_ => {} .offscreen_canvas
} .transfer_to_image_bitmap()
}); .expect("couldn't transfer offscreen canvas to image bitmap.");
offscreen_canvas_setup
.bitmap_renderer
.transfer_from_image_bitmap(&image_bitmap);
log::info!("Transferring OffscreenCanvas to ImageBitmapRenderer");
}
}
}
_ => {}
}
});
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub struct Spawner<'a> { pub struct Spawner<'a> {
executor: async_executor::LocalExecutor<'a>, executor: async_executor::LocalExecutor<'a>,
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
impl<'a> Spawner<'a> { impl<'a> Spawner<'a> {
fn new() -> Self { fn new() -> Self {
Self { Self {
executor: async_executor::LocalExecutor::new(), executor: async_executor::LocalExecutor::new(),
} }
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn spawn_local(&self, future: impl Future<Output = ()> + 'a) { pub fn spawn_local(&self, future: impl Future<Output = ()> + 'a) {
self.executor.spawn(future).detach(); self.executor.spawn(future).detach();
} }
fn run_until_stalled(&self) { fn run_until_stalled(&self) {
while self.executor.try_tick() {} while self.executor.try_tick() {}
} }
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@@ -421,69 +445,69 @@ pub struct Spawner {}
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
impl Spawner { impl Spawner {
fn new() -> Self { fn new() -> Self {
Self {} Self {}
} }
#[allow(dead_code)] #[allow(dead_code)]
pub fn spawn_local(&self, future: impl Future<Output = ()> + 'static) { pub fn spawn_local(&self, future: impl Future<Output = ()> + 'static) {
wasm_bindgen_futures::spawn_local(future); wasm_bindgen_futures::spawn_local(future);
} }
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub fn run<E: Example>(title: &str) { pub fn run<E: Example>(title: &str) {
let setup = pollster::block_on(setup::<E>(title)); let setup = pollster::block_on(setup::<E>(title));
start::<E>(setup); start::<E>(setup);
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
pub fn run<E: Example>(title: &str) { pub fn run<E: Example>(title: &str) {
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
let title = title.to_owned(); let title = title.to_owned();
wasm_bindgen_futures::spawn_local(async move { wasm_bindgen_futures::spawn_local(async move {
let setup = setup::<E>(&title).await; let setup = setup::<E>(&title).await;
let start_closure = Closure::once_into_js(move || start::<E>(setup)); let start_closure = Closure::once_into_js(move || start::<E>(setup));
// make sure to handle JS exceptions thrown inside start. // make sure to handle JS exceptions thrown inside start.
// Otherwise wasm_bindgen_futures Queue would break and never handle any tasks again. // Otherwise wasm_bindgen_futures Queue would break and never handle any tasks again.
// This is required, because winit uses JS exception for control flow to escape from `run`. // This is required, because winit uses JS exception for control flow to escape from `run`.
if let Err(error) = call_catch(&start_closure) { if let Err(error) = call_catch(&start_closure) {
let is_control_flow_exception = error.dyn_ref::<js_sys::Error>().map_or(false, |e| { let is_control_flow_exception = error.dyn_ref::<js_sys::Error>().map_or(false, |e| {
e.message().includes("Using exceptions for control flow", 0) e.message().includes("Using exceptions for control flow", 0)
}); });
if !is_control_flow_exception { if !is_control_flow_exception {
web_sys::console::error_1(&error); web_sys::console::error_1(&error);
} }
} }
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
#[wasm_bindgen(catch, js_namespace = Function, js_name = "prototype.call.call")] #[wasm_bindgen(catch, js_namespace = Function, js_name = "prototype.call.call")]
fn call_catch(this: &JsValue) -> Result<(), JsValue>; fn call_catch(this: &JsValue) -> Result<(), JsValue>;
} }
}); });
} }
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
/// Parse the query string as returned by `web_sys::window()?.location().search()?` and get a /// Parse the query string as returned by `web_sys::window()?.location().search()?` and get a
/// specific key out of it. /// specific key out of it.
pub fn parse_url_query_string<'a>(query: &'a str, search_key: &str) -> Option<&'a str> { pub fn parse_url_query_string<'a>(query: &'a str, search_key: &str) -> Option<&'a str> {
let query_string = query.strip_prefix('?')?; let query_string = query.strip_prefix('?')?;
for pair in query_string.split('&') { for pair in query_string.split('&') {
let mut pair = pair.split('='); let mut pair = pair.split('=');
let key = pair.next()?; let key = pair.next()?;
let value = pair.next()?; let value = pair.next()?;
if key == search_key { if key == search_key {
return Some(value); return Some(value);
} }
} }
None None
} }
// This allows treating the framework as a standalone example, // This allows treating the framework as a standalone example,

View File

@@ -1,48 +0,0 @@
#[derive(Debug)]
pub struct TimedInstruction<I> {
pub time: crate::body::TIME,
pub instruction: I,
}
pub trait InstructionEmitter<I> {
fn next_instruction(&self, time_limit:crate::body::TIME) -> Option<TimedInstruction<I>>;
}
pub trait InstructionConsumer<I> {
fn process_instruction(&mut self, instruction:TimedInstruction<I>);
}
//PROPER PRIVATE FIELDS!!!
pub struct InstructionCollector<I> {
time: crate::body::TIME,
instruction: Option<I>,
}
impl<I> InstructionCollector<I> {
pub fn new(time:crate::body::TIME) -> Self {
Self{
time,
instruction:None
}
}
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
match instruction {
Some(unwrap_instruction) => {
if unwrap_instruction.time<self.time {
self.time=unwrap_instruction.time;
self.instruction=Some(unwrap_instruction.instruction);
}
},
None => (),
}
}
pub fn instruction(self) -> Option<TimedInstruction<I>> {
//STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR
match self.instruction {
Some(instruction)=>Some(TimedInstruction{
time:self.time,
instruction
}),
None => None,
}
}
}

View File

@@ -1,5 +1 @@
pub mod framework; pub mod framework;
pub mod body;
pub mod zeroes;
pub mod instruction;
pub mod load_roblox;

View File

@@ -1,27 +0,0 @@
fn class_is_a(class: &str, superclass: &str) -> bool {
if class==superclass {
return true
}
let class_descriptor=rbx_reflection_database::get().classes.get(class);
if let Some(descriptor) = &class_descriptor {
if let Some(class_super) = &descriptor.superclass {
return class_is_a(&class_super, superclass)
}
}
return false
}
pub fn get_objects<R: std::io::Read>(buf_thing: R, superclass: &str) -> Result<std::vec::Vec<rbx_dom_weak::Instance>, Box<dyn std::error::Error>> {
// Using buffered I/O is recommended with rbx_binary
let dom = rbx_binary::from_reader(buf_thing)?;
let mut objects = std::vec::Vec::<rbx_dom_weak::Instance>::new();
//move matching instances into objects
let (_,mut instances) = dom.into_raw();
for (_,instance) in instances.drain() {
if class_is_a(instance.class.as_str(), superclass) {
objects.push(instance);
}
}
return Ok(objects)
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,105 +1,131 @@
struct Camera { struct SkyOutput {
// from camera to screen @builtin(position) position: vec4<f32>,
proj: mat4x4<f32>, @location(0) sampledir: vec3<f32>,
// from screen to camera
proj_inv: mat4x4<f32>,
// from world to camera
view: mat4x4<f32>,
// camera position
cam_pos: vec4<f32>,
}; };
//group 0 is the camera struct Data {
// from camera to screen
proj: mat4x4<f32>,
// from screen to camera
proj_inv: mat4x4<f32>,
// from world to camera
view: mat4x4<f32>,
// camera position
cam_pos: vec4<f32>,
};
@group(0) @group(0)
@binding(0) @binding(0)
var<uniform> camera: Camera; var<uniform> r_data: Data;
struct SkyOutput {
@builtin(position) position: vec4<f32>,
@location(0) sampledir: vec3<f32>,
};
@vertex @vertex
fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput { fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput {
// hacky way to draw a large triangle // hacky way to draw a large triangle
let tmp1 = i32(vertex_index) / 2; let tmp1 = i32(vertex_index) / 2;
let tmp2 = i32(vertex_index) & 1; let tmp2 = i32(vertex_index) & 1;
let pos = vec4<f32>( let pos = vec4<f32>(
f32(tmp1) * 4.0 - 1.0, f32(tmp1) * 4.0 - 1.0,
f32(tmp2) * 4.0 - 1.0, f32(tmp2) * 4.0 - 1.0,
1.0, 1.0,
1.0 1.0
); );
// transposition = inversion for this orthonormal matrix // transposition = inversion for this orthonormal matrix
let inv_model_view = transpose(mat3x3<f32>(camera.view[0].xyz, camera.view[1].xyz, camera.view[2].xyz)); let inv_model_view = transpose(mat3x3<f32>(r_data.view[0].xyz, r_data.view[1].xyz, r_data.view[2].xyz));
let unprojected = camera.proj_inv * pos; let unprojected = r_data.proj_inv * pos;
var result: SkyOutput; var result: SkyOutput;
result.sampledir = inv_model_view * unprojected.xyz; result.sampledir = inv_model_view * unprojected.xyz;
result.position = pos; result.position = pos;
return result; return result;
} }
const MAX_ENTITY_INSTANCES=1024; struct GroundOutput {
//group 1 is the model @builtin(position) position: vec4<f32>,
@group(1) @location(4) pos: vec3<f32>,
@binding(0)
var<uniform> entity_transforms: array<mat4x4<f32>,MAX_ENTITY_INSTANCES>;
//var<uniform> entity_texture_transforms: array<mat3x3<f32>,MAX_ENTITY_INSTANCES>;
//my fancy idea is to create a megatexture for each model that includes all the textures each intance will need
//the texture transform then maps the texture coordinates to the location of the specific texture
//how to do no texture?
@group(1)
@binding(1)
var model_texture: texture_2d<f32>;
@group(1)
@binding(2)
var model_sampler: sampler;
struct EntityOutputTexture {
@builtin(position) position: vec4<f32>,
@location(1) texture: vec2<f32>,
@location(2) normal: vec3<f32>,
@location(3) view: vec3<f32>,
}; };
@vertex @vertex
fn vs_entity_texture( fn vs_ground(@builtin(vertex_index) vertex_index: u32) -> GroundOutput {
@builtin(instance_index) instance: u32, // hacky way to draw two triangles that make a square
@location(0) pos: vec3<f32>, let tmp1 = i32(vertex_index)/2-i32(vertex_index)/3;
@location(1) texture: vec2<f32>, let tmp2 = i32(vertex_index)&1;
@location(2) normal: vec3<f32>, let pos = vec3<f32>(
) -> EntityOutputTexture { f32(tmp1) * 2.0 - 1.0,
var position: vec4<f32> = entity_transforms[instance] * vec4<f32>(pos, 1.0); 0.0,
var result: EntityOutputTexture; f32(tmp2) * 2.0 - 1.0
result.normal = (entity_transforms[instance] * vec4<f32>(normal, 0.0)).xyz; ) * 100.0;
result.texture=texture;//(entity_texture_transforms[instance] * vec3<f32>(texture, 1.0)).xy;
result.view = position.xyz - camera.cam_pos.xyz; var result: GroundOutput;
result.position = camera.proj * camera.view * position; result.pos = pos;
return result; result.position = r_data.proj * r_data.view * vec4<f32>(pos, 1.0);
return result;
} }
//group 2 is the skybox texture struct EntityOutput {
@group(2) @builtin(position) position: vec4<f32>,
@binding(0) @location(1) normal: vec3<f32>,
var cube_texture: texture_cube<f32>; @location(3) view: vec3<f32>,
@group(2) };
struct EntityTransform {
matrix3: mat3x3<f32>,
translation: vec3<f32>,
};
@group(0)
@binding(3)
var<uniform> r_EntityTransforms: array<EntityTransform, 7>;
@vertex
fn vs_entity(
@location(0) pos: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) entity_id: u32,
) -> EntityOutput {
var position: vec3<f32> = r_EntityTransforms[entity_id].matrix3 * pos+r_EntityTransforms[entity_id].translation;
var result: EntityOutput;
result.normal = r_EntityTransforms[entity_id].matrix3 * normal;
result.view = position - r_data.cam_pos.xyz;
result.position = r_data.proj * r_data.view * vec4<f32>(position, 1.0);
return result;
}
@group(0)
@binding(1) @binding(1)
var cube_sampler: sampler; var r_texture: texture_cube<f32>;
@group(0)
@binding(2)
var r_sampler: sampler;
@fragment @fragment
fn fs_sky(vertex: SkyOutput) -> @location(0) vec4<f32> { fn fs_sky(vertex: SkyOutput) -> @location(0) vec4<f32> {
return textureSample(cube_texture, model_sampler, vertex.sampledir); return textureSample(r_texture, r_sampler, vertex.sampledir);
} }
@fragment @fragment
fn fs_entity_texture(vertex: EntityOutputTexture) -> @location(0) vec4<f32> { fn fs_entity(vertex: EntityOutput) -> @location(0) vec4<f32> {
let incident = normalize(vertex.view); let incident = normalize(vertex.view);
let normal = normalize(vertex.normal); let normal = normalize(vertex.normal);
let d = dot(normal, incident); let reflected = incident - 2.0 * dot(normal, incident) * normal;
let reflected = incident - 2.0 * d * normal;
let fragment_color = textureSample(model_texture, model_sampler, vertex.texture).rgb; let reflected_color = textureSample(r_texture, r_sampler, reflected).rgb;
let reflected_color = textureSample(cube_texture, cube_sampler, reflected).rgb; return vec4<f32>(vec3<f32>(0.1) + 0.5 * reflected_color, 1.0);
return vec4<f32>(mix(vec3<f32>(0.1) + 0.5 * reflected_color,fragment_color,1.0-pow(1.0-abs(d),2.0)), 1.0); }
fn modulo_euclidean (a: f32, b: f32) -> f32 {
var m = a % b;
if (m < 0.0) {
if (b < 0.0) {
m -= b;
} else {
m += b;
}
}
return m;
}
@fragment
fn fs_ground(vertex: GroundOutput) -> @location(0) vec4<f32> {
let dir = vec3<f32>(-1.0)+vec3<f32>(modulo_euclidean(vertex.pos.x/16.,1.0),0.0,modulo_euclidean(vertex.pos.z/16.,1.0))*2.0;
return vec4<f32>(textureSample(r_texture, r_sampler, dir).rgb, 1.0);
} }

View File

@@ -1,8 +0,0 @@
//something that implements body + hitbox + transform can predict collision
impl crate::sweep::PredictCollision for Model {
fn predict_collision(&self,other:&Model) -> Option<crate::event::EventStruct> {
//math!
None
}
}

View File

@@ -1,27 +0,0 @@
//find roots of polynomials
pub fn zeroes2(a0:f32,a1:f32,a2:f32) -> Vec<f32>{
if a2==0f32{
return zeroes1(a0, a1);
}
let mut radicand=a1*a1-4f32*a2*a0;
if 0f32<radicand {
radicand=radicand.sqrt();
if 0f32<a2 {
return vec![(-a1-radicand)/(2f32*a2),(-a1+radicand)/(2f32*a2)];
} else {
return vec![(-a1+radicand)/(2f32*a2),(-a1-radicand)/(2f32*a2)];
}
} else if radicand==0f32 {
return vec![-a1/(2f32*a2)];
} else {
return vec![];
}
}
#[inline]
pub fn zeroes1(a0:f32,a1:f32) -> Vec<f32> {
if a1==0f32{
return vec![];
} else {
return vec![-a0/a1];
}
}