Golden Sun Hacking Community
February 25, 2018, 09:33:02 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
  Home   Forum   DC Wiki Help Search Calendar Downloads Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Anybody who can explain Z-buffer and Framebufferobjects?  (Read 3607 times)
0 Members and 1 Guest are viewing this topic.
Luna_blade
The last member of the Luna clan
Luna Clan

Great Member
*

Coins: 0
Offline Offline

I am: Timeless. As in, i don't have much free time.
Posts: 533

« on: March 04, 2016, 11:12:15 AM »

Just out of curiosity, I'd like to know how a Z-buffer and framebufferobjects work in a 3D game.
Apparently, both are a solution to the Visibility problem in 3D games.
I spent a lot of time looking for proper explanations, which I didn't find.
I know and understand the painters algorithm, but the other two however...

 
Logged

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
View Profile
Fox
Fox McCloud, the Hacking Doctor
Mercury Clan

Prodigy
*

Coins: 28
Offline Offline

I am: certainly not a Gallant!
Clan Position: Head Gallant
Posts: 2407

« Reply #1 on: March 04, 2016, 02:14:05 PM »

Wait, what?

I think buffer is pretty much just an array in RAM?
So I take it that Z-buffer is probably just an array where each value is for each pixel....? Probably holding the layer number or something... well... something representing priority? (My guess is if a pixel in another triangle is lower than this priority, it gets completely ignored.... but if greater, it gets set on top and z-buffer gets updated with the new info about it. - Whether "lower" or "greater" is closer to 0, I'm not sure.)


I have something for blending in Yoshi Magic.. but it's done via flags for each pixel... (1 means blend on next layer, 0 means don't...)
Before blending feature was added, I drew the bottom layer first, after adding the blending feature, I changed Yoshi Magic to draw the top layer first. I chose top-down because that's how the blended layers are selected....


---
Is framebufferobjects like a cache or something? No idea? (Guessing again.)
« Last Edit: March 04, 2016, 03:07:07 PM by Fox » Logged

Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Remember kids! Before you go on that interview, remember to wash your hands in teawater! *Coughs on hand* (Excuse me, I just coughed up a little teawater, so they're still clean!) You wouldn't want that hiring manager to be unimpressed.

May the force be with you!
Shoo! Why does it smell in here?
Maybe that's the wrong kind of force. *smirk*
View Profile
Luna_blade
The last member of the Luna clan
Luna Clan

Great Member
*

Coins: 0
Offline Offline

I am: Timeless. As in, i don't have much free time.
Posts: 533

« Reply #2 on: March 04, 2016, 04:27:39 PM »

Well, what I do understand about Z-buffer is, that it is indeed an array in the GPU-RAM and every pixel is a floating point number.
The number corresponds to what the 'depth' of that pixel is. I also get that you start with every pixel each frame set to 0 and then counting up for each object which is more in the front.
But... I don't quite get how the Z-buffer keeps all the objects apart and how it is used to draw after the depth calculations.
Logged

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
View Profile
Fox
Fox McCloud, the Hacking Doctor
Mercury Clan

Prodigy
*

Coins: 28
Offline Offline

I am: certainly not a Gallant!
Clan Position: Head Gallant
Posts: 2407

« Reply #3 on: March 04, 2016, 04:43:57 PM »

Yes... except in the event that it is a user-created z-index array, I'd argue that floating-point could be any value datatype you choose. (Preferably integer/32-bit?) I'd recommending staying away from floating point (single or double) if you don't need it since it may be slower... (Could also depend on your processor? In which case, I'd be interested in more information.)
Basically... I don't think it's about keeping the objects apart, but about calculating what's in front....
-Like draw one object... its z-indexes are set... draw the next object... and whatever pixels shown from that object alters z-indexes.. but everything that comes behind the object (Which is compared with the z-index for those pixels) is ignored.).
-Objects are kept separate in other table(s)... (Triangle and vertex listings and such).... and those are rendered to the screen every frame...

@after the depth calculations: Do you mean like the HUD one might always make displayed in front?
If you want something to always display in front... you just draw it after you've drawn your 3D map... (For stuff always on top, you may not need to use z-index table anymore... unless you got some more priority-ing going on, maybe..)

