├── LICENSE ├── README.md └── pymaze ├── __pycache__ ├── camera.cpython-38.pyc ├── constants.cpython-38.pyc ├── debug.cpython-38.pyc ├── end_portal.cpython-38.pyc ├── entities.cpython-38.pyc ├── labyrinth.cpython-38.pyc ├── player.cpython-38.pyc ├── post_processing.cpython-38.pyc ├── shaders.cpython-38.pyc ├── skybox.cpython-38.pyc ├── textures.cpython-38.pyc └── wall.cpython-38.pyc ├── camera.py ├── constants.py ├── debug.py ├── end_portal.py ├── entities.py ├── labyrinth.py ├── main.py ├── player.py ├── post_processing.py ├── shaders.py ├── shaders ├── debug_line.frag ├── debug_line.vert ├── portal.frag ├── portal.vert ├── post_processing.frag ├── post_processing.vert ├── post_processing │ ├── post_crossha.frag │ ├── post_crossha.vert │ ├── post_default.frag │ ├── post_default.vert │ ├── post_fisheye.frag │ ├── post_fisheye.vert │ ├── post_radialb.frag │ ├── post_radialb.vert │ ├── post_third3d.frag │ └── post_third3d.vert ├── shadow_debugger.frag ├── shadow_debugger.vert ├── shadow_mapping.frag ├── shadow_mapping.vert ├── skybox.frag ├── skybox.vert ├── world_geom.frag └── world_geom.vert ├── skybox.py ├── sound.py ├── textures.py └── textures ├── floor_01.png ├── skybox_01 ├── back.png ├── bottom.png ├── front.png ├── left.png ├── right.png └── top.png ├── trim_01.png └── wall_01.png /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PyGLMaze 2 | 3 | "Simple" Python + OpenGL 3D Maze Game. 4 | with few additions such as: Shadow mapping, post-processing effects, physics/collision. 5 | i might add more stuff in to it, if there's something you want to see. 6 | 7 | # Video 8 | [![PyGLMaze](https://img.youtube.com/vi/T94Ht1I5-Kk/0.jpg)](https://www.youtube.com/watch?v=T94Ht1I5-Kk) 9 | -------------------------------------------------------------------------------- /pymaze/__pycache__/camera.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/camera.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/constants.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/constants.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/debug.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/debug.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/end_portal.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/end_portal.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/entities.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/entities.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/labyrinth.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/labyrinth.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/player.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/player.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/post_processing.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/post_processing.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/shaders.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/shaders.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/skybox.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/skybox.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/textures.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/textures.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/__pycache__/wall.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/__pycache__/wall.cpython-38.pyc -------------------------------------------------------------------------------- /pymaze/camera.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | 4 | import glm 5 | import numpy as np 6 | 7 | from constants import * 8 | 9 | class PWCamera(PWConstants): 10 | def __init__(self): 11 | self.projection = glm.perspective(glm.radians(self.c_fov), self.c_aspect, self.c_near, self.c_far) 12 | 13 | self.position = glm.vec3(0.0, self.p_height, 0.0) 14 | self.front = glm.vec3(0.0, 0.0, -1.0) 15 | self.up = glm.vec3(0.0, 1.0, 0.0) 16 | 17 | self.yaw = 0.0 18 | self.pitch = 0.0 19 | 20 | # Center mouse (Not necessary needed) 21 | pygame.mouse.set_pos(self.d_resolution.x / 2, self.d_resolution.y / 2) 22 | 23 | # These 2 makes the mouse virtual (Makes the window "borderless" for the mouse) 24 | pygame.mouse.set_visible(False) 25 | pygame.event.set_grab(True) 26 | 27 | 28 | def getPosition(self): 29 | return self.position 30 | 31 | 32 | @classmethod 33 | def createViewFront(cls, pitch, yaw): 34 | pitch_r = glm.radians(pitch) 35 | yaw_r = glm.radians(yaw) 36 | 37 | front = glm.vec3(0.0, 0.0, 1.0) 38 | front.x = glm.cos(yaw_r) * glm.cos(pitch_r) 39 | front.y = glm.sin(pitch_r) 40 | front.z = glm.sin(yaw_r) * glm.cos(pitch_r) 41 | return glm.normalize(front) 42 | 43 | 44 | def updateCamera(self, delta, position): 45 | self.position.xz = position.xz 46 | self.position.y = self.p_height + position.y 47 | 48 | 49 | # -------- Pitch/Yaw 50 | 51 | mouse = pygame.mouse.get_rel() 52 | 53 | mx = glm.clamp(mouse[0], -128, 128) 54 | my = glm.clamp(mouse[1], -128, 128) 55 | 56 | self.yaw += mx * self.c_sensitivity * delta 57 | self.yaw %= 360 58 | 59 | self.pitch -= my * self.c_sensitivity * delta 60 | self.pitch = glm.clamp(self.pitch, -89.0, 89.0) # Dont go over > 90 (It'll flip the camera) 61 | 62 | # -------- Update camera front 63 | 64 | self.front = self.createViewFront(self.pitch, self.yaw); 65 | 66 | 67 | def __getViewRaw(self): 68 | return glm.lookAt(self.position, self.position + self.front, self.up) 69 | 70 | 71 | def getProjectionView(self): 72 | return np.array(self.projection * self.__getViewRaw(), dtype='float32') 73 | 74 | 75 | def getView(self): 76 | return np.array(self.__getViewRaw(), dtype='float32') 77 | 78 | 79 | def getProjection(self): 80 | return self.projection 81 | 82 | 83 | 84 | if __name__ == "__main__": 85 | pass 86 | 87 | -------------------------------------------------------------------------------- /pymaze/constants.py: -------------------------------------------------------------------------------- 1 | import glm 2 | import ctypes 3 | 4 | from OpenGL.GL import * 5 | from OpenGL.GL import shaders 6 | 7 | class PWConstants(object): 8 | # Common 9 | d_max_fps = 2048 10 | d_resolution = glm.ivec2(1280, 720) 11 | d_fsize = ctypes.sizeof(ctypes.c_float) 12 | d_gravity = 9.81 13 | 14 | # Camera 15 | c_fov = 45.0 16 | c_aspect = float(d_resolution.x) / float(d_resolution.y) 17 | c_near = 0.01 18 | c_far = 100.0 19 | c_sensitivity = 5.0 20 | 21 | # Player 22 | p_height = 0.8 23 | p_speed = 3.0 24 | p_jump_vel = 3.5 25 | 26 | # Shadows 27 | s_shadow_width = 4096 * 2 28 | s_shadow_height = 4096 * 2 29 | s_shadow_near = 0.01 30 | s_shadow_far = 64.0 31 | 32 | 33 | class PWVaoData(object): 34 | def __init__(self): 35 | self.vao = 0 36 | self.vbo = 0 37 | self.data = 0 38 | self.count = 0 39 | 40 | 41 | if __name__ == "__main__": 42 | pass 43 | -------------------------------------------------------------------------------- /pymaze/debug.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from constants import * 4 | from shaders import * 5 | 6 | class PWDebug(PWConstants): 7 | MAX_LINES = 8192 8 | 9 | # Draw commands 10 | __draw_list = [] 11 | 12 | # Data 13 | __vao = None 14 | __stride = 0 15 | __data = None 16 | 17 | 18 | @classmethod 19 | def initDebugger(cls): 20 | cls.__stride = (cls.d_fsize * 4) * 2 21 | cls.__data = np.array([0] * 8 * cls.MAX_LINES, dtype='float32') 22 | 23 | # -------- 24 | 25 | cls.__vao = PWVaoData() 26 | cls.__vao.count = 1 27 | 28 | cls.__vao.vao = glGenVertexArrays(1) 29 | glBindVertexArray(cls.__vao.vao) 30 | 31 | cls.__vao.data = glGenBuffers(1) 32 | glBindBuffer(GL_ARRAY_BUFFER, cls.__vao.data) 33 | glBufferData(GL_ARRAY_BUFFER, cls.__data, GL_STREAM_DRAW) 34 | 35 | glEnableVertexAttribArray(0) 36 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, cls.d_fsize * 4, None) 37 | 38 | 39 | @classmethod 40 | def drawLine(cls, _from, _to, grey = 1.0): 41 | if cls.__vao.count >= cls.MAX_LINES - 1: 42 | return 43 | 44 | ofs = cls.__vao.count * 8 45 | cls.__data[ofs + 0] = _from.x 46 | cls.__data[ofs + 1] = _from.y 47 | cls.__data[ofs + 2] = _from.z 48 | cls.__data[ofs + 3] = grey 49 | 50 | cls.__data[ofs + 4] = _to.x 51 | cls.__data[ofs + 5] = _to.y 52 | cls.__data[ofs + 6] = _to.z 53 | cls.__data[ofs + 7] = grey 54 | 55 | # Update line count 56 | cls.__vao.count += 1 57 | 58 | 59 | @classmethod 60 | def drawDebug(cls, camera): 61 | if not cls.__vao.count: 62 | return 63 | 64 | #glDisable(GL_DEPTH_TEST) 65 | #glDisable(GL_MULTISAMPLE) 66 | glLineWidth(2.0) 67 | 68 | shader = PWShaders.getShader(ShaderTypes.DEBUG_SHADER) 69 | glUseProgram(shader.shader) 70 | glUniformMatrix4fv(shader.proj_view, 1, GL_FALSE, camera.getProjectionView()) 71 | 72 | # -------- 73 | 74 | glBindBuffer(GL_ARRAY_BUFFER, cls.__vao.data) 75 | glBufferData(GL_ARRAY_BUFFER, cls.__data, GL_STREAM_DRAW) 76 | #glBufferSubData could work here better if more lines are needed 77 | 78 | glBindVertexArray(cls.__vao.vao) 79 | glDrawArrays(GL_LINES, 0, 2 * cls.__vao.count) 80 | 81 | # Reset line count 82 | cls.__vao.count = 0 83 | 84 | #glEnable(GL_DEPTH_TEST) 85 | #glEnable(GL_MULTISAMPLE) 86 | glLineWidth(1.0) 87 | 88 | 89 | if __name__ == "__main__": 90 | pass 91 | -------------------------------------------------------------------------------- /pymaze/end_portal.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import glm 3 | 4 | from OpenGL.GL import * 5 | 6 | from constants import * 7 | from shaders import * 8 | 9 | class PWPortal(PWConstants): 10 | def __init__(self): 11 | self.portal = PWVaoData() 12 | self.__createPortal() 13 | 14 | 15 | def __createPortal(self): 16 | self.portal.vao = glGenVertexArrays(1) 17 | glBindVertexArray(self.portal.vao) 18 | 19 | 20 | s = 0.5 21 | vertices = np.array([-s, s, 0.0, 0.0, 0.0, 22 | -s, -s, 0.0, 0.0, 1.0, 23 | s, -s, 0.0, 1.0, 1.0, 24 | 25 | -s, s, 0.0, 0.0, 0.0, 26 | s, -s, 0.0, 1.0, 1.0, 27 | s, s, 0.0, 1.0, 0.0], dtype='float32') 28 | 29 | self.portal.vbo = glGenBuffers(1) 30 | glBindBuffer(GL_ARRAY_BUFFER, self.portal.vbo) 31 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) 32 | 33 | stride = 5 34 | glEnableVertexAttribArray(0) 35 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 36 | 37 | uv_offset = 3 38 | glEnableVertexAttribArray(1) 39 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * uv_offset, ctypes.c_void_p)) 40 | 41 | 42 | def render(self, camera, seconds, color_texture, depth_texture): 43 | shader = PWShaders.getShader(ShaderTypes.PORTAL_SHADER) 44 | glUseProgram(shader.shader) 45 | 46 | glUniformMatrix4fv(shader.proj_view, 1, GL_FALSE, camera.getProjectionView()) 47 | glUniformMatrix4fv(shader.view, 1, GL_FALSE, camera.getView()) 48 | 49 | #glDisable(GL_CULL_FACE) 50 | 51 | # Player is in "center" while portal is relative to world center 52 | # add a little offset to get correct distance to the portal 53 | 54 | player_position = camera.getPosition() # Camera and player share the same position (We can use the camera position here) 55 | portal_position = glm.vec3(16.5, 0.35, -16.5) 56 | 57 | # -------- 58 | 59 | model = glm.mat4(1.0) 60 | model = glm.translate(model, portal_position) # Set end portal at the other end of the labyrinth 61 | glUniformMatrix4fv(shader.model, 1, GL_FALSE, np.array(model, dtype='float32')) 62 | 63 | glUniform1f(shader.seconds, seconds) 64 | glUniform2f(shader.resolution, self.d_resolution.x, self.d_resolution.y) 65 | 66 | # -------- 67 | 68 | glActiveTexture(GL_TEXTURE0) 69 | glBindTexture(GL_TEXTURE_2D, color_texture) 70 | 71 | glActiveTexture(GL_TEXTURE1) 72 | glBindTexture(GL_TEXTURE_2D, depth_texture) 73 | 74 | # -------- 75 | 76 | glBindVertexArray(self.portal.vao) 77 | glDrawArrays(GL_TRIANGLES, 0, 6) 78 | 79 | #glEnable(GL_CULL_FACE) 80 | 81 | # -------- 82 | 83 | # Player is in "center" while portal is relative to world center 84 | # add a little offset to get correct distance to the portal 85 | 86 | portal_position_ofs = portal_position + glm.vec3(16.5, 0.0, -16.5) # Add offset 87 | distance = glm.distance(player_position, portal_position_ofs) 88 | return distance < 1.0 89 | -------------------------------------------------------------------------------- /pymaze/entities.py: -------------------------------------------------------------------------------- 1 | import glm 2 | 3 | from debug import * 4 | 5 | class PWBBox(object): 6 | def __init__(self, wh, pos): 7 | self.wh = wh 8 | self.pos = pos 9 | 10 | def updatePos(self, x, y): 11 | self.pos.x = x 12 | self.pos.y = y 13 | 14 | def colliderect(self, rect): 15 | s = 64.0 # Increase the resolution for the collision checking 16 | 17 | p_pos1 = self.pos * s 18 | r_pos1 = (rect.pos + rect.bbox.wh) * s 19 | 20 | p_pos2 = (self.pos + self.wh) * s 21 | r_pos2 = rect.pos * s 22 | 23 | if (p_pos1.x < r_pos1.x and p_pos2.x > r_pos2.x) and \ 24 | (p_pos1.y < r_pos1.y and p_pos2.y > r_pos2.y): 25 | return True 26 | else: 27 | return False 28 | 29 | 30 | class PWWall(object): 31 | def __init__(self, position, wh): 32 | self.pos = glm.vec2(position) 33 | self.bbox = PWBBox(wh, glm.vec2(self.pos.x, self.pos.y)) 34 | 35 | def debugDraw(self): 36 | tl = glm.vec3(self.pos.x, 0.0, self.pos.y) 37 | tr = glm.vec3(self.pos.x + self.bbox.wh.x, 0.0, self.pos.y + self.bbox.wh.y) 38 | 39 | PWDebug.drawLine(tl, tl + glm.vec3(self.bbox.wh.x, 0.0, 0.0)) 40 | PWDebug.drawLine(tl, tl + glm.vec3(0.0, 0.0, self.bbox.wh.y)) 41 | 42 | PWDebug.drawLine(tr, tr - glm.vec3(self.bbox.wh.x, 0.0, 0.0)) 43 | PWDebug.drawLine(tr, tr - glm.vec3(0.0, 0.0, self.bbox.wh.y)) -------------------------------------------------------------------------------- /pymaze/labyrinth.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | import sys 4 | import os 5 | import glm 6 | import numpy as np 7 | import ctypes 8 | 9 | from OpenGL.GL import * 10 | 11 | import random 12 | #random.seed(0xdeadbeef) 13 | 14 | from constants import * 15 | from textures import * 16 | from shaders import * 17 | from debug import * 18 | from entities import * 19 | 20 | 21 | # ---------------------------------------------------------------- 22 | 23 | CELL_SIZE = 32 # Dont change! 24 | CELL_FREE = 0 # Dont change! 25 | CELL_DONE = 1 # Dont change! 26 | CELL_VIST = 2 # Dont change! 27 | 28 | # http://weblog.jamisbuck.org/2011/1/10/maze-generation-prim-s-algorithm 29 | class PWMazeGenerator(PWConstants): 30 | def __init__(self, width, height, output_data = False): 31 | self.width = width 32 | self.height = height 33 | self.output = output_data 34 | 35 | # -------- If output_data is enabled, these get filled with data. 36 | 37 | self.o_walls = [] 38 | self.o_trims = [] 39 | 40 | # -------- 41 | 42 | self.surface = pygame.Surface((512, 512)) 43 | pygame.draw.rect(self.surface, (0xff, 0xff, 0xff), (0, 0, 512, 512), 1) 44 | 45 | # 46 | self.p_grid = [[CELL_FREE for x in range(self.width)] for y in range(self.height)] 47 | self.p_done = [] 48 | self.p_cand = [] 49 | 50 | # 51 | self.dirs = [glm.ivec2(0, -1), glm.ivec2(0, 1), glm.ivec2(-1, 0), glm.ivec2(1, 0)] 52 | 53 | # 54 | self.stepMaze(True) 55 | 56 | 57 | def __withIn(self, v, v_min, v_max): 58 | return True if (v > v_min and v < v_max) else False 59 | 60 | 61 | def __withInGrid(self, p, v): 62 | if self.__withIn(p.y, -1, self.height) and self.__withIn(p.x, -1, self.width) and self.p_grid[p.y][p.x] == v: 63 | return True 64 | 65 | return False 66 | 67 | 68 | def __advance(self, p): 69 | self.p_grid[p.y][p.x] = CELL_DONE 70 | self.p_done.append(p) 71 | 72 | for direction in self.dirs: 73 | ofs = p + direction 74 | if self.__withInGrid(ofs, CELL_FREE): 75 | self.p_grid[ofs.y][ofs.x] = CELL_VIST 76 | self.p_cand.append(ofs) 77 | 78 | 79 | def __getMidPointCorr(self, _from, _to): 80 | mx = (((_from.x + _to.x) / 2.0) / CELL_SIZE) * 2.2 81 | my = (((_from.y + _to.y) / 2.0) / CELL_SIZE) * 2.2 82 | return glm.vec2(-mx, my) 83 | 84 | def __getMidPoint(self, _from, _to): 85 | mx = (_from.x + _to.x) / 2.0 86 | my = (_from.y + _to.y) / 2.0 87 | return glm.vec2(mx, my) 88 | 89 | def __buildWall(self, _from, _to, direction): 90 | pygame.draw.line(self.surface, (0xff, 0xff, 0xff), _from, _to, 1) 91 | 92 | if (self.output): 93 | mid = self.__getMidPointCorr(_from, _to) 94 | self.o_walls.extend([mid.y - 1.1, direction, mid.x + 1.1]) 95 | 96 | 97 | def __buildTrim(self, _from, _to): 98 | direction = abs(_from.x - _to.x) 99 | 100 | _from *= CELL_SIZE 101 | _to *= CELL_SIZE 102 | 103 | mid = self.__getMidPoint(_from, _to) + CELL_SIZE / 2 104 | #pygame.draw.circle(self.surface, (0xff, 0x0, 0x0), (int(mid.x), int(mid.y)), 2, 1) 105 | 106 | if (self.output): 107 | self.o_trims.extend([(mid.y / CELL_SIZE * 2.2) - 1.1, direction, -((mid.x / CELL_SIZE * 2.2) - 1.1)]) 108 | 109 | 110 | def __advanceDraw(self, _to, _from): 111 | max_x = self.width 112 | max_y = self.height 113 | 114 | x2, y2 = _to 115 | 116 | x2_m = x2 * CELL_SIZE 117 | y2_m = y2 * CELL_SIZE 118 | 119 | if (self.__withIn(y2 - 1, -1, max_y) and self.p_grid[y2 - 1][x2] == 1 and y2 - 1 != _from.y): 120 | t1 = glm.ivec2(x2_m, y2_m) 121 | t2 = glm.ivec2(x2_m + CELL_SIZE, y2_m) 122 | self.__buildWall(t1, t2, 1.0) 123 | 124 | 125 | if (self.__withIn(y2 + 1, -1, max_y) and self.p_grid[y2 + 1][x2] == 1 and y2 + 1 != _from.y): 126 | t1 = glm.ivec2(x2_m, y2_m + CELL_SIZE) 127 | t2 = glm.ivec2(x2_m + CELL_SIZE, y2_m + CELL_SIZE) 128 | self.__buildWall(t1, t2, 1.0) 129 | 130 | 131 | if (self.__withIn(x2 - 1, -1, max_x) and self.p_grid[y2][x2 - 1] == 1 and x2 - 1 != _from.x): 132 | t1 = glm.ivec2(x2_m, y2_m) 133 | t2 = glm.ivec2(x2_m, y2_m + CELL_SIZE) 134 | self.__buildWall(t1, t2, 0.0) 135 | 136 | 137 | if (self.__withIn(x2 + 1, -1, max_x) and self.p_grid[y2][x2 + 1] == 1 and x2 + 1 != _from.x): 138 | t1 = glm.ivec2(x2_m + CELL_SIZE, y2_m) 139 | t2 = glm.ivec2(x2_m + CELL_SIZE, y2_m + CELL_SIZE) 140 | self.__buildWall(t1, t2, 0.0) 141 | 142 | 143 | def __getNextValidCell(self, p): 144 | mov = [] 145 | 146 | for direction in self.dirs: 147 | ofs = p + direction 148 | if self.__withInGrid(ofs, CELL_DONE): 149 | mov.append(ofs) 150 | 151 | rdir = random.randrange(0, len(mov)) 152 | return mov[rdir] 153 | 154 | 155 | def stepMaze(self, set_spawn = False): 156 | if set_spawn: 157 | #x = random.randrange(0, self.width) 158 | #y = random.randrange(0, self.height) 159 | 160 | self.__advance(glm.ivec2(0, 0)) 161 | else: 162 | if not self.p_cand: 163 | return True 164 | 165 | rcand = random.randrange(0, len(self.p_cand)) 166 | 167 | candidate = self.p_cand[rcand] 168 | direction = self.__getNextValidCell(candidate) 169 | 170 | self.__advance(candidate) 171 | self.__advanceDraw(candidate, direction) 172 | 173 | visited = self.p_cand.pop(rcand) 174 | self.__buildTrim(direction, visited) 175 | 176 | return False 177 | 178 | 179 | def render(self, surface): 180 | surface.blit(self.surface, (0, 0)) 181 | 182 | 183 | # ---------------------------------------------------------------- 184 | 185 | 186 | class PWMaze(PWConstants): 187 | def __init__(self, width, height): 188 | self.width = width 189 | self.height = height 190 | 191 | # -------- Generate maze 192 | 193 | self.maze = PWMazeGenerator(width, height, True) 194 | while(not self.maze.stepMaze()): 195 | pass 196 | 197 | # -------- Setup Floor Geometry 198 | 199 | self.floors = PWVaoData() 200 | self.__createFloorGeom() 201 | 202 | # -------- Setup Wall Geometry 203 | 204 | self.aabb_walls = [] # Add collision for the walls 205 | self.walls = PWVaoData() 206 | self.__createWallsGeom() 207 | 208 | # -------- Setup Trim Geometry 209 | 210 | self.trims= PWVaoData() 211 | self.__createTrimsGeom() 212 | 213 | 214 | def __createFloorGeom(self): 215 | self.floors.vao = glGenVertexArrays(1) 216 | glBindVertexArray(self.floors.vao) 217 | 218 | # Position(3), Normal(3), Texture(2) == stride 219 | vertices = np.array([-1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 220 | 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 221 | -1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 222 | 223 | -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 224 | 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 225 | 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 1.0], dtype='float32') 226 | 227 | self.floors.vbo = glGenBuffers(1) 228 | glBindBuffer(GL_ARRAY_BUFFER, self.floors.vbo) 229 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) 230 | 231 | stride = 8 232 | glEnableVertexAttribArray(0) 233 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 234 | 235 | n_offset = 3 236 | glEnableVertexAttribArray(1) 237 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * n_offset, ctypes.c_void_p)) 238 | 239 | uv_offset = 6 240 | glEnableVertexAttribArray(2) 241 | glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * uv_offset, ctypes.c_void_p)) 242 | 243 | # 244 | glVertexAttribDivisor(0, 0) 245 | glVertexAttribDivisor(1, 0) 246 | glVertexAttribDivisor(2, 0) 247 | 248 | # -------- Build instance matrix (not mat4!) 249 | 250 | positions = [] 251 | for y in range(self.height): 252 | for x in range(self.width): 253 | positions.extend([(float(x) * 2.2), 0.0, -(float(y) * 2.2)]) 254 | 255 | positions = np.array(positions, dtype='float32') 256 | 257 | # Store instance count 258 | self.floors.count = int(len(positions) / 3) 259 | 260 | # -------- Feed data to instance buffer 261 | 262 | self.floors.data = glGenBuffers(1) 263 | glBindBuffer(GL_ARRAY_BUFFER, self.floors.data) 264 | glBufferData(GL_ARRAY_BUFFER, positions, GL_STATIC_DRAW) 265 | 266 | stride = 3 267 | glEnableVertexAttribArray(3) 268 | glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 269 | 270 | # 271 | glVertexAttribDivisor(3, 1) 272 | 273 | 274 | def __createWallsGeom(self): 275 | self.walls.vao = glGenVertexArrays(1) 276 | glBindVertexArray(self.walls.vao) 277 | 278 | # Position(3), Normal(3), Texture(2) == stride 279 | vertices = np.array([-1.0, 0.0, 0.1, 0.0, 0.0, 1.0, 0.0, 0.0, # Front 280 | 1.0, 2.0, 0.1, 0.0, 0.0, 1.0, 1.0, 1.0, 281 | -1.0, 2.0, 0.1, 0.0, 0.0, 1.0, 0.0, 1.0, 282 | 283 | -1.0, 0.0, 0.1, 0.0, 0.0, 1.0, 0.0, 0.0, 284 | 1.0, 0.0, 0.1, 0.0, 0.0, 1.0, 1.0, 0.0, 285 | 1.0, 2.0, 0.1, 0.0, 0.0, 1.0, 1.0, 1.0, 286 | 287 | 288 | -1.0, 0.0, -0.1, 0.0, 0.0, -1.0, 0.0, 0.0, # Back 289 | -1.0, 2.0, -0.1, 0.0, 0.0, -1.0, 0.0, 1.0, 290 | 1.0, 2.0, -0.1, 0.0, 0.0, -1.0, 1.0, 1.0, 291 | 292 | -1.0, 0.0, -0.1, 0.0, 0.0, -1.0, 0.0, 0.0, 293 | 1.0, 2.0, -0.1, 0.0, 0.0, -1.0, 1.0, 1.0, 294 | 1.0, 0.0, -0.1, 0.0, 0.0, -1.0, 1.0, 0.0], dtype='float32') 295 | 296 | self.walls.vbo = glGenBuffers(1) 297 | glBindBuffer(GL_ARRAY_BUFFER, self.walls.vbo) 298 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) 299 | 300 | stride = 8 301 | glEnableVertexAttribArray(0) 302 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 303 | 304 | n_offset = 3 305 | glEnableVertexAttribArray(1) 306 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * n_offset, ctypes.c_void_p)) 307 | 308 | uv_offset = 6 309 | glEnableVertexAttribArray(2) 310 | glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * uv_offset, ctypes.c_void_p)) 311 | 312 | # 313 | glVertexAttribDivisor(0, 0) 314 | glVertexAttribDivisor(1, 0) 315 | glVertexAttribDivisor(2, 0) 316 | 317 | # -------- Build instance matrix (not mat4!) 318 | 319 | # Add outer perimiter walls 320 | for y in range(self.height): 321 | self.maze.o_walls.extend([float(y) * 2.2, 0.0, 1.1]) 322 | self.maze.o_walls.extend([float(y) * 2.2, 0.0, -self.height * 2.2 + 1.1]) 323 | 324 | for x in range(self.width): 325 | self.maze.o_walls.extend([-1.1, 1.0, -float(x) * 2.2]) 326 | self.maze.o_walls.extend([self.width * 2.2 - 1.1, 1.0, -float(x) * 2.2]) 327 | 328 | positions = np.array(self.maze.o_walls, dtype='float32') 329 | 330 | tolerance = 0.01 # Gap between walls forming cross sections to stop getting stuck when sliding against 331 | for i in range(0, len(positions), 3): 332 | x = positions[i + 0] 333 | y = positions[i + 1] 334 | z = positions[i + 2] 335 | 336 | direction = int(y) 337 | if direction: 338 | self.aabb_walls.append(PWWall(glm.vec2(x - 0.1, z - 1.2 + tolerance), glm.vec2(0.2, 2.4 - tolerance * 2.0))) 339 | else: 340 | self.aabb_walls.append(PWWall(glm.vec2(x - 1.2 + tolerance, z - 0.1), glm.vec2(2.4 - tolerance * 2.0, 0.2))) 341 | 342 | # Store instance count 343 | self.walls.count = int(len(positions) / 3) 344 | 345 | # -------- Feed data to instance buffer 346 | 347 | self.walls.data = glGenBuffers(1) 348 | glBindBuffer(GL_ARRAY_BUFFER, self.walls.data) 349 | glBufferData(GL_ARRAY_BUFFER, positions, GL_STATIC_DRAW) 350 | 351 | stride = 3 352 | glEnableVertexAttribArray(3) 353 | glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 354 | 355 | # 356 | glVertexAttribDivisor(3, 1) 357 | 358 | 359 | def __createTrimsGeom(self): 360 | self.trims.vao = glGenVertexArrays(1) 361 | glBindVertexArray(self.trims.vao) 362 | 363 | # Position(3), Normal(3), Texture(2) == stride 364 | vertices = np.array([-0.1, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 365 | 0.1, 2.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 366 | -0.1, 2.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 367 | 368 | -0.1, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 369 | 0.1, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 370 | 0.1, 2.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 371 | 372 | 373 | -0.1, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 374 | -0.1, 2.0, 1.0, 0.0, 0.0, -1.0, 0.0, 1.0, 375 | 0.1, 2.0, 1.0, 0.0, 0.0, -1.0, 1.0, 1.0, 376 | 377 | -0.1, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 378 | 0.1, 2.0, 1.0, 0.0, 0.0, -1.0, 1.0, 1.0, 379 | 0.1, 0.0, 1.0, 0.0, 0.0, -1.0, 1.0, 0.0, 380 | 381 | 382 | -0.1, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 383 | 0.1, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 384 | -0.1, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 385 | 386 | -0.1, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 387 | 0.1, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 388 | 0.1, 0.0, -1.0, 0.0, 1.0, 0.0, 1.0, 1.0], dtype='float32') 389 | 390 | 391 | self.trims.vbo = glGenBuffers(1) 392 | glBindBuffer(GL_ARRAY_BUFFER, self.trims.vbo) 393 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) 394 | 395 | stride = 8 396 | glEnableVertexAttribArray(0) 397 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 398 | 399 | n_offset = 3 400 | glEnableVertexAttribArray(1) 401 | glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * n_offset, ctypes.c_void_p)) 402 | 403 | uv_offset = 6 404 | glEnableVertexAttribArray(2) 405 | glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * uv_offset, ctypes.c_void_p)) 406 | 407 | # 408 | glVertexAttribDivisor(0, 0) 409 | glVertexAttribDivisor(1, 0) 410 | glVertexAttribDivisor(2, 0) 411 | 412 | # -------- Build instance matrix (not mat4!) 413 | 414 | positions = np.array(self.maze.o_trims, dtype='float32') 415 | 416 | # Store instance count 417 | self.trims.count = int(len(positions) / 3) 418 | 419 | # -------- Feed data to instance buffer 420 | 421 | self.trims.data = glGenBuffers(1) 422 | glBindBuffer(GL_ARRAY_BUFFER, self.trims.data) 423 | glBufferData(GL_ARRAY_BUFFER, positions, GL_STATIC_DRAW) 424 | 425 | stride = 3 426 | glEnableVertexAttribArray(3) 427 | glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 428 | 429 | # 430 | glVertexAttribDivisor(3, 1) 431 | 432 | 433 | def __renderFloor(self, shader, depth_only): 434 | if not depth_only: 435 | glActiveTexture(GL_TEXTURE0) 436 | glBindTexture(GL_TEXTURE_2D, PWTextures.getTexture2D("floor_01").getTexture()) 437 | 438 | glUniform2f(shader.texture_scale, 2.0, 2.0) 439 | 440 | glBindVertexArray(self.floors.vao) 441 | glDrawArraysInstanced(GL_TRIANGLES, 0, 3 * 2, self.floors.count) 442 | 443 | 444 | def __renderWalls(self, shader, depth_only): 445 | if not depth_only: 446 | glActiveTexture(GL_TEXTURE0) 447 | glBindTexture(GL_TEXTURE_2D, PWTextures.getTexture2D("wall_01").getTexture()) 448 | 449 | glUniform2f(shader.texture_scale, 1.5, 1.5) 450 | 451 | glBindVertexArray(self.walls.vao) 452 | glDrawArraysInstanced(GL_TRIANGLES, 0, 3 * 4, self.walls.count) 453 | 454 | # -------- Debug stuff 455 | 456 | #for wall in self.aabb_walls: 457 | # wall.debugDraw() 458 | 459 | 460 | def __renderTrims(self, shader, depth_only): 461 | if not depth_only: 462 | glActiveTexture(GL_TEXTURE0) 463 | glBindTexture(GL_TEXTURE_2D, PWTextures.getTexture2D("trim_01").getTexture()) 464 | 465 | glUniform2f(shader.texture_scale, 1.0, 2.5) 466 | 467 | glBindVertexArray(self.trims.vao) 468 | glDrawArraysInstanced(GL_TRIANGLES, 0, 3 * 6, self.trims.count) 469 | 470 | 471 | def renderMaze(self, camera, depth_only=False, shadow_mapper=None): 472 | shader = None 473 | 474 | # depth shader should be active before making this call 475 | if not depth_only: 476 | shader = PWShaders.getShader(ShaderTypes.WORLD_SHADER) 477 | glUseProgram(shader.shader) 478 | 479 | glUniformMatrix4fv(shader.proj_view, 1, GL_FALSE, camera.getProjectionView()) 480 | glUniformMatrix4fv(shader.light_proj_view, 1, GL_FALSE, shadow_mapper.getProjectionView()) 481 | 482 | light_direction = shadow_mapper.getLightDirection() 483 | glUniform3f(shader.light_direction, light_direction.x, light_direction.y, light_direction.z) 484 | 485 | glActiveTexture(GL_TEXTURE1) 486 | glBindTexture(GL_TEXTURE_2D, shadow_mapper.getDepthMap()) 487 | 488 | # -------- 489 | 490 | self.__renderFloor(shader, depth_only) 491 | self.__renderWalls(shader, depth_only) 492 | self.__renderTrims(shader, depth_only) 493 | 494 | 495 | # Generate 2D debug view of the maze 496 | if __name__ == "__main__": 497 | os.environ['SDL_VIDEO_CENTERED'] = '1' 498 | 499 | pygame.init() 500 | screen = pygame.display.set_mode((512, 512)) 501 | 502 | clock = pygame.time.Clock() 503 | 504 | # -------- 505 | 506 | generator = PWMazeGenerator(16, 16) 507 | while(not generator.stepMaze()): 508 | pass 509 | 510 | while 1: 511 | delta = clock.tick(8192) / 1000.0 512 | seconds = pygame.time.get_ticks() / 1000.0 513 | 514 | screen.fill((0x0, 0x0, 0x0)) 515 | 516 | for event in pygame.event.get(): 517 | if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE): 518 | pygame.quit() 519 | sys.exit() 520 | 521 | generator.render(screen) 522 | 523 | pygame.display.flip() 524 | 525 | 526 | -------------------------------------------------------------------------------- /pymaze/main.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import sys 3 | import os 4 | import datetime 5 | 6 | 7 | # TODO 8 | # - Optimize collision check (Right now it just tests the collisions against all walls) 9 | # - Code could use some refactoring 10 | 11 | 12 | 13 | # Check to make sure user has the all necessary libraries 14 | # and install instructions 15 | 16 | try: 17 | import pygame 18 | from pygame.locals import * 19 | except ImportError: 20 | print("Run 'pip install pygame'") 21 | exit() 22 | 23 | try: 24 | from OpenGL.GL import * 25 | except ImportError: 26 | print("Run 'pip install PyOpenGL PyOpenGL_accelerate'") 27 | exit() 28 | 29 | try: 30 | import glm 31 | except ImportError: 32 | print("Run 'pip install PyGLM'") 33 | exit() 34 | 35 | try: 36 | import numpy as np 37 | except ImportError: 38 | print("Run 'pip install numpy'") 39 | exit() 40 | 41 | # End of check 42 | 43 | from constants import * 44 | from camera import * 45 | from textures import * 46 | from shaders import * 47 | from labyrinth import * 48 | from player import * 49 | from debug import * 50 | from skybox import * 51 | from post_processing import * 52 | from end_portal import * 53 | 54 | 55 | class PWMain(PWConstants): 56 | def __init__(self): 57 | os.environ['SDL_VIDEO_CENTERED'] = '1' 58 | 59 | pygame.init() 60 | 61 | # TODO: Need to add support for multisamplebuffers in the framebuffer texture attachments 62 | # otherwise the msaa wont work 63 | #pygame.display.gl_set_attribute(GL_MULTISAMPLEBUFFERS, 1) 64 | #pygame.display.gl_set_attribute(GL_MULTISAMPLESAMPLES, 2) # MSAA 65 | 66 | pygame.display.set_mode(self.d_resolution, DOUBLEBUF | OPENGL) 67 | 68 | self.clock = pygame.time.Clock() 69 | 70 | # -------- GL Stuff 71 | 72 | glEnable(GL_DEPTH_TEST) 73 | glDepthFunc(GL_LEQUAL) 74 | 75 | glEnable(GL_CULL_FACE) 76 | glCullFace(GL_BACK) 77 | 78 | glEnable(GL_MULTISAMPLE) 79 | glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); 80 | 81 | # -------- Data 82 | 83 | PWShaders.parseShaders() 84 | PWTextures.parseTextures() 85 | PWDebug.initDebugger() 86 | PWPostProcessing.parseShaders() 87 | 88 | # -------- Common 89 | 90 | self.maze = PWMaze(16, 16) 91 | self.skybox = PWSkybox() 92 | self.camera = PWCamera() 93 | self.player = PWPlayer(glm.vec2(0, 0)) 94 | self.post = PWPostProcessing() 95 | self.portal = PWPortal() 96 | 97 | 98 | # -------- Render world to shadow map 99 | 100 | # Since the world is mostly static, we can render the shadow map once 101 | # If you want to render the shadow map every frame, move this in to the loop 102 | # and set all functions that render something between the begin/end functions 103 | 104 | self.skybox.skybox_shadow.begin() 105 | 106 | self.maze.renderMaze(self.camera, True) 107 | 108 | self.skybox.skybox_shadow.end() 109 | 110 | # -------- 111 | 112 | found_portal = False 113 | self.time_start = pygame.time.get_ticks() 114 | self.final_time = 0 115 | 116 | 117 | def mainloop(self): 118 | while 1: 119 | delta = self.clock.tick(self.d_max_fps) / 1000.0 120 | seconds = pygame.time.get_ticks() / 1000.0 121 | 122 | glClearColor(0.0, 0.0, 0.0, 1.0) 123 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 124 | 125 | for event in pygame.event.get(): 126 | if (event.type == QUIT) or (event.type == KEYUP and event.key == K_ESCAPE): 127 | pygame.quit() 128 | sys.exit() 129 | 130 | if (event.type == KEYUP) and (event.key == K_LEFT): 131 | PPostTypes.changeShader(-1) 132 | 133 | if (event.type == KEYUP) and (event.key == K_RIGHT): 134 | PPostTypes.changeShader(1) 135 | 136 | # -------- 137 | 138 | self.player.update(delta, self.camera, self.maze.aabb_walls) 139 | self.camera.updateCamera(delta, self.player.getPosition()) 140 | 141 | # -------- 142 | 143 | # All draw commands should go between the begin/end clause for them to appear on the framebuffer textures 144 | 145 | self.post.begin() 146 | 147 | self.maze.renderMaze(self.camera, False, self.skybox.skybox_shadow) 148 | self.skybox.renderSkybox(self.camera) 149 | 150 | # Draw all debug lines last 151 | PWDebug.drawDebug(self.camera) 152 | 153 | self.post.end(seconds, self.camera) 154 | 155 | found_portal = self.portal.render(self.camera, seconds, self.post.getColorAttachment(), self.post.getDepthAttachment()) 156 | 157 | if found_portal and not self.final_time: 158 | self.final_time = pygame.time.get_ticks() - self.time_start 159 | seconds = int(self.final_time / 1000.0) 160 | print("Solved in: ({0})!".format(str(datetime.timedelta(seconds=seconds)))) 161 | 162 | pygame.display.set_caption("FPS: {0:.2f}".format(self.clock.get_fps())) 163 | pygame.display.flip() 164 | 165 | 166 | if __name__ == "__main__": 167 | PWMain().mainloop() 168 | -------------------------------------------------------------------------------- /pymaze/player.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | import glm 4 | 5 | from constants import * 6 | from debug import * 7 | from entities import * 8 | 9 | 10 | class PWPlayerAction: 11 | ACTION_NONE = 0 12 | ACTION_WALK = 1 13 | ACTION_RUN = 2 14 | ACTION_JUMP = 3 15 | ACTION_CROUCH = 4 16 | 17 | 18 | class PWPlayer(PWConstants, PWPlayerAction): 19 | def __init__(self, position): 20 | self.bbox_size = 0.25 21 | 22 | self.pos = glm.vec2(position.x, position.y) - self.bbox_size / 2.0 23 | self.old_pos = glm.vec2(position.x, position.y) - self.bbox_size / 2.0 24 | 25 | self.bbox = PWBBox(glm.vec2(self.bbox_size), glm.vec2(self.pos.x, self.pos.y)) 26 | self.bbox_advance = PWBBox(glm.vec2(self.bbox_size), glm.vec2(self.pos.x, self.pos.y)) 27 | 28 | self.pos_ud_v = 0.0 # Velocity 29 | self.pos_ud = 0.0 # Up/Down position (tricks) 30 | self.action = self.ACTION_NONE 31 | 32 | 33 | def getCurrentAction(self): 34 | return self.action 35 | 36 | 37 | def getPosition(self): 38 | position = self.pos + self.bbox_size / 2.0 39 | return glm.vec3(position.x, self.pos_ud, position.y) 40 | 41 | 42 | def __checkCollisionX(self, move_direction, vector, wall): 43 | if move_direction.x == 0: 44 | return 45 | 46 | self.bbox_advance.updatePos(self.old_pos.x, self.old_pos.y) 47 | self.bbox_advance.pos.x += vector 48 | 49 | if self.bbox_advance.colliderect(wall): 50 | if move_direction.x > 0: 51 | self.pos.x = wall.pos.x - self.bbox.wh.x 52 | else: 53 | self.pos.x = wall.pos.x + wall.bbox.wh.x 54 | 55 | 56 | def __checkCollisionY(self, move_direction, vector, wall): 57 | if move_direction.z == 0: 58 | return 59 | 60 | self.bbox_advance.updatePos(self.old_pos.x, self.old_pos.y) 61 | self.bbox_advance.pos.y += vector 62 | 63 | if self.bbox_advance.colliderect(wall): 64 | if move_direction.z > 0: 65 | self.pos.y = wall.pos.y - self.bbox.wh.y 66 | else: 67 | self.pos.y = wall.pos.y + wall.bbox.wh.y 68 | 69 | 70 | def checkCollision(self, move_direction, walls): 71 | for wall in walls: 72 | if self.bbox.colliderect(wall): 73 | length = glm.length(self.pos - self.old_pos) 74 | offset = glm.normalize(self.pos - self.old_pos) 75 | 76 | self.__checkCollisionX(move_direction, offset.x * length, wall) 77 | self.__checkCollisionY(move_direction, offset.y * length, wall) 78 | 79 | 80 | # TODO: Add crouching 81 | def handleSpecialActions(self, delta): 82 | keys = pygame.key.get_pressed() 83 | 84 | if keys[K_SPACE] and self.action == self.ACTION_NONE: 85 | self.action = self.ACTION_JUMP 86 | self.pos_ud_v += self.p_jump_vel 87 | 88 | # Player is in air 89 | if self.action == self.ACTION_JUMP: 90 | self.pos_ud_v -= self.d_gravity * delta 91 | self.pos_ud += self.pos_ud_v * delta 92 | 93 | # Player is touching the ground. Make sure player doesn't fall through the floor. 94 | if self.pos_ud <= 0.0: 95 | self.pos_ud = 0.0 96 | self.pos_ud_v = 0.0 97 | self.action = self.ACTION_NONE 98 | 99 | 100 | 101 | def getMovementDirection(self, camera): 102 | yaw = glm.radians(-camera.yaw) 103 | 104 | cam_cos = glm.cos(yaw) 105 | cam_sin = glm.sin(yaw) 106 | 107 | keys = pygame.key.get_pressed() 108 | move_direction = glm.vec3(0.0) 109 | 110 | if keys[K_w]: 111 | move_direction -= glm.vec3(-cam_cos, 0.0, cam_sin) 112 | 113 | if keys[K_s]: 114 | move_direction += glm.vec3(-cam_cos, 0.0, cam_sin) 115 | 116 | if keys[K_d]: 117 | move_direction += glm.vec3(cam_sin, 0.0, cam_cos) 118 | 119 | if keys[K_a]: 120 | move_direction -= glm.vec3(cam_sin, 0.0, cam_cos) 121 | 122 | # Normalize the direction, so going diagonally wont result in faster movement. 123 | if glm.length(move_direction) > 0: 124 | move_direction = glm.normalize(move_direction) 125 | 126 | return move_direction 127 | 128 | 129 | # Draws player bounding box 130 | def debugDraw(self): 131 | tl = glm.vec3(self.pos.x, 0.0, self.pos.y) 132 | tr = glm.vec3(self.pos.x + self.bbox.wh.x, 0.0, self.pos.y + self.bbox.wh.y) 133 | 134 | PWDebug.drawLine(tl, tl + glm.vec3(self.bbox.wh.x, 0.0, 0.0)) 135 | PWDebug.drawLine(tl, tl + glm.vec3(0.0, 0.0, self.bbox.wh.y)) 136 | 137 | PWDebug.drawLine(tr, tr - glm.vec3(self.bbox.wh.x, 0.0, 0.0)) 138 | PWDebug.drawLine(tr, tr - glm.vec3(0.0, 0.0, self.bbox.wh.y)) 139 | 140 | 141 | # TODO: Add smoother movement 142 | def update(self, delta, camera, walls): 143 | move_direction = self.getMovementDirection(camera) 144 | 145 | self.old_pos.x = self.pos.x 146 | self.old_pos.y = self.pos.y 147 | 148 | self.pos.x += move_direction.x * self.p_speed * delta 149 | self.pos.y += move_direction.z * self.p_speed * delta 150 | 151 | self.bbox.updatePos(self.pos.x, self.pos.y) 152 | #self.debugDraw() 153 | 154 | self.checkCollision(move_direction, walls) 155 | 156 | # -------- 157 | 158 | self.handleSpecialActions(delta) # These are mostly camera illusion tricks 159 | 160 | 161 | if __name__ == "__main__": 162 | pass 163 | -------------------------------------------------------------------------------- /pymaze/post_processing.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | from OpenGL.GL import * 4 | 5 | from constants import * 6 | from shaders import * 7 | from textures import * 8 | 9 | 10 | class PPostTypes: 11 | PPOST_DEFAULT = 512 12 | PPOST_FISHEYE = 513 13 | PPOST_RADIALB = 514 14 | PPOST_CROSSHA = 515 15 | PPOST_THIRD3D = 516 16 | 17 | # 18 | current_shader = 0 19 | 20 | @classmethod 21 | def changeShader(cls, key_change): 22 | all_count = len(cls.all_shaders) 23 | cls.current_shader += key_change 24 | cls.current_shader %= all_count 25 | 26 | print(cls.getCurrentShaderID()) 27 | 28 | @classmethod 29 | def getCurrentShaderID(cls): 30 | return cls.PPOST_DEFAULT + cls.current_shader 31 | 32 | 33 | # Build list ordered list of all shaders and feed it back to the class 34 | __filtered = {k:v for k, v in PPostTypes.__dict__.items() if k.startswith("PPOST")} 35 | PPostTypes.all_shaders = sorted([x for x in __filtered.values()]) 36 | 37 | 38 | # 39 | class PWPostProcessing(PWConstants): 40 | def __init__(self): 41 | self.buffer = 0 42 | self.color_texture = 0 43 | self.depth_texture = 0 44 | self.__createPassBuffer() 45 | 46 | # -------- 47 | 48 | self.quad = PWVaoData() 49 | self.__createPassQuad() 50 | 51 | 52 | def getColorAttachment(self): 53 | return self.color_texture; 54 | 55 | 56 | def getDepthAttachment(self): 57 | return self.depth_texture; 58 | 59 | 60 | def __createPassBuffer(self): 61 | self.buffer = glGenFramebuffers(1) 62 | glBindFramebuffer(GL_FRAMEBUFFER, self.buffer) 63 | 64 | # -------- Add color attachment 65 | 66 | self.color_texture = glGenTextures(1) 67 | glBindTexture(GL_TEXTURE_2D, self.color_texture) 68 | 69 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, self.d_resolution.x, self.d_resolution.y, 0, GL_RGB, GL_UNSIGNED_BYTE, None) 70 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) 71 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) 72 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self.color_texture, 0) 73 | 74 | # -------- Add depth attachment 75 | 76 | self.depth_texture = glGenTextures(1) 77 | glBindTexture(GL_TEXTURE_2D, self.depth_texture) 78 | 79 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, self.d_resolution.x, self.d_resolution.y, 0, GL_DEPTH_COMPONENT, GL_FLOAT, None) 80 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) 81 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) 82 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, self.depth_texture, 0) 83 | 84 | # -------- 85 | 86 | if glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE: 87 | print("Framebuffer Error!") 88 | # TODO: Make GL utility functions 89 | 90 | 91 | def __createPassQuad(self): 92 | self.quad.vao = glGenVertexArrays(1) 93 | glBindVertexArray(self.quad.vao) 94 | 95 | # Position(3), Texture(2) 96 | vertices = np.array([-1.0, 1.0, 0.0, 1.0, 97 | -1.0, -1.0, 0.0, 0.0, 98 | 1.0, -1.0, 1.0, 0.0, 99 | 100 | -1.0, 1.0, 0.0, 1.0, 101 | 1.0, -1.0, 1.0, 0.0, 102 | 1.0, 1.0, 1.0, 1.0], dtype='float32') 103 | 104 | self.quad.vbo = glGenBuffers(1) 105 | glBindBuffer(GL_ARRAY_BUFFER, self.quad.vbo) 106 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) 107 | 108 | stride = 4 109 | glEnableVertexAttribArray(0) 110 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 111 | 112 | uv_offset = 2 113 | glEnableVertexAttribArray(1) 114 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * uv_offset, ctypes.c_void_p)) 115 | 116 | 117 | def begin(self): 118 | # Bind out framebuffer to write all color/depth info into to it 119 | glBindFramebuffer(GL_FRAMEBUFFER, self.buffer) 120 | 121 | # Clear it 122 | glClearColor(0.0, 0.0, 0.0, 1.0) 123 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 124 | 125 | 126 | def end(self, seconds, camera): 127 | # Reset back to default buffer 128 | glBindFramebuffer(GL_FRAMEBUFFER, 0) 129 | 130 | # Render the fullscreen quad with the frame buffer attachments 131 | self.renderQuad(seconds, camera) 132 | 133 | 134 | def setExtraUniforms(self, shader, shader_type, seconds): 135 | if shader_type == PPostTypes.PPOST_THIRD3D: 136 | proj = glm.perspective(glm.radians(self.c_fov), self.c_aspect, self.c_near, self.c_far) 137 | view = glm.lookAt(glm.vec3(0.0, 0.0, 1.0), glm.vec3(0.0), glm.vec3(0.0, 1.0, 0.0)) 138 | 139 | proj_view = np.array(proj * view, dtype='float32') 140 | glUniformMatrix4fv(shader.proj_view, 1, GL_FALSE, proj_view) 141 | 142 | model = glm.mat4(1.0) 143 | model = glm.translate(model, glm.vec3(0.0, 0.0, -3.0)) 144 | model = glm.rotate(model, glm.radians(60.0), glm.vec3(0.0, 1.0, 0.0)) 145 | 146 | glUniformMatrix4fv(shader.model, 1, GL_FALSE, np.array(model, dtype='float32')) 147 | 148 | # Add more if/elifs if needed 149 | 150 | 151 | 152 | def renderQuad(self, seconds, camera): 153 | shader_type = PPostTypes.getCurrentShaderID() 154 | 155 | shader = PWShaders.getShader(shader_type) 156 | glUseProgram(shader.shader) 157 | 158 | self.setExtraUniforms(shader, shader_type, seconds) 159 | 160 | # Feed some funky stuff for the shaders 161 | glUniform1f(shader.seconds, seconds) 162 | glUniform2f(shader.resolution, self.d_resolution.x, self.d_resolution.y) 163 | 164 | # -------- 165 | 166 | glDisable(GL_DEPTH_TEST) 167 | 168 | glActiveTexture(GL_TEXTURE0) 169 | glBindTexture(GL_TEXTURE_2D, self.color_texture) 170 | 171 | glActiveTexture(GL_TEXTURE1) 172 | glBindTexture(GL_TEXTURE_2D, self.depth_texture) 173 | 174 | glBindVertexArray(self.quad.vao) 175 | glDrawArrays(GL_TRIANGLES, 0, 6) 176 | 177 | glEnable(GL_DEPTH_TEST) 178 | 179 | 180 | # All post processing shaders share the same common uniforms 181 | @classmethod 182 | def __fetchUniformLocations(cls, shader): 183 | glUseProgram(shader.shader) 184 | 185 | # 186 | shader.seconds = glGetUniformLocation(shader.shader, "uSeconds") 187 | shader.resolution = glGetUniformLocation(shader.shader, "uResolution") 188 | 189 | # 190 | glUniform1i(glGetUniformLocation(shader.shader, "colorTexture"), 0) 191 | glUniform1i(glGetUniformLocation(shader.shader, "depthTexture"), 1) 192 | 193 | 194 | @classmethod 195 | def parseShaders(cls): 196 | root_path = "shaders/post_processing/" 197 | 198 | # -------- Default passthrough 199 | 200 | PWShaders.loadShader(PPostTypes.PPOST_DEFAULT, root_path + "post_default.vert", root_path + "post_default.frag") 201 | cls.__fetchUniformLocations(PWShaders.getShader(PPostTypes.PPOST_DEFAULT)) 202 | 203 | # -------- 204 | 205 | PWShaders.loadShader(PPostTypes.PPOST_FISHEYE, root_path + "post_fisheye.vert", root_path + "post_fisheye.frag") 206 | cls.__fetchUniformLocations(PWShaders.getShader(PPostTypes.PPOST_FISHEYE)) 207 | 208 | # -------- 209 | 210 | PWShaders.loadShader(PPostTypes.PPOST_RADIALB, root_path + "post_radialb.vert", root_path + "post_radialb.frag") 211 | cls.__fetchUniformLocations(PWShaders.getShader(PPostTypes.PPOST_RADIALB)) 212 | 213 | # -------- 214 | 215 | PWShaders.loadShader(PPostTypes.PPOST_CROSSHA, root_path + "post_crossha.vert", root_path + "post_crossha.frag") 216 | cls.__fetchUniformLocations(PWShaders.getShader(PPostTypes.PPOST_CROSSHA)) 217 | 218 | # -------- 219 | 220 | PWShaders.loadShader(PPostTypes.PPOST_THIRD3D, root_path + "post_third3d.vert", root_path + "post_third3d.frag") 221 | shader = PWShaders.getShader(PPostTypes.PPOST_THIRD3D) 222 | cls.__fetchUniformLocations(shader) 223 | shader.proj_view = glGetUniformLocation(shader.shader, "projView") 224 | shader.model = glGetUniformLocation(shader.shader, "model") 225 | 226 | # -------- 227 | 228 | -------------------------------------------------------------------------------- /pymaze/shaders.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | import sys 3 | import glm 4 | 5 | from OpenGL.GL import * 6 | from OpenGL.GL import shaders 7 | 8 | 9 | from constants import * 10 | 11 | 12 | class ShaderTypes: 13 | WORLD_SHADER = 0 14 | DEBUG_SHADER = 1 15 | SKYBOX_SHADER = 2 16 | SHADOW_SHADER = 3 17 | SDEBUG_SHADER = 4 18 | PORTAL_SHADER = 5 19 | 20 | 21 | class PWShader(object): 22 | def __init__(self, shader): 23 | self.shader = shader 24 | 25 | 26 | class PWShaders(PWConstants): 27 | shaders = {} 28 | 29 | @classmethod 30 | def __parseShader(cls, shader_path, shader_type): 31 | shader_raw = "" 32 | with open(shader_path, 'r') as file: 33 | shader_raw = file.read() 34 | 35 | try: 36 | return shaders.compileShader(shader_raw, shader_type) 37 | except shaders.ShaderCompilationError as e: 38 | # TODO: Add nicer output for error messages. 39 | print(e) 40 | 41 | pygame.quit() 42 | sys.exit() 43 | 44 | 45 | @classmethod 46 | def loadShader(cls, shader_id, vert, frag): 47 | v_shader = cls.__parseShader(vert, GL_VERTEX_SHADER) 48 | v_fragment = cls.__parseShader(frag, GL_FRAGMENT_SHADER) 49 | 50 | cls.shaders[shader_id] = PWShader(shaders.compileProgram(v_shader, v_fragment)) 51 | 52 | 53 | @classmethod 54 | def getShader(cls, id): 55 | return cls.shaders[id] 56 | 57 | 58 | @classmethod 59 | def parseShaders(cls): 60 | cls.loadShader(ShaderTypes.WORLD_SHADER, "shaders/world_geom.vert", "shaders/world_geom.frag") 61 | shader = cls.getShader(ShaderTypes.WORLD_SHADER) 62 | glUseProgram(shader.shader) 63 | shader.proj_view = glGetUniformLocation(shader.shader, "projView") 64 | shader.texture_scale = glGetUniformLocation(shader.shader, "textureScale") 65 | shader.light_proj_view = glGetUniformLocation(shader.shader, "lightProjView") 66 | shader.light_direction = glGetUniformLocation(shader.shader, "lightDir") 67 | 68 | glUniform1i(glGetUniformLocation(shader.shader, "diffuse" ), 0) 69 | glUniform1i(glGetUniformLocation(shader.shader, "shadowMap"), 1) 70 | 71 | 72 | # ---------------- 73 | 74 | 75 | cls.loadShader(ShaderTypes.DEBUG_SHADER, "shaders/debug_line.vert", "shaders/debug_line.frag") 76 | shader = cls.getShader(ShaderTypes.DEBUG_SHADER) 77 | glUseProgram(shader.shader) 78 | shader.proj_view = glGetUniformLocation(shader.shader, "projView") 79 | 80 | 81 | # ---------------- 82 | 83 | 84 | cls.loadShader(ShaderTypes.SKYBOX_SHADER, "shaders/skybox.vert", "shaders/skybox.frag") 85 | shader = cls.getShader(ShaderTypes.SKYBOX_SHADER) 86 | glUseProgram(shader.shader) 87 | shader.proj_view = glGetUniformLocation(shader.shader, "projView") 88 | glUniform1i(glGetUniformLocation(shader.shader, "skybox"), 0) 89 | 90 | 91 | # ---------------- 92 | 93 | 94 | cls.loadShader(ShaderTypes.SHADOW_SHADER, "shaders/shadow_mapping.vert", "shaders/shadow_mapping.frag") 95 | shader = cls.getShader(ShaderTypes.SHADOW_SHADER) 96 | glUseProgram(shader.shader) 97 | shader.proj_view = glGetUniformLocation(shader.shader, "projView") 98 | 99 | 100 | # ---------------- 101 | 102 | 103 | cls.loadShader(ShaderTypes.SDEBUG_SHADER, "shaders/shadow_debugger.vert", "shaders/shadow_debugger.frag") 104 | shader = cls.getShader(ShaderTypes.SDEBUG_SHADER) 105 | glUseProgram(shader.shader) 106 | 107 | 108 | # ---------------- 109 | 110 | 111 | cls.loadShader(ShaderTypes.PORTAL_SHADER, "shaders/portal.vert", "shaders/portal.frag") 112 | shader = cls.getShader(ShaderTypes.PORTAL_SHADER) 113 | glUseProgram(shader.shader) 114 | shader.proj_view = glGetUniformLocation(shader.shader, "projView") 115 | shader.model = glGetUniformLocation(shader.shader, "model") 116 | shader.view = glGetUniformLocation(shader.shader, "view") 117 | shader.seconds = glGetUniformLocation(shader.shader, "uSeconds") 118 | shader.resolution = glGetUniformLocation(shader.shader, "uResolution") 119 | 120 | glUniform1i(glGetUniformLocation(shader.shader, "colorTexture"), 0) 121 | glUniform1i(glGetUniformLocation(shader.shader, "depthTexture"), 1) -------------------------------------------------------------------------------- /pymaze/shaders/debug_line.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 fragColor; 4 | 5 | void main() 6 | { 7 | fragColor = vec4(1.0f); 8 | } -------------------------------------------------------------------------------- /pymaze/shaders/debug_line.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec3 vPos; 4 | 5 | uniform mat4 projView; 6 | 7 | void main() 8 | { 9 | gl_Position = projView * vec4(vPos, 1.0f); 10 | } -------------------------------------------------------------------------------- /pymaze/shaders/portal.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | const float PI = 3.1415926535f; 4 | 5 | out vec4 fragColor; 6 | 7 | in vec2 texCoords; 8 | 9 | uniform sampler2D colorTexture; 10 | uniform sampler2D depthTexture; 11 | 12 | uniform float uSeconds; 13 | uniform vec2 uResolution; 14 | 15 | void main() 16 | { 17 | vec2 m = 1.0f / uResolution; 18 | vec2 c = gl_FragCoord.xy; 19 | 20 | float lastDepth = texture2D(depthTexture, m * c).r; 21 | float currentDepth = gl_FragCoord.z; 22 | 23 | // We need to do depth testing manually, as we are applying models top of post processing screen. 24 | if (currentDepth > lastDepth){ 25 | discard; 26 | } 27 | 28 | vec2 screenSpaceUV = gl_FragCoord.xy / uResolution; 29 | vec3 colorUV = texture2D(colorTexture, screenSpaceUV).rgb; 30 | 31 | vec3 color = colorUV; 32 | 33 | // -------- 34 | 35 | float size = 0.45f; 36 | vec2 center = vec2(0.5f) + vec2(0.02f * cos(uSeconds), 0.02f * sin(uSeconds)); 37 | float dist = length(center - texCoords); 38 | 39 | if (dist < size){ 40 | float ex = (1.0f / size * dist); 41 | color = texture2D(colorTexture, screenSpaceUV + ex + (0.02f * sin(uSeconds))).rgb; 42 | } 43 | 44 | color *= smoothstep(colorUV * vec3(0.0f), vec3(1.0f), vec3(dist * 4.0f)); 45 | 46 | fragColor = vec4(color, 1.0f); 47 | } -------------------------------------------------------------------------------- /pymaze/shaders/portal.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec3 aPos; 4 | layout(location = 1) in vec2 aTexCoords; 5 | 6 | out vec2 texCoords; 7 | 8 | uniform mat4 projView; 9 | uniform mat4 view; 10 | uniform mat4 model; 11 | 12 | void main() 13 | { 14 | mat4 view_inv = inverse(view); 15 | vec3 center = model[3].xyz; 16 | 17 | vec3 cam_right = view_inv[0].xyz; 18 | vec3 cam_up = view_inv[1].xyz; 19 | 20 | vec3 pos = center + (cam_right * aPos.x) + (cam_up * aPos.y); 21 | gl_Position = projView * model * vec4(pos, 1.0f); 22 | 23 | texCoords = aTexCoords; 24 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | const float PI = 3.1415926535f; 4 | 5 | out vec4 fragColor; 6 | 7 | in vec2 texCoords; 8 | 9 | uniform sampler2D colorTexture; 10 | uniform sampler2D depthTexture; 11 | 12 | uniform float uSeconds; 13 | uniform vec2 uResolution; 14 | 15 | /* 16 | Inbuilt - 17 | "gl_FragCoord" = Pixel coordinate(vec2) between (0 - uResolution) from bottomleft 18 | 19 | 20 | Uniforms - 21 | "uResolution" = Display resolution 22 | "uSeconds" = Game running time 23 | */ 24 | 25 | 26 | // Get depth (Linearized) 27 | float getDepth(vec2 uv) 28 | { 29 | // TODO: Bring these via uniforms? 30 | // Right now they need to match with the values in the "c_near" and "c_far" constants in "constants.py" 31 | float near = 0.01f; 32 | float far = 100.0f; 33 | 34 | // Linearize the depth 35 | float depth = texture2D(depthTexture, uv).x; 36 | return (2.0f * near) / (far + near - depth * (far - near)); 37 | } 38 | 39 | 40 | // Get color 41 | vec3 getColor(vec2 uv) 42 | { 43 | return texture2D(colorTexture, uv).rgb; 44 | } 45 | 46 | //#define T texture2D(colorTexture, 0.5f + (p.xy *= 0.992)) 47 | 48 | /* 49 | const float stitching_size = 16.0f; 50 | const int invert = 0; 51 | 52 | vec4 PostFX(sampler2D tex, vec2 uv, float time) 53 | { 54 | float rt_w = uResolution.x; 55 | float rt_h = uResolution.y; 56 | 57 | vec4 c = vec4(0.0); 58 | 59 | float size = stitching_size; 60 | vec2 cPos = uv * vec2(rt_w, rt_h); 61 | 62 | vec2 tlPos = floor(cPos / vec2(size, size)); 63 | tlPos *= size; 64 | 65 | int remX = int(mod(cPos.x, size)); 66 | int remY = int(mod(cPos.y, size)); 67 | 68 | if (remX == 0 && remY == 0){ 69 | tlPos = cPos; 70 | } 71 | 72 | vec2 blPos = tlPos; 73 | blPos.y += (size - 1.0f); 74 | 75 | if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) 76 | { 77 | if (invert == 1){ 78 | c = vec4(0.2f, 0.15f, 0.05f, 1.0f); 79 | } 80 | else { 81 | c = texture2D(tex, tlPos * vec2(1.0f / rt_w, 1.0f / rt_h)) * 1.4f; 82 | } 83 | } 84 | else 85 | { 86 | if (invert == 1) { 87 | c = texture2D(tex, tlPos * vec2(1.0f / rt_w, 1.0f / rt_h)) * 1.4f; 88 | } 89 | else { 90 | c = vec4(0.0, 0.0, 0.0, 1.0); 91 | } 92 | } 93 | 94 | return c; 95 | } 96 | */ 97 | 98 | void main() 99 | { 100 | vec2 tex = texCoords; 101 | 102 | //float r = 0.025f * sin(uSeconds + 1.0f / uResolution.y * gl_FragCoord.y * 16.0f); 103 | //tex.x += r; 104 | 105 | float depth = getDepth(tex); 106 | vec3 color = getColor(tex); 107 | 108 | // -------- 109 | 110 | /* 111 | vec2 uv = texCoords; 112 | fragColor = PostFX(colorTexture, uv, uSeconds); 113 | */ 114 | 115 | /* 116 | float aperture = 180.0f; 117 | float apertureHalf = 0.5f * aperture * (PI / 180.0f); 118 | float maxFactor = sin(apertureHalf); 119 | 120 | vec2 uv; 121 | vec2 xy = 2.0f * texCoords.xy - 1.0f; 122 | xy.x *= uResolution.x / uResolution.y; 123 | 124 | float d = length(xy); 125 | 126 | if (d < (2.0f - maxFactor)) 127 | { 128 | d = length(xy * maxFactor); 129 | float z = sqrt(1.0f - d * d); 130 | float r = atan(d, z) / PI; 131 | float phi = atan(xy.y, xy.x); 132 | 133 | uv.x = r * cos(phi) + 0.5f; 134 | uv.y = r * sin(phi) + 0.5f; 135 | } 136 | else 137 | { 138 | uv = texCoords.xy; 139 | } 140 | 141 | vec4 c = texture2D(colorTexture, uv); 142 | fragColor = c; 143 | */ 144 | 145 | /* 146 | vec3 p = vec3(gl_FragCoord.xy / uResolution - 0.5f, 0.0f); 147 | vec3 o = T.rbb; 148 | for (float i=0.;i<100.;i++){ 149 | p.z += pow(max(0.0f, 0.5f - length(T.rg)), 2.0f) * exp(-i * .008f); 150 | } 151 | 152 | fragColor = vec4(o * o + p.z, 1.0f); 153 | */ 154 | 155 | fragColor = vec4(color, 1.0f); 156 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec2 aPos; 4 | layout (location = 1) in vec2 aTexCoords; 5 | 6 | out vec2 texCoords; 7 | 8 | /* 9 | vec2 rotate(vec2 v, float a) { 10 | float s = sin(a); 11 | float c = cos(a); 12 | mat2 m = mat2(c, -s, s, c); 13 | return m * v; 14 | } 15 | 16 | uniform float uSeconds; 17 | */ 18 | 19 | void main() 20 | { 21 | //gl_Position = vec4(rotate(aPos.xy, radians(uSeconds * 8.0f)), 0.0f, 1.0f); 22 | gl_Position = vec4(aPos.xy, 0.0f, 1.0f); 23 | texCoords = aTexCoords; 24 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_crossha.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | const float PI = 3.1415926535f; 4 | 5 | out vec4 fragColor; 6 | 7 | in vec2 texCoords; 8 | 9 | uniform sampler2D colorTexture; 10 | uniform sampler2D depthTexture; 11 | 12 | uniform float uSeconds; 13 | uniform vec2 uResolution; 14 | 15 | /* 16 | Inbuilt - 17 | "gl_FragCoord" = Pixel coordinate(vec2) between (0 - uResolution) from bottomleft 18 | 19 | 20 | Uniforms - 21 | "uResolution" = Display resolution 22 | "uSeconds" = Game running time 23 | */ 24 | 25 | 26 | // Get depth (Linearized) 27 | float getDepth(vec2 uv) 28 | { 29 | // TODO: Bring these via uniforms? 30 | // Right now they need to match with the values in the "c_near" and "c_far" constants in "constants.py" 31 | float near = 0.01f; 32 | float far = 100.0f; 33 | 34 | // Linearize the depth 35 | float depth = texture2D(depthTexture, uv).x; 36 | return (2.0f * near) / (far + near - depth * (far - near)); 37 | } 38 | 39 | 40 | // Get color 41 | vec3 getColor(vec2 uv) 42 | { 43 | return texture2D(colorTexture, uv).rgb; 44 | } 45 | 46 | 47 | const float stitching_size = 8.0f; 48 | const int invert = 0; 49 | 50 | vec4 PostFX(sampler2D tex, vec2 uv, float time) 51 | { 52 | float rt_w = uResolution.x; 53 | float rt_h = uResolution.y; 54 | 55 | vec4 c = vec4(0.0); 56 | 57 | float size = stitching_size; 58 | vec2 cPos = uv * vec2(rt_w, rt_h); 59 | 60 | vec2 tlPos = floor(cPos / vec2(size, size)); 61 | tlPos *= size; 62 | 63 | int remX = int(mod(cPos.x, size)); 64 | int remY = int(mod(cPos.y, size)); 65 | 66 | if (remX == 0 && remY == 0){ 67 | tlPos = cPos; 68 | } 69 | 70 | vec2 blPos = tlPos; 71 | blPos.y += (size - 1.0f); 72 | 73 | if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y))))) 74 | { 75 | if (invert == 1){ 76 | c = vec4(0.2f, 0.15f, 0.05f, 1.0f); 77 | } 78 | else { 79 | c = texture2D(tex, tlPos * vec2(1.0f / rt_w, 1.0f / rt_h)) * 1.4f; 80 | } 81 | } 82 | else 83 | { 84 | if (invert == 1) { 85 | c = texture2D(tex, tlPos * vec2(1.0f / rt_w, 1.0f / rt_h)) * 1.4f; 86 | } 87 | else { 88 | c = vec4(0.0, 0.0, 0.0, 1.0); 89 | } 90 | } 91 | 92 | return c; 93 | } 94 | 95 | 96 | void main() 97 | { 98 | vec2 tex = texCoords; 99 | 100 | 101 | float depth = getDepth(tex); 102 | vec3 color = getColor(tex); 103 | 104 | // -------- 105 | 106 | vec2 uv = texCoords; 107 | fragColor = PostFX(colorTexture, uv, uSeconds); 108 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_crossha.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec2 aPos; 4 | layout (location = 1) in vec2 aTexCoords; 5 | 6 | out vec2 texCoords; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4(aPos.xy, 0.0f, 1.0f); 11 | texCoords = aTexCoords; 12 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_default.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | const float PI = 3.1415926535f; 4 | 5 | out vec4 fragColor; 6 | 7 | in vec2 texCoords; 8 | 9 | uniform sampler2D colorTexture; 10 | uniform sampler2D depthTexture; 11 | 12 | uniform float uSeconds; 13 | uniform vec2 uResolution; 14 | 15 | /* 16 | Inbuilt - 17 | "gl_FragCoord" = Pixel coordinate(vec2) between (0 - uResolution) from bottomleft 18 | 19 | 20 | Uniforms - 21 | "uResolution" = Display resolution 22 | "uSeconds" = Game running time 23 | */ 24 | 25 | 26 | // Get depth (Linearized) 27 | float getDepth(vec2 uv) 28 | { 29 | // TODO: Bring these via uniforms? 30 | // Right now they need to match with the values in the "c_near" and "c_far" constants in "constants.py" 31 | float near = 0.01f; 32 | float far = 100.0f; 33 | 34 | // Linearize the depth 35 | float depth = texture2D(depthTexture, uv).x; 36 | return (2.0f * near) / (far + near - depth * (far - near)); 37 | } 38 | 39 | 40 | // Get color 41 | vec3 getColor(vec2 uv) 42 | { 43 | return texture2D(colorTexture, uv).rgb; 44 | } 45 | 46 | 47 | void main() 48 | { 49 | vec2 tex = texCoords; 50 | 51 | float depth = getDepth(tex); 52 | vec3 color = getColor(tex); 53 | 54 | // -------- 55 | 56 | fragColor = vec4(color, 1.0f); 57 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_default.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec2 aPos; 4 | layout (location = 1) in vec2 aTexCoords; 5 | 6 | out vec2 texCoords; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4(aPos.xy, 0.0f, 1.0f); 11 | texCoords = aTexCoords; 12 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_fisheye.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | const float PI = 3.1415926535f; 4 | 5 | out vec4 fragColor; 6 | 7 | in vec2 texCoords; 8 | 9 | uniform sampler2D colorTexture; 10 | uniform sampler2D depthTexture; 11 | 12 | uniform float uSeconds; 13 | uniform vec2 uResolution; 14 | 15 | /* 16 | Inbuilt - 17 | "gl_FragCoord" = Pixel coordinate(vec2) between (0 - uResolution) from bottomleft 18 | 19 | 20 | Uniforms - 21 | "uResolution" = Display resolution 22 | "uSeconds" = Game running time 23 | */ 24 | 25 | 26 | // Get depth (Linearized) 27 | float getDepth(vec2 uv) 28 | { 29 | // TODO: Bring these via uniforms? 30 | // Right now they need to match with the values in the "c_near" and "c_far" constants in "constants.py" 31 | float near = 0.01f; 32 | float far = 100.0f; 33 | 34 | // Linearize the depth 35 | float depth = texture2D(depthTexture, uv).x; 36 | return (2.0f * near) / (far + near - depth * (far - near)); 37 | } 38 | 39 | 40 | // Get color 41 | vec3 getColor(vec2 uv) 42 | { 43 | return texture2D(colorTexture, uv).rgb; 44 | } 45 | 46 | 47 | void main() 48 | { 49 | vec2 tex = texCoords; 50 | 51 | float depth = getDepth(tex); 52 | vec3 color = getColor(tex); 53 | 54 | // -------- 55 | 56 | float aperture = 180.0f; 57 | float apertureHalf = 0.5f * aperture * (PI / 180.0f); 58 | float maxFactor = sin(apertureHalf); 59 | 60 | vec2 uv; 61 | vec2 xy = 2.0f * texCoords.xy - 1.0f; 62 | xy.x *= uResolution.x / uResolution.y; 63 | 64 | float d = length(xy); 65 | float rad = 2.0f - maxFactor; 66 | 67 | float s = 0.5f * (0.5f + sin(uSeconds) * 0.5f); 68 | 69 | if (d > (rad - 0.5) && d < rad) 70 | { 71 | d = length(xy * maxFactor); 72 | float z = sqrt(1.0f - d * d); 73 | float r = atan(d, z) / PI; 74 | float phi = atan(xy.y, xy.x); 75 | 76 | uv.x = r * cos(phi) + 0.5f + smoothstep(0.5f - s, 0.5f + s, d); 77 | uv.y = r * sin(phi) + 0.5f + smoothstep(0.5f - s, 0.5f + s, d); 78 | } 79 | else 80 | { 81 | uv = texCoords.xy; 82 | } 83 | 84 | vec4 c = texture2D(colorTexture, uv); 85 | fragColor = c; 86 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_fisheye.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec2 aPos; 4 | layout (location = 1) in vec2 aTexCoords; 5 | 6 | out vec2 texCoords; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4(aPos.xy, 0.0f, 1.0f); 11 | texCoords = aTexCoords; 12 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_radialb.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | const float PI = 3.1415926535f; 4 | 5 | out vec4 fragColor; 6 | 7 | in vec2 texCoords; 8 | 9 | uniform sampler2D colorTexture; 10 | uniform sampler2D depthTexture; 11 | 12 | uniform float uSeconds; 13 | uniform vec2 uResolution; 14 | 15 | /* 16 | Inbuilt - 17 | "gl_FragCoord" = Pixel coordinate(vec2) between (0 - uResolution) from bottomleft 18 | 19 | 20 | Uniforms - 21 | "uResolution" = Display resolution 22 | "uSeconds" = Game running time 23 | */ 24 | 25 | 26 | // Get depth (Linearized) 27 | float getDepth(vec2 uv) 28 | { 29 | // TODO: Bring these via uniforms? 30 | // Right now they need to match with the values in the "c_near" and "c_far" constants in "constants.py" 31 | float near = 0.01f; 32 | float far = 100.0f; 33 | 34 | // Linearize the depth 35 | float depth = texture2D(depthTexture, uv).x; 36 | return (2.0f * near) / (far + near - depth * (far - near)); 37 | } 38 | 39 | 40 | // Get color 41 | vec3 getColor(vec2 uv) 42 | { 43 | return texture2D(colorTexture, uv).rgb; 44 | } 45 | 46 | 47 | #define T texture2D(colorTexture, 0.5f + (p.xy *= 0.992f)) 48 | 49 | void main() 50 | { 51 | vec2 tex = texCoords; 52 | 53 | float depth = getDepth(tex); 54 | vec3 color = getColor(tex); 55 | 56 | // -------- 57 | 58 | vec3 p = vec3(gl_FragCoord.xy / uResolution - 0.5f, 0.0f); 59 | vec3 o = T.rbb; 60 | for (float i = 0.0f; i < 100.0f; i++){ 61 | p.z += pow(max(0.0f, 0.5f - length(T.rg)), 2.0f) * exp(-i * 0.008f); 62 | } 63 | 64 | fragColor = vec4(o * o + p.z, 1.0f); 65 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_radialb.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec2 aPos; 4 | layout (location = 1) in vec2 aTexCoords; 5 | 6 | out vec2 texCoords; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4(aPos.xy, 0.0f, 1.0f); 11 | texCoords = aTexCoords; 12 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_third3d.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | const float PI = 3.1415926535f; 4 | 5 | out vec4 fragColor; 6 | 7 | in vec2 texCoords; 8 | 9 | uniform sampler2D colorTexture; 10 | uniform sampler2D depthTexture; 11 | 12 | uniform float uSeconds; 13 | uniform vec2 uResolution; 14 | 15 | /* 16 | Inbuilt - 17 | "gl_FragCoord" = Pixel coordinate(vec2) between (0 - uResolution) from bottomleft 18 | 19 | 20 | Uniforms - 21 | "uResolution" = Display resolution 22 | "uSeconds" = Game running time 23 | */ 24 | 25 | 26 | // Get depth (Linearized) 27 | float getDepth(vec2 uv) 28 | { 29 | // TODO: Bring these via uniforms? 30 | // Right now they need to match with the values in the "c_near" and "c_far" constants in "constants.py" 31 | float near = 0.01f; 32 | float far = 100.0f; 33 | 34 | // Linearize the depth 35 | float depth = texture2D(depthTexture, uv).x; 36 | return (2.0f * near) / (far + near - depth * (far - near)); 37 | } 38 | 39 | 40 | // Get color 41 | vec3 getColor(vec2 uv) 42 | { 43 | return texture2D(colorTexture, uv).rgb; 44 | } 45 | 46 | 47 | void main() 48 | { 49 | vec2 tex = texCoords; 50 | 51 | float depth = getDepth(tex); 52 | vec3 color = getColor(tex); 53 | 54 | // -------- 55 | 56 | fragColor = vec4(color, 1.0f); 57 | } -------------------------------------------------------------------------------- /pymaze/shaders/post_processing/post_third3d.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec2 aPos; 4 | layout (location = 1) in vec2 aTexCoords; 5 | 6 | out vec2 texCoords; 7 | 8 | uniform vec2 uResolution; 9 | 10 | uniform mat4 projView; 11 | uniform mat4 model; 12 | 13 | void main() 14 | { 15 | float aspect = uResolution.x / uResolution.y; 16 | gl_Position = projView * model * vec4(aPos.xy * vec2(aspect, 1.0f), 0.0f, 1.0f); 17 | texCoords = aTexCoords; 18 | } -------------------------------------------------------------------------------- /pymaze/shaders/shadow_debugger.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 FragColor; 4 | 5 | in vec2 TexCoords; 6 | 7 | uniform sampler2D depthMap; 8 | 9 | void main() 10 | { 11 | float depthValue = texture(depthMap, TexCoords).r; 12 | FragColor = vec4(vec3(depthValue), 1.0f); 13 | } -------------------------------------------------------------------------------- /pymaze/shaders/shadow_debugger.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec3 aPos; 4 | layout (location = 1) in vec2 aTexCoords; 5 | 6 | out vec2 TexCoords; 7 | 8 | void main() 9 | { 10 | TexCoords = aTexCoords; 11 | gl_Position = vec4(aPos, 1.0f); 12 | } -------------------------------------------------------------------------------- /pymaze/shaders/shadow_mapping.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | void main() 4 | { 5 | gl_FragDepth = gl_FragCoord.z; 6 | } -------------------------------------------------------------------------------- /pymaze/shaders/shadow_mapping.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec3 vPos; 4 | layout(location = 3) in vec3 vInst; 5 | 6 | uniform mat4 projView; 7 | 8 | // Should do this on the code side rather than on shader 9 | mat4 rotationMatrix(vec3 axis, float angle) { 10 | axis = normalize(axis); 11 | float s = sin(angle); 12 | float c = cos(angle); 13 | float oc = 1.0 - c; 14 | 15 | return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0, 16 | oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0, 17 | oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0, 18 | 0.0, 0.0, 0.0, 1.0); 19 | } 20 | 21 | void main() 22 | { 23 | vec3 inst = vInst; 24 | inst.y = 0.0f; 25 | 26 | mat4 model = mat4(1.0f); 27 | 28 | // Apply rotation 29 | bool dir = bool(int(vInst.y)); 30 | if (dir){ 31 | model = rotationMatrix(vec3(0.0f, 1.0f, 0.0f), radians(90.0f)); 32 | } 33 | 34 | // Apply translation 35 | model[3][0] = inst.x; 36 | model[3][1] = inst.y; 37 | model[3][2] = inst.z; 38 | 39 | gl_Position = projView * model * vec4(vPos, 1.0f); 40 | } -------------------------------------------------------------------------------- /pymaze/shaders/skybox.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 FragColor; 4 | 5 | in vec3 TexCoords; 6 | 7 | uniform samplerCube skybox; 8 | 9 | void main() 10 | { 11 | FragColor = texture(skybox, TexCoords); 12 | } -------------------------------------------------------------------------------- /pymaze/shaders/skybox.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout (location = 0) in vec3 aPos; 4 | 5 | out vec3 TexCoords; 6 | 7 | uniform mat4 projView; 8 | 9 | void main() 10 | { 11 | TexCoords = aPos * -1.0f; // Quick fix to flip the texture 180 12 | vec4 pos = projView * vec4(aPos, 1.0f); 13 | gl_Position = pos.xyww; 14 | } -------------------------------------------------------------------------------- /pymaze/shaders/world_geom.frag: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | out vec4 fragColor; 4 | 5 | in vec2 aTexCoords; 6 | in vec3 aNormal; 7 | in vec4 aFragPosLight; 8 | 9 | uniform sampler2D diffuse; 10 | uniform sampler2D shadowMap; 11 | 12 | uniform vec2 textureScale; 13 | uniform vec3 lightDir; 14 | 15 | 16 | float getShadowFragmentSun(vec4 fragPosLight) 17 | { 18 | vec3 projCoords = (fragPosLight.xyz / fragPosLight.w) * 0.5f + 0.5f; 19 | 20 | float shadow = 0.0f; // Shadow accumulator 21 | 22 | vec2 texelSize = 1.0f / textureSize(shadowMap, 0); 23 | for(int x = -1; x <= 1; x++) 24 | { 25 | for(int y = -1; y <= 1; y++) 26 | { 27 | float depthValue = texture(shadowMap, projCoords.xy + vec2(x, y) * texelSize).r; 28 | shadow += projCoords.z > depthValue ? 1.0f : 0.0f; 29 | } 30 | } 31 | 32 | return (projCoords.z > 1.0) ? 0.0f : shadow / 9.0f; 33 | } 34 | 35 | 36 | void main() 37 | { 38 | vec3 color = texture(diffuse, aTexCoords * textureScale).rgb; 39 | float shadow = 1.0f; 40 | 41 | // All fragments that are facing away from the sun can be covered in shadow fully (duh) 42 | if (dot(aNormal, lightDir) < 0.0f){ 43 | shadow = getShadowFragmentSun(aFragPosLight); 44 | } 45 | 46 | vec3 finalOut = (color + (1.0f - shadow)) * color; 47 | fragColor = vec4(finalOut, 1.0f); 48 | } -------------------------------------------------------------------------------- /pymaze/shaders/world_geom.vert: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | 3 | layout(location = 0) in vec3 vPos; 4 | layout(location = 1) in vec3 vNormal; 5 | layout(location = 2) in vec2 vTex; 6 | layout(location = 3) in vec3 vInst; 7 | 8 | out vec2 aTexCoords; 9 | out vec3 aNormal; 10 | out vec4 aFragPosLight; 11 | 12 | uniform mat4 projView; 13 | uniform mat4 lightProjView; 14 | 15 | // Should do this on the code side rather than on shader 16 | mat4 rotationMatrix(vec3 axis, float angle) { 17 | axis = normalize(axis); 18 | float s = sin(angle); 19 | float c = cos(angle); 20 | float oc = 1.0 - c; 21 | 22 | return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0, 23 | oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0, 24 | oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0, 25 | 0.0, 0.0, 0.0, 1.0); 26 | } 27 | 28 | void main() 29 | { 30 | vec3 inst = vInst; 31 | inst.y = 0.0f; 32 | 33 | mat4 model = mat4(1.0f); 34 | 35 | // Apply rotation 36 | bool dir = bool(int(vInst.y)); 37 | if (dir){ 38 | model = rotationMatrix(vec3(0.0f, 1.0f, 0.0f), radians(90.0f)); 39 | } 40 | 41 | // Apply translation 42 | model[3][0] = inst.x; 43 | model[3][1] = inst.y; 44 | model[3][2] = inst.z; 45 | 46 | vec4 fragPos = model * vec4(vPos, 1.0f); 47 | 48 | aFragPosLight = lightProjView * vec4(fragPos.xyz, 1.0f); 49 | aTexCoords = vTex; 50 | aNormal = normalize(mat3(model) * vNormal); 51 | 52 | gl_Position = projView * fragPos; 53 | } -------------------------------------------------------------------------------- /pymaze/skybox.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | import glm 4 | 5 | import numpy as np 6 | 7 | from OpenGL.GL import * 8 | 9 | from constants import * 10 | from camera import * 11 | from shaders import * 12 | from textures import * 13 | 14 | 15 | class PWShadowDebugger(PWConstants): 16 | def __init__(self, depth_texture): 17 | self.debugger = PWVaoData() 18 | self.__createDebugger() 19 | 20 | # -------- 21 | 22 | self.depth_texture = depth_texture 23 | 24 | 25 | def __createDebugger(self): 26 | self.debugger.vao = glGenVertexArrays(1) 27 | glBindVertexArray(self.debugger.vao) 28 | 29 | vertices = np.array([-0.5, 0.5, 0.0, 0.0, 1.0, 30 | -0.5, -0.5, 0.0, 0.0, 0.0, 31 | 0.5, 0.5, 0.0, 1.0, 1.0, 32 | 0.5, -0.5, 0.0, 1.0, 0.0], dtype="float32") 33 | 34 | 35 | self.debugger.vbo = glGenBuffers(1) 36 | glBindBuffer(GL_ARRAY_BUFFER, self.debugger.vbo) 37 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) 38 | 39 | stride = 5 40 | glEnableVertexAttribArray(0) 41 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 42 | 43 | uv_offset = 3 44 | glEnableVertexAttribArray(1) 45 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, self.d_fsize * stride, ctypes.cast(self.d_fsize * uv_offset, ctypes.c_void_p)) 46 | 47 | 48 | def renderDebugMap(self): 49 | shader = PWShaders.getShader(ShaderTypes.SDEBUG_SHADER) 50 | glUseProgram(shader.shader) 51 | 52 | glActiveTexture(GL_TEXTURE0) 53 | glBindTexture(GL_TEXTURE_2D, self.depth_texture) 54 | 55 | glBindVertexArray(self.debugger.vao) 56 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4) 57 | 58 | 59 | class PWSkyboxShadow(PWConstants): 60 | def __init__(self): 61 | self.depth_buffer = 0 62 | self.depth_texture = 0 63 | self.__createDepthBuffer() 64 | 65 | # -------- 66 | 67 | pitch = 55.0 68 | yaw = 45.0 69 | 70 | self.calculateViewProjection(pitch, yaw) 71 | 72 | self.debugger = PWShadowDebugger(self.getDepthMap()) 73 | 74 | 75 | def calculateViewProjection(self, pitch, yaw): 76 | dist = 25.0 77 | self.projection = glm.ortho(-dist, dist, -dist, dist, self.s_shadow_near, self.s_shadow_far) 78 | 79 | target = glm.vec3(16.5, 0.0, -16.5) # Center of the maze 80 | self.light_direction = PWCamera.createViewFront(pitch, yaw) # Pitch, Yaw 81 | self.light_position = target + self.light_direction * dist 82 | 83 | # 84 | self.view = glm.lookAt(self.light_position, target, glm.vec3(0.0, 1.0, 0.0)) 85 | 86 | # 87 | self.projection_view = np.array(self.projection * self.view, dtype='float32') 88 | 89 | 90 | def getLightDirection(self): 91 | return -self.light_direction 92 | 93 | 94 | def getDepthMap(self): 95 | return self.depth_texture 96 | 97 | 98 | def getProjectionView(self): 99 | return self.projection_view 100 | 101 | 102 | def __createDepthBuffer(self): 103 | self.depth_buffer = glGenFramebuffers(1) 104 | glBindFramebuffer(GL_FRAMEBUFFER, self.depth_buffer) 105 | 106 | self.depth_texture = glGenTextures(1) 107 | glBindTexture(GL_TEXTURE_2D, self.depth_texture) 108 | 109 | glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, self.s_shadow_width, self.s_shadow_height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, None) 110 | 111 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) 112 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) 113 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER) 114 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER) 115 | 116 | border_color = np.array([1.0, 1.0, 1.0, 1.0], dtype='float32') 117 | glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color) 118 | 119 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, self.depth_texture, 0) 120 | 121 | glDrawBuffer(GL_NONE) 122 | glReadBuffer(GL_NONE) 123 | 124 | # Reset back to default buffer 125 | glBindFramebuffer(GL_FRAMEBUFFER, 0) 126 | 127 | 128 | def begin(self): 129 | shader = PWShaders.getShader(ShaderTypes.SHADOW_SHADER) 130 | glUseProgram(shader.shader) 131 | 132 | glUniformMatrix4fv(shader.proj_view, 1, GL_FALSE, self.projection_view) 133 | 134 | glCullFace(GL_FRONT) 135 | 136 | # Set viewport size to shadow map size 137 | glViewport(0, 0, self.s_shadow_width, self.s_shadow_height) 138 | 139 | # Set our new framebuffer active 140 | glBindFramebuffer(GL_FRAMEBUFFER, self.depth_buffer) 141 | 142 | # Clear the contents of the framebuffer 143 | glClearColor(0.0, 0.0, 0.0, 1.0) 144 | glClear(GL_DEPTH_BUFFER_BIT) 145 | 146 | 147 | def end(self): 148 | # Reset back to default buffer 149 | glBindFramebuffer(GL_FRAMEBUFFER, 0) 150 | 151 | glCullFace(GL_BACK) 152 | 153 | # Reset viewport back to default screen size 154 | glViewport(0, 0, self.d_resolution.x, self.d_resolution.y) 155 | 156 | 157 | class PWSkybox(PWConstants): 158 | def __init__(self): 159 | self.skybox = PWVaoData() 160 | self.__createSkybox() 161 | 162 | self.skybox_shadow = PWSkyboxShadow() 163 | 164 | 165 | def __createSkybox(self): 166 | self.skybox.vao = glGenVertexArrays(1) 167 | glBindVertexArray(self.skybox.vao) 168 | 169 | vertices = np.array([-1.0, 1.0, -1.0, 170 | -1.0, -1.0, -1.0, 171 | 1.0, -1.0, -1.0, 172 | 1.0, -1.0, -1.0, 173 | 1.0, 1.0, -1.0, 174 | -1.0, 1.0, -1.0, 175 | 176 | -1.0, -1.0, 1.0, 177 | -1.0, -1.0, -1.0, 178 | -1.0, 1.0, -1.0, 179 | -1.0, 1.0, -1.0, 180 | -1.0, 1.0, 1.0, 181 | -1.0, -1.0, 1.0, 182 | 183 | 1.0, -1.0, -1.0, 184 | 1.0, -1.0, 1.0, 185 | 1.0, 1.0, 1.0, 186 | 1.0, 1.0, 1.0, 187 | 1.0, 1.0, -1.0, 188 | 1.0, -1.0, -1.0, 189 | 190 | -1.0, -1.0, 1.0, 191 | -1.0, 1.0, 1.0, 192 | 1.0, 1.0, 1.0, 193 | 1.0, 1.0, 1.0, 194 | 1.0, -1.0, 1.0, 195 | -1.0, -1.0, 1.0, 196 | 197 | -1.0, 1.0, -1.0, 198 | 1.0, 1.0, -1.0, 199 | 1.0, 1.0, 1.0, 200 | 1.0, 1.0, 1.0, 201 | -1.0, 1.0, 1.0, 202 | -1.0, 1.0, -1.0, 203 | 204 | -1.0, -1.0, -1.0, 205 | -1.0, -1.0, 1.0, 206 | 1.0, -1.0, -1.0, 207 | 1.0, -1.0, -1.0, 208 | -1.0, -1.0, 1.0, 209 | 1.0, -1.0, 1.0], dtype='float32') 210 | 211 | self.skybox.vbo = glGenBuffers(1) 212 | glBindBuffer(GL_ARRAY_BUFFER, self.skybox.vbo) 213 | glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW) 214 | 215 | stride = 3 216 | glEnableVertexAttribArray(0) 217 | glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, self.d_fsize * stride, None) 218 | 219 | 220 | def renderSkybox(self, camera): 221 | shader = PWShaders.getShader(ShaderTypes.SKYBOX_SHADER) 222 | glUseProgram(shader.shader) 223 | 224 | # Remove translation from the view matrix 225 | view = glm.mat4(glm.mat3(camera.getView())) 226 | projection = camera.getProjection() 227 | 228 | glUniformMatrix4fv(shader.proj_view, 1, GL_FALSE, np.array(projection * view)) 229 | 230 | glDepthFunc(GL_LEQUAL) 231 | 232 | glActiveTexture(GL_TEXTURE0) 233 | glBindTexture(GL_TEXTURE_CUBE_MAP, PWTextures.getTexture3D("skybox_01").getTexture()) 234 | 235 | glBindVertexArray(self.skybox.vao) 236 | glDrawArrays(GL_TRIANGLES, 0, 36) 237 | 238 | glDepthFunc(GL_LESS) 239 | 240 | 241 | if __name__ == "__main__": 242 | pass 243 | -------------------------------------------------------------------------------- /pymaze/sound.py: -------------------------------------------------------------------------------- 1 | 2 | from constants import * 3 | 4 | 5 | class PWSound(PWConstants): 6 | def __init__(self): 7 | pass -------------------------------------------------------------------------------- /pymaze/textures.py: -------------------------------------------------------------------------------- 1 | import pygame 2 | from pygame.locals import * 3 | 4 | import os 5 | 6 | from OpenGL.GL import * 7 | from constants import * 8 | 9 | 10 | class PWTexture2D(object): 11 | def __init__(self, path): 12 | self.texture_id = self.__createTexture(path) 13 | 14 | 15 | def __createTexture(self, path): 16 | # Load texture and convert to format OpenGL can use 17 | surface = pygame.image.load(path).convert() 18 | surface_data = pygame.image.tostring(surface, "RGB", 1) 19 | 20 | width = surface.get_width() 21 | height = surface.get_height() 22 | 23 | # Create and bind texture (Following settings apply to the currently binded texture) 24 | texture_id = glGenTextures(1) 25 | glBindTexture(GL_TEXTURE_2D, texture_id) 26 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, surface_data) 27 | 28 | # GL_REPEAT makes texture repeatable (aka. seamless*) 29 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) 30 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) 31 | 32 | # There are dozen options for texture filtering (Setting things to GL_NEAREST makes textures look crispy) 33 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) 34 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) 35 | 36 | # Generate mipmaps (Reduces load on texture sampling with distant objects) 37 | glGenerateMipmap(GL_TEXTURE_2D) 38 | 39 | # TODO: Should query the max level first 40 | # Make textures look smooth on different angles/distance 41 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 16) 42 | 43 | glBindTexture(GL_TEXTURE_2D, 0) 44 | 45 | return texture_id 46 | 47 | 48 | def getTexture(self): 49 | return self.texture_id 50 | 51 | 52 | class PWTexture3D(object): 53 | def __init__(self, path): 54 | self.texture_id = self.__createTexture(path) 55 | 56 | 57 | def __createTexture(self, path): 58 | texture_id = glGenTextures(1) 59 | glBindTexture(GL_TEXTURE_CUBE_MAP, texture_id) 60 | 61 | for enum, texture_path in enumerate(("right.png", "left.png", "bottom.png", "top.png", "front.png", "back.png")): 62 | full_path = os.path.join(path, texture_path) 63 | 64 | surface = pygame.image.load(full_path).convert() 65 | surface_data = pygame.image.tostring(surface, "RGB", 1) 66 | 67 | width = surface.get_width() 68 | height = surface.get_height() 69 | 70 | glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + enum, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, surface_data) 71 | 72 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR) 73 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR) 74 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) 75 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) 76 | glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE) 77 | 78 | return texture_id 79 | 80 | 81 | def getTexture(self): 82 | return self.texture_id 83 | 84 | 85 | class PWTextures(PWConstants): 86 | textures2D = {} 87 | textures3D = {} 88 | 89 | @classmethod 90 | def loadTexture2D(cls, name, path): 91 | cls.textures2D[name] = PWTexture2D(path) 92 | 93 | @classmethod 94 | def getTexture2D(cls, name): 95 | return cls.textures2D[name] 96 | 97 | # -------- 98 | 99 | @classmethod 100 | def loadTexture3D(cls, name, path): 101 | cls.textures3D[name] = PWTexture3D(path) 102 | 103 | @classmethod 104 | def getTexture3D(cls, name): 105 | return cls.textures3D[name] 106 | 107 | @classmethod 108 | def parseTextures(cls): 109 | # 2D 110 | cls.loadTexture2D("wall_01", "textures/wall_01.png") 111 | cls.loadTexture2D("floor_01", "textures/floor_01.png") 112 | cls.loadTexture2D("trim_01", "textures/trim_01.png") 113 | 114 | # 3D 115 | cls.loadTexture3D("skybox_01", "textures/skybox_01") 116 | -------------------------------------------------------------------------------- /pymaze/textures/floor_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/floor_01.png -------------------------------------------------------------------------------- /pymaze/textures/skybox_01/back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/skybox_01/back.png -------------------------------------------------------------------------------- /pymaze/textures/skybox_01/bottom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/skybox_01/bottom.png -------------------------------------------------------------------------------- /pymaze/textures/skybox_01/front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/skybox_01/front.png -------------------------------------------------------------------------------- /pymaze/textures/skybox_01/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/skybox_01/left.png -------------------------------------------------------------------------------- /pymaze/textures/skybox_01/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/skybox_01/right.png -------------------------------------------------------------------------------- /pymaze/textures/skybox_01/top.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/skybox_01/top.png -------------------------------------------------------------------------------- /pymaze/textures/trim_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/trim_01.png -------------------------------------------------------------------------------- /pymaze/textures/wall_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Blakkis/PyGLMaze/e6d3c418fdb315cfd8207c91340e75f2358d7453/pymaze/textures/wall_01.png --------------------------------------------------------------------------------