Тёмный

Line Of Sight or Shadow Casting in 2D 

javidx9
Подписаться 315 тыс.
Просмотров 142 тыс.
50% 1

In this (long, sorry) video I cover a variety of things to implement a classing line-of-sight mapping, or shadow casting depending on your perspective. It's also the first olc::PixelGameEngine project I've done a video for, so I spend some time showing you how to set up Visual Studio to use this engine. I'm quite pleased with the end result of these algorithms and I expect to use them quite a bit in more ambitious tile-based projects in the future.
These resources are excellent regarding the things seen in the video:
stackoverflow.com/questions/5...
www.redblobgames.com/articles...
ncase.me/sight-and-light/
Source: github.com/OneLoneCoder/Javid...
/ discord
Blog: www.onelonecoder.com
Twitter: @javidx9
Twitch: javidx9

Наука

Опубликовано:

 

11 окт 2018

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 311   
4 года назад
0:00 _Intro_ 2:26 _Setting up Pixel Engine in VS_ 5:41 Setting up demo 6:30 _Theory talk_ 7:02 *Theory* - Converting tiles to edges (on paper) 8:26 _Talk about advantages of converting tiles to edges_ 8:50 *Theory* - Algorithm (on paper) 15:44 Implementation - Generating edges 26:21 _Optimization talk_ 26:45 *Theory* - Ray casting? (on paper) 31:05 _Resources_ 32:17 Implementation _Setup_ - Visibility 32:58 *Theory* - Ray casting order? (on paper) 33:50 Implementation - Visibility 35:42 _Ray/Edge intersection talk_ 36:02 Implementation _Setup_ - Ray/Edge intersection 36:13 *Theory* - Ray/Edge intersection (on paper) 37:01 _Resources_ - Line intersection Algorithm 37:11 Implementation - Ray/Edge intersection 39:57 Implementation - Casting shadows 40:56 _Implementation result_ 41:40 Implementation - Bug fixing 42:12 _Implementation result_ 42:42 Implementation - Generating boundaries 43:03 _Implementation result_ 43:23 _Visualizing light only with rays_ 44:14 Implementation - Reducing numbers of rays 45:33 _Implementation result_ 46:37 Implementation - Adding sprite for light source 49:02 *Final result* 49:26 Compiling in release mode 49:46 _Off screen buffer talk_
@5daydreams
@5daydreams 3 года назад
Wow, this is very organized! Thanks a lot :D
@TheMadmaxster
@TheMadmaxster 5 лет назад
I haven’t enjoyed RU-vid videos this much in a long time, fantastic content!
@javidx9
@javidx9 5 лет назад
That's really pleasing to hear MadMaxster, thanks!
@dewijones92
@dewijones92 5 лет назад
+1
@clodgozon3968
@clodgozon3968 5 лет назад
It's true. I don't know why I do not enjoy Cherno and other people's programming videos, except this channel!
@aimanal-eryani7809
@aimanal-eryani7809 5 лет назад
Yes indeed, dude's old-school
@harryfox4389
@harryfox4389 5 лет назад
I've just scrolled through your channel and you answer lots of questions and have tutorials on everything I've been trying to do. Pseudo 3d. Check Shadows. Check. Zoom and panning. Check Thanks a lot
@javidx9
@javidx9 5 лет назад
Hey welcome to the community buddy!
@avirosenblum233
@avirosenblum233 5 лет назад
There's an important error in your raycast function. In it you solve for t1 by dividing by rdx. If the ray being tested is vertical, rdx will be zero and therefore the result will be NaN. To fix this, add a check for rdx != 0 before that step. If rdx == 0, use the following to solve for t1 instead: t1 = (e2 .sy + sdy * t2 - oy) / rdy I implemented this and it fixed the issue. Hope this helped anyone else who had this problem.
@mothtolias
@mothtolias 5 лет назад
the moment you pointed out the "fan" was triangles my mind was blown. fascinating video - thank you for sharing all these resources!
@javidx9
@javidx9 5 лет назад
Yeah, its a nice conclusion - always reduce a problem into things you can do, sounds obvious I know, but so very very true...
@stevea.b.9282
@stevea.b.9282 Год назад
I can't tell you how much this video helped me, I've been struggling to get LOS working for months, and it works perfectly now (i'm making a 2d maze game). Thank you! I cut the number of extra rays needed down to 1 (rather than 2) by making a Point struct with an enum to describe the point type based on which walls it connects (north, east end west, north/west corner, T-junction etc) . If they are "continuer" types (end of a wall and corners) I add an extra ray slightly further along toward the end of the wall, or outwards from the corner, 0.1f is enough. Currently working on how to cull un-needed rays - will post result and method if I find one. Thanks again javidx9, you are a life saver!
@psyjax2
@psyjax2 5 лет назад
26:09 How dare you draw the Holy Hand Grenade of Antioch without the proper blessing!
@javidx9
@javidx9 5 лет назад
dammit XD
@mothtolias
@mothtolias 5 лет назад
looks more like a map church symbol to me.
@Jay-og4yb
@Jay-og4yb 5 лет назад
This guy is ridiculously talented. Well done man The tutorials are much appreciated!
@GermsOilCotten
@GermsOilCotten 5 лет назад
Thanks for including the set up. I'm very new to this stuff and it was very helpful. I know lots of people may know that stuff and not want to watch more explaination about it but for me that is amazingly helpful. Love your channel.
@clodgozon3968
@clodgozon3968 5 лет назад
Duh, I love explanations too. You're not the only one, lmao.
@thePrinceOfPurpose
@thePrinceOfPurpose 5 лет назад
Thank you for coming to youtube! I love your work!
@nivalius
@nivalius 5 лет назад
long videos are good thank you for all you're doing, great stuff
@laureven
@laureven 5 лет назад
Absolutely Awesome Video
@namless0o7
@namless0o7 4 года назад
Your content is very compelling, well constructed, and excellent video quality. Keep up the good work! I have learned so much from you!
@javidx9
@javidx9 4 года назад
Thanks namless!
@nilspin
@nilspin 5 лет назад
I was having problem understanding Ray casting in voxel engines, and your video made it very clear how it's done. I understood everything you explain in one go and don't have to rewind to jump back and forth topics. You explain things in a linear and structured fashion which I think sets you apart from most other programming channels. Keep up the good work!
@kevinjad4506
@kevinjad4506 4 года назад
I LOVED HOW U EXPLAINED THE FAN of triangle CONCEPT
@kubamaruszczyk4043
@kubamaruszczyk4043 5 лет назад
Excellent video! Your explanations are very clear and very well visualised. Thank you for sharing your expertise!
@javidx9
@javidx9 5 лет назад
Hey cheers Kuba!
@KSG__
@KSG__ 5 лет назад
perfect time for a javid video :D
@javidx9
@javidx9 5 лет назад
lol, perhaps not in UK, it was 12:30am here :D
@alxklgn364
@alxklgn364 5 лет назад
A pleasure to watch. Thanks.
@Otakutaru
@Otakutaru 5 лет назад
I've noticed that in a 4 edge tiled enviroment, bounding vertices always have an even number of edges attached, and any vertex with an odd number will not be relevant. So using this idea the first step would be to purge the irrelevant vertices from a grid array. Also, the number of edges in a row/column will be the number of vertex in that row/col divided by 2 (duh. but has neat properties). This means that you can start and end connections intermitently any time you encounter another vertex when running down the row/col without worrying about messing up the geometry. That way you can convert a vertex grid into an array of edges with starting and ending points. Then merge edges into vertex shapes by checking their vertices. Select one edge, compare to the next one, if they share a point, push the new vertex of the two into an ordered array until you find the edge that closes the shape by also checking if the starting and ending vertices match up, select another free edge if there are any left, repeat. You'll end up with an array of closed shapes and uninterrupted edges (hopefully).
@videopsybeam7220
@videopsybeam7220 5 лет назад
This is gonna come in real handy for GameHut's 16-bit PUBG demake.
@SnakeEngine
@SnakeEngine 5 лет назад
On Sega Saturn!
@javidx9
@javidx9 5 лет назад
Yeah Psybeam a few comments have pointed this out - it looks like a great project from an experienced coder, one to watch for sure.
@fuanka1724
@fuanka1724 4 года назад
Thanks for sharing this video. Lots to learn indeed.
@bryphi77
@bryphi77 5 лет назад
Always such great content!
@javidx9
@javidx9 5 лет назад
Cheers bryphi!
@rampage14x13
@rampage14x13 3 года назад
Wow, this is just what I was looking for! Thank you so much, I haven’t seen the video yet but based off of your other ones I’m sure this will not disappoint! It’s late at night where I am atm so I will provide an update at some other time on how my project is going after watching and hopefully implementing this into my own project..
@GG-fj5er
@GG-fj5er 4 года назад
this is amazing. thank you so much. you could absolutely charge for these videos.
@lucaxtal
@lucaxtal 5 лет назад
Great video and very clear explanation, keep doing this great job!
@javidx9
@javidx9 5 лет назад
Cheers Luca, will do!
@SamFisk
@SamFisk 5 лет назад
I've been working on this on and off for last couple weeks, and lo and behold a video appears in my feed. :P Decided to scrap the method I had been trying and go to something like this and after an afternoon of work got everything working. :D Thanks for the resource, would have been amazing to have few weeks earlier though. Definitely going to be very valuable to others.
@javidx9
@javidx9 5 лет назад
Sorry it was later than you needed Sam, oh well! At least you got it working and thanks for the support - its appreciated!
@Valentyn90A
@Valentyn90A 5 лет назад
This channel is amazing. Thank you for this!
@javidx9
@javidx9 5 лет назад
Hey thanks Val, my pleasure!
@kepeb1
@kepeb1 5 лет назад
Thanks. It's a great idea to include the little VS setup. I switched from code:blocks a week or so back and it was surprising how little information on this there was.
@kepeb1
@kepeb1 5 лет назад
Actually, it was a few things. A gap in my learning, majority of interesting RU-vid tutorials seem to use it, and it is easier to follow for a beginner if it looks the same. I am not really skilled enough to argue the merits of either. But I can say VS was WAY easier to set up. There were a number of code:blocks specific hurdles that kept interrupting my progress. Before I was even introduced to all the fundamentals there were extra steps I had to figure out in order to simply follow along.
@javidx9
@javidx9 5 лет назад
Hey Thanks Turncoat, I'm pleased it was useful to someone, its a question I get asked a lot.
@Revan727
@Revan727 4 года назад
If you don't teach you should. Your explanation of things are so clear and concise that I was able to convert your code into C#. Well at least for the converting cells into a polygon. I am now working on the visibility polygon. Awesome work!
@mattpilot
@mattpilot 5 лет назад
Thanks for your amazing videos. I dont do any C++, but they way you explain things makes it so easy to follow along and understand i have no problem applying it to javascript. Keep it up - maybe one day you'll bless us with javascript game dev videos :-)
@javidx9
@javidx9 5 лет назад
Thanks M P, I appreciate it, although I will say it is unlikely I'll do any javascript videos, but I will be doing some lua script pretty soon!
@michaeljones3448
@michaeljones3448 3 года назад
awesome channel, hope to get visual studios, seems like a neat program. Keep it up!
@florianwicher
@florianwicher 2 года назад
This is a beautifully-done tutorial, sir. Edit: Just got it working in Java :)
@Plrang
@Plrang 5 лет назад
Another short and simple video, great to watch right before a sleep at 3AM ;) tx
@javidx9
@javidx9 5 лет назад
lol, yeah yeah, I get it, shorter videos :P Sleeping just stops you from doing cool stuff anyway...
@Plrang
@Plrang 5 лет назад
@@javidx9 I got a fresh kid, don't sleep anyway;) And I know you have, watching that all the time
@Morphox
@Morphox 5 лет назад
Nice video! I once programmed something similar in C# with OpenGL I used my own method which was to iterate over every vertex of the obstacles as lines and then using dot product of the line's normal and the vertex-player direction vector to detect whether the player can see the line or not. It only works for convex shapes tho...
@javidx9
@javidx9 5 лет назад
That's a nice approach Tomlow, and is probably valid in many situations, may be worth doing a performance comparison in the future!
@beron_the_colossus
@beron_the_colossus 5 лет назад
Was just about to go to sleep but this is better!
@javidx9
@javidx9 5 лет назад
Hey thanks Peki!
@beron_the_colossus
@beron_the_colossus 5 лет назад
@rockyrivermushrooms529
@rockyrivermushrooms529 5 лет назад
I just found your channel and enjoy these videos. I feel like youll gain lots of subscribers
@javidx9
@javidx9 5 лет назад
Hi there FireFungi, hey thanks a lot buddy! As long as people enjoy the videos Im happy :D
@killereks
@killereks 5 лет назад
Finally I found a channel that teaches you useful algorithms for making 2D and 3D games while also teaching you new math. I was looking for a channel like this for ages! However I do not code in C++ and will have to learn it.
@BlazertronGames
@BlazertronGames 5 лет назад
I'm sure you could apply it to a different programming langauge.
@BlazertronGames
@BlazertronGames 5 лет назад
Also, if you're going to learn c++, make sure you get a good book. I've heard that free online beginner resources usually teach bad habits/techniques. And don't trust amazon reviews, make sure you research if you're going to buy one.
@killereks
@killereks 5 лет назад
hey, thanks for the help however i do code in C# and other languages for a long time so i have good understanding of private variables, friendly functions, destructors etc. I even learned how pointers work so I'm pretty sure i could learn c++ pretty quickly but I just don't know how to do graphics in it so I haven't tried yet. Also I don't like learning from books especially programming, I think it's better to go and try to code something or mess around with other people's code. Thanks again.
@javidx9
@javidx9 5 лет назад
Hey Killereks, nice to have you on board!
@mothtolias
@mothtolias 5 лет назад
yes, most of what's described here is abstract and could be implemented in just about any language.
@mypersonalvideos2786
@mypersonalvideos2786 5 лет назад
really good video thx
@javidx9
@javidx9 5 лет назад
Thanks MPV!
@felixspeagel5915
@felixspeagel5915 4 года назад
I think there is alternative way of "filling the gaps" than shown at 30:08 . Look, after you sort the list of triangles, you will find that between neighboring ones there will be "gaps in angles" eg.: between triangle A starting at alpha_1 and ending at alpha_2, and triangle B starting at beta_1 and ending at beta_2, there can be no triangle starting at alpha_2 and ending at beta_1. This means you can add a triangle starting at alpha_2 and ending at beta_1, with radius of the maximal radius allowed in your app. Of course, you have to take into account that the resulting triangle could have got an angle bigger than 180°, so there should be also some kind of function that will cut that triangle into smaller pieces :).
@unaigom
@unaigom 5 лет назад
New subscriber... instant follower!
@javidx9
@javidx9 5 лет назад
Thank you Unai!
@xeridea
@xeridea 2 года назад
In my game, I am using the fast raycasting from your other video for lighting. Implemented a bit different than here, as raycasting is calculated, it adds light to the tile it is in, which gets reduced as the ray travels on. If a solid tile is hit, light is reduced, rather than blocked, giving a semi transparent property. Ray distance is limited by how far it takes the light to attenuate to zero. It casts 1 ray to each tile of the edge of the effective light reach. The light level at each tile is then moved to a texture (it is actually a shade drawn alpha blended over other tiles...), that is then stretched over the viewing area, making it look very natural. This also means only 1 draw call is used for the entire scene, combined with the efficient algorithm, lighting is nearly free performance wise.
@skilz8098
@skilz8098 4 года назад
As for the nearest neighbor algorithm, something that might be a little more efficient would be to use a kernel scheme. You will have to take into an account for and check for world boundary edges and corner cases, however, we can model it after something like this where each bit represents a specific direction being present. Of the 4 bits starting with the MSB being West we would end up with W,N,E,S respectively. If there is a 1 present that direction is set. If you notice there are no values of {5,7,A,B} which makes sense since 5 = 0101 where North and South would be combined. The same for 7 which would be 0111 giving a combination of N, S, & E and A being 1010 as this would result in E & W. None of those cases makes any sense, so those values don't exist in the kernel. So you'll never have opposing directions - bits set simultaneously and you'll never have 3 bits present as there are either only 1 or 2 bits set or none for the location of the object being the center of the kernel. This has good symmetry since the center object always has a value of 0 when you are looking for the 8 adjacent neighbors and is very versatile for many applications! NW, N, NE, 1100, 0100, 0110 W, C, E, = 1000, 0000, 0010 SW, S, SE 1001, 0001, 0011 We can create a descriptive enum or class enum for this: enum DirKernel { CE = 0x00, // Center SO = 0x01, // South EA = 0x02, // East SE = 0x03, // South East NO = 0x04, // North NE = 0x06, // North East WE = 0x08, // West SW = 0x09, // South West NW = 0x0C // North West }; We can have a const lookup_kernel in two different manners: const unsigned lookup[3][3] = { {12, 4, 6 }, {8, 0, 2}, {9, 1, 3}}; or by having const std::array { 12,4,6,8,0,2,9,1,3}; Now the actual values above are completely arbitrary as one could start with N and have that as either the MSB or LSB and you can go in a CCW or CW direction... just as long as you stay consistent with the bit patterns and making sure that none of them have more than 2 or opposing directions set. Now, know that we are only going to have 4 bits that are used for independent directions. This can possibly be simplified even further to make the algorithms even more efficient by using `std::bitset direction`. There are so many possibilities that one can do with this kind of design. We can see that the current sell on the world scan here will be at the center of these lookup tables (kernels) and the values will give the bit indicator of a cell's neighboring location and direction. However, the downside to this would be more memory consumption in that each cell would have to its own (x,y) world coordinate and or grid position along with two arrays. Now the arrays are not large in themselves such that one would be an std::array neighbors and the other would be std::array neighbors_exist... As the world is being generated by the clicking of the mouse to either draw or delete such a box, these arrays would need to be updated and since they are arrays, you have const time access, linear time iteration. The math performed to test a single cell with its eight neighbors would be simply bitwise arithmetic and logic. You could even use `std::vector` instead of `array` since we know that these arrays will always be 9 in size and never change if preferred. With modern c++ we might be able to get away with a simple for loop... for (auto& c : cells) { c.check_neighbors() } And we can use the kernels within check_neighbors method... which could theoretically reduce a lot of the multiplication and nested if loops... You don't have to specifically have an if west, then if north, then if south, etc... Just loop through the grid or vector of cells and check each cell's neighbor's vector and apply the kernel to it to generate the vector of bools. The nice thing about this with the kernel is the symmetry. The current cell will always be in the center of the kernel as it will always have 4 cells before it and 4 cells after it and it will always have a value of 0. In the enum it doesn't look or appear this way as they are listed numerically in ascending order, however, they would be in the kernel vector of values as seen above in the lookup tables. {NW, N, NE, W , C, E, SW,S,SE}... Also what is nice is if you need to get a particular neighbor's existing record you can query into that vector anytime and retrieve a dir_kern::NW which is very descriptive instead of hardcoded or defined. Don't get me wrong; I truly enjoy watching your videos, and I learn quite a bit. I like seeing other people's perspectives, their train of thoughts, their problem-solving abilities, and their algorithm building or designing techniques, but I also like to give possible insight on specific topics. Yes, there might be a slightly larger memory footprint but the speeds of the calculations would reduce bottlenecks. Besides that, the extra memory can be stored in a hashmap if needed for future use and fast lookup time. You will see many tricks like this when performing specific lighting and shading techniques within DirectX, OpenGL - SpirV shaders to perform complex calculations very efficiently. Create a mask and a kernel saves a bunch of computational times which is great when you begin to work with large 3D scenes with lots of objects and multiple lights. It's a good technique for ray, light, and shadow casting, applying filters, etc. You can see them here a little bit: learnopengl.com/Advanced-Lighting/SSAO and you can see them in some of these www.rastertek.com/tutindex.html. Not only this, but this kernel setup also works very well with a physics engine for collision detections, pathfinding, AI algorithms, A* search, and more. It can even be used in 3D Audio Rendering for directional sound displacement! It can be used in animations and even particle engines! Outside of this, I did like how you converted the intersection lines into triangle fans to reduce the number of rays that are being cast out, yet it will still cover a full 360-degree rotation field of view. I also liked your pre/post-processing - deferred rendering and only drawing when something is present or updated. Excellent optimizations!
@VictorQianYT
@VictorQianYT 4 года назад
Thank you! Thank you! Thank you! Thank you! Thank you!
@up4life108
@up4life108 5 лет назад
thank you for this video. ive been trying to come up with my own way of casting 2d shadows a while ago and failed which then stopped me from actually making the game i was gonna build
@javidx9
@javidx9 5 лет назад
Oh dang Up4Life, I hate it when stuff like that happens. Perhaps now its time to dig up those idea and give it another go?
@up4life108
@up4life108 5 лет назад
it definetly is! Thank you for your respond, i will give it another try now!
@francescopiazza4882
@francescopiazza4882 4 года назад
Very nice !
@focuseletronica
@focuseletronica 5 лет назад
Fantastic!!
@javidx9
@javidx9 5 лет назад
Cheers friend!
@erichenriquez3641
@erichenriquez3641 4 года назад
Love your video, I was Playing with P5.js library and wanted to create some RayCasting, but my aproach was very bad, your algorithm is far better, will try to use it and write it in JS. Nice Content, new Subscriber here. Im not a native english speaker so sorry if I made some mistakes.
@javidx9
@javidx9 4 года назад
Glad it helped! Thanks Eric!
@James-uw4it
@James-uw4it 5 лет назад
Normally I don't comment, but your videos are really great
@javidx9
@javidx9 5 лет назад
Manuel, I really appreciate that, thanks buddy.
@amankaushik5833
@amankaushik5833 4 года назад
this is awesome!!
@TomershalevMan
@TomershalevMan 4 года назад
great content. I believe the co linearity test you perform is only good for axis aligned co linearity, therefore mis detecting other tilted cases
@jsflood
@jsflood 5 лет назад
Excellent! :-D
@javidx9
@javidx9 5 лет назад
Thanks John!
@AndreasEDM
@AndreasEDM 5 лет назад
best channel.
@cvabds
@cvabds 5 лет назад
you rock! Um abraço brasileiro!
@javidx9
@javidx9 5 лет назад
Aww, thanks cvabds!
@SketchpunkLabs
@SketchpunkLabs 5 лет назад
great job. i likey
@javidx9
@javidx9 5 лет назад
Thanks Sketchpunk!
@JoshRosario310
@JoshRosario310 3 года назад
The most visually satisfying first 1:30
@patrickelliott2169
@patrickelliott2169 3 года назад
Hmm. Sprite is a neat trick, but.... For some game engines you might want to have the "character" with different light sources, or even variable ones, so you need, instead, a "falloff" effect, and.. it maybe possible to create a "fake boundary", based on that falloff (which could be useful in some cases). At least, the case I would use this for would need this, in any case.
@PierreSoubourou
@PierreSoubourou 3 года назад
Thanks for showing quite large text (for those like me watching on a phone)
@nixonian1
@nixonian1 5 лет назад
If you go to new Project/Windows Desktop Wizard/Applicationtype:Console Application you can create a truly blank console app without the precompiled headers. Just uncheck those and check empty project.
@javidx9
@javidx9 5 лет назад
lol, Im fairly certain youve told me this before XD - I'm just so set in my ways - It's like its built in "delete auto generated stuff"
@marcusotter
@marcusotter 5 лет назад
"This is the very latest version of Visual Studio" *Yellow update flag in the top right corner* Loved the vid!
@javidx9
@javidx9 5 лет назад
lol thanks Marcus!
@bovineox1111
@bovineox1111 2 года назад
I love the mood that line of sight brings to a game. I was just looking to see if there was some other way. My own Unity based solution does some math on a shadow structure to cast the shadow onto a render texture achieving much the same result but using this in my shaders everywhere to pick visibility based on the LOS. It's pretty good but I was wondering about system that can be more efficient, less gpu\memory bound.
@heylittleguy26
@heylittleguy26 3 года назад
1:28 I know this means nothing, but this is the exact frame used in the thumbnail.
@guacamolen
@guacamolen 5 лет назад
Great video--you always put out amazing stuff. Do you have any pointers on limited line of sight, such as a flashlight with a limited angle or a softer light that doesn't extend to the edges of the screen? Or at least where to begin my research into the topic?
@javidx9
@javidx9 5 лет назад
Hi Micheal, thanks buddy. yes you can do both by adding fake edges in the shape you need around your light source before casting.
@jimboli9400
@jimboli9400 4 года назад
javidx9: **posts detailed step by step raycasting engine** **gets 34K views** Random dude: **posts 'How to ddos' free python script** **gets millions of views** RU-vid this isnt fair :(
@thecrazyinstitute1680
@thecrazyinstitute1680 4 года назад
.
@gatedrat6382
@gatedrat6382 4 года назад
RU-vid is an algorithm that doesn't care about fairness
@botteu
@botteu 2 года назад
Great video ✨ I found this while trying to find out if it’s possible to do ray casting against arbitrarily shaped pixel formations. Like the terrain in Worms for example or if I were to draw a bit of terrain in a bitmap editing software where transparent pixels mean “pass through” and black pixels mean “solid”. Is it possible then to cast rays and find out what the normals of the terrain is at different points? I can figure out how to do it with a polygon etc but not with an arbitrary pixel shape. Maybe I could use something like marching squares to make a polygon out of the pixels?
@jackpret4547
@jackpret4547 5 лет назад
Neat!
@javidx9
@javidx9 5 лет назад
Thanks Jack!
@phynx-victumterra652
@phynx-victumterra652 4 года назад
I use a rather crude version of this in my game and would upgrade to something closer to this however I need to optimize it quite a bit, one of the reference articles talk about using a sweeping ray to detect the closest line segments and only use those segments for the rest of the algorithm. I need to figure out to implement that optimization but not quite sure where to start, any ideas?
@cheako91155
@cheako91155 5 лет назад
For edge_id[] and edge_exists[] you could use struct(s) instead and if u ever need to index them u can just use a pointer. Also i think these could be one uint where edge id 0 is no edge.
@DamienFromPoison
@DamienFromPoison 5 лет назад
Hey there, great video as always. I am just wondering, would this stuff not be a bit easier, if you use the points of the lines facing the player and then cast rays from these points to form a quad. Like in the old 3D shadow volume stuff? No sorting or line intersection would be needed and visually it should look the same. So you do not draw triangles for the visible area, you would obstruct the hidden space. But anyways, big fan :)
@javidx9
@javidx9 5 лет назад
Hi Damien, Its a perfectly valid approach. The only downside I can see is the redundancy in drawing multiple "shadow" quads that may be redundant (say an edge lies within the shadow of another edge) - certainly worth experimenting with anyway.
@cheako91155
@cheako91155 5 лет назад
For types used to index arrays in C u should use size_t instead of int... For i, n, s, w, e in convert tile map to poly map.
@Thoracius
@Thoracius 4 года назад
Is casting three slightly dispersed rays at eat intersection point more efficient than checking for each intersecting point whether the opposite points of both segments lie on the same side of the ray? (if so, then you know the triangle on the opposite side extends past the point.)
@kalejaneth2457
@kalejaneth2457 3 года назад
When you copy-and-pasted the code to make similar blocks of code just after 23:44 , would it be better to "abstract it away" with a function with some parameters, or would the function possibly be harder to read/understand, or harder to implement, or even perform worse than the direct but long approach?
@kpopalitfonzelitaclide2147
@kpopalitfonzelitaclide2147 5 лет назад
you need more subs how have you only got 16k I could see you having 1 mill subs
@javidx9
@javidx9 5 лет назад
Lol thanks Homie! I appreciate that. I guess ive never really pushed the channel anywhere!
@davep7176
@davep7176 Год назад
If you can combine this effect with your Orthographic Dungeon code, this would be crazy
@conandoyle1859
@conandoyle1859 5 лет назад
я не знаю английский язык, но мне интересно смотреть твои видео!
@sirknight1291
@sirknight1291 5 лет назад
Instead of iterating through the whole array you can just check the newest block when its added. That should increase the performance in bigger maps.
@javidx9
@javidx9 5 лет назад
Absolutely Sir Knight, in fact there are many additional optimizations one can perform here. Block removal gets a bit more complex though!
@TheVersatilefungus
@TheVersatilefungus 5 лет назад
Hey Javid, thanks for another great video. Is there any chance of doing a tutorial video on voxel game design at some point?
@javidx9
@javidx9 5 лет назад
Hi Versatil Fungus and thanks! Im not interested in doing voxels the expected/conventional(?) way (i.e. yet another minecraft clone) so if I can think of a more interesting vehicle to demonstrate them then I will. After all, voxels have been around waaaay longer than minecraft so it shouldn't be too difficult ;)
@TheVersatilefungus
@TheVersatilefungus 5 лет назад
@@javidx9 I wasn't thinking so much like a Minecraft clone. More in a sense to make destructible objects with physics. Something similar to this perhaps: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-TvKhYH9RDHg.html
@prajjwalpathak2718
@prajjwalpathak2718 3 года назад
Hello sir, I was following your tutorial and implementing it in python, but got stuck at the point where you sorted the vector. I wanted to know how was it sorted ( I don't know C++ ), as t1 and t2 are float values while vecVisibilityPolygonPoints is a vector or list in python
@beyondcatastrophe_
@beyondcatastrophe_ 5 лет назад
To improve the raycasting, can't you create a new list with only the edges in a certain radius. That should make calculations faster (at least for larger maps)...
@javidx9
@javidx9 5 лет назад
You are correct! There are several ways to optimise this, but certainly this is one of the simpler ones. Checking if points are within a radius can be fiddly to though (obviously the check is simple, but you dont want to have to check all points)
@callumjohn6622
@callumjohn6622 4 года назад
The sudden change in audio quality and volume made me audibly jump.
@jakubsebek
@jakubsebek 5 лет назад
Can you please explain why is it faster when you set the realease mode?
@javidx9
@javidx9 5 лет назад
Hi Jacob, in debug mode, the compiler adds all sorts of additional code behind the scenes so you can debug your program, i.e. hooks and variable information that the debugger can display. Other things it checks for is going out of bounds on arrays, stuff like that. In release mode, it will not do any of these things, so its much higher performance
@jakubsebek
@jakubsebek 5 лет назад
@@javidx9 thx
@chris_burrows
@chris_burrows 3 года назад
Does anybody understand why the ray sweep optimization (not covered here) is faster and how it works???
@user-kf1xn1dq9t
@user-kf1xn1dq9t 3 года назад
> In this (long, sorry) video ... It explained everything clearly, so its okay.
@unveil7762
@unveil7762 Год назад
can you just store the postion of each box... than check if there are shared edge, if yes delete them and sum the rest by checking the y or the x position so you know where to connect them ... if no share make all four bounds...
@dstri1
@dstri1 4 года назад
Hello, i love the way you are vast in your knowledge. I admire you... And also wants to learn. Please can you recommend good books in graphics physics and maths that are relevant to software development.
@androth1502
@androth1502 5 лет назад
great demo. just wanted to point out that the mouse coordinates don't work for the Y axis using 2x2 pixel width/height on my laptop. it works using 1x1 pixels. this is likely due to the odd wide screen format of my display which is 1366x768. it works normally on another pc with a more standard display mode. i suspect it's due to a loss of precision in converting from float to int because a quick test showed me that 2.9 is being rounded down to 2 instead of rounding to 3 and we're off by an entire row.
@javidx9
@javidx9 5 лет назад
Hi androth, rounding down in this instance is actually desirable. The mouse coordinates become inaccurate if you resize the window, or use a window manager that resizes it for you. Are you running on linux?
@androth1502
@androth1502 5 лет назад
@@javidx9 i'm running windows 10 on both systems. the same code works on my desktop, but not on my laptop. the only thing different between these two is the display resolution. i'm trying to figure out why i'm losing more rows precision the further down i click in the window, and why if i switch to 1x1 pixels, the problem goes away. sorry, i'm coming from C#/WPF. haven't looked at C++ in over 10 years :) edit: i think it's because windows is resizing my window. the program needs 800 pixel screen height and my laptop maxes out at 768. i figured windows would just create the full size window and allow it to extend beyond the screen.
@javidx9
@javidx9 5 лет назад
What size window are you creating?
@androth1502
@androth1502 5 лет назад
@@javidx9 same as in your program, 640x400, but with 2x2 pixels, it's really 1280x800. i think that is the issue, it just didn't register in my brain. i guess i'm getting slow in my old age. anyway, i appreciate what you're doing here. i made something very similar (win32/linux gui library) in assembly language over a decade ago, but never took it beyond demo.
@javidx9
@javidx9 5 лет назад
Lol its ok androth. Sometimes just need a fresh pair of eyes! I currently dont support normalised coordinates so resizing the screen introduces mouse weirdness.
@ianmarshall3310
@ianmarshall3310 5 лет назад
Can you explain faster raycasting with tan and grid intersection in the next video?
@javidx9
@javidx9 5 лет назад
Hi Ian, Funnily enough Ive been thinking about this in the context of the First Person Shooter video - I'll see what I can do for the next one.
@beaconofwierd1883
@beaconofwierd1883 2 года назад
Thought this video would talk about how to optimize which points to cast from when some are shadowed by other points :(
@EvilStreaks
@EvilStreaks 4 года назад
I watched this, looked at that site, and made my own version. It appears to behave perfectly but casting shadows at certain angles causes a glitch where ther radial order of the vertices changes. No clue what I'm doing wrong...
@EvilStreaks
@EvilStreaks 4 года назад
Fixed. The coordinates of the vertices had to be floats
@mrferret980
@mrferret980 5 лет назад
which video is "here" where you explained the edge grouping algorithm? XD
@fredg8328
@fredg8328 5 лет назад
nice
@javidx9
@javidx9 5 лет назад
Cheers Fred!
@fredg8328
@fredg8328 5 лет назад
I never wrote a complete code to do this, but a wrote an article on my website to answer a question of somebody on FB some time ago, that was talking about raycasting and shadow polygons. fredericgoset.ovh/informatique/divers/en/raycast.html
@robertboran6234
@robertboran6234 5 лет назад
There is nothing better then wake up an feed the brain.
@javidx9
@javidx9 5 лет назад
I agree entirely Robert XD
@davidkozak9959
@davidkozak9959 2 года назад
How would the mechanics change if the edge geometry was planometrically isometric circular bodies w circular edges (or cylindrical if 3D) instead of square? E.G. Assume each cubed grid point embodied a scattered set of circular bodies contained with each isometric grid point...
@stonekase
@stonekase 5 лет назад
@javidx9 don't you think this "int w = (y + sy) * pitch + (x + sx - 1); // Western Neighbour" has a potential to cause confusion for newbies like me as there is an argument with the same name "w" in the same function. I know it is local but considering someone trying this tutorial out for the first time. A GREAT TUTORIAL TO BE HONEST
@javidx9
@javidx9 5 лет назад
Hey Akawo, you are correct in this regard - a bit lazy of me to not use a different name, to be fair, I just didnt notice :D
@Bunny99s
@Bunny99s 4 года назад
I have never used or looked into your PixelEngine but doesn't it support texture mapping when drawing the triangle fan? If it does, showing the sprite would be just a matter of assigning proper texture coordinates to each vertex. At least that would be my first approach -.-
@haudiweg
@haudiweg 4 года назад
I have programmed a game i have a invertet version from your code and without rays(but im not finished)
@flobuilds
@flobuilds 5 лет назад
Can you extend this project and add some antialiasing? That would be so awesome to see what the windows console can realy do and it would look so much better with that smoothing effect.
@javidx9
@javidx9 5 лет назад
Hi Bluestroker, just to avoid confusion, this is not rendering using a windows command prompt anymore (though the code could be ported to ConsoleGameEngine quite easily). I hope to do a video about various image processing techniques soon - I have already experimented with blurring algorithms for soft shadows and they look awesome.
@flobuilds
@flobuilds 5 лет назад
@@javidx9 ok that's awesome. I love this c++ code
@Cinicraft00
@Cinicraft00 4 года назад
This is what was used in Diablo 2
@NonExistChannel
@NonExistChannel 5 лет назад
There is a much simpler way doing the same thing and at the same time achieving global illumination: A 2D-Pathtracer
@chris_burrows
@chris_burrows 3 года назад
Go on...
@williankoessler5935
@williankoessler5935 5 лет назад
PGE
@javidx9
@javidx9 5 лет назад
Totally
@OddStare
@OddStare 4 года назад
I would like to do this in 3d but how do you keep a pool of corners in 3d ?
@javidx9
@javidx9 4 года назад
It would just be the 3d vertex no?
Далее
What Are Pointers? (C++)
41:55
Просмотров 559 тыс.
Super Fast Ray Casting in Tiled Worlds using DDA
30:03
Просмотров 175 тыс.
КТО ЭТО БЫЛ?
25:31
Просмотров 309 тыс.
Рыбачка
00:14
Просмотров 15 тыс.
2D Sprite Affine Transformations
27:59
Просмотров 33 тыс.
Tinkering With Spirographs in C++
22:01
Просмотров 11 тыс.
Creating SMART enemies from scratch! | Devlog
5:40
Просмотров 279 тыс.
Convex Polygon Collisions #1
36:40
Просмотров 126 тыс.
How I Implemented Shadows in my Game Engine
7:45
Просмотров 94 тыс.
Procedural Generation: Programming The Universe
41:57
Просмотров 203 тыс.
How Your Computer Draws Lines
4:26
Просмотров 173 тыс.
Wolfenstein 3D's map renderer
14:49
Просмотров 272 тыс.
Every 2D Node Explained in 9 Minutes !
9:19
Просмотров 275 тыс.
Asus  VivoBook Винда за 8 часов!
1:00
Просмотров 1,2 млн