13 ms·
Build your own old-school 3D shooter in a weekend
- JustSomeNobody 8y agoI love his "tiny" repositories. So cool.
- azhenley 8y agoEspecially his Tiny Renderer: https://github.com/ssloy/tinyrenderer https://github.com/ssloy/tinyrenderer
- burk96 8y agoI know right? ssloy is on fire, one of the few non-organizations I follow on Github. Does anyone else know some similar users that should get some more love?
- _dd_ 8y agoI think this repo is nice to https://github.com/petershirley/raytracinginoneweekend https://github.com/petershirley/raytracinginoneweekend
- simias 8y agoThe readme mentions it but I think it's worth pointing out that this is a very particular (and quite dated) method for sort-of-3D rendering. It's the same type of engine used in the original Wolfenstein. It's definitely a lot of fun to implement (and I recommend trying if you've never done it before) but it's very different and much more limited than what we expect from a 3D engine nowadays.
- AnIdiotOnTheNet 8y agoTrue, but what's great about it is that it is such a simple method to achieve something that seems 3D. It's very easy to explain, the math is straight-forward, and it hardly takes any code, making it a great starting point for people interested in this sort of thing. Its simplicity makes it easy to extend the functionality too. For instance, you can add Y-shearing pretty trivially and get a limited range of motion on the view's vertical axis, or add floor and ceiling casting to get textures there, a little more manipulation can add jumping and crouching, etc.
- msla 8y ago> the original Wolfenstein. Well, the original Wolfenstein 3D, the third game in the series. https://en.wikipedia.org/wiki/Castle_Wolfenstein https://en.wikipedia.org/wiki/Castle_Wolfenstein https://en.wikipedia.org/wiki/Beyond_Castle_Wolfenstein https://en.wikipedia.org/wiki/Beyond_Castle_Wolfenstein
- simias 8y agoUh, I had never heard about these games before. I always thought Id created the franchise. Thank you for that bit of videogame history.
- msla 8y agoThe first two games were top-down 2D stealth games. The third was a pseudo-3D FPS. Most people picked up the series at the third installment, and the third installment is what made it into history books as the First Popular FPS, ignoring earlier FPSes which were Not Popular.
- cwyers 8y agoTo be clear, Castle Wolfenstein and its sequel were written by Silas Warner and published by Muse Software, which went out of business in 1987 after going through Chapter 7 bankruptcy. Because the trademark was lapsed, Id was able to use the name for their game. But it wasn't a continuation of the original games, more like a reboot by another team and publisher.
- dwags 8y agoI read "Id" as " i'd " and thought this was the the most bizarre sarcastic comment. Time for more coffee
- deleted 8y ago[deleted]
- AnIdiotOnTheNet 8y agoCastle Wolfenstein was a noteworthy and revolutionary game in its own right: https://www.filfre.net/2012/04/castle-wolfenstein/ https://www.filfre.net/2012/04/castle-wolfenstein/
- AnIdiotOnTheNet 8y agoI believe the sprites used in the video are taken directly from Andre LaMothe's original Tricks of the Game Programming Gurus. I still have a copy.
- jbverschoor 8y agoThat was an awesome book
- AnIdiotOnTheNet 8y agoOnly programming book I ever read cover-to-cover.
- gorb314 8y agoOh yes! Good times! I still have my copy somewhere.
- throwaway2016a 8y agoI think leaving the "old-school" out of the title doesn't do this justice. My first thought was, with modern engines, or even raw OpenGL that isn't that hard... I did it in a weekend for my "Advanced Computer Graphics" elective in college using OpenGL and that was 2008. But this is kind of cool... it's more of a tiny ray tracer and... well to borrow the title... old-school arcade game.
- 3chelon 8y ago> it's more of a tiny ray tracer It's a ray caster, where the rays are sent out from the camera to intersect the map. With ray tracers, the rays are sent out from the light source, IIRC. Your point on OpenGL is valid, but that just removes all the learning from it. OpenGL does so much of the grunt work for you. This kind of old-school game engine is a great learning experience.
- tehsauce 8y agoRay-tracing does not necessarily mean rays are cast from the light source.
- emmanueloga_ 8y agoOh apparently ray casting is considered a form of ray tracing: "Ray casting is the most basic of many computer graphics rendering algorithms that use the geometric algorithm of ray tracing." [1] 1: https://en.wikipedia.org/wiki/Ray_casting https://en.wikipedia.org/wiki/Ray_casting
- alpaca128 8y agoWhat you mean is forward ray tracing. But "ray tracing" usually refers to the variant sending rays from the camera as forward ray tracing is almost never used. Ray casting on the other hand is basically ray tracing without any reflections or shadows, in other words each ray stops with the first collision.
- Sohcahtoa82 8y ago> It's a ray caster, where the rays are sent out from the camera to intersect the map. With ray tracers, the rays are sent out from the light source, IIRC. Not correct. I see this pedantry often, but it's factually wrong. If you look at the Wikipedia articles for both ray casting [0] and ray tracing [1], they BOTH describe the methods as sending rays from the camera/eye. From what I can tell, the difference between ray casting and ray tracing is that in ray casting, only the primary ray is traced. The ray does not get reflected, refracted, or even traced to light sources for checking shadows. At most, surface normals are dealt with for lighting and texture mapping is applied. [0] https://en.wikipedia.org/wiki/Ray_casting https://en.wikipedia.org/wiki/Ray_casting [1] https://en.wikipedia.org/wiki/Ray_tracing_(graphics) https://en.wikipedia.org/wiki/Ray_tracing_(graphics)
- tezza 8y agoUnity give away a complete 6DOF FPS with multiplayer. All source and assets included https://unity.com/fps-sample https://unity.com/fps-sample
- msla 8y agoSometimes you want to make chili from scratch instead of going out to eat Peking duck.
- pjmlp 8y agoYeah, but the recipe isn't the same as when the conquistadores discovered America.
- laputan_machine 8y agogame engine != game. learning how to raycast, the maths involved, how to make your own game engine, none of those things are covered in that repo. It's a different thing. This kind of negativity is damaging.
- Tempest1981 8y agoI'd kill for a dozen comments, esp. if a goal is to educate students. 498 lines would still be impressive.
- deleted 8y ago[deleted]
- robterrell 8y agoIt's a neat trick of projection, and really easy to hack on and extend yourself once you know the trick. Using your map of the space, cast a ray from the camera position through every column of the display rectangle; using the distance the ray travelled before intersecting the wall, you can calculate the apparent height of the wall seen in that column of the display; so, in that column, draw the wall that high. You can get fancier with textures for the walls, varying the floor height, walls that can appear and disappear (i.e. "doors"), and so on. Better than my 10-second explanation: https://lodev.org/cgtutor/raycasting.html https://lodev.org/cgtutor/raycasting.html
- AnIdiotOnTheNet 8y agoNote that the site has several more entries with extensions to that base raycaster, which you can find in the index. Interesting note about this technique: you get perspective correct texturing for free. "Real" 3D rendering usually had to cope with affine texturing due to performance costs until dedicated hardware for it came along.
- rasz 8y agolike this? https://github.com/ssloy/tinyraycaster/wiki https://github.com/ssloy/tinyraycaster/wiki table of contents is in upper right
- Tempest1981 8y agoNice!
- 8y ago
- 3chelon 8y agoWow, this reminds me of writing a very similar engine in the mid 90s after learning about ray-casting (and playing Doom of course). There was a very good book which covered the whole process called "Tricks of the Game Programming Gurus", which I would have killed for at the time!
- tombert 8y agoI need to dig up the code, but over the course of a week on the train rides to and from work, I built a very simple ray-caster in Pico-8 on the Pocket Chip. It was especially fun since I had figured out the math for it on my own (which, in fairness, isn't terribly complex with even a high-school understanding of Trigonometry). I had enough fun with it that I think it might become my new "trying out a new programming language" test, since it was easy enough to get done quickly, but difficult enough to where I had to actually learn the language.
- ddeokbokki 8y agoThousands of french millenials getting hit by the nostalgia feels as they read through the README.
- cabaalis 8y agoI'm way out of practice with C++. (It's been since like 2006.) Framebuffer clear function appears to allocate a new vector. Does std::vector automatically handle the memory releases? This is called every frame, so I wanted to check here to see if I'm crazy or not.
- dragontamer 8y ago> Does std::vector automatically handle the memory releases? Yes. What is going on here is that "img" is being assigned. The "old vector" will have its destructor called, which will call the destructor of all of its elements by default. ------- I assume you're talking about this code: https://github.com/ssloy/tinyraycaster/blob/master/framebuffer.cpp https://github.com/ssloy/tinyraycaster/blob/master/framebuff... void FrameBuffer::clear(const uint32_t color) { img = std::vector<uint32_t>(w*h, color); } Which seems inefficient to me. But it is correct code, even if it is inefficient. There's no memory leak here, but the code probably would be way more efficient if it were instead a simple memset. memset(&img[0], color, w*h*sizeof(uint32_t)); This memset is likely easier to understand, since it doesn't rely upon destructors / constructors / assignment C++ Magic. And its more efficient to boot. Vectors are guaranteed to be contiguous in memory, which is why it is compatible with memset. EDIT: Hmmm... the img is never initialized. You'd also have to do "img = std::vector<uint32_t>(w*h, color);" somewhere. ---------- The rectangle is also inefficient. for (size_t i=0; i<rect_w; i++) { for (size_t j=0; j<rect_h; j++) { If i and j were reversed, the draw rectangle function would be more efficient. As it is, "j" iterates in the wrong direction with regards to cache lines... // This would be faster! for (size_t j=0; j<rect_h; j++) { for (size_t i=0; i<rect_w; i++) { Overall though, efficiency isn't a goal at all. Its designend to be a quickie project to get things done as soon as possible. Thinking about all of these details slows down development, so there's something to be said about "just getting it done"
- saagarjha 8y agoInstead of doing a memset, I'd recommend using std::fill (which will likely call memset or another fast implementation behind the scenes): it makes it clear what you are doing, and preempts questions of "is this legal to do" (which it is, but only for POD data types).
- markstos 8y agoAnnouncement oddly timed with the anniversary of the Parkland shooting.
- oarabbus_ 8y agoI hate to be morbid but it's not exactly difficult for any announcement to coincide with the anniversary of a shooting.
- seattle_spring 8y agoNot really oddly timed, as the link between video games and real world violence has been debunked countless times.
- glouwbug 8y agoI started something similar 2 years ago and I'm now actively pushing for a release date 1-2 years from now. https://github.com/glouw/andvaranaut https://github.com/glouw/andvaranaut
- halfnibble 8y agoPeople are saying this is a "quite dated" method for creating a 3D game. Does anyone have a tutorial on creating a 3D game in one weekend (or even 1 day?) using modern tooling? It'd be cool to make a token 3D game with the kids. I'm curious myself.
- bdibs 8y agoUse a modern engine like Unreal or Unity, watch a few videos and I'm sure you can get something basic running fairly quickly.
- TheGRS 8y agoWell yea you can get an FPS game made in Unity in about an hour or two. But it won't really tell you much about what is happening in the background.
- AnIdiotOnTheNet 8y agoThis kind of engine is great as a starting place for programmers, I think, but Unity is probably what you want for the kind of thing you're doing. There's also Godot if you want to stay in Open Source land, but it probably isn't as good and certainly doesn't have the same level of coverage in tutorials and documentation. Or there's the time-tested path to gamedev: modding existing games.
- cobbzilla 8y agoDisclaimer: I've never used Unity but have played around with Godot quite a bit. Godot's 3D capabilities, while almost certainly not as full-featured as Unity, are plenty enough to make an old-school FPS, and a lot more. The Godot online docs are quite good; well organized, clean layout, easy to find stuff. But for tutorials and howtos, I've had more success with YouTube screencast videos vs the Godot docs.
- doctorpangloss 8y ago> Or there's the time-tested path to gamedev: modding existing games. Definitely for kids, modding an existing game is the right way to go. It will be way more fun, and it'll be a lot more motivating to share things with friends than to do stuff because dad said so. I think you're also right that Unity is better but it's still pretty challenging. Programming is really crazy hard, especially for young kids. That's despite great things like Code.org and Scratch. Those activities are substantiated by good observational (qualitative) evidence measuring creativity, not programming ability. The only hard quantitative data people have is engagement time--that kids spend more time in apps than equivalent regular instruction when learning idiosyncratic turtle graphics in apps. Pretty unsurprising in my opinion. As far as I know, there is no evidence that these pre-high school programming experiences retain acceptably-performing students in high school programming like AP Computer Science better than forcing them to take the class. Scratch's educational mission, which I am most familiar with, has for now not made such test-based outcomes an investigative priority. Honestly an old-school 3D shooter is just about the worst thing you can coerce a disinterested kid into doing. If they're pre-puberty and still care what dad thinks, this sort of activity is exactly what kids drop when they get older. If they're in high school and don't care what dad thinks: it's not a multiplayer game, it doesn't inhabit some social space/it isn't a "third place," it's not taking advantage of the greatest power of the classroom in high school, peer pressure. This is based on my experience making a game that kids 12+ regularly mod, being the only kid in high school that programmed regularly before 18, and interacting with (but not conducting research with) the wonderful people at Scratch, who really do know how to make algorithmic thinking and creativity work for kids 12 and younger. Maybe at Stuyvesant parents are making the kids learn C++, but you gotta understand that coercion is the placebo, not the treatment. If you're going to coerce your kids into doing something incredibly boring, it might as well be whatever narrow testing regime is hot these days and not what we fantasize vicariously they should be interested in doing.
- csours 8y agoOk, now I see why the headline was changed before. Having the words "school" and "shooter" both in a headline really changes the mood.
- porphyrogene 8y agoThis reaching for controversy is absurd.
- yashksagar 8y agoi almost read that title wrong with the words School and Shooter in them
- tibbon 8y agoI've been wanting to write a raycaster, as I've never done it before. Might try doing it in a "slow" language like Ruby that I'm better at at first, and then try it in C. I kinda suck at C these days, but it would be a good transition into it again.
- anigbrowl 8y agoWhile surely unintentional this headline is in incredibly poor taste.
- BucketSort 8y agoI don't want to simulate shooting up my old school.
- wgj 8y agoMaybe it's old hat for everyone else, but this is my first time looking at Gitpod. (Link at the bottom of the project Readme.)
- dormando 8y agoI did most of one of these on an FPGA in verilog for fun: https://github.com/dormando/verilog-raycaster https://github.com/dormando/verilog-raycaster - took a lot longer than a weekend :)
- atum47 8y agoThat's really cool. I can't tell you how many times I started to make one and stopped half way...
- newshorts 8y agoHad to reread that headline a couple times...
- AppleCorp 8y agoThere was a great 3D framework called Cocos3D that had a bunch of PowerVR tools for working with 3D mobile development. They had an example app that was a FPS made from scratch. The HUD was there, enemies, weapons, environment. There might be a Metal FPS base game available on GitHub, I can't remember what it was called.
- thinkersilver 8y agoI remember writing this for my GCSE computer project in C. It didn't take me a weekend though back then. This is a Wolf3D style game. It would be interesting to illustrate the Doom engine that followed with the diagonal walls and lighting effect. I looked at this after doing GCSe project, finding it to hard and skipping to a real 3D engine like quake because it was conceptually easier.
- pan69 8y agoThis is a great ray casting tutorial to get started: https://permadi.com/1996/05/ray-casting-tutorial-table-of-contents/ https://permadi.com/1996/05/ray-casting-tutorial-table-of-co...
- jimnotgym 8y agoI know there is a performance issue, but does anyone know of any resources to get a basic 3d shooter working in Python? It's just that my kids already know some Python...
- n-gauge 8y agoHere's a html / javascript version of simular: https://htmlgames.github.io/htmlgames/differences/gallery/index.html https://htmlgames.github.io/htmlgames/differences/gallery/in... type something like lego into the search query and it renders pictures of lego in the maze as well.
- lizardwalk5 8y agothat title does not sound right. could old-school be removed? I feel like "school" and "shooter" are somewhat misleading and potentially alarming together. could it be something like build your own 3d shooter game? or does this refer to first person shooter? I did not read the entire article so take it with a grain of salt.
- rasz 8y agoHere is another Ray casting wold3d like tutorial : https://github.com/permadi-com/ray-cast/tree/master/ https://github.com/permadi-com/ray-cast/tree/master/ It has real legacy, was created in 1996! https://permadi.com/1996/05/ray-casting-tutorial-table-of-contents/ https://permadi.com/1996/05/ray-casting-tutorial-table-of-co...