Sign in to follow this  
mauro78

Packing Data Advice

Recommended Posts

Hi All,

During a deferred pass on a D3DFMT_A16B16G16R16F render target I come across this problem:

I'm correctly computing a "in-scatter" value which is a float3 where every component are a 16bit float.

[b]Is there a good way to store (even with a little loss of precision) those 3 values into a single float (16bit)?[/b]

Hints/help/link appreciated....thx

EDIT: scatter is a float3 where every component is in the [0,1] range


Mauro
IoN6 Games Edited by mauro78

Share this post


Link to post
Share on other sites
[quote name='mauro78' timestamp='1348687405' post='4984076']
Hi All,

During a deferred pass on a D3DFMT_A16B16G16R16F render target I come across this problem:

I'm correctly computing a "in-scatter" value which is a float3 where every component are a 16bit float.

[b]Is there a good way to store (even with a little loss of precision) those 3 values into a single float (16bit)?[/b]

Hints/help/link appreciated....thx

EDIT: scatter is a float3 where every component is in the [0,1] range


Mauro
IoN6 Games
[/quote]

if you have 3 component in 0,1 range it is most likely that they fit in 8 bits per channel. So 24 bit are necessary to store them and therefore 16bits are not enough.

In deferred shading you can store everything in 8888 buffer using a color comprwession scheme (see logluv)

Share this post


Link to post
Share on other sites
Puting it into a 16 float is the hard problem. If you would have a 16 bit int you could use a 5:5:6 distribution. I don't know what your scatter value means and what value ranges they have, but there are other options.
One option is, that you can reconstruct one value from the other two (maybe using a mapping to transform the scatter value in a better representation). This way you only have two values, which could be saved as decimal number like "left_value + (right_value/MAX_RIGHT_VALUE)". This way you save the right value as fraction. Though you need to ensure that your base values are integer values and don't get too high.

Share this post


Link to post
Share on other sites
[quote name='Ashaman73' timestamp='1348724434' post='4984233']
Puting it into a 16 float is the hard problem. If you would have a 16 bit int you could use a 5:5:6 distribution. I don't know what your scatter value means and what value ranges they have, but there are other options.
One option is, that you can reconstruct one value from the other two (maybe using a mapping to transform the scatter value in a better representation). This way you only have two values, which could be saved as decimal number like "left_value + (right_value/MAX_RIGHT_VALUE)". This way you save the right value as fraction. Though you need to ensure that your base values are integer values and don't get too high.
[/quote]

He can do that trick with normals and store just xy (even though he has to be careful in which space they are as z can be negative or positive).

See [url="http://aras-p.info/texts/CompactNormalStorage.html"]http://aras-p.info/texts/CompactNormalStorage.html[/url] for several ways of compressing your normals in gbuffer.

But since he is talking about inscatter I would guess maybe he means the accumulated direct lighting and in that case we are in the context of manging hdr values.

So I would suggest if you are on PC just go for a 16bits frame buffer and use CIE to RGB conversion while tonemapping your luminance and then convert from CIE back to

RGB with the adjusted/tonemapped luminance. That will preserve your hue and saturation as it will allow you to work on just the luminance.

The need to store or compress values in smaller buffers is more relevant on consoles where the bandwidth problem is more present and, also, in the case in which you don't

support floating point blending (which is the case on PS3 if I don't remember wrong). A good approach is described in shaderx7, using LogLuv color space compression to

store HDR value in 8888 unsigned. The only disadvantage is that you can't blend in LogLuv space but there is a trick to do it and that is explained in that article.

Also you can couple that approach with a light prepass renderer scheme to reduce the bandwidth requested to your gbuffers even more, but at the cost of making two

geometry passes. Edited by MegaPixel

Share this post


Link to post
Share on other sites
[quote name='Ashaman73' timestamp='1348737113' post='4984286']
Before doing all this magic, why not use an additional render target ?
[/quote]

Actually if he is on PC he can also go for a full deferred solution as bandwidth is not as big as in the past. So I guess a minimum of 3 gbuffers is enough ... it then depends on his setup ...

Share this post


Link to post
Share on other sites
Dear MegaPixel & Ashaman73,
thanks for reply, just for clarification:

a) I'm on PC
b) In-Scatter is computed during the accumulation phase and it's a single float but since every light has it's own color a float3 is required. If I assume that every light scatter the same color the problem is solved (I'll pack this value in the A component. I've already tested that path....not bad but just one color is the limit)
c) An addition RT during the accumulation phase: not a bad idea I was thinking the same

