Compare commits
6 Commits
temp-spawn
...
redo-input
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fb63375d3 | |||
| 765da37cfa | |||
| b3f3c26cfa | |||
| cfdfb29432 | |||
| 319d864045 | |||
| b98618ef10 |
257
Cargo.lock
generated
257
Cargo.lock
generated
@@ -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.5.0"
|
version = "0.3.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"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "strafe-client"
|
name = "strafe-client"
|
||||||
version = "0.5.0"
|
version = "0.3.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,9 +14,6 @@ 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"
|
||||||
|
|
||||||
|
|||||||
BIN
images/squid.dds
BIN
images/squid.dds
Binary file not shown.
35
src/body.rs
35
src/body.rs
@@ -12,8 +12,6 @@ pub enum PhysicsInstruction {
|
|||||||
// bool,//true = Trigger; false = teleport
|
// bool,//true = Trigger; false = teleport
|
||||||
// bool,//true = Force
|
// bool,//true = Force
|
||||||
// )
|
// )
|
||||||
//temp
|
|
||||||
SetPosition(glam::Vec3),
|
|
||||||
//Both of these conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it)
|
//Both of these conditionally activate RefreshWalkTarget (by doing what SetWalkTargetVelocity used to do and then flagging it)
|
||||||
Input(InputInstruction),
|
Input(InputInstruction),
|
||||||
}
|
}
|
||||||
@@ -256,7 +254,8 @@ pub struct PhysicsState {
|
|||||||
pub hitbox_halfsize: glam::Vec3,
|
pub hitbox_halfsize: glam::Vec3,
|
||||||
pub contacts: std::collections::HashSet::<RelativeCollision>,
|
pub contacts: std::collections::HashSet::<RelativeCollision>,
|
||||||
//pub intersections: Vec<ModelId>,
|
//pub intersections: Vec<ModelId>,
|
||||||
pub models: Vec<ModelPhysics>,
|
//temp
|
||||||
|
pub models_cringe_clone: Vec<Model>,
|
||||||
//camera must exist in state because wormholes modify the camera, also camera punch
|
//camera must exist in state because wormholes modify the camera, also camera punch
|
||||||
pub camera: Camera,
|
pub camera: Camera,
|
||||||
pub mouse_interpolation: MouseInterpolationState,
|
pub mouse_interpolation: MouseInterpolationState,
|
||||||
@@ -383,13 +382,13 @@ impl Aabb {
|
|||||||
type TreyMeshFace = AabbFace;
|
type TreyMeshFace = AabbFace;
|
||||||
type TreyMesh = Aabb;
|
type TreyMesh = Aabb;
|
||||||
|
|
||||||
pub struct ModelPhysics {
|
pub struct Model {
|
||||||
//A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es
|
//A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es
|
||||||
//in this iteration, all it needs is extents.
|
//in this iteration, all it needs is extents.
|
||||||
transform: glam::Mat4,
|
transform: glam::Mat4,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModelPhysics {
|
impl Model {
|
||||||
pub fn new(transform:glam::Mat4) -> Self {
|
pub fn new(transform:glam::Mat4) -> Self {
|
||||||
Self{transform}
|
Self{transform}
|
||||||
}
|
}
|
||||||
@@ -433,10 +432,10 @@ pub struct RelativeCollision {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RelativeCollision {
|
impl RelativeCollision {
|
||||||
pub fn mesh(&self,models:&Vec<ModelPhysics>) -> TreyMesh {
|
pub fn mesh(&self,models:&Vec<Model>) -> TreyMesh {
|
||||||
return models.get(self.model as usize).unwrap().face_mesh(self.face)
|
return models.get(self.model as usize).unwrap().face_mesh(self.face)
|
||||||
}
|
}
|
||||||
pub fn normal(&self,models:&Vec<ModelPhysics>) -> glam::Vec3 {
|
pub fn normal(&self,models:&Vec<Model>) -> glam::Vec3 {
|
||||||
return models.get(self.model as usize).unwrap().face_normal(self.face)
|
return models.get(self.model as usize).unwrap().face_normal(self.face)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -495,7 +494,7 @@ impl PhysicsState {
|
|||||||
|
|
||||||
fn contact_constrain_velocity(&self,velocity:&mut glam::Vec3){
|
fn contact_constrain_velocity(&self,velocity:&mut glam::Vec3){
|
||||||
for contact in self.contacts.iter() {
|
for contact in self.contacts.iter() {
|
||||||
let n=contact.normal(&self.models);
|
let n=contact.normal(&self.models_cringe_clone);
|
||||||
let d=velocity.dot(n);
|
let d=velocity.dot(n);
|
||||||
if d<0f32{
|
if d<0f32{
|
||||||
(*velocity)-=d/n.length_squared()*n;
|
(*velocity)-=d/n.length_squared()*n;
|
||||||
@@ -504,7 +503,7 @@ impl PhysicsState {
|
|||||||
}
|
}
|
||||||
fn contact_constrain_acceleration(&self,acceleration:&mut glam::Vec3){
|
fn contact_constrain_acceleration(&self,acceleration:&mut glam::Vec3){
|
||||||
for contact in self.contacts.iter() {
|
for contact in self.contacts.iter() {
|
||||||
let n=contact.normal(&self.models);
|
let n=contact.normal(&self.models_cringe_clone);
|
||||||
let d=acceleration.dot(n);
|
let d=acceleration.dot(n);
|
||||||
if d<0f32{
|
if d<0f32{
|
||||||
(*acceleration)-=d/n.length_squared()*n;
|
(*acceleration)-=d/n.length_squared()*n;
|
||||||
@@ -604,7 +603,7 @@ impl PhysicsState {
|
|||||||
let mut best_time=time_limit;
|
let mut best_time=time_limit;
|
||||||
let mut exit_face:Option<TreyMeshFace>=None;
|
let mut exit_face:Option<TreyMeshFace>=None;
|
||||||
let mesh0=self.mesh();
|
let mesh0=self.mesh();
|
||||||
let mesh1=self.models.get(collision_data.model as usize).unwrap().mesh();
|
let mesh1=self.models_cringe_clone.get(collision_data.model as usize).unwrap().mesh();
|
||||||
let (v,a)=(-self.body.velocity,self.body.acceleration);
|
let (v,a)=(-self.body.velocity,self.body.acceleration);
|
||||||
//collect x
|
//collect x
|
||||||
match collision_data.face {
|
match collision_data.face {
|
||||||
@@ -755,7 +754,7 @@ impl PhysicsState {
|
|||||||
let mut best_time=time_limit;
|
let mut best_time=time_limit;
|
||||||
let mut best_face:Option<TreyMeshFace>=None;
|
let mut best_face:Option<TreyMeshFace>=None;
|
||||||
let mesh0=self.mesh();
|
let mesh0=self.mesh();
|
||||||
let mesh1=self.models.get(model_id as usize).unwrap().mesh();
|
let mesh1=self.models_cringe_clone.get(model_id as usize).unwrap().mesh();
|
||||||
let (p,v,a)=(self.body.position,self.body.velocity,self.body.acceleration);
|
let (p,v,a)=(self.body.position,self.body.velocity,self.body.acceleration);
|
||||||
//collect x
|
//collect x
|
||||||
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,0.5*a.x) {
|
for t in zeroes2(mesh0.max.x-mesh1.min.x,v.x,0.5*a.x) {
|
||||||
@@ -880,7 +879,7 @@ impl crate::instruction::InstructionEmitter<PhysicsInstruction> for PhysicsState
|
|||||||
collector.collect(self.predict_collision_end(self.time,time_limit,collision_data));
|
collector.collect(self.predict_collision_end(self.time,time_limit,collision_data));
|
||||||
}
|
}
|
||||||
//check for collision start instructions (against every part in the game with no optimization!!)
|
//check for collision start instructions (against every part in the game with no optimization!!)
|
||||||
for i in 0..self.models.len() {
|
for i in 0..self.models_cringe_clone.len() {
|
||||||
collector.collect(self.predict_collision_start(self.time,time_limit,i as u32));
|
collector.collect(self.predict_collision_start(self.time,time_limit,i as u32));
|
||||||
}
|
}
|
||||||
if self.grounded {
|
if self.grounded {
|
||||||
@@ -904,7 +903,6 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
//selectively update body
|
//selectively update body
|
||||||
match &ins.instruction {
|
match &ins.instruction {
|
||||||
PhysicsInstruction::Input(InputInstruction::MoveMouse(_)) => (),//dodge time for mouse movement
|
PhysicsInstruction::Input(InputInstruction::MoveMouse(_)) => (),//dodge time for mouse movement
|
||||||
PhysicsInstruction::SetPosition(_) => self.time=ins.time,//TODO: queue instructions
|
|
||||||
PhysicsInstruction::Input(_)
|
PhysicsInstruction::Input(_)
|
||||||
|PhysicsInstruction::ReachWalkTargetVelocity
|
|PhysicsInstruction::ReachWalkTargetVelocity
|
||||||
|PhysicsInstruction::CollisionStart(_)
|
|PhysicsInstruction::CollisionStart(_)
|
||||||
@@ -912,15 +910,6 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
|PhysicsInstruction::StrafeTick => self.advance_time(ins.time),
|
|PhysicsInstruction::StrafeTick => self.advance_time(ins.time),
|
||||||
}
|
}
|
||||||
match ins.instruction {
|
match ins.instruction {
|
||||||
PhysicsInstruction::SetPosition(position)=>{
|
|
||||||
//temp
|
|
||||||
self.body.position=position;
|
|
||||||
//manual clear //for c in self.contacts{process_instruction(CollisionEnd(c))}
|
|
||||||
self.contacts.clear();
|
|
||||||
self.body.acceleration=self.gravity;
|
|
||||||
self.walk.state=WalkEnum::Reached;
|
|
||||||
self.grounded=false;
|
|
||||||
}
|
|
||||||
PhysicsInstruction::CollisionStart(c) => {
|
PhysicsInstruction::CollisionStart(c) => {
|
||||||
//check ground
|
//check ground
|
||||||
match &c.face {
|
match &c.face {
|
||||||
@@ -1029,4 +1018,4 @@ impl crate::instruction::InstructionConsumer<PhysicsInstruction> for PhysicsStat
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ pub trait Example: 'static + Sized {
|
|||||||
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 device_event(&mut self, event: DeviceEvent);
|
||||||
fn render(
|
fn render(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -344,7 +344,7 @@ fn start<E: Example>(
|
|||||||
println!("{:#?}", instance.generate_report());
|
println!("{:#?}", instance.generate_report());
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
example.update(&device,event);
|
example.update(event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
event::Event::DeviceEvent {
|
event::Event::DeviceEvent {
|
||||||
|
|||||||
@@ -2,4 +2,3 @@ pub mod framework;
|
|||||||
pub mod body;
|
pub mod body;
|
||||||
pub mod zeroes;
|
pub mod zeroes;
|
||||||
pub mod instruction;
|
pub mod instruction;
|
||||||
pub mod load_roblox;
|
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
811
src/main.rs
811
src/main.rs
@@ -11,7 +11,6 @@ struct Vertex {
|
|||||||
pos: [f32; 3],
|
pos: [f32; 3],
|
||||||
texture: [f32; 2],
|
texture: [f32; 2],
|
||||||
normal: [f32; 3],
|
normal: [f32; 3],
|
||||||
color: [f32; 4],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Entity {
|
struct Entity {
|
||||||
@@ -19,65 +18,36 @@ struct Entity {
|
|||||||
index_buf: wgpu::Buffer,
|
index_buf: wgpu::Buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ModelInstance {
|
//temp?
|
||||||
transform: glam::Mat4,
|
|
||||||
color: glam::Vec4,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ModelData {
|
struct ModelData {
|
||||||
instances: Vec<ModelInstance>,
|
transform: glam::Mat4,
|
||||||
vertices: Vec<Vertex>,
|
vertex_buf: wgpu::Buffer,
|
||||||
entities: Vec<Vec<u16>>,
|
entities: Vec<Entity>,
|
||||||
}
|
|
||||||
|
|
||||||
impl ModelData {
|
|
||||||
const COLOR_FLOATS_WHITE: [f32;4] = [1.0,1.0,1.0,1.0];
|
|
||||||
const COLOR_VEC4_WHITE: glam::Vec4 = glam::vec4(1.0,1.0,1.0,1.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ModelGraphics {
|
struct ModelGraphics {
|
||||||
instances: Vec<ModelInstance>,
|
transform: glam::Mat4,
|
||||||
vertex_buf: wgpu::Buffer,
|
vertex_buf: wgpu::Buffer,
|
||||||
entities: Vec<Entity>,
|
entities: Vec<Entity>,
|
||||||
bind_group: wgpu::BindGroup,
|
bind_group: wgpu::BindGroup,
|
||||||
model_buf: wgpu::Buffer,
|
model_buf: wgpu::Buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GraphicsSamplers{
|
pub struct Skybox {
|
||||||
repeat: wgpu::Sampler,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GraphicsBindGroupLayouts{
|
|
||||||
model: wgpu::BindGroupLayout,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GraphicsBindGroups {
|
|
||||||
camera: wgpu::BindGroup,
|
|
||||||
skybox_texture: wgpu::BindGroup,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GraphicsPipelines {
|
|
||||||
skybox: wgpu::RenderPipeline,
|
|
||||||
model: wgpu::RenderPipeline,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct GraphicsData {
|
|
||||||
start_time: std::time::Instant,
|
start_time: std::time::Instant,
|
||||||
screen_size: (u32, u32),
|
screen_size: (u32, u32),
|
||||||
physics: strafe_client::body::PhysicsState,
|
physics: strafe_client::body::PhysicsState,
|
||||||
pipelines: GraphicsPipelines,
|
sky_pipeline: wgpu::RenderPipeline,
|
||||||
bind_groups: GraphicsBindGroups,
|
entity_pipeline: wgpu::RenderPipeline,
|
||||||
bind_group_layouts: GraphicsBindGroupLayouts,
|
ground_pipeline: wgpu::RenderPipeline,
|
||||||
samplers: GraphicsSamplers,
|
main_bind_group: wgpu::BindGroup,
|
||||||
temp_squid_texture_view: wgpu::TextureView,
|
|
||||||
camera_buf: wgpu::Buffer,
|
camera_buf: wgpu::Buffer,
|
||||||
models: Vec<ModelGraphics>,
|
models: Vec<ModelGraphics>,
|
||||||
depth_view: wgpu::TextureView,
|
depth_view: wgpu::TextureView,
|
||||||
staging_belt: wgpu::util::StagingBelt,
|
staging_belt: wgpu::util::StagingBelt,
|
||||||
handy_unit_cube: obj::ObjData,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphicsData {
|
impl Skybox {
|
||||||
const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth24Plus;
|
const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth24Plus;
|
||||||
|
|
||||||
fn create_depth_texture(
|
fn create_depth_texture(
|
||||||
@@ -101,139 +71,20 @@ impl GraphicsData {
|
|||||||
|
|
||||||
depth_texture.create_view(&wgpu::TextureViewDescriptor::default())
|
depth_texture.create_view(&wgpu::TextureViewDescriptor::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_modeldatas_roblox<R: std::io::Read>(&self,input:R) -> (Vec<ModelData>,glam::Vec3){
|
|
||||||
let mut spawn_point=glam::Vec3::ZERO;
|
|
||||||
let mut modeldatas=generate_modeldatas(self.handy_unit_cube.clone(),ModelData::COLOR_FLOATS_WHITE);
|
|
||||||
match strafe_client::load_roblox::get_objects(input, "BasePart") {
|
|
||||||
Ok(objects)=>{
|
|
||||||
for object in objects.iter() {
|
|
||||||
if let (
|
|
||||||
Some(rbx_dom_weak::types::Variant::CFrame(cf)),
|
|
||||||
Some(rbx_dom_weak::types::Variant::Vector3(size)),
|
|
||||||
Some(rbx_dom_weak::types::Variant::Float32(transparency)),
|
|
||||||
Some(rbx_dom_weak::types::Variant::Color3uint8(color3)),
|
|
||||||
Some(rbx_dom_weak::types::Variant::Enum(shape)),
|
|
||||||
) = (
|
|
||||||
object.properties.get("CFrame"),
|
|
||||||
object.properties.get("Size"),
|
|
||||||
object.properties.get("Transparency"),
|
|
||||||
object.properties.get("Color"),
|
|
||||||
object.properties.get("Shape"),//this will also skip unions
|
|
||||||
)
|
|
||||||
{
|
|
||||||
let transform=glam::Mat4::from_translation(
|
|
||||||
glam::Vec3::new(cf.position.x,cf.position.y,cf.position.z)
|
|
||||||
)
|
|
||||||
* glam::Mat4::from_mat3(
|
|
||||||
glam::Mat3::from_cols(
|
|
||||||
glam::Vec3::new(cf.orientation.x.x,cf.orientation.y.x,cf.orientation.z.x),
|
|
||||||
glam::Vec3::new(cf.orientation.x.y,cf.orientation.y.y,cf.orientation.z.y),
|
|
||||||
glam::Vec3::new(cf.orientation.x.z,cf.orientation.y.z,cf.orientation.z.z),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
* glam::Mat4::from_scale(
|
|
||||||
glam::Vec3::new(size.x,size.y,size.z)/2.0
|
|
||||||
);
|
|
||||||
if object.name=="MapStart"{
|
|
||||||
spawn_point=glam::Vec4Swizzles::xyz(transform*glam::Vec3::Y.extend(1.0))+glam::vec3(0.0,2.5,0.0);
|
|
||||||
println!("Found MapStart{:?}",spawn_point);
|
|
||||||
}
|
|
||||||
if *transparency==1.0||shape.to_u32()!=1 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
modeldatas[0].instances.push(ModelInstance {
|
|
||||||
transform,
|
|
||||||
color: glam::vec4(color3.r as f32/255f32, color3.g as f32/255f32, color3.b as f32/255f32, 1.0-*transparency),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => println!("lmao err {:?}", e),
|
|
||||||
}
|
|
||||||
(modeldatas,spawn_point)
|
|
||||||
}
|
|
||||||
fn generate_model_physics(&mut self,modeldatas:&Vec<ModelData>){
|
|
||||||
self.physics.models.append(&mut modeldatas.iter().map(|m|
|
|
||||||
//make aabb and run vertices to get realistic bounds
|
|
||||||
m.instances.iter().map(|t|strafe_client::body::ModelPhysics::new(t.transform))
|
|
||||||
).flatten().collect());
|
|
||||||
}
|
|
||||||
fn generate_model_graphics(&mut self,device:&wgpu::Device,mut modeldatas:Vec<ModelData>){
|
|
||||||
//drain the modeldata vec so entities can be /moved/ to models.entities
|
|
||||||
self.models.reserve(modeldatas.len());
|
|
||||||
for (i,modeldata) in modeldatas.drain(..).enumerate() {
|
|
||||||
let model_uniforms = get_instances_buffer_data(&modeldata.instances);
|
|
||||||
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
||||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
|
||||||
contents: bytemuck::cast_slice(&model_uniforms),
|
|
||||||
usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST,
|
|
||||||
});
|
|
||||||
let model_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
||||||
layout: &self.bind_group_layouts.model,
|
|
||||||
entries: &[
|
|
||||||
wgpu::BindGroupEntry {
|
|
||||||
binding: 0,
|
|
||||||
resource: model_buf.as_entire_binding(),
|
|
||||||
},
|
|
||||||
wgpu::BindGroupEntry {
|
|
||||||
binding: 1,
|
|
||||||
resource: wgpu::BindingResource::TextureView(&self.temp_squid_texture_view),
|
|
||||||
},
|
|
||||||
wgpu::BindGroupEntry {
|
|
||||||
binding: 2,
|
|
||||||
resource: wgpu::BindingResource::Sampler(&self.samplers.repeat),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
label: Some(format!("ModelGraphics{}",i).as_str()),
|
|
||||||
});
|
|
||||||
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
||||||
label: Some("Vertex"),
|
|
||||||
contents: bytemuck::cast_slice(&modeldata.vertices),
|
|
||||||
usage: wgpu::BufferUsages::VERTEX,
|
|
||||||
});
|
|
||||||
//all of these are being moved here
|
|
||||||
self.models.push(ModelGraphics{
|
|
||||||
instances:modeldata.instances,
|
|
||||||
vertex_buf,
|
|
||||||
entities: modeldata.entities.iter().map(|indices|{
|
|
||||||
let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
|
||||||
label: Some("Index"),
|
|
||||||
contents: bytemuck::cast_slice(&indices),
|
|
||||||
usage: wgpu::BufferUsages::INDEX,
|
|
||||||
});
|
|
||||||
Entity {
|
|
||||||
index_buf,
|
|
||||||
index_count: indices.len() as u32,
|
|
||||||
}
|
|
||||||
}).collect(),
|
|
||||||
bind_group: model_bind_group,
|
|
||||||
model_buf,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_instances_buffer_data(instances:&Vec<ModelInstance>) -> Vec<f32> {
|
fn get_transform_uniform_data(transform:&glam::Mat4) -> [f32; 4*4] {
|
||||||
const SIZE: usize=4*4+4;//let size=std::mem::size_of::<ModelInstance>();
|
let mut raw = [0f32; 4*4];
|
||||||
let mut raw = Vec::with_capacity(SIZE*instances.len());
|
raw[0..16].copy_from_slice(&AsRef::<[f32; 4*4]>::as_ref(transform)[..]);
|
||||||
for (i,mi) in instances.iter().enumerate(){
|
|
||||||
let mut v = raw.split_off(SIZE*i);
|
|
||||||
raw.extend_from_slice(&AsRef::<[f32; 4*4]>::as_ref(&mi.transform)[..]);
|
|
||||||
raw.extend_from_slice(AsRef::<[f32; 4]>::as_ref(&mi.color));
|
|
||||||
raw.append(&mut v);
|
|
||||||
}
|
|
||||||
raw
|
raw
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_modeldatas(data:obj::ObjData,color:[f32;4]) -> Vec<ModelData>{
|
fn add_obj(device:&wgpu::Device,modeldatas:& mut Vec<ModelData>,source:&[u8]){
|
||||||
let mut modeldatas=Vec::new();
|
let data = obj::ObjData::load_buf(&source[..]).unwrap();
|
||||||
let mut vertices = Vec::new();
|
let mut vertices = Vec::new();
|
||||||
let mut vertex_index = std::collections::HashMap::<obj::IndexTuple,u16>::new();
|
let mut vertex_index = std::collections::HashMap::<obj::IndexTuple,u16>::new();
|
||||||
for object in data.objects {
|
for object in data.objects {
|
||||||
vertices.clear();
|
let mut entities = Vec::<Entity>::new();
|
||||||
vertex_index.clear();
|
|
||||||
let mut entities = Vec::new();
|
|
||||||
for group in object.groups {
|
for group in object.groups {
|
||||||
let mut indices = Vec::new();
|
let mut indices = Vec::new();
|
||||||
for poly in group.polys {
|
for poly in group.polys {
|
||||||
@@ -248,7 +99,6 @@ fn generate_modeldatas(data:obj::ObjData,color:[f32;4]) -> Vec<ModelData>{
|
|||||||
pos: data.position[vert.0],
|
pos: data.position[vert.0],
|
||||||
texture: data.texture[vert.1.unwrap()],
|
texture: data.texture[vert.1.unwrap()],
|
||||||
normal: data.normal[vert.2.unwrap()],
|
normal: data.normal[vert.2.unwrap()],
|
||||||
color,
|
|
||||||
});
|
});
|
||||||
vertex_index.insert(vert,i);
|
vertex_index.insert(vert,i);
|
||||||
indices.push(i);
|
indices.push(i);
|
||||||
@@ -256,15 +106,27 @@ fn generate_modeldatas(data:obj::ObjData,color:[f32;4]) -> Vec<ModelData>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entities.push(indices);
|
let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
|
label: Some("Index"),
|
||||||
|
contents: bytemuck::cast_slice(&indices),
|
||||||
|
usage: wgpu::BufferUsages::INDEX,
|
||||||
|
});
|
||||||
|
entities.push(Entity {
|
||||||
|
index_buf,
|
||||||
|
index_count: indices.len() as u32,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
modeldatas.push(ModelData {
|
let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
instances: Vec::new(),
|
label: Some("Vertex"),
|
||||||
vertices:vertices.clone(),
|
contents: bytemuck::cast_slice(&vertices),
|
||||||
entities,
|
usage: wgpu::BufferUsages::VERTEX,
|
||||||
});
|
});
|
||||||
|
modeldatas.push(ModelData {
|
||||||
|
transform: glam::Mat4::default(),
|
||||||
|
vertex_buf,
|
||||||
|
entities,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
modeldatas
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -282,137 +144,59 @@ fn to_uniform_data(camera: &strafe_client::body::Camera, pos: glam::Vec3) -> [f3
|
|||||||
raw
|
raw
|
||||||
}
|
}
|
||||||
|
|
||||||
impl strafe_client::framework::Example for GraphicsData {
|
impl strafe_client::framework::Example for Skybox {
|
||||||
fn optional_features() -> wgpu::Features {
|
fn optional_features() -> wgpu::Features {
|
||||||
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
wgpu::Features::TEXTURE_COMPRESSION_ASTC
|
||||||
| wgpu::Features::TEXTURE_COMPRESSION_ETC2
|
| wgpu::Features::TEXTURE_COMPRESSION_ETC2
|
||||||
| wgpu::Features::TEXTURE_COMPRESSION_BC
|
| wgpu::Features::TEXTURE_COMPRESSION_BC
|
||||||
}
|
}
|
||||||
fn required_features() -> wgpu::Features {
|
|
||||||
wgpu::Features::STORAGE_RESOURCE_BINDING_ARRAY
|
|
||||||
}
|
|
||||||
fn required_limits() -> wgpu::Limits {
|
|
||||||
wgpu::Limits::default() //framework.rs was using goofy limits that caused me a multi-day headache
|
|
||||||
}
|
|
||||||
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 {
|
||||||
let unit_cube=obj::ObjData{
|
|
||||||
position: vec![
|
|
||||||
[-1.,-1., 1.],//left bottom back
|
|
||||||
[ 1.,-1., 1.],//right bottom back
|
|
||||||
[ 1., 1., 1.],//right top back
|
|
||||||
[-1., 1., 1.],//left top back
|
|
||||||
[-1., 1.,-1.],//left top front
|
|
||||||
[ 1., 1.,-1.],//right top front
|
|
||||||
[ 1.,-1.,-1.],//right bottom front
|
|
||||||
[-1.,-1.,-1.],//left bottom front
|
|
||||||
],
|
|
||||||
texture: vec![[0.0,0.0],[1.0,0.0],[1.0,1.0],[0.0,1.0]],
|
|
||||||
normal: vec![
|
|
||||||
[1.,0.,0.],//AabbFace::Right
|
|
||||||
[0.,1.,0.],//AabbFace::Top
|
|
||||||
[0.,0.,1.],//AabbFace::Back
|
|
||||||
[-1.,0.,0.],//AabbFace::Left
|
|
||||||
[0.,-1.,0.],//AabbFace::Bottom
|
|
||||||
[0.,0.,-1.],//AabbFace::Front
|
|
||||||
],
|
|
||||||
objects: vec![obj::Object{
|
|
||||||
name: "Unit Cube".to_owned(),
|
|
||||||
groups: vec![obj::Group{
|
|
||||||
name: "Cube Vertices".to_owned(),
|
|
||||||
index: 0,
|
|
||||||
material: None,
|
|
||||||
polys: vec![
|
|
||||||
// back (0, 0, 1)
|
|
||||||
obj::SimplePolygon(vec![
|
|
||||||
obj::IndexTuple(0,Some(0),Some(2)),
|
|
||||||
obj::IndexTuple(1,Some(1),Some(2)),
|
|
||||||
obj::IndexTuple(2,Some(2),Some(2)),
|
|
||||||
obj::IndexTuple(3,Some(3),Some(2)),
|
|
||||||
]),
|
|
||||||
// front (0, 0,-1)
|
|
||||||
obj::SimplePolygon(vec![
|
|
||||||
obj::IndexTuple(4,Some(0),Some(5)),
|
|
||||||
obj::IndexTuple(5,Some(1),Some(5)),
|
|
||||||
obj::IndexTuple(6,Some(2),Some(5)),
|
|
||||||
obj::IndexTuple(7,Some(3),Some(5)),
|
|
||||||
]),
|
|
||||||
// right (1, 0, 0)
|
|
||||||
obj::SimplePolygon(vec![
|
|
||||||
obj::IndexTuple(6,Some(0),Some(0)),
|
|
||||||
obj::IndexTuple(5,Some(1),Some(0)),
|
|
||||||
obj::IndexTuple(2,Some(2),Some(0)),
|
|
||||||
obj::IndexTuple(1,Some(3),Some(0)),
|
|
||||||
]),
|
|
||||||
// left (-1, 0, 0)
|
|
||||||
obj::SimplePolygon(vec![
|
|
||||||
obj::IndexTuple(0,Some(0),Some(3)),
|
|
||||||
obj::IndexTuple(3,Some(1),Some(3)),
|
|
||||||
obj::IndexTuple(4,Some(2),Some(3)),
|
|
||||||
obj::IndexTuple(7,Some(3),Some(3)),
|
|
||||||
]),
|
|
||||||
// top (0, 1, 0)
|
|
||||||
obj::SimplePolygon(vec![
|
|
||||||
obj::IndexTuple(5,Some(1),Some(1)),
|
|
||||||
obj::IndexTuple(4,Some(0),Some(1)),
|
|
||||||
obj::IndexTuple(3,Some(3),Some(1)),
|
|
||||||
obj::IndexTuple(2,Some(2),Some(1)),
|
|
||||||
]),
|
|
||||||
// bottom (0,-1, 0)
|
|
||||||
obj::SimplePolygon(vec![
|
|
||||||
obj::IndexTuple(1,Some(1),Some(4)),
|
|
||||||
obj::IndexTuple(0,Some(0),Some(4)),
|
|
||||||
obj::IndexTuple(7,Some(3),Some(4)),
|
|
||||||
obj::IndexTuple(6,Some(2),Some(4)),
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
}]
|
|
||||||
}],
|
|
||||||
material_libs: Vec::new(),
|
|
||||||
};
|
|
||||||
let mut modeldatas = Vec::<ModelData>::new();
|
let mut modeldatas = Vec::<ModelData>::new();
|
||||||
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teslacyberv3.0.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE));
|
add_obj(device,& mut modeldatas,include_bytes!("../models/teslacyberv3.0.obj"));
|
||||||
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/suzanne.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE));
|
add_obj(device,& mut modeldatas,include_bytes!("../models/suzanne.obj"));
|
||||||
modeldatas.append(&mut generate_modeldatas(obj::ObjData::load_buf(&include_bytes!("../models/teapot.obj")[..]).unwrap(),ModelData::COLOR_FLOATS_WHITE));
|
add_obj(device,& mut modeldatas,include_bytes!("../models/teapot.obj"));
|
||||||
modeldatas.append(&mut generate_modeldatas(unit_cube.clone(),ModelData::COLOR_FLOATS_WHITE));
|
|
||||||
println!("models.len = {:?}", modeldatas.len());
|
println!("models.len = {:?}", modeldatas.len());
|
||||||
modeldatas[0].instances.push(ModelInstance{
|
modeldatas[1].transform=glam::Mat4::from_translation(glam::vec3(10.,5.,10.));
|
||||||
transform:glam::Mat4::from_translation(glam::vec3(10.,0.,-10.)),
|
modeldatas[2].transform=glam::Mat4::from_translation(glam::vec3(-10.,5.,10.));
|
||||||
color:ModelData::COLOR_VEC4_WHITE,
|
|
||||||
});
|
|
||||||
//quad monkeys
|
|
||||||
modeldatas[1].instances.push(ModelInstance{
|
|
||||||
transform:glam::Mat4::from_translation(glam::vec3(10.,5.,10.)),
|
|
||||||
color:ModelData::COLOR_VEC4_WHITE,
|
|
||||||
});
|
|
||||||
modeldatas[1].instances.push(ModelInstance{
|
|
||||||
transform:glam::Mat4::from_translation(glam::vec3(20.,5.,10.)),
|
|
||||||
color:glam::vec4(1.0,0.0,0.0,1.0),
|
|
||||||
});
|
|
||||||
modeldatas[1].instances.push(ModelInstance{
|
|
||||||
transform:glam::Mat4::from_translation(glam::vec3(10.,5.,20.)),
|
|
||||||
color:glam::vec4(0.0,1.0,0.0,1.0),
|
|
||||||
});
|
|
||||||
modeldatas[1].instances.push(ModelInstance{
|
|
||||||
transform:glam::Mat4::from_translation(glam::vec3(20.,5.,20.)),
|
|
||||||
color:glam::vec4(0.0,0.0,1.0,1.0),
|
|
||||||
});
|
|
||||||
//teapot
|
|
||||||
modeldatas[2].instances.push(ModelInstance{
|
|
||||||
transform:glam::Mat4::from_translation(glam::vec3(-10.,5.,10.)),
|
|
||||||
color:ModelData::COLOR_VEC4_WHITE,
|
|
||||||
});
|
|
||||||
//ground
|
|
||||||
modeldatas[3].instances.push(ModelInstance{
|
|
||||||
transform:glam::Mat4::from_translation(glam::vec3(0.,0.,0.))*glam::Mat4::from_scale(glam::vec3(160.0, 1.0, 160.0)),
|
|
||||||
color:ModelData::COLOR_VEC4_WHITE,
|
|
||||||
});
|
|
||||||
|
|
||||||
let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
let main_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
|
label: None,
|
||||||
|
entries: &[
|
||||||
|
wgpu::BindGroupLayoutEntry {
|
||||||
|
binding: 0,
|
||||||
|
visibility: wgpu::ShaderStages::VERTEX,
|
||||||
|
ty: wgpu::BindingType::Buffer {
|
||||||
|
ty: wgpu::BufferBindingType::Uniform,
|
||||||
|
has_dynamic_offset: false,
|
||||||
|
min_binding_size: None,
|
||||||
|
},
|
||||||
|
count: None,
|
||||||
|
},
|
||||||
|
wgpu::BindGroupLayoutEntry {
|
||||||
|
binding: 1,
|
||||||
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||||
|
ty: wgpu::BindingType::Texture {
|
||||||
|
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||||
|
multisampled: false,
|
||||||
|
view_dimension: wgpu::TextureViewDimension::Cube,
|
||||||
|
},
|
||||||
|
count: None,
|
||||||
|
},
|
||||||
|
wgpu::BindGroupLayoutEntry {
|
||||||
|
binding: 2,
|
||||||
|
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||||
|
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||||
|
count: None,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
let model_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
entries: &[
|
entries: &[
|
||||||
wgpu::BindGroupLayoutEntry {
|
wgpu::BindGroupLayoutEntry {
|
||||||
@@ -427,79 +211,6 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
let skybox_texture_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
||||||
label: Some("Skybox Texture Bind Group Layout"),
|
|
||||||
entries: &[
|
|
||||||
wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 0,
|
|
||||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
|
||||||
ty: wgpu::BindingType::Texture {
|
|
||||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
|
||||||
multisampled: false,
|
|
||||||
view_dimension: wgpu::TextureViewDimension::Cube,
|
|
||||||
},
|
|
||||||
count: None,
|
|
||||||
},
|
|
||||||
wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 1,
|
|
||||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
|
||||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
|
||||||
count: None,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
let model_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
||||||
label: Some("Model Bind Group Layout"),
|
|
||||||
entries: &[
|
|
||||||
wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 0,
|
|
||||||
visibility: wgpu::ShaderStages::VERTEX,
|
|
||||||
ty: wgpu::BindingType::Buffer {
|
|
||||||
ty: wgpu::BufferBindingType::Storage { read_only: true },
|
|
||||||
has_dynamic_offset: false,
|
|
||||||
min_binding_size: None,
|
|
||||||
},
|
|
||||||
count: None,
|
|
||||||
},
|
|
||||||
wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 1,
|
|
||||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
|
||||||
ty: wgpu::BindingType::Texture {
|
|
||||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
|
||||||
multisampled: false,
|
|
||||||
view_dimension: wgpu::TextureViewDimension::D2,
|
|
||||||
},
|
|
||||||
count: None,
|
|
||||||
},
|
|
||||||
wgpu::BindGroupLayoutEntry {
|
|
||||||
binding: 2,
|
|
||||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
|
||||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
|
||||||
count: None,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
let clamp_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
|
||||||
label: Some("Clamp Sampler"),
|
|
||||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
|
||||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
|
||||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
|
||||||
mag_filter: wgpu::FilterMode::Linear,
|
|
||||||
min_filter: wgpu::FilterMode::Linear,
|
|
||||||
mipmap_filter: wgpu::FilterMode::Linear,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
let repeat_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
|
||||||
label: Some("Repeat Sampler"),
|
|
||||||
address_mode_u: wgpu::AddressMode::Repeat,
|
|
||||||
address_mode_v: wgpu::AddressMode::Repeat,
|
|
||||||
address_mode_w: wgpu::AddressMode::Repeat,
|
|
||||||
mag_filter: wgpu::FilterMode::Linear,
|
|
||||||
min_filter: wgpu::FilterMode::Linear,
|
|
||||||
mipmap_filter: wgpu::FilterMode::Linear,
|
|
||||||
..Default::default()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create the render pipeline
|
// Create the render pipeline
|
||||||
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||||
@@ -520,7 +231,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
grounded: false,
|
grounded: false,
|
||||||
walkspeed: 18.0,
|
walkspeed: 18.0,
|
||||||
contacts: std::collections::HashSet::new(),
|
contacts: std::collections::HashSet::new(),
|
||||||
models: Vec::new(),
|
models_cringe_clone: modeldatas.iter().map(|m|strafe_client::body::Model::new(m.transform)).collect(),
|
||||||
walk: strafe_client::body::WalkState::new(),
|
walk: strafe_client::body::WalkState::new(),
|
||||||
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
hitbox_halfsize: glam::vec3(1.0,2.5,1.0),
|
||||||
camera: strafe_client::body::Camera::from_offset(glam::vec3(0.0,4.5-2.5,0.0),(config.width as f32)/(config.height as f32)),
|
camera: strafe_client::body::Camera::from_offset(glam::vec3(0.0,4.5-2.5,0.0),(config.width as f32)/(config.height as f32)),
|
||||||
@@ -528,135 +239,51 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
controls: 0,
|
controls: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
//load textures
|
let camera_uniforms = to_uniform_data(&physics.camera,physics.body.extrapolated_position(0));
|
||||||
let device_features = device.features();
|
let camera_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
|
label: Some("Camera"),
|
||||||
|
contents: bytemuck::cast_slice(&camera_uniforms),
|
||||||
|
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||||
|
});
|
||||||
|
|
||||||
let skybox_texture_view={
|
//drain the modeldata vec so entities can be /moved/ to models.entities
|
||||||
let skybox_format = if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC) {
|
let mut models = Vec::<ModelGraphics>::with_capacity(modeldatas.len());
|
||||||
log::info!("Using ASTC");
|
for (i,modeldata) in modeldatas.drain(..).enumerate() {
|
||||||
wgpu::TextureFormat::Astc {
|
let model_uniforms = get_transform_uniform_data(&modeldata.transform);
|
||||||
block: AstcBlock::B4x4,
|
let model_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
channel: AstcChannel::UnormSrgb,
|
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||||
}
|
contents: bytemuck::cast_slice(&model_uniforms),
|
||||||
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) {
|
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||||
log::info!("Using ETC2");
|
});
|
||||||
wgpu::TextureFormat::Etc2Rgb8UnormSrgb
|
let model_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) {
|
layout: &model_bind_group_layout,
|
||||||
log::info!("Using BC");
|
entries: &[
|
||||||
wgpu::TextureFormat::Bc1RgbaUnormSrgb
|
wgpu::BindGroupEntry {
|
||||||
} else {
|
binding: 0,
|
||||||
log::info!("Using plain");
|
resource: model_buf.as_entire_binding(),
|
||||||
wgpu::TextureFormat::Bgra8UnormSrgb
|
},
|
||||||
};
|
],
|
||||||
|
label: Some(format!("ModelGraphics{}",i).as_str()),
|
||||||
let size = wgpu::Extent3d {
|
});
|
||||||
width: IMAGE_SIZE,
|
//all of these are being moved here
|
||||||
height: IMAGE_SIZE,
|
models.push(ModelGraphics{
|
||||||
depth_or_array_layers: 6,
|
transform: modeldata.transform,
|
||||||
};
|
vertex_buf:modeldata.vertex_buf,
|
||||||
|
entities: modeldata.entities,
|
||||||
let layer_size = wgpu::Extent3d {
|
bind_group: model_bind_group,
|
||||||
depth_or_array_layers: 1,
|
model_buf,
|
||||||
..size
|
|
||||||
};
|
|
||||||
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
|
|
||||||
|
|
||||||
log::debug!(
|
|
||||||
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
|
|
||||||
skybox_format,
|
|
||||||
IMAGE_SIZE,
|
|
||||||
IMAGE_SIZE,
|
|
||||||
max_mips,
|
|
||||||
);
|
|
||||||
|
|
||||||
let bytes = match skybox_format {
|
|
||||||
wgpu::TextureFormat::Astc {
|
|
||||||
block: AstcBlock::B4x4,
|
|
||||||
channel: AstcChannel::UnormSrgb,
|
|
||||||
} => &include_bytes!("../images/astc.dds")[..],
|
|
||||||
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => &include_bytes!("../images/etc2.dds")[..],
|
|
||||||
wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("../images/bc1.dds")[..],
|
|
||||||
wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("../images/bgra.dds")[..],
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let skybox_image = ddsfile::Dds::read(&mut std::io::Cursor::new(&bytes)).unwrap();
|
|
||||||
|
|
||||||
let skybox_texture = device.create_texture_with_data(
|
|
||||||
queue,
|
|
||||||
&wgpu::TextureDescriptor {
|
|
||||||
size,
|
|
||||||
mip_level_count: max_mips,
|
|
||||||
sample_count: 1,
|
|
||||||
dimension: wgpu::TextureDimension::D2,
|
|
||||||
format: skybox_format,
|
|
||||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
|
||||||
label: Some("Skybox Texture"),
|
|
||||||
view_formats: &[],
|
|
||||||
},
|
|
||||||
&skybox_image.data,
|
|
||||||
);
|
|
||||||
|
|
||||||
skybox_texture.create_view(&wgpu::TextureViewDescriptor {
|
|
||||||
label: Some("Skybox Texture View"),
|
|
||||||
dimension: Some(wgpu::TextureViewDimension::Cube),
|
|
||||||
..wgpu::TextureViewDescriptor::default()
|
|
||||||
})
|
})
|
||||||
};
|
}
|
||||||
|
|
||||||
//squid
|
|
||||||
let squid_texture_view={
|
|
||||||
let bytes = &include_bytes!("../images/squid.dds")[..];
|
|
||||||
|
|
||||||
let image = ddsfile::Dds::read(&mut std::io::Cursor::new(&bytes)).unwrap();
|
|
||||||
|
|
||||||
let size = wgpu::Extent3d {
|
|
||||||
width: image.get_width(),
|
|
||||||
height: image.get_height(),
|
|
||||||
depth_or_array_layers: 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
let layer_size = wgpu::Extent3d {
|
|
||||||
depth_or_array_layers: 1,
|
|
||||||
..size
|
|
||||||
};
|
|
||||||
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
|
|
||||||
|
|
||||||
let texture = device.create_texture_with_data(
|
|
||||||
queue,
|
|
||||||
&wgpu::TextureDescriptor {
|
|
||||||
size,
|
|
||||||
mip_level_count: max_mips,
|
|
||||||
sample_count: 1,
|
|
||||||
dimension: wgpu::TextureDimension::D2,
|
|
||||||
format: wgpu::TextureFormat::Bc7RgbaUnorm,
|
|
||||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
|
||||||
label: Some("Squid Texture"),
|
|
||||||
view_formats: &[],
|
|
||||||
},
|
|
||||||
&image.data,
|
|
||||||
);
|
|
||||||
|
|
||||||
texture.create_view(&wgpu::TextureViewDescriptor {
|
|
||||||
label: Some("Squid Texture View"),
|
|
||||||
dimension: Some(wgpu::TextureViewDimension::D2),
|
|
||||||
..wgpu::TextureViewDescriptor::default()
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
bind_group_layouts: &[
|
bind_group_layouts: &[&main_bind_group_layout, &model_bind_group_layout],
|
||||||
&camera_bind_group_layout,
|
|
||||||
&model_bind_group_layout,
|
|
||||||
&skybox_texture_bind_group_layout,
|
|
||||||
],
|
|
||||||
push_constant_ranges: &[],
|
push_constant_ranges: &[],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create the render pipelines
|
// Create the render pipelines
|
||||||
let sky_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let sky_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: Some("Sky Pipeline"),
|
label: Some("Sky"),
|
||||||
layout: Some(&pipeline_layout),
|
layout: Some(&pipeline_layout),
|
||||||
vertex: wgpu::VertexState {
|
vertex: wgpu::VertexState {
|
||||||
module: &shader,
|
module: &shader,
|
||||||
@@ -682,21 +309,48 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
multisample: wgpu::MultisampleState::default(),
|
multisample: wgpu::MultisampleState::default(),
|
||||||
multiview: None,
|
multiview: None,
|
||||||
});
|
});
|
||||||
let model_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
let entity_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
label: Some("Model Pipeline"),
|
label: Some("Entity"),
|
||||||
layout: Some(&pipeline_layout),
|
layout: Some(&pipeline_layout),
|
||||||
vertex: wgpu::VertexState {
|
vertex: wgpu::VertexState {
|
||||||
module: &shader,
|
module: &shader,
|
||||||
entry_point: "vs_entity_texture",
|
entry_point: "vs_entity",
|
||||||
buffers: &[wgpu::VertexBufferLayout {
|
buffers: &[wgpu::VertexBufferLayout {
|
||||||
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
|
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
|
||||||
step_mode: wgpu::VertexStepMode::Vertex,
|
step_mode: wgpu::VertexStepMode::Vertex,
|
||||||
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32x3, 3 => Float32x4],
|
attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32x3],
|
||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
fragment: Some(wgpu::FragmentState {
|
fragment: Some(wgpu::FragmentState {
|
||||||
module: &shader,
|
module: &shader,
|
||||||
entry_point: "fs_entity_texture",
|
entry_point: "fs_entity",
|
||||||
|
targets: &[Some(config.view_formats[0].into())],
|
||||||
|
}),
|
||||||
|
primitive: wgpu::PrimitiveState {
|
||||||
|
front_face: wgpu::FrontFace::Cw,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
depth_stencil: Some(wgpu::DepthStencilState {
|
||||||
|
format: Self::DEPTH_FORMAT,
|
||||||
|
depth_write_enabled: true,
|
||||||
|
depth_compare: wgpu::CompareFunction::LessEqual,
|
||||||
|
stencil: wgpu::StencilState::default(),
|
||||||
|
bias: wgpu::DepthBiasState::default(),
|
||||||
|
}),
|
||||||
|
multisample: wgpu::MultisampleState::default(),
|
||||||
|
multiview: None,
|
||||||
|
});
|
||||||
|
let ground_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||||
|
label: Some("Ground"),
|
||||||
|
layout: Some(&pipeline_layout),
|
||||||
|
vertex: wgpu::VertexState {
|
||||||
|
module: &shader,
|
||||||
|
entry_point: "vs_ground",
|
||||||
|
buffers: &[],
|
||||||
|
},
|
||||||
|
fragment: Some(wgpu::FragmentState {
|
||||||
|
module: &shader,
|
||||||
|
entry_point: "fs_ground",
|
||||||
targets: &[Some(config.view_formats[0].into())],
|
targets: &[Some(config.view_formats[0].into())],
|
||||||
}),
|
}),
|
||||||
primitive: wgpu::PrimitiveState {
|
primitive: wgpu::PrimitiveState {
|
||||||
@@ -714,93 +368,128 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
multiview: None,
|
multiview: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
let camera_uniforms = to_uniform_data(&physics.camera,physics.body.extrapolated_position(0));
|
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
let camera_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
label: None,
|
||||||
label: Some("Camera"),
|
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||||
contents: bytemuck::cast_slice(&camera_uniforms),
|
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||||
|
mag_filter: wgpu::FilterMode::Linear,
|
||||||
|
min_filter: wgpu::FilterMode::Linear,
|
||||||
|
mipmap_filter: wgpu::FilterMode::Linear,
|
||||||
|
..Default::default()
|
||||||
});
|
});
|
||||||
let camera_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
||||||
layout: &camera_bind_group_layout,
|
let device_features = device.features();
|
||||||
|
|
||||||
|
let skybox_format = if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ASTC) {
|
||||||
|
log::info!("Using ASTC");
|
||||||
|
wgpu::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B4x4,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
}
|
||||||
|
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_ETC2) {
|
||||||
|
log::info!("Using ETC2");
|
||||||
|
wgpu::TextureFormat::Etc2Rgb8UnormSrgb
|
||||||
|
} else if device_features.contains(wgpu::Features::TEXTURE_COMPRESSION_BC) {
|
||||||
|
log::info!("Using BC");
|
||||||
|
wgpu::TextureFormat::Bc1RgbaUnormSrgb
|
||||||
|
} else {
|
||||||
|
log::info!("Using plain");
|
||||||
|
wgpu::TextureFormat::Bgra8UnormSrgb
|
||||||
|
};
|
||||||
|
|
||||||
|
let size = wgpu::Extent3d {
|
||||||
|
width: IMAGE_SIZE,
|
||||||
|
height: IMAGE_SIZE,
|
||||||
|
depth_or_array_layers: 6,
|
||||||
|
};
|
||||||
|
|
||||||
|
let layer_size = wgpu::Extent3d {
|
||||||
|
depth_or_array_layers: 1,
|
||||||
|
..size
|
||||||
|
};
|
||||||
|
let max_mips = layer_size.max_mips(wgpu::TextureDimension::D2);
|
||||||
|
|
||||||
|
log::debug!(
|
||||||
|
"Copying {:?} skybox images of size {}, {}, 6 with {} mips to gpu",
|
||||||
|
skybox_format,
|
||||||
|
IMAGE_SIZE,
|
||||||
|
IMAGE_SIZE,
|
||||||
|
max_mips,
|
||||||
|
);
|
||||||
|
|
||||||
|
let bytes = match skybox_format {
|
||||||
|
wgpu::TextureFormat::Astc {
|
||||||
|
block: AstcBlock::B4x4,
|
||||||
|
channel: AstcChannel::UnormSrgb,
|
||||||
|
} => &include_bytes!("../images/astc.dds")[..],
|
||||||
|
wgpu::TextureFormat::Etc2Rgb8UnormSrgb => &include_bytes!("../images/etc2.dds")[..],
|
||||||
|
wgpu::TextureFormat::Bc1RgbaUnormSrgb => &include_bytes!("../images/bc1.dds")[..],
|
||||||
|
wgpu::TextureFormat::Bgra8UnormSrgb => &include_bytes!("../images/bgra.dds")[..],
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let image = ddsfile::Dds::read(&mut std::io::Cursor::new(&bytes)).unwrap();
|
||||||
|
|
||||||
|
let texture = device.create_texture_with_data(
|
||||||
|
queue,
|
||||||
|
&wgpu::TextureDescriptor {
|
||||||
|
size,
|
||||||
|
mip_level_count: max_mips,
|
||||||
|
sample_count: 1,
|
||||||
|
dimension: wgpu::TextureDimension::D2,
|
||||||
|
format: skybox_format,
|
||||||
|
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||||
|
label: None,
|
||||||
|
view_formats: &[],
|
||||||
|
},
|
||||||
|
&image.data,
|
||||||
|
);
|
||||||
|
|
||||||
|
let texture_view = texture.create_view(&wgpu::TextureViewDescriptor {
|
||||||
|
label: None,
|
||||||
|
dimension: Some(wgpu::TextureViewDimension::Cube),
|
||||||
|
..wgpu::TextureViewDescriptor::default()
|
||||||
|
});
|
||||||
|
let main_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||||
|
layout: &main_bind_group_layout,
|
||||||
entries: &[
|
entries: &[
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
resource: camera_buf.as_entire_binding(),
|
resource: camera_buf.as_entire_binding(),
|
||||||
},
|
},
|
||||||
],
|
|
||||||
label: Some("Camera"),
|
|
||||||
});
|
|
||||||
let skybox_texture_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
|
||||||
layout: &skybox_texture_bind_group_layout,
|
|
||||||
entries: &[
|
|
||||||
wgpu::BindGroupEntry {
|
|
||||||
binding: 0,
|
|
||||||
resource: wgpu::BindingResource::TextureView(&skybox_texture_view),
|
|
||||||
},
|
|
||||||
wgpu::BindGroupEntry {
|
wgpu::BindGroupEntry {
|
||||||
binding: 1,
|
binding: 1,
|
||||||
resource: wgpu::BindingResource::Sampler(&clamp_sampler),
|
resource: wgpu::BindingResource::TextureView(&texture_view),
|
||||||
|
},
|
||||||
|
wgpu::BindGroupEntry {
|
||||||
|
binding: 2,
|
||||||
|
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
label: Some("Sky Texture"),
|
label: Some("Camera"),
|
||||||
});
|
});
|
||||||
|
|
||||||
let depth_view = Self::create_depth_texture(config, device);
|
let depth_view = Self::create_depth_texture(config, device);
|
||||||
|
|
||||||
let mut graphics=GraphicsData {
|
Skybox {
|
||||||
handy_unit_cube:unit_cube,
|
|
||||||
start_time: Instant::now(),
|
start_time: Instant::now(),
|
||||||
screen_size: (config.width,config.height),
|
screen_size: (config.width,config.height),
|
||||||
physics,
|
physics,
|
||||||
pipelines:GraphicsPipelines{
|
sky_pipeline,
|
||||||
skybox:sky_pipeline,
|
entity_pipeline,
|
||||||
model:model_pipeline
|
ground_pipeline,
|
||||||
},
|
main_bind_group,
|
||||||
bind_groups:GraphicsBindGroups{
|
|
||||||
camera:camera_bind_group,
|
|
||||||
skybox_texture:skybox_texture_bind_group,
|
|
||||||
},
|
|
||||||
camera_buf,
|
camera_buf,
|
||||||
models: Vec::new(),
|
models,
|
||||||
depth_view,
|
depth_view,
|
||||||
staging_belt: wgpu::util::StagingBelt::new(0x100),
|
staging_belt: wgpu::util::StagingBelt::new(0x100),
|
||||||
bind_group_layouts: GraphicsBindGroupLayouts { model: model_bind_group_layout },
|
}
|
||||||
samplers: GraphicsSamplers { repeat: repeat_sampler },
|
|
||||||
temp_squid_texture_view: squid_texture_view,
|
|
||||||
};
|
|
||||||
|
|
||||||
graphics.generate_model_physics(&modeldatas);
|
|
||||||
graphics.generate_model_graphics(&device,modeldatas);
|
|
||||||
|
|
||||||
return graphics;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::single_match)]
|
#[allow(clippy::single_match)]
|
||||||
fn update(&mut self, device: &wgpu::Device, event: winit::event::WindowEvent) {
|
fn update(&mut self, event: winit::event::WindowEvent) {
|
||||||
match event {
|
//nothing atm
|
||||||
winit::event::WindowEvent::DroppedFile(path) => {
|
|
||||||
println!("opening file: {:?}", &path);
|
|
||||||
//oh boy! let's load the map!
|
|
||||||
if let Ok(file)=std::fs::File::open(path){
|
|
||||||
let input = std::io::BufReader::new(file);
|
|
||||||
let (modeldatas,spawn_point)=self.generate_modeldatas_roblox(input);
|
|
||||||
//if generate_modeldatas succeeds, clear the previous ones
|
|
||||||
self.models.clear();
|
|
||||||
self.physics.models.clear();
|
|
||||||
self.generate_model_physics(&modeldatas);
|
|
||||||
self.generate_model_graphics(device,modeldatas);
|
|
||||||
//manual reset
|
|
||||||
let time=self.physics.time;
|
|
||||||
strafe_client::instruction::InstructionConsumer::process_instruction(&mut self.physics, strafe_client::instruction::TimedInstruction{
|
|
||||||
time,
|
|
||||||
instruction: strafe_client::body::PhysicsInstruction::SetPosition(spawn_point),
|
|
||||||
})
|
|
||||||
}else{
|
|
||||||
println!("Could not open file");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_=>(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn device_event(&mut self, event: winit::event::DeviceEvent) {
|
fn device_event(&mut self, event: winit::event::DeviceEvent) {
|
||||||
@@ -901,7 +590,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
.copy_from_slice(bytemuck::cast_slice(&camera_uniforms));
|
.copy_from_slice(bytemuck::cast_slice(&camera_uniforms));
|
||||||
//This code only needs to run when the uniforms change
|
//This code only needs to run when the uniforms change
|
||||||
for model in self.models.iter() {
|
for model in self.models.iter() {
|
||||||
let model_uniforms = get_instances_buffer_data(&model.instances);
|
let model_uniforms = get_transform_uniform_data(&model.transform);
|
||||||
self.staging_belt
|
self.staging_belt
|
||||||
.write_buffer(
|
.write_buffer(
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
@@ -940,21 +629,25 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
rpass.set_bind_group(0, &self.bind_groups.camera, &[]);
|
rpass.set_bind_group(0, &self.main_bind_group, &[]);
|
||||||
rpass.set_bind_group(2, &self.bind_groups.skybox_texture, &[]);
|
|
||||||
|
|
||||||
rpass.set_pipeline(&self.pipelines.model);
|
rpass.set_pipeline(&self.entity_pipeline);
|
||||||
for model in self.models.iter() {
|
for model in self.models.iter() {
|
||||||
rpass.set_bind_group(1, &model.bind_group, &[]);
|
rpass.set_bind_group(1, &model.bind_group, &[]);
|
||||||
rpass.set_vertex_buffer(0, model.vertex_buf.slice(..));
|
rpass.set_vertex_buffer(0, model.vertex_buf.slice(..));
|
||||||
|
|
||||||
for entity in model.entities.iter() {
|
for entity in model.entities.iter() {
|
||||||
rpass.set_index_buffer(entity.index_buf.slice(..), wgpu::IndexFormat::Uint16);
|
rpass.set_index_buffer(entity.index_buf.slice(..), wgpu::IndexFormat::Uint16);
|
||||||
rpass.draw_indexed(0..entity.index_count, 0, 0..model.instances.len() as u32);
|
rpass.draw_indexed(0..entity.index_count, 0, 0..1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rpass.set_pipeline(&self.pipelines.skybox);
|
rpass.set_pipeline(&self.ground_pipeline);
|
||||||
|
//rpass.set_index_buffer(&[0u16,1,2,1,2,3][..] as wgpu::BufferSlice, wgpu::IndexFormat::Uint16);
|
||||||
|
//rpass.draw_indexed(0..4, 0, 0..1);
|
||||||
|
rpass.draw(0..6, 0..1);
|
||||||
|
|
||||||
|
rpass.set_pipeline(&self.sky_pipeline);
|
||||||
rpass.draw(0..3, 0..1);
|
rpass.draw(0..3, 0..1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -965,7 +658,7 @@ impl strafe_client::framework::Example for GraphicsData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
strafe_client::framework::run::<GraphicsData>(
|
strafe_client::framework::run::<Skybox>(
|
||||||
format!("Strafe Client v{}",
|
format!("Strafe Client v{}",
|
||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
).as_str()
|
).as_str()
|
||||||
|
|||||||
125
src/shader.wgsl
125
src/shader.wgsl
@@ -1,4 +1,9 @@
|
|||||||
struct Camera {
|
struct SkyOutput {
|
||||||
|
@builtin(position) position: vec4<f32>,
|
||||||
|
@location(0) sampledir: vec3<f32>,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Data {
|
||||||
// from camera to screen
|
// from camera to screen
|
||||||
proj: mat4x4<f32>,
|
proj: mat4x4<f32>,
|
||||||
// from screen to camera
|
// from screen to camera
|
||||||
@@ -8,16 +13,9 @@ struct Camera {
|
|||||||
// camera position
|
// camera position
|
||||||
cam_pos: vec4<f32>,
|
cam_pos: vec4<f32>,
|
||||||
};
|
};
|
||||||
|
|
||||||
//group 0 is the camera
|
|
||||||
@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 {
|
||||||
@@ -32,8 +30,8 @@ fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 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;
|
||||||
@@ -41,70 +39,93 @@ fn vs_sky(@builtin(vertex_index) vertex_index: u32) -> SkyOutput {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ModelInstance{
|
struct GroundOutput {
|
||||||
transform:mat4x4<f32>,
|
@builtin(position) position: vec4<f32>,
|
||||||
//texture_transform:mat3x3<f32>,
|
@location(4) pos: vec3<f32>,
|
||||||
color:vec4<f32>,
|
};
|
||||||
}
|
|
||||||
//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
|
|
||||||
//group 1 is the model
|
|
||||||
@group(1)
|
|
||||||
@binding(0)
|
|
||||||
var<storage> model_instances: array<ModelInstance>;
|
|
||||||
@group(1)
|
|
||||||
@binding(1)
|
|
||||||
var model_texture: texture_2d<f32>;
|
|
||||||
@group(1)
|
|
||||||
@binding(2)
|
|
||||||
var model_sampler: sampler;
|
|
||||||
|
|
||||||
struct EntityOutputTexture {
|
@vertex
|
||||||
|
fn vs_ground(@builtin(vertex_index) vertex_index: u32) -> GroundOutput {
|
||||||
|
// hacky way to draw two triangles that make a square
|
||||||
|
let tmp1 = i32(vertex_index)/2-i32(vertex_index)/3;
|
||||||
|
let tmp2 = i32(vertex_index)&1;
|
||||||
|
let pos = vec3<f32>(
|
||||||
|
f32(tmp1) * 2.0 - 1.0,
|
||||||
|
0.0,
|
||||||
|
f32(tmp2) * 2.0 - 1.0
|
||||||
|
) * 160.0;
|
||||||
|
|
||||||
|
var result: GroundOutput;
|
||||||
|
result.pos = pos;
|
||||||
|
result.position = r_data.proj * r_data.view * vec4<f32>(pos, 1.0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct EntityOutput {
|
||||||
@builtin(position) position: vec4<f32>,
|
@builtin(position) position: vec4<f32>,
|
||||||
@location(1) texture: vec2<f32>,
|
@location(1) texture: vec2<f32>,
|
||||||
@location(2) normal: vec3<f32>,
|
@location(2) normal: vec3<f32>,
|
||||||
@location(3) view: vec3<f32>,
|
@location(3) view: vec3<f32>,
|
||||||
@location(4) color: vec4<f32>,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@group(1)
|
||||||
|
@binding(0)
|
||||||
|
var<uniform> r_EntityTransform: mat4x4<f32>;
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
fn vs_entity_texture(
|
fn vs_entity(
|
||||||
@builtin(instance_index) instance: u32,
|
|
||||||
@location(0) pos: vec3<f32>,
|
@location(0) pos: vec3<f32>,
|
||||||
@location(1) texture: vec2<f32>,
|
@location(1) texture: vec2<f32>,
|
||||||
@location(2) normal: vec3<f32>,
|
@location(2) normal: vec3<f32>,
|
||||||
@location(3) color: vec4<f32>,
|
) -> EntityOutput {
|
||||||
) -> EntityOutputTexture {
|
var position: vec4<f32> = r_EntityTransform * vec4<f32>(pos, 1.0);
|
||||||
var position: vec4<f32> = model_instances[instance].transform * vec4<f32>(pos, 1.0);
|
var result: EntityOutput;
|
||||||
var result: EntityOutputTexture;
|
result.normal = (r_EntityTransform * vec4<f32>(normal, 0.0)).xyz;
|
||||||
result.normal = (model_instances[instance].transform * vec4<f32>(normal, 0.0)).xyz;
|
result.texture=texture;
|
||||||
result.texture=texture;//(model_instances[instance].texture_transform * vec3<f32>(texture, 1.0)).xy;
|
result.view = position.xyz - r_data.cam_pos.xyz;
|
||||||
result.color=model_instances[instance].color * color;
|
result.position = r_data.proj * r_data.view * position;
|
||||||
result.view = position.xyz - camera.cam_pos.xyz;
|
|
||||||
result.position = camera.proj * camera.view * position;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//group 2 is the skybox texture
|
@group(0)
|
||||||
@group(2)
|
|
||||||
@binding(0)
|
|
||||||
var cube_texture: texture_cube<f32>;
|
|
||||||
@group(2)
|
|
||||||
@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 d = dot(normal, incident);
|
||||||
let reflected = incident - 2.0 * d * normal;
|
let reflected = incident - 2.0 * d * normal;
|
||||||
|
|
||||||
let fragment_color = textureSample(model_texture, model_sampler, vertex.texture)*vertex.color;
|
let dir = vec3<f32>(-1.0)+2.0*vec3<f32>(vertex.texture.x,0.0,vertex.texture.y);
|
||||||
let reflected_color = textureSample(cube_texture, cube_sampler, reflected).rgb;
|
let texture_color = textureSample(r_texture, r_sampler, dir).rgb;
|
||||||
return mix(vec4<f32>(vec3<f32>(0.1) + 0.5 * reflected_color,1.0),fragment_color,1.0-pow(1.0-abs(d),2.0));
|
let reflected_color = textureSample(r_texture, r_sampler, reflected).rgb;
|
||||||
|
return vec4<f32>(mix(vec3<f32>(0.1) + 0.5 * reflected_color,texture_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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user