Or is it something I'm missing? Like texture calculations and such instead?

---
^May not have spent enough time on this post, so could take some editing.
« Last Edit: March 04, 2016, 05:13:04 PM by Fox » Logged

Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Remember kids! Before you go on that interview, remember to wash your hands in teawater! *Coughs on hand* (Excuse me, I just coughed up a little teawater, so they're still clean!) You wouldn't want that hiring manager to be unimpressed.

May the force be with you!
Shoo! Why does it smell in here?
Maybe that's the wrong kind of force. *smirk*
View Profile
leaf
Potions class is starting
Venus Clan

Death Eater+Grass Snake = Snake Eater? SNAAAAAAAKE

Veteran Member
*

Coins: 10
Offline Offline

Posts: 1322

« Reply #4 on: March 05, 2016, 05:45:40 AM »

Fox, at least read the wikipedia article before you try to help someone. The z-buffer is typically stored as a normalized 24-bit or 32-bit fixed point number (not floating point, and not an integer), taking on a value between 0 and 1, where 1 represents the cut-off point for rendering, and 0 represents the camera. This makes the camera size-agnostic, capable of handling both large and small scenes alike. Note that this isn't simply stack ranking their depth; it's precisely calculating *how* far away an object is from the camera.

As I understand it, the z-buffer essentially operates as an evolved version of the reverse painter's algorithm, but instead of operating on entire objects, it operates on individual pixels. The rendering engine examines each object in the scene that could potentially occupy a given pixel, and performs a simple less than check. It then selectively renders only the object with the lowest value (i.e. is nearest to the camera). It's important to note that it's only rendering a pixel, which is only a small sample of the object; it does not render the whole object, so if an object is partially occluded, it will only be partially rendered. This saves an immense amount of processing by reducing the amount of data that needs to be sent to the GPU; there's no need to send the data for 100 objects if only 50 of them are ever visible in the scene, and only half of those 50 objects are ever fully visible. Sending data to the GPU is the primary bottleneck in the rendering pipeline, so while you do end up saving by not doing the additional rendering passes for the hidden objects, the greatest saving ends up being that the data for the hidden objects is never sent to the GPU to begin with. Naturally, this is only useful for opaque objects.

As for a frame buffer object... I don't really know how that relates to solving the depth problem. From some cursory searching, it seems to be an OpenGL-specific thing, though other APIs use similar systems. It's basically a back buffer that can have post-processing effects applied to it. So it calculates the rendering for the next frame in one section of memory, applies whatever effects it needs to, then points to the data for that frame on the next draw call. Use of a back buffer is extremely common in rendering as a means of solving screen tearing, since there's always a complete image for the screen to display on a given frame.
« Last Edit: March 05, 2016, 09:20:50 AM by leaf » Logged

Spoiler for quotes:
[9:00:50 PM] Randel Peltier: Ok...what did I do last night?
[9:01:19 PM] Kain: Something boring, repetitive, and lasted for about sixty seconds.
---
[10:45:08 AM] Salanewt: But yeah, the elemental phalluses are being... Stroked up by Saturos and co., and the energy will go towards... Mt. Muffin, where the Golden Climax will arise.
[7:28:42 PM] Salanewt: An added bonus is that Isaac and co. were trying to stop Saturos and co. because their beliefs state that Mt. Muffin should remain a virgin.
---
[9:54:21 PM] Randel Peltier: Guess the number in my head an you get to pick what I say. Number between 1-10
[9:54:28 PM] leaf: 11
[9:54:36 PM] Randel Peltier: @#$%!
---
[8:38:13 PM] Randel Peltier: Shes like this queen up on a pedastal that I have yet to court.
[8:38:29 PM] Kain: You've tried courting her.
[8:38:43 PM] leaf: and failed spectacularly
[8:38:44 PM] Randel Peltier: Ive tried...shes the best dating game ever.
---
[12:24:35 AM] Salanewt: I need to find a picture of a naked person to put on the Christmas tree next year.
---
[2:19:06 PM] Zeadra: wait... Rief's a guy???
---
[1:09:57 PM] Zeadra: well if you want to know if its a new effect or something weird, just check GS1, if side step is there maby it is the nimble dodge thing
[1:10:35 PM] Kioll: For once, you've contributed something useful.  o.O
View Profile
Fox
Fox McCloud, the Hacking Doctor
Mercury Clan

Prodigy
*

Coins: 28
Offline Offline

I am: certainly not a Gallant!
Clan Position: Head Gallant
Posts: 2407

« Reply #5 on: March 05, 2016, 06:13:56 AM »

I saw that article when I was looking up the Painter's Algorithm article... I did go to the Z-Index article from there, and yes, I did read some of it at that time... not the whole thing because it's long... . (I don't think I was fully paying attention, though..  But I do remember reading about the 16-bit+ part and that 8-bit was rarely used... and was thinking about that in my post.... What I SHOULD have paid attention to and looked up was fixed point... since I didn't exactly realize what that was... And assumed you could use any data type you wanted as long as you had enough bits... (Yes, you can put (invisible) decimal numbers in ints (if number is shifted) ... But not straight forward for numbers that are repeating like 1/3rd, which could be rounded anyway...) based on some quick theories... note that I've not built my own 3D engine yet, but I know that with some research I can do it. (Including sin/cos rotation) Don't exactly have the motivation right now, though.)

And yes, 0 being the camera's position makes a lot of sense.

But since you seem more knowledgeable about terms, then I leave the answers up to you for right now, I guess.

I've known this for a while now, though... And I think of both as floating-point.
32-bit = Single
64-bit = Double
And huh... must have missed Decimal (fixed-point.) (I recognize that keyword Decimal, but I not pay much attention to it. - I get the feeling it is one of those things I looked up in the past, learned it was fixed-point... and then forgot about it, though.) -  I still prefer to use the integer data-types when possible, though... it's just my way of doing things, I guess. (It is possible there may be exceptions, however. But so far, I haven't had to really worry about it in my coding as of yet... - I can maybe think of some things where one may get the computer's date/time (Double), though... But we're not likely to need that here.... )


