• Create Account

## G Buffer

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

13 replies to this topic

### #1bzroom  Members

Posted 16 December 2011 - 04:28 AM

Here's my format so far

RGBA8: diffuse RGB 8 bits each, shininess 7 bits, is emissive 1 bit*
RGBA8: normal xyz 8 bits each, spec value 8 bits.
Depth 24f s8: depth 24 bits, stencil unused*

The problem is that I'm not storing both emission and diffuse. so an object must be one or the other. Unfortunately the artists will not accept this.

I could:
Add a render target (seems excessive for such a simple emission effect)
Some how use the stencil or existing channels differently (material id?)
Render emissive stuff in the transparent/blending pass afterwords.
Somehow modulate diffuse and emmision together and store some kind of unpacking ratio. (thats what I'm doing right now, except the ratio is binary)

### #2Ashaman73  Members

Posted 16 December 2011 - 05:29 AM

Start looking for an other artist ...

To be honest, talk to your artist, why does he need this requirement ? When he needs it, because he wants to deliver textures in a certain format (he delivers diffuse,normal,emissive textures) , you could still write a little converter to transform his textures in your format. It this requirement for some killer feature of your game/engine, or is it just a theoritically feature which might be useful in the future ? Which would be a useful usecase ? (a green wall with emissive blue light ? )

Ashaman

### #3AgentC  Members

Posted 16 December 2011 - 05:37 AM

If majority of your objects are *not* emissive, I would recommend rendering emissive (as well as other effects like environment mapping) in another pass after the deferred light rendering. The Z-buffer will already be primed, so you should get early-Z rejection for occluded objects.

Every time you add a boolean member variable, God kills a kitten. Every time you create a Manager class, God kills a kitten. Every time you create a Singleton...

### #4InvalidPointer  Members

Posted 16 December 2011 - 11:22 AM

If majority of your objects are *not* emissive, I would recommend rendering emissive (as well as other effects like environment mapping) in another pass after the deferred light rendering. The Z-buffer will already be primed, so you should get early-Z rejection for occluded objects.

Very workable. You can even recycle your actual illumination buffers for this purpose, and then draw light contributions in on top of the emissive. It's some extra draw calls, sure, but that shouldn't be too bad unless you have a *lot* of emissive objects.

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

### #5bzroom  Members

Posted 16 December 2011 - 11:36 AM

The most notable case is that we want the armor to sort of glow in the dark.

We want it to always glow, and yet react to light. Some swords have animated glowing regions. Like cracks with lava in them. We could easily separate these into two draw calls.
But a glowing green armor is going to be harder to "split up."

So a characters entire body suit would need to be rendered twice.

If i did render them in a second pass, i could skip the whole "1 bit is emissive" packing stuff which would be nice.

### #6Promit  Senior Moderators

Posted 16 December 2011 - 12:47 PM

To be honest, I suggest going straight to four G-buffers and stretching your legs a bit. You're probably still in the exploratory phase here for features, performance, etc and playing packing games right from the beginning is not going to be fun. Be generous with resources, find out what works and how real scenes look, and then strip it back down from there as necessary.
SlimDX | Shark Eaters for iOS | Ventspace Blog | Twitter | Proud supporter of diversity and inclusiveness in game development

### #7bzroom  Members

Posted 16 December 2011 - 02:02 PM

I'm targetting the xbox 360. Memory consumption and texture fetching is at a premium. Performance asside, we're already well into production and the scope of our art is pretty well known. At this point, besides emissive materials, the rendering methods are indistinguishable. In other words we dont really need any more features. What we need most is performance and memory.

I'm going to investigate drawing them in a separate pass.

### #8harveypekar  Members

Posted 16 December 2011 - 06:46 PM

Have you considered doing pre-pass lighting? It's basically the same as what you conclude, but for all objects in the scene. It uses less render targets (usually just one if you have hardware support for reading depth buffer) that classic deferred rendering, and also enables more variety in the materials (which is sorta that problem you're having).

Probably drawing the emissive mesh a second time is a nice thing (if there aren't too many of them), as it gives you the most flexibiltity. Imagine extruding the triangles and using some fancy-pants shader, you could probably have a volumetric glow rather than a flat emissive.

### #9InvalidPointer  Members

Posted 17 December 2011 - 12:23 PM

Have you considered doing pre-pass lighting? It's basically the same as what you conclude, but for all objects in the scene. It uses less render targets (usually just one if you have hardware support for reading depth buffer) that classic deferred rendering, and also enables more variety in the materials (which is sorta that problem you're having).

