1
0
Fork 0

Port to wgpu 8.0, broken because of spirv-stuff

This commit is contained in:
Adrian Hedqvist 2021-05-11 22:37:31 +02:00
parent 05ce6e42c3
commit ad6106b581
6 changed files with 323 additions and 349 deletions

340
Cargo.lock generated
View file

@ -26,9 +26,9 @@ checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]]
name = "aho-corasick"
version = "0.7.15"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
]
@ -69,11 +69,11 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "ash"
version = "0.31.0"
version = "0.32.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c69a8137596e84c22d57f3da1b5de1d4230b1742a710091c85f4d7ce50f00f38"
checksum = "06063a002a77d2734631db74e8f4ce7148b77fe522e6bca46f2ae7774fd48112"
dependencies = [
"libloading 0.6.7",
"libloading 0.7.0",
]
[[package]]
@ -220,12 +220,6 @@ dependencies = [
"num-traits",
]
[[package]]
name = "chlorine"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd650552110e39b7c5058986cf177decd3365841836578ac50a286094eac0be6"
[[package]]
name = "cmake"
version = "0.1.45"
@ -266,6 +260,16 @@ dependencies = [
"objc",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
dependencies = [
"termcolor",
"unicode-width",
]
[[package]]
name = "color_quant"
version = "1.1.0"
@ -371,9 +375,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.5.0"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
@ -392,9 +396,9 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.3"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12"
checksum = "52fb27eab85b17fbb9f6fd667089e07d6a2eb8743d02639ee7f6a7a7729c9c94"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
@ -405,9 +409,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.3"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49"
checksum = "4feb231f0d4d6af81aed15928e58ecf5816aa62a2393e2c82f46973e92a9a278"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
@ -416,12 +420,12 @@ dependencies = [
[[package]]
name = "d3d12"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a60cceb22c7c53035f8980524fdc7f17cf49681a3c154e6757d30afbec6ec4"
checksum = "091ed1b25fe47c7ff129fc440c23650b6114f36aa00bc7212cc8041879294428"
dependencies = [
"bitflags",
"libloading 0.6.7",
"libloading 0.7.0",
"winapi 0.3.9",
]
@ -581,9 +585,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futures"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f55667319111d593ba876406af7c409c0ebb44dc4be6132a783ccf163ea14c1"
checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253"
dependencies = [
"futures-channel",
"futures-core",
@ -596,9 +600,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939"
checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25"
dependencies = [
"futures-core",
"futures-sink",
@ -606,15 +610,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94"
checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815"
[[package]]
name = "futures-executor"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "891a4b7b96d84d5940084b2a37632dd65deeae662c114ceaa2c879629c9c0ad1"
checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d"
dependencies = [
"futures-core",
"futures-task",
@ -623,15 +627,15 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59"
checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04"
[[package]]
name = "futures-macro"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea405816a5139fb39af82c2beb921d52143f556038378d6db21183a5c37fbfb7"
checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b"
dependencies = [
"proc-macro-hack",
"proc-macro2",
@ -641,21 +645,21 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3"
checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23"
[[package]]
name = "futures-task"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80"
checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc"
[[package]]
name = "futures-util"
version = "0.3.13"
version = "0.3.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1"
checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025"
dependencies = [
"futures-channel",
"futures-core",
@ -693,9 +697,9 @@ dependencies = [
[[package]]
name = "gfx-auxil"
version = "0.8.0"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7b33ecf067f2117668d91c9b0f2e5f223ebd1ffec314caa2f3de27bb580186d"
checksum = "9ccf8711c9994dfa34337466bee3ae1462e172874c432ce4eb120ab2e98d39cf"
dependencies = [
"fxhash",
"gfx-hal",
@ -704,15 +708,15 @@ dependencies = [
[[package]]
name = "gfx-backend-dx11"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f851d03c2e8f117e3702bf41201a4fafa447d5cb1276d5375870ae7573d069dd"
checksum = "6f839f27f8c8a6dc553ccca7f5b35a42009432bc25db9688bba7061cd394161f"
dependencies = [
"arrayvec",
"bitflags",
"gfx-auxil",
"gfx-hal",
"libloading 0.6.7",
"libloading 0.7.0",
"log",
"parking_lot",
"range-alloc",
@ -726,9 +730,9 @@ dependencies = [
[[package]]
name = "gfx-backend-dx12"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36dc6ba2b7647e2c2b27b8f74ff5ccdd53c703776588eee5b1de515fdcbd6bc9"
checksum = "3937738b0da5839bba4e33980d29f9a06dbce184d04a3a08c9a949e7953700e3"
dependencies = [
"arrayvec",
"bit-set",
@ -742,14 +746,15 @@ dependencies = [
"raw-window-handle",
"smallvec",
"spirv_cross",
"thunderdome",
"winapi 0.3.9",
]
[[package]]
name = "gfx-backend-empty"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f07ef26a65954cfdd7b4c587f485100d1bb3b0bd6a51b02d817d6c87cca7a91"
checksum = "2ac55ada4bfcd35479b3421eea324d36d7da5f724e2f66ecb36d4efdb7041a5e"
dependencies = [
"gfx-hal",
"log",
@ -758,32 +763,31 @@ dependencies = [
[[package]]
name = "gfx-backend-gl"
version = "0.7.1"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6717c50ab601efe4a669bfb44db615e3888695ac8263222aeaa702642b9fbc2"
checksum = "0caa03d6e0b7b4f202aea1f20c3f3288cfa06d92d24cea9d69c9a7627967244a"
dependencies = [
"arrayvec",
"bitflags",
"gfx-auxil",
"fxhash",
"gfx-hal",
"glow",
"js-sys",
"khronos-egl",
"libloading 0.6.7",
"libloading 0.7.0",
"log",
"naga",
"parking_lot",
"raw-window-handle",
"spirv_cross",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gfx-backend-metal"
version = "0.7.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc54b456ece69ef49f8893269ebf24ac70969ed34ba2719c3f3abcc8fbff14e"
checksum = "96a809b746d8063ade971cfb3f188e2b0d655926979823d80be7590390f4b911"
dependencies = [
"arrayvec",
"bitflags",
@ -791,24 +795,24 @@ dependencies = [
"cocoa-foundation",
"copyless",
"foreign-types",
"gfx-auxil",
"fxhash",
"gfx-hal",
"log",
"metal",
"naga",
"objc",
"parking_lot",
"profiling",
"range-alloc",
"raw-window-handle",
"spirv_cross",
"storage-map",
]
[[package]]
name = "gfx-backend-vulkan"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dabe88b1a5c91e0f969b441cc57e70364858066e4ba937deeb62065654ef9bd9"
checksum = "a353fc6fdb42ec646de49bbb74e4870e37a7e680caf33f3ac0615c30b1146d94"
dependencies = [
"arrayvec",
"ash",
@ -827,9 +831,9 @@ dependencies = [
[[package]]
name = "gfx-hal"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1d9cc8d3b573dda62d0baca4f02e0209786e22c562caff001d77c389008781d"
checksum = "6d285bfd566f6b9134af908446ca350c0a1047495dfb9bbd826e701e8ee1d259"
dependencies = [
"bitflags",
"naga",
@ -855,9 +859,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "glow"
version = "0.7.2"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "072136d2c3783f3a92f131acb227bc806d3886278e2a4dc1e9990ec89ef9e70b"
checksum = "4b80b98efaa8a34fce11d60dd2ce2760d5d83c373cbcc73bb87c2a3a84a54108"
dependencies = [
"js-sys",
"slotmap",
@ -867,13 +871,12 @@ dependencies = [
[[package]]
name = "gpu-alloc"
version = "0.3.0"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e7724b9aef57ea36d70faf54e0ee6265f86e41de16bed8333efdeab5b00e16b"
checksum = "8159cab119e2c6947476a8b941d478c8de4a1ce050d92c55903f8d0192ccacda"
dependencies = [
"bitflags",
"gpu-alloc-types",
"tracing",
]
[[package]]
@ -894,7 +897,6 @@ dependencies = [
"bitflags",
"gpu-descriptor-types",
"hashbrown",
"tracing",
]
[[package]]
@ -955,50 +957,6 @@ dependencies = [
"tiff",
]
[[package]]
name = "imgui"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24cfcf6e3326886321c5d637caf1ce217006651059015fae372b1c49c0e722b2"
dependencies = [
"bitflags",
"imgui-sys",
"parking_lot",
]
[[package]]
name = "imgui-sys"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85ca00be6b78bf02b57e91468cf19d08dfcc11d0fb3c2f3dc491c29404d8d330"
dependencies = [
"cc",
"chlorine",
]
[[package]]
name = "imgui-wgpu"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79d5d73b68effcb4bcb89048e8c437e01c6d5675247d664188c584ce4d6d9696"
dependencies = [
"bytemuck",
"imgui",
"log",
"smallvec",
"wgpu",
]
[[package]]
name = "imgui-winit-support"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d632440e05c964e8a7f00f2659c4f71c97897d8c38a77a0c2dc1f3fe8d632208"
dependencies = [
"imgui",
"winit",
]
[[package]]
name = "indexmap"
version = "1.6.2"
@ -1041,9 +999,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jobserver"
version = "0.1.21"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2"
checksum = "972f5ae5d1cb9c6ae417789196c803205313edde988685da5e3aae0827b9e7fd"
dependencies = [
"libc",
]
@ -1059,9 +1017,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.46"
version = "0.3.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175"
checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c"
dependencies = [
"wasm-bindgen",
]
@ -1078,12 +1036,12 @@ dependencies = [
[[package]]
name = "khronos-egl"
version = "3.0.2"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b19cc4a81304db2a0ad69740e83cdc3a9364e3f9bd6d88a87288a4c2deec927b"
checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3"
dependencies = [
"libc",
"libloading 0.6.7",
"libloading 0.7.0",
]
[[package]]
@ -1100,9 +1058,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.92"
version = "0.2.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714"
checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
[[package]]
name = "libloading"
@ -1126,9 +1084,9 @@ dependencies = [
[[package]]
name = "lock_api"
version = "0.4.3"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176"
checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb"
dependencies = [
"scopeguard",
]
@ -1159,9 +1117,9 @@ checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memchr"
version = "2.3.4"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
[[package]]
name = "memmap2"
@ -1183,9 +1141,9 @@ dependencies = [
[[package]]
name = "metal"
version = "0.21.0"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4598d719460ade24c7d91f335daf055bf2a7eec030728ce751814c50cdd6a26c"
checksum = "1c12e48c737ee9a55e8bb2352bcde588f79ae308d3529ee888f7cc0f469b5777"
dependencies = [
"bitflags",
"block",
@ -1259,12 +1217,13 @@ dependencies = [
[[package]]
name = "naga"
version = "0.3.2"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05089b2acdf0e6a962cdbf5e328402345a27f59fcde1a59fe97a73e8149d416f"
checksum = "a462414ac6a74a8fcc2c6d235d9a92b288f22682c016cf725e75d0c9470fb515"
dependencies = [
"bit-set",
"bitflags",
"codespan-reporting",
"fxhash",
"log",
"num-traits",
@ -1577,6 +1536,12 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "profiling"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3a66d5e88679f2720126c11ee29da07a08f094eac52306b066edd7d393752d6"
[[package]]
name = "quote"
version = "1.0.9"
@ -1677,18 +1642,18 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.2.5"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9"
checksum = "85dd92e586f7355c633911e11f77f3d12f04b1b1bd76a198bd34ae3af8341ef2"
dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.4.5"
version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
checksum = "ce5f1ceb7f74abbce32601642fcf8e8508a8a8991e0621c7d750295b9095702b"
dependencies = [
"aho-corasick",
"memchr",
@ -1697,9 +1662,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.23"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "rusttype"
@ -1766,9 +1731,9 @@ dependencies = [
[[package]]
name = "slab"
version = "0.4.2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527"
[[package]]
name = "slotmap"
@ -1839,9 +1804,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "syn"
version = "1.0.65"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3a1d708c221c5a612956ef9f75b37e454e88d1f7b899fbd3a18d4252012d663"
checksum = "ad184cc9470f9117b2ac6817bfe297307418819ba40552f9b3846f05c33d5373"
dependencies = [
"proc-macro2",
"quote",
@ -1879,9 +1844,9 @@ dependencies = [
[[package]]
name = "thunderdome"
version = "0.3.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7572415bd688d401c52f6e36f4c8e805b9ae1622619303b9fa835d531db0acae"
checksum = "87b4947742c93ece24a0032141d9caa3d853752e694a57e35029dd2bd08673e0"
[[package]]
name = "tiff"
@ -1909,38 +1874,6 @@ dependencies = [
"serde",
]
[[package]]
name = "tracing"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f"
dependencies = [
"cfg-if 1.0.0",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f"
dependencies = [
"lazy_static",
]
[[package]]
name = "ttf-parser"
version = "0.6.2"
@ -1948,10 +1881,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e5d7cd7ab3e47dda6e56542f4bbf3824c15234958c6e1bd6aaa347e93499fdc"
[[package]]
name = "unicode-xid"
version = "0.2.1"
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "version_check"
@ -1978,9 +1917,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "wasm-bindgen"
version = "0.2.69"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e"
checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9"
dependencies = [
"cfg-if 1.0.0",
"wasm-bindgen-macro",
@ -1988,9 +1927,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.69"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62"
checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae"
dependencies = [
"bumpalo",
"lazy_static",
@ -2003,9 +1942,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.19"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35"
checksum = "81b8b767af23de6ac18bf2168b690bed2902743ddf0fb39252e36f9e2bfc63ea"
dependencies = [
"cfg-if 1.0.0",
"js-sys",
@ -2015,9 +1954,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.69"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084"
checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -2025,9 +1964,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.69"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c"
dependencies = [
"proc-macro2",
"quote",
@ -2038,9 +1977,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.69"
version = "0.2.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158"
checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489"
[[package]]
name = "wayland-client"
@ -2117,9 +2056,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.46"
version = "0.3.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3"
checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -2127,24 +2066,23 @@ dependencies = [
[[package]]
name = "weezl"
version = "0.1.4"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a32b378380f4e9869b22f0b5177c68a5519f03b3454fde0b291455ddbae266c"
checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
[[package]]
name = "wgpu"
version = "0.7.1"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79a0a0a63fac9492cfaf6e7e4bdf9729c128f1e94124b9e4cbc4004b8cb6d1d8"
checksum = "f07667388164ad75066dcbab46e295abd8204fd9a6dc057704b8d703837d12a8"
dependencies = [
"arrayvec",
"js-sys",
"log",
"naga",
"parking_lot",
"raw-window-handle",
"smallvec",
"syn",
"tracing",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
@ -2154,9 +2092,9 @@ dependencies = [
[[package]]
name = "wgpu-core"
version = "0.7.1"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c89fa2cc5d72236461ac09c5be967012663e29cb62f1a972654cbf35e49dffa8"
checksum = "59abd59fe91fe502fe2dd8777bcac414069199af22dd2a92a1bb635f9f251425"
dependencies = [
"arrayvec",
"bitflags",
@ -2172,12 +2110,13 @@ dependencies = [
"gfx-hal",
"gpu-alloc",
"gpu-descriptor",
"log",
"naga",
"parking_lot",
"profiling",
"raw-window-handle",
"smallvec",
"thiserror",
"tracing",
"wgpu-types",
]
@ -2194,9 +2133,6 @@ dependencies = [
"futures",
"glob",
"image",
"imgui",
"imgui-wgpu",
"imgui-winit-support",
"log",
"rayon",
"shaderc",
@ -2207,9 +2143,9 @@ dependencies = [
[[package]]
name = "wgpu-types"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72fa9ba80626278fd87351555c363378d08122d7601e58319be3d6fa85a87747"
checksum = "aa248d90c8e6832269b8955bf800e8241f942c25e18a235b7752226804d21556"
dependencies = [
"bitflags",
]

View file

@ -7,7 +7,7 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
wgpu = "0.7.1"
wgpu = { version = "0.8.0" }
winit = "0.24.0"
image = "0.23"
futures = "0.3"
@ -17,11 +17,14 @@ env_logger = "0.8"
log = "0.4"
tobj = "2"
cgmath = "0.18.0"
imgui = "0.7.0"
imgui-wgpu = "0.14.0"
imgui-winit-support = "0.7.0"
# imgui = "0.7.0"
# imgui-wgpu = "0.14.0"
# imgui-winit-support = "0.7.0"
bracket-noise = "0.8.1"
rayon = "1"
# egui = "0.11.0"
# egui_wgpu_backend = "0.7.0"
# egui_winit_platform = "0.6.0"
[build-dependencies]
shaderc = "0.7"

View file

@ -1,6 +1,5 @@
use imgui::im_str;
use model::{DrawLight, DrawModel, Model, Vertex};
use wgpu::util::DeviceExt;
use wgpu::{util::DeviceExt, vertex_attr_array};
use winit::{
dpi::PhysicalPosition,
event::*,
@ -31,9 +30,9 @@ fn main() {
let mut last_frame = std::time::Instant::now();
event_loop.run(move |event, _, control_flow| {
state
.imgui_platform
.handle_event(state.imgui.io_mut(), &state.window, &event);
// state
// .imgui_platform
// .handle_event(state.imgui.io_mut(), &state.window, &event);
match event {
Event::WindowEvent {
ref event,
@ -76,7 +75,7 @@ fn main() {
Event::MainEventsCleared => {
let now = std::time::Instant::now();
let dt = now - last_frame;
state.imgui.io_mut().update_delta_time(dt);
// state.imgui.io_mut().update_delta_time(dt);
state.update(dt.as_secs_f32());
last_frame = now;
state.window.request_redraw();
@ -131,30 +130,31 @@ impl model::Vertex for InstanceRaw {
// This means that our shaders will only change to use the next
// instance when the shader starts processing a new instance
step_mode: wgpu::InputStepMode::Instance,
// attributes: &vertex_attr_array![ 5 => Float32x4, 6 => Float32x4, 7 => Float32x4, 8 => Float32x4 ],
attributes: &[
wgpu::VertexAttribute {
offset: 0,
// While our vertex shader only uses locations 0, and 1 now, in later tutorials we'll
// be using 2, 3, and 4, for Vertex. We'll start at slot 5 not conflict with them later
shader_location: 5,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
},
// A mat4 takes up 4 vertex slots as it is technically 4 vec4s. We need to define a slot
// for each vec4. We don't have to do this in code though.
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 4]>() as wgpu::BufferAddress,
shader_location: 6,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 8]>() as wgpu::BufferAddress,
shader_location: 7,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 12]>() as wgpu::BufferAddress,
shader_location: 8,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
},
],
}
@ -200,9 +200,9 @@ struct State {
size: winit::dpi::PhysicalSize<u32>,
imgui: imgui::Context,
imgui_platform: imgui_winit_support::WinitPlatform,
imgui_renderer: imgui_wgpu::Renderer,
// imgui: imgui::Context,
// imgui_platform: imgui_winit_support::WinitPlatform,
// imgui_renderer: imgui_wgpu::Renderer,
rotation_speed: f32,
@ -266,7 +266,7 @@ impl State {
binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler {
filtering: false,
filtering: true,
comparison: false,
},
count: None,
@ -286,7 +286,7 @@ impl State {
binding: 3,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler {
filtering: false,
filtering: true,
comparison: false,
},
count: None,
@ -444,40 +444,40 @@ impl State {
let depth_texture =
texture::Texture::create_depth_texture(&device, &sc_desc, "depth_texture");
let mut imgui = imgui::Context::create();
let mut imgui_platform = imgui_winit_support::WinitPlatform::init(&mut imgui);
imgui_platform.attach_window(
imgui.io_mut(),
&window,
imgui_winit_support::HiDpiMode::Default,
);
// let mut imgui = imgui::Context::create();
// let mut imgui_platform = imgui_winit_support::WinitPlatform::init(&mut imgui);
// imgui_platform.attach_window(
// imgui.io_mut(),
// &window,
// imgui_winit_support::HiDpiMode::Default,
// );
imgui.set_ini_filename(None);
// imgui.set_ini_filename(None);
let hidpi_factor = window.scale_factor();
let font_size = (13.0 * hidpi_factor) as f32;
imgui.io_mut().font_global_scale = (1.0 / hidpi_factor) as f32;
// let hidpi_factor = window.scale_factor();
// let font_size = (13.0 * hidpi_factor) as f32;
// imgui.io_mut().font_global_scale = (1.0 / hidpi_factor) as f32;
imgui
.fonts()
.add_font(&[imgui::FontSource::DefaultFontData {
config: Some(imgui::FontConfig {
oversample_h: 1,
pixel_snap_h: true,
size_pixels: font_size,
..Default::default()
}),
}]);
// imgui
// .fonts()
// .add_font(&[imgui::FontSource::DefaultFontData {
// config: Some(imgui::FontConfig {
// oversample_h: 1,
// pixel_snap_h: true,
// size_pixels: font_size,
// ..Default::default()
// }),
// }]);
let imgui_renderer = imgui_wgpu::Renderer::new(
&mut imgui,
&device,
&queue,
imgui_wgpu::RendererConfig {
texture_format: sc_desc.format,
..Default::default()
},
);
// let imgui_renderer = imgui_wgpu::Renderer::new(
// &mut imgui,
// &device,
// &queue,
// imgui_wgpu::RendererConfig {
// texture_format: sc_desc.format,
// ..Default::default()
// },
// );
Self {
window,
@ -504,9 +504,9 @@ impl State {
instance_buffer,
render_pipeline,
size,
imgui,
imgui_platform,
imgui_renderer,
// imgui,
// imgui_platform,
// imgui_renderer,
rotation_speed: 1.0,
last_mouse_pos: (0.0, 0.0).into(),
mouse_pressed: false,
@ -534,25 +534,25 @@ impl State {
},
..
} => {
if self.imgui.io().want_capture_keyboard {
true
} else {
// if self.imgui.io().want_capture_keyboard {
// true
// } else {
self.camera_controller.process_keyboard(*key, *state)
}
// }
}
WindowEvent::CursorMoved { position, .. } => {
if !self.imgui.io().want_capture_mouse {
// if !self.imgui.io().want_capture_mouse {
let mouse_dx = position.x - self.last_mouse_pos.x;
let mouse_dy = position.y - self.last_mouse_pos.y;
if self.mouse_pressed {
self.camera_controller.process_mouse(mouse_dx, mouse_dy);
}
self.last_mouse_pos = *position;
}
// }
true
}
WindowEvent::MouseInput { state, button, .. } => {
if !self.imgui.io().want_capture_mouse && *button == MouseButton::Left {
if /* !self.imgui.io().want_capture_mouse && */ *button == MouseButton::Left {
self.mouse_pressed = *state == ElementState::Pressed;
}
true
@ -615,23 +615,23 @@ impl State {
fn render(&mut self) -> Result<(), wgpu::SwapChainError> {
let frame = self.swap_chain.get_current_frame()?;
self.imgui_platform
.prepare_frame(self.imgui.io_mut(), &self.window)
.expect("Failed to prepare imgui frame");
let ui = self.imgui.frame();
// self.imgui_platform
// .prepare_frame(self.imgui.io_mut(), &self.window)
// .expect("Failed to prepare imgui frame");
// let ui = self.imgui.frame();
{
let mut spd = self.rotation_speed;
imgui::Window::new(im_str!("wgpu tutorial!"))
.size([300.0, 100.0], imgui::Condition::FirstUseEver)
.build(&ui, || {
ui.text(im_str!("wooo!"));
imgui::Slider::new(im_str!("RotSpeed"))
.range(-10.0..=10.0)
.build(&ui, &mut spd);
});
self.rotation_speed = spd;
}
// {
// let mut spd = self.rotation_speed;
// imgui::Window::new(im_str!("wgpu tutorial!"))
// .size([300.0, 100.0], imgui::Condition::FirstUseEver)
// .build(&ui, || {
// ui.text(im_str!("wooo!"));
// imgui::Slider::new(im_str!("RotSpeed"))
// .range(-10.0..=10.0)
// .build(&ui, &mut spd);
// });
// self.rotation_speed = spd;
// }
let mut encoder = self
.device
@ -641,8 +641,8 @@ impl State {
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.output.view,
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &frame.output.view,
resolve_target: None,
ops: wgpu::Operations::<wgpu::Color> {
load: wgpu::LoadOp::Clear(wgpu::Color {
@ -654,8 +654,8 @@ impl State {
store: true,
},
}],
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
attachment: &self.depth_texture.view,
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
view: &self.depth_texture.view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(1.0),
store: true,
@ -683,12 +683,12 @@ impl State {
drop(render_pass);
self.imgui_platform.prepare_render(&ui, &self.window);
// self.imgui_platform.prepare_render(&ui, &self.window);
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.output.view,
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &frame.output.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load, // Do not clear
@ -699,9 +699,9 @@ impl State {
depth_stencil_attachment: None,
});
self.imgui_renderer
.render(ui.render(), &self.queue, &self.device, &mut rpass)
.expect("Failed to render UI!");
// self.imgui_renderer
// .render(ui.render(), &self.queue, &self.device, &mut rpass)
// .expect("Failed to render UI!");
drop(rpass);
@ -736,8 +736,7 @@ fn create_render_pipeline(
entry_point: "main",
targets: &[wgpu::ColorTargetState {
format: color_format,
alpha_blend: wgpu::BlendState::REPLACE,
color_blend: wgpu::BlendState::REPLACE,
blend: Some(wgpu::BlendState::REPLACE),
write_mask: wgpu::ColorWrite::ALL,
}],
}),
@ -745,8 +744,10 @@ fn create_render_pipeline(
topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None,
front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::Back,
cull_mode: Some(wgpu::Face::Back),
polygon_mode: wgpu::PolygonMode::Fill,
clamp_depth: false,
conservative: false,
},
depth_stencil: depth_format.map(|format| wgpu::DepthStencilState {
format,
@ -754,7 +755,6 @@ fn create_render_pipeline(
depth_compare: wgpu::CompareFunction::Less,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
clamp_depth: false,
}),
multisample: wgpu::MultisampleState {
count: 1,

View file

@ -3,7 +3,7 @@ use std::{ops::Range, path::Path};
use crate::texture;
use anyhow::*;
use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator};
use wgpu::{self, util::DeviceExt};
use wgpu::{self, util::DeviceExt, vertex_attr_array};
pub trait Vertex {
fn desc<'a>() -> wgpu::VertexBufferLayout<'a>;
@ -25,32 +25,33 @@ impl Vertex for ModelVertex {
wgpu::VertexBufferLayout {
array_stride: mem::size_of::<ModelVertex>() as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
// attributes: &vertex_attr_array![ 0 => Float32x3, 1 => Float32x2, 2 => Float32x3, 3 => Float32x3, 4 => Float32x2 ],
attributes: &[
wgpu::VertexAttribute {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
shader_location: 1,
format: wgpu::VertexFormat::Float2,
format: wgpu::VertexFormat::Float32x2,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 5]>() as wgpu::BufferAddress,
shader_location: 2,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
// Tangent & Bitangent
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 8]>() as wgpu::BufferAddress,
shader_location: 3,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 11]>() as wgpu::BufferAddress,
shader_location: 4,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
],
}

View file

@ -1,14 +1,13 @@
use bracket_noise::prelude::*;
use cgmath::{prelude::*, AbsDiffEq, Vector3};
use rayon::prelude::*;
use wgpu::vertex_attr_array;
use crate::model::Vertex;
mod table;
const CHUNK_SIZE: usize = 32;
const CHUNK_ARRAY_SIZE: usize = CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE;
const THRESHOLD: f32 = 0.5;
const THRESHOLD: f32 = 0.0;
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
@ -23,40 +22,50 @@ impl Vertex for TerrainVertex {
wgpu::VertexBufferLayout {
array_stride: mem::size_of::<TerrainVertex>() as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
// attributes: &vertex_attr_array![ 0 => Float32x3, 1 => Float32x3 ],
attributes: &[
wgpu::VertexAttribute {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
wgpu::VertexAttribute {
offset: mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
shader_location: 1,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
},
],
}
}
}
fn generate_terrain_voxels(
fn generate_terrain_voxels<const SIZE: usize>(
seed: u64,
chunk_coords: Vector3<i32>,
) -> [[[f32; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE] {
) -> [[[f32; SIZE]; SIZE]; SIZE] {
let mut noise = FastNoise::new();
let chunk_coords = chunk_coords * CHUNK_SIZE as i32;
noise.set_seed(seed);
noise.set_frequency(0.1);
let chunk_coords = chunk_coords * (SIZE-1) as i32;
let mut chunk_values = [[[0.0; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE];
noise.set_seed(seed);
noise.set_frequency(0.04);
let mut heightmap = [[0.0; SIZE]; SIZE];
heightmap.par_iter_mut().enumerate().for_each(|(x, v)| {
v.par_iter_mut().enumerate().for_each(|(y, v)| {
*v = (noise.get_noise(
chunk_coords.x as f32 + x as f32,
chunk_coords.z as f32 + y as f32,
) + 1.0) / 2.0
* SIZE as f32
})
});
let mut chunk_values = [[[0.0; SIZE]; SIZE]; SIZE];
chunk_values.par_iter_mut().enumerate().for_each(|(x, v)| {
v.par_iter_mut().enumerate().for_each(|(y, v)| {
v.par_iter_mut().enumerate().for_each(|(z, v)| {
*v = noise.get_noise3d(
chunk_coords.x as f32 + x as f32,
chunk_coords.y as f32 + y as f32,
chunk_coords.z as f32 + z as f32,
)
*v = (heightmap[x][z] - y as f32).clamp(-2.0, 2.0);
})
})
});
@ -64,11 +73,13 @@ fn generate_terrain_voxels(
chunk_values
}
fn marching_cubes(chunk_data: [[[f32; CHUNK_SIZE]; CHUNK_SIZE]; CHUNK_SIZE]) -> Vec<TerrainVertex> {
(0..CHUNK_SIZE - 1)
fn marching_cubes<const SIZE: usize>(
chunk_data: [[[f32; SIZE]; SIZE]; SIZE],
) -> Vec<TerrainVertex> {
(0..SIZE - 1)
.into_par_iter()
.flat_map(|x| (0..CHUNK_SIZE - 1).into_par_iter().map(move |y| (x, y)))
.flat_map(|(x, y)| (0..CHUNK_SIZE - 1).into_par_iter().map(move |z| (x, y, z)))
.flat_map(|x| (0..SIZE - 1).into_par_iter().map(move |y| (x, y)))
.flat_map(|(x, y)| (0..SIZE - 1).into_par_iter().map(move |z| (x, y, z)))
.map(|(x, y, z)| {
let corners = [
Vector3::new(x as f32, y as f32, z as f32),
@ -205,8 +216,8 @@ fn calculate_points(edge: i32, corners: [Vector3<f32>; 8], values: [f32; 8]) ->
fn optimize_mesh(mesh: Vec<TerrainVertex>) -> (Vec<TerrainVertex>, Vec<usize>) {
fn equal(a: &[f32; 3], b: &[f32; 3]) -> bool {
a[0].abs_diff_eq(&b[0], f32::EPSILON)
&& a[1].abs_diff_eq(&b[1], f32::EPSILON)
&& a[2].abs_diff_eq(&b[2], f32::EPSILON)
&& a[1].abs_diff_eq(&b[1], f32::EPSILON*2.0)
&& a[2].abs_diff_eq(&b[2], f32::EPSILON*2.0)
}
let mut indices: Vec<usize> = vec![];
@ -234,31 +245,54 @@ mod tests {
use super::*;
#[test]
fn test_gen() {
let start = std::time::Instant::now();
let data = generate_terrain_voxels(0, Vector3 { x: 0, y: 0, z: 0 });
let duration = std::time::Instant::now() - start;
eprintln!("Voxel generation took {}s", duration.as_secs_f64());
let chunks: Vec<(Vec<TerrainVertex>, Vec<usize>, Vector3<i32>)> = (0..9).into_par_iter().map(|i| {
let pos = Vector3 {
x: i % 3 - 1,
y: 0,
z: i / 3 - 1,
};
let time_vox = std::time::Instant::now();
let voxels = generate_terrain_voxels::<32>(0, pos);
let time_vox = std::time::Instant::now() - time_vox;
let start = std::time::Instant::now();
let vert = marching_cubes(data);
let duration = std::time::Instant::now() - start;
eprintln!("Mesh generation took {}s", duration.as_secs_f64());
let time_vert = std::time::Instant::now();
let vertices = marching_cubes(voxels);
let time_vert = std::time::Instant::now() - time_vert;
let start = std::time::Instant::now();
let (vert, idx) = optimize_mesh(vert);
let duration = std::time::Instant::now() - start;
eprintln!("Mesh optimization took {}s", duration.as_secs_f64());
let time_indexing = std::time::Instant::now();
let (verts, idx) = optimize_mesh(vertices);
let time_indexing = std::time::Instant::now() - time_indexing;
eprintln!(
"Timing for chunk: {:?}, Voxels {}s, Vertices {}s, Indexing {}s",
pos,
time_vox.as_secs_f64(),
time_vert.as_secs_f64(),
time_indexing.as_secs_f64()
);
(verts, idx, pos)
}).collect();
for v in &vert {
let [x, y, z] = v.position;
println!("v {} {} {}", x, y, z);
}
for v in &vert {
let [x, y, z] = v.normal;
println!("vn {} {} {}", x, y, z);
}
for i in idx.chunks(3) {
println!("f {} {} {}", i[0] + 1, i[1] + 1, i[2] + 1);
let mut vert = String::new();
let mut norm = String::new();
let mut face = String::new();
let mut id_offset = 1;
for (verts, idx, pos) in chunks {
let pos = Vector3::new((pos.x*31) as f32, (pos.y*31) as f32, (pos.z*31) as f32);
for v in &verts {
let [x, y, z] = v.position;
assert!(!x.is_nan() && !y.is_nan() && !z.is_nan(), "vertex was NaN!");
vert.push_str(&format!("v {} {} {}\n", x + pos.x, y + pos.y, z + pos.z));
// let [x, y, z] = v.normal;
// assert!(!x.is_nan() && !y.is_nan() && !z.is_nan(), "normal was NaN!");
// norm.push_str(&format!("vn {} {} {}\n", x, y, z));
}
for i in idx.chunks(3) {
face.push_str(&format!("f {} {} {}\n", id_offset + i[0], id_offset + i[1], id_offset + i[2]));
}
id_offset += verts.len()
}
print!("s 1\n{}{}{}", vert, norm, face);
}
}

View file

@ -1,6 +1,6 @@
use anyhow::*;
use image::GenericImageView;
use std::path::Path;
use std::{num::NonZeroU32, path::Path};
use wgpu::util::DeviceExt;
pub struct Texture {
@ -34,7 +34,7 @@ impl Texture {
let size = wgpu::Extent3d {
width,
height,
depth: 1,
depth_or_array_layers: 1,
};
let texture = device.create_texture(&wgpu::TextureDescriptor {
@ -62,15 +62,15 @@ impl Texture {
});
encoder.copy_buffer_to_texture(
wgpu::BufferCopyView {
wgpu::ImageCopyBuffer {
buffer: &buffer,
layout: wgpu::TextureDataLayout {
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: 4 * width,
rows_per_image: height,
bytes_per_row: NonZeroU32::new(4 * width),
rows_per_image: NonZeroU32::new(height),
},
},
wgpu::TextureCopyView {
wgpu::ImageCopyTexture {
texture: &texture,
mip_level: 0,
origin: wgpu::Origin3d::ZERO,
@ -116,7 +116,7 @@ impl Texture {
let size = wgpu::Extent3d {
width: sc_desc.width,
height: sc_desc.height,
depth: 1,
depth_or_array_layers: 1,
};
let desc = wgpu::TextureDescriptor {
label: Some(label),