-----
TL;DR = Basically, this post doesn't actually contribute to the topic itself.... so moving on...
« Last Edit: March 05, 2016, 07:26:40 AM by Fox » Logged

Golden Sun Docs: Broken Seal - The Lost Age - Dark Dawn | Mario Sports Docs: Mario Golf & Mario Tennis | Misc. Docs
Refer to Yoshi's Lighthouse for any M&L hacking needs...

Remember kids! Before you go on that interview, remember to wash your hands in teawater! *Coughs on hand* (Excuse me, I just coughed up a little teawater, so they're still clean!) You wouldn't want that hiring manager to be unimpressed.

May the force be with you!
Shoo! Why does it smell in here?
Maybe that's the wrong kind of force. *smirk*
View Profile
Luna_blade
The last member of the Luna clan
Luna Clan

Great Member
*

Coins: 0
Offline Offline

I am: Timeless. As in, i don't have much free time.
Posts: 533

« Reply #6 on: March 05, 2016, 07:09:33 AM »

Quote from: Fox
@after the depth calculations: Do you mean like the HUD one might always make displayed in front?
If you want something to always display in front... you just draw it after you've drawn your 3D map... (For stuff always on top, you may not need to use z-index table anymore... unless you got some more priority-ing going on, maybe..)
Well after depth calculations, the GPU starts to actually draw the frame. That's more what I meant.

As I understand it, the z-buffer essentially operates as an evolved version of the reverse painter's algorithm, but instead of operating on entire objects, it operates on individual pixels. The rendering engine examines each object in the scene that could potentially occupy a given pixel, and performs a simple less than check. It then selectively renders only the object with the lowest value (i.e. is nearest to the camera). It's important to note that it's only rendering a pixel, which is only a small sample of the object; it does not render the whole object, so if an object is partially occluded, it will only be partially rendered. (quote shortened)
So if I understand correct: first when a polygon is rendered it's pixel are give a depth value, then they are placed in the Z-buffer. And when the depth calculations are over, every pixel from this object that is visible, is drawn.

I think I understand now. Isn't it however a bit silly that the GPU still has to fetch all the colors and texture for the given drawn pixel?
Also, by using a Z-buffer, you can't just draw triangles anymore (not that it mattered for untextured things though), but have to use something else?
Logged

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
View Profile
leaf
Potions class is starting
Venus Clan

Death Eater+Grass Snake = Snake Eater? SNAAAAAAAKE

Veteran Member
*

Coins: 10
Offline Offline

Posts: 1322

« Reply #7 on: March 05, 2016, 09:18:33 AM »

How is it silly? Yes, it needs to fetch the texture data, but it only fetches that texture data once for a given object, regardless of how many pixels it takes up on screen.

Second part, not sure what you're asking, but I think that's my fault for the way I explained it. You still need to know the geometry of an object to use z-culling, but you get the advantage of fewer draw calls. Calculating geometry is done by the CPU, and is no where near as big of a deal as the process of actually rendering a texture or a light to screen.

As I alluded to earlier, sending data to the GPU is the slowest part of the rendering pipeline. It's the physical act of data being sent across from the CPU to the GPU that is slow, but it needs to be done for each draw call, which writes the display data to the buffer. Thus, we can improve rendering time by reducing the number of draw calls. In general, each texture that gets rendered to the screen needs to be a separate draw call, and game engines like unity will often batch all objects with the same texture in one draw call; this optimization is possible thanks to the z-buffer.

For example, suppose you're using the painter's algorithm. You perform a draw call for the far objects, then the nearer objects, then the nearer-nearer objects, and so on. Even if some of these objects use the same texture, they still need to be separate draw calls, because one might get overwritten later, and the buffer only stores a flat image. But, with z-culling, you calculate ahead of time which objects should actually be rendered. So if something is half-occluded, you're only writing to half as many pixels when you draw that object, and those pixels don't get written to by any other objects in the scene*. This isn't a big deal on its own (writing to a pixel is relatively cheap, performance-wise), but what happens if you have another object with the same texture in the scene, also visible in the viewing plane? Both objects can now be rendered in the same draw call, because you've calculated ahead of time which objects should be rendered in the scene. You end up only sending that texture data to the GPU once, instead of multiple times.

*(Except lights. Baked lighting is one additional draw call after all other objects are rendered, and each dynamic light is another.)
« Last Edit: March 05, 2016, 10:07:09 AM by leaf » Logged

Spoiler for quotes:
[9:00:50 PM] Randel Peltier: Ok...what did I do last night?
[9:01:19 PM] Kain: Something boring, repetitive, and lasted for about sixty seconds.
---
[10:45:08 AM] Salanewt: But yeah, the elemental phalluses are being... Stroked up by Saturos and co., and the energy will go towards... Mt. Muffin, where the Golden Climax will arise.
[7:28:42 PM] Salanewt: An added bonus is that Isaac and co. were trying to stop Saturos and co. because their beliefs state that Mt. Muffin should remain a virgin.
---
[9:54:21 PM] Randel Peltier: Guess the number in my head an you get to pick what I say. Number between 1-10
[9:54:28 PM] leaf: 11
[9:54:36 PM] Randel Peltier: @#$%!
---
[8:38:13 PM] Randel Peltier: Shes like this queen up on a pedastal that I have yet to court.
[8:38:29 PM] Kain: You've tried courting her.
[8:38:43 PM] leaf: and failed spectacularly
[8:38:44 PM] Randel Peltier: Ive tried...shes the best dating game ever.
---
[12:24:35 AM] Salanewt: I need to find a picture of a naked person to put on the Christmas tree next year.
---
[2:19:06 PM] Zeadra: wait... Rief's a guy???
---
[1:09:57 PM] Zeadra: well if you want to know if its a new effect or something weird, just check GS1, if side step is there maby it is the nimble dodge thing
[1:10:35 PM] Kioll: For once, you've contributed something useful.  o.O
View Profile
Luna_blade
The last member of the Luna clan
Luna Clan

Great Member
*

Coins: 0
Offline Offline

I am: Timeless. As in, i don't have much free time.
Posts: 533

« Reply #8 on: March 06, 2016, 06:47:15 AM »

Oh right! That makes sense.
Logged

++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
View Profile

New User


Coins: 0
Offline Offline

Posts: 1

« Reply #9 on: November 01, 2017, 09:52:10 AM »

That's what I thought. Thanks for clarification!
Logged

Cool, I'm on a roll now. Just bring it on everything you got. This clubofpassioncom site granted me everything I ever wanted. Now I'm a successful guy.
View Profile
Pages: [1]   Go Up
  Print  
 
Jump to:  

Cbox
February 19, 2018, 09:50:20 PM
KyleRunner: "difficult thing about the army": I'm very good at taking orders, so I don't have issues with autority or discipline. The most difficult thing is to be away from my family sometimes. I lived an entire year away from my son, so I'd say that was the most hard part by far. Now it's great!
February 19, 2018, 05:51:35 AM
Fox: I'm happy to see we have plenty of people serving the country here. :)
February 19, 2018, 05:47:15 AM
Fox: Civilian here.
February 19, 2018, 03:05:38 AM
Majora: Good for you, something to be proud of. Air Force, here
February 19, 2018, 02:11:31 AM
Fox: That's good to hear... just checking if there were any possibility of doubt. What would you say was your most difficult thing about the army?
February 18, 2018, 12:39:38 PM
KyleRunner: Well, it was a destiny kinda thing, but I was very happy when I decided to join. It was just like I thought it would be (not in the beginning, though). I'm very pleased with my decision.
February 17, 2018, 11:32:41 PM
Fox: That's awesome!  Trying to figure what question I want to ask Something about how you felt when you made the decision to do the army, and whether it was different than your expectations/etc.
February 17, 2018, 01:53:41 PM
KyleRunner: Wow... My english got rusty. Anyway... I'm in the army now. My life turned 180. But I think it was for the best.
February 16, 2018, 12:45:45 AM
Fox: Hm? So where does that make you today?
February 16, 2018, 12:06:38 AM
KyleRunner: Five years ago I could not even imagine where I am today. I hope it works well for you too!
February 12, 2018, 07:22:50 PM
Fox: 2018 - The year that I will probably be working a manufacturing job. xP What would I have thought, if I told myself this five years ago. Eh?
January 28, 2018, 08:35:28 PM
Fox: You referring to changing the PC/leader sprite to someone else? - I forgot to mention that you can do this using VBA's memory viewer. (Found under Tools.)
January 28, 2018, 03:46:22 PM
shenlong: Hi, Im following up on @Raijinken's question about the sprite change... How do I access that to change it? and can you tell me what the values are for the characters? newbie here
January 26, 2018, 10:12:00 PM
roger: h a p p y  b i r t h d a y  z m a n
January 26, 2018, 01:38:04 AM
Fox: (Assuming you're going for "E")
January 26, 2018, 01:37:06 AM
Fox: So like... https://i.imgur.com/cI4Bgoy.png = Does not explain how it works, but follows this type of thinking.
January 25, 2018, 09:57:44 PM
Fox: Hm... Actually, this gives me an idea! What if the lighthouse becons on each lighthouse were actually portals?
January 25, 2018, 09:56:19 PM
Fox: Hard to explain without a diagram or something... but I could decide on that later. Right now, it turned out I dreamed of something! Something to do with going into the dark dimension... and to go between light and dark, required some energy (energy sphere/warp portal?) to be on... I forget most of the details of the dream now, but it's like you could get trapped in the dark world. Er...
January 25, 2018, 04:56:04 PM
KyleRunner: Can't understand... but... nice!
January 24, 2018, 06:20:33 AM
Fox: Third approach idea = Scan char tables and set up an array that helps to quickly jump over bits that are scanned in the char tables.... to kind of mimic an actual tree a bit better/ and reduce unnecessary scans.).... (untested, but what to know what it's speed is like.)

Affiliates
Temple of Kraden Golden Sunrise
Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.064 seconds with 23 queries.