• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
RPTD

GLSL Float Packing

8 posts in this topic

If you have for example a conventional 8-bit RGB or RGBA texture you can pack a float (for example depth) in there using some GLSL based encoding/decoding trick. Now I'd like to examine some special case. Let's say we have a 16-bit float RGB or RGBA texture as render target. I have 2 float values which are in the range 0-1 and for which it would be okay to loose precision down to 8-bit or 7-bit. Is there a way to pack 2 float values into 1 16-bit float texture color component? Since that way a single GBuffer texture could hold 8 float values of limited accuracy. Somebody said one to use "float output = floor( floatValue1 * 255.0 ) + floatValue2;". Somehow I don't think that would do the trick as 16-bit float is not stored in a way for this to have much of an effect. I presume the sign bit, exponent bits and a couple of value bits would have to be used to store one value and the rest for the second.
0

Share this post


Link to post
Share on other sites
Hi!

What about packing 8 floats into an GL_RG32UI? (two unsigned ints with each 4 byte, which means 8 bit per float.)
This could save you some instructions, since you could pack with the little helper below 4 floats simultaneously (instead of just 2 if you would use 16-bit floats).

Would that help you?

[CODE]// vec4 to rgba8Unorm
uint pack(vec4 value)
{
// Ensure values are in [0..1] and make NaNs become zeros.
value = min(max(value,0.0f), 1.0f);

// Each component gets 8 bit.
value = value * 255 + 0.5f;
value = floor(value);

// Pack into one 32 bit uint.
return (((uint)value.x) |
(((uint)value.y)<< 8) |
(((uint)value.z)<<16) |
(((uint)value.w)<<24) );
}

// rgba8Unorm to vec4
vec4 unpack(uint value)
{
return vec4((float) (value & 0x000000ff) / 255,
(float) ((value>> 8) & 0x000000ff) / 255,
(float) ((value>>16) & 0x000000ff) / 255,
(float) ((value>>24) & 0x000000ff) / 255);
}[/CODE]
(Haven't checked the code... Just ported from HLSL to GLSL.)

Cheers!
0

Share this post


Link to post
Share on other sites
Not an option unfortunately since you can't use multiple render targets bound to an FBO which are of different texture format. I need RGBA_F16 so my only option is packing 2 floats into each F16 component there.
0

Share this post


Link to post
Share on other sites
[quote name='RPTD' timestamp='1334960267' post='4933371']
Not an option unfortunately since you can't use multiple render targets bound to an FBO which are of different texture format.
[/quote]
Since when?

There was (Not sure whether it still is (*). I think the limitation was lifted, but not sure) a requirement of all targets having the same total bits per texel - but no requirements on how the bits are used (ie. R32F is the same size as RGBA8).

*) After searching around a bit: not sure when, but seems the last restriction was lifted at some point - so, any and all of the required formats ( http://www.opengl.org/wiki/Image_Formats#Texture_and_Renderbuffer ) are OK. have not yet used mismatching (ex: RGBA8 + RGBA32F) ones myself.
0

Share this post


Link to post
Share on other sites
In DX10+ it's perfectly legal and usual to bind several render targets of completely different formats and bit depths and numbers of channels (such as RGBA8 + RGBA32F + RG16F + whatever) to output merger simultaneously and get perfect results. The only restriction is the same resolution (width * height * array slices). I don't see why this wouldn't work with OpenGL 3+ as SM4.0+ HW apparently supports this.
0

Share this post


Link to post
Share on other sites
[quote name='RPTD' timestamp='1334949921' post='4933327']Is there a way to pack 2 float values into 1 16-bit float texture color component? Since that way a single GBuffer texture could hold 8 float values of limited accuracy. Somebody said one to use "float output = floor( floatValue1 * 255.0 ) + floatValue2;". Somehow I don't think that would do the trick as 16-bit float is not stored in a way for this to have much of an effect. I presume the sign bit, exponent bits and a couple of value bits would have to be used to store one value and the rest for the second.[/quote]I've never done this, but it should be possible. All the required details should be on the wikipedia page on floating point (and on logarithms). I imagine a packing function would look something like:[code]half PackHalf( float A/*one bit*/, float B/*5 bits*/, float C/*10 bits*/ )//all inputs in 0-1 range
{
float s = A*2-1;// -1/+1
float e = lerp( -13, 14, B );
float f = lerp( 1024, 2047, C );
return s*f*pow(2,e);
}//N.B. most likely contains mistakes[/code]
0

Share this post


Link to post
Share on other sites
[quote name='pcmaster' timestamp='1335167282' post='4933992']
In DX10+ it's perfectly legal and usual to bind several render targets of completely different formats and bit depths and numbers of channels (such as RGBA8 + RGBA32F + RG16F + whatever) to output merger simultaneously and get perfect results. The only restriction is the same resolution (width * height * array slices). I don't see why this wouldn't work with OpenGL 3+ as SM4.0+ HW apparently supports this.
[/quote]
Because in the original specs FBOs didn't allow for such combinations and the five an FBO Incomplete error. There's some extension I think that is supposed to remove this restriction but I had no luck so far getting a mix to work reliably across different hardware so I'm hesitant to rely on such format combination although it would be of an advantage.

[quote name='Hodgman' timestamp='1335176142' post='4934028']
[quote name='RPTD' timestamp='1334949921' post='4933327']Is there a way to pack 2 float values into 1 16-bit float texture color component? Since that way a single GBuffer texture could hold 8 float values of limited accuracy. Somebody said one to use "float output = floor( floatValue1 * 255.0 ) + floatValue2;". Somehow I don't think that would do the trick as 16-bit float is not stored in a way for this to have much of an effect. I presume the sign bit, exponent bits and a couple of value bits would have to be used to store one value and the rest for the second.[/quote]I've never done this, but it should be possible. All the required details should be on the wikipedia page on floating point (and on logarithms). I imagine a packing function would look something like:[code]half PackHalf( float A/*one bit*/, float B/*5 bits*/, float C/*10 bits*/ )//all inputs in 0-1 range
{
float s = A*2-1;// -1/+1
float e = lerp( -13, 14, B );
float f = lerp( 1024, 2047, C );
return s*f*pow(2,e);
}//N.B. most likely contains mistakes[/code]
[/quote]
I see where you come from with this one. So an 8+8 bit (or 7+7 bit) encoding doesn't seem possible, only a 5+10 encoding.
0

Share this post


Link to post
Share on other sites
[quote name='RPTD' timestamp='1335217268' post='4934248']
Because in the original specs FBOs didn't allow for such combinations and the five an FBO Incomplete error. There's some extension I think that is supposed to remove this restriction but I had no luck so far getting a mix to work reliably across different hardware so I'm hesitant to rely on such format combination although it would be of an advantage.
[/quote]
The original specs did allow mixing, for example: RGBA8 + RG16F + R32F (ie. all 32bit formats). The restriction was lifted in one of the OpenGl releases (ie. no extension of any sort is needed. it is core.) - however, i was not able to track down exactly which OGL version it was :/. Probably starting with 3.0?
0

Share this post


Link to post
Share on other sites
Would be a possibility. I'm currently using 3.0 as the smallest required OGL version for the graphic module. I'm certainly gonna test it again. Maybe nVidia doesn't mess up with newer drivers anymore like it did so far. That said how much "working" do you expect from a graphic card that can't do linear filtering on a cube map without crashing U_U .
0

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  
Followers 0