#23528 - Mr. GBA - Wed Jul 14, 2004 5:55 pm
Hi,
I've just started working on some 3D ray casting effects. I am able to render the world, but I need help on applying textures to the walls which are constituted of 64x64x64 units.
The only thing that has been of help is this page: http://www.permadi.com/tutorial/raycast/rayc10.html
Please can someone help me texture a 64x64x64 wall using ray casting?
Thanks in Advance.
_________________
my dev/business site:
http://codebytesdev.afraid.org
#23558 - sajiimori - Thu Jul 15, 2004 6:11 am
Try here: http://www.gamedev.net/reference/articles/article872.asp
Edit: after reading the scaling portion, I'm convinced that their implementation is wrong and will result in a lockup. Without testing, I think this is closer to what they had in mind:
Code: |
#define SCREEN_HEIGHT 160
#define TEXTURE_HEIGHT 64
#define int2fix(x) ((x) << 16)
#define fix2int(x) ((x) >> 16)
void plot_pixel(int x, int y, Color c);
void draw_column(int x, int height, Color* texture_strip)
{
int i, y = SCREEN_HEIGHT/2 - height/2;
fixed scale = int2fix(TEXTURE_HEIGHT) / height;
fixed offset = 0;
for(i = 0; i < height; ++i, ++y)
{
int texture_offset = fix2int(offset);
plot_pixel(x, y, texture_strip[texture_offset]);
offset += scale;
}
}
|
#23580 - ecurtz - Thu Jul 15, 2004 4:44 pm
You can grab a somewhat old version of my raycaster code from here:
ftp://ftp.nuprometheus.com/pub/ARMode5/
That code has been up for a while so I'm not sure exactly what state it is in. It should have an uncommented and hard to understand texturing routine. (Actually it isn't that complex, you determine what column of the texture you're in based on where you hit the base of the wall. Then you move up the texture at a fractional pixel amount based on how far away/tall the wall is.)
#23583 - Mr. GBA - Thu Jul 15, 2004 6:40 pm
Thanks for the help guys, but I'm still stuck...
From your help I have the following code so far (my texture image is 64*64):
int offset = (int)VAy%64; //offset to texture pixel
int scale = 64 * ((s32)VerticalLength/64); //texture width * distance to wall/wall height (which is also 64)
int g = 0; //variable which is incremented by scale
for(int bloop=start; bloop <end; bloop++) //start and end define the length of the column for the wall
{
videoBuffer[where] = WallTextureData[x+g]; //videobuffer[where] = slice/column in VRAM and WallTextureData is the image
videoBuffer[where+1] = WallTextureData[x+g+120];
where += 120; //mode 4 so + 120 to go down Y axis
g +=scale;
}
Any help would be much appreciated.
Thanks in Advance.
_________________
my dev/business site:
http://codebytesdev.afraid.org
#23607 - sajiimori - Fri Jul 16, 2004 3:47 am
Have you done solid-fill rendering yet? Make sure that works before you continue. Also, post code using the code tags, say what each of your variables is for (including VAy), and use #defines instead of magic numbers (like 64 and 120).
When it's easier for us to read, it's easier for us to help you. ^_^
#23622 - Mr. GBA - Fri Jul 16, 2004 11:37 am
sajiimori wrote: |
Have you done solid-fill rendering yet? Make sure that works before you continue. Also, post code using the code tags, say what each of your variables is for (including VAy), and use #defines instead of magic numbers (like 64 and 120).
When it's easier for us to read, it's easier for us to help you. ^_^ |
Yes, I have done solid filling and everything else preceding the creation of walls is fine. I'm just stuck on the texturing of the walls.
I won't further embarrass myself by posting flimsy code that isn't even well annotated. Instead I'll tell you where I'm stuck. I am stuck on chapter 10 of the Permadi tutorial (http://www.permadi.com/tutorial/raycast/rayc10.html
). Evertything up to chapter 10 in these tutorials, I have coded and it works fine. I just need extra help texturing the walls because this part of the tutorial seems a little brief.
Thanks.
_________________
my dev/business site:
http://codebytesdev.afraid.org
#23633 - ecurtz - Fri Jul 16, 2004 4:26 pm
It looks like you need to be using fixed point math for 'scale' and 'g'. 'g' is the amount of pixels you've moved along the texture, but if you aren't shifting it at all then you don't have any accuracy for your step.
Also the +120 in the texture pointer for the second pixel plotted doesn't make sense. That may be the offset for the screen, but it isn't the offset to the next row in your texture, which is only 64x64.
If you have solid textures working why don't you try going to a striped texture next and seeing if your logic for determining the texture column is correct. (i.e. paint the whole column the color of the first pixel you look up.)
#23663 - Mr. GBA - Sat Jul 17, 2004 7:17 pm
ecurtz wrote: |
It looks like you need to be using fixed point math for 'scale' and 'g'. 'g' is the amount of pixels you've moved along the texture, but if you aren't shifting it at all then you don't have any accuracy for your step.
Also the +120 in the texture pointer for the second pixel plotted doesn't make sense. That may be the offset for the screen, but it isn't the offset to the next row in your texture, which is only 64x64.
If you have solid textures working why don't you try going to a striped texture next and seeing if your logic for determining the texture column is correct. (i.e. paint the whole column the color of the first pixel you look up.) |
Thanks for highlighting the mistakes in my flimsy code. But even with the alterations, the texture mapping still doesn't work.
I've tried the striped texturing, which you suggested and my ray caster handles it well.
I have come close to texture mapping the 64x64 walls, but I think I'm still going wrong on the scaling of the texture image to fit the wall. I've tried endless permutations of formulas and nothing works so, I'm starting to think that this topic is slightly beyond me.
I'm still in need of help from anyone who knows how to texture a wall rendered using ray casting.
Thanks.
_________________
my dev/business site:
http://codebytesdev.afraid.org
#23670 - sajiimori - Sun Jul 18, 2004 5:41 am
Do you understand the algorithm? All you have to do is calculate how far you're moving down the texture each time you move down a pixel on the screen. Since that will usually not be a whole number, you use a fixed point variable.
Try drawing some pictures to illustrate the process for yourself. Also try implementing just the scaling routine on your PC, using a float for the scale variable to make things easier. Just take a single strip of pixels and try to scale it on the screen.