Probably drawing the emissive mesh a second time is a nice thing (if there aren't too many of them), as it gives you the most flexibiltity. Imagine extruding the triangles and using some fancy-pants shader, you could probably have a volumetric glow rather than a flat emissive.

I wouldn't suggest this, overall. A light-prepass renderer would entail rendering *everything* twice for marginal gain. As bzroom stated, things are already in feature lock so I think materials, etc. don't need much more flexibility. As far as I'm aware this approach is considered more or less superceded nowadays and the advantages over straight deferred shading were somewhat dubious even way-back-when.

On topic-- If you can hold off on drawing emissives until the end of the opaque pass, you can probably even get around the second draw call, just bind the illumination buffer as an additional render target and have the shader write out the emissive color; depth rejects will take care of the rest. The one problem I see is that this is going to eat up more EDRAM, and I don't know what your budget for that is.

EDIT: I see you're using unpacked normals, too. As a thought you could switch over to a compressed format (spheremap transform comes recommended) and then have 8 bits left over for a monochrome self-illumination value. I'm unsure if this would be satisfactory for the artists, though.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.

### #10bzroom  Members

Posted 18 December 2011 - 10:22 PM

Thats a really good idea. That's essentially what i was hoping to do. Store some coefficient that transformed the diffuse into the emissive factor.

Sort of like barycentric light coordinates. Where a 0.25 would indicate that the stored color is 0.25 between diffuse and emissive.
So neither the diffuse nor the emissive value were directly stored, but rather the barycentric value and coordinate were stored.

I'm not sure if that's even possible. But your solution is almost exactly that, assuming the only difference between the two colors was intensity.

Thank you. I'll run that by them.

edit:
I'm using unpacked because each channel is only using 8 bits.
I'm pretty sure we could spare another render target. But i would be proud of the implementation if it only needed 2 targets. It would also obviously be significantly better with less render targets. In terms of memory and texture fetches and resolve times.

### #11Ashaman73  Members

Posted 19 December 2011 - 12:41 AM

Thats a really good idea. That's essentially what i was hoping to do. Store some coefficient that transformed the diffuse into the emissive factor.

Sort of like barycentric light coordinates. Where a 0.25 would indicate that the stored color is 0.25 between diffuse and emissive.
So neither the diffuse nor the emissive value were directly stored, but rather the barycentric value and coordinate were stored.

I'm not sure if that's even possible. But your solution is almost exactly that, assuming the only difference between the two colors was intensity.

Thank you. I'll run that by them.

edit:
I'm using unpacked because each channel is only using 8 bits.
I'm pretty sure we could spare another render target. But i would be proud of the implementation if it only needed 2 targets. It would also obviously be significantly better with less render targets. In terms of memory and texture fetches and resolve times.

Well, you want to keep your artist Then this is the way I do it my engine:
I support multi-layered, emissive materials, but in the g-buffer I only store the index of the material, in the lighting pass I take this index, get the material vectors and use it to do the calculation. To handle materials more granulary I save 2 indicies and an alpha value per pixel to interpolate between different material. All material vectors are saved in const shader parameters (as said, only needed in the lighting pass). When rendering a model to the g-buffer, I use a uniform parameter per surface to hold the indicies and an alpha value saved in a texture to manage the material distribution.

I would change your current gbuffer like this:

RGBA8: diffuse RGB 8 bits each, 8 bit material index A
RGBA8: compressed normal xy 8 bits each, 8 bit material index B, 8 bit alpha value

// lighting pass pseudo shader code:
vec4 materialA = materials[material_index_A]
vec4 materialB = materials[material_index_B]
vec4 material = interpolate(materialA,materialB,alpha)

final_light = diffuse * (light_factor * material.diffuse_channel + material.emissive_channel) + diffuse * ( pow(spec_factor,material.spec_exponent) * material.gloss)


This way you have some freedom to expand the material properties (I currently use 3 material vectors), while keeping a constant impact on the g-buffer.

An alternative is to save the texture coords and make several texture lookup.

For normal compression take a look here: clicky

Ashaman

### #12bzroom  Members

Posted 20 December 2011 - 02:10 PM

Thanks Aras. I have been reading your compression page for a while. I'll be sure to put it to use when i can.

The thing i haven't understood yet about material id systems is how this would work on a per pixel basis.

Specifically if they wanted to have an emissive map (along side their diffuse map.)
Say they want to have a rainbow emission texture mapped onto the surface of a model.
It seems like with the material lookup, there can only be only emission color for the whole surface.

Also, looking at your psuedo light model, it looks like they can also only have one specular intensity per material.
So the interpolation between materials would not be independent for both emission and specular.
Ie: If the material interpolator goes to one side or the other, both the specular and the emission factors will be affected.

Am i understanding correctly?

### #13Zoner  Members

Posted 21 December 2011 - 01:42 AM

Having the g-buffer output emissive as the starting point for light accumulation works out fairly well.

You can't avoid clearing the buffer to black, so you might as well have the g-buffer pass fill it in for you.

### #14bzroom  Members

Posted 21 December 2011 - 02:26 PM

That's what i'm doing now. But we're talking about how the first pass the emissive/depth fill, and future light passes differentiate between diffuse and emissive colors without explicitly storing the two in the G-Buffer.

Feel free to post the format of your G-Buffer for reference.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.