Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: HeirOfNorton on Fri 09/09/2005 06:56:25

Title: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Fri 09/09/2005 06:56:25
Well, here's what I have so far. It's far from perfect, but it does what it's supposed to do (mostly).

They say a picture is worth a thousand words, so...

(http://show.imagehosting.us/show/673535/0/nouser_673/T1_-1_673535.JPG)

(http://show.imagehosting.us/show/673540/0/nouser_673/T1_-1_673540.JPG)

Those really are screenshots from AGS. Honest.

This is a modified version of Steve Mcrea's Ags3d script module. The major additions are:

++ New Wall primitive (a flat polygon)
++ Texture mapped walls and primitives
++ The ability to modify those textures with scale and offset, etc.
++ Sky box and sky texture (check out the moon in the town square)
++ Sector-based culling and optimization*.

* What this means is, you designate sectors in the 3d world, and the primitives will only be drawn if they are in the same sector as the player. This won't help with outdoor scenes like the town square, but for complex indoor scenes (halls and rooms) it can really speed things up. (Want to see the difference? Turn it OFF in the new example room and watch the frames per second disappear.)

I did not add a HUD or weapon to the script module. I did, however, add a weapon in the new demo room using a dummy character, and hopefully it shouldn't be too hard to figure out how to do it yourself.

This is still a beta version. Several bugs and errors still in it, and the code could use cleaned up and comments, but here it is to see what you can do. This zip file only contains the source files, not a compiled version, so you will need to compile it (ctrl-s) with AGS 2.71beta5 or higher.

Download it here (http://www.americangirlscouts.org/agsuploads/files/ags3dplus.zip). Thanks to www.americangirlscouts.com for the file hosting.

Whatcha think?
Title: Re: AGS3D + Texture Mapping alpha
Post by: Rui 'Trovatore' Pires on Fri 09/09/2005 11:22:53
I noticed you disallowed mouse-looking up and down. Is that necessary?
Title: Re: AGS3D + Texture Mapping alpha
Post by: Kweepa on Fri 09/09/2005 14:46:17
Yes. Yes it is.

The sky texture really adds to the scene I must say.

As for your texture mapper, that's nice work. It just needs to be perspective correct. You can linearly interpolate 1/z across the wall, then to get the appropriate column, calculate z from 1/z and interpolate the column values at left and right.
In other words, start with z_left, c_left, z_right, c_right, x_left (pixels), x_right (pixels).
Then:
ooZ_left = 1.0/z_left;
ooZ_right = 1.0/z_right;
ooZ_inc = (ooZ_right - ooZ_left)/(x_right - x_left);

ooZ = ooZ_left;
loop over x (pixels)
  ooZ += ooZ_inc;
  z = 1.0/ooZ;
  c = c_left + (c_right-c_left)*((z - z_left)/(z_right - z_left));

You need to be careful when z_right == z_left.
In that case, just go linearly.

[EDIT]
Just before the main render loop

  if (renderWidth == 0) return;
 
  float z_left = clippedZ[0].z;
  float z_right = clippedZ[1].z;
  float ooZ_left = 1.0/z_left;
  float ooZ_right = 1.0/z_right;
  float ooZ_inc = (ooZ_right - ooZ_left)/IntToFloat(renderWidth);
  // bring in the tex coords by half a pixel
  float c_left = 0.0 + 1.0/256.0;
  float c_right = 1.0 - 1.0/256.0;
 
  float ooZ = ooZ_left;
 
  //the main rendering loop
  i = 0;
  while (i < renderWidth)
  {
    float z = 1.0/ooZ;
    ooZ += ooZ_inc;


Just before the "colToRend" calculation

    if (z_right != z_left)
    {
      texFraction = c_left + (c_right - c_left)*(z - z_left)/(z_right - z_left);
    }


You might need to flip left and right when behind the texture, and tweak c_left and c_right to get the right hand column of the texture map to show up all the time.
Title: Re: AGS3D + Texture Mapping alpha
Post by: Gregjazz on Sat 10/09/2005 00:28:16
The download link does work. :(

In fact, http://freefilebin.com does work. I'll try later, I guess.
Title: Re: AGS3D + Texture Mapping alpha
Post by: HeirOfNorton on Sat 10/09/2005 03:00:23
Quote from: SteveMcCrea on Fri 09/09/2005 14:46:17
As for your texture mapper, that's nice work. It just needs to be perspective correct.
(... Steve's suggestions snipped)


Wow. That's a LOT simpler than what I was trying to do, and unlike my version, yours WORKS. :o I bow to your obvious superiority. (In my own defense, I have always hated math and am usually quite terrible at it.)
I'm going to tweak it to work in a few options I wanted, and make a room that shows off the texture-mapping, Then, as soon as I can find a file-hosting server that will STAY UP for more than three hours >:(, I'll upload a new version.
Thanks for the help, Steve

HoN
Title: Re: AGS3D + Texture Mapping alpha
Post by: Kweepa on Sat 10/09/2005 03:09:01
Oh, so you don't need my edit then :=
Title: Re: AGS3D + Texture Mapping alpha
Post by: TheYak on Sat 10/09/2005 09:17:46
It's awfully daft of me to try, but this version doesn't run in conjunction with AGS MacRuntime.
Error: run_text_script1: error -6 running function 'game_start':
Error: invalid instruction 69 found in code stream
in Ags3d with Texture Mapping (line 315)
from Global script (line 17)
Title: Re: AGS3D + Texture Mapping alpha
Post by: scotch on Sat 10/09/2005 09:50:45
You know there is an upload place for AGS games, right?  It is generally for proper games, but stuff like this is also fine. http://www.americangirlscouts.org/agsuploads/
The work on AGS3d never ceases to amaze.
Title: Re: AGS3D + Texture Mapping alpha
Post by: Pumaman on Sat 10/09/2005 13:28:13
Quote from: YakSpit on Sat 10/09/2005 09:17:46
It's awfully daft of me to try, but this version doesn't run in conjunction with AGS MacRuntime.

That'd be because this was compiled with 2.71 beta 5 and the Mac runtime is currently beta 3.

Great work by the way, the sky texture really does add something to the scene :)
Title: Re: AGS3D + Texture Mapping alpha
Post by: TheYak on Sat 10/09/2005 13:38:44
There's really that much difference in scripting commands in beta 5?  I tend to stay away from the betas as they always give me chlamydia.

So, are there height coordinates that are kept track of?  The performance was grand (>/= 33fps) except when causing clipping errors (>/= 22fps).  Fun was ruined when I fell off the world and wasn't greeted with an inspiring death scene.
Title: Re: AGS3D + Texture Mapping alpha
Post by: Kweepa on Sat 10/09/2005 19:49:44
Quote from: Pumaman on Sat 10/09/2005 13:28:13
That'd be because this was compiled with 2.71 beta 5 and the Mac runtime is currently beta 3.

It didn't work with the mac runtime anyway. RawDrawImage doesn't draw sprites that aren't the same resolution as the screen, and the mac version promotes the screen from 16 bit to 32 bit. :'(
Title: Re: AGS3D + Texture Mapping alpha
Post by: HeirOfNorton on Mon 12/09/2005 01:16:25
Quote from: SteveMcCrea on Sat 10/09/2005 03:09:01
Oh, so you don't need my edit then :=

Well, I'm certainly INTERESTED in your edit, if there's any more to it than what you posted here. Right now I'm working on cleaning up the code, adding some more features (not all of them directly related to texture-mapping), and creating a demo room to show it all off. I've got tonight free to work at it, so I'll post it sometime tonight or tomorrow.

HoN
Title: Re: AGS3D + Texture Mapping alpha
Post by: Kweepa on Mon 12/09/2005 04:44:58
No, just what you see... (I did edit my post up above there).
Title: Re: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Fri 16/09/2005 03:05:10
Bump for new version, eager to hear everyone's thoughts.

BTW Steve, if there's anything out of the modification that you would like to add to the main script module, please feel free.

HoN
Title: Re: AGS3D +PLUS+ beta
Post by: Jay on Fri 16/09/2005 04:03:12
Very impressive and exciting! I can't wait until this is finished!

As for bug reports: I noticed some sorting issues, where for instance the sky is put in front of a brick wall. There's also a blue border around some walls (seems to be the sky). And the wall on the right-hand side of the stairs renders weirdly.
This screenshot (http://www.jayssite.com/misc/AGS3D_SCREEN.PNG) shows the weirdly-rendered wall by the stairs as well as the blue border.

I couldn't go back into the FPS Alley after I left because of this error:
Error: run_text_script1: error -6 running function 'room_a':
Error: Array index out of bounds (index: 10, bounds: 0..9)
in Ags3d +PLUS+ (line 3471)
from Room 3 script (line 413)
Title: Re: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Fri 16/09/2005 04:28:57
Whoops!
I always miss the obvious little stuff.  ::) In this case, I forgot to reset one of the variables. I'll fix it for the next version, but mean time you can fix it yourself by adding the following line:


  sectors[numSectors-1].numCubes = 0;


at line 3464 of the script module.

HoN
Title: Re: AGS3D +PLUS+ beta
Post by: Gregjazz on Fri 16/09/2005 05:29:09
Pretty f'n cool!!!

Slows down with the stairs, but I guess that's just the fact that there's no graphics acceleration in AGS, right?
Title: Re: AGS3D +PLUS+ beta
Post by: Kweepa on Fri 16/09/2005 06:34:15
Wow, it's faster than I thought!

I don't know what's up with the sorting unfortunately. I don't have a lot of time to look at it right now. And the sector stuff you put in, while cool, makes it difficult to look at the layout! :=

The stair slowdown is, I presume, because it has to sort all those stairs into the correct draw order.

Looks promising!
Title: Re: AGS3D +PLUS+ beta
Post by: Rui 'Trovatore' Pires on Fri 16/09/2005 09:17:47
Great work! Now, this is just healthy curiosity... what would I need to do if I wanted to shoot the sarge while from a bigger distance? I've mentally toyed with the idea of getting the camera's coordinates X,Z to know where the player is in AGS' terms (I assume that'd work, it works with other characters) and knowing which direction he's facing (which I guess I'd do by taking the camera's rotation... but I'll be darned if I know what I'd do with that info. Steve?) and then making a very very fast invisible object going forwards, and seeing if it colided with the Sarge internally, and so on. Would this be a viable solution?

Nothin' to it, just a plain hypothetical question from an inquisitive mind.
Title: Re: AGS3D +PLUS+ beta
Post by: Gilbert on Fri 16/09/2005 09:42:53
Amazing! But of course speed is a problem (for 2.5GHz here, at the critical spot, i.e. the stairs, is 10FPS), so it's nice for testing but when used practically we shouldn't make complicated and heavily textured scenes.

Now, it's not very good looking for the tons of texture sprites scattering around, definitely need the crop sprite feature to be implemented in the engine. (I know this had been brought up quite frequently now, I mentioned it once again to push some lazy ass to really work on it). :=
Title: Re: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Fri 16/09/2005 13:39:40
Replies in no particular order:

Rui: Theoretically you should just need to set SetLookAtRange larger, but I couldn't get it to work right, I'm looking into improving that.

Steve: You can turn off the sector stuff by commenting out the SetUseSectors line in the room script. When I post the next version, I'll have all the primitives sorted and commented as what each one is. Also, some of the sorting problems could be due to the fact that the wall primitives are completely flat, but have a scale of 1.0 thick. (If I set 'em to 0.0, that'll cause division by zero errors. Maybe if they're scaled dowm to, like, 0.0001. I'll try it.)

Gilbot: Yeah, that sprit cropping will make the editor a LOT less cluttered, and easier for others to set up.  ;D

HoN
Title: Re: AGS3D +PLUS+ beta
Post by: simulacra on Fri 16/09/2005 14:14:56
But... what will we use the 3D features for? Any ideas so far?

I am considering an old school cyberspace interface.
Title: Re: AGS3D +PLUS+ beta
Post by: Pumaman on Fri 16/09/2005 18:36:07
This is amazing stuff, I can't believe you've basically managed to recreate Wolf 3D in AGS  :)
Title: Re: AGS3D +PLUS+ beta
Post by: Scorpiorus on Fri 16/09/2005 20:10:13
Hehe, I think it's already close to Quake, in terms of level structure at least -- great work! :)
Title: Re: AGS3D +PLUS+ beta
Post by: GarageGothic on Fri 16/09/2005 20:26:19
Yes, this is certainly turning out to be an awesome 3D engine. Not quite Quake, but certainly Castle Master with optional Wolfenstein 3D areas :) I'm probably going to use the non-textured primitives for environment and then use textures for non-rotating sprites like signs etc.

Marvellous work from everybody involved.
Title: Re: AGS3D +PLUS+ beta
Post by: Scavenger on Fri 16/09/2005 22:09:29
This is truely awe inspiring. o.o I am amazed at how much you people have done in a short amount of time! Obviously, it might need a little tuning up and speed fixes (the stairs in particular... though, that's not really an issue if you don't need stairs.), but I really could see this being put into great use!

I wonder if there'd be a speed increase if the game were 8bit rather than 16bit? Probably not, since it's sorting issues slowing it down (or so I've read) Well, if you did have it in 8bit, you could have rudimentary texture animation like running water though CyclePalette... I was thinking a waterfall or something similar...
Title: Re: AGS3D +PLUS+ beta
Post by: GarageGothic on Fri 16/09/2005 22:15:18
But it shouldn't be that hard to have texture animation, should it? After all the screen is redrawn every game cycle anyway, so you would just need to set up a timer function to determine which sprite to draw at which time. But of course it would require a lot of sprites.
Title: Re: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Sat 17/09/2005 00:40:29
Texture animation shouldn't be too hard at all. Each textured 'face' has its texture set with a single function, and it should be no trouble to reset it in rep-ex (similar to how I do with the switch in the demo). Of course, yes, that IS a lot of sprit columns running around, at least until CJ adds sprite cropping...

HoN

PS, this is officially the last time I'll bring up sprite cropping. I think I've harped von it just about enough, especially since CJ has already said that it's next on his list.
Title: Re: AGS3D +PLUS+ beta
Post by: Gregjazz on Sat 17/09/2005 01:00:37
Quote from: HeirOfNorton on Sat 17/09/2005 00:40:29
Texture animation shouldn't be too hard at all. Each textured 'face' has its texture set with a single function, and it should be no trouble to reset it in rep-ex (similar to how I do with the switch in the demo). Of course, yes, that IS a lot of sprit columns running around, at least until CJ adds sprite cropping...

HoN

PS, this is officially the last time I'll bring up sprite cropping. I think I've harped von it just about enough, especially since CJ has already said that it's next on his list.

For the record, I think I could find sprite cropping useful, too.

So you're not alone or anything. :)
Title: Re: AGS3D +PLUS+ beta
Post by: Jay on Sat 17/09/2005 01:05:25
Quote from: Scavenger on Fri 16/09/2005 22:09:29
Obviously, it might need a little tuning up and speed fixes (the stairs in particular... though, that's not really an issue if you don't need stairs.),

I was thinking about the stairs, and I remembered that on Nintendo 64, stairs were usually created by making a slope with a stair-like texture on it, rather than actually creating each individual step as a cube.
Just an idea, if anyone needs it.
Title: Re: AGS3D +PLUS+ beta
Post by: Gregjazz on Sat 17/09/2005 21:12:43
Quote from: Jay on Sat 17/09/2005 01:05:25
Quote from: Scavenger on Fri 16/09/2005 22:09:29
Obviously, it might need a little tuning up and speed fixes (the stairs in particular... though, that's not really an issue if you don't need stairs.),

I was thinking about the stairs, and I remembered that on Nintendo 64, stairs were usually created by making a slope with a stair-like texture on it, rather than actually creating each individual step as a cube.
Just an idea, if anyone needs it.

Not a bad idea, come to think of it. I mean, it would probably be the best representation of stairs you could get with a low CPU load...
Title: Re: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Sat 17/09/2005 23:51:56
Unfortunately, adding stairs this way is currently impossible. In order for this type of texture-mapping to work, the surfaces to be textured have to be perfectly verticle.

HoN
Title: Re: AGS3D +PLUS+ beta
Post by: Scavenger on Sun 18/09/2005 22:39:39
(http://img305.imageshack.us/img305/8085/wtf2ul.png)
It seems sometimes only one column is drawn to the screen for a wall. Strange, no?

Question. Why are ceiling and floor textures unfeasable? I mean, there weren't either in Wolf3D... I really can't see any reason why we can't add them. I guess there is one... probably something to do with.. er.. not being able to draw the sprite at that angle? Mreh... I don't know.
Title: Re: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Mon 19/09/2005 03:35:03
Yeah, I know about that error. That one, at least, is almost certainly just a mistake on my part, I just have to find it.

As for floor/ceiling textures... This sort of texture-mapping is done by taking 'slices' of each texture and rendering them sequentially, scaled up or down. Up till now, floor textures have been impossible because floors could be seen at any angle, not just head-on like the walls (that's why mouse-look is disabled). However, now that CJ has added sprite-cropping, this combined with sprite rotation MIGHT make floor textures a possibility. I'm looking into it.

HoN
Title: Re: AGS3D +PLUS+ beta
Post by: Kweepa on Mon 19/09/2005 04:12:40
Quote from: HeirOfNorton on Mon 19/09/2005 03:35:03
However, now that CJ has added sprite-cropping, this combined with sprite rotation MIGHT make floor textures a possibility. I'm looking into it.
You are crazy! I like it.
If you need help with the maths let me know - although it should be pretty much the same as the perspective calculations on the walls.
I would take a 2x2 tiled version of the texture, so that when it's rotated you can always take a square section from the middle and tile that. I think that'll help.
Title: Re: AGS3D +PLUS+ beta
Post by: TheYak on Mon 19/09/2005 05:01:44
So can the rawdraw function be used for transparent shapes as well?  I'm assuming if it were possible, it'd kill the hell out of the framerate.  *Twiddling fingers patiently waiting for the incorporation of EBM and normal maps*  It's just jaw-dropping progress from both of you, I hope some creative soul manages to incorporate it cleverly into a game and we don't just see a slew of Rogerstein games.
Title: Re: AGS3D +PLUS+ beta
Post by: SSH on Tue 20/09/2005 17:38:12
I might do a 3d remake of Pixel Hunt, given that my 3d modelling abilities should just about manage the GFX for that  ;)
Title: Re: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Wed 21/09/2005 04:23:44
Quote from: YakSpit on Mon 19/09/2005 05:01:44
So can the rawdraw function be used for transparent shapes as well?

Not sure quite what you mean by this. If you mean textures with transparent sections, no problem. I alread have one of those in the example. Textures with alpha channels would probably work too, though I haven't tried it. If you mean translucent SOLID shapes--like say a glass sphere--then no, the rawdraw functions can't do it right now. (as far as I know)

HoN
Title: Re: AGS3D +PLUS+ beta
Post by: TheYak on Thu 22/09/2005 09:20:27
The latter.  Specifically, if you wanted to do a shadow overlay that would darken both the "walls", ground, and character  (Or light overlay, for that matter).  You could do this with 2D overlay, but a polygon could make for more realism.  I actually had a specific purpose in mind but have since  brain-dumped it. 

So, with the textures, a masking effect is possible but not tranparency (alpha) as of yet? I would assume if you did something like a glass wall that allowed you to see into the next room it would slow things to a crawl.  Aside from very specialized applications (e.g. silhouette s) I can't think of a use for translucent solids.  Transparent ones would be too resource-consuming in the end to replace 2D semi-functional counterparts.
Title: Re: AGS3D +PLUS+ beta
Post by: HeirOfNorton on Thu 22/09/2005 14:12:53
Oh. I had the same idea, trying to figure out how to add lighting effects to the textured walls. With the current state of the RawDraw functions, about the only way I can think of to do this is to have a 1 X 1 pixel sprite and RawDrawImageTransparent that sucker all across the screen. Rather unwieldy.

The best solution(s), in my opinion, would be for CJ to add RawDrawImageResizedTransparent, and/or to add a transparency setting to the regular RawDraw functions. Personally, I vote for the latter, as it could be useful for other applications than this.

HoN
Title: Re: AGS3D +PLUS+ beta
Post by: Cpt Ezz on Mon 27/07/2009 07:46:11
it Looks sooooo :o :o good
Just thought i might add something soo it gets bumped up to the top of the list again i know soo many people that are looking for this....trying to help
Title: Re: AGS3D +PLUS+ beta
Post by: Gilbert on Mon 27/07/2009 10:55:37
The problem is, this is quite old that it might not work with new AGS versions anyway. So why bump this up if there isn't really much to contribute (like, offer a hand to update it for example)? :P
Title: Re: AGS3D +PLUS+ beta
Post by: Cpt Ezz on Tue 28/07/2009 04:02:56
ok i will download it and see if it works

EDIT: it works on version 3.1.2 sp1

Will add update asap
Title: Re: AGS3D +PLUS+ beta
Post by: Construed on Wed 16/02/2011 04:22:44
Dead :(
Title: Re: AGS3D +PLUS+ beta
Post by: Dualnames on Wed 16/02/2011 06:01:36
Quote from: GrimReapYou on Wed 16/02/2011 04:22:44
Dead :(

Great observation skills.
Title: Re: AGS3D +PLUS+ beta
Post by: Matti on Wed 16/02/2011 10:55:38
Quote from: Dualnames on Wed 16/02/2011 06:01:36
Quote from: GrimReapYou on Wed 16/02/2011 04:22:44
Dead :(

Great observation skills.

Indeed!

GrimReapYou, please don't bump old threads on a daily basis just to tell everyone that the link is dead. You can just PM the author and eventually he will update the link - if the module itself isn't outdated anyway.
Title: Re: AGS3D +PLUS+ beta
Post by: Construed on Wed 16/02/2011 11:39:30
yeh, well perhaps you should work on pruning out the garbage.
Title: Re: AGS3D +PLUS+ beta
Post by: Matti on Wed 16/02/2011 11:54:56
Giving silly answers to serious posts doesn't help.
Title: Re: AGS3D +PLUS+ beta
Post by: kaputtnik on Wed 16/02/2011 11:58:53
Quote from: GrimReapYou on Wed 16/02/2011 11:39:30
yeh, well perhaps you should work on pruning out the garbage.

What goal are you pursuing by digging up those old module threads anyway? Are you trying to build the next fantastomatic-super awesome 3D online game with AGS? If so, maybe you should look into using another engine, because AGS will not be your tool of choice.
Title: Re: AGS3D +PLUS+ beta
Post by: Construed on Wed 16/02/2011 12:03:33
there may be better engines, but not more comfortable ones, and im sorry for snappin at ya matti, im pissy today.
Title: Re: AGS3D +PLUS+ beta
Post by: Khris on Wed 16/02/2011 12:18:45
Quote from: GrimReapYou on Wed 16/02/2011 11:39:30
yeh, well perhaps you should work on pruning out the garbage.

In a forum this is done by letting a thread wander further and further back as new threads push it there.
Necroposting screws that up.
Please check the date of the original post, whether the OP ist still active and when the thread was last active before reviving it.
Title: Re: AGS3D +PLUS+ beta
Post by: Construed on Wed 16/02/2011 12:50:45
Yea, your right.
I want to apolagize to you, matti ddq and anyone else i snapped at lately.
You guys are awesome!

I've just been in a bit of a rage lately :(
Title: Re: AGS3D +PLUS+ beta
Post by: Dualnames on Wed 16/02/2011 13:02:33
Okay, first pruning out the garbage. Done. Already.

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=41360.0

So everything till that date ever released has been gathered. I may miss an occasional one or two. If something is amiss, it's either newer, or never got the chance to get a working link.