Archivo: Categoría 'Elvis Enmanuel - gamedusa blog'


Pack normal and height data in one float texture

[ Blog: Elvis Enmanuel - gamedusa blog ]
2010:03:30 02:42:00
Wow, hard coding night. But in the end I can code two routines that allows me to store normal mapping data and terrain height in one float texture. Remember that in order to perform vertex texture fetch in the vertex shader we need to access to the topology with one float texture.

I coded this in C++ but it's easy portable to GLSL or HLSL.

In this example I store only 2 normal components: X and Y in range 0 to 255. Remember that you must extract third component as follows: sqrt( 1.0 - nx*nx + ny*ny );

Heightmap has custom precision values, due big imprecision of floating point conversion. With 11 bits of precision we can store heights from 0 to 2043. This happened because we loose 4 numbers with this precision. The formula is:

unsigned char hPrecisionBits = 11; // (1<<11) = 2048
unsigned char expectedError = 1 << (hPrecisionBits - 9); // 4
unsigned short maxHeight = (1 << hPrecisionBits) - expectedError; // 2044

//! Gives fractional number
inline float frac( float _value ) {
return _value - floorf( _value );
}

// NX | NY | HEIGHT -> float32
// 8 | 8 | 16
inline float packNormalAndHeight( unsigned char _nx, unsigned char _ny, unsigned short _height, char _hPrecisionBits )
{
return
(_nx / 256.0) +
((_ny / 256.0) / 256.0) +
(_height / ((float)(1<<_hPrecisionBits)) / 65536.0);
}

// float32 -> NX | NY | HEIGHT
// 8 | 8 | 16
inline void unpackNormalAndHeight( float _value, char _hPrecisionBits, float* nx_, float* ny_, float* height_ )
{
*nx_ = floorf( frac( _value ) * 256.0 );
*ny_ = floorf( frac( _value * 256.0 ) * 256.0 );
*height_ = frac( _value * 65536.0 ) * ((float)(1<<_hPrecisionBits));
}


Usage example:

unsigned char hPrecisionBits = 11; // (1<<11) = 2048
unsigned char expectedError = 1 << (hPrecisionBits - 9); // 4
unsigned short maxHeight = (1 << hPrecisionBits) - expectedError; // 2044

// Pack as 8 | 8 | 16
float packedValue = packNormalAndHeight( 231, 137, 2043, hPrecisionBits );

// Unpack from single float
float x,y,h;
unpackNormalAndHeight( packedValue, hPrecisionBits, &x, &y, &h );

Notice that 'expectedError' brings us the amount of error values returned in height function. For example, if our precision bits are 9, expected error will be 1 (135 when we store 136 number). For 10, error will be 2, for 11, will be 4, for 12 will be 8, etc...

I hope it will be useful.

A message to the world

[ Blog: Elvis Enmanuel - gamedusa blog ]
2010:01:06 16:22:00


...or when the human beings became adults.

Codelite

[ Blog: Elvis Enmanuel - gamedusa blog ]
2009:12:05 18:04:00

Surfing through the xubuntu repository I found this new fantastic c++ multiplatform ide:
In Windows it uses gcc 4.4 and has an integrated Subversion plugin!!!
http://www.codelite.org/

Currently I'm trying it with my home projects. OhYesYesYesYes

Campanas por la gripe A

[ Blog: Elvis Enmanuel - gamedusa blog ]
2009:10:13 18:55:00
Una de vacunas:

TERESA FORCADES, doctora en Salut Pública, hace una reflexión sobre la historia de la GRIPE A, aportando datos científicos, y enumerando las irregularidades relacionadas con el tema.



Explica las consecuencias de la declaracion de PANDEMIA, las implicaciones políticas que de ello se derivan y hace una propuesta para mantener la calma, así como un llamamiento urgente para activar los mecanismos legales y de participación ciudadana en relación a este tema.

Lucera Project

[ Blog: Elvis Enmanuel - gamedusa blog ]
2009:09:18 13:51:00
"Lucera Project is a small videogame company that wants to realize some basic libraries to help other ‘indie’ programmers to make games easily. Performing all difficult and cumbersome stuff to allow developers to implement their games without worrying about details like load sounds and textures, render on screen, capture inputs, and so on.

In addition, Lucera Project libraries are cross platform and can compile the same code for different platforms such as Windows or iPhoneOS.

We hope to help many people to achieve their dreams of creating video games."

Blog:
http://lucera-project.blogspot.com/

2D engine:
http://mindshake-lucera.blogspot.com/

Sound engine:
http://brainwave-lucera.blogspot.com/

Good luck!

Indian Hopi message

[ Blog: Elvis Enmanuel - gamedusa blog ]
2009:09:12 15:12:00
Roy LittleSun's message:

ShaderX7 contribution

[ Blog: Elvis Enmanuel - gamedusa blog ]
2009:08:29 12:05:00
Finaly, my article doesn't appears in the ShaderX7 book :(
But, hey! I appear inside as contributor. My fifteen minutes of fame :D





Light shafts

[ Blog: Elvis Enmanuel - gamedusa blog ]
2009:08:13 16:20:00




In my holidays I'm trying new techniques for my terrain engine. Unfortunately, in my screen space terrain implementations, the well-known artifact of "vertex swimming" appears and it's very noticiable :|

I think that I can reuse the technique in order to code a cool screen space water effect in the near future.

For now, I'd been added the "Game Programming Gems 6" terrain technique (very simple, pretty fast, and without any pre-calculation), light shafts (but the effect needs a radial blur), and particle billboards for cloud rendering.

Goodbye :(

[ Blog: Elvis Enmanuel - gamedusa blog ]
2009:06:26 14:58:00

Busyyyyy

[ Blog: Elvis Enmanuel - gamedusa blog ]
2009:03:06 03:27:00
:|