AGS3D +PLUS+ beta

Started by HeirOfNorton, Fri 09/09/2005 06:56:25

Previous topic - Next topic

HeirOfNorton

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...





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. Thanks to www.americangirlscouts.com for the file hosting.

Whatcha think?

Rui 'Trovatore' Pires

I noticed you disallowed mouse-looking up and down. Is that necessary?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Kweepa

#2
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
Code: ags

  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
Code: ags

    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.
Still waiting for Purity of the Surf II

Gregjazz

The download link does work. :(

In fact, http://freefilebin.com does work. I'll try later, I guess.

HeirOfNorton

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

Kweepa

Oh, so you don't need my edit then :=
Still waiting for Purity of the Surf II

TheYak

It's awfully daft of me to try, but this version doesn't run in conjunction with AGS MacRuntime.
Code: ags
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)

scotch

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.

Pumaman

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 :)

TheYak

#9
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.

Kweepa

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. :'(
Still waiting for Purity of the Surf II

HeirOfNorton

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

Kweepa

No, just what you see... (I did edit my post up above there).
Still waiting for Purity of the Surf II

HeirOfNorton

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

Jay

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 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)

HeirOfNorton

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:

Code: ags

  sectors[numSectors-1].numCubes = 0;


at line 3464 of the script module.

HoN

Gregjazz

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?

Kweepa

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!
Still waiting for Purity of the Surf II

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Gilbert

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). :=

SMF spam blocked by CleanTalk