Golden Sun Hacking Community
December 14, 2017, 10:26:40 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 2897 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: 2393

« 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...
Did you know? In English, you are suppose to capitalize the languages. (e.g. English is a proper noun.) Subjects like math, science, history can be left lower-cased unless they are a title. (Kind of like how you can say either "my mom" or "Mom" in "I went with (X) to the store.", except that I don't think languages are ever lower-cased in English.) In Spanish, both subjects and languages are left lower-cased. (I put this here because I've noticed people make this mistake quite often. And am curious if they know about this, and whether they use their way because they believe this grammar usage should have never been a thing?

Remember kids! In getting a job, it's not about what you know, it's about WHO you know! So start making friends with the people that work where you want to work. :) (Friend of a friend and volunteering count too, so keep that in mind.)[/si
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: 2393

« 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...
Did you know? In English, you are suppose to capitalize the languages. (e.g. English is a proper noun.) Subjects like math, science, history can be left lower-cased unless they are a title. (Kind of like how you can say either "my mom" or "Mom" in "I went with (X) to the store.", except that I don't think languages are ever lower-cased in English.) In Spanish, both subjects and languages are left lower-cased. (I put this here because I've noticed people make this mistake quite often. And am curious if they know about this, and whether they use their way because they believe this grammar usage should have never been a thing?

Remember kids! In getting a job, it's not about what you know, it's about WHO you know! So start making friends with the people that work where you want to work. :) (Friend of a friend and volunteering count too, so keep that in mind.)[/si
View Profile
leaf
Potions class is starting
Venus Clan

Death Eater+Grass Snake = Snake Eater? SNAAAAAAAKE

Veteran Member
*

Coins: 10
Offline Offline

Posts: 1320

« 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: 2393

« 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...
Did you know? In English, you are suppose to capitalize the languages. (e.g. English is a proper noun.) Subjects like math, science, history can be left lower-cased unless they are a title. (Kind of like how you can say either "my mom" or "Mom" in "I went with (X) to the store.", except that I don't think languages are ever lower-cased in English.) In Spanish, both subjects and languages are left lower-cased. (I put this here because I've noticed people make this mistake quite often. And am curious if they know about this, and whether they use their way because they believe this grammar usage should have never been a thing?

Remember kids! In getting a job, it's not about what you know, it's about WHO you know! So start making friends with the people that work where you want to work. :) (Friend of a friend and volunteering count too, so keep that in mind.)[/si
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: 1320

« 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
Yesterday at 09:19:38 PM
Fox: Okay, so that Summon Night games adds the fram number to the seed, before generating another seed via mul/add....  (GS1-GS3 never adds the fram number.) ... So um, that makes sense! ;  Summon Night:  ((seed + frame) * 0x343FD + 0x269E3C) >> 0x10 ; Which is also on the list here: https://en.wikipedia.org/wiki/Linear_congruential_generator
December 12, 2017, 11:10:45 PM
Fox: Yes, and there could be contests. Maybe ones where 1st/2nd/3rd place get a cash reward, but eh. Dunno.... Kind of thinking about making a topic about how people got their job, and what was their experience. (e.g. Did they use references of people already working in the job, and various other things.)
December 09, 2017, 04:24:14 AM
Majora: Import old forum posts for reference, perhaps take posts containing important info like documentation away from the old stickied forum post model and make them into their own pages on a site with an in-built search bar. Might help with SEO, too. If nothing else, perhaps whipping them into PDFs and hosting them via Scribd? The possibilities are boundless when it comes to restructuring a site
December 09, 2017, 04:20:02 AM
Majora: Just a nice idea to have even if it doesn't come to fruition. Updating, modernizing, always a good idea. Could probably do something pretty nifty using a good Wordpress theme
December 09, 2017, 04:15:45 AM
Majora: Would be kind of neat to do something like that for GSHC. Could change it up a bit to show all tweets/instagram posts/facebook posts/golden sun subreddit posts all in one sidebar. It would be cool in that it gives the site it's on (and the topic in general) appear more lively and active, which is a plus
December 09, 2017, 04:14:19 AM
Majora: That does sound interesting. One cool thing I've seen some sites use is a sort of unique take on a sidebar option that acts like a social media integration (like, "See GSHC's latest Tweets"). It displays activity from a variety of related sites, such as Reddit, Twitter, Instagram, etc.
December 09, 2017, 12:58:53 AM
Fox: And the way it'd work via code is not that all users would instantly get nicknames the minute you register... but rather, the moment you view a name if it doesn't have a nickname, it gets one. (My Thoughts.)
December 09, 2017, 12:53:55 AM
Fox: (I was thinking that it would be "Name (Nickname)" ... The nickname is what you first known the user as, and you can change that yourself... and the Name is what the user wants to be called... Something like that.
December 09, 2017, 12:47:56 AM
Fox: So like... for starters, one idea I had was to make it so anyone can name anyone... much like how it works on Skype, and you (the namer) would be the only one to see it, and such...
December 09, 2017, 12:45:02 AM
Fox: Would need to be carefully thought out and tested, though.
December 09, 2017, 12:43:02 AM
Fox: I'm thinking I could make it so that name changes can happen whenever... (Without any limit)... Since I believe there's a way to do it with minimum confusion. (I think.) Hmm....
December 09, 2017, 12:31:36 AM
Fox: (I mean an offline version... at least initially.)
December 09, 2017, 12:25:01 AM
Fox: Now that I have thought about it a bit more, would I be right to assume that GSHC would be one of the most interesting websites to administrate, or no? It's sad to see not much going on with it. == I almost want to make a concept website at some point. :D Anyway, how is everyone doing today?
December 06, 2017, 12:12:59 AM
Fox: Like... Start using Github or something... Do like how many of those other projects such as Citra (WIP 3DS Emulator) does. Etc.
December 06, 2017, 12:08:12 AM
Fox: No idea. I just wish OpenGoldenSun would release it as unfinished, but oh well.
December 05, 2017, 06:52:09 AM
MaxiPower: Bummed out that the open golden sun project is dead it seems with no actitivy in close to a year at this point. Is there any hope left in any other projects?
November 27, 2017, 10:25:28 AM
Fox: (When I say research, mainly refering to the data in the game, though checking websites can count to a degree.)
November 27, 2017, 09:52:27 AM
Fox: Maybe. But Dark Dawn is meh, hahah... I still research it, though, because data can be interesting.
November 27, 2017, 05:28:36 AM
Portakin: I'm here! This game is underrated!
November 25, 2017, 08:03:23 PM
Fox: .... and the email listed in that post makes me think we should just make a new rules topic with most of the same information. (So the old ones can be sort o archived.)

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.067 seconds with 22 queries.