• 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
barsiwek

Packing DXGI_FORMAT_R11G11B10_FLOAT

8 posts in this topic

Hi everyone,

I would like to ask how to properly pack values of a vertex normal using DXGI_FORMAT_R11G11B10_FLOAT format.
My input, per vertex, is a 3 dimensional vector with components in range [-1,1] stored in 32bit floats. I do know that I have to scale that into the [0, 1] range since there is no signs in R11G11B10 format, but what am I suppose to do after? I can extract the exponent and mantisa but is truncating them bitwise the right way to go?
0

Share this post


Link to post
Share on other sites
[quote name='barsiwek' timestamp='1350217394' post='4990022']
Hi everyone,

I would like to ask how to properly pack values of a vertex normal using DXGI_FORMAT_R11G11B10_FLOAT format.
My input, per vertex, is a 3 dimensional vector with components in range [-1,1] stored in 32bit floats. I do know that I have to scale that into the [0, 1] range since there is no signs in R11G11B10 format, but what am I suppose to do after? I can extract the exponent and mantisa but is truncating them bitwise the right way to go?
[/quote]

What exactly do you want to do?
Get your normal with as high precision as possible to your shader using only 32 bits total for the vector?
0

Share this post


Link to post
Share on other sites
store in the shader:

stored_normal = normal * 0.5f + 0.5f;

restore in the shader:

restored_normal = stored_normal * 2.0f - 1.0f;

Nothing more complicated than that. However, I'm not sure if DXGI_FORMAT_R11G11B10_FLOAT has good precision for normals.

Cheers! Edited by kauna
0

Share this post


Link to post
Share on other sites
[quote name='Erik Rufelt' timestamp='1350220791' post='4990028']
What exactly do you want to do?
Get your normal with as high precision as possible to your shader using only 32 bits total for the vector?
[/quote]
I want to try out different formats for storing normals at vertices and compare quality to pick the one that suits me the best. Most formats are either simple to pack to have functions that do that for you (for example - D3DX_FLOAT4_to_R10G10B10A2_UNORM). With this one I do not know how to do it correctly.


[quote name='kauna' timestamp='1350230832' post='4990065']
store in the shader:

stored_normal = normal * 0.5f + 0.5f;

restore in the shader:

restored_normal = stored_normal * 2.0f - 1.0f;

Nothing more complicated than that. However, I'm not sure if DXGI_FORMAT_R11G11B10_FLOAT has good precision for normals.

Cheers!
[/quote]

I was hoping on a description how to do it on application side (in C++ for example) - so I can store this in a binary file for fast loading later.
0

Share this post


Link to post
Share on other sites
[quote name='barsiwek' timestamp='1350231165' post='4990070']
I want to try out different formats for storing normals at vertices and compare quality to pick the one that suits me the best. Most formats are either simple to pack to have functions that do that for you (for example - D3DX_FLOAT4_to_R10G10B10A2_UNORM). With this one I do not know how to do it correctly.
[/quote]

[s]I see. The source for that function is in D3DX_DXGIFormatConvert.inl in the DX SDK Include folder., so you can always do it the same way.
Looking at the source, that function also saturates your input to [0, 1], so you'd have to do that first to use the same method, with (x + 1) / 2. Then modify the scale to match R11G11B10, which means 2047 for x, 2047 for y, shift with 11 instead of 10 for y, and still 1023 for z but shift by 22. W is skipped.
In the unpack function replace the shifts and scales the same way, shift 11 for y and 22 for z, divide by 2047 for x and y, and the mask for x and y is 0x7ff instead of 0x3ff.
And to restore your values from [0, 1] to [-1, 1] use x * 2 - 1.[/s]

Actually never mind, you're trying to use a float format. Sorry about that. Edited by Erik Rufelt
0

Share this post


Link to post
Share on other sites
This is completely untested.. but something like the following will probably work if the input is in [0, 1]:
[source]
typedef unsigned int uint32;

uint32 convertFloat32ToFloat11Bits(float f) {
uint32 floatBits;
memcpy(&floatBits, &f, 4);

uint32 exponent = (floatBits >> 23U) & 0xffU;
uint32 mantissa = floatBits & 0x7fffffU;

uint32 float11Exponent = exponent - 127 + 15;
uint32 float11Mantissa = mantissa >> 17;
if(exponent < 112) {
float11Exponent = 0;
float11Mantissa = 0;
}

uint32 float11Bits = (float11Exponent << 6) | float11Mantissa;

return float11Bits;
}

uint32 convertFloat32ToFloat10Bits(float f) {
uint32 floatBits;
memcpy(&floatBits, &f, 4);

uint32 exponent = (floatBits >> 23U) & 0xffU;
uint32 mantissa = floatBits & 0x7fffffU;

uint32 float10Exponent = exponent - 127 + 15;
uint32 float10Mantissa = mantissa >> 18;
if(exponent < 112) {
float10Exponent = 0;
float10Mantissa = 0;
}

uint32 float10Bits = (float10Exponent << 5) | float10Mantissa;

return float10Bits;
}

uint32 convertFloat32VectorToR11G11B10(XMFLOAT3 vec) {
uint32 rbits = convertFloat32ToFloat11Bits(vec.x);
uint32 gbits = convertFloat32ToFloat11Bits(vec.y);
uint32 bbits = covnertFloat32ToFloat10Bits(vec.z);

uint32 result = rbits | (gbits << 11) | (bbits << 22);

return result;
}
[/source]

[Edited to fix too small values]. Edited by Erik Rufelt
0

Share this post


Link to post
Share on other sites
DirectXMath has a whole bunch of [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ee418728%28v=vs.85%29.aspx#graphics_library_type_equivalence"]format conversion types[/url] in the PackedVector namespace, including [url="http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xmfloat3pk%28v=vs.85%29.aspx"]XMFLOAT3PK[/url] which works for R11G11B10_FLOAT. You can just use that directly, or look at the implementation XMLoadFloat3PK/XMStoreFloat3PK to see how it's done.
0

Share this post


Link to post
Share on other sites
Wow! Thank you Erik for the code and MJP for reference.
Microsoft should work a bit on their documentation - I did a bunch of searching on MSDN and did not come over this article at all :/
0

Share this post


Link to post
Share on other sites
If you want to efficiently store normals in vertices, I strongly suggest you that you read:

[url="http://www.crytek.com/download/izfrey_siggraph2011.pdf"]Crytek's QTangents:[/url] Storing normal, tangent & reflection data in just 4 floats (very useful for normal mapping). Starts at slide 8
[url="http://www.humus.name/Articles/Persson_CreatingVastGameWorlds.pptx"]Emil Persson's (Avalanche Studios) Creating Vast Game Worlds[/url]: Store normal, tangent & bitangents in just 4 bytes. Starts at slide 19

As for storing the normal maps in textures with just an RGB888 texture, Google Crytek's Best-fit normals technique

Cheers
Dark Sylinc
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