Page 3 of 3
Re: Cool ideas for a modern 2D system.
Posted: Tue Apr 07, 2015 7:14 pm
by Drew Sebastino
I'm not even going to lie, but I've never really understood what raycasting is or how it works. Is it no more "3D" than scaling and rotating sprites or mode 7 style BGs?
Re: Cool ideas for a modern 2D system.
Posted: Tue Apr 07, 2015 8:15 pm
by pops
Ray casting is a variant of ray tracing. Ray tracing requires that you trace a ray from the camera viewpoint to the level geometry for each pixel in the viewport. This is computationally expensive (640x480 = ~300k rays!). However, if we constrain the camera viewpoint so it is unable to rotate about the z-axis, and we constrain the level geometry so all walls are at 90-degree angles to flat surfaces (floors, ceilings, etc), then we need only cast one ray for each pixel in the x-dimension of the viewport. For a viewport of 640x480, this is a 480x reduction in rays cast.
It's easier to explain in motion, and I couldn't hope to explain it better than this website:
http://fabiensanglard.net/doomIphone/do ... nderer.php
Re: Cool ideas for a modern 2D system.
Posted: Tue Apr 07, 2015 8:34 pm
by tokumaru
That being said, it's important to note that Doom uses neither ray casting nor ray tracing.
Re: Cool ideas for a modern 2D system.
Posted: Wed Apr 08, 2015 4:53 am
by pops
toku is right, and I'm mistaken. Wolfenstein-3D uses ray casting. Doom, on the other hand:
The Doom engine renders the walls as it traverses the BSP tree, drawing subsectors by order of distance from the camera (that is, the closest segs are drawn first). As the segs are drawn, they are stored in a linked list. This is used to clip other segs rendered later on, reducing overdraw. The list is also used later to clip the edges of sprites. ...
Once the engine reaches a solid (one-sided) wall at a particular X coordinate, no more lines need to be drawn at that area. As this occurs, the engine builds up a "map" of areas of the screen where solid walls have been reached. This allows distant parts of the level, currently invisible to the player, to be clipped completely.
http://doom.wikia.com/wiki/Doom_rendering_engine
Re: Cool ideas for a modern 2D system.
Posted: Wed Apr 08, 2015 6:11 am
by tepples
The Build engine, used for
Duke Nukem 3D, uses "portal casting", which traverses a network of sectors that are connected to adjacent sectors and rejects any sector obscured by the walls of closer sectors. If portal casting were applied to the square grid world of
Wolfenstein 3D, it'd look like the
GIF I posted here. Replace the square grid with arbitrary polygons and you have Build.
Re: Cool ideas for a modern 2D system.
Posted: Wed Apr 08, 2015 9:04 am
by ShaneM
To hyperlink, simply do (url)link_here(/url) replacing the ()s with []s. So, it becomes:
http://doom.wikia.com/wiki/Doom_rendering_engine
I hope this was helpful.

--ShaneM, the Master of ASM
EDIT: Or, simply hit the "
URL" button at the top adjacent to "Message body:".
Re: Cool ideas for a modern 2D system.
Posted: Wed Apr 08, 2015 1:14 pm
by Sik
Espozo wrote:I really don't get it, but why would having triangles be any better than squares?
Forget about how Doom does it, with triangles you can get arbitrary 3D meshes (and they're
much easier to compute than any other kind of filled primitive), plain and simple. (also the Lynx does quads to some extent too, which is how you render sprites normally in fact)
In any case my point being that arbitrary 3D meshes are better than restricted 3D engines no matter how you look at it =P (provided you have enough performance)