├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── assets └── shaders │ ├── noise4d.glsl │ ├── ocean.glslf │ ├── ocean.glslv │ ├── shader_150.glslf │ └── shader_150.glslv └── src ├── camera.rs ├── macros.rs ├── main.rs ├── ocean.rs ├── planet.rs ├── renderable.rs ├── triangle.rs └── vertex.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [root] 2 | name = "planet_rust" 3 | version = "0.1.0" 4 | dependencies = [ 5 | "cgmath 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 6 | "glium 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", 7 | "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 8 | ] 9 | 10 | [[package]] 11 | name = "android_glue" 12 | version = "0.2.1" 13 | source = "registry+https://github.com/rust-lang/crates.io-index" 14 | 15 | [[package]] 16 | name = "approx" 17 | version = "0.1.1" 18 | source = "registry+https://github.com/rust-lang/crates.io-index" 19 | 20 | [[package]] 21 | name = "backtrace" 22 | version = "0.2.3" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | dependencies = [ 25 | "backtrace-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 26 | "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 27 | "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 28 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 29 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 30 | "rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 31 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 32 | ] 33 | 34 | [[package]] 35 | name = "backtrace-sys" 36 | version = "0.1.5" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | dependencies = [ 39 | "gcc 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)", 40 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 41 | ] 42 | 43 | [[package]] 44 | name = "bitflags" 45 | version = "0.3.3" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | 48 | [[package]] 49 | name = "bitflags" 50 | version = "0.7.0" 51 | source = "registry+https://github.com/rust-lang/crates.io-index" 52 | 53 | [[package]] 54 | name = "block" 55 | version = "0.1.6" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | 58 | [[package]] 59 | name = "byteorder" 60 | version = "0.5.3" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | 63 | [[package]] 64 | name = "cfg-if" 65 | version = "0.1.0" 66 | source = "registry+https://github.com/rust-lang/crates.io-index" 67 | 68 | [[package]] 69 | name = "cgl" 70 | version = "0.1.5" 71 | source = "registry+https://github.com/rust-lang/crates.io-index" 72 | dependencies = [ 73 | "gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", 74 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 75 | ] 76 | 77 | [[package]] 78 | name = "cgmath" 79 | version = "0.12.0" 80 | source = "registry+https://github.com/rust-lang/crates.io-index" 81 | dependencies = [ 82 | "approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 83 | "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", 84 | "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 85 | "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", 86 | ] 87 | 88 | [[package]] 89 | name = "cocoa" 90 | version = "0.3.3" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | dependencies = [ 93 | "bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 94 | "core-graphics 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 95 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 96 | "objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 97 | ] 98 | 99 | [[package]] 100 | name = "cocoa" 101 | version = "0.5.2" 102 | source = "registry+https://github.com/rust-lang/crates.io-index" 103 | dependencies = [ 104 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 105 | "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 106 | "core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 107 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 108 | "objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 109 | ] 110 | 111 | [[package]] 112 | name = "core-foundation" 113 | version = "0.2.2" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | dependencies = [ 116 | "core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 117 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 118 | ] 119 | 120 | [[package]] 121 | name = "core-foundation-sys" 122 | version = "0.2.2" 123 | source = "registry+https://github.com/rust-lang/crates.io-index" 124 | dependencies = [ 125 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 126 | ] 127 | 128 | [[package]] 129 | name = "core-graphics" 130 | version = "0.3.2" 131 | source = "registry+https://github.com/rust-lang/crates.io-index" 132 | dependencies = [ 133 | "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 134 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 135 | "serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)", 136 | ] 137 | 138 | [[package]] 139 | name = "core-graphics" 140 | version = "0.4.2" 141 | source = "registry+https://github.com/rust-lang/crates.io-index" 142 | dependencies = [ 143 | "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 144 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 145 | "serde 0.8.21 (registry+https://github.com/rust-lang/crates.io-index)", 146 | ] 147 | 148 | [[package]] 149 | name = "dbghelp-sys" 150 | version = "0.2.0" 151 | source = "registry+https://github.com/rust-lang/crates.io-index" 152 | dependencies = [ 153 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 154 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 155 | ] 156 | 157 | [[package]] 158 | name = "dlib" 159 | version = "0.3.1" 160 | source = "registry+https://github.com/rust-lang/crates.io-index" 161 | dependencies = [ 162 | "libloading 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 163 | ] 164 | 165 | [[package]] 166 | name = "dtoa" 167 | version = "0.2.2" 168 | source = "registry+https://github.com/rust-lang/crates.io-index" 169 | 170 | [[package]] 171 | name = "dwmapi-sys" 172 | version = "0.1.0" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | dependencies = [ 175 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 176 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 177 | ] 178 | 179 | [[package]] 180 | name = "fnv" 181 | version = "1.0.5" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | 184 | [[package]] 185 | name = "fs2" 186 | version = "0.2.5" 187 | source = "registry+https://github.com/rust-lang/crates.io-index" 188 | dependencies = [ 189 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 190 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 191 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 192 | ] 193 | 194 | [[package]] 195 | name = "gcc" 196 | version = "0.3.41" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | 199 | [[package]] 200 | name = "gdi32-sys" 201 | version = "0.1.1" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | dependencies = [ 204 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 205 | ] 206 | 207 | [[package]] 208 | name = "gl_generator" 209 | version = "0.5.2" 210 | source = "registry+https://github.com/rust-lang/crates.io-index" 211 | dependencies = [ 212 | "khronos_api 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 213 | "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 214 | "xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 215 | ] 216 | 217 | [[package]] 218 | name = "gleam" 219 | version = "0.2.30" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | dependencies = [ 222 | "gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 223 | "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 224 | ] 225 | 226 | [[package]] 227 | name = "glium" 228 | version = "0.16.0" 229 | source = "registry+https://github.com/rust-lang/crates.io-index" 230 | dependencies = [ 231 | "backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", 232 | "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 233 | "gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 234 | "glutin 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 235 | "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 236 | "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", 237 | ] 238 | 239 | [[package]] 240 | name = "glutin" 241 | version = "0.7.2" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | dependencies = [ 244 | "android_glue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 245 | "cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 246 | "cocoa 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 247 | "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 248 | "core-graphics 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 249 | "dwmapi-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 250 | "gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 251 | "gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 252 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 253 | "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 254 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 255 | "objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 256 | "osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 257 | "shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 258 | "shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 259 | "user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 260 | "wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", 261 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 262 | "winit 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", 263 | "x11-dl 2.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 264 | ] 265 | 266 | [[package]] 267 | name = "itoa" 268 | version = "0.1.1" 269 | source = "registry+https://github.com/rust-lang/crates.io-index" 270 | 271 | [[package]] 272 | name = "kernel32-sys" 273 | version = "0.2.2" 274 | source = "registry+https://github.com/rust-lang/crates.io-index" 275 | dependencies = [ 276 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 277 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 278 | ] 279 | 280 | [[package]] 281 | name = "khronos_api" 282 | version = "1.0.0" 283 | source = "registry+https://github.com/rust-lang/crates.io-index" 284 | 285 | [[package]] 286 | name = "lazy_static" 287 | version = "0.2.2" 288 | source = "registry+https://github.com/rust-lang/crates.io-index" 289 | 290 | [[package]] 291 | name = "libc" 292 | version = "0.2.19" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | 295 | [[package]] 296 | name = "libloading" 297 | version = "0.3.1" 298 | source = "registry+https://github.com/rust-lang/crates.io-index" 299 | dependencies = [ 300 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 301 | "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 302 | "target_build_utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 303 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 304 | ] 305 | 306 | [[package]] 307 | name = "log" 308 | version = "0.3.6" 309 | source = "registry+https://github.com/rust-lang/crates.io-index" 310 | 311 | [[package]] 312 | name = "malloc_buf" 313 | version = "0.0.6" 314 | source = "registry+https://github.com/rust-lang/crates.io-index" 315 | dependencies = [ 316 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 317 | ] 318 | 319 | [[package]] 320 | name = "memmap" 321 | version = "0.4.0" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | dependencies = [ 324 | "fs2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", 325 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 326 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 327 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 328 | ] 329 | 330 | [[package]] 331 | name = "num-traits" 332 | version = "0.1.36" 333 | source = "registry+https://github.com/rust-lang/crates.io-index" 334 | 335 | [[package]] 336 | name = "objc" 337 | version = "0.2.2" 338 | source = "registry+https://github.com/rust-lang/crates.io-index" 339 | dependencies = [ 340 | "malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 341 | ] 342 | 343 | [[package]] 344 | name = "osmesa-sys" 345 | version = "0.1.2" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | dependencies = [ 348 | "shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 349 | ] 350 | 351 | [[package]] 352 | name = "phf" 353 | version = "0.7.20" 354 | source = "registry+https://github.com/rust-lang/crates.io-index" 355 | dependencies = [ 356 | "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", 357 | ] 358 | 359 | [[package]] 360 | name = "phf_codegen" 361 | version = "0.7.20" 362 | source = "registry+https://github.com/rust-lang/crates.io-index" 363 | dependencies = [ 364 | "phf_generator 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", 365 | "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", 366 | ] 367 | 368 | [[package]] 369 | name = "phf_generator" 370 | version = "0.7.20" 371 | source = "registry+https://github.com/rust-lang/crates.io-index" 372 | dependencies = [ 373 | "phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", 374 | "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 375 | ] 376 | 377 | [[package]] 378 | name = "phf_shared" 379 | version = "0.7.20" 380 | source = "registry+https://github.com/rust-lang/crates.io-index" 381 | 382 | [[package]] 383 | name = "pkg-config" 384 | version = "0.3.8" 385 | source = "registry+https://github.com/rust-lang/crates.io-index" 386 | 387 | [[package]] 388 | name = "rand" 389 | version = "0.3.15" 390 | source = "registry+https://github.com/rust-lang/crates.io-index" 391 | dependencies = [ 392 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 393 | ] 394 | 395 | [[package]] 396 | name = "rustc-demangle" 397 | version = "0.1.3" 398 | source = "registry+https://github.com/rust-lang/crates.io-index" 399 | 400 | [[package]] 401 | name = "rustc-serialize" 402 | version = "0.3.22" 403 | source = "registry+https://github.com/rust-lang/crates.io-index" 404 | 405 | [[package]] 406 | name = "rustc_version" 407 | version = "0.1.7" 408 | source = "registry+https://github.com/rust-lang/crates.io-index" 409 | dependencies = [ 410 | "semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", 411 | ] 412 | 413 | [[package]] 414 | name = "semver" 415 | version = "0.1.20" 416 | source = "registry+https://github.com/rust-lang/crates.io-index" 417 | 418 | [[package]] 419 | name = "serde" 420 | version = "0.7.15" 421 | source = "registry+https://github.com/rust-lang/crates.io-index" 422 | 423 | [[package]] 424 | name = "serde" 425 | version = "0.8.21" 426 | source = "registry+https://github.com/rust-lang/crates.io-index" 427 | 428 | [[package]] 429 | name = "serde_json" 430 | version = "0.8.4" 431 | source = "registry+https://github.com/rust-lang/crates.io-index" 432 | dependencies = [ 433 | "dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 434 | "itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 435 | "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", 436 | "serde 0.8.21 (registry+https://github.com/rust-lang/crates.io-index)", 437 | ] 438 | 439 | [[package]] 440 | name = "shared_library" 441 | version = "0.1.5" 442 | source = "registry+https://github.com/rust-lang/crates.io-index" 443 | dependencies = [ 444 | "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 445 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 446 | ] 447 | 448 | [[package]] 449 | name = "shell32-sys" 450 | version = "0.1.1" 451 | source = "registry+https://github.com/rust-lang/crates.io-index" 452 | dependencies = [ 453 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 454 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 455 | ] 456 | 457 | [[package]] 458 | name = "smallvec" 459 | version = "0.1.8" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | 462 | [[package]] 463 | name = "target_build_utils" 464 | version = "0.1.2" 465 | source = "registry+https://github.com/rust-lang/crates.io-index" 466 | dependencies = [ 467 | "phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", 468 | "phf_codegen 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)", 469 | "serde_json 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", 470 | ] 471 | 472 | [[package]] 473 | name = "tempfile" 474 | version = "2.1.4" 475 | source = "registry+https://github.com/rust-lang/crates.io-index" 476 | dependencies = [ 477 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 478 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 479 | "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", 480 | "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 481 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 482 | ] 483 | 484 | [[package]] 485 | name = "user32-sys" 486 | version = "0.1.2" 487 | source = "registry+https://github.com/rust-lang/crates.io-index" 488 | dependencies = [ 489 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 490 | "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 491 | ] 492 | 493 | [[package]] 494 | name = "wayland-client" 495 | version = "0.7.6" 496 | source = "registry+https://github.com/rust-lang/crates.io-index" 497 | dependencies = [ 498 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 499 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 500 | "wayland-scanner 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", 501 | "wayland-sys 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", 502 | ] 503 | 504 | [[package]] 505 | name = "wayland-kbd" 506 | version = "0.6.2" 507 | source = "registry+https://github.com/rust-lang/crates.io-index" 508 | dependencies = [ 509 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 510 | "dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 511 | "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 512 | "memmap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 513 | "wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", 514 | ] 515 | 516 | [[package]] 517 | name = "wayland-scanner" 518 | version = "0.7.6" 519 | source = "registry+https://github.com/rust-lang/crates.io-index" 520 | dependencies = [ 521 | "xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", 522 | ] 523 | 524 | [[package]] 525 | name = "wayland-sys" 526 | version = "0.7.6" 527 | source = "registry+https://github.com/rust-lang/crates.io-index" 528 | dependencies = [ 529 | "dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 530 | "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 531 | ] 532 | 533 | [[package]] 534 | name = "wayland-window" 535 | version = "0.4.3" 536 | source = "registry+https://github.com/rust-lang/crates.io-index" 537 | dependencies = [ 538 | "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", 539 | "tempfile 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 540 | "wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", 541 | ] 542 | 543 | [[package]] 544 | name = "winapi" 545 | version = "0.2.8" 546 | source = "registry+https://github.com/rust-lang/crates.io-index" 547 | 548 | [[package]] 549 | name = "winapi-build" 550 | version = "0.1.1" 551 | source = "registry+https://github.com/rust-lang/crates.io-index" 552 | 553 | [[package]] 554 | name = "winit" 555 | version = "0.5.7" 556 | source = "registry+https://github.com/rust-lang/crates.io-index" 557 | dependencies = [ 558 | "android_glue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 559 | "cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 560 | "cocoa 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 561 | "core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 562 | "core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 563 | "dwmapi-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 564 | "gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 565 | "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 566 | "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 567 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 568 | "objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 569 | "shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 570 | "shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 571 | "user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", 572 | "wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", 573 | "wayland-kbd 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", 574 | "wayland-window 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", 575 | "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", 576 | "x11-dl 2.12.0 (registry+https://github.com/rust-lang/crates.io-index)", 577 | ] 578 | 579 | [[package]] 580 | name = "x11-dl" 581 | version = "2.12.0" 582 | source = "registry+https://github.com/rust-lang/crates.io-index" 583 | dependencies = [ 584 | "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 585 | "libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)", 586 | "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 587 | ] 588 | 589 | [[package]] 590 | name = "xml-rs" 591 | version = "0.3.5" 592 | source = "registry+https://github.com/rust-lang/crates.io-index" 593 | dependencies = [ 594 | "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 595 | ] 596 | 597 | [metadata] 598 | "checksum android_glue 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e2b80445d331077679dfc6f3014f3e9ab7083e588423d35041d3fc017198189" 599 | "checksum approx 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08abcc3b4e9339e33a3d0a5ed15d84a687350c05689d825e0f6655eef9e76a94" 600 | "checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f" 601 | "checksum backtrace-sys 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3602e8d8c43336088a8505fa55cae2b3884a9be29440863a11528a42f46f6bb7" 602 | "checksum bitflags 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "32866f4d103c4e438b1db1158aa1b1a80ee078e5d77a59a2f906fd62a577389c" 603 | "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" 604 | "checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" 605 | "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" 606 | "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" 607 | "checksum cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8bdd78cca65a739cb5475dbf6b6bbb49373e327f4a6f2b499c0f98632df38c10" 608 | "checksum cgmath 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "232472604dbad61c384edfc4d833315d487894826856836b7227b37fe3abe02b" 609 | "checksum cocoa 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3afe4613f57a171039a98db1773f5840b5743cf85aaf03afb65ddfade4f4a9db" 610 | "checksum cocoa 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1e1be5fd98bb7e8ef0eea233a4984f4e85ecdcfa002a90b8b12b7a20faf44dc1" 611 | "checksum core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "20a6d0448d3a99d977ae4a2aa5a98d886a923e863e81ad9ff814645b6feb3bbd" 612 | "checksum core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "05eed248dc504a5391c63794fe4fb64f46f071280afaa1b73308f3c0ce4574c5" 613 | "checksum core-graphics 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0c56c6022ba22aedbaa7d231be545778becbe1c7aceda4c82ba2f2084dd4c723" 614 | "checksum core-graphics 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "66e998abb8823fecd2a8a7205429b17a340d447d8c69b3bce86846dcdea3e33b" 615 | "checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" 616 | "checksum dlib 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "148bce4ce1c36c4509f29cb54e62c2bd265551a9b00b38070fad551a851866ec" 617 | "checksum dtoa 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0dd841b58510c9618291ffa448da2e4e0f699d984d436122372f446dae62263d" 618 | "checksum dwmapi-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07c4c7cc7b396419bc0a4d90371d0cee16cb5053b53647d287c0b728000c41fe" 619 | "checksum fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6cc484842f1e2884faf56f529f960cc12ad8c71ce96cc7abba0a067c98fee344" 620 | "checksum fs2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bcd414e5a1a979b931bb92f41b7a54106d3f6d2e6c253e9ce943b7cd468251ef" 621 | "checksum gcc 0.3.41 (registry+https://github.com/rust-lang/crates.io-index)" = "3689e1982a563af74960ae3a4758aa632bb8fd984cfc3cc3b60ee6109477ab6e" 622 | "checksum gdi32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "65256ec4dc2592e6f05bfc1ca3b956a4e0698aa90b1dff1f5687d55a5a3fd59a" 623 | "checksum gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1d8edc81c5ae84605a62f5dac661a2313003b26d59839f81d47d46cf0f16a55" 624 | "checksum gleam 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "6af023107aa969ccf8868a0304fead4b2f813c19aa9a6a243fddc041f3e51da5" 625 | "checksum glium 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c468bf7855f25954a1140f066ebacc1ad5342fd33bf96be28e184c084176f11" 626 | "checksum glutin 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f10fe6cb2f7e559e470cc0dfa2c89a4f476fc99ec1862632b057e68c3831eb7a" 627 | "checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1" 628 | "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 629 | "checksum khronos_api 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09c9d3760673c427d46f91a0350f0a84a52e6bc5a84adf26dc610b6c52436630" 630 | "checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b" 631 | "checksum libc 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)" = "9e030dc72013ed68994d1b2cbf36a94dd0e58418ba949c4b0db7eeb70a7a6352" 632 | "checksum libloading 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "84816a8c6ed8163dfe0dbdd2b09d35c6723270ea77a4c7afa4bedf038a36cb99" 633 | "checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" 634 | "checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" 635 | "checksum memmap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69253224aa10070855ea8fe9dbe94a03fc2b1d7930bb340c9e586a7513716fea" 636 | "checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c" 637 | "checksum objc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "877f30f37acef6749b1841cceab289707f211aecfc756553cd63976190e6cc2e" 638 | "checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" 639 | "checksum phf 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "0c6afb2057bb5f846a7b75703f90bc1cef4970c35209f712925db7768e999202" 640 | "checksum phf_codegen 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "6b63f121bf9a128f2172a65d8313a8e0e79d63874eeb4b4b7d82e6dda6b62f7c" 641 | "checksum phf_generator 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "50ffbd7970f75afa083c5dd7b6830c97b72b81579c7a92d8134ef2ee6c0c7eb0" 642 | "checksum phf_shared 0.7.20 (registry+https://github.com/rust-lang/crates.io-index)" = "286385a0e50d4147bce15b2c19f0cf84c395b0e061aaf840898a7bf664c2cfb7" 643 | "checksum pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8cee804ecc7eaf201a4a207241472cc870e825206f6c031e3ee2a72fa425f2fa" 644 | "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" 645 | "checksum rustc-demangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1430d286cadb237c17c885e25447c982c97113926bb579f4379c0eca8d9586dc" 646 | "checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" 647 | "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" 648 | "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" 649 | "checksum serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0e0732aa8ec4267f61815a396a942ba3525062e3bd5520aa8419927cfc0a92" 650 | "checksum serde 0.8.21 (registry+https://github.com/rust-lang/crates.io-index)" = "7b7c6bf11cf766473ea1d53eb4e3bc4e80f31f50082fc24077cf06f600279a66" 651 | "checksum serde_json 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3f7d3c184d35801fb8b32b46a7d58d57dbcc150b0eb2b46a1eb79645e8ecfd5b" 652 | "checksum shared_library 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb04126b6fcfd2710fb5b6d18f4207b6c535f2850a7e1a43bcd526d44f30a79a" 653 | "checksum shell32-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72f20b8f3c060374edb8046591ba28f62448c369ccbdc7b02075103fb3a9e38d" 654 | "checksum smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "fcc8d19212aacecf95e4a7a2179b26f7aeb9732a915cf01f05b0d3e044865410" 655 | "checksum target_build_utils 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54c550e226618cd35334b75e92bfa5437c61474bdb75c38bf330ab5a8037b77c" 656 | "checksum tempfile 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9270837a93bad1b1dac18fe67e786b3c960513af86231f6f4f57fddd594ff0c8" 657 | "checksum user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6717129de5ac253f5642fc78a51d0c7de6f9f53d617fc94e9bae7f6e71cf5504" 658 | "checksum wayland-client 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8c3e3edc131b755a1c6ab9873ce27557f5c5f075959597cd201bc00019555c9e" 659 | "checksum wayland-kbd 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7707deadab966d6ea58651f4150add1fc442058a9598c3da11f0ce27c99f440f" 660 | "checksum wayland-scanner 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c7459efa4b7bab8f34657ce6167ff470871cc7932d75cfc8db7e2ef99f81397b" 661 | "checksum wayland-sys 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "bb879ab3916b7bbacda1258df0bc78eaa12b483f377a73ecc40b9f0b24f15465" 662 | "checksum wayland-window 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "58f705c7b57886d3e708c02ba9b26924f6db6f869aa108bf621731a7d900799f" 663 | "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" 664 | "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" 665 | "checksum winit 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "43f10685de37740dd0a63bffb4449c805866941b0c2eb56aa3d09dc2c25475b5" 666 | "checksum x11-dl 2.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf1f9986368c9bbdd8191a783a7ceb42e0c9c6d3348616c873f829b3288a139c" 667 | "checksum xml-rs 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b15eed12692bd59d15e98ee7f8dc8408465b992d8ddb4d1672c24865132ec7" 668 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "planet_rust" 3 | version = "0.1.0" 4 | authors = ["Mikhail Kharitonovich "] 5 | 6 | [dependencies] 7 | cgmath="*" 8 | glium="*" 9 | rand="*" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Mikhail Kharitonovich 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # planet-rust 2 | Port of my C# planet generator (https://github.com/Minizinger/PlanetDemo) into rust 3 | Results are pretty simmilar to the original one: 4 | 5 | ![Screenshots](http://i.imgur.com/fFrbzmU.png) 6 | ![Screenshots](http://i.imgur.com/qxLRrKv.png) 7 | ![Screenshots](http://i.imgur.com/qLPbdfJ.png) 8 | 9 | Rust is wonderful language. It's hard to learn (and I'm not going to say that I have, not yet anyways), but potential of it is insane. 10 | -------------------------------------------------------------------------------- /assets/shaders/noise4d.glsl: -------------------------------------------------------------------------------- 1 | #version 140 2 | 3 | // 4 | // Description : Array and textureless GLSL 2D/3D/4D simplex 5 | // noise functions. 6 | // Author : Ian McEwan, Ashima Arts. 7 | // Maintainer : stegu 8 | // Lastmod : 20110822 (ijm) 9 | // License : Copyright (C) 2011 Ashima Arts. All rights reserved. 10 | // Distributed under the MIT License. See LICENSE file. 11 | // https://github.com/ashima/webgl-noise 12 | // https://github.com/stegu/webgl-noise 13 | // 14 | 15 | vec4 mod289(vec4 x) { 16 | return x - floor(x * (1.0 / 289.0)) * 289.0; } 17 | 18 | float mod289(float x) { 19 | return x - floor(x * (1.0 / 289.0)) * 289.0; } 20 | 21 | vec4 permute(vec4 x) { 22 | return mod289(((x*34.0)+1.0)*x); 23 | } 24 | 25 | float permute(float x) { 26 | return mod289(((x*34.0)+1.0)*x); 27 | } 28 | 29 | vec4 taylorInvSqrt(vec4 r) 30 | { 31 | return 1.79284291400159 - 0.85373472095314 * r; 32 | } 33 | 34 | float taylorInvSqrt(float r) 35 | { 36 | return 1.79284291400159 - 0.85373472095314 * r; 37 | } 38 | 39 | vec4 grad4(float j, vec4 ip) 40 | { 41 | const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0); 42 | vec4 p,s; 43 | 44 | p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0; 45 | p.w = 1.5 - dot(abs(p.xyz), ones.xyz); 46 | s = vec4(lessThan(p, vec4(0.0))); 47 | p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www; 48 | 49 | return p; 50 | } 51 | 52 | // (sqrt(5) - 1)/4 = F4, used once below 53 | #define F4 0.309016994374947451 54 | 55 | float snoise(vec4 v) 56 | { 57 | const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4 58 | 0.276393202250021, // 2 * G4 59 | 0.414589803375032, // 3 * G4 60 | -0.447213595499958); // -1 + 4 * G4 61 | 62 | // First corner 63 | vec4 i = floor(v + dot(v, vec4(F4)) ); 64 | vec4 x0 = v - i + dot(i, C.xxxx); 65 | 66 | // Other corners 67 | 68 | // Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI) 69 | vec4 i0; 70 | vec3 isX = step( x0.yzw, x0.xxx ); 71 | vec3 isYZ = step( x0.zww, x0.yyz ); 72 | // i0.x = dot( isX, vec3( 1.0 ) ); 73 | i0.x = isX.x + isX.y + isX.z; 74 | i0.yzw = 1.0 - isX; 75 | // i0.y += dot( isYZ.xy, vec2( 1.0 ) ); 76 | i0.y += isYZ.x + isYZ.y; 77 | i0.zw += 1.0 - isYZ.xy; 78 | i0.z += isYZ.z; 79 | i0.w += 1.0 - isYZ.z; 80 | 81 | // i0 now contains the unique values 0,1,2,3 in each channel 82 | vec4 i3 = clamp( i0, 0.0, 1.0 ); 83 | vec4 i2 = clamp( i0-1.0, 0.0, 1.0 ); 84 | vec4 i1 = clamp( i0-2.0, 0.0, 1.0 ); 85 | 86 | // x0 = x0 - 0.0 + 0.0 * C.xxxx 87 | // x1 = x0 - i1 + 1.0 * C.xxxx 88 | // x2 = x0 - i2 + 2.0 * C.xxxx 89 | // x3 = x0 - i3 + 3.0 * C.xxxx 90 | // x4 = x0 - 1.0 + 4.0 * C.xxxx 91 | vec4 x1 = x0 - i1 + C.xxxx; 92 | vec4 x2 = x0 - i2 + C.yyyy; 93 | vec4 x3 = x0 - i3 + C.zzzz; 94 | vec4 x4 = x0 + C.wwww; 95 | 96 | // Permutations 97 | i = mod289(i); 98 | float j0 = permute( permute( permute( permute(i.w) + i.z) + i.y) + i.x); 99 | vec4 j1 = permute( permute( permute( permute ( 100 | i.w + vec4(i1.w, i2.w, i3.w, 1.0 )) 101 | + i.z + vec4(i1.z, i2.z, i3.z, 1.0 )) 102 | + i.y + vec4(i1.y, i2.y, i3.y, 1.0 )) 103 | + i.x + vec4(i1.x, i2.x, i3.x, 1.0 )); 104 | 105 | // Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope 106 | // 7*7*6 = 294, which is close to the ring size 17*17 = 289. 107 | vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ; 108 | 109 | vec4 p0 = grad4(j0, ip); 110 | vec4 p1 = grad4(j1.x, ip); 111 | vec4 p2 = grad4(j1.y, ip); 112 | vec4 p3 = grad4(j1.z, ip); 113 | vec4 p4 = grad4(j1.w, ip); 114 | 115 | // Normalise gradients 116 | vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3))); 117 | p0 *= norm.x; 118 | p1 *= norm.y; 119 | p2 *= norm.z; 120 | p3 *= norm.w; 121 | p4 *= taylorInvSqrt(dot(p4,p4)); 122 | 123 | // Mix contributions from the five corners 124 | vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0); 125 | vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0); 126 | m0 = m0 * m0; 127 | m1 = m1 * m1; 128 | return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 ))) 129 | + dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ; 130 | 131 | } -------------------------------------------------------------------------------- /assets/shaders/ocean.glslf: -------------------------------------------------------------------------------- 1 | #version 140 2 | 3 | in vec3 v_normal; 4 | in vec3 v_light; 5 | in vec3 v_position; 6 | 7 | uniform vec3 u_color; 8 | 9 | out vec4 color; 10 | 11 | const vec3 specular_color = vec3(1.0, 1.0, 1.0); 12 | 13 | void main() { 14 | //color = vec4(0.0, 1.0, 0.0, 1.0); 15 | float brightness = max(dot(normalize(v_normal), normalize(v_light)), 0.0); 16 | vec3 dark_color = u_color * vec3(0.6, 0.6, 0.6); 17 | vec3 regular_color = u_color; 18 | 19 | vec3 camera_dir = normalize(-v_position); 20 | vec3 half_direction = normalize(normalize(v_light) + camera_dir); 21 | float specular = pow(max(dot(half_direction, normalize(v_normal)), 0.0), 16.0); 22 | 23 | color = vec4(mix(dark_color, regular_color, brightness) + specular * specular_color, 1.0); 24 | } -------------------------------------------------------------------------------- /assets/shaders/ocean.glslv: -------------------------------------------------------------------------------- 1 | #version 140 2 | 3 | in vec3 position; 4 | in vec3 normal; 5 | 6 | out vec3 v_normal; 7 | out vec3 v_light; 8 | out vec3 v_position; 9 | 10 | uniform mat4 projection; 11 | uniform mat4 view; 12 | uniform vec3 u_light; 13 | uniform float f_time; 14 | uniform mat4 scale; 15 | 16 | void main() { 17 | v_normal = transpose(inverse(mat3(view))) * normal; 18 | v_light = transpose(inverse(mat3(view))) * u_light; 19 | vec4 pos = vec4(position, 1.0); 20 | pos = pos * scale; 21 | pos = pos + (normalize(pos) * sin(pos * 50 + f_time)) * 0.001; 22 | pos = projection * view * pos; 23 | v_position = pos.xyz / pos.w; 24 | gl_Position = pos; 25 | } -------------------------------------------------------------------------------- /assets/shaders/shader_150.glslf: -------------------------------------------------------------------------------- 1 | #version 140 2 | 3 | in vec3 v_normal; 4 | in vec3 v_light; 5 | 6 | uniform vec3 u_color; 7 | 8 | out vec4 color; 9 | 10 | void main() { 11 | //color = vec4(0.0, 1.0, 0.0, 1.0); 12 | float brightness = dot(normalize(v_normal), normalize(v_light)); 13 | vec3 dark_color = u_color * vec3(0.6, 0.6, 0.6); 14 | vec3 regular_color = u_color; 15 | 16 | color = vec4(mix(dark_color, regular_color, brightness), 1.0); 17 | } -------------------------------------------------------------------------------- /assets/shaders/shader_150.glslv: -------------------------------------------------------------------------------- 1 | //132 2 | //#version 140 3 | 4 | in vec3 position; 5 | in vec3 normal; 6 | 7 | out vec3 v_normal; 8 | out vec3 v_light; 9 | 10 | uniform mat4 projection; 11 | uniform mat4 view; 12 | uniform vec3 u_light; 13 | 14 | uniform float f_seed; 15 | uniform float f_persistance; 16 | uniform float f_lacunarity; 17 | uniform int i_octaves; 18 | 19 | float Noise(vec4 p) 20 | { 21 | return (0.5 * snoise(p) + 0.5); 22 | } 23 | 24 | float getNoiseValue(vec3 p, float scale) { 25 | float amplitude = 1; 26 | float frequency = 1; 27 | float value = 0; 28 | for (int i = 0; i < i_octaves; i++) { 29 | value += amplitude * Noise(vec4(frequency * p.x / scale, frequency * p.y / scale, frequency * p.z / scale, f_seed)); 30 | amplitude *= f_persistance; 31 | frequency *= f_lacunarity; 32 | } 33 | return value; 34 | } 35 | 36 | void main() { 37 | v_normal = transpose(inverse(mat3(view))) * normal; 38 | v_light = transpose(inverse(mat3(view))) * u_light; 39 | vec3 pos3 = position; 40 | //pos3 *= Terrain(vec4(pos3, 1.0), 6, 36) * 10; 41 | pos3 = pos3 + (normalize(pos3) * getNoiseValue(pos3, 1.0)) * 0.1; 42 | vec4 pos = vec4(pos3, 1.0); 43 | pos = projection * view * pos; 44 | gl_Position = pos; 45 | } -------------------------------------------------------------------------------- /src/camera.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | use cgmath::{perspective, Matrix4, Vector3, Point3, Rad, InnerSpace, EuclideanSpace}; 3 | use cgmath::conv::array4x4; 4 | 5 | pub struct Camera { 6 | pub view: [[f32; 4]; 4], 7 | pub projection: [[f32; 4]; 4], 8 | 9 | position: Vector3, 10 | fov: Rad, 11 | asp: f32, 12 | camera_orbit: f32, 13 | } 14 | 15 | impl Camera { 16 | pub fn new(pos: Vector3 /*, fov_deg: f32*/, aspect: f32, orbit: f32) -> Camera { 17 | let norm_pos = pos.normalize_to(orbit); 18 | let view_martix = Matrix4::::look_at(Point3::from_vec(norm_pos), 19 | Point3::new(0., 0., 0.), 20 | Vector3::new(0., 0., 1.)); 21 | Camera { 22 | view: array4x4(view_martix), 23 | projection: array4x4(perspective(Rad(PI / 4.), aspect, 0.1, 500.)), 24 | 25 | position: norm_pos, 26 | fov: Rad(PI / 4.), 27 | asp: aspect, 28 | camera_orbit: orbit, 29 | } 30 | } 31 | 32 | pub fn update_matricies(&mut self) { 33 | self.view = array4x4(Matrix4::::look_at(Point3::from_vec(self.position), 34 | Point3::new(0., 0., 0.), 35 | Vector3::new(0., 0., 1.))); 36 | self.projection = array4x4(perspective(self.fov, self.asp, 0.1, 100.)); 37 | } 38 | 39 | pub fn get_position(&self) -> Vector3 { 40 | self.position 41 | } 42 | pub fn set_position(&mut self, new_pos: Vector3) { 43 | self.position = new_pos.normalize_to(self.camera_orbit); 44 | self.update_matricies(); 45 | } 46 | #[allow(dead_code)] //maybe will be useful later 47 | pub fn get_orbit(&self) -> f32 { 48 | self.camera_orbit 49 | } 50 | #[allow(dead_code)] //maybe will be useful later 51 | pub fn set_orbit(&mut self, new_orbit: f32) { 52 | self.position = self.position.normalize_to(new_orbit); 53 | self.update_matricies(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/macros.rs: -------------------------------------------------------------------------------- 1 | macro_rules! vec3 { 2 | [$x:expr, $y:expr, $z:expr] => ( Vector3::new($x, $y, $z) ) 3 | } 4 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate glium; 3 | extern crate cgmath; 4 | extern crate rand; 5 | 6 | #[macro_use] 7 | mod macros; 8 | mod vertex; 9 | mod camera; 10 | mod planet; 11 | mod triangle; 12 | mod renderable; 13 | mod ocean; 14 | 15 | fn main() { 16 | use glium::{DisplayBuild, Surface}; 17 | use vertex::{VertexPosition, Normal}; 18 | use camera::Camera; 19 | use cgmath::Vector3; 20 | use planet::Planet; 21 | use ocean::Ocean; 22 | 23 | let display = glium::glutin::WindowBuilder::new().with_depth_buffer(24).build_glium().unwrap(); 24 | let target = display.draw(); 25 | let (width, height) = target.get_dimensions(); 26 | target.finish().unwrap(); 27 | 28 | let mut cam: Camera = Camera::new(Vector3::new(0.0, -5.0, 0.0), 29 | width as f32 / height as f32, 30 | 5.); 31 | let mut planet: Planet = Planet::new(&display, 4); 32 | let mut ocean: Ocean = Ocean::new(&display, 4, 1.09); 33 | 34 | let mut vertical_position: f32 = 0.; 35 | let mut horisontal_angle: f32 = 0.; 36 | 37 | let light = [-1.0, 0.4, 0.9f32]; 38 | 39 | let mut time = 0.0; 40 | 41 | loop { 42 | let mut target = display.draw(); 43 | 44 | target.clear_color_and_depth((0.0, 0.0, 0.0, 1.0), 1.0); 45 | 46 | let params = glium::DrawParameters { 47 | depth: glium::Depth { 48 | test: glium::draw_parameters::DepthTest::IfLess, 49 | write: true, 50 | ..Default::default() 51 | }, 52 | ..Default::default() 53 | }; 54 | 55 | time += 0.05; 56 | ocean.draw(&mut target, ¶ms, cam.view, cam.projection, light, time); 57 | planet.draw(&mut target, ¶ms, cam.view, cam.projection, light); 58 | 59 | target.finish().unwrap(); 60 | 61 | let mut cam_pos = cam.get_position(); 62 | 63 | for ev in display.poll_events() { 64 | use glium::glutin::Event::*; 65 | use glium::glutin::VirtualKeyCode::*; 66 | 67 | match ev { 68 | KeyboardInput(_, _, Some(Escape)) | 69 | Closed => return, 70 | KeyboardInput(_, _, Some(Up)) => { 71 | vertical_position += 0.1 72 | } 73 | KeyboardInput(_, _, Some(Down)) => { 74 | vertical_position -= 0.1 75 | } 76 | KeyboardInput(_, _, Some(Right)) => { 77 | horisontal_angle += 0.1 78 | } 79 | KeyboardInput(_, _, Some(Left)) => { 80 | horisontal_angle -= 0.1 81 | } 82 | KeyboardInput(_, _, Some(Space)) => { 83 | planet = Planet::new(&display, 4); 84 | ocean = Ocean::new(&display, 4, 1.09); 85 | } 86 | _ => (), 87 | } 88 | } 89 | 90 | if vertical_position < -1. { 91 | vertical_position = -1.; 92 | } else if vertical_position > 1. { 93 | vertical_position = 1.; 94 | } 95 | 96 | cam_pos += Vector3::new(f32::cos(horisontal_angle), 97 | f32::sin(horisontal_angle), 98 | vertical_position); 99 | cam.set_position(cam_pos); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/ocean.rs: -------------------------------------------------------------------------------- 1 | use vertex::AnyVertex; 2 | use super::glium::backend::Facade; 3 | use super::glium::{Frame, DrawParameters}; 4 | use cgmath::*; 5 | use triangle::*; 6 | use renderable::{RenderableVertexNormal, Renderable}; 7 | use rand::distributions::Range; 8 | use rand::distributions::IndependentSample; 9 | use rand; 10 | 11 | pub struct Ocean { 12 | triangles: Vec>, 13 | pub verticies: Vec, 14 | pub normals: Vec, 15 | pub renderable: RenderableVertexNormal, 16 | scale: [[f32; 4]; 4], 17 | u_color: [f32; 3], 18 | } 19 | 20 | impl Ocean 21 | where T: AnyVertex, 22 | N: AnyVertex 23 | { 24 | pub fn new(display: &Facade, subdivisions: i32, size: f32) -> Self { 25 | let t: f32 = (1. + (5.0f32).sqrt()) / 2.; 26 | 27 | let p0 = vec3![-1., t, 0.].normalize(); 28 | let p1 = vec3![1., t, 0.].normalize(); 29 | let p2 = vec3![-1., -t, 0.].normalize(); 30 | let p3 = vec3![1., -t, 0.].normalize(); 31 | 32 | let p4 = vec3![0., -1., t].normalize(); 33 | let p5 = vec3![0., 1., t].normalize(); 34 | let p6 = vec3![0., -1., -t].normalize(); 35 | let p7 = vec3![0., 1., -t].normalize(); 36 | 37 | let p8 = vec3![t, 0., -1.].normalize(); 38 | let p9 = vec3![t, 0., 1.].normalize(); 39 | let p10 = vec3![-t, 0., -1.].normalize(); 40 | let p11 = vec3![-t, 0., 1.].normalize(); 41 | 42 | let mut tris = vec![Triangle::new([p0, p11, p5], 0.), 43 | Triangle::new([p0, p5, p1], 0.), 44 | Triangle::new([p0, p1, p7], 0.), 45 | Triangle::new([p0, p7, p10], 0.), 46 | Triangle::new([p0, p10, p11], 0.), 47 | 48 | Triangle::new([p1, p5, p9], 0.), 49 | Triangle::new([p5, p11, p4], 0.), 50 | Triangle::new([p11, p10, p2], 0.), 51 | Triangle::new([p10, p7, p6], 0.), 52 | Triangle::new([p7, p1, p8], 0.), 53 | 54 | Triangle::new([p3, p9, p4], 0.), 55 | Triangle::new([p3, p4, p2], 0.), 56 | Triangle::new([p3, p2, p6], 0.), 57 | Triangle::new([p3, p6, p8], 0.), 58 | Triangle::new([p3, p8, p9], 0.), 59 | 60 | Triangle::new([p4, p9, p5], 0.), 61 | Triangle::new([p2, p4, p11], 0.), 62 | Triangle::new([p6, p2, p10], 0.), 63 | Triangle::new([p8, p6, p7], 0.), 64 | Triangle::new([p9, p8, p1], 0.)]; 65 | 66 | for _ in 0..subdivisions { 67 | for tri in tris.iter_mut() { 68 | (*tri).subdivide(); 69 | } 70 | } 71 | 72 | let mut verts: Vec = Vec::with_capacity(tris.len()); 73 | for tri in tris.iter_mut() { 74 | verts.append(&mut tri.get_verticies()); 75 | } 76 | 77 | let mut nrm: Vec = Vec::with_capacity(tris.len()); 78 | for t in tris.iter_mut() { 79 | nrm.append(&mut t.get_normal()); 80 | } 81 | 82 | let vertex_shader = include_str!("../assets/shaders/ocean.glslv"); 83 | let fragment_shader = include_str!("../assets/shaders/ocean.glslf"); 84 | let rnd = 85 | RenderableVertexNormal::new(display, &verts, &nrm, &vertex_shader, &fragment_shader); 86 | 87 | let scal = [[size, 0.0, 0.0, 0.0], 88 | [0.0, size, 0.0, 0.0], 89 | [0.0, 0.0, size, 0.0], 90 | [0.0, 0.0, 0.0, 1.0]]; 91 | 92 | let mut rng = rand::thread_rng(); 93 | let col = Range::new(0.0f32, 1.0f32); 94 | 95 | Ocean { 96 | triangles: tris, 97 | verticies: verts, 98 | normals: nrm, 99 | renderable: rnd, 100 | scale: scal, 101 | u_color: [col.ind_sample(&mut rng), col.ind_sample(&mut rng), col.ind_sample(&mut rng)], 102 | } 103 | } 104 | 105 | pub fn draw(&mut self, 106 | target: &mut Frame, 107 | params: &DrawParameters, 108 | m_view: [[f32; 4]; 4], 109 | m_proj: [[f32; 4]; 4], 110 | light: [f32; 3], 111 | time: f32) { 112 | let uni = uniform!{view : m_view, projection: m_proj, u_light: light, f_time : time, scale: self.scale, u_color : self.u_color}; 113 | self.renderable.render(target, params, &uni); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/planet.rs: -------------------------------------------------------------------------------- 1 | use vertex::AnyVertex; 2 | use super::glium::backend::Facade; 3 | use super::glium::{Frame, DrawParameters}; 4 | use cgmath::*; 5 | use triangle::*; 6 | use std::f32; 7 | use renderable::{RenderableVertexNormal, Renderable}; 8 | use rand::distributions::Range; 9 | use rand::distributions::IndependentSample; 10 | use rand::random; 11 | use rand; 12 | 13 | pub struct Planet { 14 | triangles: Vec>, 15 | pub verticies: Vec, 16 | pub normals: Vec, 17 | pub renderable: RenderableVertexNormal, 18 | f_seed: f32, 19 | f_persistance: f32, 20 | f_lacunarity: f32, 21 | i_octaves: i32, 22 | u_color: [f32; 3], 23 | } 24 | 25 | impl Planet { 26 | pub fn new(display: &Facade, subdivisions: i32) -> Self { 27 | let t: f32 = (1. + (5.0f32).sqrt()) / 2.; 28 | 29 | let p0 = vec3![-1., t, 0.].normalize(); 30 | let p1 = vec3![1., t, 0.].normalize(); 31 | let p2 = vec3![-1., -t, 0.].normalize(); 32 | let p3 = vec3![1., -t, 0.].normalize(); 33 | 34 | let p4 = vec3![0., -1., t].normalize(); 35 | let p5 = vec3![0., 1., t].normalize(); 36 | let p6 = vec3![0., -1., -t].normalize(); 37 | let p7 = vec3![0., 1., -t].normalize(); 38 | 39 | let p8 = vec3![t, 0., -1.].normalize(); 40 | let p9 = vec3![t, 0., 1.].normalize(); 41 | let p10 = vec3![-t, 0., -1.].normalize(); 42 | let p11 = vec3![-t, 0., 1.].normalize(); 43 | 44 | let mut tris = vec![Triangle::new([p0, p11, p5], 0.), 45 | Triangle::new([p0, p5, p1], 0.), 46 | Triangle::new([p0, p1, p7], 0.), 47 | Triangle::new([p0, p7, p10], 0.), 48 | Triangle::new([p0, p10, p11], 0.), 49 | 50 | Triangle::new([p1, p5, p9], 0.), 51 | Triangle::new([p5, p11, p4], 0.), 52 | Triangle::new([p11, p10, p2], 0.), 53 | Triangle::new([p10, p7, p6], 0.), 54 | Triangle::new([p7, p1, p8], 0.), 55 | 56 | Triangle::new([p3, p9, p4], 0.), 57 | Triangle::new([p3, p4, p2], 0.), 58 | Triangle::new([p3, p2, p6], 0.), 59 | Triangle::new([p3, p6, p8], 0.), 60 | Triangle::new([p3, p8, p9], 0.), 61 | 62 | Triangle::new([p4, p9, p5], 0.), 63 | Triangle::new([p2, p4, p11], 0.), 64 | Triangle::new([p6, p2, p10], 0.), 65 | Triangle::new([p8, p6, p7], 0.), 66 | Triangle::new([p9, p8, p1], 0.)]; 67 | 68 | for _ in 0..subdivisions { 69 | for tri in tris.iter_mut() { 70 | (*tri).subdivide(); 71 | } 72 | } 73 | 74 | let mut verts: Vec = Vec::with_capacity(tris.len()); 75 | for tri in tris.iter_mut() { 76 | verts.append(&mut tri.get_verticies()); 77 | } 78 | 79 | let mut nrm: Vec = Vec::with_capacity(tris.len()); 80 | for t in tris.iter_mut() { 81 | nrm.append(&mut t.get_normal()); 82 | } 83 | let vertex_shader = format!("{}{}", 84 | include_str!("../assets/shaders/noise4d.glsl"), 85 | include_str!("../assets/shaders/shader_150.glslv")); 86 | let fragment_shader = include_str!("../assets/shaders/shader_150.glslf"); 87 | let rnd = 88 | RenderableVertexNormal::new(display, &verts, &nrm, &vertex_shader, &fragment_shader); 89 | 90 | let mut rng = rand::thread_rng(); 91 | let random_pers = Range::new(0.0f32, 1.0f32); 92 | let random_lac = Range::new(1.0f32, 3.0f32); 93 | let random_step = Range::new(1i32, 10i32); 94 | 95 | Planet { 96 | triangles: tris, 97 | verticies: verts, 98 | normals: nrm, 99 | renderable: rnd, 100 | f_seed: random::(), 101 | f_persistance: random_pers.ind_sample(&mut rng), 102 | f_lacunarity: random_lac.ind_sample(&mut rng), 103 | i_octaves: random_step.ind_sample(&mut rng), 104 | u_color: [random_pers.ind_sample(&mut rng), 105 | random_pers.ind_sample(&mut rng), 106 | random_pers.ind_sample(&mut rng)], 107 | } 108 | } 109 | 110 | pub fn draw(&mut self, 111 | target: &mut Frame, 112 | params: &DrawParameters, 113 | m_view: [[f32; 4]; 4], 114 | m_proj: [[f32; 4]; 4], 115 | light: [f32; 3]) { 116 | let uni = uniform!{view : m_view, projection: m_proj, u_light: light, f_seed: self.f_seed, f_persistance: self.f_persistance, f_lacunarity: self.f_lacunarity, i_octaves: self.i_octaves, u_color: self.u_color}; 117 | self.renderable.render(target, params, &uni); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/renderable.rs: -------------------------------------------------------------------------------- 1 | use super::glium::{Surface, Vertex, VertexBuffer, Program, Frame, DrawParameters}; 2 | use super::glium::index::NoIndices; 3 | use super::glium::backend::Facade; 4 | use super::glium::uniforms::{Uniforms, AsUniformValue, UniformsStorage}; 5 | 6 | pub trait Renderable<'a, T: AsUniformValue, R: Uniforms> { 7 | fn render(&mut self, 8 | target: &mut Frame, 9 | params: &DrawParameters, 10 | uniforms: &UniformsStorage<'a, T, R>); 11 | } 12 | 13 | pub struct RenderableVertexNormal { 14 | vertex_buffer: VertexBuffer, 15 | normal_buffer: VertexBuffer, 16 | index_buffer: NoIndices, 17 | shader: Program, 18 | } 19 | #[allow(dead_code)] //maybe will be useful later 20 | pub struct RenderableVertex { 21 | vertex_buffer: VertexBuffer, 22 | index_buffer: NoIndices, 23 | shader: Program, 24 | } 25 | 26 | impl RenderableVertexNormal { 27 | pub fn new(display: &Facade, 28 | verts: &Vec, 29 | normals: &Vec, 30 | vshader: &str, 31 | fshader: &str) 32 | -> RenderableVertexNormal { 33 | use super::glium::index::PrimitiveType; 34 | 35 | let vb = VertexBuffer::new(display, verts).unwrap(); 36 | let nb = VertexBuffer::new(display, normals).unwrap(); 37 | let ib = NoIndices(PrimitiveType::TrianglesList); 38 | 39 | let program = Program::from_source(display, vshader, fshader, None).unwrap(); 40 | 41 | RenderableVertexNormal { 42 | vertex_buffer: vb, 43 | normal_buffer: nb, 44 | index_buffer: ib, 45 | shader: program, 46 | } 47 | } 48 | } 49 | #[allow(dead_code)] //maybe will be useful later 50 | impl RenderableVertex { 51 | pub fn new(display: &Facade, 52 | verts: &Vec, 53 | vshader: &str, 54 | fshader: &str) 55 | -> RenderableVertex { 56 | use super::glium::index::PrimitiveType; 57 | 58 | let vb = VertexBuffer::new(display, verts).unwrap(); 59 | let ib = NoIndices(PrimitiveType::TrianglesList); 60 | 61 | let program = Program::from_source(display, vshader, fshader, None).unwrap(); 62 | 63 | RenderableVertex { 64 | vertex_buffer: vb, 65 | index_buffer: ib, 66 | shader: program, 67 | } 68 | } 69 | } 70 | 71 | impl<'a, T: AsUniformValue, R: Uniforms, V: Vertex, N: Vertex> Renderable<'a, T, R> 72 | for RenderableVertexNormal { 73 | fn render(&mut self, 74 | target: &mut Frame, 75 | params: &DrawParameters, 76 | uniforms: &UniformsStorage<'a, T, R>) { 77 | target.draw((&self.vertex_buffer, &self.normal_buffer), 78 | &self.index_buffer, 79 | &self.shader, 80 | uniforms, 81 | params) 82 | .unwrap(); 83 | } 84 | } 85 | impl<'a, T: AsUniformValue, R: Uniforms, V: Vertex> Renderable<'a, T, R> for RenderableVertex { 86 | fn render(&mut self, 87 | target: &mut Frame, 88 | params: &DrawParameters, 89 | uniforms: &UniformsStorage<'a, T, R>) { 90 | target.draw(&self.vertex_buffer, 91 | &self.index_buffer, 92 | &self.shader, 93 | uniforms, 94 | params) 95 | .unwrap(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/triangle.rs: -------------------------------------------------------------------------------- 1 | use vertex::*; 2 | use cgmath::{Vector3, InnerSpace}; 3 | use std::cell::RefCell; 4 | use std::rc::Rc; 5 | 6 | pub enum TriangleContent { 7 | Triangles([Rc>>; 4]), 8 | Verticies([T; 3]), 9 | } 10 | 11 | pub struct Triangle { 12 | pub subdivided: bool, 13 | pub level_of_subdivision: f32, 14 | pub contents: TriangleContent, 15 | } 16 | 17 | impl Triangle { 18 | pub fn new(pos: [Vector3; 3], los: f32) -> Triangle { 19 | let verts: [T; 3] = [T::new(pos[0].into()), T::new(pos[1].into()), T::new(pos[2].into())]; 20 | Triangle { 21 | subdivided: false, 22 | level_of_subdivision: los, 23 | contents: TriangleContent::Verticies(verts), 24 | } 25 | } 26 | 27 | pub fn subdivide(&mut self) { 28 | let tris: [Rc>>; 4] = 29 | [Rc::new(RefCell::new(Triangle::new([Vector3::new(0., 0., 0.); 3], 0.))), 30 | Rc::new(RefCell::new(Triangle::new([Vector3::new(0., 0., 0.); 3], 0.))), 31 | Rc::new(RefCell::new(Triangle::new([Vector3::new(0., 0., 0.); 3], 0.))), 32 | Rc::new(RefCell::new(Triangle::new([Vector3::new(0., 0., 0.); 3], 0.)))]; 33 | let mut triangles_temp: TriangleContent = TriangleContent::Triangles(tris); 34 | 35 | match self.contents { 36 | TriangleContent::Triangles(ref t) => { 37 | for value in t.iter() { 38 | value.borrow_mut().subdivide(); 39 | } 40 | } 41 | TriangleContent::Verticies(ref v) => { 42 | let a = Triangle::::middle_point(v[0].get_position(), v[1].get_position()); 43 | let b = Triangle::::middle_point(v[1].get_position(), v[2].get_position()); 44 | let c = Triangle::::middle_point(v[2].get_position(), v[0].get_position()); 45 | 46 | let triangles: [Rc>>; 4] = 47 | [Rc::new(RefCell::new(Triangle::new([v[0].get_position(), a, c], 48 | self.level_of_subdivision + 1.))), 49 | Rc::new(RefCell::new(Triangle::new([v[1].get_position(), b, a], 50 | self.level_of_subdivision + 1.))), 51 | Rc::new(RefCell::new(Triangle::new([v[2].get_position(), c, b], 52 | self.level_of_subdivision + 1.))), 53 | Rc::new(RefCell::new(Triangle::new([a, b, c], 54 | self.level_of_subdivision + 1.)))]; 55 | triangles_temp = TriangleContent::Triangles(triangles); 56 | } 57 | } 58 | if !self.subdivided { 59 | self.contents = triangles_temp; 60 | self.subdivided = true; 61 | } 62 | } 63 | 64 | pub fn middle_point(p1: Vector3, p2: Vector3) -> Vector3 { 65 | Vector3::::new((p1.x + p2.x) / 2., (p1.y + p2.y) / 2., (p1.z + p2.z) / 2.).normalize() 66 | } 67 | 68 | pub fn get_verticies(&self) -> Vec { 69 | let mut out: Vec = Vec::new(); 70 | 71 | match self.contents { 72 | TriangleContent::Triangles(ref t) => { 73 | for value in t.iter() { 74 | out.append(&mut value.borrow_mut().get_verticies()); 75 | } 76 | } 77 | TriangleContent::Verticies(ref v) => { 78 | out = v.to_vec(); 79 | } 80 | } 81 | 82 | out 83 | } 84 | 85 | pub fn get_normal(&self) -> Vec { 86 | let mut out: Vec = Vec::new(); 87 | match self.contents { 88 | TriangleContent::Triangles(ref t) => { 89 | for value in t.iter() { 90 | out.append(&mut value.borrow_mut().get_normal()); 91 | } 92 | } 93 | TriangleContent::Verticies(ref v) => { 94 | let v1 = v[2].get_position() - v[0].get_position(); 95 | let v2 = v[1].get_position() - v[0].get_position(); 96 | let n = v1.cross(v2); 97 | let norm = N::new([n.x, n.y, n.z]); 98 | out = vec![norm, norm, norm]; 99 | } 100 | } 101 | out 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/vertex.rs: -------------------------------------------------------------------------------- 1 | use cgmath::Vector3; 2 | use super::glium::vertex::Vertex; 3 | 4 | pub trait AnyVertex: Vertex { 5 | fn new(point: [f32; 3]) -> Self; 6 | fn get_position(&self) -> Vector3; 7 | } 8 | 9 | #[derive(Copy, Clone)] 10 | pub struct VertexPosition { 11 | position: [f32; 3], 12 | } 13 | 14 | #[derive(Copy, Clone)] 15 | pub struct Normal { 16 | normal: [f32; 3], 17 | } 18 | 19 | implement_vertex!(VertexPosition, position); 20 | implement_vertex!(Normal, normal); 21 | 22 | impl AnyVertex for VertexPosition { 23 | fn new(point: [f32; 3]) -> VertexPosition { 24 | VertexPosition { position: point } 25 | } 26 | 27 | fn get_position(&self) -> Vector3 { 28 | Vector3::new(self.position[0], self.position[1], self.position[2]) 29 | } 30 | } 31 | impl AnyVertex for Normal { 32 | fn new(point: [f32; 3]) -> Normal { 33 | Normal { normal: point } 34 | } 35 | 36 | fn get_position(&self) -> Vector3 { 37 | Vector3::new(self.normal[0], self.normal[1], self.normal[2]) 38 | } 39 | } 40 | --------------------------------------------------------------------------------