• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
zacaj

Help with floorcasting

5 posts in this topic

Been trying to make a little textured raycaster for fun the past few days.  Walls went fine, but I hit a wall when it came to floor texturing.  No idea how to do it.  So I found http://lodev.org/cgtutor/raycasting2.html , and I was able to adapt their floorcasting code quite easily.  It worked, except that it couldn't handle it when I changed the camera height.  Looking at their section on computing the 'currentDist' (from current pixel to floor, I'm assuming vertically), none of what they say makes any sense.

 

 

The distance the projection of the current pixel is to the floor can be calculated as follows:
  • If the pixel is in the center of the screen (in vertical direction), the distance is infinite.
  • If the pixel is at the bottom of the screen, you can choose a certain distance, for example 1
  • So all the pixels between those are between 1 and infinite, the distance the pixel represents in function of it's height in the bottom half of the screen is inversely related as 1 / height. You can use the formula "currentDist = h / (2.0 * y - h)" for the distance of the current pixel.
  • You can also precalculate a lookup table for this instead, since there are only h / 2 possible values (one half of the screen in vertical direction).

"the distance from a pixel in the center of the screen to the floor is infinite"  What?

"for the bottom of the screen, you can choose a distance" I'm assuming this would be where my camera elevation goes in

"for example, 1" oh, thank god they chose 1 as their magic number.  It's not like that ever comes up anywhere else

"the distance the pixel represents in function of it's height in the bottom half of the screen is inversely related as 1 / height."  that wasn't even proper english.  Plus, when they say 'inversely' and then use 1/x I assume the 1 is from standard math, but it's the only place on the page where they make any reference to the camera height which they so helpfully chose as 1 earlier.

"you can use this formula" no explanation on how they got that, or anything.

 

Is it even possible to have different camera elevations with this technique?  

0

Share this post


Link to post
Share on other sites

"the distance from a pixel in the center of the screen to the floor is infinite" What?

This makes sense when you assume the ceiling or floor is not at the same height as your camera. The exact center of the screen would be the point where the ceiling or wall touch the depth axis (e.g. 'Z'), but they don't, so the distance where the screen center meets the floor is... infinitely far away.
But there is no vertical center of the screen if you have an even number of pixels in the vertical dimension... not sure why the guy brings that up at all.
If his explanation for some of the things are confusing, try to figure it out yourself.

"You can also precalculate a lookup table for this instead, since there are only h / 2 possible values (one half of the screen in vertical direction)."

This is true, if he means the difference of distance (e.g. Z coordinates if Z is your depth axis) from one horizontal row of the screen to the next, or easier for later use, the difference to the bottom row, i.e. if you assume you would draw your floor completely from bottom row of your screen to the "center" row, each next row will be a bit further away. And since this sort of rendering has the restriction that you cannot look up/down and thus all floor / ceiling planes are parallel to your viewing direction, you have constant-height all over e.g. a floor plane. So you can make a table for each row from bottom to center, holding the difference in depth from bottom row. When rendering, you have to add those to e.g. the actual depth value of your bottom row which you calculate based on current camera height. So, you quickly have the real current depth values for each row.

You also need to rotate your floor plane based on camera angle. Then, if you go row by row, e.g. from bottom to center for the floor, imagine each row is layed on the rotated floor plane, at a start and end positions (first and last pixel of current row) which you determine with the camera position on the floor plane, and the rotation. So to say, actually you rotate those points about the inverse camera angle, not the floor itself.
Then when you move along the pixel row, from first to last pixel, you can compute where on the floor plane the current pixel would "hit", and thus compute the current texture index (assuming you have some grid specifying what texture some "cell" of floor has) and texture coordinates.
If you draw sketches of that on paper, you'll see how this works I hope, I can't draw anything here right now.

Hope this makes sense ^^

1

Share this post


Link to post
Share on other sites

ah, and also note that, when drawing a row, you don't have to compute each pixel's floor coordinate the expensive way you compute the start,end pixel's coords. Because of the geometrical and camera orientation restrictions making your floor constant height for one render frame, also, your depth value for that frame is constant over the whole row of pixels. So you can just linearly step from start pixel's tex coord to the the end pixel's, by adding a delta vector each next pixel of the row, of the length (end - start) / pixels_per_row.

This all assumes always the whole lower screen half is drawn as floor, and the walls then on top, having overdraw up to a factor of 2. If you don't want to run that on spme weak machine, you can probably afford that, otherwise things get more complicated.
I haven't looked intensely at how the tutorial guy does this... but I'd rather not dig through his code ;)

If this is all confusing, I could draw some things later.

0

Share this post


Link to post
Share on other sites

Ah!  When he was saying "the distance from the projected pixel to the floor" I thought he meant vertical distance!  That makes all of his code make sense, even if I still can't get the floor to render right when I change the camera height.  (I've got it working fine for z=0)

 

In his tutorial, he renders the floor in vertical spans above and below the wall sections, computing for every pixel.  You seem to be suggesting that I do floor spans horizontally?  Wouldn't that mean I'm going to need some kind of complicated algorithm to figure out the horizontal spans, since the walls are all drawn vertically?

0

Share this post


Link to post
Share on other sites

Heh you're right, what I suggested was just shrugging off the overdraw, if you can afford it.
You'll have to see what's faster... Since each horizontal line is constant-Z and you can just step through the texcoords linearly.
This does not work vertically, but since if you make those tables spoken of earlier, it might be similarly fast... I was thinking too much 3D earlier and thinking of perspective correct floor rendering as more expensive vertically, but that way it probably isn't ^^

Makes sense to just draw the spans vertically then along with the walls, yeah.
You should be able to have different camera heights, at least with what I have in mind, but I haven't looked at the guys exact implementation. 

0

Share this post


Link to post
Share on other sites

Btw., I guess it wouldn't be too compicated to do it horizontally. If you track, for each horizontal position of the screen, the top and bottom positions of all walls if you render them first, when drawing e.g. the ceiling afterwards you'd just need to run through the buffer for the top positions. You find the spans of current scanline by finding the highest positions (intersecting the current scanline) on left and right side of each "valley" in the buffer, one after another...

Back then I just drew floor and ceiling completely, horizontally, and painted the walls over it, it still ran sufficiently fast on my K6 200 or so, not at very high resolutions, granted ^^ It's luxurious for wolfenstein, but my goal back then was not to really do much with it game wise.

 

Btw., on today's PCs this may run faster if you use 32bit pixel format, not 8bit or what this old stuff uses...

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0