Author Topic: Field Files/Texture management  (Read 7288 times)

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Field Files/Texture management
« on: 2001-08-24 12:59:00 »
*WARNING the pictures in this document are around 400K in size. They take a while to download*

Ok, everyone gather around. Remember to bring your pens and paper. You may have to take notes on this.

Ok, I've been taking apart the PSX version of FF7. Now this helps to figure out how the PC version works because it's a direct port. Now I'm going to show you how the field files and the texture management work in the PSX version and you should find the PC version working exactly the same way. Now before I begin with the nitty gritty, I have to get you guys up to speed about how a PSX does its graphics so we all know what's going on.

The PSX only has 1 Meg of video memory. Actually it's a "surface" that's 1024x512. Now we can allocate that whole thing to be viewable, but then there would be nothing left for textures or page flipping. Usually a "window" is created and the rest is left to textures. This leads us to the second problem with the PSX. Video memory is 100% off limits to the CPU. You have to manipulate everything through the GPU (Graphics prossessing unit). If you want to load textures into video memory, it has to be in TIM file format. Which is nothing but a PSX bitmap.

Now this following       http://www.execpc.com/~halkun/field/vidmem.png" TARGET=_blank>picture       is what the video memory looks like after the movie stops running on the first field file. I've marked off key locations so you can see what they are. The framebuffer and backbuffer are where the animation is flipped back and forth. The 24 bit overflow area is when the movies play in 24 bit color, they need a little more memory. (The PC version didn't have 24 bit movies). Under that is the Color Look Up Table or CLUT. When you load a field file, the pallette goes here. The next thing is the GPU texture cache. This can be disregarded. Now the thing I have labeled as "field layers" is actually in a place I call the "transient texture cache" it's very easily overwritable. It happens to have the field layer textures in it right now. When other modules load, such as "battle" this area is the first to be overwritten. Below that is the "semi-permanant" area. What is written in there tends to stick between module loads. "Eyes" are the characters eyes (they randomly blink, even if you don't see the character on screen) and the section is for the PHS, and finally the text and status menu textures which never go away.

The next       http://www.execpc.com/~halkun/field/trainvid.png" TARGET=_blank>picture       is the engine in motion. Now you can see the display buffer and back buffer working. You can see some squares on the display buffer being drawn on the field picture, I'm going to go into that now.

This       http://www.execpc.com/~halkun/field/prio.png" TARGET=_blank>picture       shows the field file's priority layers. I had the computer put a box around all the textures. The color of the box shows it's priority. The lowest priority is white. You can see our friend Cloud is standing in an area of white priority boxes so no textures are "infront" of him. The next priority is purple. This can either be infront of or behind a character depending on location.  The light blue and then dark blue are next. Light blue is higher than purple and dark blue will always be on top, no matter how close the character is. It's hard to see the difference between light and dark blue in this picture. but if you look at the train conductor farthest away, you can see it's in the light blue priority.

Now do you see the pipe on the train, the one sticking way out on top, and has a green outline around it? You can also see the building behind it. Ok, the pipe is in a light blue priority, but the green outline allows everything *around* the pipe to be shown through. (Jessie jumped behind this pipe at the beginning) That's why Mr. Far conductor is not being obscured by the train. The obscuring starts at the pipe in the corner of that square. You got it so far?

What happens when you get into a fight? Well, I'll show you. Take a look at this       http://www.execpc.com/~halkun/field/battlevid.png" TARGET=_blank>picture       here. You can see that the battle textures overwrote the field data, but not entirely. The rest of the field data is cached. Now, look at the frame buffer. You can see that one of the battle textures overwrote the 24-bit overflow area, that's fine. The battles are never in 24 bit anyway so clipping isn't a problem. Now the semi-permanent area at the bottom was filled with all kinds of textures. Those are common battle textures, such as limit auras, magic auras, potion auras, thinks like that. They won't go away after the battle is finished so the load times are kept down. The eyes are gone though. Actually. Clouds eye is next to the top framebuffer. That's the only texture there, when you get more characters those fill in, such as Barret's tatoo and Tifa's eye. Also when any special attack does off, such as magic, it will fill up after the battle textures eating away at the field texture cache. Wanna see the battle close up? Take a look       http://www.execpc.com/~halkun/field/battlewire.png" TARGET=_blank>here       Notice the little dust texture at the feet of Mr. bad guy? Thats in the semi-permanent area in video memory. It's a very popular texture.

So what about the video memory after battle? well if you look       http://www.execpc.com/~halkun/field/afterbat.png" TARGET=_blank>here       you will find the semi-permanent textures stuck, but the field textures overwrote the battle ones, except  which was in the 24 bit overflow area.

This right       http://www.execpc.com/~halkun/field/prio2.png" TARGET=_blank>here       is another picture showing how priorities work a little better. Notice that Cloud's foot is in a dark blue priority box? It is being overwritten, but it's the pipe that isn't transparent. The lamp over on the left is priority color purple. Cloud can walk both in front or behind it depending on his location. The sign? That's priority dark blue. It's animated too. When animation is done, it's only the boxes that change get changes, not the whole priority layer.