Share this post


Link to post
Share on other sites
[quote name='MegaPixel' timestamp='1348733400' post='4984269']
[quote name='Ashaman73' timestamp='1348724434' post='4984233']
Puting it into a 16 float is the hard problem. If you would have a 16 bit int you could use a 5:5:6 distribution. I don't know what your scatter value means and what value ranges they have, but there are other options.
One option is, that you can reconstruct one value from the other two (maybe using a mapping to transform the scatter value in a better representation). This way you only have two values, which could be saved as decimal number like "left_value + (right_value/MAX_RIGHT_VALUE)". This way you save the right value as fraction. Though you need to ensure that your base values are integer values and don't get too high.
[/quote]

He can do that trick with normals and store just xy (even though he has to be careful in which space they are as z can be negative or positive).

See [url="http://aras-p.info/texts/CompactNormalStorage.html"]http://aras-p.info/t...malStorage.html[/url] for several ways of compressing your normals in gbuffer.

But since he is talking about inscatter I would guess maybe he means the accumulated direct lighting and in that case we are in the context of manging hdr values.

So I would suggest if you are on PC just go for a 16bits frame buffer and use CIE to RGB conversion while tonemapping your luminance and then convert from CIE back to

RGB with the adjusted/tonemapped luminance. That will preserve your hue and saturation as it will allow you to work on just the luminance.

The need to store or compress values in smaller buffers is more relevant on consoles where the bandwidth problem is more present and, also, in the case in which you don't

