8 ms·
Wolfenstein's original rendering engine as 450 line shader with no external data
- tluyben2 9y agoI am reading Fabiens Wolfenstein 3d Black book (and implementing several parts to really understand things); great to see this. The Wolfenstein 3d engine was rather compact already but this is very cool. Smooth run on the iPhone 7 as well.
- deleted 9y ago[deleted]
- city41 9y agoInteresting that it worked for you on the iPhone 7. On my iPhone 6 I just get a black window.
- tluyben2 9y agoI hit 60 fps on chrome on ios while black like you have on Safari. I assumed they both use webkit and would be more or less the same.
- daveslash 9y agoA co-worker gave me that book recently. Excellent. For anyone who enjoyed this post, I suggest you look into Fabien Sanglard's work (books/blog-posts).
- nukeop 9y agoThe title is misleading - the shader does not implement the original Wolfenstein rendering engine, it's an experiment in generating textures inside the code.
- jcl 9y agoIt's actually closer to the Wolfenstein rendering engine than one might expect... Like the original, it does a ray-march in the ground plane to find map objects: https://github.com/id-Software/wolf3d/blob/0516778/WOLFSRC/WL_DR_A.ASM#L414 https://github.com/id-Software/wolf3d/blob/0516778/WOLFSRC/W... And, like the original, it separates the cases of wall blocks, door blocks, and sprites. It also expedites ceiling/floor drawing by just picking a flat color for the top and bottom halves of the screen: https://github.com/id-Software/wolf3d/blob/0516778/WOLFSRC/WL_DRAW.C#L946 https://github.com/id-Software/wolf3d/blob/0516778/WOLFSRC/W... But it naturally differs from the original in that it is rendering per-pixel rather than per-column, so it does not need to accumulate a list of sprite intersections to draw in reverse order over the walls -- it can just stop raymarching when it encounters an opaque pixel: https://github.com/id-Software/wolf3d/blob/0516778/WOLFSRC/WL_DRAW.C#L1157 https://github.com/id-Software/wolf3d/blob/0516778/WOLFSRC/W... In a sense, the shader works like rewriting and optimizing the original renderer so that it renders to a screen of a single pixel, then running 147,456 instances of the renderer to fill the 512x288 pixel screen.
- deleted 9y ago[deleted]
- crescentfresh 9y agoWhy am I seeing Nazi symbols? What is this?
- tldsfgiuoisdf 9y agoYou are aware of Wolfenstein, stop trolling.
- crescentfresh 9y agoNo sir, am I not. This is HN, give me the benefit of the doubt, please.
- paines 9y agoThose aren't nazi symbols silly. They are buddhist symbols abused by the 3rd reich!
- Jaruzel 9y agohttps://en.wikipedia.org/wiki/Swastika https://en.wikipedia.org/wiki/Swastika
- darklajid 9y agoNot helpful. Sometimes technically correct isn't correct enough or good enough. The symbol was - in large parts of the world - tainted by the Nazis. By Germans (I'm one). Sorry for Buddhists that suffer in Europe, but I am a supporter of the ban of this symbol (and lots of other speech, Free Speech is a different concept from elsewhere).
- mjevans 9y agoThis definitely is a case where use and intent should matter. I agree with making the reverence of a /Nazi/ symbol something to censor for the public good. However, use in a historically accurate context? Or even an alternate history, either of which should present it as a symbol being used to spearhead hate and atrocities? I feel like that is a truthful non-worshiping view that should be retained. Uses outside of that context, such as the symbol's older geometric and religious meanings (probably identifiable by their lack of historically / physically WW-II ties) should be fine.
- ngcazz 9y agoThis is fun -- getting very trippy results by changing around some of the constants... vec3 rotate(vec3 r, float v){ return vec3(v*0.1*r.x*cos(v)+r.z*sin(v),r.y,r.z*cos(v)-r.x*sin(v));}
- itomato 9y agoWolfenstein 3DMT
- dtx1 9y agoNSFW AF
- 2aa07e2 9y agoNazi symbols are SFW for me.
- asow92 9y agoDo you work with Nazis?
- 2aa07e2 9y agoNo. [1] [1] https://www.vox.com/world/2017/8/16/16152088/nazi-swastikas-germany-charlottesville https://www.vox.com/world/2017/8/16/16152088/nazi-swastikas-...
- smt88 9y agoYour speech is free in the US, but you can still be fired for it.
- 2aa07e2 9y agoI am located in Europe.
- smt88 9y agoYour comment implies you're either in Germany or the US, and since you said "SFW", I inferred you're in the US. Either way, freedom of speech doesn't automatically make all allowed speech into SFW speech.
- 2aa07e2 9y agoI'm located in Eastern Europe and I am a European citizen. If I were in Germany it would probably be NSFW indeed. I wouldn't want to trigger them. In my country and my working environment there'd be no risk for me whatsoever. Why is it that much NSFW to read an article that describes the technical merits of a game where the player kills Nazis?
- CPLX 9y agoThis is awesome. I was watching it waiting for a guard to scream at me in unintelligible 8-bit German.
- wukerplank 9y ago"Achtung!" "Mein Leben!" Good times. A game that worked without mini-map and without constantly patting the player on the back.
- OscarTheGrinch 9y agoSchutzstaffel!
- FranOntanaya 9y agoGuess you never got lost in the purple level!
- mhd 9y agoAbout twice as many lines with a more conservative indent setting.
- tomp 9y agowhat's the `mix` function?
- sdmadf2834 9y agoNSFW warning please. I read HN at work
- atesti 9y agoWhere is the map stored? So far there seems to be no texture and all textures are procedurally created, but I can't figure out yet where the map is. Is it in isMap and isDoor? They are very short
- gpm 9y agoisWall, isDoor, isObject seem to determine if a location is a door, wall, or object and be the primary map generating functions. They take a floor coordinate and return true/false depending on if it is/isn't hit. Additionally wall/room height seems to be hardcoded as 1 (from 0 to 1 specifically) in getColorForPosition. If it doesn't hit a wall, door, or object, then it is the floor/ceiling as decided by how color is initialized in main above the call to castRay.
- nimbius 9y agoThis game was responsible for two amazing moments in my childhood. 1. Realizing I wanted to be a computer programmer 2. My parents being confronted by school administrators because I was whistling Horst Wessel Lied, or as i called it "the cool Wolfenstein song." at school frequently.
- se30b 9y agoThat is really, really funny.
- Mantipath 9y agoI'm trying to figure out how that second point worked. Is it that you were whistling too often and it would have been a problem even if you were going with, say, the Andy Griffith theme, or did you both whistle so well and have school administrators so educated that they identified that you were whistling Nazi propaganda? It's not that characteristic a tune.
- boomlinde 9y agoIt was the national anthem of Nazi Germany. If you have a even a passing interest in WWII, which I hope at least some teachers would, it should be familiar.
- gpm 9y agoThe aliasing in this was driving me insane, fortunately it's really easy to implement anti aliasing. Change the function signature of the current main function to vec3 getColor(in vec2 fragCoord ) { And the last line to return col Then just call it a bunch of times with nearby points in a new main function void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec3 c1 = getColor(fragCoord + vec2( 0.25, 0.25)); vec3 c2 = getColor(fragCoord + vec2( 0.25, -0.25)); vec3 c3 = getColor(fragCoord + vec2(-0.25, 0.25)); vec3 c4 = getColor(fragCoord + vec2(-0.25, -0.25)); fragColor = vec4((c1 + c2 + c3 + c4) / 4., 1.0); } Obviously this does 4x the amount of work as without antialiasing, but with modern hardware you don't notice it and it looks way better.
- pjc50 9y agoThe aliasing is highly authentic for the original 320x200 render mode :)
- gpm 9y agoTrue
- organsnyder 9y agoIt would have been softened by the CRTs of the time, though (or, at least, the CRTs I had...).
- msla 9y agoCRTs in general are complex pieces of machinery which do odd, hard-to-emulate things to graphics. Here's an interesting post on the topic: http://ascii.textfiles.com/archives/3786 http://ascii.textfiles.com/archives/3786 And one with more detail: http://bogost.com/games/a_television_simulator/ http://bogost.com/games/a_television_simulator/
- dahart 9y ago> CRTs in general are complex pieces of machinery which do odd, hard-to-emulate things to graphics. True, but that doesn't stop the smart guys on Shadertoy from trying... ;) https://www.shadertoy.com/view/4dlyWX https://www.shadertoy.com/view/4dlyWX https://www.shadertoy.com/view/ldSfWV https://www.shadertoy.com/view/ldSfWV
- jcl 9y agoIf you like this one, you'll probably also enjoy the "DOOM E1M1" shader, which not only reproduces the DOOM graphics, but also the level audio in a separate shader (note: sound autoplays): https://www.shadertoy.com/view/lsSXzD https://www.shadertoy.com/view/lsSXzD
- Gargoyle 9y agoVery tangentially related, but curious if anything thinks it would be worth reading through Abrash's Zen Of Graphics Programming at this point. Is the info in there still useful (even as a foundation) or is it totally outdated?
- spitfire 9y agoGo with the black book. I've written a comment about this before but can't be bothered to look for it. The Abrash's black book is both totally outdated and highly relevant. All the technical material is entirely outdated - which probably makes it a better teaching tool. But the methods, approaches and thought processes he describes through the book and the beginning vignettes are priceless. Particularly for me the Video 7 story.
- dr_zoidberg 9y agoStill useful in the sense that he teaches how to do profiling right: measure, measure, and measure. Don't just jump to attack the code without profiling, try to reason about the code, try to reason about the algorithms and data structures, and only at the end go for "low level performance tricks" (as in writing everything in assembly). It's an entertaining read, mostly, but you'll surely don't get much from the 386, 486 and Pentium quirks (and cycle counting) to extract the last drop of performance, other that "back in the old days, Pentium would issue 2 instructions at the same time given a very particular set of conditions". But again, as he does focus on analyzing the problem at large, finding the correct algorithm and data structure, it's still useful.
- pjmlp 9y ago"Oops your WebGL implementation has crashed!" The wonderful world of mobile WebGL. It looks great on the desktop, though.
- Hans_Dorn 9y agoWarning: NSFW if you're in Germany
- jlmorton 9y agoAlso NSFW if you're, you know, at work. While some co-workers may recognize the game, others may be put off by large swastikas zooming around your monitor.
- oblio 9y agoIt seems there's a wave of silly Wolfenstein implementations, about a week ago we had the Microsoft Excel one. Keep them coming, I'm always amazed by the creativity some people have :)
- zaroth 9y agoSooooo thankful your second sentence turned out the way it did. Just enough time reading the first sentence for “WTF” to form in my mind in anticipation of the condescension to come, and then the second sentence and it was a nice bit of stress release. Hurray for the hacker in Hacker News.
- oblio 9y agoI'd love if everyone in the world could work on making me rich, healthy and immortal, but it they don't, they might as well have fun instead :p
- ascagnel_ 9y agoWolf3D is a pretty easy-to-understand renderer by nature (it's a 3D representation of what is really a 2D game, so it's a matter of matching columns), and that simplicity lends itself to creativity.
- cwyers 9y agoWatching that is really unsettling. The graphics look very much like what I remember, but movement is so very off. It's so smooth and the turning allows for much more subtle changes in orientation than the game did. Kinda breaks by brain a little. Still really cool.
- hinkley 9y agoIIRC didn’t wolf and doom use ‘binary radians’ where 2π = 256
- StanislavPetrov 9y agoWhen I saw "original" I was expecting to see the 1980s version.
- digi_owl 9y agoWatching the animation play i could almost hear the shouts of the soldiers. And it has been decades since i fired up the game.
- etaioinshrdlu 9y agoIt really makes you realize that 8GB (or bigger!) games these days are simply not really trying procedural generation at all. Even most mobile games at something like 50MB are a huge waste of space!