Animation? Did I say animation? If you want to see the video memory of a "full" field file with animation look       http://www.execpc.com/~halkun/field/anivid.png" TARGET=_blank>here.       The smoke that blows about is there and it's filled all the way to the semi-permanent textures. Just remember, if cloud leaves this scene and comes back, what isn't overwritten is cached.

I think that covers everything I've found so far. Do with this information as you wish. It may be in your best interests to save these pictures as I think I'm over quota at my ISP. I'll keep them up for about a week.

Anyway I'm going to bed. Feel free to talk amongst yourselves.

-Halkun

[This message has been edited by halkun (edited August 24, 2001).]

[This message has been edited by halkun (edited August 24, 2001).]

Third EDIT by The SaiNt in an effort to correct halkun's horrible spelling.

[This message has been edited by The SaiNt (edited August 24, 2001).]


ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Field Files/Texture management
« Reply #1 on: 2001-08-24 13:47:00 »
That IS pretty interesting ... but how does it help us decode any of the files?

So far what you've discovered is very good to know, but doesn't actually help us any with the file formats.


The SaiNt

  • *
  • Posts: 1300
    • View Profile
Field Files/Texture management
« Reply #2 on: 2001-08-24 14:00:00 »
Hey, fice is around!
So, i bet he's the only one besides me who read halkun's unedited document  :wink:

Actually, it does help a little with the C source. I can find out what more offsets do, and hopefully it will indirectly help us decode the file format.


ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Field Files/Texture management
« Reply #3 on: 2001-08-24 15:57:00 »
Analysing the PSX version could help us with the PC version; but looking at it's graphic techniques won't. The PC handles that differently. It has to; it uses DirectX rather than a PSX-GPU. The *file formats* are the same. What it actually *does* with them ain't, not so far as interacting with the hardware goes.

The SaiNt

  • *
  • Posts: 1300
    • View Profile
Field Files/Texture management
« Reply #4 on: 2001-08-24 16:23:00 »
Actually, I find the way it handles memory nearly the same. In fact, the caching methods are next to identical. Hardware interfacing however is unlikely to be the same cause FF7 uses DirectX. BTW, do you happen to know how to intercept the directX function calls to the video card?

Sir Canealot

  • *
  • Posts: 900
    • View Profile
Field Files/Texture management
« Reply #5 on: 2001-08-24 17:44:00 »
Pretty intresting but
Quote
Now this helps to figure out how the PC version works because it's a direct port
Quote

If so why wouldent it run on my P75 with 16 megs of ram and 1 meg vide card then?  :P (joke)


ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Field Files/Texture management
« Reply #6 on: 2001-08-24 18:07:00 »
SaiNt: Sure. Write a DirectX replacement layer, implementing the original COM interface and selectively filtering calls through to an instance created from the original COM factory.

Sounds complex? It is! You can get the source code for the FF8 Configurator from mine or the FFSF site, that does it for DirectMusic ... however, it isn't that simple, and DirectMusic is the easiest to write a replacement for. It WOULD be hard to do it for D3D/DDraw.


The SaiNt

  • *
  • Posts: 1300
    • View Profile
Field Files/Texture management
« Reply #7 on: 2001-08-24 20:37:00 »
Above my knowledge  :)

ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Field Files/Texture management
« Reply #8 on: 2001-08-24 21:41:00 »
It ain't simple. I didn't even code the replacement layer in FF8 Configurator myself; Dag did that and I modified it, though I think I could program a DirectMusic replacement layer myself if I'd had to. The other parts of DirectX are pretty complex though; not sure whether I could do them.

Ged

  • *
  • Posts: 452
    • View Profile
    • http://acn.waw.pl/vanyel
Field Files/Texture management
« Reply #9 on: 2001-08-24 23:20:00 »
Oh yes, Ficedula, did you work on the FF8 Graphic Resolution Enchancer? You mentioned something about raising the resolution someday...

ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Field Files/Texture management
« Reply #10 on: 2001-08-25 00:05:00 »
God no, I've been far too busy with the Remake to work on anything else. And like I said, a DirectX layer is pretty difficult to program anyway.

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Field Files/Texture management
« Reply #11 on: 2001-08-25 02:46:00 »
You can use my examples to see how the engine runs. I'm sure the prioity system is exactly the same, along with exture management. Yes I'm sure the video memory is *compleatly* differnt, but when it comes to what gets loaded when is exactly the same. It also give a bit of a hint on what to look for. Also give idea on how the models are built. It will see FF7 uses both triangles and quads. The textures can be quads (eyes) and triangels (mouth) You will have to define that somegow though.

ficedula

  • *
  • Posts: 2178
    • View Profile
    • http://www.ficedula.co.uk
Field Files/Texture management
« Reply #12 on: 2001-08-25 03:37:00 »
??? I'm still not following you.

How does it help us to know when things get loaded? Or to know what sort of polygons it's using for the models? We can read in P files ok ... it's positioning them that's the problem. And looking at the PSX doing it won't help ... we'll just see a perfectly positioned model, same as you would running the PC version.

I'm sure *some* things can be found out looking at the PSX version - I just question whether you'd find anything out that couldn't be found just as easily looking at the PC version.