support floating point blending (which is the case on PS3 if I don't remember wrong). A good approach is described in shaderx7, using LogLuv color space compression to

store HDR value in 8888 unsigned. The only disadvantage is that you can't blend in LogLuv space but there is a trick to do it and that is explained in that article.

Also you can couple that approach with a light prepass renderer scheme to reduce the bandwidth requested to your gbuffers even more, but at the cost of making two

geometry passes.
[/quote]

Let me clarify this: during the light accumulation phase of the deferred rendering pipeline I'm storing (for every light):

(RT1)R,G,B channels: diffuse light accumulation
(RT1)A channel: In-Scatter accumulation (monochromatic light scattering)

as described before maybe I'll create another RT and go to this scenario:

(RT1)R,G,B channels: diffuse light accumulation
(RT2)R,G,B: In-Scatter accumulation (colored lights)

Regards Edited by mauro78

Share this post


Link to post
Share on other sites
[quote name='mauro78' timestamp='1348754753' post='4984354']
[quote name='MegaPixel' timestamp='1348733400' post='4984269']
[quote name='Ashaman73' timestamp='1348724434' post='4984233']
Puting it into a 16 float is the hard problem. If you would have a 16 bit int you could use a 5:5:6 distribution. I don't know what your scatter value means and what value ranges they have, but there are other options.
One option is, that you can reconstruct one value from the other two (maybe using a mapping to transform the scatter value in a better representation). This way you only have two values, which could be saved as decimal number like "left_value + (right_value/MAX_RIGHT_VALUE)". This way you save the right value as fraction. Though you need to ensure that your base values are integer values and don't get too high.
[/quote]

He can do that trick with normals and store just xy (even though he has to be careful in which space they are as z can be negative or positive).

See [url="http://aras-p.info/texts/CompactNormalStorage.html"]http://aras-p.info/t...malStorage.html[/url] for several ways of compressing your normals in gbuffer.

But since he is talking about inscatter I would guess maybe he means the accumulated direct lighting and in that case we are in the context of manging hdr values.

So I would suggest if you are on PC just go for a 16bits frame buffer and use CIE to RGB conversion while tonemapping your luminance and then convert from CIE back to

RGB with the adjusted/tonemapped luminance. That will preserve your hue and saturation as it will allow you to work on just the luminance.

The need to store or compress values in smaller buffers is more relevant on consoles where the bandwidth problem is more present and, also, in the case in which you don't

support floating point blending (which is the case on PS3 if I don't remember wrong). A good approach is described in shaderx7, using LogLuv color space compression to

store HDR value in 8888 unsigned. The only disadvantage is that you can't blend in LogLuv space but there is a trick to do it and that is explained in that article.

Also you can couple that approach with a light prepass renderer scheme to reduce the bandwidth requested to your gbuffers even more, but at the cost of making two

geometry passes.
[/quote]

Let me clarify this: during the light accumulation phase of the deferred rendering pipeline I'm storing (for every light):

(RT1)R,G,B channels: diffuse light accumulation
(RT1)A channel: In-Scatter accumulation (monochromatic light scattering)

as described before maybe I'll create another RT and go to this scenario:

(RT1)R,G,B channels: diffuse light accumulation
(RT2)R,G,B: In-Scatter accumulation (colored lights)

Regards
[/quote]

I personally use one render target 16bit fp only as everything get modulated in one go:

return dffuseTerm*lightColor

diffuseTerm should be what you call in-scatter and light color is the rgb color of a given light.

I don't see why you have to use so many render target to store the computed lighting ... any reason for that ?

The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your bandwidth. Edited by MegaPixel

Share this post


Link to post
Share on other sites
[quote name='MegaPixel' timestamp='1348755712' post='4984362']
I personally use one render target 16bit fp only as everything get modulated in one go:

return dffuseTerm*lightColor

diffuseTerm should be what you call in-scatter and light color is the rgb color of a given light.

I don't see why you have to use so many render target to store the computed lighting ... any reason for that ?

The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your bandwidth.
[/quote]

MegaPixel, In-scatter is not diffuse lighting that's why I need more space :-)

[url="http://en.wikipedia.org/wiki/Light_scattering...."]http://en.wikipedia...._scattering....[/url]

my final color is:
fragment color = (diffuse fragment color*texture_color) + inscatter fragment color

regards

p.s.
[b]>The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your >bandwidth.[/b]

I agree but my problem is not about this (g-Buffer creation phase)...but in the next one: accumulation phase Edited by mauro78

Share this post


Link to post
Share on other sites
Yes, bandwidth might be a performance problem, but even games which supports lot of (older) hardware writes up to 4 buffers at once(=> StarCraft II, 4x 16bit float RGBA). Putting 3 independent values in the range of [0..1] into a single 16 bit float is really hard without loosing lot of quality. Try to write up your render engine first and see if you can optimize it later on.

Share this post


Link to post
Share on other sites
[quote name='mauro78' timestamp='1348756396' post='4984365']
[quote name='MegaPixel' timestamp='1348755712' post='4984362']
I personally use one render target 16bit fp only as everything get modulated in one go:

return dffuseTerm*lightColor

diffuseTerm should be what you call in-scatter and light color is the rgb color of a given light.

I don't see why you have to use so many render target to store the computed lighting ... any reason for that ?

The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your bandwidth.
[/quote]

MegaPixel, In-scatter is not diffuse lighting that's why I need more space :-)

[url="http://en.wikipedia.org/wiki/Light_scattering...."]http://en.wikipedia...._scattering....[/url]

my final color is:
fragment color = (diffuse fragment color*texture_color) + inscatter fragment color

regards

p.s.
[b]>The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your >bandwidth.[/b]

I agree but my problem is not about this (g-Buffer creation phase)...but in the next one: accumulation phase
[/quote]

Ohh you meant indirect lighting ?

Share this post


Link to post
Share on other sites
[quote name='mauro78' timestamp='1348756396' post='4984365']
[quote name='MegaPixel' timestamp='1348755712' post='4984362']
I personally use one render target 16bit fp only as everything get modulated in one go:

return dffuseTerm*lightColor

diffuseTerm should be what you call in-scatter and light color is the rgb color of a given light.

I don't see why you have to use so many render target to store the computed lighting ... any reason for that ?

The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your bandwidth.
[/quote]

MegaPixel, In-scatter is not diffuse lighting that's why I need more space :-)

[url="http://en.wikipedia.org/wiki/Light_scattering...."]http://en.wikipedia...._scattering....[/url]

my final color is:
fragment color = (diffuse fragment color*texture_color) + inscatter fragment color

regards

p.s.
[b]>The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your >bandwidth.[/b]

I agree but my problem is not about this (g-Buffer creation phase)...but in the next one: accumulation phase
[/quote]

The accumulation phase is not a problem, just use another render target [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]. I personally use a different render target for my indirect lighting [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] ...

Again, the problem is normally the gbuffer phase, in a typical pipeline when you need to compose different results it's very normal to subdivide those in more passes, with each

pass it's own render target etc. and then compose them at the end. Edited by MegaPixel

Share this post


Link to post
Share on other sites
[quote name='MegaPixel' timestamp='1348818490' post='4984649']
[quote name='mauro78' timestamp='1348756396' post='4984365']
[quote name='MegaPixel' timestamp='1348755712' post='4984362']
I personally use one render target 16bit fp only as everything get modulated in one go:

return dffuseTerm*lightColor

diffuseTerm should be what you call in-scatter and light color is the rgb color of a given light.

I don't see why you have to use so many render target to store the computed lighting ... any reason for that ?

The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your bandwidth.
[/quote]

MegaPixel, In-scatter is not diffuse lighting that's why I need more space :-)

[url="http://en.wikipedia.org/wiki/Light_scattering...."]http://en.wikipedia...._scattering....[/url]

my final color is:
fragment color = (diffuse fragment color*texture_color) + inscatter fragment color

regards

p.s.
[b]>The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your >bandwidth.[/b]

I agree but my problem is not about this (g-Buffer creation phase)...but in the next one: accumulation phase
[/quote]

Ohh you meant indirect lighting ?
[/quote]

No It's not.
Diffuse computation model the interaction between photons and surface
Scattered light model the interaction between photons and athmosphere or other medium. Here You can have 3 types of results in-scattered,out-scattered,absorbed.

The resulting effects is sort of volumetric effects..... Edited by mauro78

Share this post


Link to post
Share on other sites
[quote name='mauro78' timestamp='1348847187' post='4984749']
[quote name='MegaPixel' timestamp='1348818490' post='4984649']
[quote name='mauro78' timestamp='1348756396' post='4984365']
[quote name='MegaPixel' timestamp='1348755712' post='4984362']
I personally use one render target 16bit fp only as everything get modulated in one go:

return dffuseTerm*lightColor

diffuseTerm should be what you call in-scatter and light color is the rgb color of a given light.

I don't see why you have to use so many render target to store the computed lighting ... any reason for that ?

The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your bandwidth.
[/quote]

MegaPixel, In-scatter is not diffuse lighting that's why I need more space :-)

[url="http://en.wikipedia.org/wiki/Light_scattering...."]http://en.wikipedia...._scattering....[/url]

my final color is:
fragment color = (diffuse fragment color*texture_color) + inscatter fragment color

regards

p.s.
[b]>The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your >bandwidth.[/b]

I agree but my problem is not about this (g-Buffer creation phase)...but in the next one: accumulation phase
[/quote]

Ohh you meant indirect lighting ?
[/quote]

No It's not.
Diffuse computation model the interaction between photons and surface
Scattered light model the interaction between photons and athmosphere or other medium. Here You can have 3 types of results in-scattered,out-scattered,absorbed.

The resulting effects is sort of volumetric effects.....
[/quote]

Ok so you are talking about sky light (the light reflected from the sky)? Light shafts ? ... Edited by MegaPixel

Share this post


Link to post
Share on other sites
[quote name='MegaPixel' timestamp='1348850320' post='4984764']
[quote name='mauro78' timestamp='1348847187' post='4984749']
[quote name='MegaPixel' timestamp='1348818490' post='4984649']
[quote name='mauro78' timestamp='1348756396' post='4984365']
[quote name='MegaPixel' timestamp='1348755712' post='4984362']
I personally use one render target 16bit fp only as everything get modulated in one go:

return dffuseTerm*lightColor

diffuseTerm should be what you call in-scatter and light color is the rgb color of a given light.

I don't see why you have to use so many render target to store the computed lighting ... any reason for that ?

The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your bandwidth.
[/quote]

MegaPixel, In-scatter is not diffuse lighting that's why I need more space :-)

[url="http://en.wikipedia.org/wiki/Light_scattering...."]http://en.wikipedia...._scattering....[/url]

my final color is:
fragment color = (diffuse fragment color*texture_color) + inscatter fragment color

regards

p.s.
[b]>The problem, IMHO, is more relevant when you have to chose the number of gbuffers and their number of bit per channel as that is one thing that can influence your >bandwidth.[/b]

I agree but my problem is not about this (g-Buffer creation phase)...but in the next one: accumulation phase
[/quote]

Ohh you meant indirect lighting ?
[/quote]

No It's not.
Diffuse computation model the interaction between photons and surface
Scattered light model the interaction between photons and athmosphere or other medium. Here You can have 3 types of results in-scattered,out-scattered,absorbed.

The resulting effects is sort of volumetric effects.....
[/quote]

Ok so you are talking about sky light (the light reflected from the sky)? Light shafts ? ...
[/quote]

Yeah MegaPixel, Light Shafts are a perfect example of in-scattering [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img] Edited by mauro78

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this